include_quantization_kernels.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.
Defined as empty because onnx-light does not require explicit
__declspec(dllexport)or__attribute__((visibility("default")))annotations — visibility is controlled at the shared-library level. The macro is provided so that vendored ONNX headers that decorate their declarations withONNX_APIcompile without modification.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 onnx_kernels
-
namespace kernel
-
class DequantizeLinear : public onnx_light::onnx_kernels::kernel::KernelBase#
- #include <include_quantization_kernels.h>
Per-tensor or per-axis linear dequantization of an integer or float8 input
xto a FLOAT outputyusingy = (x - x_zero_point) * x_scale. Whenx_zero_pointis omitted the zero point defaults to 0. Whenx_scalehas more than one element, per-axis dequantization is performed alongaxis(only FLOATx_scaleis supported for per-axis).Public Functions
-
Tensor operator()(const Tensor &x, const Tensor &x_scale) const#
Omitted
x_zero_point: zero point defaults to 0.
-
Tensor operator()(const Tensor &x, const Tensor &x_scale, const Tensor &x_zero_point) const#
Explicit
x_zero_point: must have the same element type asx.
-
void operator()(const Tensor &x, const Tensor &x_scale, const Tensor &x_zero_point, Tensor &output) const#
-
Tensor operator()(const Tensor &x, const Tensor &x_scale, const Tensor &x_zero_point, int64_t axis) const#
Per-axis overloads:
x_scaleandx_zero_pointhave one entry per slice alongaxis. Delegates to the per-tensor overload whenx_scaleis scalar.
-
void operator()(const Tensor &x, const Tensor &x_scale, const Tensor &x_zero_point, int64_t axis, Tensor &output) const#
-
Tensor operator()(const Tensor &x, const Tensor &x_scale, int64_t axis) const#
Per-axis overloads with the
x_zero_pointomitted (defaults to 0). Delegates to the per-tensor overload whenx_scaleis scalar.
-
inline explicit KernelBase(const KernelContext &ctx)#
Public Static Functions
-
static inline constexpr bool CanRunInPlace() noexcept#
Output element type (FLOAT) differs from the integer/float8 input element type, so storage can never be shared with an input.
-
Tensor operator()(const Tensor &x, const Tensor &x_scale) const#
-
class DynamicQuantizeLinear : public onnx_light::onnx_kernels::kernel::KernelBase#
- #include <include_quantization_kernels.h>
Per-tensor dynamic linear quantization of a FLOAT input
xto a UINT8 outputytogether with the derived scalary_scale(FLOAT) and scalary_zero_point(UINT8). Matches the ONNXDynamicQuantizeLinearoperator (opset 11) for the canonical uint8 case:y_scale = (max(0, max(x)) - min(0, min(x))) / 255y_zero_point = saturate(round(-min(0, min(x)) / y_scale))y = saturate(round(x / y_scale) + y_zero_point)Public Functions
-
std::tuple<Tensor, Tensor, Tensor> operator()(const Tensor &x) const#
Returning overload: produces
{y, y_scale, y_zero_point}.
-
void operator()(const Tensor &x, Tensor &y, Tensor &y_scale, Tensor &y_zero_point) const#
In-place overload writing into caller-allocated outputs.
-
inline explicit KernelBase(const KernelContext &ctx)#
Public Static Functions
-
static inline constexpr bool CanRunInPlace() noexcept#
Output element type (UINT8) differs from the FLOAT input element type, so storage can never be shared with the input.
-
std::tuple<Tensor, Tensor, Tensor> operator()(const Tensor &x) const#
-
class QLinearConv : public onnx_light::onnx_kernels::kernel::KernelBase#
- #include <include_quantization_kernels.h>
Reference N-D
QLinearConvkernel for the per-tensor (or per-output-channelw_scale/w_zero_point) case, restricted to INT8/UINT8x,wandyand FLOAT scales. Implementsy = saturate(round(((x - x_zp) * x_scale) * ((w - w_zp) * w_scale) / y_scale + bias * x_scale * w_scale / y_scale) + y_zp)using the standard :cpp:class:Convshape/padding/dilation rules.Public Functions
-
Tensor operator()(const Tensor &x, const Tensor &x_scale, const Tensor &x_zero_point, const Tensor &w, const Tensor &w_scale, const Tensor &w_zero_point, const Tensor &y_scale, const Tensor &y_zero_point, const Tensor &B, const Attributes &attrs) const#
Returning overload.
Bmay be a default-constructed (empty)Tensorto indicate the optional bias is missing.
-
void operator()(const Tensor &x, const Tensor &x_scale, const Tensor &x_zero_point, const Tensor &w, const Tensor &w_scale, const Tensor &w_zero_point, const Tensor &y_scale, const Tensor &y_zero_point, const Tensor &B, const Attributes &attrs, Tensor &output) const#
-
inline explicit KernelBase(const KernelContext &ctx)#
Public Static Functions
-
static inline constexpr bool CanRunInPlace() noexcept#
Output dtype/shape generally differs from any input, so storage cannot be shared.
-
struct Attributes#
- #include <include_quantization_kernels.h>
Attributes carried by the ONNX
QLinearConvoperator.
-
Tensor operator()(const Tensor &x, const Tensor &x_scale, const Tensor &x_zero_point, const Tensor &w, const Tensor &w_scale, const Tensor &w_zero_point, const Tensor &y_scale, const Tensor &y_zero_point, const Tensor &B, const Attributes &attrs) const#
-
class QLinearMatMul : public onnx_light::onnx_kernels::kernel::KernelBase#
- #include <include_quantization_kernels.h>
Reference
QLinearMatMulkernel for the per-tensor (scalar scales and scalar zero-points) case, restricted to INT8/UINT8 inputs and outputs and FLOAT scales. Implementsy = saturate(round(((a - a_zp) * a_scale) * ((b - b_zp) * b_scale) / y_scale) + y_zp). Matrix multiplication follows the standard :cpp:class:MatMulbroadcasting rules.Public Functions
-
Tensor operator()(const Tensor &a, const Tensor &a_scale, const Tensor &a_zero_point, const Tensor &b, const Tensor &b_scale, const Tensor &b_zero_point, const Tensor &y_scale, const Tensor &y_zero_point) const#
Returning overload. Output element type is taken from
y_zero_point.
-
void operator()(const Tensor &a, const Tensor &a_scale, const Tensor &a_zero_point, const Tensor &b, const Tensor &b_scale, const Tensor &b_zero_point, const Tensor &y_scale, const Tensor &y_zero_point, Tensor &output) const#
In-place overload writing into a caller-allocated output.
-
inline explicit KernelBase(const KernelContext &ctx)#
Public Static Functions
-
static inline constexpr bool CanRunInPlace() noexcept#
Output dtype/shape generally differs from any input, so storage cannot be shared.
-
Tensor operator()(const Tensor &a, const Tensor &a_scale, const Tensor &a_zero_point, const Tensor &b, const Tensor &b_scale, const Tensor &b_zero_point, const Tensor &y_scale, const Tensor &y_zero_point) const#
-
class QuantizeLinear : public onnx_light::onnx_kernels::kernel::KernelBase#
- #include <include_quantization_kernels.h>
Per-tensor and per-axis linear quantization of a FLOAT input
xto an integer or sub-byte output. The output element type is taken fromy_zero_point(UINT8, INT8, UINT16, INT16, FLOAT8E4M3FN, FLOAT8E5M2, INT4, UINT4, INT2, UINT2, or FLOAT4E2M1); ify_zero_pointis omitted the output defaults to UINT8 with a zero point of 0.Public Functions
-
Tensor operator()(const Tensor &x, const Tensor &y_scale) const#
Omitted
y_zero_point: output is UINT8 with zero point 0.
-
Tensor operator()(const Tensor &x, const Tensor &y_scale, const Tensor &y_zero_point) const#
Explicit
y_zero_point: its data_type drives the output element type. Per-tensor (scalary_scale) quantization.
-
void operator()(const Tensor &x, const Tensor &y_scale, const Tensor &y_zero_point, Tensor &output) const#
-
Tensor operator()(const Tensor &x, const Tensor &y_scale, const Tensor &y_zero_point, int64_t axis) const#
Per-axis quantization:
y_scale(andy_zero_point) may have one entry per slice alongaxis. Wheny_scale.element_count() == 1the call is forwarded to the scalar overload above.
-
void operator()(const Tensor &x, const Tensor &y_scale, const Tensor &y_zero_point, int64_t axis, Tensor &output) const#
-
Tensor operator()(const Tensor &x, const Tensor &y_scale, int64_t axis, int32_t output_dtype) const#
Per-axis/blocked quantization without explicit
y_zero_point.output_dtypespecifies the output element type; zero point is 0.
-
void operator()(const Tensor &x, const Tensor &y_scale, int64_t axis, int32_t output_dtype, Tensor &output) const#
-
inline explicit KernelBase(const KernelContext &ctx)#
Public Static Functions
-
static inline constexpr bool CanRunInPlace() noexcept#
Output element type differs from the FLOAT input element type, so storage can never be shared with an input.
-
Tensor operator()(const Tensor &x, const Tensor &y_scale) const#
-
class DequantizeLinear : public onnx_light::onnx_kernels::kernel::KernelBase#
-
namespace kernel
-
namespace onnx_kernels