Skip to content

C++ interfaces and Python comparison API

Engine construction, saving and reuse, execution, and plugin registration use the C++ SDK. The model package calls these interfaces directly and exposes inference through its own binding. Follow the user guide and separate consumer wheel for integration.

Public C++ headers

The installed SDK is under tensoracle/cpp in the wheel. Use find_package(tensoracle 2 CONFIG REQUIRED) and link tensoracle::tensoracle.

C ABI header C++ wrapper Operations
tensoracle/tensoracle.h tensoracle/tensoracle.hpp Version checks, status and owned diagnostics, CPU output comparison
tensoracle/builder.h tensoracle/builder.hpp Open and own safetensors with tensoracle::open_weights, read tensors and file metadata, network callback, input profiles, I/O checks, tensoracle::open_engine
tensoracle/engine.h tensoracle/engine.hpp Engine handles, execution units, scratch size and caller-owned scratch memory, input shapes, tensor metadata, enqueue on a caller stream
tensoracle/plugins.h tensoracle/plugins.hpp Library inspection and process-lifetime registration with tensoracle::register_libraries
tensoracle/cache.h tensoracle/cache.hpp List saved engines, plan pruning, and apply pruning
tensoracle/cubin.h tensoracle/cubin.hpp Compile CUDA C++ kernels and inspect bundles or wheels

tensoracle/cubin_plugin.hpp supplies the source-based TensorRT plugin helper. The plugin build guide describes its CMake functions and source files.

The C boundary uses opaque handles, struct_size fields, status values, and owned diagnostics. Initialize each structure's struct_size to the size actually supplied. Destroy error handles with tensoracle_error_destroy; diagnostic text is borrowed until destruction. No C++ exception crosses this boundary. The header-only C++ wrappers release handles automatically and throw tensoracle::error, whose status() preserves the C status.

Python utilities

Only OutputComparison and compare_outputs are exported directly from tensoracle. Other Python operations live in tensoracle.producer, tensoracle.bundle, and tensoracle.convert, or the tensoracle cache commands. They wrap C++ operations except for checkpoint conversion, which uses torch. See Migrate from 1.x for removed Python names and their C++ replacements.

Output comparison

The caller runs inference and passes CPU NumPy candidate and reference arrays to the comparison function. The application chooses quality limits; this function does not run an engine or make an acceptance decision.

OutputComparison dataclass

Measurements for a candidate output against its reference output.

Float measurements are None for integer or boolean arrays and when either float array contains a non-finite value. Tolerance measurements are also None when the caller has not supplied both tolerances. Mismatch measurements apply only to integer and boolean arrays.

candidate_nonfinite_count instance-attribute

reference_nonfinite_count instance-attribute

max_absolute_error = None class-attribute instance-attribute

relative_l2_error = None class-attribute instance-attribute

cosine_similarity = None class-attribute instance-attribute

outside_tolerance_count = None class-attribute instance-attribute

outside_tolerance_fraction = None class-attribute instance-attribute

mismatch_count = None class-attribute instance-attribute

mismatch_fraction = None class-attribute instance-attribute

__init__(candidate_nonfinite_count, reference_nonfinite_count, max_absolute_error=None, relative_l2_error=None, cosine_similarity=None, outside_tolerance_count=None, outside_tolerance_fraction=None, mismatch_count=None, mismatch_fraction=None)

compare_outputs(candidate, reference, *, atol=None, rtol=None)

Measure one candidate output against the corresponding reference output.

Both inputs must be nonempty NumPy arrays of equal shape and the same kind: floating point, integer, or boolean. Floating point inputs are converted to float64 before arithmetic. Tolerances must be finite, nonnegative, and supplied together. This function reports measurements; the caller chooses the limits that constitute an acceptable output.