sync 4385228f788d
Browse filesFiles changed (6)
44 unmodified lines454647484950515253484950515253545556575858596061626364656667666768697071727374757677787944 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- [`depth-to-space-nchw-coarsened4.wgsl.jinja`](build/webgpu/depth-to-space-nchw-coarsened4.wgsl.jinja)- [`space-depth-permute.wgsl.jinja`](build/webgpu/space-depth-permute.wgsl.jinja)- [`metadata.json`](https://huggingface.co/kernels/webgpu-kernels/ai.onnx.DepthToSpace/blob/v1/build/webgpu/metadata.json) — kernel metadata (id, file digests, manifest spec, provenance)- [`manifest.json`](https://huggingface.co/kernels/webgpu-kernels/ai.onnx.DepthToSpace/blob/v1/build/webgpu/manifest.json) — the op contract (source of truth)- [`test.json`](https://huggingface.co/kernels/webgpu-kernels/ai.onnx.DepthToSpace/blob/v1/build/webgpu/test.json) — correctness cases- [`bench.json`](https://huggingface.co/kernels/webgpu-kernels/ai.onnx.DepthToSpace/blob/v1/build/webgpu/bench.json) — benchmark cases- [`depth-to-space-nchw-coarsened4.wgsl.jinja`](https://huggingface.co/kernels/webgpu-kernels/ai.onnx.DepthToSpace/blob/v1/build/webgpu/depth-to-space-nchw-coarsened4.wgsl.jinja)- [`space-depth-permute.wgsl.jinja`](https://huggingface.co/kernels/webgpu-kernels/ai.onnx.DepthToSpace/blob/v1/build/webgpu/space-depth-permute.wgsl.jinja)
## Use with `@huggingface/kernels`
```shnpm install --save-exact @huggingface/kernels@0.0.1-preview.3npm 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`.
Replace each `*Data` placeholder with a typed array containing the corresponding input data.
```jsimport { getKernel } from "@huggingface/kernels";
const kernel = await getKernel("webgpu-kernels/ai.onnx.DepthToSpace", { version: 1 });
const inputData = Float32Array.of(0, 9, 18, 27, 36, 45, 54, 63);
const { output } = await kernel({ input: { data: inputData, shape: [1, 8, 1, 1] } }, { attrs: { blocksize: 2 },});console.log({ output });```1123456678910111213 unmodified lines2627282629303132{% macro flat_index_2d(workgroupSize, name="i", bound="params.count", guardInline=false) %}{% 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 %} if ({{ name }} >= {{ bound }}) { return; }{% endmacro %}{{ env.wgsl.resourceDeclarations }}
// Four adjacent output columns share N/C/H decoding and the block-row lookup.13 unmodified lines
@compute @workgroup_size({{ tunables.WORKGROUP_SIZE }})fn main(@builtin(global_invocation_id) gid: vec3<u32>) {{{ flat_index_2d("WG", "q", "GROUPS", guardInline=true) }}{{ flat_index_2d("WG", "q", "GROUPS") }}
let owBase = (q % OUT_W_GROUPS) * 4u; var t = q / OUT_W_GROUPS;1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101{ "domain": "ai.onnx", "name": "DepthToSpace", "sinceVersion": 13, "inputs": { "input": { "dtype": "T", "rank": 4 } }, "outputs": { "output": { "dtype": "T", "rank": 4, "shape": ["dim(shapes.input, 0)", "dim(shapes.input, 1) / (attrs.blocksize * attrs.blocksize)", "dim(shapes.input, 2) * attrs.blocksize", "dim(shapes.input, 3) * attrs.blocksize"] } }, "attributes": { "mode": { "default": "DCR" }, "blocksize": {} }, "attributeConstraints": { "blocksize": { "required": true }, "mode": { "values": ["DCR", "CRD"] } }, "typeConstraints": { "T": ["float32", "float16", "int32", "int16", "int8", "uint32", "uint8", "bool"] }, "tunables": { "WORKGROUP_SIZE": { "default": 256 } }, "derive": { "variableSubgroup16To32": "device.features.has(\"subgroups\") and has(device.adapterInfo, \"subgroupMinSize\") and has(device.adapterInfo, \"subgroupMaxSize\") and device.adapterInfo.subgroupMinSize == 16 and device.adapterInfo.subgroupMaxSize == 32", "shapeContract": "attrs.blocksize > 0 and ranks.input == 4 and ranks.output == 4 and dim(shapes.output, 0) == dim(shapes.input, 0) and dim(shapes.output, 1) * attrs.blocksize * attrs.blocksize == dim(shapes.input, 1) and dim(shapes.output, 2) == dim(shapes.input, 2) * attrs.blocksize and dim(shapes.output, 3) == dim(shapes.input, 3) * attrs.blocksize and f16Ok(dtypes.T)", "scalar": "dtypes.T", "modeSpec": "attrs.mode", "blocksize": "attrs.blocksize", "inC": "dim(shapes.input, 1)", "inH": "dim(shapes.input, 2)", "inW": "dim(shapes.input, 3)" }, "when": ["shapeContract"], "bindings": { "output": { "elementType": "$outputElement" } }, "variants": [ { "id": "nchw_vec4", "priority": 20, "when": ["dim(shapes.output, 3) % 4 == 0"], "demoteWhen": ["variableSubgroup16To32 and dtypes.T == \"f16\""], "derive": { "outputElement": "\"vec4<\" ~ dtypes.T ~ \">\"", "vectorScalar": "\"vec4<\" ~ dtypes.T ~ \">\"" }, "passes": [ { "id": "main", "name": "DepthToSpace", "shader": "space-depth-permute.wgsl.jinja", "derive": { "vectorizedSpec": true, "count": "numel(shapes.output) / 4", "outWUnits": "dim(shapes.output, 3) / 4", "outH": "dim(shapes.output, 2)", "outC": "dim(shapes.output, 1)" }, "bindings": ["input", "output"], "dispatch": { "x": "min(ceilDiv((numel(shapes.output) / 4), (tunables.WORKGROUP_SIZE)), 65535)", "y": "ceilDiv(ceilDiv((numel(shapes.output) / 4), (tunables.WORKGROUP_SIZE)), 65535)", "z": 1 } } ] }, { "id": "nchw_const", "priority": 10, "derive": { "outputElement": "dtypes.T" }, "passes": [ { "id": "main", "name": "DepthToSpace", "shader": "space-depth-permute.wgsl.jinja", "derive": { "vectorizedSpec": false, "count": "numel(shapes.output)", "outWUnits": "dim(shapes.output, 3)", "outC": "dim(shapes.output, 1)", "outH": "dim(shapes.output, 2)", "outW": "dim(shapes.output, 3)" }, "bindings": ["input", "output"], "dispatch": { "x": "min(ceilDiv((numel(shapes.output)), (tunables.WORKGROUP_SIZE)), 65535)", "y": "ceilDiv(ceilDiv((numel(shapes.output)), (tunables.WORKGROUP_SIZE)), 65535)", "z": 1 } } ] }, { "id": "nchw_coarsened4", "priority": 15, "when": ["dim(shapes.output, 3) % 4 != 0", "numel(shapes.output) >= 4096"], "derive": { "outputElement": "dtypes.T" }, "passes": [ { "id": "main", "name": "DepthToSpace.Coarsened4", "shader": "depth-to-space-nchw-coarsened4.wgsl.jinja", "derive": { "groups": "dim(shapes.output, 0) * dim(shapes.output, 1) * dim(shapes.output, 2) * ceil(dim(shapes.output, 3) / 4)", "outWGroups": "ceil(dim(shapes.output, 3) / 4)", "outC": "dim(shapes.output, 1)", "outH": "dim(shapes.output, 2)", "outW": "dim(shapes.output, 3)" }, "bindings": ["input", "output"], "dispatch": { "x": "min(ceilDiv((dim(shapes.output, 0) * dim(shapes.output, 1) * dim(shapes.output, 2) * ceil(dim(shapes.output, 3) / 4)), (tunables.WORKGROUP_SIZE)), 65535)", "y": "ceilDiv(ceilDiv((dim(shapes.output, 0) * dim(shapes.output, 1) * dim(shapes.output, 2) * ceil(dim(shapes.output, 3) / 4)), (tunables.WORKGROUP_SIZE)), 65535)", "z": 1 } } ] } ]}{"domain":"ai.onnx","name":"DepthToSpace","sinceVersion":13,"inputs":{"input":{"dtype":"T","rank":4}},"outputs":{"output":{"dtype":"T","rank":4,"shape":["dim(shapes.input, 0)","dim(shapes.input, 1) / (attrs.blocksize * attrs.blocksize)","dim(shapes.input, 2) * attrs.blocksize","dim(shapes.input, 3) * attrs.blocksize"]}},"attributes":{"mode":{"default":"DCR"},"blocksize":{}},"attributeConstraints":{"blocksize":{"required":true},"mode":{"values":["DCR","CRD"]}},"typeConstraints":{"T":["float32","float16","int32","int16","int8","uint32","uint8","bool"]},"tunables":{"WORKGROUP_SIZE":{"default":256}},"derive":{"variableSubgroup16To32":"device.features.has(\"subgroups\") and has(device.adapterInfo, \"subgroupMinSize\") and has(device.adapterInfo, \"subgroupMaxSize\") and device.adapterInfo.subgroupMinSize == 16 and device.adapterInfo.subgroupMaxSize == 32","shapeContract":"attrs.blocksize > 0 and ranks.input == 4 and ranks.output == 4 and dim(shapes.output, 0) == dim(shapes.input, 0) and dim(shapes.output, 1) * attrs.blocksize * attrs.blocksize == dim(shapes.input, 1) and dim(shapes.output, 2) == dim(shapes.input, 2) * attrs.blocksize and dim(shapes.output, 3) == dim(shapes.input, 3) * attrs.blocksize and f16Ok(dtypes.T)","scalar":"dtypes.T","modeSpec":"attrs.mode","blocksize":"attrs.blocksize","inC":"dim(shapes.input, 1)","inH":"dim(shapes.input, 2)","inW":"dim(shapes.input, 3)"},"when":["shapeContract"],"bindings":{"output":{"elementType":"$outputElement"}},"variants":[{"id":"nchw_vec4","priority":20,"when":["dim(shapes.output, 3) % 4 == 0"],"demoteWhen":["variableSubgroup16To32 and dtypes.T == \"f16\""],"derive":{"outputElement":"\"vec4<\" ~ dtypes.T ~ \">\"","vectorScalar":"\"vec4<\" ~ dtypes.T ~ \">\""},"passes":[{"id":"main","name":"DepthToSpace","shader":"space-depth-permute.wgsl.jinja","derive":{"vectorizedSpec":true,"count":"numel(shapes.output) / 4","outWUnits":"dim(shapes.output, 3) / 4","outH":"dim(shapes.output, 2)","outC":"dim(shapes.output, 1)"},"bindings":["input","output"],"dispatch":{"x":"min(ceilDiv((numel(shapes.output) / 4), (tunables.WORKGROUP_SIZE)), 65535)","y":"ceilDiv(ceilDiv((numel(shapes.output) / 4), (tunables.WORKGROUP_SIZE)), 65535)","z":1}}]},{"id":"nchw_const","priority":10,"derive":{"outputElement":"dtypes.T"},"passes":[{"id":"main","name":"DepthToSpace","shader":"space-depth-permute.wgsl.jinja","derive":{"vectorizedSpec":false,"count":"numel(shapes.output)","outWUnits":"dim(shapes.output, 3)","outC":"dim(shapes.output, 1)","outH":"dim(shapes.output, 2)","outW":"dim(shapes.output, 3)"},"bindings":["input","output"],"dispatch":{"x":"min(ceilDiv((numel(shapes.output)), (tunables.WORKGROUP_SIZE)), 65535)","y":"ceilDiv(ceilDiv((numel(shapes.output)), (tunables.WORKGROUP_SIZE)), 65535)","z":1}}]},{"id":"nchw_coarsened4","priority":15,"when":["dim(shapes.output, 3) % 4 != 0","numel(shapes.output) >= 4096"],"derive":{"outputElement":"dtypes.T"},"passes":[{"id":"main","name":"DepthToSpace.Coarsened4","shader":"depth-to-space-nchw-coarsened4.wgsl.jinja","derive":{"groups":"dim(shapes.output, 0) * dim(shapes.output, 1) * dim(shapes.output, 2) * ceil(dim(shapes.output, 3) / 4)","outWGroups":"ceil(dim(shapes.output, 3) / 4)","outC":"dim(shapes.output, 1)","outH":"dim(shapes.output, 2)","outW":"dim(shapes.output, 3)"},"bindings":["input","output"],"dispatch":{"x":"min(ceilDiv((dim(shapes.output, 0) * dim(shapes.output, 1) * dim(shapes.output, 2) * ceil(dim(shapes.output, 3) / 4)), (tunables.WORKGROUP_SIZE)), 65535)","y":"ceilDiv(ceilDiv((dim(shapes.output, 0) * dim(shapes.output, 1) * dim(shapes.output, 2) * ceil(dim(shapes.output, 3) / 4)), (tunables.WORKGROUP_SIZE)), 65535)","z":1}}]}]}12345678910111213141516171819202122232425261{ "name": "ai.onnx.DepthToSpace", "id": "_ai_onnx_depthtospace_webgpu_6dcb40b", "version": 1, "license": "Apache-2.0", "backend": { "type": "webgpu" }, "digest": { "algorithm": "sha256", "files": { "bench.json": "JU/Zd5udt4ll47K2EnVjXxjt0sEh9KmpBf5fZnZrXFY=", "depth-to-space-nchw-coarsened4.wgsl.jinja": "W8vNJZ/U3oL0d11TQBVoSxOkJmvXNxolOI0xFXlG1bU=", "manifest.json": "/2NFeZFb4YB+4NEuZeBjEgD6NuRQmZoAXjMRXWW4TjQ=", "space-depth-permute.wgsl.jinja": "0fv5363hhXl9ojT6/Mz0lMAqdqHgoiZUSrnZTspEO30=", "test.json": "hs7y38XH3BuXDsaABYqenTgiC4pdBPPan6x4uUc0EU0=" } }, "provenance": { "kernel": { "sha": "6fdf6301e2bbcc2f03bf1eaf493b7ad55ef33afc", "dirty": false } }, "webgpu": { "manifestSpec": "2.1", "variants": { "nchw_vec4": ["space-depth-permute.wgsl.jinja"], "nchw_const": ["space-depth-permute.wgsl.jinja"], "nchw_coarsened4": ["depth-to-space-nchw-coarsened4.wgsl.jinja"] } }}{"name":"ai.onnx.DepthToSpace","id":"_ai_onnx_depthtospace_webgpu_42ea13d","version":1,"license":"Apache-2.0","backend":{"type":"webgpu"},"digest":{"algorithm":"sha256","files":{"bench.json":"JU/Zd5udt4ll47K2EnVjXxjt0sEh9KmpBf5fZnZrXFY=","depth-to-space-nchw-coarsened4.wgsl.jinja":"GW+UmV8+QZrHdCaTTQa+1tOoH4l/Dg6fN53kvs0a7YA=","manifest.json":"OaazMabk07honUhpBh43tG4X5Emy/WAUz67RZ7p5f7Y=","space-depth-permute.wgsl.jinja":"WxA6Ytbek0acmlzk2p3d2aoEf7oT0QMXS8fJUiap3II=","test.json":"Sf4t9C1tJxkmsyXRXqqp9sd4lxDnHxtqovF0k2uuTBE="}},"provenance":{"kernel":{"sha":"4385228f788ddaa1bd7aec6a80a20f3ddffd8011","dirty":false}},"webgpu":{"manifestSpec":"2.2"}}1223456789910111213{% set flatVector = false %}{% macro flat_index_2d(workgroupSize, name="i", bound="params.count", guardInline=false) %}{% 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 %}{% endmacro %}{{ env.wgsl.resourceDeclarations }}
// Specializing all geometry lets division and modulo lower to constant479 unmodified lines48048148248348348448548626 unmodified lines513514515516516517518519479 unmodified lines "provenance": { "source": "onnxruntime/test/providers/cpu/tensor/space_depth_ops_test.cc", "test": "TensorOpTest.DepthToSpaceTest_int_opset13", "notes": "ONNX DepthToSpace-13 permits int32; signed extrema prove the widened i32 route is a bit-exact permutation." "notes": "int32 input [1,4,1,2] in DCR mode with blocksize 2, holding the int32 extrema and +-16777217 (which float32 cannot represent); the output must be an exact permutation of the input." }, "attrs": { "blocksize": 2, "mode": "DCR" }, "inputs": {26 unmodified lines "provenance": { "source": "onnxruntime/test/providers/cpu/tensor/space_depth_ops_test.cc", "test": "TensorOpTest.DepthToSpaceTest_int_opset13", "notes": "Uses both int8 extrema so the widened i32 storage route cannot hide narrowing or sign loss." "notes": "int8 input in DCR mode with blocksize 2 holding both extrema (-128 and 127); the output must be an exact permutation with no narrowing or sign loss." }, "attrs": { "blocksize": 2, "mode": "DCR" }, "inputs": {README.md+13-9
build/webgpu/depth-to-space-nchw-coarsened4.wgsl.jinja+6-3
build/webgpu/manifest.json+1-110
build/webgpu/metadata.json+1-26
build/webgpu/space-depth-permute.wgsl.jinja+3-2
build/webgpu/test.json+2-2