ai.onnx.Gemm
ai.onnx · standard ONNX operator · ONNX opset ≥ 13
Description
Computes Y = alpha * A' * B' + beta * C, where A' and B' are optionally transposed views of the 2-D input matrices A and B, and C is an optional bias broadcastable to shape (M, N). Output Y has shape (M, N).
See the ONNX Gemm spec for the reference semantics.
Inputs
| Name | Bind key | Logical dtype | Rank | Shape | Description | Presence |
|---|---|---|---|---|---|---|
A |
a |
T |
2 |
— | Input matrix A with shape (M, K) when transA is 0, or (K, M) when transA is non-zero. |
required |
B |
b |
T |
2 |
— | Input matrix B with shape (K, N) when transB is 0, or (N, K) when transB is non-zero. |
required |
C |
bias |
T |
— | — | Optional bias tensor broadcastable to (M, N); treated as scalar 0 if absent. |
optional |
Outputs
| Name | Bind key | Logical dtype | Rank | Shape | Description | Presence |
|---|---|---|---|---|---|---|
Y |
y |
T |
2 |
derived; see description | Output matrix of shape (M, N). |
required |
Runtime arguments
| Name | Kind | Semantic | Description | Presence |
|---|---|---|---|---|
M |
u32 |
M |
Optional output-row count for the packed model-layout route; inferred from A for the standard matrix route. |
optional |
inFeatures |
u32 |
K |
Optional reduction dimension for the packed model-layout route; inferred from A and B for the standard matrix route. |
optional |
outFeatures |
u32 |
N |
Optional output-column count for the packed model-layout route; inferred from B for the standard matrix route. |
optional |
Attributes
Default values (overridable per request):
| Attribute | Default | Description |
|---|---|---|
alpha |
1 |
Scalar multiplier applied to the matrix product A' * B'. |
beta |
1 |
Scalar multiplier applied to the optional bias tensor C. |
transA |
0 |
When non-zero, A is transposed before the multiplication. |
transB |
0 |
When non-zero, B is transposed before the multiplication. |
Type constraints
| Variable | Allowed dtypes |
|---|---|
T |
float32, float16 |
Device requirements
Some implementation variants require subgroup-matrix, shader-f16, and subgroups. These are route-specific capabilities, not package-wide requirements; availability also depends on the request shape and dtype.
Files
metadata.json— kernel metadata (id, digests, provenance)manifest.json— the op contract (source of truth)test.json— correctness casesbench.json— benchmark + tuning casesdense-tiled-matmul.wgsl.jinjagemm-dense-f32-tiled-reg.wgsl.jinjagemm-generic-tiled-reg.wgsl.jinjagemm-model-m1-vec4.wgsl.jinjagemm-subgroup-matrix.wgsl.jinjagemm-transa-tail-correction.wgsl.jinjagemm.model.wgsl.jinjagemm.wgsl.jinjamatmul-notrans-vec4-tiled-reg.wgsl.jinjareduce-axis0-splitk-combine.wgsl.jinja
Use with @huggingface/kernels
The loader derives every required output's shape and logical dtype from the manifest contract and this call. It then allocates the result tensors automatically.
The version: 1 option selects the published kernel contract; it is independent of any operator opset, contrib since_version, or model version.
Replace each *Data placeholder with a typed array containing the corresponding input data.
import { getKernel } from "@huggingface/kernels";
const kernel = await getKernel("webgpu-kernels/ai.onnx.Gemm", { version: 1 });
const { y } = await kernel({ a: { data: aData, shape: [2, 4] }, b: { data: bData, shape: [4, 3] } });
- Downloads last month
- -
Requires WebGPU support. See the compatibility table.