HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
graph_transformer_utils.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 <unordered_set>
8 #include <vector>
9 
11 #include "core/framework/session_options.h"
13 
14 #if !defined(ORT_MINIMAL_BUILD)
17 #endif
18 
19 #if !defined(ORT_MINIMAL_BUILD) || defined(ORT_EXTENDED_MINIMAL_BUILD)
20 #include "core/optimizer/selectors_actions/selector_action_transformer_apply_contexts.h"
21 #endif
22 
23 namespace onnxruntime {
24 class IExecutionProvider;
25 
26 namespace optimizer_utils {
27 
28 #if !defined(ORT_MINIMAL_BUILD)
29 
30 /** Generates all predefined rules for this level.
31  If rules_to_enable is not empty, it returns the intersection of predefined rules and rules_to_enable.
32  TODO: This is visible for testing at the moment, but we should rather make it private. */
35  const InlinedHashSet<std::string>& rules_to_disable = {});
36 
37 /** Given a TransformerLevel, this method generates a name for the rule-based graph transformer of that level. */
39 
40 /** Generates all rule-based transformers for this level. */
41 std::unique_ptr<RuleBasedGraphTransformer> GenerateRuleBasedGraphTransformer(
42  TransformerLevel level,
43  const InlinedHashSet<std::string>& rules_to_disable,
44  const InlinedHashSet<std::string_view>& compatible_execution_providers);
45 
46 /** Generates all predefined (both rule-based and non-rule-based) transformers for this level.
47  Any transformers or rewrite rules named in rules_and_transformers_to_disable will be excluded. */
49  TransformerLevel level,
50  const SessionOptions& session_options,
51  const IExecutionProvider& execution_provider /*required by constant folding*/,
52  const InlinedHashSet<std::string>& rules_and_transformers_to_disable = {});
53 
54 #endif // !defined(ORT_MINIMAL_BUILD)
55 
56 #if !defined(ORT_MINIMAL_BUILD) || defined(ORT_EXTENDED_MINIMAL_BUILD)
57 
58 /** Generates all predefined transformers which can be used to provide runtime optimizations for this level
59  in a minimal build.
60  Any transformers or rewrite rules named in rules_and_transformers_to_disable will be excluded.
61 
62  This is a distinct function from GenerateTransformers() because:
63  - An ORT format model used in a minimal build will have been pre-optimized to at least level 1 when created, so
64  level 1 transformers are not included.
65  - In a minimal build we have limited optimization/Graph capabilities
66  - Graph::Resolve is not available so the transformer must keep the Graph in a valid state
67  - Limited graph_utils capabilities are included
68  - Only a small subset of transformers support storing/replaying runtime optimizations with an ORT format model
69  - this capability is provided by the SelectionActionTransformer infrastructure
70  - the logic to determine the set of nodes a transformer should modify is captured during creation of the ORT
71  format model
72  - this information is saved in the ORT format model
73  - only the logic to modify the set of nodes is included in the minimal build
74  - The QDQFinalCleanupTransformer and NhwcTransformer transformers are also supported in a minimal build
75 */
77  TransformerLevel level,
78  const SessionOptions& session_options,
79  const SatApplyContextVariant& apply_context,
80  const IExecutionProvider& cpu_execution_provider,
81  const InlinedHashSet<std::string>& rules_and_transformers_to_disable = {});
82 
83 #endif // !defined(ORT_MINIMAL_BUILD) || defined(ORT_EXTENDED_MINIMAL_BUILD)
84 
85 } // namespace optimizer_utils
86 } // namespace onnxruntime
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
GLint level
Definition: glcorearb.h:108
std::unique_ptr< RuleBasedGraphTransformer > GenerateRuleBasedGraphTransformer(TransformerLevel level, const InlinedHashSet< std::string > &rules_to_disable, const InlinedHashSet< std::string_view > &compatible_execution_providers)
InlinedVector< std::unique_ptr< GraphTransformer > > GenerateTransformers(TransformerLevel level, const SessionOptions &session_options, const IExecutionProvider &execution_provider, const InlinedHashSet< std::string > &rules_and_transformers_to_disable={})
absl::InlinedVector< T, N, Allocator > InlinedVector
InlinedVector< std::unique_ptr< GraphTransformer > > GenerateTransformersForMinimalBuild(TransformerLevel level, const SessionOptions &session_options, const SatApplyContextVariant &apply_context, const IExecutionProvider &cpu_execution_provider, const InlinedHashSet< std::string > &rules_and_transformers_to_disable={})
std::string GenerateRuleBasedTransformerName(TransformerLevel level)
InlinedVector< std::unique_ptr< RewriteRule > > GenerateRewriteRules(TransformerLevel level, const InlinedHashSet< std::string > &rules_to_disable={})