operator_groups.h#

Shared operator-group proposals, ordered interfaces and replacement schedules returned by both transfer-aware partitioning and repeated-layer detection. The common consumer validates interval coverage before constructing functions.

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_NAMESPACE so 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_proto uses hidden visibility by default.

Namespace alias so that ONNX C++ code (and consumers such as onnxruntime) that refers to the literal onnx namespace — rather than the ONNX_NAMESPACE macro — resolves to the onnx-light namespace. The standard onnx package lives in namespace onnx; onnx-light uses onnx_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 from onnx.

namespace core
namespace builder
namespace graph

Enums

enum class OperatorGroupStatus#

Describes why a grouping algorithm accepted or declined a graph.

Values:

enumerator kFound#
enumerator kNoMatch#
enumerator kInsideFunction#
enumerator kIncompatibleOpset#
enumerator kResourceLimit#

Functions

OperatorGroupProposal MakeIntervalGroupProposal(std::vector<OperatorGroup> groups, std::size_t node_count)#

Builds the source-order schedule for disjoint intervals, retaining Constants.

bool IsOperatorGroupAnchor(const NodeProto &node, const builder::GraphBuilder &builder, std::size_t &work)#

Detects exact attention/MatMul anchors, including bounded local-function traversal. Shares a cumulative work budget across calls; zero starts a fresh search.

std::string MakeOperatorGroupFunctionName(builder::GraphBuilder &source, const utils::RepeatedProtoField<NodeProto> &nodes, const std::string &prefix, std::size_t &suffix)#

Returns prefix_<mainop>_<index>, advancing the caller’s naming counter. Uses the first anchor in source order, or the first operator without anchors. Avoids function, graph-value and registered-operator collisions in ai.rt. Requires ai.rt opset 1 in source; the caller installs the returned name. Throws builder::BuilderError for an empty prefix/body or exhausted indices.

std::vector<OperatorGroupInput> FindCommonOperatorGroupInputs(const builder::GraphGraph &graph, std::span<const OperatorGroup> instances)#

Finds common small constants and Shape producers of corresponding boundary inputs. Requires matching Shape attributes and source-input positions across all instances. Loads deferred payloads only after the small-constant size guard; never specializes overridable graph inputs or loads ownerless external references.

std::vector<std::string> InlineOperatorGroupInputs(GraphProto &body, const OperatorGroup &group, const std::vector<OperatorGroupInput> &producers)#

Internalizes selected producers in dependency order and returns the remaining arguments.

std::string AddOperatorGroupFunction(builder::GraphBuilder &source, GraphProto body, const std::string &prefix, std::size_t &suffix)#

Consumes a closed body to create or reuse a model-local ai.rt function with shared naming.

utils::RepeatedProtoField<NodeProto> MakeOperatorGroupReplacements(builder::GraphGraph &graph, const OperatorGroupProposal &proposal, const std::function<NodeProto(std::size_t)> &make_group)#

Validates a freshly rederived proposal before creating any local functions. Copies untouched nodes with shared tensor storage and delegates each body to make_group. The caller must install the result at proposal.first.

struct OperatorGroup#
#include <operator_groups.h>

Describes a function body through source indices and ordered interfaces.

Public Members

std::vector<std::size_t> node_indices#
std::vector<std::string> inputs#

Source-boundary inputs, before optional constant/Shape internalization.

std::vector<std::string> outputs#
std::optional<uint64_t> transfer_bytes#

Transfer estimate when reported by the proposing algorithm.

class OperatorGroupFunctions#
#include <operator_groups.h>

Caches and indexes normalized definitions for one append-only extraction operation. Binds the source and prefix explicitly; existing definitions and source opsets must remain unchanged while the cache is used. Tensor payloads remain shared.

Public Functions

OperatorGroupFunctions(builder::GraphBuilder &source, std::string prefix)#
std::string Find(const GraphProto &body)#

Returns an equivalent function name, using exact comparisons within hash buckets. Returns an empty string when no safely comparable definition matches.

std::string Add(GraphProto body, std::size_t &suffix)#

Creates or reuses a function and advances suffix only for newly created names.

inline const OperatorGroupFunctionStats &Stats() const noexcept#

Returns cumulative candidate normalization and exact comparison counts.

Private Members

builder::GraphBuilder &source_#
std::string prefix_#
std::size_t indexed_functions_ = 0#
OperatorGroupFunctionStats stats_#
std::unordered_map<std::size_t, std::vector<std::pair<std::string, GraphProto>>> definitions_#
struct OperatorGroupFunctionStats#
#include <operator_groups.h>

Reports candidate-side work performed by a function index.

Public Members

std::size_t candidate_normalizations = 0#
std::size_t exact_comparisons = 0#
struct OperatorGroupInput#
#include <operator_groups.h>

Describes a Constant or Shape producer replacing a formal input.

Public Members

std::size_t input_index#
std::optional<std::size_t> source_input#
NodeProto node#
struct OperatorGroupProposal#
#include <operator_groups.h>

Describes a non-mutating, scheduled operator-group proposal.

Both partitioning and repeated-layer detection return this class. Group node indices are sorted in source order; schedule indices refer either to groups or source nodes. The schedule covers the inclusive [first, last] interval. The proposing algorithm guarantees dependency-safe contraction. Source indices and interfaces are valid only while the source graph is unchanged.

Public Functions

void Validate(std::size_t node_count) const#

Checks bounds, disjoint groups and complete, nonduplicated schedule coverage.

std::vector<const NodeProto*> MatchedNodes(const utils::RepeatedProtoField<NodeProto> &nodes) const#

Returns borrowed nodes covering the validated replacement interval.

Public Members

OperatorGroupStatus status = OperatorGroupStatus::kNoMatch#
std::vector<OperatorGroup> groups#
std::vector<OperatorGroupStep> schedule#
std::size_t first = 0#
std::size_t last = 0#
bool capture_analysis_limited = false#

Reports incomplete repeated-layer capture analysis, even when safe groups were found.

struct OperatorGroupStep#
#include <operator_groups.h>

Selects a proposed group or an untouched source node in replacement order.

Public Members

bool is_group#
std::size_t index#