| { |
| "domain": "com.microsoft", |
| "name": "BiasAdd", |
| "sinceVersion": 1, |
| "description": "Adds a 1-D `bias` (broadcast over the channel dimension) to input `X`, then adds the residual tensor `skip` elementwise. All three tensors share the same channel count `C`; `X` and `skip` have shape `(N, S, C)`.", |
| "inputs": [ |
| { |
| "role": "X", |
| "dtype": "T", |
| "rank": 3, |
| "description": "Input tensor of shape `(N, S, C)`: batch size `N`, spatial size `S`, and `C` channels." |
| }, |
| { |
| "role": "bias", |
| "dtype": "T", |
| "rank": 1, |
| "description": "1-D bias vector of length C, broadcast-added along the channel dimension." |
| }, |
| { |
| "role": "skip", |
| "dtype": "T", |
| "rank": 3, |
| "description": "Residual tensor with the same `(N, S, C)` shape as `X`, added after the bias." |
| } |
| ], |
| "outputs": [ |
| { |
| "role": "Y", |
| "dtype": "T", |
| "rank": 3, |
| "shape": "shapes.X", |
| "description": "Output tensor of shape `(N, S, C)`: the elementwise sum `X + bias + skip`." |
| } |
| ], |
| "typeConstraints": { "T": ["float32", "float16"] }, |
| "args": { |
| "X": { "kind": "tensor", "semantic": "X", "role": "input" }, |
| "bias": { "kind": "tensor", "semantic": "bias", "role": "input" }, |
| "skip": { "kind": "tensor", "semantic": "skip", "role": "input" }, |
| "Y": { "kind": "tensor", "semantic": "Y", "role": "output" } |
| }, |
| "tunables": { "WORKGROUP_SIZE": 256 }, |
| "constants": { |
| "scalar": "dtypes.T", |
| "usesF16": "dtypes.T == \"f16\"", |
| "hidden": "dim(shapes.X, ranks.X - 1) if dim(shapes.X, ranks.X - 1) > 0 else 1" |
| }, |
| "variants": [ |
| { |
| "id": "vec4", |
| "priority": 30, |
| "when": ["ranks.X == 3", "ranks.skip == 3", "ranks.Y == 3", "sameShape(shapes.X, shapes.skip)", "sameShape(shapes.X, shapes.Y)", "f16Ok(dtypes.T)", "ranks.bias == 1", "dim(shapes.bias, 0) == dim(shapes.X, 2)", "numel(shapes.X) > 0", "numel(shapes.X) % 4 == 0", "dim(shapes.X, 2) % 4 == 0"], |
| "constants": { "vec4": true, "vectorScalar": "\"vec4<\" ~ dtypes.T ~ \">\"" }, |
| "passes": [ |
| { |
| "id": "main", |
| "name": "BiasAdd.vec4", |
| "shader": "bias-add.wgsl.jinja", |
| "bindings": [ |
| { |
| "name": "x", |
| "arg": "X", |
| "semantic": "X", |
| "buffer": { "type": "read-only-storage" }, |
| "elementType": "$scalar" |
| }, |
| { |
| "name": "bias", |
| "arg": "bias", |
| "semantic": "bias", |
| "buffer": { "type": "read-only-storage" }, |
| "elementType": "$scalar", |
| "length": "$hidden" |
| }, |
| { |
| "name": "skip", |
| "arg": "skip", |
| "semantic": "skip", |
| "buffer": { "type": "read-only-storage" }, |
| "elementType": "$scalar" |
| }, |
| { |
| "name": "y", |
| "arg": "Y", |
| "semantic": "Y", |
| "buffer": { "type": "storage" }, |
| "elementType": "$vectorScalar" |
| }, |
| { |
| "name": "params", |
| "semantic": "kernel.params", |
| "buffer": { "type": "uniform" }, |
| "struct": { |
| "name": "Params", |
| "fields": [{ "name": "count", "type": "u32", "value": "numel(shapes.X) / 4" }] |
| } |
| } |
| ], |
| "dispatch": { "threads": "numel(shapes.X) / 4", "workgroupSize": "tunables.WORKGROUP_SIZE" } |
| } |
| ] |
| }, |
| { |
| "id": "scalar", |
| "priority": 0, |
| "when": ["ranks.X == 3", "ranks.skip == 3", "ranks.Y == 3", "sameShape(shapes.X, shapes.skip)", "sameShape(shapes.X, shapes.Y)", "f16Ok(dtypes.T)", "ranks.bias == 1", "dim(shapes.bias, 0) == dim(shapes.X, 2)"], |
| "constants": { "vec4": false }, |
| "passes": [ |
| { |
| "id": "main", |
| "name": "BiasAdd.scalar", |
| "shader": "bias-add.wgsl.jinja", |
| "source": { "inputs": { "itemsPerInvocation": 4 } }, |
| "bindings": [ |
| { |
| "name": "x", |
| "arg": "X", |
| "semantic": "X", |
| "buffer": { "type": "read-only-storage" }, |
| "elementType": "$scalar" |
| }, |
| { |
| "name": "bias", |
| "arg": "bias", |
| "semantic": "bias", |
| "buffer": { "type": "read-only-storage" }, |
| "elementType": "$scalar" |
| }, |
| { |
| "name": "skip", |
| "arg": "skip", |
| "semantic": "skip", |
| "buffer": { "type": "read-only-storage" }, |
| "elementType": "$scalar" |
| }, |
| { "name": "y", "arg": "Y", "semantic": "Y", "buffer": { "type": "storage" }, "elementType": "$scalar" }, |
| { |
| "name": "params", |
| "semantic": "kernel.params", |
| "buffer": { "type": "uniform" }, |
| "struct": { "name": "Params", "fields": [{ "name": "count", "type": "u32", "value": "numel(shapes.X)" }] } |
| } |
| ], |
| "dispatch": { "threads": "ceilDiv(numel(shapes.X), 4)", "workgroupSize": "tunables.WORKGROUP_SIZE" } |
| } |
| ] |
| } |
| ] |
| } |
|
|