elementwise_helpers.h#

namespace ONNX_LIGHT_NAMESPACE
namespace onnx_backend_test
namespace kernel#
namespace detail#

Functions

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_dtype and that their shapes are equal or broadcastable via scalar broadcasting (one side has a single element). Throws std::invalid_argument otherwise.

void CheckPreallocatedOutput(const char *op_name, const char *dtype_name, int32_t expected_dtype, const std::vector<int64_t> &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)#

In-place element-wise binary kernel driver. Validates inputs + output then invokes op(a, b) -> TOut for each element pair (with scalar broadcasting). TIn and TOut must match the byte layout of the expected_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)#

Allocating element-wise binary kernel driver. Builds the output tensor with the broadcasted shape and expected_dtype, then delegates to :cpp:func:BinaryElementwise to fill it in.

struct BroadcastInfo#
#include <elementwise_helpers.h>

Information about a validated binary broadcast: the output shape, total element count, and the individual input element counts (used by the loop to apply scalar broadcasting).

Public Members

std::vector<int64_t> shape#
int64_t element_count = 0#
int64_t nx = 0#
int64_t ny = 0#