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