sync 4385228f788d
Browse filesFiles changed (5)
37 unmodified lines383940414243444546474849505152535455565758596061626364656667686937 unmodified lines## Files- [`metadata.json`](build/webgpu/metadata.json) — kernel metadata (id, digests, per-variant templates, provenance)- [`manifest.json`](build/webgpu/manifest.json) — the op contract (source of truth)- [`test.json`](build/webgpu/test.json) — correctness cases- [`bench.json`](build/webgpu/bench.json) — benchmark cases- [`gated-add.wgsl.jinja`](build/webgpu/gated-add.wgsl.jinja)## Use with `@huggingface/kernels````shnpm install --save-exact @huggingface/kernels@0.0.1-preview.3```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`.Replace each `*Data` placeholder with a typed array containing the corresponding input data.```jsimport { getKernel } from "@huggingface/kernels";const kernel = await getKernel("webgpu-kernels/com.microsoft.GatedAdd", { version: 1 });const { output } = await kernel({X: { data: XData, shape: [2, 3] },Y: { data: YData, shape: [2, 3] },gate: { data: gateData, shape: [2, 1] },});```37 unmodified lines383940414243444546474849505152535455565758596061626364656667686970717273747537 unmodified lines## Files- [`metadata.json`](https://huggingface.co/kernels/webgpu-kernels/com.microsoft.GatedAdd/blob/v1/build/webgpu/metadata.json) — kernel metadata (id, file digests, manifest spec, provenance)- [`manifest.json`](https://huggingface.co/kernels/webgpu-kernels/com.microsoft.GatedAdd/blob/v1/build/webgpu/manifest.json) — the op contract (source of truth)- [`test.json`](https://huggingface.co/kernels/webgpu-kernels/com.microsoft.GatedAdd/blob/v1/build/webgpu/test.json) — correctness cases- [`bench.json`](https://huggingface.co/kernels/webgpu-kernels/com.microsoft.GatedAdd/blob/v1/build/webgpu/bench.json) — benchmark cases- [`gated-add.wgsl.jinja`](https://huggingface.co/kernels/webgpu-kernels/com.microsoft.GatedAdd/blob/v1/build/webgpu/gated-add.wgsl.jinja)## Use with `@huggingface/kernels````shnpm 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`.```jsimport { getKernel } from "@huggingface/kernels";const kernel = await getKernel("webgpu-kernels/com.microsoft.GatedAdd", { version: 1 });const XData = Float32Array.of(1, 2, 3, 4, 5, 6);const YData = Float32Array.of(0.5, -1, 2, 10, -0.25, 0.125);const gateData = Float32Array.of(2, -0.5);const { output } = await kernel({X: { data: XData, shape: [2, 3] },Y: { data: YData, shape: [2, 3] },gate: { data: gateData, shape: [2, 1] },});console.log({ output });```
9 unmodified lines10111213141516171819202122232425269 unmodified lineslet begin = invocation * {{ itemsPerInvocation }}u;let end = min(begin + {{ itemsPerInvocation }}u, params.count);for (var i = begin; i < end; i = i + 1u) {{%- endmacro %}{% macro flat_tail_close() %}}{% endmacro %}{% macro flat_index_2d(workgroupSize, name="i", bound="params.count", guardInline=false) %}{% set wgTerm = workgroupSize ~ "u" if workgroupSize is number else workgroupSize %}// 2D-folded flat index: gid.y carries the high bits past the dispatch's// per-axis workgroup fold width.let {{ name }} = gid.x + gid.y * {{ DISPATCH_FOLD_WIDTH }}u * {{ wgTerm }};if ({{ name }} >= {{ bound }}) {return;}{% endmacro %}{{ env.wgsl.resourceDeclarations }}// com.microsoft.GatedAdd : output = X + round_to_T(Y * gate)9 unmodified lines1011121314151617181920212223242526279 unmodified lineslet begin = invocation * {{ itemsPerInvocation }}u;let end = min(begin + {{ itemsPerInvocation }}u, params.count);for (var i = begin; i < end; i = i + 1u) {{% endmacro %}{% macro flat_tail_close() %}}{% endmacro %}{% macro flat_index_2d(workgroupSize, name="i", bound="params.count") %}{% set wgTerm = workgroupSize ~ "u" if workgroupSize is number else workgroupSize %}// 2D-folded flat index: gid.y carries the high bits past the dispatch's// per-axis workgroup fold width.let {{ name }} = gid.x + gid.y * {{ DISPATCH_FOLD_WIDTH }}u * {{ wgTerm }};if ({{ name }} >= {{ bound }}) {return;}{% endmacro %}{{ env.wgsl.resourceDeclarations }}// com.microsoft.GatedAdd : output = X + round_to_T(Y * gate)
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869{"domain": "com.microsoft","name": "GatedAdd","sinceVersion": 1,"inputs": { "X": { "dtype": "T" }, "Y": { "dtype": "T" }, "gate": { "dtype": "T" } },"outputs": { "output": { "dtype": "T", "rank": "ranks.X", "shape": "shapes.X" } },"typeConstraints": { "T": ["float32", "float16"] },"tunables": { "WORKGROUP_SIZE": { "default": 256 } },"derive": {"channels": "dim(shapes.X, ranks.X - 1)","gateContract": "ranks.X >= 1 and channels > 0 and ranks.Y == ranks.X and ranks.gate == ranks.X and sameShape(shapes.Y, shapes.X) and sameShape(shapes.output, shapes.X) and dim(shapes.gate, ranks.gate - 1) == 1 and sameShape(prefix(shapes.gate, ranks.gate - 1), prefix(shapes.X, ranks.X - 1)) and f16Ok(dtypes.T)","vec4Rows": "channels % 4 == 0 and numel(shapes.X) % 4 == 0","scalar": "dtypes.T","hidden": "channels if channels > 0 else 1"},"when": ["gateContract"],"variants": [{"id": "vec4","priority": 30,"when": ["vec4Rows", "numel(shapes.X) > 0"],"derive": { "vec4": true, "vectorScalar": "\"vec4<\" ~ dtypes.T ~ \">\"" },"passes": [{"id": "main","name": "GatedAdd.Vec4","shader": "gated-add.wgsl.jinja","bindings": [{ "arg": "X", "name": "x", "elementType": "$vectorScalar" },{ "arg": "Y", "name": "y", "elementType": "$vectorScalar" },"gate",{ "arg": "output", "elementType": "$vectorScalar" },{ "name": "params", "struct": [{ "name": "count", "type": "u32", "value": "numel(shapes.X) / 4" }] }],"dispatch": {"x": "min(ceilDiv((numel(shapes.X) / 4), (tunables.WORKGROUP_SIZE)), 65535)","y": "ceilDiv(ceilDiv((numel(shapes.X) / 4), (tunables.WORKGROUP_SIZE)), 65535)","z": 1}}]},{"id": "scalar","priority": 0,"derive": { "vec4": false },"passes": [{"id": "main","name": "GatedAdd.Scalar","shader": "gated-add.wgsl.jinja","derive": { "itemsPerInvocation": 4 },"bindings": [{ "arg": "X", "name": "x", "elementType": "$scalar" },{ "arg": "Y", "name": "y", "elementType": "$scalar" },"gate","output",{ "name": "params", "struct": [{ "name": "count", "type": "u32", "value": "numel(shapes.X)" }] }],"dispatch": {"x": "min(ceilDiv((ceilDiv(numel(shapes.X), 4)), (tunables.WORKGROUP_SIZE)), 65535)","y": "ceilDiv(ceilDiv((ceilDiv(numel(shapes.X), 4)), (tunables.WORKGROUP_SIZE)), 65535)","z": 1}}]}]}1{"domain":"com.microsoft","name":"GatedAdd","sinceVersion":1,"inputs":{"X":{"dtype":"T"},"Y":{"dtype":"T"},"gate":{"dtype":"T"}},"outputs":{"output":{"dtype":"T","rank":"ranks.X","shape":"shapes.X"}},"typeConstraints":{"T":["float32","float16"]},"tunables":{"WORKGROUP_SIZE":{"default":256}},"derive":{"channels":"dim(shapes.X, ranks.X - 1)","gateContract":"ranks.X >= 1 and channels > 0 and ranks.Y == ranks.X and ranks.gate == ranks.X and sameShape(shapes.Y, shapes.X) and sameShape(shapes.output, shapes.X) and dim(shapes.gate, ranks.gate - 1) == 1 and sameShape(prefix(shapes.gate, ranks.gate - 1), prefix(shapes.X, ranks.X - 1)) and f16Ok(dtypes.T)","vec4Rows":"channels % 4 == 0 and numel(shapes.X) % 4 == 0","scalar":"dtypes.T","hidden":"channels if channels > 0 else 1"},"when":["gateContract"],"variants":[{"id":"vec4","priority":30,"when":["vec4Rows","numel(shapes.X) > 0"],"derive":{"vec4":true,"vectorScalar":"\"vec4<\" ~ dtypes.T ~ \">\""},"passes":[{"id":"main","name":"GatedAdd.Vec4","shader":"gated-add.wgsl.jinja","bindings":[{"arg":"X","name":"x","elementType":"$vectorScalar"},{"arg":"Y","name":"y","elementType":"$vectorScalar"},"gate",{"arg":"output","elementType":"$vectorScalar"},{"name":"params","struct":[{"name":"count","type":"u32","value":"numel(shapes.X) / 4"}]}],"dispatch":{"x":"min(ceilDiv((numel(shapes.X) / 4), (tunables.WORKGROUP_SIZE)), 65535)","y":"ceilDiv(ceilDiv((numel(shapes.X) / 4), (tunables.WORKGROUP_SIZE)), 65535)","z":1}}]},{"id":"scalar","priority":0,"derive":{"vec4":false},"passes":[{"id":"main","name":"GatedAdd.Scalar","shader":"gated-add.wgsl.jinja","derive":{"itemsPerInvocation":4},"bindings":[{"arg":"X","name":"x","elementType":"$scalar"},{"arg":"Y","name":"y","elementType":"$scalar"},"gate","output",{"name":"params","struct":[{"name":"count","type":"u32","value":"numel(shapes.X)"}]}],"dispatch":{"x":"min(ceilDiv((ceilDiv(numel(shapes.X), 4)), (tunables.WORKGROUP_SIZE)), 65535)","y":"ceilDiv(ceilDiv((ceilDiv(numel(shapes.X), 4)), (tunables.WORKGROUP_SIZE)), 65535)","z":1}}]}]}
123456789101112131415161718192021{"name": "com.microsoft.GatedAdd","id": "_com_microsoft_gatedadd_webgpu_34aae76","version": 1,"license": "Apache-2.0","backend": { "type": "webgpu" },"digest": {"algorithm": "sha256","files": {"bench.json": "f/TmVS5V2Nom2d9yiZ8HU0gLA+HtwVePXaGO4EmsmoY=","gated-add.wgsl.jinja": "jZnIxRERHOaeJx2usJ13f9c7XLMB2bVMMIfqZ1DMYu8=","manifest.json": "PCK9cwNdN2BqtsElsaqlUDXwrON3HQA3nxwc8lmw2LM=","test.json": "Mu0iaJZ9Ygpmyu+1cY1bU6ytPO2Q0eYGf401O3L6o6w="}},"provenance": { "kernel": { "sha": "6fdf6301e2bbcc2f03bf1eaf493b7ad55ef33afc", "dirty": false } },"webgpu": {"manifestSpec": "2.1","variants": { "vec4": ["gated-add.wgsl.jinja"], "scalar": ["gated-add.wgsl.jinja"] }}}1{"name":"com.microsoft.GatedAdd","id":"_com_microsoft_gatedadd_webgpu_d066b3c","version":1,"license":"Apache-2.0","backend":{"type":"webgpu"},"digest":{"algorithm":"sha256","files":{"bench.json":"f/TmVS5V2Nom2d9yiZ8HU0gLA+HtwVePXaGO4EmsmoY=","gated-add.wgsl.jinja":"dknWwqghNwmnjWmWGvQsLbvM7ySMyWTDUU2nA7QbH1Y=","manifest.json":"alZH3vBaVZH8DOXLSGXE0gjb+gEL8HB1uLWidL3beEs=","test.json":"XOhFIpHKShCTDcVoTGmnF7SZNGYTltQ9KgVwRweZUa8="}},"provenance":{"kernel":{"sha":"4385228f788ddaa1bd7aec6a80a20f3ddffd8011","dirty":false}},"webgpu":{"manifestSpec":"2.2"}}
121 unmodified lines12212312412512612712813 unmodified lines142143144145146147148121 unmodified lines{"name": "f16_product_rounds_to_type_pinned","provenance": {"notes": "Pins the round_to_T rule that separates this op from a wider-precision fused multiply-add. Row 0 uses gate = 1 + 2^-10, so Y = 1025 gives a real product of 1026.0009765625 that float16 rounds to 1026.0; X = -1026 then cancels it exactly to 0. A kernel that let the product stay unrounded -- by contracting the multiply into the add -- would return 2^-10 there instead. Every other value is exact in float16, so the whole expectation is hand-computable."},"inputs": {"X": {13 unmodified lines"dtype": "float16","shape": [2, 4],"data": { "kind": "values", "values": [0.0, 25.0, 513.0, 0.0078125, 2.5, 3.0, 6.25, 11.0] },"tolerance": 0.0005}}},121 unmodified lines12212312412512612712813 unmodified lines142143144145146147148149121 unmodified lines{"name": "f16_product_rounds_to_type_pinned","provenance": {"notes": "The product of the gate and Y is rounded to the tensor type before the add, unlike a wider-precision fused multiply-add. Row 0 uses gate = 1 + 2^-10, so Y = 1025 gives a real product of 1026.0009765625 that float16 rounds to 1026.0; X = -1026 then cancels it exactly to 0. A fused multiply-add that kept the product unrounded would return 2^-10 there instead. Every other value is exact in float16, so the whole expectation is hand-computable."},"inputs": {"X": {13 unmodified lines"dtype": "float16","shape": [2, 4],"data": { "kind": "values", "values": [0.0, 25.0, 513.0, 0.0078125, 2.5, 3.0, 6.25, 11.0] },"tolerance": 0.0005,"exactRounding": true}}},
README.md+14-8
build/webgpu/gated-add.wgsl.jinja+4-3
build/webgpu/manifest.json+1-69
build/webgpu/metadata.json+1-21
build/webgpu/test.json+3-2