dim_sum.h#

Helpers to sum many symbolic dimension expressions cheaply.

onnx_light::core::expressions::simplify_expression is super-linear in the number of additive terms it receives, so repeatedly simplifying an ever-growing sum (as happens when profiling large graphs) dominates the cost. :cpp:class:DimSum collapses byte-identical terms into coeff*(term) before simplifying, feeding the simplifier only as many terms as there are distinct expressions while producing a byte-identical result.

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 expressions#

Typedefs

using SimplifiedExpressionCache = std::unordered_map<std::string, DimType>#

Memoization cache mapping a symbolic expression string to its simplified form, shared across simplifications to avoid re-running the symbolic simplifier on the same expression.

Functions

DimType simplify_dim_type(const DimType &value, SimplifiedExpressionCache *cache = nullptr)#

Returns value unchanged when it is already a concrete integer, otherwise the canonical simplified form of the symbolic expression it holds (memoized in cache when provided).

class DimSum#
#include <dim_sum.h>

Accumulates symbolic dimension expressions, grouping identical terms.

Successive :cpp:func:Add calls bucket concrete integers into a running constant and identical symbolic expressions into integer coefficients. :cpp:func:Build emits the packed constant + c1*(expr1) + c2*(expr2) ... expression and simplifies it once. The result is byte-identical to summing and simplifying each term individually, but the simplifier only ever sees the distinct terms.

Public Functions

void Add(const DimType &term)#

Adds a single term to the running sum.

DimType Build(SimplifiedExpressionCache *cache = nullptr) const#

Returns the simplified sum of every added term (0 when empty).

Private Members

int64_t constant_ = 0#
std::map<std::string, int64_t> coefficients_#