elementwise_helpers.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 runtime
-
namespace detail#
-
Functions
-
Shape BroadcastShape(const char *op_name, const Shape &a, const Shape &b)#
Returns the multidirectional-broadcast output shape of
aandb. Throwsstd::invalid_argumentwith a message prefixed byop_namewhen the shapes are not broadcastable.
-
BroadcastInfo CheckBinaryBroadcast(const char *op_name, const char *dtype_name, int32_t expected_dtype, const Tensor &x, const Tensor &y)#
Verifies both inputs have
expected_dtypeand that their shapes are multidirectional-broadcastable per the standard NumPy/ONNX rules. Throwsstd::invalid_argumentotherwise.
-
BroadcastInfo CheckBinaryBroadcastInOut(const char *op_name, const char *in_dtype_name, int32_t expected_in_dtype, const Tensor &x, const Tensor &y)#
Variant of :cpp:func:
CheckBinaryBroadcastfor kernels whose input and output dtypes differ (e.g.Greater/Lesstake numeric inputs and returnBOOLoutputs). Validates that both inputs haveexpected_in_dtypeand computes the broadcast info; the caller is responsible for validating the output against its own dtype.
-
void CheckPreallocatedOutput(const char *op_name, const char *dtype_name, int32_t expected_dtype, const Shape &expected_shape, size_t expected_bytes, const Tensor &output)#
Verifies the caller-supplied preallocated output tensor matches the expected dtype, shape and byte buffer size.
-
template<typename TIn, typename TOut, typename Op>
void BinaryElementwise(const char *op_name, const char *dtype_name, int32_t expected_dtype, const Tensor &x, const Tensor &y, Tensor &output, Op op, int64_t parallel_minimum_elements = std::numeric_limits<int64_t>::max())# In-place element-wise binary kernel driver. Validates inputs + output then invokes
op(a, b) -> TOutfor each element pair, with full multidirectional broadcasting.TInandTOutmust match the byte layout of theexpected_dtype.
-
template<typename TIn, typename TOut, typename Op>
Tensor BinaryElementwiseAlloc(const char *op_name, const char *dtype_name, int32_t expected_dtype, const Tensor &x, const Tensor &y, Op op, RawBufferAllocator *allocator = nullptr, int64_t parallel_minimum_elements = std::numeric_limits<int64_t>::max())# Allocating element-wise binary kernel driver. Builds the output tensor with the broadcasted shape and
expected_dtype, then delegates to :cpp:func:BinaryElementwiseto fill it in.When
allocatoris non-null the output buffer is acquired from it directly, so no copy is needed later when the tensor is stored in a :cpp:class:RuntimeContext. Passnullptr(or omit the argument) to fall back to the legacy inline-allocation path.
-
template<typename TIn, typename TOut, typename Op>
void BinaryElementwiseInOut(const char *op_name, const char *in_dtype_name, int32_t in_dtype, const char *out_dtype_name, int32_t out_dtype, const Tensor &x, const Tensor &y, Tensor &output, Op op, int64_t parallel_minimum_elements = std::numeric_limits<int64_t>::max())# Variant of :cpp:func:
BinaryElementwisefor kernels whose input and output dtypes differ (e.g.Greater/Less). Validates that both inputs havein_dtypeand that the preallocated output hasout_dtypeand the broadcasted shape, then invokesop(a, b) -> TOutfor each element pair with full multidirectional broadcasting.
-
template<typename TIn, typename TOut, typename Op>
Tensor BinaryElementwiseAllocInOut(const char *op_name, const char *in_dtype_name, int32_t in_dtype, const char *out_dtype_name, int32_t out_dtype, const Tensor &x, const Tensor &y, Op op, RawBufferAllocator *allocator = nullptr, int64_t parallel_minimum_elements = std::numeric_limits<int64_t>::max())# Allocating variant of :cpp:func:
BinaryElementwiseInOut. Builds the output tensor with the broadcasted shape andout_dtype, then delegates to :cpp:func:BinaryElementwiseInOutto fill it in.When
allocatoris non-null the output buffer is acquired from it directly. Passnullptr(or omit the argument) to use inline allocation.
-
template<typename Op>
void BinaryHalfElementwise(const char *op_name, const char *dtype_name, int32_t dtype, const Tensor &x, const Tensor &y, Tensor &output, HalfDecodeFunc decode, HalfEncodeFunc encode, Op op, int64_t parallel_minimum_elements = std::numeric_limits<int64_t>::max())# In-place half-precision binary element-wise kernel.
-
template<typename Op>
Tensor BinaryHalfElementwiseAlloc(const char *op_name, const char *dtype_name, int32_t dtype, const Tensor &x, const Tensor &y, HalfDecodeFunc decode, HalfEncodeFunc encode, Op op, RawBufferAllocator *allocator = nullptr, int64_t parallel_minimum_elements = std::numeric_limits<int64_t>::max())# Allocating half-precision binary element-wise kernel.
When
allocatoris non-null the output buffer is acquired from it directly. Passnullptr(or omit the argument) to use inline allocation.
-
template<typename TOut, typename Op>
void BinaryHalfElementwiseInOut(const char *op_name, const char *in_dtype_name, int32_t in_dtype, const char *out_dtype_name, int32_t out_dtype, const Tensor &x, const Tensor &y, Tensor &output, HalfDecodeFunc decode, Op op)# In-place half-precision binary kernel for FLOAT16/BFLOAT16 inputs and a distinct POD output dtype (for example BOOL in comparison operators).
-
template<typename TOut, typename Op>
Tensor BinaryHalfElementwiseAllocInOut(const char *op_name, const char *in_dtype_name, int32_t in_dtype, const char *out_dtype_name, int32_t out_dtype, const Tensor &x, const Tensor &y, HalfDecodeFunc decode, Op op, RawBufferAllocator *allocator = nullptr)# Allocating variant of :cpp:func:
BinaryHalfElementwiseInOut.When
allocatoris non-null the output buffer is acquired from it directly. Passnullptr(or omit the argument) to use inline allocation.
-
template<typename Op>
void UnaryHalfElementwise(const Tensor &x, Tensor &output, HalfDecodeFunc decode, HalfEncodeFunc encode, int64_t grain_size, Op op)# Unary half-precision element-wise kernel (single-pass, no allocation).
-
template<typename Op>
void UnaryHalfElementwise(const Tensor &x, Tensor &output, HalfDecodeFunc decode, HalfEncodeFunc encode, Op op)# Unary half-precision element-wise kernel using the default parallel grain.
-
template<typename Op>
void BinaryHalfCompareElementwise(const char *op_name, const char *dtype_name, int32_t dtype, const Tensor &x, const Tensor &y, Tensor &output, HalfDecodeFunc decode, Op op, int64_t parallel_minimum_elements = std::numeric_limits<int64_t>::max())# In-place half-precision binary comparison kernel (decode→compare→BOOL).
-
template<typename Op>
Tensor BinaryHalfCompareElementwiseAlloc(const char *op_name, const char *dtype_name, int32_t dtype, const Tensor &x, const Tensor &y, HalfDecodeFunc decode, Op op, RawBufferAllocator *allocator = nullptr, int64_t parallel_minimum_elements = std::numeric_limits<int64_t>::max())# Allocating half-precision binary comparison kernel (decode→compare→BOOL).
When
allocatoris non-null the output buffer is acquired from it directly. Passnullptr(or omit the argument) to use inline allocation.
-
struct BroadcastInfo#
- #include <elementwise_helpers.h>
Information about a validated binary broadcast: the output shape, total element count, the individual input element counts, and per-input element-strides aligned to the output rank (a stride of 0 marks a broadcast dimension). The rank-aligned
shape_x/shape_yare also reported for diagnostics.nx/nyare kept for fast-path detection (equal-shape or scalar broadcasting).
-
Shape BroadcastShape(const char *op_name, const Shape &a, const Shape &b)#
-
namespace detail#
-
namespace runtime
-
namespace core