ai.onnx.MatMulInteger
ai.onnx · standard ONNX operator · ONNX opset ≥ 10
Description
Computes an integer matrix product with 8-bit inputs, int32 accumulation, and independently optional zero points that default to 0. The package implements rank-1 dot products, rank-2 products, rank-2/rank-3 broadcasting, rank-3 products, and rank-4-by-rank-4 products. Scalar zero points are supported throughout; b_zero_point additionally supports [N] for rank-2 B and [batch, 1, N] for non-broadcast rank-3 B. Other standard ONNX matmul rank combinations and N-D per-row/per-column zero-point layouts are unsupported.
See the ONNX MatMulInteger spec for the reference semantics.
Inputs
| Name | Upstream name | Logical dtype | Rank | Shape | Description | Presence |
|---|---|---|---|---|---|---|
a |
A |
TA |
— | — | N-dimensional integer matrix A (int8 or uint8). | required |
b |
B |
TB |
— | — | N-dimensional integer matrix B (int8 or uint8). | required |
a_zero_point |
— | TA |
— | — | Optional scalar zero point for A; defaults to 0. Standard N-D per-row layouts are unsupported. | optional |
b_zero_point |
— | TB |
— | — | Optional zero point for B; defaults to 0. Supports a scalar, [N] for rank-2 B, or [batch, 1, N] for non-broadcast rank-3 B; other standard N-D per-column layouts are unsupported. |
optional |
Outputs
| Name | Upstream name | Logical dtype | Rank | Shape | Description | Presence |
|---|---|---|---|---|---|---|
y |
Y |
TY |
derived | ONNX MatMul result of a and b |
int32 matrix product result of A * B. | required |
Type constraints
| Variable | Allowed dtypes |
|---|---|
TA |
uint8, int8 |
TB |
uint8, int8 |
TY |
int32 |
Implementation variants
One implementation is selected per call from the device capabilities, the request shapes and the dtypes; these notes say what each one covers.
sgmat_integer_16x16x16— Experimental16x16x16raw-byte matrix multiplication withint32wraparound and scalar or per-column B zero points. Complete 32- or 64-lane subgroups use the matrix primitive. Other layouts use scalar accumulation.sgmat_integer_16x16x32— Experimental16x16x32raw-byte matrix multiplication withint32wraparound and scalar or per-column B zero points. Complete 32- or 64-lane subgroups use the matrix primitive. Other layouts use scalar accumulation.sgmat_integer_16x8x32— Experimental16x8x32raw-byte matrix multiplication withint32wraparound and scalar or per-column B zero points. Complete 32- or 64-lane subgroups use the matrix primitive. Other layouts use scalar accumulation.sgmat_tiled_i8— Byte-packed 8-bit operands feed the general subgroup-matrix GEMM: a 2 x 2 subgroup grid owns 128 x 128 tiles when that grid fills the device, else 64 x 128 or 64 x 64. Unsigned bytes are bias-shifted and zero points folded exactly through row and column byte sums.sgmat_tiled_i8_a_cols,sgmat_tiled_i8_b_rows,sgmat_tiled_i8_a_cols_b_rows— Integer subgroup-matrix GEMM for signed operands without zero points that stages A by columns, B by rows, or both, instead of along K. Not used by default.sgmat_precast_f16— A first pass converts each byte minus its zero point to an exact f16 value once; the subgroup matrices then load these directly, accumulating in f32. Row groups follow matrix geometry, output rows, invocation limits and workgroup storage; bounded partial sums retain exact modular int32 arithmetic.portable_precast_f16— A first pass converts each byte minus its zero point to an exact f16 value; a vector workgroup GEMM then runs with exact bounded f32 partials and modular int32 totals. Geometry follows output rows, invocation and storage limits; f32 storage requires enough row reuse to amortize preparation.sgmat_precast— A first pass converts each byte minus its zero point to an exact f32 value once; the subgroup matrices then load these directly, accumulating in f32. Row groups follow matrix geometry, output rows, invocation limits and workgroup storage; bounded partial sums retain exact modular int32 arithmetic.portable_precast— A first pass converts each byte minus its zero point to an exact f32 value; a vector workgroup GEMM then runs with exact bounded f32 partials and modular int32 totals. Geometry follows output rows, invocation and storage limits; f32 storage requires enough row reuse to amortize preparation.sgmat_exact— Exact integer products through bounded f32 subgroup-matrix partials accumulated with modular int32 additions. Tile height follows workgroup memory and invocation limits.dp4a_rank2_b_zero_point_per_column— Packed-dot rank-2 matmul with per-column B zero points. Large prefill tiles use twice as many output-column lanes on variable 16–32-lane devices with sufficient workgroup capacity.dp4a_rank2_packed_b,dp4a_rank2_b_zero_point_per_column_packed_b— Packed integer dot products with reusable column weights and exact zero-point correction.
Device requirements
Some implementation variants require subgroup-matrix, shader-f16, and subgroups. Other variants run without them; which variant runs also depends on the request's shapes and dtypes.
Files
metadata.json— kernel metadata (id, file digests, manifest spec, provenance)manifest.json— the op contract (source of truth)test.json— correctness casesbench.json— benchmark casesinteger-pack-columns.wgsl.jinjainteger-pack-rows.wgsl.jinjamatmul-integer-batched.wgsl.jinjamatrix-shaped-integer-gemm.wgsl.jinjapack-b.wgsl.jinjaquant-dp4a-matmul.wgsl.jinjaquant-exact-matrix.wgsl.jinjaquant-exact-portable.wgsl.jinjaquant-exact-prepare.wgsl.jinjaquant-matmul-accumulate-rank2.wgsl.jinjaquant-matmul-accumulate-rank4.wgsl.jinjasubgroup-matrix-gemm.wgsl.jinja
Use with @huggingface/kernels
npm install --save-exact @huggingface/kernels@0.0.1-preview.4
Paste the example into a browser app that resolves npm imports. Serve the app over HTTPS or localhost with WebGPU available.
Required output shapes and logical data types are inferred from the supplied inputs and attributes; result tensors are allocated automatically.
The version: 1 option selects the published kernel contract; it is independent of any operator opset, contrib since_version, or model version.
It follows the v1 branch as fixes land. To pin exact artifact bytes, pass a 40-character commit revision instead of version.
import { getKernel } from "@huggingface/kernels";
const kernel = await getKernel("webgpu-kernels/ai.onnx.MatMulInteger", { version: 1 });
const aData = Uint8Array.of(11);
const bData = Uint8Array.of(13);
const { y } = await kernel({ a: { data: aData, shape: [1, 1] }, b: { data: bData, shape: [1, 1] } });
console.log({ y });
- Downloads last month
- -
Requires WebGPU support. See the compatibility table.