sync 91d990483a17
Browse filesFiles changed (13)
- README.md+16-12
- build/webgpu/bench.json-1
- build/webgpu/datamove-scatter-row.wgsl.jinja+5-9
- build/webgpu/manifest.json+218-341
- build/webgpu/metadata.json+26-14
- build/webgpu/scatter-f16-f32-convert.wgsl.jinja+3-4
- build/webgpu/scatter-flat-copy.wgsl.jinja+32-10
- build/webgpu/scatter-narrow-wrap.wgsl.jinja+2-3
- build/webgpu/scatter-nd-reduction-atomic.wgsl.jinja+37-38
- build/webgpu/scatter-nd-reduction-f16-packed-atomic.wgsl.jinja+21-25
- build/webgpu/scatter-nd-reduction-slice.wgsl.jinja+41-44
- build/webgpu/scatter-nd.wgsl.jinja+21-24
- build/webgpu/test.json+53-49
17 unmodified lines18192021222324252627282930313233341 unmodified line363738394041424 unmodified lines474849505152539 unmodified lines6364656667686970717217 unmodified lines## Inputs| Name | Bind key | Logical dtype | WebGPU storage | Rank | Shape | Description | Presence || --- | --- | --- | --- | --- | --- | --- | --- || `data` | `data` | `T` | runtime-selected; narrow integers and bool use 32-bit slots | — | — | Source tensor of rank r >= 1 that is copied to form the base of the output. | required || `indices` | `indices` | `I` | `int32` | — | — | Logical int64 index tensor of rank q >= 1 whose last dimension gives signed k-tuples that address into `data`; WebGPU stores it as int32. | required || `updates` | `updates` | `T` | runtime-selected; narrow integers and bool use 32-bit slots | — | — | Values to scatter into the output, of rank q + r - k - 1, matching the leading (q-1) index dimensions and the trailing (r-k) data slice dimensions. | required |## Outputs| Name | Bind key | Logical dtype | Rank | Shape | Description | Presence || --- | --- | --- | --- | --- | --- | --- || `output` | `output` | `T` | same as `data` | same as `data` | Result tensor of rank r with the same shape as `data`, with selected positions overwritten or reduced by `updates`. | required |## Attributes1 unmodified line| Attribute | Default | Description || --- | --- | --- || `reduction` | `"none"` | Reduction to apply when writing each update value: `none` (overwrite), `add`, `mul`, `max`, or `min`. |## Type constraints4 unmodified lines## Files- [`metadata.json`](build/webgpu/metadata.json) — kernel metadata (id, digests, provenance)- [`manifest.json`](build/webgpu/manifest.json) — the op contract (source of truth)- [`test.json`](build/webgpu/test.json) — correctness cases- [`bench.json`](build/webgpu/bench.json) — benchmark + tuning cases9 unmodified lines## Use with `@huggingface/kernels`The loader derives every required output's shape and logical dtype from the manifest contract and this call.It then allocates the result tensors automatically.The `version: 1` option selects the published kernel contract; it is independent of any operator opset, contrib `since_version`, or model version.Replace each `*Data` placeholder with a typed array containing the corresponding input data.17 unmodified lines18192021222324252627282930313233341 unmodified line363738394041424 unmodified lines474849505152539 unmodified lines636465666768697071727374757617 unmodified lines## Inputs| Name | Logical dtype | WebGPU storage | Rank | Shape | Description | Presence || --- | --- | --- | --- | --- | --- | --- || `data` | `T` | runtime-selected; narrow integers and bool use 32-bit slots | — | — | Source tensor of rank r >= 1 that is copied to form the base of the output. | required || `indices` | `I` | `int32` | — | — | Logical int64 index tensor of rank q >= 1 whose last dimension gives signed k-tuples that address into `data`; WebGPU stores it as int32. | required || `updates` | `T` | runtime-selected; narrow integers and bool use 32-bit slots | — | — | Values to scatter into the output, of rank q + r - k - 1, matching the leading (q-1) index dimensions and the trailing (r-k) data slice dimensions. | required |## Outputs| Name | Logical dtype | Rank | Shape | Description | Presence || --- | --- | --- | --- | --- | --- || `output` | `T` | same as `data` | same as `data` | Result tensor of rank r with the same shape as `data`, with selected positions overwritten or reduced by `updates`. | required |## Attributes1 unmodified line| Attribute | Default | Description || --- | --- | --- || `reduction` | `"none"` | Reduction to apply when writing each update value: `none` (overwrite, no duplicate index tuples), `add`, `mul`, `max`, or `min`. |## Type constraints4 unmodified lines## Files- [`metadata.json`](build/webgpu/metadata.json) — kernel metadata (id, digests, per-variant templates, provenance)- [`manifest.json`](build/webgpu/manifest.json) — the op contract (source of truth)- [`test.json`](build/webgpu/test.json) — correctness cases- [`bench.json`](build/webgpu/bench.json) — benchmark + tuning cases9 unmodified lines## Use with `@huggingface/kernels````shnpm install --save-exact @huggingface/kernels@0.0.1-preview.2```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.
12345{"op": "ai.onnx.ScatterND","cases": [{"name": "row_updates",1234{"cases": [{"name": "row_updates",
1 unmodified line2345678910111213141516171817 unmodified lines363738394041421 unmodified line// vec4-copies the contiguous inner slice from updates[row] into// output[scatter_index]. This path handles indexDepth == 1 (scatter along// data axis 0) with an inner size divisible by four. It performs no reduction;// duplicate indices are last-write-wins, matching ONNX's nondeterministic// duplicate-index semantics.{% if usesF16 %}enable f16;{% endif %}{{ env.wgsl.resourceDeclarations }}const WG: u32 = {{ tunables.WORKGROUP_SIZE }}u;const NUM_INDICES: u32 = {{ source.numIndices }}u;const AXIS_DIM: u32 = {{ source.axisDim }}u;const ROW_VECS: u32 = {{ source.rowVecs }}u;const INVALID_INDEX: u32 = 0xffffffffu;fn normalize_index(raw: {{ indexScalar }}, dim: u32) -> u32 {17 unmodified lines) {for (var row = wid.x; row < NUM_INDICES; row += nwg.x) {let scatter_index = normalize_index(indices[row], AXIS_DIM);// Out-of-range index: skip the row (ONNX leaves it to the copied `data`).// The continue is uniform across the workgroup (all threads share `row`).if (scatter_index == INVALID_INDEX) {continue;1 unmodified line23456789101112131417 unmodified lines323334353637381 unmodified line// vec4-copies the contiguous inner slice from updates[row] into// output[scatter_index]. This path handles indexDepth == 1 (scatter along// data axis 0) with an inner size divisible by four. It performs no reduction;// indices must be unique, as required by ONNX for reduction=none.{{ env.wgsl.resourceDeclarations }}const WG: u32 = {{ tunables.WORKGROUP_SIZE }}u;const NUM_INDICES: u32 = {{ numIndices }}u;const AXIS_DIM: u32 = {{ axisDimSpec }}u;const ROW_VECS: u32 = {{ rowVecs }}u;const INVALID_INDEX: u32 = 0xffffffffu;fn normalize_index(raw: {{ indexScalar }}, dim: u32) -> u32 {17 unmodified lines) {for (var row = wid.x; row < NUM_INDICES; row += nwg.x) {let scatter_index = normalize_index(indices[row], AXIS_DIM);// Defensively skip out-of-range indices, which are invalid ONNX inputs.// The continue is uniform across the workgroup (all threads share `row`).if (scatter_index == INVALID_INDEX) {continue;
1 unmodified line23456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263644 unmodified lines697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072088 unmodified lines2172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582594 unmodified lines2642652662672682692702712722732742752762772782792801 unmodified line2822832842852862872882892 unmodified lines2922932942952962972984 unmodified lines3033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543551 unmodified line3573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963971 unmodified line3994004014024034044053 unmodified lines4094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534541 unmodified line4564574584594604614621 unmodified line4644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974981 unmodified line5005015025035045055065074 unmodified lines5125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535541 unmodified line5565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885891 unmodified line"domain": "ai.onnx","name": "ScatterND","sinceVersion": 18,"description": "Copies `data` and then scatters values from `updates` into the copy at positions specified by `indices`, producing an output with the same shape as `data`. Each entry in `indices` is a k-tuple that addresses either a single element (when k equals the rank of `data`) or a slice; an optional `reduction` attribute replaces the default overwrite with an elementwise `add`, `mul`, `max`, or `min` accumulation.","inputs": [{"role": "data","dtype": "T","description": "Source tensor of rank r >= 1 that is copied to form the base of the output."},{"role": "indices","dtype": "I","description": "Logical int64 index tensor of rank q >= 1 whose last dimension gives signed k-tuples that address into `data`; WebGPU stores it as int32."},{"role": "updates","dtype": "T","description": "Values to scatter into the output, of rank q + r - k - 1, matching the leading (q-1) index dimensions and the trailing (r-k) data slice dimensions."}],"outputs": [{"role": "output","dtype": "T","rank": "ranks.data","description": "Result tensor of rank r with the same shape as `data`, with selected positions overwritten or reduced by `updates`.","shape": "shapes.data"}],"attributes": { "reduction": "none" },"attributeDescriptions": {"reduction": "Reduction to apply when writing each update value: `none` (overwrite), `add`, `mul`, `max`, or `min`."},"attributeConstraints": { "reduction": { "values": ["none", "add", "mul", "max", "min"] } },"typeConstraints": {"T": ["float32", "float16", "int32", "uint32", "int8", "uint8", "int16", "bool"],"I": ["int64"]},"args": {"data": { "kind": "tensor", "semantic": "data", "role": "input" },"indices": { "kind": "tensor", "semantic": "indices", "role": "indices", "dtype": "int32", "narrowing": "checked" },"updates": { "kind": "tensor", "semantic": "updates", "role": "updates" },"output": { "kind": "tensor", "semantic": "output", "role": "output" }},"tunables": {"WORKGROUP_SIZE": 256,"F16_ATOMIC_MIN_UPDATES": 4096,"SCALAR_ADD_MIN_UPDATES": 256,"PREAGG_ITEMS_PER_THREAD": 8,"PREAGG_MIN_DUPLICATION": 8,"PREAGG_SUBGROUP_ROUNDS": 2,"SCALAR_ADD_ITEMS_PER_THREAD": 16},"derive": {"deviceWorkgroupCap": "min(device.limits.maxComputeInvocationsPerWorkgroup, device.limits.maxComputeWorkgroupSizeX)","foldedDispatchCapacity": "device.limits.maxComputeWorkgroupsPerDimension * device.limits.maxComputeWorkgroupsPerDimension","indexDepth": "dim(shapes.indices, ranks.indices - 1)","narrowIntData": "tensorDtypes.data == \"int8\" or tensorDtypes.data == \"uint8\" or tensorDtypes.data == \"int16\"","validLayout": "(dtypes.I == \"u32\" or dtypes.I == \"i32\") and ranks.data == ranks.output and ranks.data >= 1 and ranks.indices >= 2 and indexDepth <= ranks.data and ranks.updates == ranks.indices - 1 + ranks.data - indexDepth and numel(shapes.data) == numel(shapes.output)","workgroupLimit": "min(tunables.WORKGROUP_SIZE, deviceWorkgroupCap)","workgroupSize": "max(1, pow2ceil(workgroupLimit + 1) / 2)","foldedThreadCapacity": "foldedDispatchCapacity * workgroupSize",4 unmodified lines"preaggStorageFits": "workgroupSize * dtypeBytes(\"float32\") + 16 <= device.limits.maxComputeWorkgroupStorageSize","scalarAddStorageFits": "workgroupSize * dtypeBytes(\"float32\") <= device.limits.maxComputeWorkgroupStorageSize"},"bindingSets": {"copy": [{"name": "src","arg": "data","semantic": "data","buffer": { "type": "read-only-storage" },"elementType": "$copyElementType"},{"name": "dst","arg": "output","semantic": "output","buffer": { "type": "storage" },"elementType": "$copyElementType"}],"rowVec4": [{"name": "indices","arg": "indices","semantic": "indices","buffer": { "type": "read-only-storage" },"elementType": "$indexScalar"},{"name": "updates","arg": "updates","semantic": "updates","buffer": { "type": "read-only-storage" },"elementType": "$vectorScalar"},{"name": "output","arg": "output","semantic": "output","buffer": { "type": "storage" },"elementType": "$vectorScalar"}],"scatter": [{"name": "indices","arg": "indices","semantic": "indices","buffer": { "type": "read-only-storage" },"elementType": "$indexScalar"},{"name": "updates","arg": "updates","semantic": "updates","buffer": { "type": "read-only-storage" },"elementType": "$updateElement"},{"name": "output","arg": "output","semantic": "output","buffer": { "type": "storage" },"elementType": "$outputElement"},{"name": "params","semantic": "kernel.params","buffer": { "type": "uniform" },"struct": { "name": "Params", "fields": [{ "name": "count", "type": "u32", "value": "numel(shapes.updates)" }] }}],"f16WideInit": [{"name": "narrow","arg": "data","semantic": "data","buffer": { "type": "read-only-storage" },"elementType": "f16"},{ "name": "wide", "semantic": "accum", "buffer": { "type": "storage" }, "elementType": "u32" },{"name": "params","semantic": "kernel.params","buffer": { "type": "uniform" },"struct": { "name": "Params", "fields": [{ "name": "count", "type": "u32", "value": "numel(shapes.output)" }] }}],"f16AtomicAccumulate": [{"name": "indices","arg": "indices","semantic": "indices","buffer": { "type": "read-only-storage" },"elementType": "$indexScalar"},{"name": "updates","arg": "updates","semantic": "updates","buffer": { "type": "read-only-storage" },"elementType": "f16"},{ "name": "output", "semantic": "accum", "buffer": { "type": "storage" }, "elementType": "atomic<u32>" },{"name": "params","semantic": "kernel.params","buffer": { "type": "uniform" },"struct": { "name": "Params", "fields": [{ "name": "count", "type": "u32", "value": "numel(shapes.updates)" }] }}],"f16NarrowFinalize": [{ "name": "wide", "semantic": "accum", "buffer": { "type": "read-only-storage" }, "elementType": "u32" },{ "name": "narrow", "arg": "output", "semantic": "output", "buffer": { "type": "storage" }, "elementType": "f16" },{"name": "params","semantic": "kernel.params","buffer": { "type": "uniform" },"struct": { "name": "Params", "fields": [{ "name": "count", "type": "u32", "value": "numel(shapes.output)" }] }}],"narrowWrap": [{ "name": "values", "arg": "output", "semantic": "output", "buffer": { "type": "storage" }, "elementType": "u32" },{"name": "params","semantic": "kernel.params","buffer": { "type": "uniform" },"struct": { "name": "Params", "fields": [{ "name": "count", "type": "u32", "value": "numel(shapes.output)" }] }}]},"variants": [{"id": "reduction_f16_atomic_f32","priority": 35,"when": ["(attrs.reduction == \"add\" or attrs.reduction == \"min\" or attrs.reduction == \"max\")", "dtypes.T == \"f16\"", "validLayout", "indexDepth == ranks.data", "numel(shapes.updates) >= tunables.F16_ATOMIC_MIN_UPDATES", "f16Ok(dtypes.T)", "f16AccumFits", "outputDispatchFits", "updateDispatchFits"],"constants": {"scalar": "\"f32\"","indexScalar": "dtypes.I","usesF16": true,8 unmodified lines{"id": "init","name": "ScatterND.F16InitF32","source": { "shader": "scatter-f16-f32-convert.wgsl.jinja", "inputs": { "toWide": true } },"bindings": "f16WideInit","dispatch": { "threads": "numel(shapes.output)", "workgroupSize": "workgroupSize" }},{"id": "scatter","name": "ScatterND.F16AtomicF32","subgroupCollectivesWidth": "portable","source": {"shader": "scatter-nd-reduction-atomic.wgsl.jinja","inputs": {"dataShape": "shapes.data","indicesShape": "shapes.indices","updatesShape": "shapes.updates","dataRank": "ranks.data","indicesRank": "ranks.indices","updatesRank": "ranks.updates","indexDepth": "indexDepth"}},"bindings": "f16AtomicAccumulate","dispatch": { "threads": "numel(shapes.updates)", "workgroupSize": "workgroupSize" }},{"id": "finalize","name": "ScatterND.F16FinalizeF32","source": { "shader": "scatter-f16-f32-convert.wgsl.jinja", "inputs": { "toWide": false } },"bindings": "f16NarrowFinalize","dispatch": { "threads": "numel(shapes.output)", "workgroupSize": "workgroupSize" }}]},{"id": "scalar_output_add_parallel_reduce","priority": 30,"when": ["attrs.reduction == \"add\"", "validLayout", "dtypes.T == \"f32\"", "ranks.data == 1", "ranks.output == 1", "numel(shapes.data) == 1", "numel(shapes.output) == 1", "ranks.indices == 2", "dim(shapes.indices, 1) == 1", "ranks.updates == 1", "dim(shapes.updates, 0) == dim(shapes.indices, 0)", "numel(shapes.updates) >= tunables.SCALAR_ADD_MIN_UPDATES", "scalarAddStorageFits"],"constants": {"scalar": "dtypes.T","indexScalar": "dtypes.I","copyElementType": "dtypes.T",4 unmodified lines{"id": "copy","name": "ScatterND.Copy","source": { "shader": "scatter-flat-copy.wgsl.jinja", "inputs": { "count": "numel(shapes.output)" } },"bindings": "copy","dispatch": { "gridStride": "numel(shapes.output)", "workgroupSize": "workgroupSize" }},{"id": "reduce","name": "ScatterND.ScalarAddParallelReduce","shader": "scatter-scalar-add.wgsl.jinja","bindings": "scatter","dispatch": {"x": "min(ceilDiv(numel(shapes.updates), workgroupSize * tunables.SCALAR_ADD_ITEMS_PER_THREAD), device.limits.maxComputeWorkgroupsPerDimension)"}}]1 unmodified line{"id": "reduction_narrow_wrap_atomic","priority": 26,"when": ["(attrs.reduction == \"add\" or attrs.reduction == \"mul\")", "validLayout", "narrowIntData", "updateDispatchFits", "outputDispatchFits"],"constants": {"scalar": "\"u32\"","indexScalar": "dtypes.I","usesF16": false,2 unmodified lines"useWorkgroupPreagg": false,"preaggRounds": "tunables.PREAGG_SUBGROUP_ROUNDS","preaggItemsPerThread": "tunables.PREAGG_ITEMS_PER_THREAD","workgroupSize": "workgroupSize","narrowBits": "16 if tensorDtypes.data == \"int16\" else 8","narrowSigned": "tensorDtypes.data == \"int8\" or tensorDtypes.data == \"int16\"","copyElementType": "(\"vec4<\" ~ dtypes.T ~ \">\") if numel(shapes.output) % 4 == 0 else dtypes.T",4 unmodified lines{"id": "copy","name": "ScatterND.Copy","source": {"shader": "scatter-flat-copy.wgsl.jinja","inputs": { "count": "numel(shapes.output) / 4 if numel(shapes.output) % 4 == 0 else numel(shapes.output)" }},"bindings": "copy","dispatch": {"gridStride": "numel(shapes.output) / 4 if numel(shapes.output) % 4 == 0 else numel(shapes.output)","workgroupSize": "workgroupSize"}},{"id": "scatter","name": "ScatterND.NarrowWrapAtomic","subgroupCollectivesWidth": "portable","source": {"shader": "scatter-nd-reduction-atomic.wgsl.jinja","inputs": {"dataShape": "shapes.data","indicesShape": "shapes.indices","updatesShape": "shapes.updates","dataRank": "ranks.data","indicesRank": "ranks.indices","updatesRank": "ranks.updates","indexDepth": "indexDepth"}},"bindings": "scatter","dispatch": { "threads": "numel(shapes.updates)", "workgroupSize": "workgroupSize" }},{"id": "narrow","name": "ScatterND.NarrowWrapFinalize","shader": "scatter-narrow-wrap.wgsl.jinja","bindings": "narrowWrap","dispatch": { "threads": "numel(shapes.output)", "workgroupSize": "workgroupSize" }}]},{"id": "reduction_f16_packed_atomic_add","priority": 36,"when": ["attrs.reduction == \"add\"", "dtypes.T == \"f16\"", "validLayout", "indexDepth < ranks.data", "numel(shapes.output) % 2 == 0", "numel(shapes.updates) >= tunables.F16_ATOMIC_MIN_UPDATES", "f16Ok(dtypes.T)", "outputDispatchFits", "updateDispatchFits"],"constants": {"indexScalar": "dtypes.I","usesF16": true,"copyElementType": "(\"vec4<\" ~ dtypes.T ~ \">\") if numel(shapes.output) % 4 == 0 else dtypes.T","workgroupSize": "workgroupSize","updateElement": "\"f16\"","outputElement": "\"atomic<u32>\""},1 unmodified line{"id": "copy","name": "ScatterND.Copy","source": {"shader": "scatter-flat-copy.wgsl.jinja","inputs": { "count": "numel(shapes.output) / 4 if numel(shapes.output) % 4 == 0 else numel(shapes.output)" }},"bindings": "copy","dispatch": {"gridStride": "numel(shapes.output) / 4 if numel(shapes.output) % 4 == 0 else numel(shapes.output)","workgroupSize": "workgroupSize"}},{"id": "scatter","name": "ScatterND.F16PackedAtomicAdd","source": {"shader": "scatter-nd-reduction-f16-packed-atomic.wgsl.jinja","inputs": {"dataShape": "shapes.data","indicesShape": "shapes.indices","updatesShape": "shapes.updates","dataRank": "ranks.data","indicesRank": "ranks.indices","updatesRank": "ranks.updates","indexDepth": "indexDepth"}},"bindings": "scatter","dispatch": { "threads": "numel(shapes.updates)", "workgroupSize": "workgroupSize" }}]},{"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\")))", "updateDispatchFits"],"constants": {"scalar": "dtypes.T","indexScalar": "dtypes.I","usesF16": "dtypes.T == \"f16\"",1 unmodified line"useSubgroups": "device.features.has(\"subgroups\") and (attrs.reduction == \"add\" or attrs.reduction == \"mul\")","useWorkgroupPreagg": "attrs.reduction == \"add\" and dtypes.T == \"f32\" and indexDepth == ranks.data and numel(shapes.updates) >= numel(shapes.output) * tunables.PREAGG_MIN_DUPLICATION and preaggStorageFits","preaggRounds": "tunables.PREAGG_SUBGROUP_ROUNDS","workgroupSize": "workgroupSize","preaggItemsPerThread": "tunables.PREAGG_ITEMS_PER_THREAD","copyElementType": "(\"vec4<\" ~ dtypes.T ~ \">\") if numel(shapes.output) % 4 == 0 else dtypes.T","updateElement": "dtypes.T",3 unmodified lines{"id": "copy","name": "ScatterND.Copy","source": {"shader": "scatter-flat-copy.wgsl.jinja","inputs": { "count": "numel(shapes.output) / 4 if numel(shapes.output) % 4 == 0 else numel(shapes.output)" }},"bindings": "copy","dispatch": {"gridStride": "numel(shapes.output) / 4 if numel(shapes.output) % 4 == 0 else numel(shapes.output)","workgroupSize": "workgroupSize"}},{"id": "scatter","name": "ScatterND.ReductionAtomic","subgroupCollectivesWidth": "portable","source": {"shader": "scatter-nd-reduction-atomic.wgsl.jinja","inputs": {"dataShape": "shapes.data","indicesShape": "shapes.indices","updatesShape": "shapes.updates","dataRank": "ranks.data","indicesRank": "ranks.indices","updatesRank": "ranks.updates","indexDepth": "indexDepth"}},"bindings": "scatter","dispatch": {"threads": "ceilDiv(numel(shapes.updates), tunables.PREAGG_ITEMS_PER_THREAD) if attrs.reduction == \"add\" and dtypes.T == \"f32\" and indexDepth == ranks.data and numel(shapes.updates) >= numel(shapes.output) * tunables.PREAGG_MIN_DUPLICATION and preaggStorageFits else numel(shapes.updates)","workgroupSize": "workgroupSize"}}]},{"id": "reduction_slice","priority": 21,"supersededBy": ["scalar_output_add_parallel_reduce"],"when": ["(attrs.reduction == \"add\" or attrs.reduction == \"mul\" or attrs.reduction == \"min\" or attrs.reduction == \"max\")", "validLayout", "f16Ok(dtypes.T)"],"constants": {"scalar": "dtypes.T","indexScalar": "dtypes.I","usesF16": "dtypes.T == \"f16\"",1 unmodified line"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\"","copyElementType": "(\"vec4<\" ~ dtypes.T ~ \">\") if numel(shapes.output) % 4 == 0 else dtypes.T","workgroupSize": "workgroupSize","updateElement": "dtypes.T","outputElement": "dtypes.T"},1 unmodified line{"id": "copy","name": "ScatterND.Copy","source": {"shader": "scatter-flat-copy.wgsl.jinja","inputs": { "count": "numel(shapes.output) / 4 if numel(shapes.output) % 4 == 0 else numel(shapes.output)" }},"bindings": "copy","dispatch": {"gridStride": "numel(shapes.output) / 4 if numel(shapes.output) % 4 == 0 else numel(shapes.output)","workgroupSize": "workgroupSize"}},{"id": "scatter","name": "ScatterND.ReductionSlice","source": {"shader": "scatter-nd-reduction-slice.wgsl.jinja","inputs": {"dataShape": "shapes.data","indicesShape": "shapes.indices","updatesShape": "shapes.updates","dataRank": "ranks.data","indicesRank": "ranks.indices","updatesRank": "ranks.updates","indexDepth": "indexDepth"}},"bindings": "scatter","dispatch": {"gridStride": "numel(shapes.updates) * indexDepth / numel(shapes.indices)","workgroupSize": "workgroupSize"}}]1 unmodified line{"id": "row_fast_vec4","priority": 10,"when": ["attrs.reduction == \"none\"", "validLayout", "f16Ok(dtypes.T)", "indexDepth == 1", "inner(shapes.data, 0) % 4 == 0", "numel(shapes.indices) > 0"],"constants": {"scalar": "dtypes.T","indexScalar": "dtypes.I","usesF16": "dtypes.T == \"f16\"",4 unmodified lines{"id": "copy","name": "ScatterND.Copy","source": {"shader": "scatter-flat-copy.wgsl.jinja","inputs": { "count": "numel(shapes.output) / 4 if numel(shapes.output) % 4 == 0 else numel(shapes.output)" }},"bindings": "copy","dispatch": {"gridStride": "numel(shapes.output) / 4 if numel(shapes.output) % 4 == 0 else numel(shapes.output)","workgroupSize": "workgroupSize"},"viewAlias": [{ "input": "src", "output": "dst" }]},{"id": "scatter","name": "ScatterND.Scatter","source": {"shader": "datamove-scatter-row.wgsl.jinja","inputs": {"numIndices": "numel(shapes.indices)","axisDim": "dim(shapes.data, 0)","rowVecs": "inner(shapes.data, 0) / 4"}},"bindings": "rowVec4","dispatch": { "gridStride": "numel(shapes.indices)" }}]},{"id": "batch0","priority": 0,"when": ["attrs.reduction == \"none\"", "validLayout", "f16Ok(dtypes.T)", "updateDispatchFits"],"constants": {"scalar": "dtypes.T","indexScalar": "dtypes.I","usesF16": "dtypes.T == \"f16\"","copyElementType": "(\"vec4<\" ~ dtypes.T ~ \">\") if numel(shapes.output) % 4 == 0 else dtypes.T","workgroupSize": "workgroupSize","updateElement": "dtypes.T","outputElement": "dtypes.T"},1 unmodified line{"id": "copy","name": "ScatterND.Copy","source": {"shader": "scatter-flat-copy.wgsl.jinja","inputs": { "count": "numel(shapes.output) / 4 if numel(shapes.output) % 4 == 0 else numel(shapes.output)" }},"bindings": "copy","dispatch": {"gridStride": "numel(shapes.output) / 4 if numel(shapes.output) % 4 == 0 else numel(shapes.output)","workgroupSize": "workgroupSize"},"viewAlias": [{ "input": "src", "output": "dst" }]},{"id": "scatter","name": "ScatterND.Scatter","source": {"shader": "scatter-nd.wgsl.jinja","inputs": {"dataShape": "shapes.data","indicesShape": "shapes.indices","updatesShape": "shapes.updates","dataRank": "ranks.data","indicesRank": "ranks.indices","updatesRank": "ranks.updates","indexDepth": "indexDepth"}},"bindings": "scatter","dispatch": { "threads": "numel(shapes.updates)", "workgroupSize": "workgroupSize" }}]}1 unmodified line23456789101112131415161718192021222324252627282930313233344 unmodified lines39404142434445464748495051525354555657585960616263646566678 unmodified lines7677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361374 unmodified lines1421431441451461471481491501511521531541551561571581591601611621631 unmodified line1651661671681691701711722 unmodified lines1751761771781791804 unmodified lines1851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392401 unmodified line2422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812821 unmodified line2842852862872882893 unmodified lines2932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343351 unmodified line3373383393403413421 unmodified line3443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743751 unmodified line3773783793803813823833844 unmodified lines3893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304311 unmodified line4334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654661 unmodified line"domain": "ai.onnx","name": "ScatterND","sinceVersion": 18,"inputs": {"data": { "dtype": "T" },"indices": { "dtype": "I", "storage": "int32", "narrowing": "checked" },"updates": { "dtype": "T" }},"outputs": { "output": { "dtype": "T", "rank": "ranks.data", "shape": "shapes.data" } },"attributes": { "reduction": { "default": "none" } },"attributeConstraints": { "reduction": { "values": ["none", "add", "mul", "max", "min"] } },"typeConstraints": {"T": ["float32", "float16", "int32", "uint32", "int8", "uint8", "int16", "bool"],"I": ["int64"]},"tunables": {"WORKGROUP_SIZE": { "default": 256 },"F16_ATOMIC_MIN_UPDATES": { "default": 4096 },"SCALAR_ADD_MIN_UPDATES": { "default": 256 },"PREAGG_ITEMS_PER_THREAD": { "default": 8 },"PREAGG_MIN_DUPLICATION": { "default": 8 },"PREAGG_SUBGROUP_ROUNDS": { "default": 2 },"SCALAR_ADD_ITEMS_PER_THREAD": { "default": 16 }},"derive": {"deviceWorkgroupCap": "min(device.limits.maxComputeInvocationsPerWorkgroup, device.limits.maxComputeWorkgroupSizeX)","foldedDispatchCapacity": "min(device.limits.maxComputeWorkgroupsPerDimension, 65535) * min(device.limits.maxComputeWorkgroupsPerDimension, 65535)","indexDepth": "dim(shapes.indices, ranks.indices - 1)","narrowIntData": "tensorDtypes.data == \"int8\" or tensorDtypes.data == \"uint8\" or tensorDtypes.data == \"int16\"","validLayout": "(dtypes.I == \"u32\" or dtypes.I == \"i32\") and ranks.data == ranks.output and ranks.data >= 1 and ranks.indices >= 1 and indexDepth <= ranks.data and ranks.updates == ranks.indices - 1 + ranks.data - indexDepth and numel(shapes.data) == numel(shapes.output)","workgroupLimit": "min(tunables.WORKGROUP_SIZE, deviceWorkgroupCap)","workgroupSize": "max(1, pow2ceil(workgroupLimit + 1) / 2)","foldedThreadCapacity": "foldedDispatchCapacity * workgroupSize",4 unmodified lines"preaggStorageFits": "workgroupSize * dtypeBytes(\"float32\") + 16 <= device.limits.maxComputeWorkgroupStorageSize","scalarAddStorageFits": "workgroupSize * dtypeBytes(\"float32\") <= device.limits.maxComputeWorkgroupStorageSize"},"when": ["validLayout"],"bindings": {"params": { "buffer": "uniform", "struct": [{ "name": "count", "type": "u32", "value": "numel(shapes.output)" }] },"indices": { "buffer": "read-only-storage", "elementType": "$indexScalar" },"output": { "scratch": "accum", "buffer": "storage", "elementType": "atomic<u32>" },"params_2": {"name": "params","buffer": "uniform","struct": [{ "name": "count", "type": "u32", "value": "numel(shapes.updates)" }]},"src": { "arg": "data", "buffer": "read-only-storage", "elementType": "$copyElementType" },"dst": { "arg": "output", "buffer": "storage", "elementType": "$copyElementType" },"updates_2": { "name": "updates", "buffer": "read-only-storage", "elementType": "$updateElement" },"output_2": { "name": "output", "buffer": "storage", "elementType": "$outputElement" },"updates_3": { "name": "updates", "buffer": "read-only-storage", "elementType": "$vectorScalar" },"output_3": { "name": "output", "buffer": "storage", "elementType": "$vectorScalar" }},"variants": [{"id": "reduction_f16_atomic_f32","priority": 35,"when": ["(attrs.reduction == \"add\" or attrs.reduction == \"min\" or attrs.reduction == \"max\")", "dtypes.T == \"f16\"", "indexDepth == ranks.data", "numel(shapes.updates) >= tunables.F16_ATOMIC_MIN_UPDATES", "f16Ok(dtypes.T)", "f16AccumFits", "outputDispatchFits", "updateDispatchFits"],"derive": {"scalar": "\"f32\"","indexScalar": "dtypes.I","usesF16": true,8 unmodified lines{"id": "init","name": "ScatterND.F16InitF32","shader": "scatter-f16-f32-convert.wgsl.jinja","derive": { "toWide": true },"bindings": [{ "arg": "data", "name": "narrow", "elementType": "f16" },{ "scratch": "accum", "name": "wide", "elementType": "u32" },"params"],"dispatch": {"x": "min(ceilDiv((numel(shapes.output)), (workgroupSize)), 65535)","y": "ceilDiv(ceilDiv((numel(shapes.output)), (workgroupSize)), 65535)","z": 1}},{"id": "scatter","name": "ScatterND.F16AtomicF32","shader": "scatter-nd-reduction-atomic.wgsl.jinja","derive": {"dataShape": "shapes.data","indicesShape": "shapes.indices","updatesShape": "shapes.updates","dataRank": "ranks.data","indicesRank": "ranks.indices","updatesRank": "ranks.updates"},"bindings": ["indices", { "arg": "updates", "elementType": "f16" }, "output", "params_2"],"dispatch": {"x": "min(ceilDiv((numel(shapes.updates)), (workgroupSize)), 65535)","y": "ceilDiv(ceilDiv((numel(shapes.updates)), (workgroupSize)), 65535)","z": 1},"subgroupCollectivesWidth": "portable"},{"id": "finalize","name": "ScatterND.F16FinalizeF32","shader": "scatter-f16-f32-convert.wgsl.jinja","derive": { "toWide": false },"bindings": [{ "scratch": "accum", "name": "wide", "buffer": "read-only-storage", "elementType": "u32" },{ "arg": "output", "name": "narrow", "elementType": "f16" },"params"],"dispatch": {"x": "min(ceilDiv((numel(shapes.output)), (workgroupSize)), 65535)","y": "ceilDiv(ceilDiv((numel(shapes.output)), (workgroupSize)), 65535)","z": 1}}]},{"id": "scalar_output_add_parallel_reduce","priority": 30,"when": ["attrs.reduction == \"add\"", "dtypes.T == \"f32\"", "ranks.data == 1", "ranks.output == 1", "numel(shapes.data) == 1", "numel(shapes.output) == 1", "ranks.indices == 2", "dim(shapes.indices, 1) == 1", "ranks.updates == 1", "dim(shapes.updates, 0) == dim(shapes.indices, 0)", "numel(shapes.updates) >= tunables.SCALAR_ADD_MIN_UPDATES", "scalarAddStorageFits"],"derive": {"scalar": "dtypes.T","indexScalar": "dtypes.I","copyElementType": "dtypes.T",4 unmodified lines{"id": "copy","name": "ScatterND.Copy","shader": "scatter-flat-copy.wgsl.jinja","derive": { "count": "numel(shapes.output)" },"bindings": ["src", "dst"],"dispatch": {"x": "min(ceilDiv((numel(shapes.output)), (workgroupSize)), 65535)","y": "ceilDiv(ceilDiv((numel(shapes.output)), (workgroupSize)), 65535)","z": 1}},{"id": "reduce","name": "ScatterND.ScalarAddParallelReduce","shader": "scatter-scalar-add.wgsl.jinja","bindings": ["indices", "updates_2", "output_2", "params_2"],"dispatch": {"x": "min(ceilDiv(numel(shapes.updates), workgroupSize * tunables.SCALAR_ADD_ITEMS_PER_THREAD), min(device.limits.maxComputeWorkgroupsPerDimension, 65535))"}}]1 unmodified line{"id": "reduction_narrow_wrap_atomic","priority": 26,"when": ["(attrs.reduction == \"add\" or attrs.reduction == \"mul\")", "narrowIntData", "updateDispatchFits", "outputDispatchFits"],"derive": {"scalar": "\"u32\"","indexScalar": "dtypes.I","usesF16": false,2 unmodified lines"useWorkgroupPreagg": false,"preaggRounds": "tunables.PREAGG_SUBGROUP_ROUNDS","preaggItemsPerThread": "tunables.PREAGG_ITEMS_PER_THREAD","narrowBits": "16 if tensorDtypes.data == \"int16\" else 8","narrowSigned": "tensorDtypes.data == \"int8\" or tensorDtypes.data == \"int16\"","copyElementType": "(\"vec4<\" ~ dtypes.T ~ \">\") if numel(shapes.output) % 4 == 0 else dtypes.T",4 unmodified lines{"id": "copy","name": "ScatterND.Copy","shader": "scatter-flat-copy.wgsl.jinja","derive": { "count": "numel(shapes.output) / 4 if numel(shapes.output) % 4 == 0 else numel(shapes.output)" },"bindings": ["src", "dst"],"dispatch": {"x": "min(ceilDiv((numel(shapes.output) / 4 if numel(shapes.output) % 4 == 0 else numel(shapes.output)), (workgroupSize)), 65535)","y": "ceilDiv(ceilDiv((numel(shapes.output) / 4 if numel(shapes.output) % 4 == 0 else numel(shapes.output)), (workgroupSize)), 65535)","z": 1}},{"id": "scatter","name": "ScatterND.NarrowWrapAtomic","shader": "scatter-nd-reduction-atomic.wgsl.jinja","derive": {"dataShape": "shapes.data","indicesShape": "shapes.indices","updatesShape": "shapes.updates","dataRank": "ranks.data","indicesRank": "ranks.indices","updatesRank": "ranks.updates"},"bindings": ["indices", "updates_2", "output_2", "params_2"],"dispatch": {"x": "min(ceilDiv((numel(shapes.updates)), (workgroupSize)), 65535)","y": "ceilDiv(ceilDiv((numel(shapes.updates)), (workgroupSize)), 65535)","z": 1},"subgroupCollectivesWidth": "portable"},{"id": "narrow","name": "ScatterND.NarrowWrapFinalize","shader": "scatter-narrow-wrap.wgsl.jinja","bindings": [{ "arg": "output", "name": "values", "elementType": "u32" }, "params"],"dispatch": {"x": "min(ceilDiv((numel(shapes.output)), (workgroupSize)), 65535)","y": "ceilDiv(ceilDiv((numel(shapes.output)), (workgroupSize)), 65535)","z": 1}}]},{"id": "reduction_f16_packed_atomic_add","priority": 36,"when": ["attrs.reduction == \"add\"", "dtypes.T == \"f16\"", "indexDepth < ranks.data", "numel(shapes.output) % 2 == 0", "numel(shapes.updates) >= tunables.F16_ATOMIC_MIN_UPDATES", "f16Ok(dtypes.T)", "outputDispatchFits", "updateDispatchFits"],"derive": {"indexScalar": "dtypes.I","usesF16": true,"copyElementType": "(\"vec4<\" ~ dtypes.T ~ \">\") if numel(shapes.output) % 4 == 0 else dtypes.T","updateElement": "\"f16\"","outputElement": "\"atomic<u32>\""},1 unmodified line{"id": "copy","name": "ScatterND.Copy","shader": "scatter-flat-copy.wgsl.jinja","derive": { "count": "numel(shapes.output) / 4 if numel(shapes.output) % 4 == 0 else numel(shapes.output)" },"bindings": ["src", "dst"],"dispatch": {"x": "min(ceilDiv((numel(shapes.output) / 4 if numel(shapes.output) % 4 == 0 else numel(shapes.output)), (workgroupSize)), 65535)","y": "ceilDiv(ceilDiv((numel(shapes.output) / 4 if numel(shapes.output) % 4 == 0 else numel(shapes.output)), (workgroupSize)), 65535)","z": 1}},{"id": "scatter","name": "ScatterND.F16PackedAtomicAdd","shader": "scatter-nd-reduction-f16-packed-atomic.wgsl.jinja","derive": {"dataShape": "shapes.data","indicesShape": "shapes.indices","updatesShape": "shapes.updates","dataRank": "ranks.data","indicesRank": "ranks.indices","updatesRank": "ranks.updates"},"bindings": ["indices", "updates_2", "output_2", "params_2"],"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\")", "(tensorDtypes.data == \"float32\" or tensorDtypes.data == \"int32\" or tensorDtypes.data == \"uint32\" or (narrowIntData and (attrs.reduction == \"min\" or attrs.reduction == \"max\")))", "updateDispatchFits"],"derive": {"scalar": "dtypes.T","indexScalar": "dtypes.I","usesF16": "dtypes.T == \"f16\"",1 unmodified line"useSubgroups": "device.features.has(\"subgroups\") and (attrs.reduction == \"add\" or attrs.reduction == \"mul\")","useWorkgroupPreagg": "attrs.reduction == \"add\" and dtypes.T == \"f32\" and indexDepth == ranks.data and numel(shapes.updates) >= numel(shapes.output) * tunables.PREAGG_MIN_DUPLICATION and preaggStorageFits","preaggRounds": "tunables.PREAGG_SUBGROUP_ROUNDS","preaggItemsPerThread": "tunables.PREAGG_ITEMS_PER_THREAD","copyElementType": "(\"vec4<\" ~ dtypes.T ~ \">\") if numel(shapes.output) % 4 == 0 else dtypes.T","updateElement": "dtypes.T",3 unmodified lines{"id": "copy","name": "ScatterND.Copy","shader": "scatter-flat-copy.wgsl.jinja","derive": { "count": "numel(shapes.output) / 4 if numel(shapes.output) % 4 == 0 else numel(shapes.output)" },"bindings": ["src", "dst"],"dispatch": {"x": "min(ceilDiv((numel(shapes.output) / 4 if numel(shapes.output) % 4 == 0 else numel(shapes.output)), (workgroupSize)), 65535)","y": "ceilDiv(ceilDiv((numel(shapes.output) / 4 if numel(shapes.output) % 4 == 0 else numel(shapes.output)), (workgroupSize)), 65535)","z": 1}},{"id": "scatter","name": "ScatterND.ReductionAtomic","shader": "scatter-nd-reduction-atomic.wgsl.jinja","derive": {"dataShape": "shapes.data","indicesShape": "shapes.indices","updatesShape": "shapes.updates","dataRank": "ranks.data","indicesRank": "ranks.indices","updatesRank": "ranks.updates"},"bindings": ["indices", "updates_2", "output_2", "params_2"],"dispatch": {"x": "min(ceilDiv((ceilDiv(numel(shapes.updates), tunables.PREAGG_ITEMS_PER_THREAD) if attrs.reduction == \"add\" and dtypes.T == \"f32\" and indexDepth == ranks.data and numel(shapes.updates) >= numel(shapes.output) * tunables.PREAGG_MIN_DUPLICATION and preaggStorageFits else numel(shapes.updates)), (workgroupSize)), 65535)","y": "ceilDiv(ceilDiv((ceilDiv(numel(shapes.updates), tunables.PREAGG_ITEMS_PER_THREAD) if attrs.reduction == \"add\" and dtypes.T == \"f32\" and indexDepth == ranks.data and numel(shapes.updates) >= numel(shapes.output) * tunables.PREAGG_MIN_DUPLICATION and preaggStorageFits else numel(shapes.updates)), (workgroupSize)), 65535)","z": 1},"subgroupCollectivesWidth": "portable"}]},{"id": "reduction_slice","priority": 21,"when": ["(attrs.reduction == \"add\" or attrs.reduction == \"mul\" or attrs.reduction == \"min\" or attrs.reduction == \"max\")", "f16Ok(dtypes.T)"],"supersededBy": ["scalar_output_add_parallel_reduce"],"derive": {"scalar": "dtypes.T","indexScalar": "dtypes.I","usesF16": "dtypes.T == \"f16\"",1 unmodified line"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\"","copyElementType": "(\"vec4<\" ~ dtypes.T ~ \">\") if numel(shapes.output) % 4 == 0 else dtypes.T","updateElement": "dtypes.T","outputElement": "dtypes.T"},1 unmodified line{"id": "copy","name": "ScatterND.Copy","shader": "scatter-flat-copy.wgsl.jinja","derive": { "count": "numel(shapes.output) / 4 if numel(shapes.output) % 4 == 0 else numel(shapes.output)" },"bindings": ["src", "dst"],"dispatch": {"x": "min(ceilDiv((numel(shapes.output) / 4 if numel(shapes.output) % 4 == 0 else numel(shapes.output)), (workgroupSize)), 65535)","y": "ceilDiv(ceilDiv((numel(shapes.output) / 4 if numel(shapes.output) % 4 == 0 else numel(shapes.output)), (workgroupSize)), 65535)","z": 1}},{"id": "scatter","name": "ScatterND.ReductionSlice","shader": "scatter-nd-reduction-slice.wgsl.jinja","derive": {"dataShape": "shapes.data","indicesShape": "shapes.indices","updatesShape": "shapes.updates","dataRank": "ranks.data","indicesRank": "ranks.indices","updatesRank": "ranks.updates"},"bindings": ["indices", "updates_2", "output_2", "params_2"],"dispatch": {"x": "min(ceilDiv((numel(shapes.updates) * indexDepth / numel(shapes.indices)), (workgroupSize)), min(device.limits.maxComputeWorkgroupsPerDimension, 65535))","y": 1,"z": 1}}]1 unmodified line{"id": "row_fast_vec4","priority": 10,"when": ["attrs.reduction == \"none\"", "f16Ok(dtypes.T)", "indexDepth == 1", "inner(shapes.data, 0) % 4 == 0", "numel(shapes.indices) > 0"],"derive": {"scalar": "dtypes.T","indexScalar": "dtypes.I","usesF16": "dtypes.T == \"f16\"",4 unmodified lines{"id": "copy","name": "ScatterND.Copy","shader": "scatter-flat-copy.wgsl.jinja","derive": { "count": "numel(shapes.output) / 4 if numel(shapes.output) % 4 == 0 else numel(shapes.output)" },"bindings": ["src", "dst"],"dispatch": {"x": "min(ceilDiv((numel(shapes.output) / 4 if numel(shapes.output) % 4 == 0 else numel(shapes.output)), (workgroupSize)), 65535)","y": "ceilDiv(ceilDiv((numel(shapes.output) / 4 if numel(shapes.output) % 4 == 0 else numel(shapes.output)), (workgroupSize)), 65535)","z": 1},"viewAlias": [{ "input": "src", "output": "dst" }]},{"id": "scatter","name": "ScatterND.Scatter","shader": "datamove-scatter-row.wgsl.jinja","derive": {"numIndices": "numel(shapes.indices)","axisDimSpec": "dim(shapes.data, 0)","rowVecs": "inner(shapes.data, 0) / 4"},"bindings": ["indices", "updates_3", "output_3"],"dispatch": {"x": "min(numel(shapes.indices), min(device.limits.maxComputeWorkgroupsPerDimension, 65535))","y": 1,"z": 1}}]},{"id": "batch0","priority": 0,"when": ["attrs.reduction == \"none\"", "f16Ok(dtypes.T)", "updateDispatchFits"],"derive": {"scalar": "dtypes.T","indexScalar": "dtypes.I","usesF16": "dtypes.T == \"f16\"","copyElementType": "(\"vec4<\" ~ dtypes.T ~ \">\") if numel(shapes.output) % 4 == 0 else dtypes.T","updateElement": "dtypes.T","outputElement": "dtypes.T"},1 unmodified line{"id": "copy","name": "ScatterND.Copy","shader": "scatter-flat-copy.wgsl.jinja","derive": { "count": "numel(shapes.output) / 4 if numel(shapes.output) % 4 == 0 else numel(shapes.output)" },"bindings": ["src", "dst"],"dispatch": {"x": "min(ceilDiv((numel(shapes.output) / 4 if numel(shapes.output) % 4 == 0 else numel(shapes.output)), (workgroupSize)), 65535)","y": "ceilDiv(ceilDiv((numel(shapes.output) / 4 if numel(shapes.output) % 4 == 0 else numel(shapes.output)), (workgroupSize)), 65535)","z": 1},"viewAlias": [{ "input": "src", "output": "dst" }]},{"id": "scatter","name": "ScatterND.Scatter","shader": "scatter-nd.wgsl.jinja","derive": {"dataShape": "shapes.data","indicesShape": "shapes.indices","updatesShape": "shapes.updates","dataRank": "ranks.data","indicesRank": "ranks.indices","updatesRank": "ranks.updates"},"bindings": ["indices", "updates_2", "output_2", "params_2"],"dispatch": {"x": "min(ceilDiv((numel(shapes.updates)), (workgroupSize)), 65535)","y": "ceilDiv(ceilDiv((numel(shapes.updates)), (workgroupSize)), 65535)","z": 1}}]}
1234567891011121314151617181920212223242526{"name": "ai.onnx.ScatterND","id": "_ai_onnx_scatternd_webgpu_9191cc3","version": 1,"license": "Apache-2.0","backend": { "type": "webgpu" },"digest": {"algorithm": "sha256","files": {"bench.json": "OlU9qeMBpVSt/3anSGYi9zttsxaB4rorBl4y6WpwqUI=","datamove-scatter-row.wgsl.jinja": "nfTmOf2O7JCLw3aMpwqmEnUiLlraLVBklQLxkqhVUNg=","manifest.json": "ISRWqj8bAyNt1z7/35pzxXtQvaPRq4fRwm92neVyjgo=","scatter-f16-f32-convert.wgsl.jinja": "6ZiaoKGXqY9I7aiy2QY76t8N9f8tQTVed2GoDwBD9/o=","scatter-flat-copy.wgsl.jinja": "j95cywCwuvbfDJJxf9+SLt2Li3CvLllAesHpPykppFk=","scatter-narrow-wrap.wgsl.jinja": "skKLW560sgq8K0xFclFx8eEyk5tSDoPy11OgZhEQUfI=","scatter-nd-reduction-atomic.wgsl.jinja": "EEOc7xPQZcqWGQGN9sjbiHFaDFFm+FZqj0y3CsEtDog=","scatter-nd-reduction-f16-packed-atomic.wgsl.jinja": "B8AVBcP3R7qpgdMIZvwc1wFbZhanlnEib0kXY+4Ovj0=","scatter-nd-reduction-slice.wgsl.jinja": "N9MUXlG46j0ZO144klWLlT2tq8U8yeSkI8UIih6y2Q8=","scatter-nd.wgsl.jinja": "PJRmnpsn+b33y/t3VrpSqg1VuPA3Y1VZU1O9tl0eXWc=","scatter-scalar-add.wgsl.jinja": "GUpLZ/XGwu51w1vl/GEjAKdL3+iiWzSrcWqnb6qBwyQ=","test.json": "8D1gbC8s0AyoDrU6AG/OMKPiSSOe8uJnnZXOxy8uxwE="}},"provenance": { "kernel": { "sha": "c928d21e6cc1310861cba3bafb75f5f679ecf5f3", "dirty": false } },"webgpu": { "manifestSpec": "1.0", "specialized": true, "opPath": "ops/ai.onnx.ScatterND" }}1234567891011121314151617181920212223242526272829303132333435363738{"name": "ai.onnx.ScatterND","id": "_ai_onnx_scatternd_webgpu_a07505d","version": 1,"license": "Apache-2.0","backend": { "type": "webgpu" },"digest": {"algorithm": "sha256","files": {"bench.json": "MKCSwvJxYt/6aDGuGblJOAvpZWu5h+ao+mlkXzeNAe0=","datamove-scatter-row.wgsl.jinja": "iKeu7afSqJ9trqC1O/wTsUkzLYOTBNuF+qxEOZghSLo=","manifest.json": "J9Ki7ftJdy2Rwx8MMYeI01k8cJ9Hcya2dXDT3LFyEz8=","scatter-f16-f32-convert.wgsl.jinja": "4HsmLoXQfbpO7zz1EZBTCRIixT9YitCDYw5hm6KM4bU=","scatter-flat-copy.wgsl.jinja": "mXcfAXV6Nxe+Y+cvem8Wwwt0BeqRQXaiCNhQoiynX0M=","scatter-narrow-wrap.wgsl.jinja": "QrKUwVFSIPypTMk5Go8vgqIsiJO/Lb/n5BeakIu6mME=","scatter-nd-reduction-atomic.wgsl.jinja": "EOKtQVRtTVa+S78jQTyQ2GbeAqezyqYrN2d0JmBmAcA=","scatter-nd-reduction-f16-packed-atomic.wgsl.jinja": "ccWecheCnUD/Nf+ESyUkWPBjD0srS8q5mvgHE8k+LBk=","scatter-nd-reduction-slice.wgsl.jinja": "4nndx9stQgFaFQYObZY0ztmdRjvxA6GX9iR08hc66gI=","scatter-nd.wgsl.jinja": "sYufGwGZXv+cNcPqCJQ+tmkqlBrYAR++6ePBqpAlwk0=","scatter-scalar-add.wgsl.jinja": "GUpLZ/XGwu51w1vl/GEjAKdL3+iiWzSrcWqnb6qBwyQ=","test.json": "IEtjDQmSgaE5pot/HBgG+W0FWGOoW4ov3irOg1YUAgo="}},"provenance": { "kernel": { "sha": "91d990483a174128daf7673f3f37a7c890493ae1", "dirty": false } },"webgpu": {"manifestSpec": "2.0","variants": {"reduction_f16_atomic_f32": ["scatter-f16-f32-convert.wgsl.jinja", "scatter-nd-reduction-atomic.wgsl.jinja"],"scalar_output_add_parallel_reduce": ["scatter-flat-copy.wgsl.jinja", "scatter-scalar-add.wgsl.jinja"],"reduction_narrow_wrap_atomic": ["scatter-flat-copy.wgsl.jinja", "scatter-narrow-wrap.wgsl.jinja", "scatter-nd-reduction-atomic.wgsl.jinja"],"reduction_f16_packed_atomic_add": ["scatter-flat-copy.wgsl.jinja", "scatter-nd-reduction-f16-packed-atomic.wgsl.jinja"],"reduction_atomic": ["scatter-flat-copy.wgsl.jinja", "scatter-nd-reduction-atomic.wgsl.jinja"],"reduction_slice": ["scatter-flat-copy.wgsl.jinja", "scatter-nd-reduction-slice.wgsl.jinja"],"row_fast_vec4": ["datamove-scatter-row.wgsl.jinja", "scatter-flat-copy.wgsl.jinja"],"batch0": ["scatter-flat-copy.wgsl.jinja", "scatter-nd.wgsl.jinja"]}}}
4 unmodified lines567891011121314154 unmodified lines// payload bits in u32 words so the middle pass can bind the same allocation as// atomic<u32> and perform portable float CAS operations.@compute @workgroup_size({{ workgroupSize }})fn main(@builtin(global_invocation_id) gid: vec3<u32>,@builtin(num_workgroups) nwg: vec3<u32>) {let i = gid.x + gid.y * nwg.x * {{ workgroupSize }}u;if (i >= params.count) { return; }{% if source.toWide %}wide[i] = bitcast<u32>(f32(narrow[i]));{% else %}narrow[i] = f16(bitcast<f32>(wide[i]));4 unmodified lines5678910111213144 unmodified lines// payload bits in u32 words so the middle pass can bind the same allocation as// atomic<u32> and perform portable float CAS operations.@compute @workgroup_size({{ workgroupSize }})fn main(@builtin(global_invocation_id) gid: vec3<u32>) {let i = gid.x + gid.y * {{ DISPATCH_FOLD_WIDTH }}u * {{ workgroupSize }}u;if (i >= params.count) { return; }{% if toWide %}wide[i] = bitcast<u32>(f32(narrow[i]));{% else %}narrow[i] = f16(bitcast<f32>(wide[i]));
1 unmodified line23456789101112131415161718192021222324251 unmodified line// pass. The element width is owned by the binding element type: when// 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. A grid-stride// loop lets the dispatch stay within maxComputeWorkgroupsPerDimension.{% if usesF16 %}enable f16;{% endif %}{{ env.wgsl.resourceDeclarations }}{% set wg = workgroupSize if workgroupSize is defined else tunables.WORKGROUP_SIZE %}const COUNT: u32 = {{ source.count }}u;const WG: u32 = {{ wg }}u;@compute @workgroup_size({{ wg }})fn main(@builtin(global_invocation_id) gid: vec3<u32>,@builtin(num_workgroups) nwg: vec3<u32>) {let stride = nwg.x * WG;for (var i = gid.x; i < COUNT; i += stride) {dst[i] = src[i];}}1 unmodified line2345678910111213141516171819202122232425262728293031323334353637383940414243444546471 unmodified line// pass. The element width is owned by the binding element type: when// 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.{% set scalarTailSafe = scalarTailSafe is defined and scalarTailSafe %}{% set copyWidth = copyWidth | default(0) %}{% set elementCount = elementCount | default(0) %}{% if usesF16 %}enable f16;{% endif %}{{ env.wgsl.resourceDeclarations }}{% set wg = workgroupSize if workgroupSize is defined else tunables.WORKGROUP_SIZE %}const COUNT: u32 = {{ count }}u;const WG: u32 = {{ wg }}u;@compute @workgroup_size({{ wg }})fn main(@builtin(global_invocation_id) gid: vec3<u32>) {let i = gid.x + gid.y * {{ DISPATCH_FOLD_WIDTH }}u * WG;if (i >= COUNT) {return;}{% if scalarTailSafe %}let base = i * {{ copyWidth }}u;dst[base] = src[base];if (base + 1u < {{ elementCount }}u) { dst[base + 1u] = src[base + 1u]; }if (base + 2u < {{ elementCount }}u) { dst[base + 2u] = src[base + 2u]; }if (base + 3u < {{ elementCount }}u) { dst[base + 3u] = src[base + 3u]; }if (base + 4u < {{ elementCount }}u) { dst[base + 4u] = src[base + 4u]; }if (base + 5u < {{ elementCount }}u) { dst[base + 5u] = src[base + 5u]; }if (base + 6u < {{ elementCount }}u) { dst[base + 6u] = src[base + 6u]; }if (base + 7u < {{ elementCount }}u) { dst[base + 7u] = src[base + 7u]; }{% if copyWidth == 16 %}if (base + 8u < {{ elementCount }}u) { dst[base + 8u] = src[base + 8u]; }if (base + 9u < {{ elementCount }}u) { dst[base + 9u] = src[base + 9u]; }if (base + 10u < {{ elementCount }}u) { dst[base + 10u] = src[base + 10u]; }if (base + 11u < {{ elementCount }}u) { dst[base + 11u] = src[base + 11u]; }if (base + 12u < {{ elementCount }}u) { dst[base + 12u] = src[base + 12u]; }if (base + 13u < {{ elementCount }}u) { dst[base + 13u] = src[base + 13u]; }if (base + 14u < {{ elementCount }}u) { dst[base + 14u] = src[base + 14u]; }if (base + 15u < {{ elementCount }}u) { dst[base + 15u] = src[base + 15u]; }{% endif %}{% else %}dst[i] = src[i];{% endif %}}
18 unmodified lines19202122232425262718 unmodified lines{% endif %}@compute @workgroup_size({{ workgroupSize }})fn main(@builtin(global_invocation_id) gid: vec3<u32>,@builtin(num_workgroups) nwg: vec3<u32>) {let i = gid.x + gid.y * nwg.x * {{ workgroupSize }}u;if (i >= params.count) { return; }let low = values[i] & MASK;{% if narrowSigned %}18 unmodified lines192021222324252618 unmodified lines{% endif %}@compute @workgroup_size({{ workgroupSize }})fn main(@builtin(global_invocation_id) gid: vec3<u32>) {let i = gid.x + gid.y * {{ DISPATCH_FOLD_WIDTH }}u * {{ workgroupSize }}u;if (i >= params.count) { return; }let low = values[i] & MASK;{% if narrowSigned %}
7 unmodified lines891011121314151625 unmodified lines42434445464748495051525354555657585960614 unmodified lines66676869707172737475767778798081828384858687888990919293949596979824 unmodified lines12312412512612712812913030 unmodified lines16116216316416516616716816917017117248 unmodified lines22122222322422522622722872 unmodified lines3013023033043053063073083 unmodified lines3123133143153163173183193203213223233243257 unmodified lines// ensures every lane reaches each collective. Floating-point grouping and atomic// update order can both change rounding. Without subgroups, an all-equal-key f32// add workgroup reduces locally and emits one CAS; mixed keys use per-update CAS.{% if usesF16 %}enable f16;{% endif %}{% if useSubgroups %}enable subgroups;{% endif %}25 unmodified linesfn indices_base(update_index: u32) -> u32 {var rem = update_index;var offset = 0u;{% for axis in range(source.updatesRank) %}{% set update_stride = namespace(value=1) %}{% for j in range(axis + 1, source.updatesRank) %}{% set update_stride.value = update_stride.value * source.updatesShape[j] %}{% endfor %}{% set update_stride_divisor = update_stride.value if update_stride.value != 0 else 1 %}{% if axis < source.indicesRank - 1 %}let coord{{ axis }} = rem / {{ update_stride_divisor }}u;{% endif %}rem = rem % {{ update_stride_divisor }}u;{% if axis < source.indicesRank - 1 %}{% set index_stride = namespace(value=source.indexDepth) %}{% for j in range(axis + 1, source.indicesRank - 1) %}{% set index_stride.value = index_stride.value * source.indicesShape[j] %}{% endfor %}offset = offset + coord{{ axis }} * {{ index_stride.value }}u;{% endif %}4 unmodified linesfn output_offset(update_index: u32) -> u32 {let index_base = indices_base(update_index);var rem = update_index;{% for axis in range(source.updatesRank) %}{% set update_stride = namespace(value=1) %}{% for j in range(axis + 1, source.updatesRank) %}{% set update_stride.value = update_stride.value * source.updatesShape[j] %}{% endfor %}{% set update_stride_divisor = update_stride.value if update_stride.value != 0 else 1 %}{% set suffixBegin = source.indicesRank - 1 %}{% set suffixEnd = suffixBegin + source.dataRank - source.indexDepth %}{% if axis >= suffixBegin and axis < suffixEnd %}let ucoord{{ axis }} = rem / {{ update_stride_divisor }}u;{% endif %}rem = rem % {{ update_stride_divisor }}u;{% endfor %}var offset = 0u;{% for axis in range(source.dataRank) %}{% set data_stride = namespace(value=1) %}{% for j in range(axis + 1, source.dataRank) %}{% set data_stride.value = data_stride.value * source.dataShape[j] %}{% endfor %}{% if axis < source.indexDepth %}let gathered{{ axis }} = normalize_index(indices[index_base + {{ axis }}u], {{ source.dataShape[axis] }}u);if (gathered{{ axis }} == INVALID_INDEX) {return INVALID_INDEX;}offset = offset + gathered{{ axis }} * {{ data_stride.value }}u;{% else %}{% set suffix_axis = (source.indicesRank - 1) + (axis - source.indexDepth) %}offset = offset + ucoord{{ suffix_axis }} * {{ data_stride.value }}u;{% endif %}{% endfor %}24 unmodified lines}}{% elif reductionOp == "mul" %}// No atomicMul in WGSL: CAS loop on the native integer payload (wrapping// integer multiply, same as the serial shader's current * update).fn apply_update(dst: u32, update: {{ scalar }}) {var old = atomicLoad(&output[dst]);loop {30 unmodified lines// back to per-lane atomics for the remainder. A compile-time constant so the// round loop has a uniform trip count (no data-dependent break): the subgroup// builtins inside it are reached by every lane on every round, i.e. in// subgroup-uniform control flow. ROUNDS covers the common contention shapes// (few hot slots per subgroup, incl. the all-same-slot worst case in round 0);// rare highly-scattered subgroups simply spill to the per-lane path.const PREAGG_ROUNDS: u32 = {{ preaggRounds }}u;// Warp-aggregated atomic: in each round, all still-pending lanes elect the// smallest target slot (subgroupMin), the lanes hitting that slot combine their// updates locally with subgroupAdd/subgroupMul, and one leader lane issues a// single atomic for it. After PREAGG_ROUNDS rounds any lane still pending does a48 unmodified lines@compute @workgroup_size(WG)fn main(@builtin(global_invocation_id) gid: vec3<u32>,@builtin(num_workgroups) nwg: vec3<u32>{%- if useSubgroups %},@builtin(subgroup_invocation_id) sg_lane: u32,@builtin(subgroup_size) sg_size: u3272 unmodified lines{% elif useSubgroups %}// The folded 2D dispatch assigns one index to every lane. Every lane calls// `aggregate_update` once, keeping its subgroup builtins uniform; lanes past// the count join as non-pending and neither read nor write.let i = gid.y * (nwg.x * WG) + gid.x;let in_range = i < params.count;var dst = INVALID_INDEX;var upd = {{ scalar }}(0);3 unmodified lines}aggregate_update(dst, upd, in_range, sg_lane, sg_size);{% else %}// Without subgroups, grid-stride over the folded 2D dispatch and issue one// atomic for each valid update.let row = nwg.x * WG;let stride = row * nwg.y;for (var i = gid.y * row + gid.x; i < params.count; i += stride) {let dst = output_offset(i);if (dst == INVALID_INDEX) {continue;}apply_update(dst, {{ scalar }}(updates[i]));}7 unmodified lines891011121325 unmodified lines39404142434445464748495051525354555657584 unmodified lines63646566676869707172737475767778798081828384858687888990919293949524 unmodified lines12012112212312412512612730 unmodified lines15815916016116216316416516616716848 unmodified lines21721821922022122222322472 unmodified lines2972982993003013023033043053 unmodified lines3093103113123133143153163173183193203213223233247 unmodified lines// ensures every lane reaches each collective. Floating-point grouping and atomic// update order can both change rounding. Without subgroups, an all-equal-key f32// add workgroup reduces locally and emits one CAS; mixed keys use per-update CAS.{% if useSubgroups %}enable subgroups;{% endif %}25 unmodified linesfn indices_base(update_index: u32) -> u32 {var rem = update_index;var offset = 0u;{% for axis in range(updatesRank) %}{% set update_stride = namespace(value=1) %}{% for j in range(axis + 1, updatesRank) %}{% set update_stride.value = update_stride.value * updatesShape[j] %}{% endfor %}{% set update_stride_divisor = update_stride.value if update_stride.value != 0 else 1 %}{% if axis < indicesRank - 1 %}let coord{{ axis }} = rem / {{ update_stride_divisor }}u;{% endif %}rem = rem % {{ update_stride_divisor }}u;{% if axis < indicesRank - 1 %}{% set index_stride = namespace(value=indexDepth) %}{% for j in range(axis + 1, indicesRank - 1) %}{% set index_stride.value = index_stride.value * indicesShape[j] %}{% endfor %}offset = offset + coord{{ axis }} * {{ index_stride.value }}u;{% endif %}4 unmodified linesfn output_offset(update_index: u32) -> u32 {let index_base = indices_base(update_index);var rem = update_index;{% for axis in range(updatesRank) %}{% set update_stride = namespace(value=1) %}{% for j in range(axis + 1, updatesRank) %}{% set update_stride.value = update_stride.value * updatesShape[j] %}{% endfor %}{% set update_stride_divisor = update_stride.value if update_stride.value != 0 else 1 %}{% set suffixBegin = indicesRank - 1 %}{% set suffixEnd = suffixBegin + dataRank - indexDepth %}{% if axis >= suffixBegin and axis < suffixEnd %}let ucoord{{ axis }} = rem / {{ update_stride_divisor }}u;{% endif %}rem = rem % {{ update_stride_divisor }}u;{% endfor %}var offset = 0u;{% for axis in range(dataRank) %}{% set data_stride = namespace(value=1) %}{% for j in range(axis + 1, dataRank) %}{% set data_stride.value = data_stride.value * dataShape[j] %}{% endfor %}{% if axis < indexDepth %}let gathered{{ axis }} = normalize_index(indices[index_base + {{ axis }}u], {{ dataShape[axis] }}u);if (gathered{{ axis }} == INVALID_INDEX) {return INVALID_INDEX;}offset = offset + gathered{{ axis }} * {{ data_stride.value }}u;{% else %}{% set suffix_axis = (indicesRank - 1) + (axis - indexDepth) %}offset = offset + ucoord{{ suffix_axis }} * {{ data_stride.value }}u;{% endif %}{% endfor %}24 unmodified lines}}{% elif reductionOp == "mul" %}// WGSL has no atomic multiplication. This CAS loop replaces the native integer// payload with wrapping `old * update`.fn apply_update(dst: u32, update: {{ scalar }}) {var old = atomicLoad(&output[dst]);loop {30 unmodified lines// back to per-lane atomics for the remainder. A compile-time constant so the// round loop has a uniform trip count (no data-dependent break): the subgroup// builtins inside it are reached by every lane on every round, i.e. in// subgroup-uniform control flow. ROUNDS bounds the number of distinct target// slots combined within a subgroup; remaining slots use the per-lane path.const PREAGG_ROUNDS: u32 = {{ preaggRounds }}u;// Subgroup-aggregated atomic: in each round, all still-pending lanes elect the// smallest target slot (subgroupMin), the lanes hitting that slot combine their// updates locally with subgroupAdd/subgroupMul, and one leader lane issues a// single atomic for it. After PREAGG_ROUNDS rounds any lane still pending does a48 unmodified lines@compute @workgroup_size(WG)fn main(@builtin(global_invocation_id) gid: vec3<u32>{% if useWorkgroupPreagg %},@builtin(num_workgroups) nwg: vec3<u32>{% endif %}{%- if useSubgroups %},@builtin(subgroup_invocation_id) sg_lane: u32,@builtin(subgroup_size) sg_size: u3272 unmodified lines{% elif useSubgroups %}// The folded 2D dispatch assigns one index to every lane. Every lane calls// `aggregate_update` once, keeping its subgroup builtins uniform; lanes past// the count join as non-pending and neither read nor write. The baked fold// width maps the two-dimensional dispatch back to one flat update index.let i = gid.y * ({{ DISPATCH_FOLD_WIDTH }}u * WG) + gid.x;let in_range = i < params.count;var dst = INVALID_INDEX;var upd = {{ scalar }}(0);3 unmodified lines}aggregate_update(dst, upd, in_range, sg_lane, sg_size);{% else %}// Without subgroups, one lane per update over the folded 2D dispatch issues// one atomic for each valid update (baked fold width, see above).let i = gid.y * ({{ DISPATCH_FOLD_WIDTH }}u * WG) + gid.x;if (i >= params.count) {return;}{let dst = output_offset(i);if (dst == INVALID_INDEX) {return;}apply_update(dst, {{ scalar }}(updates[i]));}
3 unmodified lines45678910111213141514 unmodified lines30313233343536373839404142434445464748494 unmodified lines5455565758596061626364656667686970717273747576777879808182838485863 unmodified lines// element. Updating either half preserves the other half from the successful// observed word, so adjacent columns and duplicate indices remain race-free// without widening the output into scratch storage.// Add only: the one case that selects this shader gates on// attrs.reduction == "add", so min/max never reach it. The general// atomic and slice routes carry the other reductions.//// The same case requires numel(updates) >= F16_ATOMIC_MIN_UPDATES, so no// update extent is zero and every stride below divides.const WG: u32 = {{ workgroupSize }}u;const INVALID_INDEX: u32 = 0xffffffffu;14 unmodified linesfn indices_base(update_index: u32) -> u32 {var rem = update_index;var offset = 0u;{% for axis in range(source.updatesRank) %}{% set update_stride = namespace(value=1) %}{% for j in range(axis + 1, source.updatesRank) %}{% set update_stride.value = update_stride.value * source.updatesShape[j] %}{% endfor %}{% set update_stride_divisor = update_stride.value %}{% if axis < source.indicesRank - 1 %}let coord{{ axis }} = rem / {{ update_stride_divisor }}u;{% endif %}rem %= {{ update_stride_divisor }}u;{% if axis < source.indicesRank - 1 %}{% set index_stride = namespace(value=source.indexDepth) %}{% for j in range(axis + 1, source.indicesRank - 1) %}{% set index_stride.value = index_stride.value * source.indicesShape[j] %}{% endfor %}offset += coord{{ axis }} * {{ index_stride.value }}u;{% endif %}4 unmodified linesfn output_offset(update_index: u32) -> u32 {let index_base = indices_base(update_index);var rem = update_index;{% for axis in range(source.updatesRank) %}{% set update_stride = namespace(value=1) %}{% for j in range(axis + 1, source.updatesRank) %}{% set update_stride.value = update_stride.value * source.updatesShape[j] %}{% endfor %}{% set update_stride_divisor = update_stride.value %}{% set suffixBegin = source.indicesRank - 1 %}{% set suffixEnd = suffixBegin + source.dataRank - source.indexDepth %}{% if axis >= suffixBegin and axis < suffixEnd %}let ucoord{{ axis }} = rem / {{ update_stride_divisor }}u;{% endif %}rem %= {{ update_stride_divisor }}u;{% endfor %}var offset = 0u;{% for axis in range(source.dataRank) %}{% set data_stride = namespace(value=1) %}{% for j in range(axis + 1, source.dataRank) %}{% set data_stride.value = data_stride.value * source.dataShape[j] %}{% endfor %}{% if axis < source.indexDepth %}let gathered{{ axis }} = normalize_index(indices[index_base + {{ axis }}u], {{ source.dataShape[axis] }}u);if (gathered{{ axis }} == INVALID_INDEX) {return INVALID_INDEX;}offset += gathered{{ axis }} * {{ data_stride.value }}u;{% else %}{% set suffix_axis = (source.indicesRank - 1) + (axis - source.indexDepth) %}offset += ucoord{{ suffix_axis }} * {{ data_stride.value }}u;{% endif %}{% endfor %}3 unmodified lines456789101114 unmodified lines26272829303132333435363738394041424344454 unmodified lines5051525354555657585960616263646566676869707172737475767778798081823 unmodified lines// element. Updating either half preserves the other half from the successful// observed word, so adjacent columns and duplicate indices remain race-free// without widening the output into scratch storage.// This packed-pair variant implements addition only. Its input contract requires// a nonzero update extent, so every compile-time stride used below is nonzero.const WG: u32 = {{ workgroupSize }}u;const INVALID_INDEX: u32 = 0xffffffffu;14 unmodified linesfn indices_base(update_index: u32) -> u32 {var rem = update_index;var offset = 0u;{% for axis in range(updatesRank) %}{% set update_stride = namespace(value=1) %}{% for j in range(axis + 1, updatesRank) %}{% set update_stride.value = update_stride.value * updatesShape[j] %}{% endfor %}{% set update_stride_divisor = update_stride.value %}{% if axis < indicesRank - 1 %}let coord{{ axis }} = rem / {{ update_stride_divisor }}u;{% endif %}rem %= {{ update_stride_divisor }}u;{% if axis < indicesRank - 1 %}{% set index_stride = namespace(value=indexDepth) %}{% for j in range(axis + 1, indicesRank - 1) %}{% set index_stride.value = index_stride.value * indicesShape[j] %}{% endfor %}offset += coord{{ axis }} * {{ index_stride.value }}u;{% endif %}4 unmodified linesfn output_offset(update_index: u32) -> u32 {let index_base = indices_base(update_index);var rem = update_index;{% for axis in range(updatesRank) %}{% set update_stride = namespace(value=1) %}{% for j in range(axis + 1, updatesRank) %}{% set update_stride.value = update_stride.value * updatesShape[j] %}{% endfor %}{% set update_stride_divisor = update_stride.value %}{% set suffixBegin = indicesRank - 1 %}{% set suffixEnd = suffixBegin + dataRank - indexDepth %}{% if axis >= suffixBegin and axis < suffixEnd %}let ucoord{{ axis }} = rem / {{ update_stride_divisor }}u;{% endif %}rem %= {{ update_stride_divisor }}u;{% endfor %}var offset = 0u;{% for axis in range(dataRank) %}{% set data_stride = namespace(value=1) %}{% for j in range(axis + 1, dataRank) %}{% set data_stride.value = data_stride.value * dataShape[j] %}{% endfor %}{% if axis < indexDepth %}let gathered{{ axis }} = normalize_index(indices[index_base + {{ axis }}u], {{ dataShape[axis] }}u);if (gathered{{ axis }} == INVALID_INDEX) {return INVALID_INDEX;}offset += gathered{{ axis }} * {{ data_stride.value }}u;{% else %}{% set suffix_axis = (indicesRank - 1) + (axis - indexDepth) %}offset += ucoord{{ suffix_axis }} * {{ data_stride.value }}u;{% endif %}{% endfor %}
4 unmodified lines567891011121314151617181914 unmodified lines34353637383940414243444546474849505152534 unmodified lines58596061626364656667686970717273747576777879808182838485868788899014 unmodified lines1051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481494 unmodified lines// slice sweep within each column stays serial to order read-modify-write safely.// A grid-stride loop covers any width.// INNER_WIDTH = product(updatesShape[indicesRank-1:]) = data slice width.{% if usesF16 %}enable f16;{% endif %}{{ env.wgsl.resourceDeclarations }}const WG: u32 = {{ workgroupSize }}u;{% set inner_width = namespace(value=1) %}{% for j in range(source.indicesRank - 1, source.updatesRank) %}{% set inner_width.value = inner_width.value * source.updatesShape[j] %}{% endfor %}const INNER_WIDTH: u32 = {{ inner_width.value if inner_width.value != 0 else 1 }}u;const INVALID_INDEX: u32 = 0xffffffffu;14 unmodified linesfn indices_base(update_index: u32) -> u32 {var rem = update_index;var offset = 0u;{% for axis in range(source.updatesRank) %}{% set update_stride = namespace(value=1) %}{% for j in range(axis + 1, source.updatesRank) %}{% set update_stride.value = update_stride.value * source.updatesShape[j] %}{% endfor %}{% set update_stride_divisor = update_stride.value if update_stride.value != 0 else 1 %}{% if axis < source.indicesRank - 1 %}let coord{{ axis }} = rem / {{ update_stride_divisor }}u;{% endif %}rem = rem % {{ update_stride_divisor }}u;{% if axis < source.indicesRank - 1 %}{% set index_stride = namespace(value=source.indexDepth) %}{% for j in range(axis + 1, source.indicesRank - 1) %}{% set index_stride.value = index_stride.value * source.indicesShape[j] %}{% endfor %}offset = offset + coord{{ axis }} * {{ index_stride.value }}u;{% endif %}4 unmodified linesfn output_offset(update_index: u32) -> u32 {let index_base = indices_base(update_index);var rem = update_index;{% for axis in range(source.updatesRank) %}{% set update_stride = namespace(value=1) %}{% for j in range(axis + 1, source.updatesRank) %}{% set update_stride.value = update_stride.value * source.updatesShape[j] %}{% endfor %}{% set update_stride_divisor = update_stride.value if update_stride.value != 0 else 1 %}{% set suffixBegin = source.indicesRank - 1 %}{% set suffixEnd = suffixBegin + source.dataRank - source.indexDepth %}{% if axis >= suffixBegin and axis < suffixEnd %}let ucoord{{ axis }} = rem / {{ update_stride_divisor }}u;{% endif %}rem = rem % {{ update_stride_divisor }}u;{% endfor %}var offset = 0u;{% for axis in range(source.dataRank) %}{% set data_stride = namespace(value=1) %}{% for j in range(axis + 1, source.dataRank) %}{% set data_stride.value = data_stride.value * source.dataShape[j] %}{% endfor %}{% if axis < source.indexDepth %}let gathered{{ axis }} = normalize_index(indices[index_base + {{ axis }}u], {{ source.dataShape[axis] }}u);if (gathered{{ axis }} == INVALID_INDEX) {return INVALID_INDEX;}offset = offset + gathered{{ axis }} * {{ data_stride.value }}u;{% else %}{% set suffix_axis = (source.indicesRank - 1) + (axis - source.indexDepth) %}offset = offset + ucoord{{ suffix_axis }} * {{ data_stride.value }}u;{% endif %}{% endfor %}14 unmodified linesif (dst == INVALID_INDEX) {continue;}{% set scatterIndent = " " %}{% if scalar == "i32" or scalar == "u32" %}{{ scatterIndent }}let current = output[dst];{{ scatterIndent }}let update = updates[i];{% if reductionOp == "add" %}{{ scatterIndent }}let combined = current + update;{% elif reductionOp == "mul" %}{{ scatterIndent }}let combined = current * update;{% elif reductionOp == "min" %}{{ scatterIndent }}output[dst] = min(current, update);{% else %}{{ scatterIndent }}output[dst] = max(current, update);{% endif %}{% if reductionOp == "add" or reductionOp == "mul" %}{% if narrowBits == 8 and narrowSigned %}{{ scatterIndent }}let low = combined & 255;{{ scatterIndent }}output[dst] = select(low, low - 256, low > 127);{% elif narrowBits == 16 and narrowSigned %}{{ scatterIndent }}let low = combined & 65535;{{ scatterIndent }}output[dst] = select(low, low - 65536, low > 32767);{% elif narrowBits == 8 %}{{ scatterIndent }}output[dst] = combined & 255u;{% else %}{{ scatterIndent }}output[dst] = combined;{% endif %}{% endif %}{% else %}{{ scatterIndent }}let current = f32(output[dst]);{{ scatterIndent }}let update = f32(updates[i]);{% if reductionOp == "add" %}{{ scatterIndent }}output[dst] = {{ scalar }}(current + update);{% elif reductionOp == "mul" %}{{ scatterIndent }}output[dst] = {{ scalar }}(current * update);{% elif reductionOp == "min" %}{{ scatterIndent }}output[dst] = {{ scalar }}(min(current, update));{% else %}{{ scatterIndent }}output[dst] = {{ scalar }}(max(current, update));{% endif %}{% endif %}}}}4 unmodified lines567891011121314151614 unmodified lines31323334353637383940414243444546474849504 unmodified lines55565758596061626364656667686970717273747576777879808182838485868714 unmodified lines1021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451464 unmodified lines// slice sweep within each column stays serial to order read-modify-write safely.// A grid-stride loop covers any width.// INNER_WIDTH = product(updatesShape[indicesRank-1:]) = data slice width.{{ env.wgsl.resourceDeclarations }}const WG: u32 = {{ workgroupSize }}u;{% set inner_width = namespace(value=1) %}{% for j in range(indicesRank - 1, updatesRank) %}{% set inner_width.value = inner_width.value * updatesShape[j] %}{% endfor %}const INNER_WIDTH: u32 = {{ inner_width.value if inner_width.value != 0 else 1 }}u;const INVALID_INDEX: u32 = 0xffffffffu;14 unmodified linesfn indices_base(update_index: u32) -> u32 {var rem = update_index;var offset = 0u;{% for axis in range(updatesRank) %}{% set update_stride = namespace(value=1) %}{% for j in range(axis + 1, updatesRank) %}{% set update_stride.value = update_stride.value * updatesShape[j] %}{% endfor %}{% set update_stride_divisor = update_stride.value if update_stride.value != 0 else 1 %}{% if axis < indicesRank - 1 %}let coord{{ axis }} = rem / {{ update_stride_divisor }}u;{% endif %}rem = rem % {{ update_stride_divisor }}u;{% if axis < indicesRank - 1 %}{% set index_stride = namespace(value=indexDepth) %}{% for j in range(axis + 1, indicesRank - 1) %}{% set index_stride.value = index_stride.value * indicesShape[j] %}{% endfor %}offset = offset + coord{{ axis }} * {{ index_stride.value }}u;{% endif %}4 unmodified linesfn output_offset(update_index: u32) -> u32 {let index_base = indices_base(update_index);var rem = update_index;{% for axis in range(updatesRank) %}{% set update_stride = namespace(value=1) %}{% for j in range(axis + 1, updatesRank) %}{% set update_stride.value = update_stride.value * updatesShape[j] %}{% endfor %}{% set update_stride_divisor = update_stride.value if update_stride.value != 0 else 1 %}{% set suffixBegin = indicesRank - 1 %}{% set suffixEnd = suffixBegin + dataRank - indexDepth %}{% if axis >= suffixBegin and axis < suffixEnd %}let ucoord{{ axis }} = rem / {{ update_stride_divisor }}u;{% endif %}rem = rem % {{ update_stride_divisor }}u;{% endfor %}var offset = 0u;{% for axis in range(dataRank) %}{% set data_stride = namespace(value=1) %}{% for j in range(axis + 1, dataRank) %}{% set data_stride.value = data_stride.value * dataShape[j] %}{% endfor %}{% if axis < indexDepth %}let gathered{{ axis }} = normalize_index(indices[index_base + {{ axis }}u], {{ dataShape[axis] }}u);if (gathered{{ axis }} == INVALID_INDEX) {return INVALID_INDEX;}offset = offset + gathered{{ axis }} * {{ data_stride.value }}u;{% else %}{% set suffix_axis = (indicesRank - 1) + (axis - indexDepth) %}offset = offset + ucoord{{ suffix_axis }} * {{ data_stride.value }}u;{% endif %}{% endfor %}14 unmodified linesif (dst == INVALID_INDEX) {continue;}{% filter indent(6, true) %}{% if scalar == "i32" or scalar == "u32" %}let current = output[dst];let update = updates[i];{% if reductionOp == "add" %}let combined = current + update;{% elif reductionOp == "mul" %}let combined = current * update;{% elif reductionOp == "min" %}output[dst] = min(current, update);{% else %}output[dst] = max(current, update);{% endif %}{% if reductionOp == "add" or reductionOp == "mul" %}{% if narrowBits == 8 and narrowSigned %}let low = combined & 255;output[dst] = select(low, low - 256, low > 127);{% elif narrowBits == 16 and narrowSigned %}let low = combined & 65535;output[dst] = select(low, low - 65536, low > 32767);{% elif narrowBits == 8 %}output[dst] = combined & 255u;{% else %}output[dst] = combined;{% endif %}{% endif %}{% else %}let current = f32(output[dst]);let update = f32(updates[i]);{% if reductionOp == "add" %}output[dst] = {{ scalar }}(current + update);{% elif reductionOp == "mul" %}output[dst] = {{ scalar }}(current * update);{% elif reductionOp == "min" %}output[dst] = {{ scalar }}(min(current, update));{% else %}output[dst] = {{ scalar }}(max(current, update));{% endif %}{% endif %}{%- endfilter %} }}}
12345615 unmodified lines22232425262728293031323334353637383940414 unmodified lines4647484950515253545556575859606162636465666768697071727374757677781 unmodified line80818283848586878889{% if usesF16 %}enable f16;{% endif %}{{ env.wgsl.resourceDeclarations }}const INVALID_INDEX: u32 = 0xffffffffu;15 unmodified linesfn indices_base(update_index: u32) -> u32 {var rem = update_index;var offset = 0u;{% for axis in range(source.updatesRank) %}{% set update_stride = namespace(value=1) %}{% for j in range(axis + 1, source.updatesRank) %}{% set update_stride.value = update_stride.value * source.updatesShape[j] %}{% endfor %}{% set update_stride_divisor = update_stride.value if update_stride.value != 0 else 1 %}{% if axis < source.indicesRank - 1 %}let coord{{ axis }} = rem / {{ update_stride_divisor }}u;{% endif %}rem = rem % {{ update_stride_divisor }}u;{% if axis < source.indicesRank - 1 %}{% set index_stride = namespace(value=source.indexDepth) %}{% for j in range(axis + 1, source.indicesRank - 1) %}{% set index_stride.value = index_stride.value * source.indicesShape[j] %}{% endfor %}offset = offset + coord{{ axis }} * {{ index_stride.value }}u;{% endif %}4 unmodified linesfn output_offset(update_index: u32) -> u32 {let index_base = indices_base(update_index);var rem = update_index;{% for axis in range(source.updatesRank) %}{% set update_stride = namespace(value=1) %}{% for j in range(axis + 1, source.updatesRank) %}{% set update_stride.value = update_stride.value * source.updatesShape[j] %}{% endfor %}{% set update_stride_divisor = update_stride.value if update_stride.value != 0 else 1 %}{% set suffixBegin = source.indicesRank - 1 %}{% set suffixEnd = suffixBegin + source.dataRank - source.indexDepth %}{% if axis >= suffixBegin and axis < suffixEnd %}let ucoord{{ axis }} = rem / {{ update_stride_divisor }}u;{% endif %}rem = rem % {{ update_stride_divisor }}u;{% endfor %}var offset = 0u;{% for axis in range(source.dataRank) %}{% set data_stride = namespace(value=1) %}{% for j in range(axis + 1, source.dataRank) %}{% set data_stride.value = data_stride.value * source.dataShape[j] %}{% endfor %}{% if axis < source.indexDepth %}let gathered{{ axis }} = normalize_index(indices[index_base + {{ axis }}u], {{ source.dataShape[axis] }}u);if (gathered{{ axis }} == INVALID_INDEX) {return INVALID_INDEX;}offset = offset + gathered{{ axis }} * {{ data_stride.value }}u;{% else %}{% set suffix_axis = (source.indicesRank - 1) + (axis - source.indexDepth) %}offset = offset + ucoord{{ suffix_axis }} * {{ data_stride.value }}u;{% endif %}{% endfor %}1 unmodified line}@compute @workgroup_size(WG)fn main(@builtin(global_invocation_id) gid: vec3<u32>, @builtin(num_workgroups) nwg: vec3<u32>) {// 2D-folded flat index: gid.y carries the high bits past the device's// per-dimension dispatch limit.let i = gid.x + gid.y * nwg.x * WG;if (i >= params.count) {return;}12315 unmodified lines19202122232425262728293031323334353637384 unmodified lines4344454647484950515253545556575859606162636465666768697071727374751 unmodified line77787980818283848586{{ env.wgsl.resourceDeclarations }}const INVALID_INDEX: u32 = 0xffffffffu;15 unmodified linesfn indices_base(update_index: u32) -> u32 {var rem = update_index;var offset = 0u;{% for axis in range(updatesRank) %}{% set update_stride = namespace(value=1) %}{% for j in range(axis + 1, updatesRank) %}{% set update_stride.value = update_stride.value * updatesShape[j] %}{% endfor %}{% set update_stride_divisor = update_stride.value if update_stride.value != 0 else 1 %}{% if axis < indicesRank - 1 %}let coord{{ axis }} = rem / {{ update_stride_divisor }}u;{% endif %}rem = rem % {{ update_stride_divisor }}u;{% if axis < indicesRank - 1 %}{% set index_stride = namespace(value=indexDepth) %}{% for j in range(axis + 1, indicesRank - 1) %}{% set index_stride.value = index_stride.value * indicesShape[j] %}{% endfor %}offset = offset + coord{{ axis }} * {{ index_stride.value }}u;{% endif %}4 unmodified linesfn output_offset(update_index: u32) -> u32 {let index_base = indices_base(update_index);var rem = update_index;{% for axis in range(updatesRank) %}{% set update_stride = namespace(value=1) %}{% for j in range(axis + 1, updatesRank) %}{% set update_stride.value = update_stride.value * updatesShape[j] %}{% endfor %}{% set update_stride_divisor = update_stride.value if update_stride.value != 0 else 1 %}{% set suffixBegin = indicesRank - 1 %}{% set suffixEnd = suffixBegin + dataRank - indexDepth %}{% if axis >= suffixBegin and axis < suffixEnd %}let ucoord{{ axis }} = rem / {{ update_stride_divisor }}u;{% endif %}rem = rem % {{ update_stride_divisor }}u;{% endfor %}var offset = 0u;{% for axis in range(dataRank) %}{% set data_stride = namespace(value=1) %}{% for j in range(axis + 1, dataRank) %}{% set data_stride.value = data_stride.value * dataShape[j] %}{% endfor %}{% if axis < indexDepth %}let gathered{{ axis }} = normalize_index(indices[index_base + {{ axis }}u], {{ dataShape[axis] }}u);if (gathered{{ axis }} == INVALID_INDEX) {return INVALID_INDEX;}offset = offset + gathered{{ axis }} * {{ data_stride.value }}u;{% else %}{% set suffix_axis = (indicesRank - 1) + (axis - indexDepth) %}offset = offset + ucoord{{ suffix_axis }} * {{ data_stride.value }}u;{% endif %}{% endfor %}1 unmodified line}@compute @workgroup_size(WG)fn main(@builtin(global_invocation_id) gid: vec3<u32>) {// 2D-folded flat index: gid.y carries the high bits past the device's// per-dimension dispatch limit.let i = gid.x + gid.y * {{ DISPATCH_FOLD_WIDTH }}u * WG;if (i >= params.count) {return;}
12345245 unmodified lines25125225325425525625727 unmodified lines28528628728828929029111 unmodified lines30330430530630730830951 unmodified lines361362363364365366367127 unmodified lines4954964974984995005017 unmodified lines50951051151251351451515 unmodified lines53153253353453553653762 unmodified lines60060160260360460560615 unmodified lines62262362462562662762815 unmodified lines64464564664764864965015 unmodified lines66666766866967067167215 unmodified lines688689690691692693694146 unmodified lines84184284384484584684798 unmodified lines94694794894995095195257 unmodified lines101010111012101310141015101638 unmodified lines105510561057105810591060106110 unmodified lines10721073107410751076107710786 unmodified lines108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111517 unmodified lines11331134113511361137113811394 unmodified lines114411451146114711481149115026 unmodified lines117711781179118011811182118337 unmodified lines122112221223122412251226122745 unmodified lines127312741275127612771278127932 unmodified lines13121313131413151316131713182 unmodified lines132113221323132413251326{"op": "ai.onnx.ScatterND","fixtureArrays": {"scatter_nd_data_4x4x4": [1, 2, 3, 4, 5, 6, 7, 8, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 8, 7, 6, 5, 4, 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8],"backend_row_slice_updates_input_updates": [5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4],245 unmodified lines"provenance": {"source": "onnxruntime/test/providers/cpu/tensor/scatter_nd_op_test.cc","test": "ScatterNDOpTest.ScatterND_batched_index_int64","notes": "ORT uses int64 data; this framework covers the same batched-index pattern with float32 data."},"inputs": {"data": { "dtype": "float32", "shape": [2, 2], "data": { "kind": "values", "values": [2.0, 3.0, 2.0, 3.0] } },27 unmodified lines"provenance": {"source": "onnxruntime/test/providers/cpu/tensor/scatter_nd_op_test.cc","test": "ScatterNDOpTest.ScatterND_sliced_index_int64","notes": "ORT uses int64 data; this framework covers the same sliced-index update pattern with float32 data."},"inputs": {"data": { "dtype": "float32", "shape": [2, 2], "data": { "kind": "constant", "value": 0.0 } },11 unmodified lines"provenance": {"source": "onnxruntime/test/providers/cpu/tensor/scatter_nd_op_test.cc","test": "ScatterNDOpTest.ScatterND_batched_3tensor_int64","notes": "Compact uint32 batched ScatterND fixture using the same depth-2 index pattern as ORT."},"inputs": {"data": {51 unmodified lines{"name": "empty_indices_zero_width_reduction_add_identity","provenance": {"notes": "Reduction twin of the zero-width identity above. The slice route floors its inner width at one so a zero-width data suffix cannot divide by zero, and only a reduction case reaches that route."},"attrs": { "reduction": "add" },"inputs": {127 unmodified lines"provenance": {"source": "onnxruntime/test/providers/cpu/tensor/scatter_nd_op_test.cc","test": "ScatterNDOpTest.ScatterND_matrice_int64_int64_neg_indices","notes": "ORT uses int64 data and indices; this framework covers the same negative-index pattern with float32 data and int32 index storage."},"inputs": {"data": { "dtype": "float32", "shape": [2, 2], "data": { "kind": "values", "values": [1.0, 1.0, 2.0, 2.0] } },7 unmodified lines"provenance": {"source": "onnxruntime/test/providers/cpu/tensor/scatter_nd_op_test.cc","test": "ScatterNDOpTest.ScatterND_3tensor_int64","notes": "ORT uses integer data; this framework covers the same negative-index slice update with float32 data and int32 index storage."},"inputs": {"data": {15 unmodified lines"provenance": {"source": "onnxruntime/test/providers/cpu/tensor/scatter_nd_op_test.cc","test": "ScatterNDOpTest.ScatterND_18_mul_long_shape","notes": "Same duplicate-index reduction pattern as ORT's long-shape case, constrained to this manifest's rank-6 limit."},"attrs": { "reduction": "mul" },"inputs": {62 unmodified lines"outputs": { "output": { "dtype": "float32", "shape": [4, 4, 4] } },"provenance": {"source": "cmake/external/onnx/onnx/backend/test/data/node/test_scatternd","notes": "ONNX int64 tensors use framework int32/uint32 slots where representable."}},{15 unmodified lines"outputs": { "output": { "dtype": "float32", "shape": [4, 4, 4] } },"provenance": {"source": "cmake/external/onnx/onnx/backend/test/data/node/test_scatternd_add","notes": "ONNX int64 tensors use framework int32/uint32 slots where representable."}},{15 unmodified lines"outputs": { "output": { "dtype": "float32", "shape": [4, 4, 4] } },"provenance": {"source": "cmake/external/onnx/onnx/backend/test/data/node/test_scatternd_max","notes": "ONNX int64 tensors use framework int32/uint32 slots where representable."}},{15 unmodified lines"outputs": { "output": { "dtype": "float32", "shape": [4, 4, 4] } },"provenance": {"source": "cmake/external/onnx/onnx/backend/test/data/node/test_scatternd_min","notes": "ONNX int64 tensors use framework int32/uint32 slots where representable."}},{15 unmodified lines"outputs": { "output": { "dtype": "float32", "shape": [4, 4, 4] } },"provenance": {"source": "cmake/external/onnx/onnx/backend/test/data/node/test_scatternd_multiply","notes": "ONNX int64 tensors use framework int32/uint32 slots where representable."}},{146 unmodified lines"provenance": {"source": "onnxruntime/test/providers/cpu/tensor/scatter_nd_op_test.cc","test": "ScatterNDOpTest.ScatterND_18_add","notes": "Same duplicate slice-add reduction as ORT, with signed negative indices that normalize to rows 0, 1, 0."},"attrs": { "reduction": "add" },"inputs": {98 unmodified lines"provenance": {"source": "onnxruntime/test/providers/cpu/tensor/scatter_nd_op_test.cc","test": "ScatterNDOpTest.ScatterND_18_add","notes": "int8 add reduction with duplicate indices kept within int8 range (no overflow/wrap), exercising the untested serial f32-cast int8 reduction branch."},"attrs": { "reduction": "add" },"inputs": {57 unmodified lines{"name": "reduction_add_single_hot_slot_many_updates","provenance": {"notes": "Compact semantic sibling for the hot-slot atomic benchmark: many duplicate scalar updates target one output slot and must accumulate deterministically against the CPU reference."},"attrs": { "reduction": "add" },"inputs": {38 unmodified lines{"name": "scalar_output_add_many_updates_parallel_reduce_i32_negative","provenance": {"notes": "Negative indices on the same route. ONNX admits them and normalizeGatherIndex wraps them, so -1 addresses the sole output element exactly as 0 does; alternating the two makes a route that drops one of the spellings differ from the reference rather than merely halving the sum."},"attrs": { "reduction": "add" },"inputs": {10 unmodified lines{"name": "reduction_add_padding_hotspot_many_updates","provenance": {"notes": "Correctness sibling for sparse-routing and padding-token workloads where many updates target one hot key in a much larger output table."},"attrs": { "reduction": "add" },"inputs": {6 unmodified lines{"name": "f16_reduction_add_sparse_router_gradient","provenance": {"notes": "Correctness lock for f16 scalar sparse-gradient accumulation through the f32 atomic scratch path."},"attrs": { "reduction": "add" },"inputs": {"data": { "dtype": "float16", "shape": [64], "data": { "kind": "constant", "value": 0.0 } },"indices": {"dtype": "int32","shape": [4096, 1],"data": {"kind": "cycle","values": { "$ref": "#/fixtureArrays/f16_reduction_add_sparse_router_gradient_input_indices" }}},"updates": {"dtype": "float16","shape": [4096],"data": { "kind": "fillFloat32", "sinStep": 0.031, "cosStep": 0.047, "scale": 0.01 }}},"outputs": { "output": { "dtype": "float16", "shape": [64], "tolerance": 0.1, "relTolerance": 0.02 } }},{"name": "f16_reduction_add_sparse_router_gradient_offset_scale_lock","provenance": {"notes": "Scale lock for f16 reduction-add through atomic f32 scratch. Each of 64 slots receives 64 updates offset around +0.02, preventing zero-mean cancellation and making a lost, duplicated, or uniformly rescaled contribution observable. Tolerance covers the expected difference between per-add f16 rounding in the reference and one final f16 rounding after f32 scratch accumulation."},"attrs": { "reduction": "add" },"inputs": {17 unmodified lines{"name": "f16_reduction_add_row_slice_packed_atomic_route","provenance": {"notes": "Correctness lock for direct packed-f16 CAS row-slice accumulation. Duplicate rows and adjacent columns contend on both halves of each output word."},"requires": { "features": ["shader-f16"] },"attrs": { "reduction": "add" },4 unmodified lines"shape": [4096, 1],"data": { "kind": "cycle", "values": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15] }},"updates": { "dtype": "float16", "shape": [4096, 4], "data": { "kind": "constant", "value": 1.0 } }},"outputs": { "output": { "dtype": "float16", "shape": [16, 4], "tolerance": 0.01 } }},26 unmodified lines{"name": "f16_reduction_max_full_depth_atomic_f32_route","provenance": {"notes": "Correctness lock for the generalized full-index-depth f16 scratch-atomic route. Four thousand duplicate scalar updates contend on one destination, and max remains exact regardless of atomic order."},"attrs": { "reduction": "max" },"inputs": {37 unmodified lines"name": "ort_int8_reduction_mul_wrap8","provenance": {"source": "ONNX Runtime CPUExecutionProvider","notes": "The existing INT8 route previously accumulated the physical i32 product without narrowing it."},"attrs": { "reduction": "mul" },"inputs": {45 unmodified lines{"name": "int8_reduction_add_high_contention_wrap","provenance": {"notes": "3000 updates over 4 slots, every slot wrapping several times. The parallel narrow-int route reduces on the raw two's-complement bits and narrows once at the end; this pins that against the reference's narrow-every-step arithmetic at a contention level a two-update fixture cannot reach. Index and update cycles share a period so each slot's total is distinct, which also catches a mispaired index/update lane."},"attrs": { "reduction": "add" },"inputs": {32 unmodified lines{"name": "int16_reduction_max_duplicate_indices","provenance": {"notes": "16-bit signed max over the same i32-widened atomic path as int8, at values no 8-bit fixture can represent."},"attrs": { "reduction": "max" },"inputs": {2 unmodified lines"updates": { "dtype": "int16", "shape": [512], "data": { "kind": "cycle", "values": [-20000, 32767, -1, 5] } }},"outputs": { "output": { "dtype": "int16", "shape": [3], "tolerance": 0 } }}]}1234245 unmodified lines25025125225325425525627 unmodified lines28428528628728828929011 unmodified lines30230330430530630730851 unmodified lines360361362363364365366127 unmodified lines4944954964974984995007 unmodified lines50850951051151251351415 unmodified lines53053153253353453553662 unmodified lines59960060160260360460515 unmodified lines62162262362462562662715 unmodified lines64364464564664764864915 unmodified lines66566666766866967067115 unmodified lines687688689690691692693146 unmodified lines84084184284384484584698 unmodified lines94594694794894995095157 unmodified lines100910101011101210131014101538 unmodified lines105410551056105710581059106010 unmodified lines10711072107310741075107610776 unmodified lines108410851086108710881089109017 unmodified lines11081109111011111112111311144 unmodified lines1119112011211122112311241125112611271128112926 unmodified lines115611571158115911601161116237 unmodified lines120012011202120312041205120645 unmodified lines125212531254125512561257125832 unmodified lines12911292129312941295129612972 unmodified lines1300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330{"fixtureArrays": {"scatter_nd_data_4x4x4": [1, 2, 3, 4, 5, 6, 7, 8, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 8, 7, 6, 5, 4, 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8],"backend_row_slice_updates_input_updates": [5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4],245 unmodified lines"provenance": {"source": "onnxruntime/test/providers/cpu/tensor/scatter_nd_op_test.cc","test": "ScatterNDOpTest.ScatterND_batched_index_int64","notes": "A float32 payload exercises the batched-index pattern."},"inputs": {"data": { "dtype": "float32", "shape": [2, 2], "data": { "kind": "values", "values": [2.0, 3.0, 2.0, 3.0] } },27 unmodified lines"provenance": {"source": "onnxruntime/test/providers/cpu/tensor/scatter_nd_op_test.cc","test": "ScatterNDOpTest.ScatterND_sliced_index_int64","notes": "A float32 payload exercises the sliced-index update pattern."},"inputs": {"data": { "dtype": "float32", "shape": [2, 2], "data": { "kind": "constant", "value": 0.0 } },11 unmodified lines"provenance": {"source": "onnxruntime/test/providers/cpu/tensor/scatter_nd_op_test.cc","test": "ScatterNDOpTest.ScatterND_batched_3tensor_int64","notes": "A compact uint32 ScatterND case uses batched depth-2 indices."},"inputs": {"data": {51 unmodified lines{"name": "empty_indices_zero_width_reduction_add_identity","provenance": {"notes": "An empty index tensor with a zero-width data suffix leaves the input unchanged under add reduction. The slice path must return without dividing by the zero inner width."},"attrs": { "reduction": "add" },"inputs": {127 unmodified lines"provenance": {"source": "onnxruntime/test/providers/cpu/tensor/scatter_nd_op_test.cc","test": "ScatterNDOpTest.ScatterND_matrice_int64_int64_neg_indices","notes": "A float32 payload and int32 indices exercise the negative-index pattern."},"inputs": {"data": { "dtype": "float32", "shape": [2, 2], "data": { "kind": "values", "values": [1.0, 1.0, 2.0, 2.0] } },7 unmodified lines"provenance": {"source": "onnxruntime/test/providers/cpu/tensor/scatter_nd_op_test.cc","test": "ScatterNDOpTest.ScatterND_3tensor_int64","notes": "A float32 payload and int32 indices exercise a negative-index slice update."},"inputs": {"data": {15 unmodified lines"provenance": {"source": "onnxruntime/test/providers/cpu/tensor/scatter_nd_op_test.cc","test": "ScatterNDOpTest.ScatterND_18_mul_long_shape","notes": "A rank-6 tensor with duplicate indices exercises multiply reduction over long slices."},"attrs": { "reduction": "mul" },"inputs": {62 unmodified lines"outputs": { "output": { "dtype": "float32", "shape": [4, 4, 4] } },"provenance": {"source": "cmake/external/onnx/onnx/backend/test/data/node/test_scatternd","notes": "This WebGPU package stores representable ONNX int64 indices in int32 or uint32 slots."}},{15 unmodified lines"outputs": { "output": { "dtype": "float32", "shape": [4, 4, 4] } },"provenance": {"source": "cmake/external/onnx/onnx/backend/test/data/node/test_scatternd_add","notes": "This WebGPU package stores representable ONNX int64 indices in int32 or uint32 slots."}},{15 unmodified lines"outputs": { "output": { "dtype": "float32", "shape": [4, 4, 4] } },"provenance": {"source": "cmake/external/onnx/onnx/backend/test/data/node/test_scatternd_max","notes": "This WebGPU package stores representable ONNX int64 indices in int32 or uint32 slots."}},{15 unmodified lines"outputs": { "output": { "dtype": "float32", "shape": [4, 4, 4] } },"provenance": {"source": "cmake/external/onnx/onnx/backend/test/data/node/test_scatternd_min","notes": "This WebGPU package stores representable ONNX int64 indices in int32 or uint32 slots."}},{15 unmodified lines"outputs": { "output": { "dtype": "float32", "shape": [4, 4, 4] } },"provenance": {"source": "cmake/external/onnx/onnx/backend/test/data/node/test_scatternd_multiply","notes": "This WebGPU package stores representable ONNX int64 indices in int32 or uint32 slots."}},{146 unmodified lines"provenance": {"source": "onnxruntime/test/providers/cpu/tensor/scatter_nd_op_test.cc","test": "ScatterNDOpTest.ScatterND_18_add","notes": "Duplicate signed negative indices normalize to rows 0, 1, and 0 before slice-add reduction."},"attrs": { "reduction": "add" },"inputs": {98 unmodified lines"provenance": {"source": "onnxruntime/test/providers/cpu/tensor/scatter_nd_op_test.cc","test": "ScatterNDOpTest.ScatterND_18_add","notes": "Duplicate int8 updates accumulate at indices 0 and 2, with every intermediate and final value remaining inside the int8 range."},"attrs": { "reduction": "add" },"inputs": {57 unmodified lines{"name": "reduction_add_single_hot_slot_many_updates","provenance": {"notes": "Many duplicate scalar updates target one output slot and must produce their exact accumulated sum."},"attrs": { "reduction": "add" },"inputs": {38 unmodified lines{"name": "scalar_output_add_many_updates_parallel_reduce_i32_negative","provenance": {"notes": "ONNX normalizes -1 and 0 to the sole output element. Alternating both spellings makes an omitted negative or nonnegative update change the exact sum."},"attrs": { "reduction": "add" },"inputs": {10 unmodified lines{"name": "reduction_add_padding_hotspot_many_updates","provenance": {"notes": "Many updates target one hot key in a much larger output table, as in sparse routing or padding-token accumulation."},"attrs": { "reduction": "add" },"inputs": {6 unmodified lines{"name": "f16_reduction_add_sparse_router_gradient","provenance": {"notes": "Each of 64 slots receives 64 float16 updates offset around +0.02 through f32 atomic scratch. The nonzero mean makes lost or rescaled contributions observable; the tolerance allows one final f16 rounding after f32 accumulation."},"attrs": { "reduction": "add" },"inputs": {17 unmodified lines{"name": "f16_reduction_add_row_slice_packed_atomic_route","provenance": {"notes": "Duplicate rows and adjacent float16 columns contend on both halves of each packed output word during CAS slice accumulation; each column carries its own update value, so a write that lands in the neighbouring half is visible."},"requires": { "features": ["shader-f16"] },"attrs": { "reduction": "add" },4 unmodified lines"shape": [4096, 1],"data": { "kind": "cycle", "values": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15] }},"updates": {"dtype": "float16","shape": [4096, 4],"data": { "kind": "cycle", "values": [1.0, 2.0, 3.0, 4.0] }}},"outputs": { "output": { "dtype": "float16", "shape": [16, 4], "tolerance": 0.01 } }},26 unmodified lines{"name": "f16_reduction_max_full_depth_atomic_f32_route","provenance": {"notes": "Four thousand duplicate float16 scalar updates contend on one full-index-depth destination; maximum reduction remains exact regardless of atomic order."},"attrs": { "reduction": "max" },"inputs": {37 unmodified lines"name": "ort_int8_reduction_mul_wrap8","provenance": {"source": "ONNX Runtime CPUExecutionProvider","notes": "An int8 reduction must narrow each product to the logical eight-bit range instead of retaining the physical int32 product."},"attrs": { "reduction": "mul" },"inputs": {45 unmodified lines{"name": "int8_reduction_add_high_contention_wrap","provenance": {"notes": "Three thousand int8 updates wrap repeatedly across four slots. Reduction uses raw two's-complement bits and narrows once at the end; synchronized index and update cycles give each slot a distinct total and expose mispaired lanes."},"attrs": { "reduction": "add" },"inputs": {32 unmodified lines{"name": "int16_reduction_max_duplicate_indices","provenance": {"notes": "Signed int16 maximum reduction uses i32-widened atomic storage at values outside the int8 range."},"attrs": { "reduction": "max" },"inputs": {2 unmodified lines"updates": { "dtype": "int16", "shape": [512], "data": { "kind": "cycle", "values": [-20000, 32767, -1, 5] } }},"outputs": { "output": { "dtype": "int16", "shape": [3], "tolerance": 0 } }},{"name": "rank1_index_tuple_updates_one_slice","provenance": {"source": "ONNX ScatterND-18 specification","notes": "The minimal spelling of a single slice update: `indices` is rank 1, so the whole tensor is the one index tuple and `updates` carries just the slice. Row 2 is replaced and the other rows must be copied through unchanged."},"attrs": {},"inputs": {"data": {"dtype": "float32","shape": [4, 3],"data": { "kind": "values", "values": [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0] }},"indices": { "dtype": "int32", "shape": [1], "data": { "kind": "values", "values": [2] } },"updates": { "dtype": "float32", "shape": [3], "data": { "kind": "values", "values": [-1.0, -2.0, -3.0] } }},"outputs": {"output": {"dtype": "float32","shape": [4, 3],"data": { "kind": "values", "values": [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, -1.0, -2.0, -3.0, 10.0, 11.0, 12.0] },"tolerance": 0}}}]}
README.md+16-12
build/webgpu/bench.json-1
build/webgpu/datamove-scatter-row.wgsl.jinja+5-9
build/webgpu/manifest.json+218-341
build/webgpu/metadata.json+26-14
build/webgpu/scatter-f16-f32-convert.wgsl.jinja+3-4
build/webgpu/scatter-flat-copy.wgsl.jinja+32-10
build/webgpu/scatter-narrow-wrap.wgsl.jinja+2-3
build/webgpu/scatter-nd-reduction-atomic.wgsl.jinja+37-38
build/webgpu/scatter-nd-reduction-f16-packed-atomic.wgsl.jinja+21-25
build/webgpu/scatter-nd-reduction-slice.wgsl.jinja+41-44
build/webgpu/scatter-nd.wgsl.jinja+21-24
build/webgpu/test.json+53-49