pattern_optimization.h#
-
namespace onnx_light
Alias that makes onnx-light headers compatible with code that references
ONNX_LIGHT_NAMESPACE(the macro used in the standard onnx package).Set to
ONNX_LIGHT_NAMESPACEso both names resolve to the same namespace.Symbol-visibility attribute for the public onnx-light C++ API.
Maps the upstream compatibility macro to onnx-light’s explicit proto ABI annotation. This keeps declarations from vendored ONNX headers visible when
lib_onnx_protouses hidden visibility by default.Namespace alias so that ONNX C++ code (and consumers such as onnxruntime) that refers to the literal
onnxnamespace — rather than theONNX_NAMESPACEmacro — resolves to the onnx-light namespace. The standard onnx package lives innamespace onnx; onnx-light usesonnx_light(via ONNX_LIGHT_NAMESPACE), so this alias keeps onnx-light a true drop-in. It is only introduced when the onnx-light namespace differs fromonnx.-
namespace core
-
namespace builder
-
struct LocalRewriting#
- #include <pattern_optimization.h>
Persistent description of one applied local graph rewrite.
Public Members
-
std::shared_ptr<const PatternOptimization> pattern#
Shared link to the pattern that produced the rewrite.
-
std::vector<std::string> graph_path#
Nested builder path from the root graph; empty means the root graph.
-
std::vector<std::size_t> matched_nodes#
Positions of the nodes selected by the match.
Positions refer to the graph at the start of the rewrite batch identified by
iteration, not to the original model: a later batch may match nodes added by an earlier one. This batch-local coordinate system is also used by :cpp:var:insert_at.
-
utils::RepeatedProtoField<NodeProto> added_nodes#
Replacement nodes owned by this record.
-
std::vector<std::size_t> added_nodes_positions#
Positions occupied by added nodes after this rewrite batch.
-
utils::RepeatedProtoField<TensorProto> added_initializers#
Initializers created while applying the pattern.
-
std::vector<std::size_t> added_initializer_positions#
Positions occupied by added initializers after this rewrite batch.
-
std::vector<std::pair<std::string, std::string>> value_renames#
Value-name replacements applied to node inputs and nested captures.
-
int64_t match_time_ns = 0#
Time spent recognizing this match, in nanoseconds.
-
int64_t apply_time_ns = 0#
Time spent building its replacement nodes, in nanoseconds.
-
std::shared_ptr<const PatternOptimization> pattern#
-
struct MatchResult#
- #include <pattern_optimization.h>
Describes one subgraph recognized by an optimization pattern.
Public Members
-
const PatternOptimization *pattern = nullptr#
Pattern that produced this match.
-
std::vector<const NodeProto*> nodes#
Nodes involved in the rewrite, in the order expected by Apply.
A null pointer is an ignored positional placeholder for an optional role. It is not positioned, marked, removed, or persisted in the rewrite.
-
const NodeProto *insert_at = nullptr#
Optional node before which the replacement should be inserted.
-
std::optional<PatternNoMatch> no_match = std::nullopt#
Diagnostic attached to an empty result, when the pattern supplied one.
-
const PatternOptimization *pattern = nullptr#
-
struct OptimizationReport#
- #include <pattern_optimization.h>
Optional timing report populated by :cpp:func:
GraphGraph::Optimize.Public Functions
-
int64_t TotalTimeNs() const noexcept#
Returns the sum of all phase durations, in nanoseconds.
Public Members
-
int64_t matching_time_ns = 0#
Time spent matching candidates in this graph, excluding subgraphs.
-
int64_t rewriting_time_ns = 0#
Time spent applying matches and rebuilding this graph, excluding subgraphs.
-
int64_t cleanup_time_ns = 0#
Time spent in cleanup passes for this graph, excluding subgraphs.
-
int64_t constant_folding_time_ns = 0#
Time spent folding replacements in this graph, excluding subgraphs.
-
int64_t subgraph_optimization_time_ns = 0#
Total wall-clock time spent recursively optimizing subgraphs.
-
std::vector<PatternOptimizationStatistics> patterns#
Aggregated root and subgraph counters in pattern evaluation order.
-
std::vector<SubgraphOptimizationStatistics> subgraphs#
Flat, deterministic list of recursively optimized subgraphs.
-
int64_t TotalTimeNs() const noexcept#
-
struct PatternNoMatch#
- #include <pattern_optimization.h>
Explains why one candidate did not match a pattern.
Public Members
-
struct PatternNoMatchStatistics#
- #include <pattern_optimization.h>
Aggregated reason and source location for rejected pattern candidates.
Public Members
-
class PatternOptimization#
- #include <pattern_optimization.h>
Stateless interface implemented by graph-rewriting patterns.
Public Functions
-
inline explicit PatternOptimization(int priority = 1, std::string name = {})#
Creates a pattern with the given optimization priority.
-
virtual ~PatternOptimization() = default#
-
inline const std::string &Name() const noexcept#
Returns the stable diagnostic name of this pattern.
-
void SetRegisteredName(const std::string &name)#
Assigns the registry name, rejecting a conflicting intrinsic name.
-
inline virtual std::set<std::string> FastOpType() const#
Returns the invariant operator types from which this pattern can start. The optimization driver caches this value once per optimization.
-
virtual MatchResult Match(GraphGraph &graph, const NodeProto &candidate) const = 0#
Returns the match rooted at
candidate. A null pattern means no match.
-
virtual utils::RepeatedProtoField<NodeProto> Apply(GraphGraph &graph, const std::vector<const NodeProto*> &nodes) const = 0#
Builds the replacement nodes for one match.
Public Members
-
int priority#
Priority used by the optimization driver.
Protected Functions
-
template<std::size_t N>
inline MatchResult NoMatch(const NodeProto &candidate, const char (&reason)[N], std::source_location location = std::source_location::current()) const# Returns an empty match with a rejection reason and its call-site location.
This is the normal result for a candidate that does not satisfy a pattern.
Applyis only called for successful matches; invalid arguments passed directly to it remain contract violations.
Private Functions
-
MatchResult NoMatchImpl(const NodeProto &candidate, std::string_view reason, std::source_location location) const#
-
inline explicit PatternOptimization(int priority = 1, std::string name = {})#
-
struct PatternOptimizationStatistics#
- #include <pattern_optimization.h>
Aggregated timing and activity counters for one optimization pattern.
Public Members
-
int64_t match_time_ns = 0#
Total time spent matching candidates, in nanoseconds.
-
int64_t apply_time_ns = 0#
Total time spent building replacement nodes, in nanoseconds.
-
std::vector<PatternNoMatchStatistics> no_matches = {}#
Rejection conditions aggregated by source location and reason.
-
int64_t match_time_ns = 0#
-
struct SubgraphOptimizationStatistics#
- #include <pattern_optimization.h>
Activity and elapsed time for one recursively optimized subgraph.
-
struct LocalRewriting#
-
namespace builder
-
namespace core