HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
graph_transformer_config.h
Go to the documentation of this file.
1 // Copyright (c) Microsoft Corporation. All rights reserved.
2 // Licensed under the MIT License.
3 
4 #pragma once
5 #include <string>
6 #include <vector>
7 #include <type_traits>
8 namespace onnxruntime {
9 
12  // Propagate FP16 Cast operations up and FP32 operations down
13  /*
14  * Cast propagation strategy.
15  * One strategy is to insert casts around all the nodes with the allowed opcodes
16  * and reduce, by removing redundent-casts and back-to-back-casts etc., and
17  * the other is to propagate casts using flood-fill approach, expanding float16 regions in the graph
18  * traversing the graph up/down.
19  */
20  enum class Strategy {
21  None = 0,
22  InsertAndReduce = 1,
23  FloodFill = 2, /* Propagate FP16 Cast operations up and FP32 operations down */
24  };
26  friend constexpr Strategy operator|(const Strategy s1, const Strategy s2) {
27  return static_cast<Strategy>(static_cast<Strategy_t>(s1) | static_cast<Strategy_t>(s2));
28  }
29 
30  friend Strategy& operator|=(Strategy& s1, Strategy s2) {
31  s1 = s1 | s2;
32  return s1;
33  }
34 
35  friend constexpr Strategy operator&(const Strategy s1, const Strategy s2) {
36  return static_cast<Strategy>(static_cast<Strategy_t>(s1) & static_cast<Strategy_t>(s2));
37  }
38 
39  friend constexpr Strategy& operator&=(Strategy& s1, Strategy s2) {
40  s1 = s1 & s2;
41  return s1;
42  }
43 
44  friend constexpr bool operator==(Strategy s1, Strategy s2) {
45  return static_cast<Strategy_t>(s1) == static_cast<Strategy_t>(s2);
46  }
47 
48  friend constexpr bool operator!=(Strategy s1, Strategy s2) {
49  return (s1 == s2) == false;
50  }
51 
52  int level{1}; /* -1 => no cast propagation,
53  0 => use user specified list of opcodes to allow moving cast operations,
54  1 => use ORT predefined list of level 1 opcodes in addition to the user specified allow opcodes
55  2 => use ORT predefined list of level 2 opcodes in addition to the user specified allow opcodes
56  */
58  // List of allowed opcodes to consider as safe to execute in float16, while moving cast operations
59  std::vector<std::string> allow;
60  };
61 
63 };
64 
65 // The following declarations are required to refer to these operators in pybind11.
72 
73 } // namespace onnxruntime
GLint level
Definition: glcorearb.h:108
ORT_HOST_DEVICE bool operator==(const Float8E4M3FN &left, const Float8E4M3FN &right)
Definition: float8.h:156
ORT_HOST_DEVICE bool operator!=(const Float8E4M3FN &left, const Float8E4M3FN &right)
Definition: float8.h:157
constexpr GraphTransformerConfiguration::PropagateCastOpsConfiguration::Strategy operator&(GraphTransformerConfiguration::PropagateCastOpsConfiguration::Strategy, GraphTransformerConfiguration::PropagateCastOpsConfiguration::Strategy)
PropagateCastOpsConfiguration propagate_cast_ops_config
friend constexpr Strategy operator&(const Strategy s1, const Strategy s2)
friend constexpr Strategy & operator&=(Strategy &s1, Strategy s2)
constexpr GraphTransformerConfiguration::PropagateCastOpsConfiguration::Strategy operator|(GraphTransformerConfiguration::PropagateCastOpsConfiguration::Strategy, GraphTransformerConfiguration::PropagateCastOpsConfiguration::Strategy)
friend constexpr Strategy operator|(const Strategy s1, const Strategy s2)
type
Definition: core.h:1059