File size: 5,266 Bytes
a44211c 504ada0 a44211c 504ada0 a44211c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | {
"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" }
}
]
}
]
}
|