HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
indexed_sub_graph.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 
6 #include <memory>
7 #include <string>
8 #include <vector>
9 
10 #include "core/graph/basic_types.h"
11 #if !defined(ORT_MINIMAL_BUILD)
12 #include "onnx/defs/schema.h"
13 #else
14 #include "onnx/defs/data_type_utils.h"
15 #endif
16 #include "onnx/onnx_pb.h"
17 #include "onnx/onnx-operators_pb.h"
18 
19 namespace onnxruntime {
20 
21 class OpKernel;
22 class OpKernelInfo;
23 
24 /**
25 @class IndexedSubGraph
26 
27 Class containing information about a subgraph of Nodes from a Graph.
28 It contains a NodeIndex array of the Nodes covered by the subgraph,
29 and the meta definition needed for representing this subgraph as a FunctionProto,
30 which could be serialized/saved to a model file.
31 */
33  struct MetaDef {
34  std::string name; ///< Name of customized SubGraph/FunctionProto
35  std::string domain; ///< Domain of customized SubGraph/FunctionProto
36  int since_version; ///< Since version of customized SubGraph/FunctionProto.
37 
38  ONNX_NAMESPACE::OperatorStatus status; ///< Status of customized SubGraph/FunctionProto.
39 
40  std::vector<std::string> inputs; ///< Inputs of customized SubGraph/FunctionProto.
41  std::vector<std::string> outputs; ///< Outputs of customized SubGraph/FunctionProto.
42  std::vector<std::string> constant_initializers; ///< Constant initializers of customized SubGraph/FunctionProto.
43  NodeAttributes attributes; ///< Attributes of customized SubGraph/FunctionProto.
44 
45  std::string doc_string; ///< Doc string of customized SubGraph/FunctionProto.
46 #if !defined(ORT_MINIMAL_BUILD)
47  /** Type and shape inference function that can optionally be defined for the fused node */
48  std::function<void(ONNX_NAMESPACE::InferenceContext&)> type_and_shape_inference_function;
49 #endif
50  };
51 
52  /** Nodes covered by this subgraph. The NodeIndex values are from the parent Graph.*/
53  std::vector<onnxruntime::NodeIndex> nodes;
54 
55  enum class SourceOfSchema : uint8_t {
56  CREATE, /// create new schema from info in IndexedSubGraph instance.
57  /// schema instance will not be re-usable.
58  REUSE_OR_CREATE, /// re-use existing dynamically created schema with matching domain+name.
59  /// create re-usable schema if one is not found.
60  EXISTING, /// use existing statically registered schema.
61  /// e.g. domain+name matches ONNX or contrib op domain+op_type+opset.
62  };
63  // Either using an existing schema or generating reusable one when fusing nodes using the MetaDef.
64  // MetaDef.domain + MetaDef.name => the domain.op_type that a schema must exist for with a valid since_version.
66 
67  /** Set the meta definition needed to represent this subgraph as a FunctionProto
68  It's needed IF AND ONLY IF there are multiple indexes contained in #nodes. */
69  void SetMetaDef(std::unique_ptr<MetaDef>&& meta_def) {
70  meta_def_ = std::move(meta_def);
71  }
72 
73  /** Gets the meta definition needed to represent this subgraph as a FunctionProto.
74  @returns MetaDef instance if it has been set. nullptr if not. */
75  const MetaDef* GetMetaDef() const {
76  return meta_def_.get();
77  }
78 
79  private:
80  // subgraph meta definition.
81  std::unique_ptr<MetaDef> meta_def_;
82 };
83 
84 } // namespace onnxruntime
std::string doc_string
Doc string of customized SubGraph/FunctionProto.
std::function< void(ONNX_NAMESPACE::InferenceContext &)> type_and_shape_inference_function
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
std::string domain
Domain of customized SubGraph/FunctionProto.
std::vector< std::string > constant_initializers
Constant initializers of customized SubGraph/FunctionProto.
std::vector< std::string > outputs
Outputs of customized SubGraph/FunctionProto.
std::vector< onnxruntime::NodeIndex > nodes
std::unordered_map< std::string, ONNX_NAMESPACE::AttributeProto > NodeAttributes
Definition: basic_types.h:42
int since_version
Since version of customized SubGraph/FunctionProto.
const MetaDef * GetMetaDef() const
ONNX_NAMESPACE::OperatorStatus status
Status of customized SubGraph/FunctionProto.
NodeAttributes attributes
Attributes of customized SubGraph/FunctionProto.
std::string name
Name of customized SubGraph/FunctionProto.
void SetMetaDef(std::unique_ptr< MetaDef > &&meta_def)
std::vector< std::string > inputs
Inputs of customized SubGraph/FunctionProto.