sync 6fdf6301e2bb
Browse filesFiles changed (5)
40 unmodified lines41424344444546474849505051525340 unmodified lines- [`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 + tuning 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.2npm 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.11 unmodified lines121314151617181920212223242526272829303132333415161718193738392040414243442122474849235024252611 unmodified lines38394068414243443 unmodified lines4849507851525311 unmodified lines for (var i = begin; i < end; i = i + 1u) {{%- endmacro %}{% macro flat_tail_close() %} }{% endmacro %}
{% macro flat_index_2d(name="i", bound="params.count", guardInline=false, note="dispatch-limit") %}{% if note == "dispatch-limit" %} // 2D-folded flat index: gid.y carries the high bits past the dispatch's // per-axis workgroup fold width (outputs > 16.7M elements).{% elif note == "limit" %} // 2D-folded flat index: gid.y carries the high bits past the dispatch's // per-axis workgroup fold width.{% elif note == "device-axis" %} // The flat dispatch is folded across x/y at a fixed per-axis workgroup // width; gid.y carries the high portion of the output index.{% elif note == "vec4-limit" %} // 2D-folded flat vec4 index: gid.y carries the high bits past the dispatch's // per-axis workgroup fold width (the dispatch caps x and spills into y).{% elif note == "element-limit" %} // 2D-folded flat element index: gid.y carries the high bits past the // dispatch's per-axis workgroup fold width.{% elif note == "dispatch" %} }{% 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.{% endif %}{% if bound == "" %} let {{ name }} = gid.x + gid.y * {{ DISPATCH_FOLD_WIDTH }}u * {{ tunables.WORKGROUP_SIZE }}u; let {{ name }} = gid.x + gid.y * {{ DISPATCH_FOLD_WIDTH }}u * {{ wgTerm }};{%- elif guardInline %} let {{ name }} = gid.x + gid.y * {{ DISPATCH_FOLD_WIDTH }}u * {{ tunables.WORKGROUP_SIZE }}u; if ({{ name }} >= {{ bound }}) { return; }{%- else %} let {{ name }} = gid.x + gid.y * {{ DISPATCH_FOLD_WIDTH }}u * {{ tunables.WORKGROUP_SIZE }}u; if ({{ name }} >= {{ bound }}) { return; }{%- endif %}{% endmacro %} }{% endmacro %}
{{ env.wgsl.resourceDeclarations }}
// com.microsoft.GatedAdd : output = X + round_to_T(Y * gate)11 unmodified lines{% if vec4 %}@compute @workgroup_size({{ tunables.WORKGROUP_SIZE }})fn main(@builtin(global_invocation_id) gid: vec3<u32>) {{{ flat_index_2d() }}{{ flat_index_2d(tunables.WORKGROUP_SIZE) }} // A vec4 group is four consecutive channels of one row: HIDDEN % 4 == 0 stops // it from ever straddling two rows, so the whole group shares one gate value. let g = vec4<{{ scalar }}>(gate[i * 4u / HIDDEN]);3 unmodified lines{{ flat_tail_open() }} let g = gate[i / HIDDEN]; output[i] = x[i] + fma(y[i], g, {{ scalar }}(0.0));{{ flat_tail_close() -}}{{ flat_tail_close() }}}{% endif %}22 unmodified lines232425262627282917 unmodified lines474849505051525322 unmodified lines "passes": [ { "id": "main", "name": "GatedAdd.vec4", "name": "GatedAdd.Vec4", "shader": "gated-add.wgsl.jinja", "bindings": [ { "arg": "X", "name": "x", "elementType": "$vectorScalar" },17 unmodified lines "passes": [ { "id": "main", "name": "GatedAdd.scalar", "name": "GatedAdd.Scalar", "shader": "gated-add.wgsl.jinja", "derive": { "itemsPerInvocation": 4 }, "bindings": [12334561 unmodified line891011121311121314151616171818192021{ "name": "com.microsoft.GatedAdd", "id": "_com_microsoft_gatedadd_webgpu_913bb83", "id": "_com_microsoft_gatedadd_webgpu_34aae76", "version": 1, "license": "Apache-2.0", "backend": { "type": "webgpu" },1 unmodified line "algorithm": "sha256", "files": { "bench.json": "f/TmVS5V2Nom2d9yiZ8HU0gLA+HtwVePXaGO4EmsmoY=", "gated-add.wgsl.jinja": "6xWRekBrMasrrGGXBN6cHj1NeycAppVTPGz1QPRDnUQ=", "manifest.json": "a3y5tgF4lud3fMIhIIyomyBnUdsTqCeCaWuGJOSdW1U=", "test.json": "CgQChPZDm5zqD3shwXcy5E57YHqJlw8wSwSyTQeEvN4=" "gated-add.wgsl.jinja": "jZnIxRERHOaeJx2usJ13f9c7XLMB2bVMMIfqZ1DMYu8=", "manifest.json": "PCK9cwNdN2BqtsElsaqlUDXwrON3HQA3nxwc8lmw2LM=", "test.json": "Mu0iaJZ9Ygpmyu+1cY1bU6ytPO2Q0eYGf401O3L6o6w=" } }, "provenance": { "kernel": { "sha": "91d990483a174128daf7673f3f37a7c890493ae1", "dirty": false } }, "provenance": { "kernel": { "sha": "6fdf6301e2bbcc2f03bf1eaf493b7ad55ef33afc", "dirty": false } }, "webgpu": { "manifestSpec": "2.0", "manifestSpec": "2.1", "variants": { "vec4": ["gated-add.wgsl.jinja"], "scalar": ["gated-add.wgsl.jinja"] } }}178 unmodified lines179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262178 unmodified lines "gate": { "dtype": "float16", "shape": [4, 1], "data": { "kind": "values", "values": [0.75, -1.25, 3.0, 0.5] } } }, "outputs": { "output": { "dtype": "float16", "shape": [4, 5], "tolerance": 0.0005, "relTolerance": 0.002 } } }, { "name": "ort_gated_add_rank3_hidden7_f32", "inputs": { "X": { "dtype": "float32", "shape": [2, 3, 7], "data": { "kind": "fillFloat32", "sinStep": 0.13, "cosStep": 0.29 } }, "Y": { "dtype": "float32", "shape": [2, 3, 7], "data": { "kind": "fillFloat32", "sinStep": 0.31, "cosStep": 0.07 } }, "gate": { "dtype": "float32", "shape": [2, 3, 1], "data": { "kind": "fillFloat32", "sinStep": 0.41, "cosStep": 0.17, "offset": 0.75 } } }, "outputs": { "output": { "dtype": "float32", "shape": [2, 3, 7], "tolerance": 0.000001, "relTolerance": 0.000001 } } }, { "name": "ort_gated_add_rank1_hidden7_f32", "inputs": { "X": { "dtype": "float32", "shape": [7], "data": { "kind": "fillFloat32", "sinStep": 0.13, "cosStep": 0.29 } }, "Y": { "dtype": "float32", "shape": [7], "data": { "kind": "fillFloat32", "sinStep": 0.31, "cosStep": 0.07 } }, "gate": { "dtype": "float32", "shape": [1], "data": { "kind": "fillFloat32", "sinStep": 0.41, "cosStep": 0.17, "offset": 0.75 } } }, "outputs": { "output": { "dtype": "float32", "shape": [7], "tolerance": 0.000001, "relTolerance": 0.000001 } } }, { "name": "ort_gated_add_empty_outer_dim_f32", "inputs": { "X": { "dtype": "float32", "shape": [0, 7], "data": { "kind": "fillFloat32", "sinStep": 0.13, "cosStep": 0.29 } }, "Y": { "dtype": "float32", "shape": [0, 7], "data": { "kind": "fillFloat32", "sinStep": 0.31, "cosStep": 0.07 } }, "gate": { "dtype": "float32", "shape": [0, 1], "data": { "kind": "fillFloat32", "sinStep": 0.41, "cosStep": 0.17, "offset": 0.75 } } }, "outputs": { "output": { "dtype": "float32", "shape": [0, 7], "tolerance": 0.000001, "relTolerance": 0.000001 } } }, { "name": "ort_gated_add_f16_hidden2048", "inputs": { "X": { "dtype": "float16", "shape": [1, 4, 2048], "data": { "kind": "fillFloat32", "sinStep": 0.13, "cosStep": 0.29 } }, "Y": { "dtype": "float16", "shape": [1, 4, 2048], "data": { "kind": "fillFloat32", "sinStep": 0.31, "cosStep": 0.07 } }, "gate": { "dtype": "float16", "shape": [1, 4, 1], "data": { "kind": "fillFloat32", "sinStep": 0.41, "cosStep": 0.17, "offset": 0.75 } } }, "outputs": { "output": { "dtype": "float16", "shape": [1, 4, 2048], "tolerance": 0.0005, "relTolerance": 0.002 } } } ]}README.md+2-2
build/webgpu/gated-add.wgsl.jinja+7-34
build/webgpu/manifest.json+2-2
build/webgpu/metadata.json+6-6
build/webgpu/test.json+78