sync 4385228f788d
Browse filesFiles changed (6)
44 unmodified lines4546474849505152535455565758596061626364656667686970717273747544 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)## 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/ai.onnx.DepthToSpace", { version: 1 });const { output } = await kernel({ input: { data: inputData, shape: [1, 8, 1, 1] } }, {attrs: { blocksize: 2 },});```44 unmodified lines454647484950515253545556575859606162636465666768697071727374757677787944 unmodified lines## Files- [`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.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/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 });```
12345678913 unmodified lines23242526272829{% 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 }}// 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) }}let owBase = (q % OUT_W_GROUPS) * 4u;var t = q / OUT_W_GROUPS;12345678910111213 unmodified lines26272829303132{% 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 }}// 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") }}let owBase = (q % OUT_W_GROUPS) * 4u;var t = q / OUT_W_GROUPS;
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110{"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}}]}]}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}}]}]}
1234567891011121314151617181920212223242526{"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"]}}}1{"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"}}
123456789101112{% set flatVector = false %}{% 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 }}// Specializing all geometry lets division and modulo lower to constant12345678910111213{% set flatVector = 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 %}{{ env.wgsl.resourceDeclarations }}// Specializing all geometry lets division and modulo lower to constant
479 unmodified lines48048148248348448548626 unmodified lines513514515516517518519479 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."},"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."},"attrs": { "blocksize": 2, "mode": "DCR" },"inputs": {479 unmodified lines48048148248348448548626 unmodified lines513514515516517518519479 unmodified lines"provenance": {"source": "onnxruntime/test/providers/cpu/tensor/space_depth_ops_test.cc","test": "TensorOpTest.DepthToSpaceTest_int_opset13","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": "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