expect.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 backend_test#
Functions
-
void Expect(const NodeProto &node, const Tensors &inputs, const Tensors &outputs, const std::string &name, const std::vector<OpsetId> &opset_imports, const std::string &producer_name, std::vector<TestCase> ®istry, const std::string &tag = "", const std::vector<TypeSpec> &output_types = {})#
Appends a lazy single-node :ref:
TestCasebuilt fromnodeand the provided typed inputs/outputs toregistry.Mirrors
onnx_light.backend.test.case.base.expect(). Only the inputs and outputs whose name is non-empty in the node are wired into the graph. TheModelProtoand data set are not built at registration time; the givennode/inputs/outputsare captured and :func:BuildSingleNodeCaseis invoked only when the case is materialized (viaTestCase::model/ :func:TestCase::data_sets/ :func:TestCase::Materialize). The declared element counts are recorded eagerly from the input/output tensors so the sizing stays inspectable without materializing.- Parameters:
node – Single-node template; its
op_type,domainandattributes are kept.inputs – Concrete input tensors corresponding to the non-empty entries of
node.input.outputs – Concrete expected output tensors corresponding to the non-empty entries of
node.output.name – Unique test name (used both for
TestCase.nameand the graph name).opset_imports – Opset imports for the generated model. If empty the caller is responsible for ensuring a default has been applied — typically pass at least
DefaultOpset(since_version).producer_name – Producer name written into the model.
registry – Output registry (appended to).
tag – Optional grouping tag (defaults to the node domain for non-default operator domains).
output_types – Optional per-output declared type specs. When non-empty it must contain one entry per output tensor; each output value-info is then declared from its
TypeSpecinstead of the materialized tensor type. Used to declareSequence/Mapvalued outputs whose runtime representation is a plainTensor.
- Throws:
std::invalid_argument – if
inputs.size()does not equal the number of non-empty entries innode.inputor ifoutputs.size()does not equal the number of non-empty entries innode.output, or ifoutput_typesis non-empty and its size does not equaloutputs.size().
-
BuiltCase BuildSingleNodeCase(const NodeProto &node, Tensors inputs, Tensors outputs, const std::string &name, const std::vector<OpsetId> &opset_imports, const std::string &producer_name, const std::vector<TypeSpec> &output_types = {}, std::vector<Map> maps = {})#
Builds a single-node
ModelProtoand its one data set fromnodeand the provided typed inputs/outputs. This is the shared core of both :func:Expectoverloads, invoked on demand when a lazy case is materialized. Only the inputs and outputs whose name is non-empty in the node are wired into the graph.Map-typed graph inputs are supplied via
maps: eachMap::namemust match a non-empty entry innode.input, is declared with amap(key_type, value_type)TypeProto in the graph, and is stored inDataSet::mapsso the runtime can retrieve it by name. The remaining (tensor-typed) inputs come frominputsin positional order. The suminputs.size() + maps.size()must equal the number of non-empty entries innode.input.- Throws:
std::invalid_argument – under the same conditions as :func:
Expect.
-
void Expect(std::vector<TestCase> ®istry, NodeProto node, std::string name, std::vector<OpsetId> opset_imports, std::vector<int64_t> in_counts, std::vector<int64_t> out_counts, std::function<IoData()> make_io, std::string producer_name = "backend-test", std::string tag = "", std::vector<TypeSpec> output_types = {})#
Appends a lazy single-node :ref:
TestCasewhose inputs/outputs are generated on demand bymake_io. Overload of :func:Expectfor cases — chiefly theBENCHMARKcases — whose (potentially very large) inputs and expected outputs are too expensive to materialize at registration time.make_io(which performs the input generation and kernel evaluation) is invoked only when the case is materialized viaTestCase::model/ :func:TestCase::data_sets/ :func:TestCase::Materialize.in_counts/out_countsrecord the declared element count of each input/output so the sizing can be validated without runningmake_io.- Parameters:
registry – Output registry (appended to).
node – Single-node template; its
op_type,domainandattributes are kept. Consumed (moved).name – Unique test name.
opset_imports – Opset imports for the generated model.
in_counts – Declared element count of each (non-empty) input.
out_counts – Declared element count of each (non-empty) output.
make_io – Callable producing the concrete inputs/outputs on demand.
producer_name – Producer name written into the model.
tag – Optional grouping tag (defaults to the node domain for non-default operator domains).
output_types – Optional per-output declared type specs (see :func:
Expect).
-
inline void Expect(std::vector<TestCase> ®istry, NodeProto node, std::string name, std::vector<OpsetId> opset_imports, std::function<IoData()> make_io, std::string producer_name = "backend-test", std::string tag = "", std::vector<TypeSpec> output_types = {})#
Convenience overload of the lazy :func:
Expectthat omits the element-count vectors. Equivalent to calling the six-parameter lazy overload with emptyin_counts/out_counts. Use for small test cases where pre-declaring element counts adds no value over deriving them from the materialised tensors.
-
template<typename Kernel>
void ExpectBenchmarkUnaryFloat(const std::string &op_type, const Kernel &kernel, const std::string &name, const OpsetId &opset, std::vector<TestCase> ®istry, bool with_float16 = true, bool with_bfloat16 = true, int64_t size = kBenchmarkElementwiseSize, uint64_t seed = 987654321ULL, const std::string &input_name = "x", const std::string &output_name = "y")# Appends benchmark :ref:
TestCases for a unary element-wise float operator.kernelis any callable mapping the inputTensorto the outputTensor(typically the operator’s kernel functor); the expected output is computed by invoking it. The generated node carries no attributes, so operators whose behaviour depends on attributes should build their own benchmark case instead.When
with_float16is true (the default) a second FLOAT16 benchmark case namedname + "_float16"is registered alongside the FLOAT one. Operators whose kernel does not support FLOAT16 must passwith_float16 = false.A third BFLOAT16 benchmark case named
name + "_bfloat16"is registered by default alongside the FLOAT and FLOAT16 cases. Operators whose kernel does not support BFLOAT16 must passwith_bfloat16 = false.
-
template<typename Kernel>
void ExpectBenchmarkBinaryFloat(const std::string &op_type, const Kernel &kernel, const std::string &name, const OpsetId &opset, std::vector<TestCase> ®istry, bool with_float16 = true, bool with_bfloat16 = true, int64_t size = kBenchmarkElementwiseSize, uint64_t seed = 987654321ULL)# Appends benchmark :ref:
TestCases for a binary element-wise float operator with two equally-shaped 1-D inputs.kernelis any callable mapping the two inputTensors to the outputTensor; the expected output is computed by invoking it. The generated node carries no attributes. The inputs and expected output are produced lazily (see themake_iooverload of :func:Expect).When
with_float16is true (the default) a second FLOAT16 benchmark case namedname + "_float16"is registered alongside the FLOAT one. Operators whose kernel does not support FLOAT16 must passwith_float16 = false.A third BFLOAT16 benchmark case named
name + "_bfloat16"is registered by default alongside the FLOAT and FLOAT16 cases. Operators whose kernel does not support BFLOAT16 must passwith_bfloat16 = false.
Variables
-
constexpr int64_t kBenchmarkElementwiseSize = 1 << 22#
Default element count for a 1-D float benchmark input of a cheap element-wise operator. Sized (4M floats = 16 MiB) so a single kernel evaluation processes enough data to be timed reliably (~0.1 s). Operators with heavier per-element cost (transcendental, matmul, …) pass a smaller explicit size to the benchmark helpers below.
-
void Expect(const NodeProto &node, const Tensors &inputs, const Tensors &outputs, const std::string &name, const std::vector<OpsetId> &opset_imports, const std::string &producer_name, std::vector<TestCase> ®istry, const std::string &tag = "", const std::vector<TypeSpec> &output_types = {})#
-
namespace backend_test#
-
namespace core#