File size: 4,912 Bytes
3aadfb1 02e3be6 3aadfb1 02e3be6 3aadfb1 02e3be6 3aadfb1 02e3be6 fe69102 3aadfb1 02e3be6 fe69102 3aadfb1 02e3be6 3aadfb1 fe69102 3aadfb1 02e3be6 3aadfb1 02e3be6 3aadfb1 fe69102 3aadfb1 02e3be6 3aadfb1 fe69102 02e3be6 3aadfb1 fe69102 3aadfb1 fe69102 3aadfb1 fe69102 02e3be6 3aadfb1 fe69102 3aadfb1 fe69102 3aadfb1 fe69102 02e3be6 3aadfb1 | 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 | {
"domain": "com.microsoft",
"name": "FastGelu",
"sinceVersion": 1,
"inputs": { "X": { "dtype": "T" }, "bias": { "dtype": "T", "rank": 1, "optional": true } },
"outputs": { "Y": { "dtype": "T", "rank": "ranks.X", "shape": "shapes.X" } },
"typeConstraints": { "T": ["float32", "float16"] },
"tunables": { "WORKGROUP_SIZE": { "default": 256 } },
"derive": {
"deviceWorkgroupCap": "min(device.limits.maxComputeInvocationsPerWorkgroup, device.limits.maxComputeWorkgroupSizeX)",
"storageBufferLimit": "min(device.limits.maxStorageBufferBindingSize, device.limits.maxBufferSize)",
"workgroupSize": "min(tunables.WORKGROUP_SIZE, deviceWorkgroupCap)",
"buffersFit": "numel(shapes.X) * dtypeBytes(dtypes.T) <= storageBufferLimit and numel(shapes.Y) * dtypeBytes(dtypes.T) <= storageBufferLimit and (not present.bias or numel(shapes.bias) * dtypeBytes(dtypes.T) <= storageBufferLimit)",
"dispatchFits": "numel(shapes.X) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) * min(device.limits.maxComputeWorkgroupsPerDimension, 65535) * workgroupSize * 4",
"baseOk": "workgroupSize > 0 and ranks.X >= 1 and numel(shapes.X) == numel(shapes.Y) and f16Ok(dtypes.T) and buffersFit and dispatchFits",
"biasOk": "present.bias and ranks.bias == 1 and dim(shapes.bias, 0) == dim(shapes.X, ranks.X - 1)",
"noBiasOk": "not present.bias",
"vec4Ok": "numel(shapes.X) > 0 and numel(shapes.X) % 4 == 0 and dim(shapes.X, ranks.X - 1) % 4 == 0",
"scalar": "dtypes.T"
},
"when": ["baseOk"],
"bindings": {
"x": { "arg": "X", "elementType": "$vectorScalar" },
"y": { "arg": "Y", "elementType": "$vectorScalar" },
"params": { "struct": [{ "name": "count", "type": "u32", "value": "numel(shapes.X) / 4" }] },
"x_x": { "arg": "X", "name": "x", "elementType": "$scalar" },
"y_y": { "arg": "Y", "name": "y", "elementType": "$scalar" },
"params_main": { "name": "params", "struct": [{ "name": "count", "type": "u32", "value": "numel(shapes.X)" }] }
},
"variants": [
{
"id": "vec4_bias",
"priority": 30,
"when": ["biasOk", "vec4Ok"],
"derive": {
"vec4": true,
"vec4Tail": false,
"hasBias": true,
"vectorScalar": "\"vec4<\" ~ dtypes.T ~ \">\"",
"hidden": "dim(shapes.X, ranks.X - 1) if dim(shapes.X, ranks.X - 1) > 0 else 1"
},
"passes": [
{
"id": "main",
"name": "FastGelu.Vec4Bias",
"shader": "elementwise-bias-gelu.wgsl.jinja",
"bindings": ["x", { "arg": "bias", "elementType": "$scalar", "length": "$hidden" }, "y", "params"],
"dispatch": {
"x": "min(ceilDiv((numel(shapes.X) / 4), (workgroupSize)), 65535)",
"y": "ceilDiv(ceilDiv((numel(shapes.X) / 4), (workgroupSize)), 65535)",
"z": 1
}
}
]
},
{
"id": "vec4_no_bias",
"priority": 25,
"when": ["noBiasOk", "vec4Ok"],
"derive": { "vec4": true, "vec4Tail": false, "hasBias": false, "vectorScalar": "\"vec4<\" ~ dtypes.T ~ \">\"" },
"passes": [
{
"id": "main",
"name": "FastGelu.Vec4",
"shader": "elementwise-bias-gelu.wgsl.jinja",
"bindings": ["x", "y", "params"],
"dispatch": {
"x": "min(ceilDiv((numel(shapes.X) / 4), (workgroupSize)), 65535)",
"y": "ceilDiv(ceilDiv((numel(shapes.X) / 4), (workgroupSize)), 65535)",
"z": 1
}
}
]
},
{
"id": "vec4_tail_bias",
"priority": 20,
"when": ["biasOk"],
"derive": {
"vec4": false,
"vec4Tail": "numel(shapes.X) > 0",
"hasBias": true,
"hidden": "dim(shapes.X, ranks.X - 1) if dim(shapes.X, ranks.X - 1) > 0 else 1"
},
"passes": [
{
"id": "main",
"name": "FastGelu.Vec4TailBias",
"shader": "elementwise-bias-gelu.wgsl.jinja",
"bindings": ["x_x", "bias", "y_y", "params_main"],
"dispatch": {
"x": "min(ceilDiv((ceilDiv(numel(shapes.X), 4)), (workgroupSize)), 65535)",
"y": "ceilDiv(ceilDiv((ceilDiv(numel(shapes.X), 4)), (workgroupSize)), 65535)",
"z": 1
}
}
]
},
{
"id": "vec4_tail_no_bias",
"priority": 15,
"when": ["noBiasOk"],
"derive": { "vec4": false, "vec4Tail": "numel(shapes.X) > 0", "hasBias": false },
"passes": [
{
"id": "main",
"name": "FastGelu.Vec4Tail",
"shader": "elementwise-bias-gelu.wgsl.jinja",
"bindings": ["x_x", "y_y", "params_main"],
"dispatch": {
"x": "min(ceilDiv((ceilDiv(numel(shapes.X), 4)), (workgroupSize)), 65535)",
"y": "ceilDiv(ceilDiv((ceilDiv(numel(shapes.X), 4)), (workgroupSize)), 65535)",
"z": 1
}
}
]
}
]
}
|