sync 4385228f788d
Browse filesFiles changed (14)
- README.md+32-17
- build/webgpu/bench.json+1-1
- build/webgpu/manifest.json+1-383
- build/webgpu/metadata.json+1-36
- build/webgpu/scatter-elements-ordered-chunks.wgsl.jinjaAdded+191
- build/webgpu/scatter-elements-ordered-global.wgsl.jinjaAdded+90
- build/webgpu/scatter-elements-ordered-list.wgsl.jinjaAdded+123
- build/webgpu/scatter-elements-owned-row.wgsl.jinjaAdded+52
- build/webgpu/scatter-elements-reduction-slab.wgsl.jinja+2-4
- build/webgpu/scatter-elements.wgsl.jinja+3-2
- build/webgpu/scatter-f16-f32-convert.wgsl.jinja+6-3
- build/webgpu/scatter-flat-copy.wgsl.jinja+3-2
- build/webgpu/scatter-narrow-wrap.wgsl.jinja+6-3
- build/webgpu/test.json+326-11
49 unmodified lines50515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969749 unmodified linesOne implementation is selected per call from the device capabilities, the request shapes and the dtypes; these notes say what each one covers.- `reduction_f32_add_axis0_histogram` — Fold the updates axis into workgroup bins per 32-column tile, then add each touched bin into the copied output with one device atomic. Striping the updates axis widens the grid a column-only dispatch caps at ceil(columns / 32) workgroups.- `reduction_f16_slab` — Stages f16 slabs in workgroup memory as f32 bits and reduces repeated indices there with a compare-exchange loop. Requires a fixed 32-wide subgroup: on adapters reporting any other subgroup range the duplicate-index merge can lose updates, so the variant is not used there.## Device requirementsSome implementation variants require `subgroups`. These are route-specific capabilities, not package-wide requirements; availability also depends on the request shape and dtype.## 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- [`scatter-elements-f32-add-axis0-histogram.wgsl.jinja`](build/webgpu/scatter-elements-f32-add-axis0-histogram.wgsl.jinja)- [`scatter-elements-reduction-atomic.wgsl.jinja`](build/webgpu/scatter-elements-reduction-atomic.wgsl.jinja)- [`scatter-elements-reduction-slab.wgsl.jinja`](build/webgpu/scatter-elements-reduction-slab.wgsl.jinja)- [`scatter-elements-reduction.wgsl.jinja`](build/webgpu/scatter-elements-reduction.wgsl.jinja)- [`scatter-elements.wgsl.jinja`](build/webgpu/scatter-elements.wgsl.jinja)- [`scatter-f16-f32-convert.wgsl.jinja`](build/webgpu/scatter-f16-f32-convert.wgsl.jinja)- [`scatter-flat-copy.wgsl.jinja`](build/webgpu/scatter-flat-copy.wgsl.jinja)- [`scatter-narrow-wrap.wgsl.jinja`](build/webgpu/scatter-narrow-wrap.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.ScatterElements", { version: 1 });const { output } = await kernel({data: { data: dataData, shape: [3] },indices: { data: indicesData, shape: [2] },updates: { data: updatesData, shape: [2] },});```49 unmodified lines505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111249 unmodified linesOne implementation is selected per call from the device capabilities, the request shapes and the dtypes; these notes say what each one covers.- `reduction_f16_ordered_global` — Builds bounded destination chains, locally sorts short chains by original update position, and scans long chains in original order. Consecutive column batches reuse the same workspace; output half pairs have a single writer.- `reduction_f16_ordered_chunks` — Stages a slice of destinations and rounds to half after each update in input order. Without subgroups, smaller slices keep the direct destination table within workgroup storage. Subgroup devices can use a bounded hash table for larger slices.- `reduction_f16_ordered_list` — Builds destination-owned update chains, sorts their original positions, and applies each additive update with float16 rounding. Uses no global accumulator.- `reduction_f32_add_axis0_histogram` — Fold the updates axis into workgroup bins per 32-column tile, then add each touched bin into the copied output with one device atomic. Striping the updates axis widens the grid a column-only dispatch caps at ceil(columns / 32) workgroups.- `reduction_f16_atomic_f32` — Reduces half minima or maxima through float32 atomic storage and converts the result back to half. Additive updates use ordered per-update half rounding.- `reduction_f16_slab` — Stages half slabs as float32 bits and combines extrema or products in workgroup memory on compatible fixed-width subgroups. Additive updates use ordered per-update half rounding.- `reduction_owned_row` — Owns one complete aligned short half row, applies additive updates in original order with per-update rounding, and writes the packed row once.## Device requirementsSome implementation variants require `subgroups`. Other variants run without it; which variant runs also depends on the request's shapes and dtypes.## Files- [`metadata.json`](https://huggingface.co/kernels/webgpu-kernels/ai.onnx.ScatterElements/blob/v1/build/webgpu/metadata.json) — kernel metadata (id, file digests, manifest spec, provenance)- [`manifest.json`](https://huggingface.co/kernels/webgpu-kernels/ai.onnx.ScatterElements/blob/v1/build/webgpu/manifest.json) — the op contract (source of truth)- [`test.json`](https://huggingface.co/kernels/webgpu-kernels/ai.onnx.ScatterElements/blob/v1/build/webgpu/test.json) — correctness cases- [`bench.json`](https://huggingface.co/kernels/webgpu-kernels/ai.onnx.ScatterElements/blob/v1/build/webgpu/bench.json) — benchmark cases- [`scatter-elements-f32-add-axis0-histogram.wgsl.jinja`](https://huggingface.co/kernels/webgpu-kernels/ai.onnx.ScatterElements/blob/v1/build/webgpu/scatter-elements-f32-add-axis0-histogram.wgsl.jinja)- [`scatter-elements-ordered-chunks.wgsl.jinja`](https://huggingface.co/kernels/webgpu-kernels/ai.onnx.ScatterElements/blob/v1/build/webgpu/scatter-elements-ordered-chunks.wgsl.jinja)- [`scatter-elements-ordered-global.wgsl.jinja`](https://huggingface.co/kernels/webgpu-kernels/ai.onnx.ScatterElements/blob/v1/build/webgpu/scatter-elements-ordered-global.wgsl.jinja)- [`scatter-elements-ordered-list.wgsl.jinja`](https://huggingface.co/kernels/webgpu-kernels/ai.onnx.ScatterElements/blob/v1/build/webgpu/scatter-elements-ordered-list.wgsl.jinja)- [`scatter-elements-owned-row.wgsl.jinja`](https://huggingface.co/kernels/webgpu-kernels/ai.onnx.ScatterElements/blob/v1/build/webgpu/scatter-elements-owned-row.wgsl.jinja)- [`scatter-elements-reduction-atomic.wgsl.jinja`](https://huggingface.co/kernels/webgpu-kernels/ai.onnx.ScatterElements/blob/v1/build/webgpu/scatter-elements-reduction-atomic.wgsl.jinja)- [`scatter-elements-reduction-slab.wgsl.jinja`](https://huggingface.co/kernels/webgpu-kernels/ai.onnx.ScatterElements/blob/v1/build/webgpu/scatter-elements-reduction-slab.wgsl.jinja)- [`scatter-elements-reduction.wgsl.jinja`](https://huggingface.co/kernels/webgpu-kernels/ai.onnx.ScatterElements/blob/v1/build/webgpu/scatter-elements-reduction.wgsl.jinja)- [`scatter-elements.wgsl.jinja`](https://huggingface.co/kernels/webgpu-kernels/ai.onnx.ScatterElements/blob/v1/build/webgpu/scatter-elements.wgsl.jinja)- [`scatter-f16-f32-convert.wgsl.jinja`](https://huggingface.co/kernels/webgpu-kernels/ai.onnx.ScatterElements/blob/v1/build/webgpu/scatter-f16-f32-convert.wgsl.jinja)- [`scatter-flat-copy.wgsl.jinja`](https://huggingface.co/kernels/webgpu-kernels/ai.onnx.ScatterElements/blob/v1/build/webgpu/scatter-flat-copy.wgsl.jinja)- [`scatter-narrow-wrap.wgsl.jinja`](https://huggingface.co/kernels/webgpu-kernels/ai.onnx.ScatterElements/blob/v1/build/webgpu/scatter-narrow-wrap.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.ScatterElements", { version: 1 });const dataData = Uint32Array.of(1, 2, 3);const indicesData = Int32Array.of(2, 0);const updatesData = Uint32Array.of(9, 8);const { output } = await kernel({data: { data: dataData, shape: [3] },indices: { data: indicesData, shape: [2] },updates: { data: updatesData, shape: [2] },});console.log({ output });```
4 unmodified lines5678910114 unmodified lines"attrs": { "axis": 1 },"inputs": {"data": { "dtype": "float32", "shape": [1024, 768] },"indices": { "dtype": "int32", "shape": [1024, 128], "min": 0, "max": 768 },"updates": { "dtype": "float32", "shape": [1024, 128] }},"outputs": { "output": { "dtype": "float32", "shape": [1024, 768] } }4 unmodified lines5678910114 unmodified lines"attrs": { "axis": 1 },"inputs": {"data": { "dtype": "float32", "shape": [1024, 768] },"indices": { "dtype": "int32", "shape": [1024, 128], "dist": "linearMod", "step": 137, "mod": 768 },"updates": { "dtype": "float32", "shape": [1024, 128] }},"outputs": { "output": { "dtype": "float32", "shape": [1024, 768] } }
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383{"domain": "ai.onnx","name": "ScatterElements","sinceVersion": 18,"inputs": { "data": { "dtype": "T" }, "indices": { "dtype": "I" }, "updates": { "dtype": "T" } },"outputs": { "output": { "dtype": "T", "rank": "ranks.data", "shape": "shapes.data" } },"attributes": { "axis": { "default": 0 }, "reduction": { "default": "none" } },"attributeConstraints": { "reduction": { "values": ["none", "add", "mul", "max", "min"] } },"typeConstraints": {"T": ["float32", "float16", "int32", "uint32", "int8", "uint8", "int16", "bool", "int64"],"I": ["int32"]},"tunables": {"WORKGROUP_SIZE": { "default": 256 },"ATOMIC_WORKGROUP_SIZE": { "default": 64 },"F16_ATOMIC_MIN_AXIS": { "default": 1024 },"F16_ATOMIC_MAX_SLICES": { "default": 2048 },"SUBGROUP_PREAGG_ROUNDS": { "default": 2 },"F16_SLAB_MIN_OUTER": { "default": 8 },"F16_SLAB_MIN_CELLS": { "default": 32 },"F16_SLAB_MAX_SLABS": { "default": 4 },"F16_ATOMIC_WORKGROUP_SIZE": { "default": 256 },"ATOMIC_UPDATES_PER_LANE": { "default": 2 },"HISTOGRAM_TARGET_WORKGROUPS": { "default": 256 }},"derive": {"deviceWorkgroupCap": "min(device.limits.maxComputeInvocationsPerWorkgroup, device.limits.maxComputeWorkgroupSizeX)","storageBufferLimit": "min(device.limits.maxStorageBufferBindingSize, device.limits.maxBufferSize)","wave32Adapter": "has(device.adapterInfo, \"subgroupMinSize\") and has(device.adapterInfo, \"subgroupMaxSize\") and device.adapterInfo.subgroupMinSize == 32 and device.adapterInfo.subgroupMaxSize == 32","reportedNonWave32Adapter": "not wave32Adapter and (has(device.adapterInfo, \"subgroupMinSize\") or has(device.adapterInfo, \"subgroupMaxSize\"))","narrowIntData": "tensorDtypes.data == \"int8\" or tensorDtypes.data == \"uint8\" or tensorDtypes.data == \"int16\"","indexScalar": "dtypes.I","copyElementType": "(\"vec4<\" ~ dtypes.T ~ \">\") if dtypes.T != \"vec2<u32>\" and numel(shapes.output) % 4 == 0 else dtypes.T","reductionOp": "attrs.reduction","narrowBits": "8 if tensorDtypes.data == \"int8\" or tensorDtypes.data == \"uint8\" else (16 if tensorDtypes.data == \"int16\" else 0)","narrowSigned": "tensorDtypes.data == \"int8\" or tensorDtypes.data == \"int16\"","boolData": "tensorDtypes.data == \"bool\"","dataShape": "shapes.data","updatesShape": "shapes.updates","axis": "attrs.axis if attrs.axis >= 0 else attrs.axis + ranks.data","updateSlices": "numel(shapes.updates) / dim(shapes.updates, axis) if dim(shapes.updates, axis) > 0 else 0","workgroupSize": "min(tunables.WORKGROUP_SIZE, deviceWorkgroupCap)","atomicWorkgroupSize": "min(tunables.ATOMIC_WORKGROUP_SIZE, deviceWorkgroupCap)","f16AtomicWorkgroupSize": "min(tunables.F16_ATOMIC_WORKGROUP_SIZE, deviceWorkgroupCap)","bindingsFit": "numel(shapes.data) * dtypeBytes(dtypes.T) <= storageBufferLimit and numel(shapes.indices) * dtypeBytes(dtypes.I) <= storageBufferLimit and numel(shapes.updates) * dtypeBytes(dtypes.T) <= storageBufferLimit and numel(shapes.output) * dtypeBytes(dtypes.T) <= storageBufferLimit","dispatchFits": "max(numel(shapes.output), numel(shapes.updates)) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) * min(device.limits.maxComputeWorkgroupsPerDimension, 65535) * workgroupSize","f16AccumFits": "numel(shapes.output) * dtypeBytes(\"uint32\") <= storageBufferLimit","validLayout": "workgroupSize > 0 and bindingsFit and dispatchFits and ranks.data == ranks.output and ranks.indices == ranks.updates and ranks.data >= 1 and ranks.indices == ranks.data and attrs.axis + ranks.data >= 0 and attrs.axis < ranks.data and numel(shapes.data) == numel(shapes.output) and numel(shapes.indices) == numel(shapes.updates)","slabInner": "inner(shapes.data, axis)","slabOuter": "outer(shapes.data, axis)","slabCells": "dim(shapes.data, axis) * slabInner","slabBytes": "slabCells * dtypeBytes(\"uint32\")","slabWorkgroupSize": "min(workgroupSize, pow2ceil(max(slabCells, tunables.F16_SLAB_MIN_CELLS)))","slabsPerWorkgroup": "max(1, min(tunables.F16_SLAB_MAX_SLABS, floor(device.limits.maxComputeWorkgroupStorageSize / max(slabBytes, 4))))","slabVec4": "slabCells % 4 == 0","slabUpdatesMatchData": "sameShape(prefix(shapes.updates, axis), prefix(shapes.data, axis)) and sameShape(suffix(shapes.updates, axis + 1), suffix(shapes.data, axis + 1))","slabElement": "\"vec4<f16>\" if slabVec4 else \"f16\"","histogramColumnLanes": 32,"histogramRowLanes": 8,"histogramColumnGroups": "ceilDiv(max(dim(shapes.data, 1), 1), histogramColumnLanes)","histogramStripeCap": "max(1, floor(dim(shapes.updates, 0) / (4 * max(dim(shapes.data, 0), 1))))","histogramStripes": "max(1, min(ceilDiv(tunables.HISTOGRAM_TARGET_WORKGROUPS, histogramColumnGroups), histogramStripeCap, ceilDiv(dim(shapes.updates, 0), histogramRowLanes)))","updatesPerLane": "tunables.ATOMIC_UPDATES_PER_LANE","rank": "ranks.data","axisSpec": "axis"},"bindings": {"indices": { "elementType": "$indexScalar" },"params": {"struct": [{"name": "count","type": "u32","value": "numel(shapes.output) / 4 if numel(shapes.output) % 4 == 0 else numel(shapes.output)"}]},"updates_f16": { "name": "updates", "elementType": "f16" },"output_scatter": { "scratch": "accum", "name": "output", "elementType": "atomic<u32>" },"params_scatter": {"name": "params","struct": [{ "name": "count", "type": "u32", "value": "numel(shapes.updates)" },{ "name": "axisDim", "type": "u32", "value": "dim(shapes.data, axis)" }]},"params_init": { "name": "params", "struct": [{ "name": "count", "type": "u32", "value": "numel(shapes.output)" }] },"src": { "arg": "data", "elementType": "$copyElementType" },"dst": { "arg": "output", "elementType": "$copyElementType" },"updates_scatter": { "name": "updates", "elementType": "$updateElement" },"output_generic": { "name": "output", "elementType": "$outputElement" }},"when": ["dtypes.T != \"vec2<u32>\" or attrs.reduction == \"none\""],"variants": [{"id": "reduction_f32_add_axis0_histogram","priority": 35,"when": ["attrs.reduction == \"add\"", "device.features.has(\"subgroups\")", "(attrs.axis == 0 or attrs.axis == -2)", "dtypes.T == \"f32\"", "ranks.data == 2", "ranks.indices == 2", "ranks.updates == 2", "ranks.output == 2", "dim(shapes.data, 0) > 0", "dim(shapes.data, 0) * histogramColumnLanes * 4 <= device.limits.maxComputeWorkgroupStorageSize", "dim(shapes.data, 1) >= histogramColumnLanes", "histogramColumnGroups <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535)", "dim(shapes.output, 0) == dim(shapes.data, 0)", "dim(shapes.output, 1) == dim(shapes.data, 1)", "dim(shapes.indices, 0) == dim(shapes.updates, 0)", "dim(shapes.indices, 1) == dim(shapes.updates, 1)", "dim(shapes.updates, 0) >= 1024", "dim(shapes.updates, 1) == dim(shapes.data, 1)"],"derive": {"scalar": "dtypes.T","useSubgroups": false,"updateElement": "dtypes.T","outputElement": "\"atomic<u32>\""},"passes": [{"id": "copy","name": "ScatterElements.Copy","shader": "scatter-flat-copy.wgsl.jinja","derive": {"count": "numel(shapes.output) / 4 if numel(shapes.output) % 4 == 0 else numel(shapes.output)","workgroupSize": "tunables.WORKGROUP_SIZE"},"bindings": ["src", "dst"],"dispatch": {"x": "min(ceilDiv((numel(shapes.output) / 4 if numel(shapes.output) % 4 == 0 else numel(shapes.output)), (tunables.WORKGROUP_SIZE)), 65535)","y": "ceilDiv(ceilDiv((numel(shapes.output) / 4 if numel(shapes.output) % 4 == 0 else numel(shapes.output)), (tunables.WORKGROUP_SIZE)), 65535)","z": 1}},{"id": "histogram","name": "ScatterElements.F32AddAxis0Histogram","shader": "scatter-elements-f32-add-axis0-histogram.wgsl.jinja","derive": {"dataRows": "dim(shapes.data, 0)","columns": "dim(shapes.data, 1)","updateRows": "dim(shapes.updates, 0)","rowStripes": "histogramStripes"},"bindings": ["indices", "updates_scatter", "output_generic"],"dispatch": { "x": "histogramColumnGroups", "y": "histogramStripes" }}]},{"id": "reduction_f16_atomic_f32","priority": 30,"when": ["(attrs.reduction == \"add\" or attrs.reduction == \"min\" or attrs.reduction == \"max\")", "dtypes.T == \"f16\"", "validLayout", "(dim(shapes.updates, axis) >= tunables.F16_ATOMIC_MIN_AXIS or updateSlices < tunables.F16_ATOMIC_MAX_SLICES)", "f16AccumFits", "f16Ok(dtypes.T)"],"derive": {"scalar": "\"f32\"","useSubgroups": "device.features.has(\"subgroups\") and attrs.reduction == \"add\" and inner(shapes.updates, axis) == 1","preaggRounds": "tunables.SUBGROUP_PREAGG_ROUNDS","workgroupSize": "f16AtomicWorkgroupSize","narrowElement": "\"vec4<f16>\" if numel(shapes.output) % 4 == 0 else \"f16\"","wideElement": "\"vec4<u32>\" if numel(shapes.output) % 4 == 0 else \"u32\""},"intermediates": [{ "id": "accum", "dtype": "uint32", "shape": "[numel(shapes.output)]" }],"passes": [{"id": "init","name": "ScatterElements.F16InitF32","shader": "scatter-f16-f32-convert.wgsl.jinja","derive": { "toWide": true, "vec4": "numel(shapes.output) % 4 == 0" },"bindings": [{ "arg": "data", "name": "narrow", "elementType": "$narrowElement" },{ "scratch": "accum", "name": "wide", "elementType": "$wideElement" },"params"],"dispatch": {"x": "min(ceilDiv((numel(shapes.output) / 4 if numel(shapes.output) % 4 == 0 else numel(shapes.output)), (f16AtomicWorkgroupSize)), 65535)","y": "ceilDiv(ceilDiv((numel(shapes.output) / 4 if numel(shapes.output) % 4 == 0 else numel(shapes.output)), (f16AtomicWorkgroupSize)), 65535)","z": 1}},{"id": "scatter","name": "ScatterElements.F16AtomicF32","shader": "scatter-elements-reduction-atomic.wgsl.jinja","bindings": ["indices", "updates_f16", "output_scatter", "params_scatter"],"dispatch": {"x": "min(ceilDiv((ceilDiv(numel(shapes.updates), tunables.ATOMIC_UPDATES_PER_LANE)), (f16AtomicWorkgroupSize)), 65535)","y": "ceilDiv(ceilDiv((ceilDiv(numel(shapes.updates), tunables.ATOMIC_UPDATES_PER_LANE)), (f16AtomicWorkgroupSize)), 65535)","z": 1}},{"id": "finalize","name": "ScatterElements.F16FinalizeF32","shader": "scatter-f16-f32-convert.wgsl.jinja","derive": { "toWide": false, "vec4": "numel(shapes.output) % 4 == 0" },"bindings": [{ "scratch": "accum", "name": "wide", "buffer": "read-only-storage", "elementType": "$wideElement" },{ "arg": "output", "name": "narrow", "elementType": "$narrowElement" },"params"],"dispatch": {"x": "min(ceilDiv((numel(shapes.output) / 4 if numel(shapes.output) % 4 == 0 else numel(shapes.output)), (f16AtomicWorkgroupSize)), 65535)","y": "ceilDiv(ceilDiv((numel(shapes.output) / 4 if numel(shapes.output) % 4 == 0 else numel(shapes.output)), (f16AtomicWorkgroupSize)), 65535)","z": 1}}]},{"id": "reduction_f16_slab","priority": 35,"when": ["(attrs.reduction == \"add\" or attrs.reduction == \"min\" or attrs.reduction == \"max\" or attrs.reduction == \"mul\")", "dtypes.T == \"f16\"", "validLayout", "slabUpdatesMatchData", "slabCells >= tunables.F16_SLAB_MIN_CELLS", "slabOuter >= tunables.F16_SLAB_MIN_OUTER", "slabBytes <= device.limits.maxComputeWorkgroupStorageSize", "f16Ok(dtypes.T)", "not reportedNonWave32Adapter"],"derive": { "workgroupSize": "slabWorkgroupSize" },"passes": [{"id": "scatter","name": "ScatterElements.F16SlabReduction","shader": "scatter-elements-reduction-slab.wgsl.jinja","derive": {"innerSize": "slabInner","axisDimSpec": "dim(shapes.data, axis)","updateAxisDim": "dim(shapes.updates, axis)","outerSize": "slabOuter"},"bindings": [{ "arg": "data", "elementType": "$slabElement" },"indices","updates_f16",{ "arg": "output", "elementType": "$slabElement" }],"dispatch": {"x": "min(ceilDiv(slabOuter, slabsPerWorkgroup), 65535)","y": "ceilDiv(ceilDiv(slabOuter, slabsPerWorkgroup), 65535)","z": 1}}]},{"id": "reduction_narrow_wrap_atomic","priority": 26,"when": ["(attrs.reduction == \"add\" or attrs.reduction == \"mul\")", "validLayout", "narrowIntData"],"derive": {"scalar": "\"u32\"","useSubgroups": "device.features.has(\"subgroups\") and inner(shapes.updates, axis) == 1","preaggRounds": "tunables.SUBGROUP_PREAGG_ROUNDS","workgroupSize": "atomicWorkgroupSize","updateElement": "\"u32\"","outputElement": "\"atomic<u32>\""},"passes": [{"id": "copy","name": "ScatterElements.Copy","shader": "scatter-flat-copy.wgsl.jinja","derive": {"count": "numel(shapes.output) / 4 if dtypes.T != \"vec2<u32>\" and numel(shapes.output) % 4 == 0 else numel(shapes.output)"},"bindings": ["src", "dst"],"dispatch": {"x": "min(ceilDiv((numel(shapes.output) / 4 if dtypes.T != \"vec2<u32>\" and numel(shapes.output) % 4 == 0 else numel(shapes.output)), (workgroupSize)), 65535)","y": "ceilDiv(ceilDiv((numel(shapes.output) / 4 if dtypes.T != \"vec2<u32>\" and numel(shapes.output) % 4 == 0 else numel(shapes.output)), (workgroupSize)), 65535)","z": 1}},{"id": "scatter","name": "ScatterElements.NarrowWrapAtomic","shader": "scatter-elements-reduction-atomic.wgsl.jinja","bindings": ["indices", "updates_scatter", "output_generic", "params_scatter"],"dispatch": {"x": "min(ceilDiv((ceilDiv(numel(shapes.updates), tunables.ATOMIC_UPDATES_PER_LANE)), (atomicWorkgroupSize)), 65535)","y": "ceilDiv(ceilDiv((ceilDiv(numel(shapes.updates), tunables.ATOMIC_UPDATES_PER_LANE)), (atomicWorkgroupSize)), 65535)","z": 1}},{"id": "narrow","name": "ScatterElements.NarrowWrapFinalize","shader": "scatter-narrow-wrap.wgsl.jinja","bindings": [{ "arg": "output", "name": "values", "elementType": "u32" }, "params_init"],"dispatch": {"x": "min(ceilDiv((numel(shapes.output)), (workgroupSize)), 65535)","y": "ceilDiv(ceilDiv((numel(shapes.output)), (workgroupSize)), 65535)","z": 1}}]},{"id": "generic","priority": 0,"when": ["attrs.reduction == \"none\"", "validLayout", "f16Ok(dtypes.T)"],"derive": { "updateElement": "dtypes.T", "outputElement": "dtypes.T" },"passes": [{"id": "copy","name": "ScatterElements.Copy","shader": "scatter-flat-copy.wgsl.jinja","derive": {"count": "numel(shapes.output) / 4 if dtypes.T != \"vec2<u32>\" and numel(shapes.output) % 4 == 0 else numel(shapes.output)"},"bindings": ["src", "dst"],"dispatch": {"x": "min(ceilDiv((numel(shapes.output) / 4 if dtypes.T != \"vec2<u32>\" and numel(shapes.output) % 4 == 0 else numel(shapes.output)), (workgroupSize)), 65535)","y": "ceilDiv(ceilDiv((numel(shapes.output) / 4 if dtypes.T != \"vec2<u32>\" and numel(shapes.output) % 4 == 0 else numel(shapes.output)), (workgroupSize)), 65535)","z": 1}},{"id": "scatter","name": "ScatterElements.Scatter","shader": "scatter-elements.wgsl.jinja","bindings": ["indices", "updates_scatter", "output_generic", "params_scatter"],"dispatch": {"x": "min(ceilDiv((numel(shapes.updates)), (workgroupSize)), 65535)","y": "ceilDiv(ceilDiv((numel(shapes.updates)), (workgroupSize)), 65535)","z": 1}}]},{"id": "reduction_atomic","priority": 25,"when": ["(attrs.reduction == \"add\" or attrs.reduction == \"mul\" or attrs.reduction == \"min\" or attrs.reduction == \"max\")", "validLayout", "(tensorDtypes.data == \"float32\" or tensorDtypes.data == \"int32\" or tensorDtypes.data == \"uint32\" or (narrowIntData and (attrs.reduction == \"min\" or attrs.reduction == \"max\")))"],"derive": {"scalar": "dtypes.T","useSubgroups": "device.features.has(\"subgroups\") and (attrs.reduction == \"add\" or attrs.reduction == \"mul\") and inner(shapes.updates, axis) == 1","preaggRounds": "tunables.SUBGROUP_PREAGG_ROUNDS","workgroupSize": "atomicWorkgroupSize","updateElement": "dtypes.T","outputElement": "\"atomic<i32>\" if dtypes.T == \"i32\" else \"atomic<u32>\""},"passes": [{"id": "copy","name": "ScatterElements.Copy","shader": "scatter-flat-copy.wgsl.jinja","derive": {"count": "numel(shapes.output) / 4 if dtypes.T != \"vec2<u32>\" and numel(shapes.output) % 4 == 0 else numel(shapes.output)"},"bindings": ["src", "dst"],"dispatch": {"x": "min(ceilDiv((numel(shapes.output) / 4 if dtypes.T != \"vec2<u32>\" and numel(shapes.output) % 4 == 0 else numel(shapes.output)), (workgroupSize)), 65535)","y": "ceilDiv(ceilDiv((numel(shapes.output) / 4 if dtypes.T != \"vec2<u32>\" and numel(shapes.output) % 4 == 0 else numel(shapes.output)), (workgroupSize)), 65535)","z": 1}},{"id": "scatter","name": "ScatterElements.ReductionAtomic","shader": "scatter-elements-reduction-atomic.wgsl.jinja","bindings": ["indices", "updates_scatter", "output_generic", "params_scatter"],"dispatch": {"x": "min(ceilDiv((ceilDiv(numel(shapes.updates), tunables.ATOMIC_UPDATES_PER_LANE)), (atomicWorkgroupSize)), 65535)","y": "ceilDiv(ceilDiv((ceilDiv(numel(shapes.updates), tunables.ATOMIC_UPDATES_PER_LANE)), (atomicWorkgroupSize)), 65535)","z": 1}}]},{"id": "reduction_slice","priority": 20,"when": ["(attrs.reduction == \"add\" or attrs.reduction == \"mul\" or attrs.reduction == \"min\" or attrs.reduction == \"max\")", "validLayout", "f16Ok(dtypes.T)"],"derive": { "scalar": "dtypes.T", "updateElement": "dtypes.T", "outputElement": "dtypes.T" },"passes": [{"id": "copy","name": "ScatterElements.Copy","shader": "scatter-flat-copy.wgsl.jinja","derive": {"count": "numel(shapes.output) / 4 if dtypes.T != \"vec2<u32>\" and numel(shapes.output) % 4 == 0 else numel(shapes.output)"},"bindings": ["src", "dst"],"dispatch": {"x": "min(ceilDiv((numel(shapes.output) / 4 if dtypes.T != \"vec2<u32>\" and numel(shapes.output) % 4 == 0 else numel(shapes.output)), (workgroupSize)), 65535)","y": "ceilDiv(ceilDiv((numel(shapes.output) / 4 if dtypes.T != \"vec2<u32>\" and numel(shapes.output) % 4 == 0 else numel(shapes.output)), (workgroupSize)), 65535)","z": 1}},{"id": "scatter","name": "ScatterElements.Reduction","shader": "scatter-elements-reduction.wgsl.jinja","bindings": ["indices", "updates_scatter", "output_generic", "params_scatter"],"dispatch": {"x": "min(ceilDiv((updateSlices), (workgroupSize)), min(device.limits.maxComputeWorkgroupsPerDimension, 65535))","y": 1,"z": 1}}]}]}1{"domain":"ai.onnx","name":"ScatterElements","sinceVersion":18,"inputs":{"data":{"dtype":"T"},"indices":{"dtype":"I"},"updates":{"dtype":"T"}},"outputs":{"output":{"dtype":"T","rank":"ranks.data","shape":"shapes.data"}},"attributes":{"axis":{"default":0},"reduction":{"default":"none"}},"attributeConstraints":{"reduction":{"values":["none","add","mul","max","min"]}},"typeConstraints":{"T":["float32","float16","int32","uint32","int8","uint8","int16","bool","int64"],"I":["int32"]},"tunables":{"WORKGROUP_SIZE":{"default":256},"ATOMIC_WORKGROUP_SIZE":{"default":64},"F16_ATOMIC_MIN_AXIS":{"default":1024},"F16_ATOMIC_MAX_SLICES":{"default":2048},"SUBGROUP_PREAGG_ROUNDS":{"default":2},"F16_SLAB_MIN_OUTER":{"default":8},"F16_SLAB_MIN_CELLS":{"default":32},"F16_SLAB_MAX_SLABS":{"default":4},"F16_ATOMIC_WORKGROUP_SIZE":{"default":256},"ATOMIC_UPDATES_PER_LANE":{"default":2},"HISTOGRAM_TARGET_WORKGROUPS":{"default":256},"OWNED_ROW_MAX_AXIS":{"default":16},"ORDERED_GLOBAL_MAX_BYTES":{"default":2097152},"ORDERED_GLOBAL_LOCAL_CHAIN":{"default":16},"ORDERED_GLOBAL_MAX_FALLBACK_STEPS":{"default":268435456}},"derive":{"deviceWorkgroupCap":"min(device.limits.maxComputeInvocationsPerWorkgroup, device.limits.maxComputeWorkgroupSizeX)","storageBufferLimit":"min(device.limits.maxStorageBufferBindingSize, device.limits.maxBufferSize)","wave32Adapter":"has(device.adapterInfo, \"subgroupMinSize\") and has(device.adapterInfo, \"subgroupMaxSize\") and device.adapterInfo.subgroupMinSize == 32 and device.adapterInfo.subgroupMaxSize == 32","reportedNonWave32Adapter":"not wave32Adapter and (has(device.adapterInfo, \"subgroupMinSize\") or has(device.adapterInfo, \"subgroupMaxSize\"))","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","narrowIntData":"tensorDtypes.data == \"int8\" or tensorDtypes.data == \"uint8\" or tensorDtypes.data == \"int16\"","indexScalar":"dtypes.I","copyElementType":"(\"vec4<\" ~ dtypes.T ~ \">\") if dtypes.T != \"vec2<u32>\" and numel(shapes.output) % 4 == 0 else dtypes.T","reductionOp":"attrs.reduction","narrowBits":"8 if tensorDtypes.data == \"int8\" or tensorDtypes.data == \"uint8\" else (16 if tensorDtypes.data == \"int16\" else 0)","narrowSigned":"tensorDtypes.data == \"int8\" or tensorDtypes.data == \"int16\"","boolData":"tensorDtypes.data == \"bool\"","dataShape":"shapes.data","updatesShape":"shapes.updates","axis":"attrs.axis if attrs.axis >= 0 else attrs.axis + ranks.data","updateSlices":"numel(shapes.updates) / dim(shapes.updates, axis) if dim(shapes.updates, axis) > 0 else 0","workgroupSize":"min(tunables.WORKGROUP_SIZE, deviceWorkgroupCap)","atomicWorkgroupSize":"min(tunables.ATOMIC_WORKGROUP_SIZE, deviceWorkgroupCap)","f16AtomicWorkgroupSize":"min(tunables.F16_ATOMIC_WORKGROUP_SIZE, deviceWorkgroupCap)","bindingsFit":"numel(shapes.data) * dtypeBytes(dtypes.T) <= storageBufferLimit and numel(shapes.indices) * dtypeBytes(dtypes.I) <= storageBufferLimit and numel(shapes.updates) * dtypeBytes(dtypes.T) <= storageBufferLimit and numel(shapes.output) * dtypeBytes(dtypes.T) <= storageBufferLimit","dispatchFits":"max(numel(shapes.output), numel(shapes.updates)) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) * min(device.limits.maxComputeWorkgroupsPerDimension, 65535) * workgroupSize","f16AccumFits":"numel(shapes.output) * dtypeBytes(\"uint32\") <= storageBufferLimit","validLayout":"workgroupSize > 0 and bindingsFit and dispatchFits and ranks.data == ranks.output and ranks.indices == ranks.updates and ranks.data >= 1 and ranks.indices == ranks.data and attrs.axis + ranks.data >= 0 and attrs.axis < ranks.data and numel(shapes.data) == numel(shapes.output) and numel(shapes.indices) == numel(shapes.updates)","slabInner":"inner(shapes.data, axis)","slabOuter":"outer(shapes.data, axis)","slabCells":"dim(shapes.data, axis) * slabInner","slabBytes":"slabCells * dtypeBytes(\"uint32\")","slabWorkgroupSize":"min(workgroupSize, pow2ceil(max(slabCells, tunables.F16_SLAB_MIN_CELLS)))","slabsPerWorkgroup":"max(1, min(tunables.F16_SLAB_MAX_SLABS, floor(device.limits.maxComputeWorkgroupStorageSize / max(slabBytes, 4))))","slabVec4":"slabCells % 4 == 0","slabUpdatesMatchData":"sameShape(prefix(shapes.updates, axis), prefix(shapes.data, axis)) and sameShape(suffix(shapes.updates, axis + 1), suffix(shapes.data, axis + 1))","slabElement":"\"vec4<f16>\" if slabVec4 else \"f16\"","histogramColumnLanes":32,"histogramRowLanes":8,"histogramColumnGroups":"ceilDiv(max(dim(shapes.data, 1), 1), histogramColumnLanes)","histogramStripeCap":"max(1, floor(dim(shapes.updates, 0) / (4 * max(dim(shapes.data, 0), 1))))","histogramStripes":"max(1, min(ceilDiv(tunables.HISTOGRAM_TARGET_WORKGROUPS, histogramColumnGroups), histogramStripeCap, ceilDiv(dim(shapes.updates, 0), histogramRowLanes)))","updatesPerLane":"tunables.ATOMIC_UPDATES_PER_LANE","rank":"ranks.data","axisSpec":"axis","orderedSlabUpdates":"dim(shapes.updates, axis) * slabInner","orderedSlabHeadWords":"ceilDiv(slabCells, 2)","orderedSlabBytes":"ceilDiv(orderedSlabHeadWords * 4, 16) * 16 + ceilDiv(max(orderedSlabUpdates, 1) * 4, 16) * 16","orderedChunkWorkgroupSize":"workgroupSize / 2 if updateSlices >= workgroupSize and workgroupSize >= 2 else workgroupSize","orderedDirectStageCapacity":"floor((device.limits.maxComputeWorkgroupStorageSize - 32) / (dtypeBytes(\"uint32\") + dtypeBytes(\"float16\"))) - orderedChunkWorkgroupSize","orderedStageTarget":"min(dim(shapes.data, axis), max(1, floor(device.limits.maxComputeWorkgroupStorageSize / 4)))","orderedStageCells":"orderedStageTarget if device.features.has(\"subgroups\") else min(orderedStageTarget, max(1, 2 * floor(orderedDirectStageCapacity / 2)))","orderedStagesPerColumn":"ceilDiv(dim(shapes.data, axis), orderedStageCells) if dim(shapes.data, axis) > 0 else 0","orderedGlobalChainCapacity":"min(max(1, floor(tunables.ORDERED_GLOBAL_LOCAL_CHAIN)), device.adapterInfo.subgroupMinSize) if variableSubgroup16To32 else 1","orderedGlobalFallbackSteps":"floor(dim(shapes.updates, axis) / (orderedGlobalChainCapacity + 1)) * dim(shapes.updates, axis)","orderedGlobalBytesPerColumn":"4 * (dim(shapes.data, axis) + dim(shapes.updates, axis))","orderedGlobalColumns":"min(updateSlices, floor(min(tunables.ORDERED_GLOBAL_MAX_BYTES, device.limits.maxStorageBufferBindingSize, device.limits.maxBufferSize) / max(1, orderedGlobalBytesPerColumn)), floor(tunables.ORDERED_GLOBAL_MAX_FALLBACK_STEPS / max(1, orderedGlobalFallbackSteps)))","orderedGlobalHeadCells":"orderedGlobalColumns * dim(shapes.data, axis)","orderedGlobalLinkCells":"orderedGlobalColumns * dim(shapes.updates, axis)"},"bindings":{"indices":{"elementType":"$indexScalar"},"params":{"struct":[{"name":"count","type":"u32","value":"numel(shapes.output) / 4 if numel(shapes.output) % 4 == 0 else numel(shapes.output)"}]},"updates_f16":{"name":"updates","elementType":"f16"},"output_scatter":{"scratch":"accum","name":"output","elementType":"atomic<u32>"},"params_scatter":{"name":"params","struct":[{"name":"count","type":"u32","value":"numel(shapes.updates)"},{"name":"axisDim","type":"u32","value":"dim(shapes.data, axis)"}]},"params_init":{"name":"params","struct":[{"name":"count","type":"u32","value":"numel(shapes.output)"}]},"src":{"arg":"data","elementType":"$copyElementType"},"dst":{"arg":"output","elementType":"$copyElementType"},"updates_scatter":{"name":"updates","elementType":"$updateElement"},"output_generic":{"name":"output","elementType":"$outputElement"},"params_ordered_columns":{"name":"params","struct":[{"name":"columnBase","type":"u32","value":"repeat.columnBatch * orderedGlobalColumns"},{"name":"columnCount","type":"u32","value":"min(orderedGlobalColumns, updateSlices - repeat.columnBatch * orderedGlobalColumns)"}]},"data_f16":{"arg":"data","elementType":"f16","name":"data"}},"when":["dtypes.T != \"vec2<u32>\" or attrs.reduction == \"none\""],"variants":[{"id":"reduction_f16_ordered_global","priority":41,"when":["variableSubgroup16To32","attrs.reduction == \"add\"","dtypes.T == \"f16\"","validLayout","slabUpdatesMatchData","slabInner == 1","dim(shapes.data, axis) > 0","dim(shapes.data, axis) % 2 == 0","dim(shapes.updates, axis) > 0","dim(shapes.updates, axis) <= 2 * dim(shapes.data, axis)","orderedGlobalColumns >= 1","updateSlices < 4 * workgroupSize","orderedGlobalHeadCells <= DISPATCH_FOLD_WIDTH * min(device.limits.maxComputeWorkgroupsPerDimension, 65535) * min(workgroupSize, 2 * device.adapterInfo.subgroupMaxSize)","orderedGlobalLinkCells <= DISPATCH_FOLD_WIDTH * min(device.limits.maxComputeWorkgroupsPerDimension, 65535) * min(workgroupSize, 2 * device.adapterInfo.subgroupMaxSize)","f16Ok(dtypes.T)"],"derive":{"axisDimSpec":"dim(shapes.data, axis)","updateAxisDimSpec":"dim(shapes.updates, axis)","chainCapacity":"orderedGlobalChainCapacity","globalWorkgroupSize":"min(workgroupSize, 2 * device.adapterInfo.subgroupMaxSize)"},"intermediates":[{"id":"orderedHeads","dtype":"uint32","shape":"[orderedGlobalHeadCells]"},{"id":"orderedLinks","dtype":"uint32","shape":"[orderedGlobalLinkCells]"}],"passes":[{"id":"column_batches","repeat":{"index":"columnBatch","count":"ceilDiv(updateSlices, orderedGlobalColumns)"},"passes":[{"id":"init","shader":"scatter-elements-ordered-global.wgsl.jinja","derive":{"phase":"\"init\""},"bindings":[{"name":"heads","scratch":"orderedHeads","elementType":"atomic<u32>"},{"name":"params","struct":[{"name":"count","type":"u32","value":"(min(orderedGlobalColumns, updateSlices - repeat.columnBatch * orderedGlobalColumns)) * dim(shapes.data, axis)"}]}],"dispatch":{"x":"min(ceilDiv(((min(orderedGlobalColumns, updateSlices - repeat.columnBatch * orderedGlobalColumns)) * dim(shapes.data, axis)), (globalWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv(((min(orderedGlobalColumns, updateSlices - repeat.columnBatch * orderedGlobalColumns)) * dim(shapes.data, axis)), (globalWorkgroupSize)), 65535)","z":1}},{"id":"link","shader":"scatter-elements-ordered-global.wgsl.jinja","derive":{"phase":"\"link\""},"bindings":["indices",{"name":"heads","scratch":"orderedHeads","elementType":"atomic<u32>"},{"name":"links","scratch":"orderedLinks","elementType":"u32"},"params_ordered_columns"],"dispatch":{"x":"min(ceilDiv(((min(orderedGlobalColumns, updateSlices - repeat.columnBatch * orderedGlobalColumns)) * dim(shapes.updates, axis)), (globalWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv(((min(orderedGlobalColumns, updateSlices - repeat.columnBatch * orderedGlobalColumns)) * dim(shapes.updates, axis)), (globalWorkgroupSize)), 65535)","z":1}},{"id":"apply","shader":"scatter-elements-ordered-global.wgsl.jinja","derive":{"phase":"\"apply\""},"bindings":[{"arg":"data","elementType":"vec2<f16>"},"indices","updates_f16",{"name":"heads","scratch":"orderedHeads","elementType":"u32","buffer":"read-only-storage"},{"name":"links","scratch":"orderedLinks","elementType":"u32","buffer":"read-only-storage"},{"arg":"output","elementType":"vec2<f16>"},"params_ordered_columns"],"dispatch":{"x":"min(ceilDiv(((min(orderedGlobalColumns, updateSlices - repeat.columnBatch * orderedGlobalColumns)) * dim(shapes.data, axis) / 2), (globalWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv(((min(orderedGlobalColumns, updateSlices - repeat.columnBatch * orderedGlobalColumns)) * dim(shapes.data, axis) / 2), (globalWorkgroupSize)), 65535)","z":1}}]}],"demoteWhen":["numel(shapes.data) < 4 * workgroupSize or dim(shapes.updates, axis) < workgroupSize"]},{"id":"reduction_f16_ordered_chunks","priority":39,"when":["attrs.reduction == \"add\"","dtypes.T == \"f16\"","validLayout","slabUpdatesMatchData","f16Ok(dtypes.T)","dim(shapes.data, axis) > 0","numel(shapes.updates) > 0","dim(shapes.updates, axis) >= workgroupSize","updateSlices < 4 * workgroupSize","orderedChunkWorkgroupSize >= 2","pow2ceil(orderedChunkWorkgroupSize) == orderedChunkWorkgroupSize","orderedChunkWorkgroupSize * 32 + 32 + orderedStageTarget * 2 <= device.limits.maxComputeWorkgroupStorageSize","updateSlices * orderedStagesPerColumn <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) * min(device.limits.maxComputeWorkgroupsPerDimension, 65535)"],"derive":{"chunkWorkgroupSize":"orderedChunkWorkgroupSize","stageCells":"orderedStageCells","stagesPerColumn":"orderedStagesPerColumn","axisDimSpec":"dim(shapes.data, axis)","updateAxisDimSpec":"dim(shapes.updates, axis)","useDirectHeads":"stageCells <= orderedDirectStageCapacity"},"passes":[{"id":"scatter","shader":"scatter-elements-ordered-chunks.wgsl.jinja","bindings":["data_f16","indices","updates_f16",{"arg":"output","elementType":"f16"}],"dispatch":{"x":"min(updateSlices * stagesPerColumn, 65535)","y":"ceilDiv(updateSlices * stagesPerColumn, 65535)","z":1}}]},{"id":"reduction_f16_ordered_list","priority":40,"when":["attrs.reduction == \"add\"","dtypes.T == \"f16\"","validLayout","slabUpdatesMatchData","slabCells >= tunables.F16_SLAB_MIN_CELLS","slabOuter >= tunables.F16_SLAB_MIN_OUTER","f16Ok(dtypes.T)","orderedSlabBytes <= device.limits.maxComputeWorkgroupStorageSize","orderedSlabUpdates < 65535","orderedSlabUpdates > 0","slabOuter <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) * min(device.limits.maxComputeWorkgroupsPerDimension, 65535)"],"derive":{"workgroupSize":"min(tunables.WORKGROUP_SIZE, deviceWorkgroupCap)"},"passes":[{"id":"main","shader":"scatter-elements-ordered-list.wgsl.jinja","derive":{"innerSize":"slabInner","axisDimSpec":"dim(shapes.data, axis)","slabCells":"slabCells","updateSlab":"orderedSlabUpdates","outerSize":"slabOuter","headWords":"orderedSlabHeadWords"},"bindings":["data_f16","indices","updates_f16",{"arg":"output","elementType":"f16"}],"dispatch":{"x":"min(slabOuter, 65535)","y":"ceilDiv(slabOuter, 65535)","z":1}}]},{"id":"reduction_f32_add_axis0_histogram","priority":35,"when":["attrs.reduction == \"add\"","device.features.has(\"subgroups\")","(attrs.axis == 0 or attrs.axis == -2)","dtypes.T == \"f32\"","ranks.data == 2","ranks.indices == 2","ranks.updates == 2","ranks.output == 2","dim(shapes.data, 0) > 0","dim(shapes.data, 0) * histogramColumnLanes * 4 <= device.limits.maxComputeWorkgroupStorageSize","dim(shapes.data, 1) >= histogramColumnLanes","histogramColumnGroups <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535)","dim(shapes.output, 0) == dim(shapes.data, 0)","dim(shapes.output, 1) == dim(shapes.data, 1)","dim(shapes.indices, 0) == dim(shapes.updates, 0)","dim(shapes.indices, 1) == dim(shapes.updates, 1)","dim(shapes.updates, 0) >= 1024","dim(shapes.updates, 1) == dim(shapes.data, 1)"],"derive":{"scalar":"dtypes.T","useSubgroups":false,"updateElement":"dtypes.T","outputElement":"\"atomic<u32>\""},"passes":[{"id":"copy","name":"ScatterElements.Copy","shader":"scatter-flat-copy.wgsl.jinja","derive":{"count":"numel(shapes.output) / 4 if numel(shapes.output) % 4 == 0 else numel(shapes.output)","workgroupSize":"tunables.WORKGROUP_SIZE"},"bindings":["src","dst"],"dispatch":{"x":"min(ceilDiv((numel(shapes.output) / 4 if numel(shapes.output) % 4 == 0 else numel(shapes.output)), (tunables.WORKGROUP_SIZE)), 65535)","y":"ceilDiv(ceilDiv((numel(shapes.output) / 4 if numel(shapes.output) % 4 == 0 else numel(shapes.output)), (tunables.WORKGROUP_SIZE)), 65535)","z":1}},{"id":"histogram","name":"ScatterElements.F32AddAxis0Histogram","shader":"scatter-elements-f32-add-axis0-histogram.wgsl.jinja","derive":{"dataRows":"dim(shapes.data, 0)","columns":"dim(shapes.data, 1)","updateRows":"dim(shapes.updates, 0)","rowStripes":"histogramStripes"},"bindings":["indices","updates_scatter","output_generic"],"dispatch":{"x":"histogramColumnGroups","y":"histogramStripes"}}]},{"id":"reduction_f16_atomic_f32","priority":30,"when":["(attrs.reduction == \"min\" or attrs.reduction == \"max\")","dtypes.T == \"f16\"","validLayout","(dim(shapes.updates, axis) >= tunables.F16_ATOMIC_MIN_AXIS or updateSlices < tunables.F16_ATOMIC_MAX_SLICES)","f16AccumFits","f16Ok(dtypes.T)"],"derive":{"scalar":"\"f32\"","useSubgroups":false,"workgroupSize":"f16AtomicWorkgroupSize","narrowElement":"\"vec4<f16>\" if numel(shapes.output) % 4 == 0 else \"f16\"","wideElement":"\"vec4<u32>\" if numel(shapes.output) % 4 == 0 else \"u32\""},"intermediates":[{"id":"accum","dtype":"uint32","shape":"[numel(shapes.output)]"}],"passes":[{"id":"init","name":"ScatterElements.F16InitF32","shader":"scatter-f16-f32-convert.wgsl.jinja","derive":{"toWide":true,"vec4":"numel(shapes.output) % 4 == 0"},"bindings":[{"arg":"data","name":"narrow","elementType":"$narrowElement"},{"scratch":"accum","name":"wide","elementType":"$wideElement"},"params"],"dispatch":{"x":"min(ceilDiv((numel(shapes.output) / 4 if numel(shapes.output) % 4 == 0 else numel(shapes.output)), (f16AtomicWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((numel(shapes.output) / 4 if numel(shapes.output) % 4 == 0 else numel(shapes.output)), (f16AtomicWorkgroupSize)), 65535)","z":1}},{"id":"scatter","name":"ScatterElements.F16AtomicF32","shader":"scatter-elements-reduction-atomic.wgsl.jinja","bindings":["indices","updates_f16","output_scatter","params_scatter"],"dispatch":{"x":"min(ceilDiv((ceilDiv(numel(shapes.updates), tunables.ATOMIC_UPDATES_PER_LANE)), (f16AtomicWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((ceilDiv(numel(shapes.updates), tunables.ATOMIC_UPDATES_PER_LANE)), (f16AtomicWorkgroupSize)), 65535)","z":1}},{"id":"finalize","name":"ScatterElements.F16FinalizeF32","shader":"scatter-f16-f32-convert.wgsl.jinja","derive":{"toWide":false,"vec4":"numel(shapes.output) % 4 == 0"},"bindings":[{"scratch":"accum","name":"wide","buffer":"read-only-storage","elementType":"$wideElement"},{"arg":"output","name":"narrow","elementType":"$narrowElement"},"params"],"dispatch":{"x":"min(ceilDiv((numel(shapes.output) / 4 if numel(shapes.output) % 4 == 0 else numel(shapes.output)), (f16AtomicWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((numel(shapes.output) / 4 if numel(shapes.output) % 4 == 0 else numel(shapes.output)), (f16AtomicWorkgroupSize)), 65535)","z":1}}]},{"id":"reduction_f16_slab","priority":35,"when":["(attrs.reduction == \"min\" or attrs.reduction == \"max\" or attrs.reduction == \"mul\")","dtypes.T == \"f16\"","validLayout","slabUpdatesMatchData","slabCells >= tunables.F16_SLAB_MIN_CELLS","slabOuter >= tunables.F16_SLAB_MIN_OUTER","slabBytes <= device.limits.maxComputeWorkgroupStorageSize","f16Ok(dtypes.T)","not reportedNonWave32Adapter"],"derive":{"workgroupSize":"slabWorkgroupSize"},"passes":[{"id":"scatter","name":"ScatterElements.F16SlabReduction","shader":"scatter-elements-reduction-slab.wgsl.jinja","derive":{"innerSize":"slabInner","axisDimSpec":"dim(shapes.data, axis)","updateAxisDim":"dim(shapes.updates, axis)","outerSize":"slabOuter"},"bindings":[{"arg":"data","elementType":"$slabElement"},"indices","updates_f16",{"arg":"output","elementType":"$slabElement"}],"dispatch":{"x":"min(ceilDiv(slabOuter, slabsPerWorkgroup), 65535)","y":"ceilDiv(ceilDiv(slabOuter, slabsPerWorkgroup), 65535)","z":1}}]},{"id":"reduction_narrow_wrap_atomic","priority":26,"when":["(attrs.reduction == \"add\" or attrs.reduction == \"mul\")","validLayout","narrowIntData"],"derive":{"scalar":"\"u32\"","useSubgroups":"device.features.has(\"subgroups\") and inner(shapes.updates, axis) == 1","preaggRounds":"tunables.SUBGROUP_PREAGG_ROUNDS","workgroupSize":"atomicWorkgroupSize","updateElement":"\"u32\"","outputElement":"\"atomic<u32>\""},"passes":[{"id":"copy","name":"ScatterElements.Copy","shader":"scatter-flat-copy.wgsl.jinja","derive":{"count":"numel(shapes.output) / 4 if dtypes.T != \"vec2<u32>\" and numel(shapes.output) % 4 == 0 else numel(shapes.output)"},"bindings":["src","dst"],"dispatch":{"x":"min(ceilDiv((numel(shapes.output) / 4 if dtypes.T != \"vec2<u32>\" and numel(shapes.output) % 4 == 0 else numel(shapes.output)), (workgroupSize)), 65535)","y":"ceilDiv(ceilDiv((numel(shapes.output) / 4 if dtypes.T != \"vec2<u32>\" and numel(shapes.output) % 4 == 0 else numel(shapes.output)), (workgroupSize)), 65535)","z":1}},{"id":"scatter","name":"ScatterElements.NarrowWrapAtomic","shader":"scatter-elements-reduction-atomic.wgsl.jinja","bindings":["indices","updates_scatter","output_generic","params_scatter"],"dispatch":{"x":"min(ceilDiv((ceilDiv(numel(shapes.updates), tunables.ATOMIC_UPDATES_PER_LANE)), (atomicWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((ceilDiv(numel(shapes.updates), tunables.ATOMIC_UPDATES_PER_LANE)), (atomicWorkgroupSize)), 65535)","z":1}},{"id":"narrow","name":"ScatterElements.NarrowWrapFinalize","shader":"scatter-narrow-wrap.wgsl.jinja","bindings":[{"arg":"output","name":"values","elementType":"u32"},"params_init"],"dispatch":{"x":"min(ceilDiv((numel(shapes.output)), (workgroupSize)), 65535)","y":"ceilDiv(ceilDiv((numel(shapes.output)), (workgroupSize)), 65535)","z":1}}]},{"id":"generic","priority":0,"when":["attrs.reduction == \"none\"","validLayout","f16Ok(dtypes.T)"],"derive":{"updateElement":"dtypes.T","outputElement":"dtypes.T"},"passes":[{"id":"copy","name":"ScatterElements.Copy","shader":"scatter-flat-copy.wgsl.jinja","derive":{"count":"numel(shapes.output) / 4 if dtypes.T != \"vec2<u32>\" and numel(shapes.output) % 4 == 0 else numel(shapes.output)"},"bindings":["src","dst"],"dispatch":{"x":"min(ceilDiv((numel(shapes.output) / 4 if dtypes.T != \"vec2<u32>\" and numel(shapes.output) % 4 == 0 else numel(shapes.output)), (workgroupSize)), 65535)","y":"ceilDiv(ceilDiv((numel(shapes.output) / 4 if dtypes.T != \"vec2<u32>\" and numel(shapes.output) % 4 == 0 else numel(shapes.output)), (workgroupSize)), 65535)","z":1}},{"id":"scatter","name":"ScatterElements.Scatter","shader":"scatter-elements.wgsl.jinja","bindings":["indices","updates_scatter","output_generic","params_scatter"],"dispatch":{"x":"min(ceilDiv((numel(shapes.updates)), (workgroupSize)), 65535)","y":"ceilDiv(ceilDiv((numel(shapes.updates)), (workgroupSize)), 65535)","z":1}}]},{"id":"reduction_atomic","priority":25,"when":["(attrs.reduction == \"add\" or attrs.reduction == \"mul\" or attrs.reduction == \"min\" or attrs.reduction == \"max\")","validLayout","(tensorDtypes.data == \"float32\" or tensorDtypes.data == \"int32\" or tensorDtypes.data == \"uint32\" or (narrowIntData and (attrs.reduction == \"min\" or attrs.reduction == \"max\")))"],"derive":{"scalar":"dtypes.T","useSubgroups":"device.features.has(\"subgroups\") and (attrs.reduction == \"add\" or attrs.reduction == \"mul\") and inner(shapes.updates, axis) == 1","preaggRounds":"tunables.SUBGROUP_PREAGG_ROUNDS","workgroupSize":"atomicWorkgroupSize","updateElement":"dtypes.T","outputElement":"\"atomic<i32>\" if dtypes.T == \"i32\" else \"atomic<u32>\""},"passes":[{"id":"copy","name":"ScatterElements.Copy","shader":"scatter-flat-copy.wgsl.jinja","derive":{"count":"numel(shapes.output) / 4 if dtypes.T != \"vec2<u32>\" and numel(shapes.output) % 4 == 0 else numel(shapes.output)"},"bindings":["src","dst"],"dispatch":{"x":"min(ceilDiv((numel(shapes.output) / 4 if dtypes.T != \"vec2<u32>\" and numel(shapes.output) % 4 == 0 else numel(shapes.output)), (workgroupSize)), 65535)","y":"ceilDiv(ceilDiv((numel(shapes.output) / 4 if dtypes.T != \"vec2<u32>\" and numel(shapes.output) % 4 == 0 else numel(shapes.output)), (workgroupSize)), 65535)","z":1}},{"id":"scatter","name":"ScatterElements.ReductionAtomic","shader":"scatter-elements-reduction-atomic.wgsl.jinja","bindings":["indices","updates_scatter","output_generic","params_scatter"],"dispatch":{"x":"min(ceilDiv((ceilDiv(numel(shapes.updates), tunables.ATOMIC_UPDATES_PER_LANE)), (atomicWorkgroupSize)), 65535)","y":"ceilDiv(ceilDiv((ceilDiv(numel(shapes.updates), tunables.ATOMIC_UPDATES_PER_LANE)), (atomicWorkgroupSize)), 65535)","z":1}}]},{"id":"reduction_slice","priority":20,"when":["(attrs.reduction == \"add\" or attrs.reduction == \"mul\" or attrs.reduction == \"min\" or attrs.reduction == \"max\")","validLayout","f16Ok(dtypes.T)"],"derive":{"scalar":"dtypes.T","updateElement":"dtypes.T","outputElement":"dtypes.T"},"passes":[{"id":"copy","name":"ScatterElements.Copy","shader":"scatter-flat-copy.wgsl.jinja","derive":{"count":"numel(shapes.output) / 4 if dtypes.T != \"vec2<u32>\" and numel(shapes.output) % 4 == 0 else numel(shapes.output)"},"bindings":["src","dst"],"dispatch":{"x":"min(ceilDiv((numel(shapes.output) / 4 if dtypes.T != \"vec2<u32>\" and numel(shapes.output) % 4 == 0 else numel(shapes.output)), (workgroupSize)), 65535)","y":"ceilDiv(ceilDiv((numel(shapes.output) / 4 if dtypes.T != \"vec2<u32>\" and numel(shapes.output) % 4 == 0 else numel(shapes.output)), (workgroupSize)), 65535)","z":1}},{"id":"scatter","name":"ScatterElements.Reduction","shader":"scatter-elements-reduction.wgsl.jinja","bindings":["indices","updates_scatter","output_generic","params_scatter"],"dispatch":{"x":"min(ceilDiv((updateSlices), (workgroupSize)), min(device.limits.maxComputeWorkgroupsPerDimension, 65535))","y":1,"z":1}}]},{"id":"reduction_owned_row","priority":31,"when":["attrs.reduction == \"add\"","dtypes.T == \"f16\"","validLayout","slabUpdatesMatchData","axis == ranks.data - 1","dim(shapes.data, axis) >= 1","dim(shapes.data, axis) <= tunables.OWNED_ROW_MAX_AXIS","device.features.has(\"subgroups\")","has(device.adapterInfo, \"subgroupMinSize\")","has(device.adapterInfo, \"subgroupMaxSize\")","device.adapterInfo.subgroupMinSize < device.adapterInfo.subgroupMaxSize","dim(shapes.data, axis) % 4 == 0","dim(shapes.updates, axis) % 4 == 0","dim(shapes.updates, axis) <= tunables.OWNED_ROW_MAX_AXIS","dtypes.I == \"i32\"","f16Ok(dtypes.T)"],"derive":{"scalar":"dtypes.T","updateElement":"\"vec4<f16>\"","outputElement":"\"vec4<f16>\"","rowWidth":"dim(shapes.data, axis)","updateWidth":"dim(shapes.updates, axis)","packedIndexType":"\"vec4<\" ~ dtypes.I ~ \">\""},"passes":[{"id":"main","name":"ScatterElements.OwnedRows","shader":"scatter-elements-owned-row.wgsl.jinja","bindings":[{"arg":"data","elementType":"vec4<f16>"},{"arg":"indices","elementType":"$packedIndexType"},"updates_scatter","output_generic",{"name":"params","struct":[{"name":"rows","type":"u32","value":"numel(shapes.output) / dim(shapes.data, axis)"},{"name":"axisDim","type":"u32","value":"dim(shapes.data, axis)"}]}],"dispatch":{"x":"min(ceilDiv((numel(shapes.output) / dim(shapes.data, axis)), (workgroupSize)), 65535)","y":"ceilDiv(ceilDiv((numel(shapes.output) / dim(shapes.data, axis)), (workgroupSize)), 65535)","z":1}}]}]}
123456789101112131415161718192021222324252627282930313233343536{"name": "ai.onnx.ScatterElements","id": "_ai_onnx_scatterelements_webgpu_d7dbbc0","version": 1,"license": "Apache-2.0","backend": { "type": "webgpu" },"digest": {"algorithm": "sha256","files": {"bench.json": "E5MoLfuKSh1Ix1R54JJwZrvueuBdTUUw0TP+S8zgM54=","manifest.json": "v/7WMPJpojLdnk66z/MnpwZN2ZlhByPH+nrzLUyeiZY=","scatter-elements-f32-add-axis0-histogram.wgsl.jinja": "3ND4rbj88fQ5rVx9ydVOGwdU9/b5OoMlSBr6GPvB61A=","scatter-elements-reduction-atomic.wgsl.jinja": "A9ncQc57m4TXjILRWEyOCcqiOfuOzIWT19TxULR3r5o=","scatter-elements-reduction-slab.wgsl.jinja": "O1NS6CUnPtQGxsQC/sz7vbde6Zr1HjLNHG6WbelPZKs=","scatter-elements-reduction.wgsl.jinja": "/xQDs+dVNe4gd99uJbDwhOiPD8m3c4vhNVPDBd2CzAU=","scatter-elements.wgsl.jinja": "2db6ZkeKfawvX35zFWe1zqWsqVj4YOx8/hTVWMDPX/o=","scatter-f16-f32-convert.wgsl.jinja": "DTnbR5Cjs5cUPwLfj0z0XwElTpeW2x6ikt0HrFS47C8=","scatter-flat-copy.wgsl.jinja": "89MyQb8EJE6PbOYFwGRg7CdubyGGXDuPz6T7c6C70BA=","scatter-narrow-wrap.wgsl.jinja": "Z7SJrfU4PfNeqr0UVRD74bb0hQqFrJXIgaTUBuVqu+4=","test.json": "15k8uQDQzQA1q2Qiy87z/irQrkDr2ulgzjTOAUbGSOA="}},"provenance": { "kernel": { "sha": "6fdf6301e2bbcc2f03bf1eaf493b7ad55ef33afc", "dirty": false } },"webgpu": {"manifestSpec": "2.1","variants": {"reduction_f32_add_axis0_histogram": ["scatter-elements-f32-add-axis0-histogram.wgsl.jinja", "scatter-flat-copy.wgsl.jinja"],"reduction_f16_atomic_f32": ["scatter-elements-reduction-atomic.wgsl.jinja", "scatter-f16-f32-convert.wgsl.jinja"],"reduction_f16_slab": ["scatter-elements-reduction-slab.wgsl.jinja"],"reduction_narrow_wrap_atomic": ["scatter-elements-reduction-atomic.wgsl.jinja", "scatter-flat-copy.wgsl.jinja", "scatter-narrow-wrap.wgsl.jinja"],"generic": ["scatter-elements.wgsl.jinja", "scatter-flat-copy.wgsl.jinja"],"reduction_atomic": ["scatter-elements-reduction-atomic.wgsl.jinja", "scatter-flat-copy.wgsl.jinja"],"reduction_slice": ["scatter-elements-reduction.wgsl.jinja", "scatter-flat-copy.wgsl.jinja"]}}}1{"name":"ai.onnx.ScatterElements","id":"_ai_onnx_scatterelements_webgpu_1cdd089","version":1,"license":"Apache-2.0","backend":{"type":"webgpu"},"digest":{"algorithm":"sha256","files":{"bench.json":"4Dy2BMjSqPHSTxdtm0qW41i8/H73GvwvYYOVYiHVomk=","manifest.json":"ESRcHuZx0ue6g1d/M7QqZBGV2G9tfTuNQzciRe7Tl/M=","scatter-elements-f32-add-axis0-histogram.wgsl.jinja":"3ND4rbj88fQ5rVx9ydVOGwdU9/b5OoMlSBr6GPvB61A=","scatter-elements-ordered-chunks.wgsl.jinja":"VhIeqTu0ToaC/xMQJ/a19Q80qkiz8DK+zIYjdOLd+Rk=","scatter-elements-ordered-global.wgsl.jinja":"bQpKr7Uqp7dXPC35dO+UlCegb7Seg5TqWHVu9JbT84M=","scatter-elements-ordered-list.wgsl.jinja":"2kZvUz1p4Oj/Nt4tsqBcs/kS5C/J8R5+S0nlP4IvaUk=","scatter-elements-owned-row.wgsl.jinja":"1YUv/T5Sll2EIDCWq+ofwC0pLPdzDJJYbEsr+gx1l4w=","scatter-elements-reduction-atomic.wgsl.jinja":"A9ncQc57m4TXjILRWEyOCcqiOfuOzIWT19TxULR3r5o=","scatter-elements-reduction-slab.wgsl.jinja":"dXt+R0fsYFmiWqCrWfh0s2Rx6jx1ac72/vvP1diqoEE=","scatter-elements-reduction.wgsl.jinja":"/xQDs+dVNe4gd99uJbDwhOiPD8m3c4vhNVPDBd2CzAU=","scatter-elements.wgsl.jinja":"cdh+7xlGi/cRas+ZEYGJKlfXDUtVpz0VdPHobh8ZsRw=","scatter-f16-f32-convert.wgsl.jinja":"1NbglO3YcmWVUwvOMdOJjwXEcAAeJkJC7XBwqE8G1Ag=","scatter-flat-copy.wgsl.jinja":"j6WvF9FB3E/wlhlPXZp90TLzb/Ww62KuLDmwngbpb8U=","scatter-narrow-wrap.wgsl.jinja":"Oo859qtaha8PiLl4G9aRJZO1Y798eaUKZM+gBOGFnms=","test.json":"depAv2I8YhP8Wdlsst1Ln7eWeEVBh7qGoiiWe6OsApE="}},"provenance":{"kernel":{"sha":"4385228f788ddaa1bd7aec6a80a20f3ddffd8011","dirty":false}},"webgpu":{"manifestSpec":"2.2"}}
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191{{ env.wgsl.resourceDeclarations }}const WG: u32 = {{ chunkWorkgroupSize }}u;const UPDATES: u32 = WG;const EMPTY: u32 = 0xffffffffu;const INVALID_INDEX: u32 = EMPTY;{% if useDirectHeads %}var<workgroup> heads: array<atomic<u32>, {{ stageCells }}>;{% else %}const CAPACITY: u32 = 2u * WG;var<workgroup> keys: array<atomic<u32>, {{ 2 * chunkWorkgroupSize }}>;var<workgroup> heads: array<atomic<u32>, {{ 2 * chunkWorkgroupSize }}>;var<workgroup> overflow: atomic<u32>;{% endif %}var<workgroup> staged: array<f16, {{ stageCells }}>;var<workgroup> links: array<u32, {{ chunkWorkgroupSize }}>;{% if not useDirectHeads %}var<workgroup> bins: array<u32, {{ chunkWorkgroupSize }}>;{% endif %}var<workgroup> values: array<f16, {{ chunkWorkgroupSize }}>;fn normalize_index(raw: {{ indexScalar }}, dim: u32) -> u32 { let dim_i = i32(dim); var index = raw; if (index < 0) { index = index + dim_i; } if (index < 0 || index >= dim_i) { return INVALID_INDEX; } return u32(index);}fn sorted_chain(first: u32) -> u32 { if (first == EMPTY) { return first; } let second = links[first]; if (second == EMPTY) { return first; } if (links[second] == EMPTY) { let lo = min(first, second); let hi = max(first, second); links[lo] = hi; links[hi] = EMPTY; return lo; } var head = first; for (var width = 1u; width < UPDATES; width *= 2u) { var p = head; var new_head = EMPTY; var tail = EMPTY; var merges = 0u; for (var run = 0u; run < UPDATES && p != EMPTY; run += 1u) { merges += 1u; var q = p; var left = 0u; for (var scan = 0u; scan < width && q != EMPTY; scan += 1u) { left += 1u; q = links[q]; } var right = width; for (var step = 0u; step < 2u * width; step += 1u) { if (left == 0u && (right == 0u || q == EMPTY)) { break; } var node = EMPTY; if (left == 0u) { node = q; q = links[q]; right -= 1u; } else if (right == 0u || q == EMPTY) { node = p; p = links[p]; left -= 1u; } else if (p < q) { node = p; p = links[p]; left -= 1u; } else { node = q; q = links[q]; right -= 1u; } if (tail == EMPTY) { new_head = node; } else { links[tail] = node; } tail = node; } p = q; } links[tail] = EMPTY; head = new_head; if (merges <= 1u) { break; } } return head;}
@compute @workgroup_size({{ chunkWorkgroupSize }})fn main(@builtin(workgroup_id) wid: vec3<u32>, @builtin(local_invocation_index) lane: u32) { let group = wid.x + wid.y * {{ DISPATCH_FOLD_WIDTH }}u; let col = group / {{ stagesPerColumn }}u; let stage_start = (group % {{ stagesPerColumn }}u) * {{ stageCells }}u; if (col >= {{ updateSlices }}u) { return; } let outer = col / {{ slabInner }}u; let inner = col % {{ slabInner }}u; let stage_count = min({{ stageCells }}u, {{ axisDimSpec }}u - stage_start); for (var cell = lane; cell < stage_count; cell += WG) {{% if useDirectHeads %} atomicStore(&heads[cell], EMPTY);{% endif %} staged[cell] = data[outer * {{ slabCells }}u + (stage_start + cell) * {{ slabInner }}u + inner]; } workgroupBarrier(); for (var start = 0u; start < {{ updateAxisDimSpec }}u; start += WG) {{% if not useDirectHeads %} for (var slot = lane; slot < CAPACITY; slot += WG) { atomicStore(&keys[slot], EMPTY); atomicStore(&heads[slot], EMPTY); } if (lane == 0u) { atomicStore(&overflow, 0u); }{% endif %}{% if useDirectHeads %} let k = start + lane;{% endif %} var bin = INVALID_INDEX; var value = 0.0h;{% if not useDirectHeads %} let k = start + lane;{% endif %} if (k < {{ updateAxisDimSpec }}u) { let u = outer * {{ orderedSlabUpdates }}u + k * {{ slabInner }}u + inner; bin = normalize_index(indices[u], {{ axisDimSpec }}u); if (bin < stage_start || bin >= stage_start + stage_count) { bin = INVALID_INDEX; } value = updates[u]; }{% if not useDirectHeads %} bins[lane] = bin;{% endif %} values[lane] = value;{% if not useDirectHeads %} workgroupBarrier();{% endif %} var owned = false;{% if not useDirectHeads %} var owned_slot = 0u;{% endif %} if (bin != INVALID_INDEX) {{% if useDirectHeads %} let previous = atomicExchange(&heads[bin - stage_start], lane); links[lane] = previous; owned = previous == EMPTY;{% else %} var slot = (bin * 2654435761u) & (CAPACITY - 1u); var inserted = false; for (var probe = 0u; probe < CAPACITY; probe += 1u) { let claim = atomicCompareExchangeWeak(&keys[slot], EMPTY, bin); if (claim.exchanged || claim.old_value == bin) { let previous = atomicExchange(&heads[slot], lane); links[lane] = previous; owned = previous == EMPTY; owned_slot = slot; inserted = true; break; } if (claim.old_value != EMPTY) { slot = (slot + 1u) & (CAPACITY - 1u); } } if (!inserted) { atomicStore(&overflow, 1u); }{% endif %} } workgroupBarrier();{% if not useDirectHeads %} if (atomicLoad(&overflow) != 0u) { if (lane == 0u) { for (var node = 0u; node < WG; node += 1u) { let key = bins[node]; if (key != INVALID_INDEX) { let dst = key - stage_start; staged[dst] = f16(f32(staged[dst]) + f32(values[node])); } } } } else{% endif %} if (owned) {{% if useDirectHeads %} let dst = bin - stage_start; var node = sorted_chain(atomicLoad(&heads[dst]));{% else %} var node = sorted_chain(atomicLoad(&heads[owned_slot])); let dst = bin - stage_start;{% endif %} var accumulated = staged[dst]; for (var step = 0u; step < WG && node != EMPTY; step += 1u) { accumulated = f16(f32(accumulated) + f32(values[node])); node = links[node]; } staged[dst] = accumulated;{% if useDirectHeads %} atomicStore(&heads[dst], EMPTY);{% endif %} } workgroupBarrier(); } for (var cell = lane; cell < stage_count; cell += WG) { output[outer * {{ slabCells }}u + (stage_start + cell) * {{ slabInner }}u + inner] = staged[cell]; }}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990{% 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 }}const WG: u32 = {{ globalWorkgroupSize }}u;{% if phase != "init" %}const EMPTY: u32 = 0xffffffffu;const INVALID_INDEX: u32 = EMPTY;const AXIS_DIM: u32 = {{ axisDimSpec }}u;const UPDATE_AXIS: u32 = {{ updateAxisDimSpec }}u;fn normalize_index(raw: {{ indexScalar }}, dim: u32) -> u32 { let dim_i = i32(dim); var index = raw; if (index < 0) { index = index + dim_i; } if (index < 0 || index >= dim_i) { return INVALID_INDEX; } return u32(index);}{% endif %}{% if phase == "apply" %}fn apply_cell(bin: u32, initial: f16) -> f16 { var ids: array<u32, {{ chainCapacity }}>; var count = 0u; var node = heads[bin]; for (var visit = 0u; visit < {{ chainCapacity }}u && node != EMPTY; visit++) { ids[count] = node; count++; node = links[node]; } var value = initial; if (node != EMPTY) { let column = params.columnBase + bin / AXIS_DIM; let destination = bin % AXIS_DIM; for (var k = 0u; k < UPDATE_AXIS; k++) { let u = column * UPDATE_AXIS + k; if (normalize_index(indices[u], AXIS_DIM) == destination) { value = f16(f32(value) + f32(updates[u])); } } return value; } for (var k = 1u; k < count; k++) { let item = ids[k]; var j = k; loop { if (j == 0u) { break; } if (ids[j - 1u] <= item) { break; } ids[j] = ids[j - 1u]; j--; } ids[j] = item; } for (var k = 0u; k < count; k++) { let u = params.columnBase * UPDATE_AXIS + ids[k]; value = f16(f32(value) + f32(updates[u])); } return value;}{% endif %}@compute @workgroup_size({{ globalWorkgroupSize }})fn main(@builtin(global_invocation_id) gid: vec3<u32>) {{% if phase == "init" %}{{ flat_index_2d("WG", bound="params.count") }} atomicStore(&heads[i], 0xffffffffu);{% elif phase == "link" %}{{ flat_index_2d("WG", bound="params.columnCount * UPDATE_AXIS") }} let localColumn = i / UPDATE_AXIS; let u = params.columnBase * UPDATE_AXIS + i; let destination = normalize_index(indices[u], AXIS_DIM); if (destination != INVALID_INDEX) { links[i] = atomicExchange(&heads[localColumn * AXIS_DIM + destination], i); } else { links[i] = EMPTY; }{% else %}{{ flat_index_2d("WG", bound="params.columnCount * AXIS_DIM / 2u") }} let outPair = params.columnBase * (AXIS_DIM / 2u) + i; let initial = data[outPair]; output[outPair] = vec2<f16>(apply_cell(i * 2u, initial.x), apply_cell(i * 2u + 1u, initial.y));{% endif %}}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123{{ env.wgsl.resourceDeclarations }}const WG: u32 = {{ workgroupSize }}u;const INNER: u32 = {{ innerSize }}u;const AXIS_DIM: u32 = {{ axisDimSpec }}u;const SLAB: u32 = {{ slabCells }}u;const UPDATES: u32 = {{ updateSlab }}u;const OUTER: u32 = {{ outerSize }}u;const EMPTY: u32 = 65535u;const INVALID_INDEX: u32 = 0xffffffffu;var<workgroup> heads: array<atomic<u32>, {{ headWords }}>;var<workgroup> links: array<u32, {{ updateSlab }}>;fn normalize_index(raw: {{ indexScalar }}, dim: u32) -> u32 { let dim_i = i32(dim); var index = raw; if (index < 0) { index = index + dim_i; } if (index < 0 || index >= dim_i) { return INVALID_INDEX; } return u32(index);}
fn prepend(bin: u32, node: u32) -> u32 { let word = bin / 2u; let shift = (bin & 1u) * 16u; let mask = 65535u << shift; var old = atomicLoad(&heads[word]); // Firefox's validator rejects a function whose final statement is a loop. // Return after the loop rather than from inside it: some validators reject a function whose final statement is // a loop. loop { let desired = (old & ~mask) | (node << shift); let result = atomicCompareExchangeWeak(&heads[word], old, desired); if (result.exchanged) { break; } old = result.old_value; } return (old >> shift) & 65535u;}
// Bottom-up linked-list merge sort. Node IDs are original update positions.// Each output cell owns a disjoint chain after the construction barrier.fn sorted_chain(first: u32) -> u32 { if (first == EMPTY) { return first; } let second = links[first]; if (second == EMPTY) { return first; } if (links[second] == EMPTY) { let lo = min(first, second); let hi = max(first, second); links[lo] = hi; links[hi] = EMPTY; return lo; } var head = first; for (var width = 1u; width < UPDATES; width *= 2u) { var p = head; var new_head = EMPTY; var tail = EMPTY; var merges = 0u; for (var run = 0u; run < UPDATES && p != EMPTY; run += 1u) { merges += 1u; var q = p; var left = 0u; for (var scan = 0u; scan < width && q != EMPTY; scan += 1u) { left += 1u; q = links[q]; } var right = width; for (var step = 0u; step < 2u * width; step += 1u) { if (left == 0u && (right == 0u || q == EMPTY)) { break; } var node = EMPTY; if (left == 0u) { node = q; q = links[q]; right -= 1u; } else if (right == 0u || q == EMPTY) { node = p; p = links[p]; left -= 1u; } else if (p < q) { node = p; p = links[p]; left -= 1u; } else { node = q; q = links[q]; right -= 1u; } if (tail == EMPTY) { new_head = node; } else { links[tail] = node; } tail = node; } p = q; } links[tail] = EMPTY; head = new_head; if (merges <= 1u) { break; } } return head;}
fn combine(current: f16, update: f16) -> f16 { return f16(f32(current) + f32(update));}
@compute @workgroup_size({{ workgroupSize }})fn main(@builtin(workgroup_id) wid: vec3<u32>, @builtin(local_invocation_index) lane: u32) { let outer = wid.x + wid.y * {{ DISPATCH_FOLD_WIDTH }}u; if (outer >= OUTER) { return; } for (var word = lane; word < {{ headWords }}u; word += WG) { atomicStore(&heads[word], 0xffffffffu); } workgroupBarrier(); for (var u = lane; u < UPDATES; u += WG) { let gathered = normalize_index(indices[outer * UPDATES + u], AXIS_DIM); if (gathered != INVALID_INDEX) { links[u] = prepend(gathered * INNER + u % INNER, u); } } workgroupBarrier(); for (var bin = lane; bin < SLAB; bin += WG) { let packed = atomicLoad(&heads[bin / 2u]); let first = (packed >> ((bin & 1u) * 16u)) & 65535u; var node = sorted_chain(first); var value = data[outer * SLAB + bin]; for (var step = 0u; step < UPDATES && node != EMPTY; step += 1u) { value = combine(value, updates[outer * UPDATES + node]); node = links[node]; } output[outer * SLAB + bin] = value; }}12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152{% 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 }}const WG: u32 = {{ workgroupSize }}u;const INVALID_INDEX: u32 = 0xffffffffu;fn normalize_index(raw: {{ indexScalar }}, dim: u32) -> u32 { let dim_i = i32(dim); var index = raw; if (index < 0) { index = index + dim_i; } if (index < 0 || index >= dim_i) { return INVALID_INDEX; } return u32(index);}@compute @workgroup_size(WG)fn main(@builtin(global_invocation_id) gid: vec3<u32>) {{{ flat_index_2d("WG", "row", "params.rows") }}{% for segment in range((rowWidth / 4)|int) %} let initial_{{ segment }}=data[row*{{ (rowWidth / 4)|int }}u+{{ segment }}u];{% for lane in range(4) %} var state_{{ segment * 4 + lane }}=initial_{{ segment }}[{{ lane }}];{% endfor %}{% endfor %}{% for segment in range((updateWidth / 4)|int) %} let update_{{ segment }}=updates[row*{{ (updateWidth / 4)|int }}u+{{ segment }}u]; let indices_{{ segment }}=indices[row*{{ (updateWidth / 4)|int }}u+{{ segment }}u];{% for lane in range(4) %} { let gathered=normalize_index(indices_{{ segment }}[{{ lane }}],params.axisDim); let update=f32(update_{{ segment }}[{{ lane }}]);{% for column in range(rowWidth) %} if(gathered=={{ column }}u){ let current=f32(state_{{ column }}); state_{{ column }}={{ scalar }}(current+update); }{% endfor %} }{% endfor %}{% endfor %}{% for segment in range((rowWidth / 4)|int) %} output[row*{{ (rowWidth / 4)|int }}u+{{ segment }}u]=vec4<{{ scalar }}>(state_{{ segment * 4 }},state_{{ segment * 4 + 1 }},state_{{ segment * 4 + 2 }},state_{{ segment * 4 + 3 }});{% endfor %}}3 unmodified lines4567891028 unmodified lines3940414243444546473 unmodified lines// owns SUPER consecutive slabs: it stages them in workgroup memory as f32 bits,// applies their updates with workgroup compare-exchange (WGSL has neither f16// nor float atomics), and writes every cell back narrowed once. That removes// the copy pass and the widen/narrow round trips of the global-atomic route;// the accumulation order is data-dependent there as well.//// Processing several short slabs per workgroup shares launch and barrier work.28 unmodified linesvar old_bits = atomicLoad(&bins[bin]);loop {let current = bitcast<f32>(old_bits);{% if reductionOp == "add" %}let combined = current + update;{% elif reductionOp == "mul" %}let combined = current * update;{% elif reductionOp == "min" %}let combined = min(current, update);3 unmodified lines4567891028 unmodified lines394041424344453 unmodified lines// owns SUPER consecutive slabs: it stages them in workgroup memory as f32 bits,// applies their updates with workgroup compare-exchange (WGSL has neither f16// nor float atomics), and writes every cell back narrowed once. That removes// the copy pass and the widen/narrow round trips of the global-atomic variant;// the accumulation order is data-dependent there as well.//// Processing several short slabs per workgroup shares launch and barrier work.28 unmodified linesvar old_bits = atomicLoad(&bins[bin]);loop {let current = bitcast<f32>(old_bits);{% if reductionOp == "mul" %}let combined = current * update;{% elif reductionOp == "min" %}let combined = min(current, update);
1234567891011{% 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 }}const INVALID_INDEX: u32 = 0xffffffffu;123456789101112{% 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 }}const INVALID_INDEX: u32 = 0xffffffffu;
1234567891 unmodified line11121314151617{% 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 }}// Narrow/wide conversion around f16 scatter reductions. `wide` stores f321 unmodified line// atomic<u32> and perform portable float CAS operations.@compute @workgroup_size({{ workgroupSize }})fn main(@builtin(global_invocation_id) gid: vec3<u32>) {{{ flat_index_2d(workgroupSize, guardInline=true) }}{% if vec4 is defined and vec4 %}{% if toWide %}wide[i] = bitcast<vec4<u32>>(vec4<f32>(narrow[i]));1234567891011121 unmodified line14151617181920{% 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 }}// Narrow/wide conversion around f16 scatter reductions. `wide` stores f321 unmodified line// atomic<u32> and perform portable float CAS operations.@compute @workgroup_size({{ workgroupSize }})fn main(@builtin(global_invocation_id) gid: vec3<u32>) {{{ flat_index_2d(workgroupSize) }}{% if vec4 is defined and vec4 %}{% if toWide %}wide[i] = bitcast<vec4<u32>>(vec4<f32>(narrow[i]));
2 unmodified lines3456789101112131415162 unmodified lines// numel(output) % 4 == 0 the bindings rebind as vec4<T> (128-bit loads).// Tail-safe modes keep scalar bindings but copy a compile-time group of adjacent// elements per invocation, guarding only the final partial group.{% 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 }}{% set wg = workgroupSize if workgroupSize is defined else tunables.WORKGROUP_SIZE %}2 unmodified lines345678910111213141516172 unmodified lines// numel(output) % 4 == 0 the bindings rebind as vec4<T> (128-bit loads).// Tail-safe modes keep scalar bindings but copy a compile-time group of adjacent// elements per invocation, guarding only the final partial group.{% 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 }}{% set wg = workgroupSize if workgroupSize is defined else tunables.WORKGROUP_SIZE %}
12345678916 unmodified lines26272829303132{% 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 }}{% set mask = 255 if narrowBits == 8 else 65535 %}{% set sign_bit = 128 if narrowBits == 8 else 32768 %}16 unmodified lines@compute @workgroup_size({{ workgroupSize }})fn main(@builtin(global_invocation_id) gid: vec3<u32>) {{{ flat_index_2d(workgroupSize, guardInline=true) }}let low = values[i] & MASK;{% if narrowSigned %}values[i] = select(low, low | ~MASK, low >= SIGN_BIT);12345678910111216 unmodified lines29303132333435{% 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 }}{% set mask = 255 if narrowBits == 8 else 65535 %}{% set sign_bit = 128 if narrowBits == 8 else 32768 %}16 unmodified lines@compute @workgroup_size({{ workgroupSize }})fn main(@builtin(global_invocation_id) gid: vec3<u32>) {{{ flat_index_2d(workgroupSize) }}let low = values[i] & MASK;{% if narrowSigned %}values[i] = select(low, low | ~MASK, low >= SIGN_BIT);
110 unmodified lines111112113114115116117580 unmodified lines698699700701702703704413 unmodified lines1118111911201121112211231124129 unmodified lines125412551256125712581259126046 unmodified lines130713081309131013111312131340 unmodified lines135413551356135713581359136058 unmodified lines14191420142114221423142414256 unmodified lines14321433143414351436143714388 unmodified lines144714481449145014511452145383 unmodified lines1537153815391540154115421543184 unmodified lines172817291730173117321733173418 unmodified lines175317541755175617571758110 unmodified lines"provenance": {"source": "onnxruntime/test/providers/cpu/tensor/scatter_op_test.cc","test": "Scatter.BoolInputWithAxis","notes": "ORT runs this helper for ScatterElements too; ONNX allows bool data and updates."},"attrs": { "axis": 1 },"inputs": {580 unmodified lines{"name": "empty_updates_reduction_add_noop","provenance": {"notes": "Empty updates make both the axis stride and updates-per-column count zero. The reduction path must return without dividing by either extent and leave the input unchanged."},"attrs": { "axis": 1, "reduction": "add" },"inputs": {413 unmodified lines"name": "ort_uint32_axis0_replacement","provenance": {"source": "ONNX Runtime's CPU provider","notes": "Covers standard UINT32 payload storage on the replacement route."},"attrs": { "axis": 0 },"inputs": {129 unmodified lines{"name": "f16_reduction_add_axis1_slab_outer16_axis48_duplicates","provenance": {"notes": "Slab route: sixteen rows of 48 stage in workgroup memory, twenty updates per row land on repeated and negative indices, and every cell writes back once."},"attrs": { "axis": 1, "reduction": "add" },"inputs": {46 unmodified lines{"name": "f16_reduction_mul_axis1_rank3_slab_inner5","provenance": {"notes": "Slab route with an inner stride: axis 1 of a rank-3 tensor keeps each update in its own inner column while the slab (axis extent times inner) stages as one block."},"attrs": { "axis": 1, "reduction": "mul" },"inputs": {40 unmodified lines{"name": "f16_reduction_max_axis2_rank3_slab_last_axis","provenance": {"notes": "Slab route on the last axis: forty slabs of 32 with a unit inner stride, repeated and negative indices."},"attrs": { "axis": 2, "reduction": "max" },"inputs": {58 unmodified lines{"name": "f16_reduction_min_slab_updates_smaller_outer","provenance": {"notes": "Updates [8,20] cover only the first 8 of the data's 16 rows (a valid ScatterElements layout: update extents <= data extents). A slab route that walks the data's outer extent would read past the updates tensor for rows 8..15 and fold zeros into the min; rows 8..15 must stay 5."},"attrs": { "axis": 1, "reduction": "min" },"inputs": {6 unmodified lines{"name": "f16_reduction_add_slab_updates_narrower_inner","provenance": {"notes": "Rank-3 add along axis 1 whose updates [8,8,4] are narrower than the data [8,8,8] on the inner axis; every update targets axis index 2 so data[o,2,0..3] gains 8 * 0.5. A slab route keyed on the data's inner extent would misplace half the updates."},"attrs": { "axis": 1, "reduction": "add" },"inputs": {8 unmodified lines"provenance": {"source": "onnxruntime/test/providers/cpu/tensor/scatter_op_test.cc","test": "ScatterElements.AddReductionInt32SemanticDispatch","notes": "0x3f800000 is the IEEE bit pattern of 1.0f. Integer addition gives 0x7f000000 = 2130706432; a reduction dispatched on a float representative type would give 2.0f = 0x40000000 = 1073741824."},"attrs": { "axis": 0, "reduction": "add" },"inputs": {83 unmodified lines"provenance": {"source": "onnxruntime/test/providers/cpu/tensor/scatter_op_test.cc","test": "ScatterElements.FullDTypeUInt32","notes": "uint32 mul reduction smoke case; uint32 coverage here is add only (`ort_uint32_reduction_add_wrap32`)."},"attrs": { "axis": 0, "reduction": "mul" },"inputs": {184 unmodified lines"provenance": {"source": "onnxruntime/test/providers/cpu/tensor/scatter_op_test.cc","test": "Scatter.BoolInputWithAxis","notes": "ORT runs this helper for ScatterElements too; ONNX allows bool data and updates."},"attrs": { "axis": 1 },"inputs": {18 unmodified lines"outputs": { "output": { "dtype": "int64", "shape": [1, 5], "tolerance": 0, "relTolerance": 0 } },"tolerance": 0,"relTolerance": 0}]}110 unmodified lines111112113114115116117580 unmodified lines698699700701702703704413 unmodified lines1118111911201121112211231124129 unmodified lines125412551256125712581259126046 unmodified lines130713081309131013111312131340 unmodified lines135413551356135713581359136058 unmodified lines14191420142114221423142414256 unmodified lines14321433143414351436143714388 unmodified lines144714481449145014511452145383 unmodified lines1537153815391540154115421543184 unmodified lines172817291730173117321733173418 unmodified lines175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073110 unmodified lines"provenance": {"source": "onnxruntime/test/providers/cpu/tensor/scatter_op_test.cc","test": "Scatter.BoolInputWithAxis","notes": "ONNX allows bool data and updates: a bool [1,5] input with indices [1,3] and updates [1,0] along axis 1."},"attrs": { "axis": 1 },"inputs": {580 unmodified lines{"name": "empty_updates_reduction_add_noop","provenance": {"notes": "Indices and updates have zero extent on both axis 1 and axis 2, so the add reduction must leave the input unchanged."},"attrs": { "axis": 1, "reduction": "add" },"inputs": {413 unmodified lines"name": "ort_uint32_axis0_replacement","provenance": {"source": "ONNX Runtime's CPU provider","notes": "uint32 data [1,2,3] with indices [2,0] and updates [9,8] along axis 0, replacing elements 2 and 0."},"attrs": { "axis": 0 },"inputs": {129 unmodified lines{"name": "f16_reduction_add_axis1_slab_outer16_axis48_duplicates","provenance": {"notes": "Reduction add along axis 1 of a float16 [16,48] tensor: each row receives 20 updates on repeated indices (0, 3, 5, 12 and 47 each appear more than once, counting -48 as 0 and -1 as 47) and negative indices (-1 and -48)."},"attrs": { "axis": 1, "reduction": "add" },"inputs": {46 unmodified lines{"name": "f16_reduction_mul_axis1_rank3_slab_inner5","provenance": {"notes": "float16 multiply reduction along axis 1 of a rank-3 [12,8,5] tensor: each update lands in its own inner column, with repeated and negative indices (-8)."},"attrs": { "axis": 1, "reduction": "mul" },"inputs": {40 unmodified lines{"name": "f16_reduction_max_axis2_rank3_slab_last_axis","provenance": {"notes": "float16 max reduction along the last axis of a [10,4,32] tensor: 40 rows of 32 with 16 updates each, including repeated and negative indices (-1 and -32)."},"attrs": { "axis": 2, "reduction": "max" },"inputs": {58 unmodified lines{"name": "f16_reduction_min_slab_updates_smaller_outer","provenance": {"notes": "Updates [8,20] cover only the first 8 of the data's 16 rows (update extents may be smaller than data extents), so rows 8..15 must stay 5 while the min with the updates (3) changes element 0 of rows 0..7."},"attrs": { "axis": 1, "reduction": "min" },"inputs": {6 unmodified lines{"name": "f16_reduction_add_slab_updates_narrower_inner","provenance": {"notes": "Rank-3 add along axis 1 whose updates [8,8,4] are narrower than the data [8,8,8] on the inner axis; every update targets axis index 2, so data[o,2,0..3] gains 8 * 0.5 and the other inner columns keep their input values."},"attrs": { "axis": 1, "reduction": "add" },"inputs": {8 unmodified lines"provenance": {"source": "onnxruntime/test/providers/cpu/tensor/scatter_op_test.cc","test": "ScatterElements.AddReductionInt32SemanticDispatch","notes": "The int32 values 1065353216 (0x3f800000) are the IEEE bit pattern of 1.0f: integer addition gives 2130706432 (0x7f000000), whereas adding them as floats would give 2.0f (1073741824)."},"attrs": { "axis": 0, "reduction": "add" },"inputs": {83 unmodified lines"provenance": {"source": "onnxruntime/test/providers/cpu/tensor/scatter_op_test.cc","test": "ScatterElements.FullDTypeUInt32","notes": "The uint32 multiplication reduction is exercised with nontrivial values."},"attrs": { "axis": 0, "reduction": "mul" },"inputs": {184 unmodified lines"provenance": {"source": "onnxruntime/test/providers/cpu/tensor/scatter_op_test.cc","test": "Scatter.BoolInputWithAxis","notes": "int64 [1,5] data and updates holding values beyond 32 bits (full int64 range), with indices [1,3] along axis 1."},"attrs": { "axis": 1 },"inputs": {18 unmodified lines"outputs": { "output": { "dtype": "int64", "shape": [1, 5], "tolerance": 0, "relTolerance": 0 } },"tolerance": 0,"relTolerance": 0},{"name": "f16_owned_rows_aligned_512x4_duplicates","attrs": { "axis": 1, "reduction": "add" },"inputs": {"data": { "dtype": "float16", "shape": [512, 4], "data": { "kind": "constant", "value": 0.25 } },"indices": { "dtype": "int32", "shape": [512, 4], "data": { "kind": "cycle", "values": [0, 0, -1, 0] } },"updates": { "dtype": "float16", "shape": [512, 4], "data": { "kind": "constant", "value": 0.125 } }},"outputs": {"output": {"dtype": "float16","shape": [512, 4],"data": { "kind": "cycle", "values": [0.625, 0.25, 0.25, 0.375] },"tolerance": 0}},"provenance": { "notes": "Three duplicate adds to column 0 per float16 row; index -1 adds to column 3." }},{"name": "f16_owned_rows_aligned_512x4_invalid_indices","attrs": { "axis": 1, "reduction": "add" },"inputs": {"data": { "dtype": "float16", "shape": [512, 4], "data": { "kind": "constant", "value": 0.25 } },"indices": { "dtype": "int32", "shape": [512, 4], "data": { "kind": "cycle", "values": [0, -5, -1, 4] } },"updates": { "dtype": "float16", "shape": [512, 4], "data": { "kind": "constant", "value": 0.125 } }},"outputs": {"output": {"dtype": "float16","shape": [512, 4],"data": { "kind": "cycle", "values": [0.375, 0.25, 0.25, 0.375] },"tolerance": 0}},"provenance": {"notes": "Out-of-range indices -5 and 4 are ignored; valid indices 0 and -1 add to columns 0 and 3."}},{"name": "f16_add_fractional_collisions_ordered","attrs": { "axis": 1, "reduction": "add" },"inputs": {"data": { "dtype": "float16", "shape": [9, 33], "data": { "kind": "constant", "value": 0.0 } },"indices": { "dtype": "int32", "shape": [9, 64], "data": { "kind": "constant", "value": 0 } },"updates": { "dtype": "float16", "shape": [9, 64], "data": { "kind": "constant", "value": 0.1 } }},"outputs": {"output": {"dtype": "float16","shape": [9, 33],"data": {"kind": "cycle","values": [6.42578125, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]},"tolerance": 0,"relTolerance": 0,"exactRounding": true}},"provenance": {"notes": "Every update targets the first cell in its row. Fractional half updates distinguish per-update half rounding from a single float32 accumulation and final conversion."}},{"name": "f16_reduction_min_axis1_slab_outer16_axis33_scalar_staging","provenance": {"notes": "An odd slab of 33 values requires scalar half staging and stores. Repeated and negative indices select exact minimum updates within each row."},"attrs": { "axis": 1, "reduction": "min" },"inputs": {"data": {"dtype": "float16","shape": [16, 33],"data": { "kind": "fillFloat32", "sinStep": 0.11, "cosStep": 0.07, "scale": 0.5 }},"indices": {"dtype": "int32","shape": [16, 12],"data": { "kind": "cycle", "values": [0, 5, 32, 5, -1, 12, 12, 30, 31, 0, 7, -33] }},"updates": {"dtype": "float16","shape": [16, 12],"data": { "kind": "fillFloat32", "sinStep": 0.13, "cosStep": 0.17, "scale": 0.25 }}},"outputs": { "output": { "dtype": "float16", "shape": [16, 33], "tolerance": 0, "relTolerance": 0 } }},{"name": "f16_ordered_chunks_rounding_and_update_tail","attrs": { "axis": 0, "reduction": "add" },"inputs": {"data": {"dtype": "float16","shape": [8],"data": { "kind": "values", "values": [1.0, 2.0, 0.0, 4.0, 5.0, 6.0, 7.0, 8.0] }},"indices": { "dtype": "int32", "shape": [1025], "data": { "kind": "constant", "value": 2 } },"updates": {"dtype": "float16","shape": [1025],"data": { "kind": "cycle", "values": [2048.0, 1.0, -2048.0, 0.0] }}},"outputs": {"output": {"dtype": "float16","shape": [8],"data": { "kind": "values", "values": [1.0, 2.0, 2048.0, 4.0, 5.0, 6.0, 7.0, 8.0] },"tolerance": 0,"relTolerance": 0}},"provenance": {"source": "synthetic","notes": "Per-update half rounding loses the unit between cancelling 2048 values; float32 accumulation or unordered grouping gives a different answer. An update tail crosses multiple bounded chunks."}},{"name": "f16_ordered_chunks_rank3_negative_indices","attrs": { "axis": 1, "reduction": "add" },"inputs": {"data": { "dtype": "float16", "shape": [2, 7, 3], "data": { "kind": "constant", "value": 1.0 } },"indices": {"dtype": "int32","shape": [2, 513, 3],"data": { "kind": "cycle", "values": [0, -1, 2, 4, 5, -3, 1] }},"updates": {"dtype": "float16","shape": [2, 513, 3],"data": { "kind": "cycle", "values": [2048.0, 1.0, -2048.0, 0.0] }}},"outputs": { "output": { "dtype": "float16", "shape": [2, 7, 3], "tolerance": 0, "relTolerance": 0 } },"provenance": {"source": "synthetic","notes": "Rank-3 float16 add-scatter on axis 1, including indices -1 and -3, keeps non-axis coordinates and rounds in update order."}},{"name": "f16_ordered_chunks_hash_collisions","attrs": { "axis": 0, "reduction": "add" },"inputs": {"data": { "dtype": "float16", "shape": [1025], "data": { "kind": "constant", "value": 0.0 } },"indices": {"dtype": "int32","shape": [1537],"data": { "kind": "cycle", "values": [0, 512, 256, 768, 1024] }},"updates": {"dtype": "float16","shape": [1537],"data": { "kind": "cycle", "values": [1.0, -1.0, 0.5, -0.5] }}},"outputs": { "output": { "dtype": "float16", "shape": [1025], "tolerance": 0, "relTolerance": 0 } },"provenance": {"source": "synthetic","notes": "Float16 add updates 1, -1, 0.5 and -0.5 cycle over destinations 0, 512, 256, 768 and 1024, all multiples of 256."}},{"name": "f16_ordered_chunks_output_stage_tail","attrs": { "axis": 1, "reduction": "add" },"inputs": {"data": { "dtype": "float16", "shape": [2, 16385], "data": { "kind": "constant", "value": 1.0 } },"indices": {"dtype": "int32","shape": [2, 257],"data": { "kind": "cycle", "values": [0, 8191, 8192, 16383, 16384, -1] }},"updates": { "dtype": "float16", "shape": [2, 257], "data": { "kind": "constant", "value": 0.00390625 } }},"outputs": { "output": { "dtype": "float16", "shape": [2, 16385], "tolerance": 0, "relTolerance": 0 } },"provenance": {"source": "synthetic","notes": "Output staging spans multiple resource-bounded slices, including a one-element last slice and updates at each slice boundary."}},{"name": "ordered_global_half_rounding_long_chain","attrs": { "axis": 1, "reduction": "add" },"tunables": {},"inputs": {"data": {"dtype": "float16","shape": [3, 32],"data": { "kind": "cycle", "values": [0.125, 0.25, 0.375, 0.5, 0.625, 0.75, 0.875] }},"indices": { "dtype": "int32", "shape": [3, 49], "data": { "kind": "cycle", "values": [0] } },"updates": {"dtype": "float16","shape": [3, 49],"data": { "kind": "cycle", "values": [2048.0, 1.0, -2048.0, 0.5, 0.25, -0.5, -0.25] }}},"outputs": { "output": { "dtype": "float16", "shape": [3, 32], "tolerance": 0, "relTolerance": 0 } }},{"name": "ordered_global_negative_invalid_indices","attrs": { "axis": 1, "reduction": "add" },"tunables": {},"inputs": {"data": { "dtype": "float16", "shape": [3, 32], "data": { "kind": "constant", "value": 0.0 } },"indices": {"dtype": "int32","shape": [3, 48],"data": { "kind": "cycle", "values": [0, -1, -32, 32, -33, 8, 15] }},"updates": {"dtype": "float16","shape": [3, 48],"data": { "kind": "cycle", "values": [2048.0, 1.0, -2048.0, 0.5, 0.25, -0.5, -0.25] }}},"outputs": { "output": { "dtype": "float16", "shape": [3, 32], "tolerance": 0, "relTolerance": 0 } }},{"name": "ordered_global_small_workspace_fallback_tail","attrs": { "axis": 1, "reduction": "add" },"tunables": { "ORDERED_GLOBAL_MAX_BYTES": 512, "ORDERED_GLOBAL_LOCAL_CHAIN": 1 },"inputs": {"data": { "dtype": "float16", "shape": [3, 32], "data": { "kind": "constant", "value": 0.0 } },"indices": {"dtype": "int32","shape": [3, 48],"data": { "kind": "cycle", "values": [0, -1, -32, 32, -33, 8, 15] }},"updates": {"dtype": "float16","shape": [3, 48],"data": { "kind": "cycle", "values": [2048.0, 1.0, -2048.0, 0.5, 0.25, -0.5, -0.25] }}},"outputs": { "output": { "dtype": "float16", "shape": [3, 32], "tolerance": 0, "relTolerance": 0 } }},{"name": "f16_ordered_direct_embedding","attrs": { "axis": 0, "reduction": "add" },"inputs": {"data": {"dtype": "float16","shape": [4096, 8],"data": { "kind": "cycle", "values": [0.125, 0.25, 0.375, 0.5, 0.625, 0.75, 0.875] }},"indices": {"dtype": "int32","shape": [8193, 8],"data": { "kind": "cycle", "values": [0, 4095, -1, -4096, 2048, 17, -7, 4096, -4097, 1365, 1] }},"updates": {"dtype": "float16","shape": [8193, 8],"data": { "kind": "cycle", "values": [2048.0, 1.0, -2048.0, 0.0, 0.125, -0.25, 0.00390625] }}},"outputs": { "output": { "dtype": "float16", "shape": [4096, 8], "tolerance": 0, "relTolerance": 0 } },"provenance": {"source": "synthetic","notes": "Indices repeat destinations and include negative and out-of-range values; update rows number twice the axis extent plus one. Float16 rounding follows update order."}},{"name": "f16_ordered_direct_storage_boundary","attrs": { "axis": 0, "reduction": "add" },"inputs": {"data": {"dtype": "float16","shape": [5200, 2],"data": { "kind": "cycle", "values": [0.125, 0.25, 0.375, 0.5, 0.625, 0.75, 0.875] }},"indices": {"dtype": "int32","shape": [10401, 2],"data": { "kind": "cycle", "values": [0, 5199, -1, -5200, 2600, 17, -7, 5200, -5201, 1733, 1] }},"updates": {"dtype": "float16","shape": [10401, 2],"data": { "kind": "cycle", "values": [2048.0, 1.0, -2048.0, 0.0, 0.125, -0.25, 0.00390625] }}},"outputs": { "output": { "dtype": "float16", "shape": [5200, 2], "tolerance": 0, "relTolerance": 0 } },"provenance": {"source": "synthetic","notes": "Indices repeat destinations and include negative and out-of-range values; update rows number twice the axis extent plus one. Float16 rounding follows update order."}},{"name": "f16_ordered_direct_storage_fallback","attrs": { "axis": 0, "reduction": "add" },"inputs": {"data": {"dtype": "float16","shape": [5201, 2],"data": { "kind": "cycle", "values": [0.125, 0.25, 0.375, 0.5, 0.625, 0.75, 0.875] }},"indices": {"dtype": "int32","shape": [10403, 2],"data": { "kind": "cycle", "values": [0, 5200, -1, -5201, 2600, 17, -7, 5201, -5202, 1733, 1] }},"updates": {"dtype": "float16","shape": [10403, 2],"data": { "kind": "cycle", "values": [2048.0, 1.0, -2048.0, 0.0, 0.125, -0.25, 0.00390625] }}},"outputs": { "output": { "dtype": "float16", "shape": [5201, 2], "tolerance": 0, "relTolerance": 0 } },"provenance": {"source": "synthetic","notes": "Indices repeat destinations and include negative and out-of-range values; update rows number twice the axis extent plus one. Float16 rounding follows update order."}}]}
README.md+32-17
build/webgpu/bench.json+1-1
build/webgpu/manifest.json+1-383
build/webgpu/metadata.json+1-36
build/webgpu/scatter-elements-ordered-chunks.wgsl.jinjaAdded+191
build/webgpu/scatter-elements-ordered-global.wgsl.jinjaAdded+90
build/webgpu/scatter-elements-ordered-list.wgsl.jinjaAdded+123
build/webgpu/scatter-elements-owned-row.wgsl.jinjaAdded+52
build/webgpu/scatter-elements-reduction-slab.wgsl.jinja+2-4
build/webgpu/scatter-elements.wgsl.jinja+3-2
build/webgpu/scatter-f16-f32-convert.wgsl.jinja+6-3
build/webgpu/scatter-flat-copy.wgsl.jinja+3-2
build/webgpu/scatter-narrow-wrap.wgsl.jinja+6-3
build/webgpu/test.json+326-11