sync 91d990483a17
Browse filesFiles changed (15)
- README.md+16-7
- build/webgpu/bench.json+77-4
- build/webgpu/manifest.json+308-355
- build/webgpu/metadata.json+33-15
- build/webgpu/softmax-longrow-normalize.wgsl.jinja+3-3
- build/webgpu/softmax-longrow-stats.wgsl.jinja+29-35
- build/webgpu/softmax-normalize.wgsl.jinja+14-17
- build/webgpu/softmax-online-packed-rows.wgsl.jinja+40-8
- build/webgpu/softmax-online.wgsl.jinja+37-51
- build/webgpu/softmax-row-stage-strided-vec4.wgsl.jinja+13-14
- build/webgpu/softmax-row-stage.wgsl.jinja+22-29
- build/webgpu/softmax-strided-online-coop.wgsl.jinja+59-24
- build/webgpu/softmax-strided-packed4-tail.wgsl.jinja+7-8
- build/webgpu/softmax-subgroup-rows.wgsl.jinjaAdded+121
- build/webgpu/test.json+214-11
17 unmodified lines1819202122232425262728293031329 unmodified lines4243444546474849506 unmodified lines5758596061626364656667686917 unmodified lines## Inputs| Name | Bind key | Logical dtype | Rank | Shape | Description | Presence || --- | --- | --- | --- | --- | --- | --- || `input` | `x` | `T` | — | — | The input tensor of rank >= 1. | required |## Outputs| Name | Bind key | Logical dtype | Rank | Shape | Description | Presence || --- | --- | --- | --- | --- | --- | --- || `output` | `y` | `T` | same as `input` | same as `input` | The log-softmax values; same shape as the input. | required |## Attributes9 unmodified lines| --- | --- || `T` | `float32`, `float16` |## 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 cases6 unmodified lines- [`softmax-row-stage.wgsl.jinja`](build/webgpu/softmax-row-stage.wgsl.jinja)- [`softmax-strided-online-coop.wgsl.jinja`](build/webgpu/softmax-strided-online-coop.wgsl.jinja)- [`softmax-strided-packed4-tail.wgsl.jinja`](build/webgpu/softmax-strided-packed4-tail.wgsl.jinja)## 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 lines1819202122232425262728293031329 unmodified lines424344454647484950515253546 unmodified lines61626364656667686970717273747576777817 unmodified lines## Inputs| Name | Upstream name | Logical dtype | Rank | Shape | Description | Presence || --- | --- | --- | --- | --- | --- | --- || `x` | `input` | `T` | — | — | The input tensor of rank >= 1. | required |## Outputs| Name | Upstream name | Logical dtype | Rank | Shape | Description | Presence || --- | --- | --- | --- | --- | --- | --- || `y` | `output` | `T` | same as `x` | same as `x` | The log-softmax values; same shape as the input. | required |## Attributes9 unmodified lines| --- | --- || `T` | `float32`, `float16` |## Device requirementsSome implementation variants require `subgroups`. These are route-specific capabilities, not package-wide requirements; availability also depends on the request shape and dtype.## Files- [`metadata.json`](build/webgpu/metadata.json) — kernel metadata (id, digests, per-variant templates, provenance)- [`manifest.json`](build/webgpu/manifest.json) — the op contract (source of truth)- [`test.json`](build/webgpu/test.json) — correctness cases- [`bench.json`](build/webgpu/bench.json) — benchmark + tuning cases6 unmodified lines- [`softmax-row-stage.wgsl.jinja`](build/webgpu/softmax-row-stage.wgsl.jinja)- [`softmax-strided-online-coop.wgsl.jinja`](build/webgpu/softmax-strided-online-coop.wgsl.jinja)- [`softmax-strided-packed4-tail.wgsl.jinja`](build/webgpu/softmax-strided-packed4-tail.wgsl.jinja)- [`softmax-subgroup-rows.wgsl.jinja`](build/webgpu/softmax-subgroup-rows.wgsl.jinja)## 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.
1234583 unmodified lines8990919293949510 unmodified lines1061071081091101111129 unmodified lines12212312412512612712817 unmodified lines146147148149150151{"op": "ai.onnx.LogSoftmax","tunableSpace": { "WORKGROUP_SIZE": [64, 128, 256] },"cases": [{83 unmodified lines"preset": "stress","provenance": {"source": "strided-axis selector crossover","notes": "Below-crossover control for the large-inner tail pathology. At 8,320 independent strided rows the cooperative packed-4 reducer still beats the serial-lane capacity path."},"vars": { "dtype": "float32", "outer": 64, "axisDim": 2048, "inner": 130 },"attrs": { "axis": 1 },10 unmodified lines"preset": "stress","provenance": {"source": "strided-axis selector crossover","notes": "Above-crossover probe for the large-inner tail pathology. At 12,480 independent strided rows the serial-lane capacity path overtakes the cooperative packed-4 reducer."},"vars": { "dtype": "float32", "outer": 96, "axisDim": 2048, "inner": 130 },"attrs": { "axis": 1 },9 unmodified lines"name": "logsoftmax-f32-strided-axis1-120x2048x130-large-inner","preset": "stress","provenance": {"source": "authored for variant coverage","notes": "Inner=130 exercises the two-element tail of the scalar-aligned packed-4 online reducer while sharing one workgroup across four adjacent rows."},"vars": { "dtype": "float32", "outer": 120, "axisDim": 2048, "inner": 130 },17 unmodified lines"inputs": { "x": { "shape": [8192, 512], "dtype": "float32", "dist": "normal", "seed": 215, "scale": 2 } },"outputs": { "y": { "shape": [8192, 512], "dtype": "float32" } },"bench": { "metrics": [{ "type": "bandwidth", "value": "args.rows * args.cols * dtypeBytes(args.dtype) * 2" }] }}]}123483 unmodified lines8889909192939410 unmodified lines1051061071081091101119 unmodified lines12112212312412512612717 unmodified lines145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224{"tunableSpace": { "WORKGROUP_SIZE": [64, 128, 256] },"cases": [{83 unmodified lines"preset": "stress","provenance": {"source": "strided-axis selector crossover","notes": "At 8,320 independent strided rows with an inner extent of 130, the selector uses the cooperative packed-four reduction path."},"vars": { "dtype": "float32", "outer": 64, "axisDim": 2048, "inner": 130 },"attrs": { "axis": 1 },10 unmodified lines"preset": "stress","provenance": {"source": "strided-axis selector crossover","notes": "A large-inner tail with 12,480 independent strided rows measures the selector boundary between the serial-lane capacity path and cooperative packed-four reduction."},"vars": { "dtype": "float32", "outer": 96, "axisDim": 2048, "inner": 130 },"attrs": { "axis": 1 },9 unmodified lines"name": "logsoftmax-f32-strided-axis1-120x2048x130-large-inner","preset": "stress","provenance": {"source": "local fixture","notes": "Inner=130 exercises the two-element tail of the scalar-aligned packed-4 online reducer while sharing one workgroup across four adjacent rows."},"vars": { "dtype": "float32", "outer": 120, "axisDim": 2048, "inner": 130 },17 unmodified lines"inputs": { "x": { "shape": [8192, 512], "dtype": "float32", "dist": "normal", "seed": 215, "scale": 2 } },"outputs": { "y": { "shape": [8192, 512], "dtype": "float32" } },"bench": { "metrics": [{ "type": "bandwidth", "value": "args.rows * args.cols * dtypeBytes(args.dtype) * 2" }] }},{"name": "logsoftmax-f32-64x50257-vocab-odd-pathology","preset": "stress","provenance": {"notes": "GPT-2 vocabulary width (50257 % 4 != 0): online_wg scalar because online_wg_vec4 needs cols % 4 == 0 (it is otherwise eligible here, cols >= 1024 with subgroups) and the subgroup-rows route is out of range (> 8 vec4 per lane). Control: logsoftmax-f32-64x50260-vocab-control."},"vars": { "dtype": "float32", "rows": 64, "cols": 50257 },"attrs": { "axis": 1 },"inputs": { "x": { "shape": [64, 50257], "dtype": "float32", "dist": "normal", "seed": 415, "scale": 4 } },"outputs": { "y": { "shape": [64, 50257], "dtype": "float32", "dist": "empty" } },"bench": { "metrics": [{ "type": "bandwidth", "value": "args.rows * args.cols * dtypeBytes(args.dtype) * 2" }] }},{"name": "logsoftmax-f32-64x50260-vocab-control","preset": "stress","provenance": {"notes": "Nearest multiple-of-4 vocabulary width for logsoftmax-f32-64x50257-vocab-odd-pathology; same bytes within 0.01%, selects online_wg_vec4."},"vars": { "dtype": "float32", "rows": 64, "cols": 50260 },"attrs": { "axis": 1 },"inputs": { "x": { "shape": [64, 50260], "dtype": "float32", "dist": "normal", "seed": 416, "scale": 4 } },"outputs": { "y": { "shape": [64, 50260], "dtype": "float32", "dist": "empty" } },"bench": { "metrics": [{ "type": "bandwidth", "value": "args.rows * args.cols * dtypeBytes(args.dtype) * 2" }] }},{"name": "online_stream_axis31_f32","attrs": { "axis": 1 },"inputs": { "x": { "dtype": "float32", "shape": [2, 31, 8], "dist": "normal", "seed": 913, "scale": 2 } },"outputs": { "y": { "dtype": "float32", "shape": [2, 31, 8] } },"bench": { "metrics": [{ "type": "bandwidth", "value": "numel(shapes.x) * 8" }] }},{"name": "online_stream_axis32_f32","attrs": { "axis": 1 },"inputs": { "x": { "dtype": "float32", "shape": [2, 32, 8], "dist": "normal", "seed": 913, "scale": 2 } },"outputs": { "y": { "dtype": "float32", "shape": [2, 32, 8] } },"bench": { "metrics": [{ "type": "bandwidth", "value": "numel(shapes.x) * 8" }] }},{"name": "online_stream_axis33_f32","attrs": { "axis": 1 },"inputs": { "x": { "dtype": "float32", "shape": [2, 33, 8], "dist": "normal", "seed": 913, "scale": 2 } },"outputs": { "y": { "dtype": "float32", "shape": [2, 33, 8] } },"bench": { "metrics": [{ "type": "bandwidth", "value": "numel(shapes.x) * 8" }] }},{"name": "online_stream_axis64_f32","attrs": { "axis": 1 },"inputs": { "x": { "dtype": "float32", "shape": [2, 64, 8], "dist": "normal", "seed": 913, "scale": 2 } },"outputs": { "y": { "dtype": "float32", "shape": [2, 64, 8] } },"bench": { "metrics": [{ "type": "bandwidth", "value": "numel(shapes.x) * 8" }] }},{"name": "online_stream_axis65_f32","attrs": { "axis": 1 },"inputs": { "x": { "dtype": "float32", "shape": [2, 65, 8], "dist": "normal", "seed": 913, "scale": 2 } },"outputs": { "y": { "dtype": "float32", "shape": [2, 65, 8] } },"bench": { "metrics": [{ "type": "bandwidth", "value": "numel(shapes.x) * 8" }] }},{"name": "online_stream_columns_tail_f32","attrs": { "axis": 1 },"inputs": { "x": { "dtype": "float32", "shape": [129, 67, 130], "dist": "normal", "seed": 913, "scale": 2 } },"outputs": { "y": { "dtype": "float32", "shape": [129, 67, 130] } },"bench": { "metrics": [{ "type": "bandwidth", "value": "numel(shapes.x) * 8" }] }},{"name": "online_stream_four_way_tail_f32","attrs": { "axis": 1 },"inputs": { "x": { "dtype": "float32", "shape": [2, 129, 8], "dist": "normal", "seed": 913, "scale": 2 } },"outputs": { "y": { "dtype": "float32", "shape": [2, 129, 8] } },"bench": { "metrics": [{ "type": "bandwidth", "value": "numel(shapes.x) * 8" }] },"tunables": { "STRIDED_ONLINE_STREAMS": 4 }}]}
1 unmodified line23456789101112131415161718192021222324252627282930313233343536374 unmodified lines4243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722812 unmodified lines2412422432442452462472482 unmodified lines2512522532542552562572582592602612622632642651 unmodified line2672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203211 unmodified line3233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803819 unmodified lines3913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264272 unmodified lines4304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914925 unmodified lines4984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415421 unmodified line5445455465475485495505515522 unmodified lines5555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855861 unmodified line"domain": "ai.onnx","name": "LogSoftmax","sinceVersion": 13,"description": "Computes `log(softmax(input, axis))` along a single axis using a numerically stable shifted reduction. The output has the same shape as the input.","inputs": [{ "role": "input", "dtype": "T", "description": "The input tensor of rank >= 1." }],"outputs": [{"role": "output","dtype": "T","rank": "ranks.input","description": "The log-softmax values; same shape as the input.","shape": "shapes.input"}],"attributes": { "axis": -1 },"attributeDescriptions": {"axis": "The axis along which log-softmax is computed. Negative values count from the end; the default `-1` operates over the last dimension. Accepted range is `[-r, r-1]` where `r` is the input rank."},"typeConstraints": { "T": ["float32", "float16"] },"args": {"x": { "kind": "tensor", "semantic": "input", "role": "input" },"y": { "kind": "tensor", "semantic": "output", "role": "output" }},"tunables": {"WORKGROUP_SIZE": 256,"ROW_MIN_WORKGROUP": 64,"ROW_COLS_PER_LANE": 8,"BLOCK_COLS": 1024,"LONGROW_SPLIT_MIN_COLS": 65536,"STRIDED_CAPACITY_MIN_ROWS": 12288},"derive": {"storageBufferLimit": "min(device.limits.maxStorageBufferBindingSize, device.limits.maxBufferSize)","axis": "attrs.axis if attrs.axis >= 0 else attrs.axis + ranks.x","lastCols": "dim(shapes.x, ranks.x - 1)","lastRows": "rows(shapes.x, ranks.x - 1)",4 unmodified lines"lastRowScratchFits": "4 * lastRows <= storageBufferLimit","axisRowScratchFits": "4 * axisRows <= storageBufferLimit","longrowBlockScratchFits": "4 * lastRows * longrowBlocks <= storageBufferLimit","lastDispatchFits": "ceilDiv(lastRows, device.limits.maxComputeWorkgroupsPerDimension) <= device.limits.maxComputeWorkgroupsPerDimension","axisDispatchFits": "ceilDiv(axisRows, device.limits.maxComputeWorkgroupsPerDimension) <= device.limits.maxComputeWorkgroupsPerDimension","axisThreadDispatchFits": "ceilDiv(ceilDiv(axisRows, tunables.WORKGROUP_SIZE), device.limits.maxComputeWorkgroupsPerDimension) <= device.limits.maxComputeWorkgroupsPerDimension","lastAxisOk": "numel(shapes.x) == numel(shapes.y) and ranks.x >= 1 and (attrs.axis == -1 or attrs.axis == ranks.x - 1) and f16Ok(dtypes.T)","stridedAxisOk": "numel(shapes.x) == numel(shapes.y) and ranks.x >= 2 and attrs.axis + ranks.x >= 0 and attrs.axis < ranks.x and not (attrs.axis == -1 or attrs.axis == ranks.x - 1)","stridedCoopTileCols": "min(128, max(8, pow2ceil(ceilDiv(axisOuter * axisInner, 256))))","rowWorkgroupSize": "min(tunables.WORKGROUP_SIZE, max(tunables.ROW_MIN_WORKGROUP, pow2ceil(ceilDiv(lastCols, tunables.ROW_COLS_PER_LANE))))"},"bindingSets": {"longrowBlockStats": [{ "name": "x", "arg": "x", "buffer": { "type": "read-only-storage" }, "elementType": "$T" },{ "name": "blockMax", "semantic": "blockMax", "buffer": { "type": "storage" }, "elementType": "f32" },{ "name": "blockSum", "semantic": "blockSum", "buffer": { "type": "storage" }, "elementType": "f32" },{"name": "params","semantic": "kernel.params","buffer": { "type": "uniform" },"struct": {"name": "Params","fields": [{ "name": "cols", "type": "u32", "value": "lastCols" },{ "name": "blocks", "type": "u32", "value": "ceilDiv(lastCols, tunables.BLOCK_COLS)" }]}}],"longrowRowStats": [{ "name": "blockMax", "semantic": "blockMax", "buffer": { "type": "read-only-storage" }, "elementType": "f32" },{ "name": "blockSum", "semantic": "blockSum", "buffer": { "type": "read-only-storage" }, "elementType": "f32" },{ "name": "rowMax", "semantic": "rowMax", "buffer": { "type": "storage" }, "elementType": "f32" },{ "name": "rowSum", "semantic": "rowSum", "buffer": { "type": "storage" }, "elementType": "f32" },{"name": "params","semantic": "kernel.params","buffer": { "type": "uniform" },"struct": {"name": "Params","fields": [{ "name": "blocks", "type": "u32", "value": "ceilDiv(lastCols, tunables.BLOCK_COLS)" }]}}],"longrowNormalize": [{ "name": "x", "arg": "x", "buffer": { "type": "read-only-storage" }, "elementType": "$T" },{ "name": "rowMax", "semantic": "rowMax", "buffer": { "type": "read-only-storage" }, "elementType": "f32" },{ "name": "rowSum", "semantic": "rowSum", "buffer": { "type": "read-only-storage" }, "elementType": "f32" },{ "name": "y", "arg": "y", "buffer": { "type": "storage" }, "elementType": "$T" },{"name": "params","semantic": "kernel.params","buffer": { "type": "uniform" },"struct": { "name": "Params", "fields": [{ "name": "cols", "type": "u32", "value": "lastCols" }] }}],"online_vec4": [{"name": "x","arg": "x","semantic": "X","buffer": { "type": "read-only-storage" },"elementType": "$vectorScalar"},{ "name": "y", "arg": "y", "buffer": { "type": "storage" }, "elementType": "$vectorScalar" },{"name": "params","semantic": "kernel.params","buffer": { "type": "uniform" },"struct": {"name": "Params","fields": [{ "name": "rows", "type": "u32", "value": "lastRows" },{ "name": "vecCols", "type": "u32", "value": "lastCols / 4" }]}}],"online_scalar": [{"name": "x","arg": "x","semantic": "input","buffer": { "type": "read-only-storage" },"elementType": "$scalar"},{ "name": "y", "arg": "y", "semantic": "output", "buffer": { "type": "storage" }, "elementType": "$scalar" },{"name": "params","semantic": "kernel.params","buffer": { "type": "uniform" },"struct": {"name": "Params","fields": [{ "name": "rows", "type": "u32", "value": "lastRows" },{ "name": "cols", "type": "u32", "value": "lastCols" }]}}],"stableReduceMax": [{ "name": "x", "arg": "x", "buffer": { "type": "read-only-storage" }, "elementType": "$T" },{ "name": "rowMax", "semantic": "rowMax", "buffer": { "type": "storage" }, "elementType": "f32" },{"name": "params","semantic": "kernel.params","buffer": { "type": "uniform" },"struct": {"name": "Params","fields": [{ "name": "rows", "type": "u32", "value": "lastRows" },{ "name": "cols", "type": "u32", "value": "lastCols" }]}}],"stableExpSum": [{ "name": "x", "arg": "x", "buffer": { "type": "read-only-storage" }, "elementType": "$T" },{ "name": "rowMax", "semantic": "rowMax", "buffer": { "type": "read-only-storage" }, "elementType": "f32" },{ "name": "y", "arg": "y", "buffer": { "type": "storage" }, "elementType": "$T" },{ "name": "rowSum", "semantic": "rowSum", "buffer": { "type": "storage" }, "elementType": "f32" },{"name": "params","semantic": "kernel.params","buffer": { "type": "uniform" },"struct": {"name": "Params","fields": [{ "name": "rows", "type": "u32", "value": "lastRows" },{ "name": "cols", "type": "u32", "value": "lastCols" }]}}],"normalize": [{ "name": "x", "arg": "x", "semantic": "input", "buffer": { "type": "read-only-storage" }, "elementType": "$T" },{ "name": "rowMax", "semantic": "rowMax", "buffer": { "type": "read-only-storage" }, "elementType": "f32" },{ "name": "rowSum", "semantic": "rowSum", "buffer": { "type": "read-only-storage" }, "elementType": "f32" },{ "name": "y", "arg": "y", "semantic": "output", "buffer": { "type": "storage" }, "elementType": "$T" },{"name": "params","semantic": "kernel.params","buffer": { "type": "uniform" },"struct": { "name": "Params", "fields": [{ "name": "count", "type": "u32", "value": "numel(shapes.x)" }] }}],"stableNormalize": [{ "name": "x", "arg": "x", "semantic": "input", "buffer": { "type": "read-only-storage" }, "elementType": "$T" },{ "name": "rowMax", "semantic": "rowMax", "buffer": { "type": "read-only-storage" }, "elementType": "f32" },{ "name": "rowSum", "semantic": "rowSum", "buffer": { "type": "read-only-storage" }, "elementType": "f32" },{ "name": "y", "arg": "y", "semantic": "output", "buffer": { "type": "storage" }, "elementType": "$T" },{"name": "params","semantic": "kernel.params","buffer": { "type": "uniform" },"struct": {"name": "Params","fields": [{ "name": "count", "type": "u32", "value": "numel(shapes.x)" },{ "name": "cols", "type": "u32", "value": "lastCols" }]}}],"stridedScalarReduce": [{ "name": "x", "arg": "x", "buffer": { "type": "read-only-storage" }, "elementType": "$T" },{ "name": "rowMax", "semantic": "rowMax", "buffer": { "type": "storage" }, "elementType": "f32" }],"stridedScalarExpSum": [{ "name": "x", "arg": "x", "buffer": { "type": "read-only-storage" }, "elementType": "$T" },{ "name": "rowMax", "semantic": "rowMax", "buffer": { "type": "read-only-storage" }, "elementType": "f32" },{ "name": "y", "arg": "y", "buffer": { "type": "storage" }, "elementType": "$T" },{ "name": "rowSum", "semantic": "rowSum", "buffer": { "type": "storage" }, "elementType": "f32" }],"stridedOnline": [{ "name": "x", "arg": "x", "buffer": { "type": "read-only-storage" }, "elementType": "$T" },{ "name": "y", "arg": "y", "buffer": { "type": "storage" }, "elementType": "$T" }]},"variants": [{"id": "longrow_split","priority": 30,"when": ["lastCols >= tunables.LONGROW_SPLIT_MIN_COLS", "rows(shapes.x, ranks.x - 1) <= device.limits.maxComputeWorkgroupsPerDimension", "ceilDiv(dim(shapes.x, ranks.x - 1), tunables.BLOCK_COLS) <= device.limits.maxComputeWorkgroupsPerDimension", "lastRowScratchFits", "longrowBlockScratchFits", "lastAxisOk"],"intermediates": [{"id": "blockMax",12 unmodified lines{"id": "block_stats","name": "LogSoftmax.LongRowBlockStats","source": { "shader": "softmax-longrow-stats.wgsl.jinja", "inputs": { "stage": "\"block\"" } },"bindings": "longrowBlockStats","dispatch": {"x": "ceilDiv(dim(shapes.x, ranks.x - 1), tunables.BLOCK_COLS)","y": "rows(shapes.x, ranks.x - 1)"2 unmodified lines{"id": "row_stats","name": "LogSoftmax.LongRowStats","source": { "shader": "softmax-longrow-stats.wgsl.jinja", "inputs": { "stage": "\"row\"" } },"bindings": "longrowRowStats","dispatch": { "x": "rows(shapes.x, ranks.x - 1)" }},{"id": "normalize","name": "LogSoftmax.LongRowNormalize","source": { "shader": "softmax-longrow-normalize.wgsl.jinja", "inputs": { "op": "\"logsoftmax\"" } },"bindings": "longrowNormalize","dispatch": {"x": "ceilDiv(dim(shapes.x, ranks.x - 1), tunables.BLOCK_COLS)","y": "rows(shapes.x, ranks.x - 1)"1 unmodified line}]},{"id": "online_wg_vec4","priority": 16,"when": ["(device.features.has(\"subgroups\") and dim(shapes.x, ranks.x - 1) >= 1024) or (not device.features.has(\"subgroups\") and dim(shapes.x, ranks.x - 1) > 32)", "dim(shapes.x, ranks.x - 1) % 4 == 0", "ceilDiv(rows(shapes.x, ranks.x - 1), device.limits.maxComputeWorkgroupsPerDimension) <= device.limits.maxComputeWorkgroupsPerDimension", "lastAxisOk"],"constants": {"combineSubgroups": "device.features.has(\"subgroups\") and dim(shapes.x, ranks.x - 1) >= 1024","scalar": "dtypes.T","vectorScalar": "\"vec4<\" ~ dtypes.T ~ \">\"","usesF16": "dtypes.T == \"f16\"","workgroupSize": "rowWorkgroupSize"},"passes": [{"id": "main","name": "LogSoftmax.OnlineWorkgroupVec4","source": { "shader": "softmax-online.wgsl.jinja", "inputs": { "op": "\"logsoftmax\"", "useVec4": "true" } },"bindings": "online_vec4","dispatch": { "workgroups": "rows(shapes.x, ranks.x - 1)" }}]},{"id": "online_wg","priority": 15,"when": ["(device.features.has(\"subgroups\") and dim(shapes.x, ranks.x - 1) > 0) or dim(shapes.x, ranks.x - 1) > 32", "ceilDiv(rows(shapes.x, ranks.x - 1), device.limits.maxComputeWorkgroupsPerDimension) <= device.limits.maxComputeWorkgroupsPerDimension", "lastAxisOk"],"constants": {"combineSubgroups": "device.features.has(\"subgroups\")","scalar": "dtypes.T","usesF16": "dtypes.T == \"f16\"","workgroupSize": "rowWorkgroupSize"},"passes": [{"id": "main","name": "LogSoftmax.OnlineWorkgroup","source": { "shader": "softmax-online.wgsl.jinja", "inputs": { "op": "\"logsoftmax\"", "useVec4": "false" } },"bindings": "online_scalar","dispatch": { "workgroups": "rows(shapes.x, ranks.x - 1)" }}]},{"id": "online_packed_rows_vec4_nosg","priority": 17,"when": ["dim(shapes.x, ranks.x - 1) > 0", "dim(shapes.x, ranks.x - 1) <= 32", "dim(shapes.x, ranks.x - 1) % 4 == 0", "rows(shapes.x, ranks.x - 1) > 32", "lastAxisOk"],"constants": {"scalar": "dtypes.T","vectorScalar": "\"vec4<\" ~ dtypes.T ~ \">\"","usesF16": "dtypes.T == \"f16\"","lanesPerRow": 8,"rowsPerWorkgroup": 32},1 unmodified line{"id": "main","name": "LogSoftmax.OnlinePackedRowsVec4NoSg","source": {"shader": "softmax-online-packed-rows.wgsl.jinja","inputs": {"op": "\"logsoftmax\"","lanesPerRow": "constants.lanesPerRow","rowsPerWorkgroup": "constants.rowsPerWorkgroup"}},"bindings": "online_vec4","dispatch": { "gridStride": "ceilDiv(rows(shapes.x, ranks.x - 1), constants.rowsPerWorkgroup)" }}]},{"id": "online_local_vec4_nosg","priority": 16,"tunables": { "WORKGROUP_SIZE": 8 },"when": ["dim(shapes.x, ranks.x - 1) > 0", "dim(shapes.x, ranks.x - 1) <= 32", "dim(shapes.x, ranks.x - 1) % 4 == 0", "ceilDiv(rows(shapes.x, ranks.x - 1), device.limits.maxComputeWorkgroupsPerDimension) <= device.limits.maxComputeWorkgroupsPerDimension", "lastAxisOk"],"constants": {"combineSubgroups": false,"scalar": "dtypes.T","vectorScalar": "\"vec4<\" ~ dtypes.T ~ \">\"","usesF16": "dtypes.T == \"f16\"","workgroupSize": "tunables.WORKGROUP_SIZE"},"passes": [{"id": "main","name": "LogSoftmax.OnlineLocalVec4NoSg","source": { "shader": "softmax-online.wgsl.jinja", "inputs": { "op": "\"logsoftmax\"", "useVec4": "true" } },"bindings": "online_vec4","dispatch": { "workgroups": "rows(shapes.x, ranks.x - 1)" }}]},{"id": "online_local_nosg","priority": 14,"tunables": { "WORKGROUP_SIZE": 32 },"when": ["dim(shapes.x, ranks.x - 1) > 0", "dim(shapes.x, ranks.x - 1) <= 32", "ceilDiv(rows(shapes.x, ranks.x - 1), device.limits.maxComputeWorkgroupsPerDimension) <= device.limits.maxComputeWorkgroupsPerDimension", "lastAxisOk"],"constants": {"combineSubgroups": false,"scalar": "dtypes.T","usesF16": "dtypes.T == \"f16\"","workgroupSize": "tunables.WORKGROUP_SIZE"},"passes": [{"id": "main","name": "LogSoftmax.OnlineLocalNoSg","source": { "shader": "softmax-online.wgsl.jinja", "inputs": { "op": "\"logsoftmax\"", "useVec4": "false" } },"bindings": "online_scalar","dispatch": { "workgroups": "rows(shapes.x, ranks.x - 1)" }}]},9 unmodified lines{"id": "reduce_max","name": "LogSoftmax.ReduceMax","source": { "shader": "softmax-row-stage.wgsl.jinja", "inputs": { "stage": "\"max\"", "strided": "false" } },"bindings": "stableReduceMax","dispatch": { "workgroups": "numel(shapes.x) / dim(shapes.x, ranks.x - 1)" }},{"id": "exp_sum","name": "LogSoftmax.ExpSum","source": {"shader": "softmax-row-stage.wgsl.jinja","inputs": { "stage": "\"exp_sum\"", "strided": "false" }},"bindings": "stableExpSum","dispatch": { "workgroups": "numel(shapes.x) / dim(shapes.x, ranks.x - 1)" }},{"id": "normalize","name": "LogSoftmax.Normalize","source": {"shader": "softmax-normalize.wgsl.jinja","inputs": { "strided": "false", "op": "\"logsoftmax\"" }},"bindings": "stableNormalize","dispatch": { "threads": "numel(shapes.x)", "workgroupSize": "tunables.WORKGROUP_SIZE" }}]},{"id": "strided_3pass_vec4","priority": 14,"derive": { "axis": "attrs.axis if attrs.axis >= 0 else attrs.axis + ranks.x" },"when": ["dtypes.T == \"f32\"", "stridedAxisOk", "inner(shapes.x, attrs.axis if attrs.axis >= 0 else attrs.axis + ranks.x) % 4 == 0", "axisDispatchFits", "axisRowScratchFits"],"intermediates": [{ "id": "rowMax", "dtype": "float32", "shape": "[numel(shapes.x) / dim(shapes.x, axis)]" },{ "id": "rowSum", "dtype": "float32", "shape": "[numel(shapes.x) / dim(shapes.x, axis)]" }2 unmodified lines{"id": "reduce_max","name": "LogSoftmax.StridedReduceMaxVec4","source": {"shader": "softmax-row-stage-strided-vec4.wgsl.jinja","inputs": { "stage": "\"max\"", "xShape": "shapes.x", "axis": "axis" }},"bindings": [{"name": "x","arg": "x","semantic": "input","buffer": { "type": "read-only-storage" },"elementType": "vec4<f32>"},{ "name": "rowMax", "semantic": "rowMax", "buffer": { "type": "storage" }, "elementType": "vec4<f32>" }],"dispatch": { "workgroups": "numel(shapes.x) / dim(shapes.x, axis) / 4" }},{"id": "exp_sum","name": "LogSoftmax.StridedExpSumVec4","source": {"shader": "softmax-row-stage-strided-vec4.wgsl.jinja","inputs": { "stage": "\"exp_sum\"", "xShape": "shapes.x", "axis": "axis" }},"bindings": [{"name": "x","arg": "x","semantic": "input","buffer": { "type": "read-only-storage" },"elementType": "vec4<f32>"},{"name": "rowMax","semantic": "rowMax","buffer": { "type": "read-only-storage" },"elementType": "vec4<f32>"},{"name": "y","arg": "y","semantic": "output","buffer": { "type": "storage" },"elementType": "vec4<f32>"},{ "name": "rowSum", "semantic": "rowSum", "buffer": { "type": "storage" }, "elementType": "vec4<f32>" }],"dispatch": { "workgroups": "numel(shapes.x) / dim(shapes.x, axis) / 4" }},{"id": "normalize","name": "LogSoftmax.StridedNormalize","source": {"shader": "softmax-normalize.wgsl.jinja","inputs": { "strided": "true", "xShape": "shapes.x", "axis": "axis", "op": "\"logsoftmax\"" }},"bindings": "normalize","dispatch": { "threads": "numel(shapes.x)", "workgroupSize": "tunables.WORKGROUP_SIZE" }}]},5 unmodified lines{"id": "main","name": "LogSoftmax.StridedOnlineCoop","source": {"shader": "softmax-strided-online-coop.wgsl.jinja","inputs": {"xShape": "shapes.x","axis": "axis","op": "\"logsoftmax\"","tileCols": "stridedCoopTileCols"}},"bindings": "stridedOnline","dispatch": { "workgroups": "ceilDiv(axisOuter * axisInner, stridedCoopTileCols)" }}]},{"id": "strided_online_packed4_tail","priority": 18,"derive": { "axis": "attrs.axis if attrs.axis >= 0 else attrs.axis + ranks.x" },"when": ["dtypes.T == \"f32\"", "stridedAxisOk", "inner(shapes.x, attrs.axis if attrs.axis >= 0 else attrs.axis + ranks.x) >= 4", "inner(shapes.x, attrs.axis if attrs.axis >= 0 else attrs.axis + ranks.x) % 4 != 0", "dim(shapes.x, axis) < 2048 or axisRows < tunables.STRIDED_CAPACITY_MIN_ROWS", "axisDispatchFits"],"passes": [{"id": "main","name": "LogSoftmax.StridedOnlinePacked4Tail","source": {"shader": "softmax-strided-packed4-tail.wgsl.jinja","inputs": { "xShape": "shapes.x", "axis": "axis" }},"bindings": [{"name": "x","arg": "x","semantic": "input","buffer": { "type": "read-only-storage" },"elementType": "f32"},{ "name": "y", "arg": "y", "semantic": "output", "buffer": { "type": "storage" }, "elementType": "f32" }],"dispatch": {"workgroups": "numel(shapes.x) / dim(shapes.x, axis) / inner(shapes.x, axis) * ceilDiv(inner(shapes.x, axis), 4)"}}]1 unmodified line{"id": "strided_3pass","priority": 12,"derive": { "axis": "attrs.axis if attrs.axis >= 0 else attrs.axis + ranks.x" },"demoteWhen": ["dtypes.T == \"f32\" and inner(shapes.x, attrs.axis if attrs.axis >= 0 else attrs.axis + ranks.x) >= 4 and inner(shapes.x, attrs.axis if attrs.axis >= 0 else attrs.axis + ranks.x) % 4 != 0"],"when": ["stridedAxisOk", "f16Ok(dtypes.T)", "axisDispatchFits", "axisRowScratchFits"],"intermediates": [{ "id": "rowMax", "dtype": "float32", "shape": "[numel(shapes.x) / dim(shapes.x, axis)]" },{ "id": "rowSum", "dtype": "float32", "shape": "[numel(shapes.x) / dim(shapes.x, axis)]" }2 unmodified lines{"id": "reduce_max","name": "LogSoftmax.StridedReduceMax","source": {"shader": "softmax-row-stage.wgsl.jinja","inputs": { "stage": "\"max\"", "strided": "true", "xShape": "shapes.x", "axis": "axis" }},"bindings": "stridedScalarReduce","dispatch": { "workgroups": "numel(shapes.x) / dim(shapes.x, axis)" }},{"id": "exp_sum","name": "LogSoftmax.StridedExpSum","source": {"shader": "softmax-row-stage.wgsl.jinja","inputs": { "stage": "\"exp_sum\"", "strided": "true", "xShape": "shapes.x", "axis": "axis" }},"bindings": "stridedScalarExpSum","dispatch": { "workgroups": "numel(shapes.x) / dim(shapes.x, axis)" }},{"id": "normalize","name": "LogSoftmax.StridedNormalize","source": {"shader": "softmax-normalize.wgsl.jinja","inputs": { "strided": "true", "xShape": "shapes.x", "axis": "axis", "op": "\"logsoftmax\"" }},"bindings": "normalize","dispatch": { "threads": "numel(shapes.x)", "workgroupSize": "tunables.WORKGROUP_SIZE" }}]}1 unmodified line2345678910111213141516171819202122232425264 unmodified lines313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828312 unmodified lines969798991001011021031041051061071081091101111121131141152 unmodified lines1181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491 unmodified line1511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402411 unmodified line2432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323339 unmodified lines3433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994002 unmodified lines4034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444455 unmodified lines4514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884891 unmodified line4914924934944954964974984992 unmodified lines5025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385391 unmodified line"domain": "ai.onnx","name": "LogSoftmax","sinceVersion": 13,"inputs": { "x": { "onnx": "input", "dtype": "T" } },"outputs": { "y": { "onnx": "output", "dtype": "T", "rank": "ranks.x", "shape": "shapes.x" } },"attributes": { "axis": { "default": -1 } },"typeConstraints": { "T": ["float32", "float16"] },"tunables": {"WORKGROUP_SIZE": { "default": 256 },"ROW_MIN_WORKGROUP": { "default": 64 },"ROW_COLS_PER_LANE": { "default": 8 },"BLOCK_COLS": { "default": 1024 },"LONGROW_SPLIT_MIN_COLS": { "default": 65536 },"STRIDED_CAPACITY_MIN_ROWS": { "default": 12288 },"PACKED_ROWS_MAX_COLS": { "default": 256 },"PACKED_ROWS_MIN_ROW_GROUPS": { "default": 64 },"PACKED_ROWS_VEC4_MAX_COLS": { "default": 128 },"STRIDED_ONLINE_STREAMS": { "default": 2 }},"derive": {"storageBufferLimit": "min(device.limits.maxStorageBufferBindingSize, device.limits.maxBufferSize)","deviceWorkgroupCap": "min(device.limits.maxComputeInvocationsPerWorkgroup, device.limits.maxComputeWorkgroupSizeX)","axis": "attrs.axis if attrs.axis >= 0 else attrs.axis + ranks.x","lastCols": "dim(shapes.x, ranks.x - 1)","lastRows": "rows(shapes.x, ranks.x - 1)",4 unmodified lines"lastRowScratchFits": "4 * lastRows <= storageBufferLimit","axisRowScratchFits": "4 * axisRows <= storageBufferLimit","longrowBlockScratchFits": "4 * lastRows * longrowBlocks <= storageBufferLimit","lastDispatchFits": "ceilDiv(lastRows, min(device.limits.maxComputeWorkgroupsPerDimension, 65535)) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535)","axisDispatchFits": "ceilDiv(axisRows, min(device.limits.maxComputeWorkgroupsPerDimension, 65535)) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535)","axisThreadDispatchFits": "ceilDiv(ceilDiv(axisRows, tunables.WORKGROUP_SIZE), min(device.limits.maxComputeWorkgroupsPerDimension, 65535)) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535)","lastAxisOk": "numel(shapes.x) == numel(shapes.y) and ranks.x >= 1 and (attrs.axis == -1 or attrs.axis == ranks.x - 1) and f16Ok(dtypes.T)","stridedAxisOk": "numel(shapes.x) == numel(shapes.y) and ranks.x >= 2 and attrs.axis + ranks.x >= 0 and attrs.axis < ranks.x and not (attrs.axis == -1 or attrs.axis == ranks.x - 1)","stridedCoopTileCols": "min(128, max(8, pow2ceil(ceilDiv(axisOuter * axisInner, 256))))","rowWorkgroupSize": "min(tunables.WORKGROUP_SIZE, max(tunables.ROW_MIN_WORKGROUP, pow2ceil(ceilDiv(lastCols, tunables.ROW_COLS_PER_LANE))))","subgroupRowsWorkgroup": "min(tunables.WORKGROUP_SIZE, deviceWorkgroupCap)","subgroupRowsLaneVecs": "ceilDiv(lastCols / 4, device.adapterInfo.subgroupMinSize) if (device.features.has(\"subgroups\") and has(device.adapterInfo, \"subgroupMinSize\") and device.adapterInfo.subgroupMinSize > 0) else 0","stridedOnlineStreams": "min(4, pow2ceil(max(1, tunables.STRIDED_ONLINE_STREAMS)), max(1, ceilDiv(dim(shapes.x, axis), 256 / stridedCoopTileCols))) if dtypes.T == \"f32\" else 1"},"bindings": {"rowMax": { "buffer": "storage", "elementType": "f32" },"rowSum": { "buffer": "storage", "elementType": "f32" },"rowMax_2": { "name": "rowMax", "buffer": "read-only-storage", "elementType": "f32" },"rowSum_2": { "name": "rowSum", "buffer": "read-only-storage", "elementType": "f32" },"x_2": { "name": "x", "buffer": "read-only-storage", "elementType": "$vectorScalar" },"y_2": { "name": "y", "buffer": "storage", "elementType": "$vectorScalar" },"params": {"buffer": "uniform","struct": [{ "name": "rows", "type": "u32", "value": "lastRows" },{ "name": "vecCols", "type": "u32", "value": "lastCols / 4" }]},"x_3": { "name": "x", "buffer": "read-only-storage", "elementType": "$scalar" },"y_3": { "name": "y", "buffer": "storage", "elementType": "$scalar" },"params_5": {"name": "params","buffer": "uniform","struct": [{ "name": "rows", "type": "u32", "value": "lastRows" },{ "name": "cols", "type": "u32", "value": "lastCols" }]},"x_4": { "name": "x", "buffer": "read-only-storage", "elementType": "vec4<f32>" },"params_7": {"name": "params","buffer": "uniform","struct": [{ "name": "count", "type": "u32", "value": "numel(shapes.x)" }]}},"variants": [{"id": "longrow_split","priority": 30,"when": ["lastCols >= tunables.LONGROW_SPLIT_MIN_COLS", "rows(shapes.x, ranks.x - 1) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535)", "ceilDiv(dim(shapes.x, ranks.x - 1), tunables.BLOCK_COLS) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535)", "lastRowScratchFits", "longrowBlockScratchFits", "lastAxisOk"],"intermediates": [{"id": "blockMax",12 unmodified lines{"id": "block_stats","name": "LogSoftmax.LongRowBlockStats","shader": "softmax-longrow-stats.wgsl.jinja","derive": { "stage": "\"block\"" },"bindings": ["x",{ "name": "blockMax", "buffer": "storage", "elementType": "f32" },{ "name": "blockSum", "buffer": "storage", "elementType": "f32" },{"name": "params","struct": [{ "name": "cols", "type": "u32", "value": "lastCols" },{ "name": "blocks", "type": "u32", "value": "ceilDiv(lastCols, tunables.BLOCK_COLS)" }]}],"dispatch": {"x": "ceilDiv(dim(shapes.x, ranks.x - 1), tunables.BLOCK_COLS)","y": "rows(shapes.x, ranks.x - 1)"2 unmodified lines{"id": "row_stats","name": "LogSoftmax.LongRowStats","shader": "softmax-longrow-stats.wgsl.jinja","derive": { "stage": "\"row\"" },"bindings": [{ "name": "blockMax", "buffer": "read-only-storage", "elementType": "f32" },{ "name": "blockSum", "buffer": "read-only-storage", "elementType": "f32" },"rowMax","rowSum",{"name": "params","struct": [{ "name": "blocks", "type": "u32", "value": "ceilDiv(lastCols, tunables.BLOCK_COLS)" }]}],"dispatch": { "x": "rows(shapes.x, ranks.x - 1)" }},{"id": "normalize","name": "LogSoftmax.LongRowNormalize","shader": "softmax-longrow-normalize.wgsl.jinja","derive": { "op": "\"logsoftmax\"" },"bindings": ["x","rowMax_2","rowSum_2","y",{ "name": "params", "struct": [{ "name": "cols", "type": "u32", "value": "lastCols" }] }],"dispatch": {"x": "ceilDiv(dim(shapes.x, ranks.x - 1), tunables.BLOCK_COLS)","y": "rows(shapes.x, ranks.x - 1)"1 unmodified line}]},{"id": "online_subgroup_rows_vec4","priority": 18,"when": ["dim(shapes.x, ranks.x - 1) % 4 == 0", "has(device.adapterInfo, \"subgroupMinSize\")", "device.adapterInfo.subgroupMinSize >= 16", "dim(shapes.x, ranks.x - 1) >= 64", "subgroupRowsLaneVecs >= 1", "subgroupRowsLaneVecs <= 8", "lastRows >= 64", "has(device.adapterInfo, \"subgroupMaxSize\")", "device.adapterInfo.subgroupMaxSize <= subgroupRowsWorkgroup", "pow2ceil(subgroupRowsWorkgroup) == subgroupRowsWorkgroup", "ceilDiv(ceilDiv(lastRows, subgroupRowsWorkgroup / device.adapterInfo.subgroupMaxSize), min(device.limits.maxComputeWorkgroupsPerDimension, 65535)) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535)", "lastAxisOk"],"requires": { "features": ["subgroups"] },"derive": {"scalar": "dtypes.T","vectorScalar": "\"vec4<\" ~ dtypes.T ~ \">\"","workgroupSize": "subgroupRowsWorkgroup","vecsPerLane": "subgroupRowsLaneVecs"},"passes": [{"id": "main","name": "LogSoftmax.OnlineSubgroupRowsVec4","shader": "softmax-subgroup-rows.wgsl.jinja","derive": { "op": "\"logsoftmax\"" },"bindings": ["x_2", "y_2", "params"],"dispatch": {"x": "min(ceilDiv(lastRows, subgroupRowsWorkgroup / device.adapterInfo.subgroupMaxSize), 65535)","y": "ceilDiv(ceilDiv(lastRows, subgroupRowsWorkgroup / device.adapterInfo.subgroupMaxSize), 65535)","z": 1},"subgroupCollectivesWidth": "portable"}]},{"id": "online_wg_vec4","priority": 16,"when": ["(device.features.has(\"subgroups\") and dim(shapes.x, ranks.x - 1) >= 1024) or (not device.features.has(\"subgroups\") and dim(shapes.x, ranks.x - 1) > 32)", "dim(shapes.x, ranks.x - 1) % 4 == 0", "ceilDiv(rows(shapes.x, ranks.x - 1), min(device.limits.maxComputeWorkgroupsPerDimension, 65535)) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535)", "lastAxisOk"],"derive": {"combineSubgroups": "device.features.has(\"subgroups\") and dim(shapes.x, ranks.x - 1) >= 1024","scalar": "dtypes.T","vectorScalar": "\"vec4<\" ~ dtypes.T ~ \">\"","workgroupSize": "rowWorkgroupSize"},"passes": [{"id": "main","name": "LogSoftmax.OnlineWorkgroupVec4","shader": "softmax-online.wgsl.jinja","subgroupCollectivesWidth": "portable","derive": { "op": "\"logsoftmax\"", "useVec4": "true" },"bindings": ["x_2", "y_2", "params"],"dispatch": {"x": "min(rows(shapes.x, ranks.x - 1), 65535)","y": "ceilDiv(rows(shapes.x, ranks.x - 1), 65535)","z": 1}}]},{"id": "online_wg","priority": 15,"when": ["(device.features.has(\"subgroups\") and dim(shapes.x, ranks.x - 1) > 0) or dim(shapes.x, ranks.x - 1) > 32", "ceilDiv(rows(shapes.x, ranks.x - 1), min(device.limits.maxComputeWorkgroupsPerDimension, 65535)) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535)", "lastAxisOk"],"derive": {"combineSubgroups": "device.features.has(\"subgroups\")","scalar": "dtypes.T","workgroupSize": "rowWorkgroupSize"},"passes": [{"id": "main","name": "LogSoftmax.OnlineWorkgroup","shader": "softmax-online.wgsl.jinja","subgroupCollectivesWidth": "portable","derive": { "op": "\"logsoftmax\"", "useVec4": "false" },"bindings": ["x_3", "y_3", "params_5"],"dispatch": {"x": "min(rows(shapes.x, ranks.x - 1), 65535)","y": "ceilDiv(rows(shapes.x, ranks.x - 1), 65535)","z": 1}}]},{"id": "online_packed_rows_vec4_nosg","priority": 19,"when": ["lastCols > 0", "lastCols % 4 == 0", "lastCols <= tunables.PACKED_ROWS_VEC4_MAX_COLS", "lastRows > 32", "lastCols <= 32 or ceilDiv(lastRows, 32) >= tunables.PACKED_ROWS_MIN_ROW_GROUPS", "lastAxisOk"],"derive": {"scalar": "dtypes.T","vectorScalar": "\"vec4<\" ~ dtypes.T ~ \">\"","lanesPerRow": 8,"rowsPerWorkgroup": 32},1 unmodified line{"id": "main","name": "LogSoftmax.OnlinePackedRowsVec4NoSg","shader": "softmax-online-packed-rows.wgsl.jinja","derive": {"op": "\"logsoftmax\"","lanesPerRow": "lanesPerRow","rowsPerWorkgroup": "rowsPerWorkgroup","useVec4": "true"},"bindings": ["x_2", "y_2", "params"],"dispatch": {"x": "min(ceilDiv(rows(shapes.x, ranks.x - 1), rowsPerWorkgroup), min(device.limits.maxComputeWorkgroupsPerDimension, 65535))","y": 1,"z": 1}}]},{"id": "online_packed_rows_nosg","priority": 19,"when": ["lastCols > 32", "lastCols % 4 != 0", "lastCols <= tunables.PACKED_ROWS_MAX_COLS", "ceilDiv(lastRows, 32) >= tunables.PACKED_ROWS_MIN_ROW_GROUPS", "lastAxisOk"],"derive": { "scalar": "dtypes.T", "lanesPerRow": 8, "rowsPerWorkgroup": 32 },"passes": [{"id": "main","name": "LogSoftmax.OnlinePackedRowsNoSg","shader": "softmax-online-packed-rows.wgsl.jinja","derive": {"op": "\"logsoftmax\"","useVec4": "false","lanesPerRow": "lanesPerRow","rowsPerWorkgroup": "rowsPerWorkgroup"},"bindings": ["x_3", "y_3", "params_5"],"dispatch": {"x": "min(ceilDiv(rows(shapes.x, ranks.x - 1), rowsPerWorkgroup), min(device.limits.maxComputeWorkgroupsPerDimension, 65535))","y": 1,"z": 1}}]},{"id": "online_local_vec4_nosg","priority": 16,"when": ["dim(shapes.x, ranks.x - 1) > 0", "dim(shapes.x, ranks.x - 1) <= 32", "dim(shapes.x, ranks.x - 1) % 4 == 0", "ceilDiv(rows(shapes.x, ranks.x - 1), min(device.limits.maxComputeWorkgroupsPerDimension, 65535)) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535)", "lastAxisOk"],"tunables": { "WORKGROUP_SIZE": { "default": 8 } },"derive": {"combineSubgroups": false,"scalar": "dtypes.T","vectorScalar": "\"vec4<\" ~ dtypes.T ~ \">\"","workgroupSize": "tunables.WORKGROUP_SIZE"},"passes": [{"id": "main","name": "LogSoftmax.OnlineLocalVec4NoSg","shader": "softmax-online.wgsl.jinja","derive": { "op": "\"logsoftmax\"", "useVec4": "true" },"bindings": ["x_2", "y_2", "params"],"dispatch": {"x": "min(rows(shapes.x, ranks.x - 1), 65535)","y": "ceilDiv(rows(shapes.x, ranks.x - 1), 65535)","z": 1}}]},{"id": "online_local_nosg","priority": 14,"when": ["dim(shapes.x, ranks.x - 1) > 0", "dim(shapes.x, ranks.x - 1) <= 32", "ceilDiv(rows(shapes.x, ranks.x - 1), min(device.limits.maxComputeWorkgroupsPerDimension, 65535)) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535)", "lastAxisOk"],"tunables": { "WORKGROUP_SIZE": { "default": 32 } },"derive": { "combineSubgroups": false, "scalar": "dtypes.T", "workgroupSize": "tunables.WORKGROUP_SIZE" },"passes": [{"id": "main","name": "LogSoftmax.OnlineLocalNoSg","shader": "softmax-online.wgsl.jinja","derive": { "op": "\"logsoftmax\"", "useVec4": "false" },"bindings": ["x_3", "y_3", "params_5"],"dispatch": {"x": "min(rows(shapes.x, ranks.x - 1), 65535)","y": "ceilDiv(rows(shapes.x, ranks.x - 1), 65535)","z": 1}}]},9 unmodified lines{"id": "reduce_max","name": "LogSoftmax.ReduceMax","shader": "softmax-row-stage.wgsl.jinja","derive": { "stage": "\"max\"", "strided": "false" },"bindings": ["x", "rowMax", "params_5"],"dispatch": {"x": "min(numel(shapes.x) / dim(shapes.x, ranks.x - 1), 65535)","y": "ceilDiv(numel(shapes.x) / dim(shapes.x, ranks.x - 1), 65535)","z": 1}},{"id": "exp_sum","name": "LogSoftmax.ExpSum","shader": "softmax-row-stage.wgsl.jinja","derive": { "stage": "\"exp_sum\"", "strided": "false" },"bindings": ["x", "rowMax_2", "y", "rowSum", "params_5"],"dispatch": {"x": "min(numel(shapes.x) / dim(shapes.x, ranks.x - 1), 65535)","y": "ceilDiv(numel(shapes.x) / dim(shapes.x, ranks.x - 1), 65535)","z": 1}},{"id": "normalize","name": "LogSoftmax.Normalize","shader": "softmax-normalize.wgsl.jinja","derive": { "strided": "false", "op": "\"logsoftmax\"" },"bindings": ["x","rowMax_2","rowSum_2","y",{"name": "params","struct": [{ "name": "count", "type": "u32", "value": "numel(shapes.x)" },{ "name": "cols", "type": "u32", "value": "lastCols" }]}],"dispatch": {"x": "min(ceilDiv((numel(shapes.x)), (tunables.WORKGROUP_SIZE)), 65535)","y": "ceilDiv(ceilDiv((numel(shapes.x)), (tunables.WORKGROUP_SIZE)), 65535)","z": 1}}]},{"id": "strided_3pass_vec4","priority": 14,"when": ["dtypes.T == \"f32\"", "stridedAxisOk", "inner(shapes.x, attrs.axis if attrs.axis >= 0 else attrs.axis + ranks.x) % 4 == 0", "axisDispatchFits", "axisRowScratchFits"],"derive": { "axis": "attrs.axis if attrs.axis >= 0 else attrs.axis + ranks.x" },"intermediates": [{ "id": "rowMax", "dtype": "float32", "shape": "[numel(shapes.x) / dim(shapes.x, axis)]" },{ "id": "rowSum", "dtype": "float32", "shape": "[numel(shapes.x) / dim(shapes.x, axis)]" }2 unmodified lines{"id": "reduce_max","name": "LogSoftmax.StridedReduceMaxVec4","shader": "softmax-row-stage-strided-vec4.wgsl.jinja","derive": { "stage": "\"max\"", "xShape": "shapes.x", "axisSpec": "axis" },"bindings": ["x_4", { "name": "rowMax", "buffer": "storage", "elementType": "vec4<f32>" }],"dispatch": {"x": "min(numel(shapes.x) / dim(shapes.x, axis) / 4, 65535)","y": "ceilDiv(numel(shapes.x) / dim(shapes.x, axis) / 4, 65535)","z": 1}},{"id": "exp_sum","name": "LogSoftmax.StridedExpSumVec4","shader": "softmax-row-stage-strided-vec4.wgsl.jinja","derive": { "stage": "\"exp_sum\"", "xShape": "shapes.x", "axisSpec": "axis" },"bindings": ["x_4",{ "name": "rowMax", "buffer": "read-only-storage", "elementType": "vec4<f32>" },{ "arg": "y", "elementType": "vec4<f32>" },{ "name": "rowSum", "buffer": "storage", "elementType": "vec4<f32>" }],"dispatch": {"x": "min(numel(shapes.x) / dim(shapes.x, axis) / 4, 65535)","y": "ceilDiv(numel(shapes.x) / dim(shapes.x, axis) / 4, 65535)","z": 1}},{"id": "normalize","name": "LogSoftmax.StridedNormalize","shader": "softmax-normalize.wgsl.jinja","derive": { "strided": "true", "xShape": "shapes.x", "axisSpec": "axis", "op": "\"logsoftmax\"" },"bindings": ["x", "rowMax_2", "rowSum_2", "y", "params_7"],"dispatch": {"x": "min(ceilDiv((numel(shapes.x)), (tunables.WORKGROUP_SIZE)), 65535)","y": "ceilDiv(ceilDiv((numel(shapes.x)), (tunables.WORKGROUP_SIZE)), 65535)","z": 1}}]},5 unmodified lines{"id": "main","name": "LogSoftmax.StridedOnlineCoop","shader": "softmax-strided-online-coop.wgsl.jinja","derive": {"xShape": "shapes.x","axisSpec": "axis","op": "\"logsoftmax\"","tileCols": "stridedCoopTileCols","onlineStreams": "stridedOnlineStreams"},"bindings": ["x", "y"],"dispatch": {"x": "min(ceilDiv(axisOuter * axisInner, stridedCoopTileCols), 65535)","y": "ceilDiv(ceilDiv(axisOuter * axisInner, stridedCoopTileCols), 65535)","z": 1}}]},{"id": "strided_online_packed4_tail","priority": 18,"when": ["dtypes.T == \"f32\"", "stridedAxisOk", "inner(shapes.x, attrs.axis if attrs.axis >= 0 else attrs.axis + ranks.x) >= 4", "inner(shapes.x, attrs.axis if attrs.axis >= 0 else attrs.axis + ranks.x) % 4 != 0", "dim(shapes.x, axis) < 2048 or axisRows < tunables.STRIDED_CAPACITY_MIN_ROWS", "axisDispatchFits"],"derive": { "axis": "attrs.axis if attrs.axis >= 0 else attrs.axis + ranks.x" },"passes": [{"id": "main","name": "LogSoftmax.StridedOnlinePacked4Tail","shader": "softmax-strided-packed4-tail.wgsl.jinja","derive": { "xShape": "shapes.x", "axisSpec": "axis" },"bindings": [{ "arg": "x", "elementType": "f32" }, { "arg": "y", "elementType": "f32" }],"dispatch": {"x": "min(numel(shapes.x) / dim(shapes.x, axis) / inner(shapes.x, axis) * ceilDiv(inner(shapes.x, axis), 4), 65535)","y": "ceilDiv(numel(shapes.x) / dim(shapes.x, axis) / inner(shapes.x, axis) * ceilDiv(inner(shapes.x, axis), 4), 65535)","z": 1}}]1 unmodified line{"id": "strided_3pass","priority": 12,"when": ["stridedAxisOk", "f16Ok(dtypes.T)", "axisDispatchFits", "axisRowScratchFits"],"demoteWhen": ["dtypes.T == \"f32\" and inner(shapes.x, attrs.axis if attrs.axis >= 0 else attrs.axis + ranks.x) >= 4 and inner(shapes.x, attrs.axis if attrs.axis >= 0 else attrs.axis + ranks.x) % 4 != 0"],"derive": { "axis": "attrs.axis if attrs.axis >= 0 else attrs.axis + ranks.x" },"intermediates": [{ "id": "rowMax", "dtype": "float32", "shape": "[numel(shapes.x) / dim(shapes.x, axis)]" },{ "id": "rowSum", "dtype": "float32", "shape": "[numel(shapes.x) / dim(shapes.x, axis)]" }2 unmodified lines{"id": "reduce_max","name": "LogSoftmax.StridedReduceMax","shader": "softmax-row-stage.wgsl.jinja","derive": { "stage": "\"max\"", "strided": "true", "xShape": "shapes.x", "axisSpec": "axis" },"bindings": ["x", "rowMax"],"dispatch": {"x": "min(numel(shapes.x) / dim(shapes.x, axis), 65535)","y": "ceilDiv(numel(shapes.x) / dim(shapes.x, axis), 65535)","z": 1}},{"id": "exp_sum","name": "LogSoftmax.StridedExpSum","shader": "softmax-row-stage.wgsl.jinja","derive": { "stage": "\"exp_sum\"", "strided": "true", "xShape": "shapes.x", "axisSpec": "axis" },"bindings": ["x", "rowMax_2", "y", "rowSum"],"dispatch": {"x": "min(numel(shapes.x) / dim(shapes.x, axis), 65535)","y": "ceilDiv(numel(shapes.x) / dim(shapes.x, axis), 65535)","z": 1}},{"id": "normalize","name": "LogSoftmax.StridedNormalize","shader": "softmax-normalize.wgsl.jinja","derive": { "strided": "true", "xShape": "shapes.x", "axisSpec": "axis", "op": "\"logsoftmax\"" },"bindings": ["x", "rowMax_2", "rowSum_2", "y", "params_7"],"dispatch": {"x": "min(ceilDiv((numel(shapes.x)), (tunables.WORKGROUP_SIZE)), 65535)","y": "ceilDiv(ceilDiv((numel(shapes.x)), (tunables.WORKGROUP_SIZE)), 65535)","z": 1}}]}
1234567891011121314151617181920212223242526{"name": "ai.onnx.LogSoftmax","id": "_ai_onnx_logsoftmax_webgpu_00d56e1","version": 1,"license": "Apache-2.0","backend": { "type": "webgpu" },"digest": {"algorithm": "sha256","files": {"bench.json": "rqFaX5XmJwQz0QQ1ET5FRMCuYEMotdcOJR+z6Y57a/0=","manifest.json": "m0YO7FppNrFhQRavPhUB1ruckiRUpkx9OaKbZWrZpdc=","softmax-longrow-normalize.wgsl.jinja": "AamVdoPDaWPQ3sk5loxtcuNu7oftC5J7hsPwLRDA7M0=","softmax-longrow-stats.wgsl.jinja": "K0PI+9cmRgjJsOOcBRyugN0Dm7yxBy0xvyPamEpCgxo=","softmax-normalize.wgsl.jinja": "eekHyttLyBk2X/mG54dUS2kIc5KycR3grH6000pqh1A=","softmax-online-packed-rows.wgsl.jinja": "94Xmz8Mtj/ji7XpIQUpsDdO6uShKJtWknzEI0Er+sT8=","softmax-online.wgsl.jinja": "s3GyunMaKcOIzUKhI2TUkb650oKqApFW3EASngfE/Ro=","softmax-row-stage-strided-vec4.wgsl.jinja": "l1byT6xoLl6Q7kSPd/uws6X5NsS2PwlSv2TBMCioVZA=","softmax-row-stage.wgsl.jinja": "dxlM6y02DwXeLeavHDiq70h0NCRZgz+bniCltyEgRX4=","softmax-strided-online-coop.wgsl.jinja": "bZkpOM+peRv2E0z0iT4V6bJTEsCHBpiF1ScPwENDFlU=","softmax-strided-packed4-tail.wgsl.jinja": "z7+TYeybaE/yXds/ODe4wMyosZeIrCtTfUmZsA2eIXo=","test.json": "uvZ0xakkYLGTptboBDjo8khdaQQ2h+QWiu4Z/wLWmfQ="}},"provenance": { "kernel": { "sha": "c928d21e6cc1310861cba3bafb75f5f679ecf5f3", "dirty": false } },"webgpu": { "manifestSpec": "1.0", "specialized": true, "opPath": "ops/ai.onnx.LogSoftmax" }}1234567891011121314151617181920212223242526272829303132333435363738394041424344{"name": "ai.onnx.LogSoftmax","id": "_ai_onnx_logsoftmax_webgpu_eafe4e3","version": 1,"license": "Apache-2.0","backend": { "type": "webgpu" },"digest": {"algorithm": "sha256","files": {"bench.json": "PypxQO0F40vAAACduE1EoHuJbXFSoUdf/1sxjfO3XYI=","manifest.json": "YEgGrgHNsUKssjpYJg/VI7JNOc7ROOzoE7TnwK8uD48=","softmax-longrow-normalize.wgsl.jinja": "WUMowCIMomWax9n1OZifCH/q1sfWCKgwU5OdAH6eOMo=","softmax-longrow-stats.wgsl.jinja": "prBVBse5ULq+Wl8maEVHnHtV24ispCW8XYS6ys3rzmA=","softmax-normalize.wgsl.jinja": "5HX4KpHm5VW4oAq0LfwDIv2h4ZcaW5F6DIw8hYHiwBA=","softmax-online-packed-rows.wgsl.jinja": "R05RjrEHTCi8zUwQKccDnrznkHAi3i4Xl1+VAXECEyQ=","softmax-online.wgsl.jinja": "t/yk5HbGLSgCjBNT2NbQ93rACba+TWWe0Hc/I4M3YhY=","softmax-row-stage-strided-vec4.wgsl.jinja": "bJgInlBtWpRzBoQLGZzAIWQ+crsQ9rt4Sokaq/fozFE=","softmax-row-stage.wgsl.jinja": "HyD4uC2ncynJAQwamSNH9orhDje96yEs5IecERo2ivI=","softmax-strided-online-coop.wgsl.jinja": "/OpczYeV5thgixotFxCXjWVCQvqO3kEKY0fmCgm0GPw=","softmax-strided-packed4-tail.wgsl.jinja": "CUut2x8eExSySbqp4R97Rt6F0GbFJ6b5LOHLKLpWG5Q=","softmax-subgroup-rows.wgsl.jinja": "jwyn5Nf1BBfBuaAIKIfJ5tMg16FcOeMW7llo2hy/ktw=","test.json": "pLfIl89rWpvYoFMWrF35r5mJTQQ1BkpZPmChvLUF2nQ="}},"provenance": { "kernel": { "sha": "91d990483a174128daf7673f3f37a7c890493ae1", "dirty": false } },"webgpu": {"manifestSpec": "2.0","variants": {"longrow_split": ["softmax-longrow-normalize.wgsl.jinja", "softmax-longrow-stats.wgsl.jinja"],"online_subgroup_rows_vec4": ["softmax-subgroup-rows.wgsl.jinja"],"online_wg_vec4": ["softmax-online.wgsl.jinja"],"online_wg": ["softmax-online.wgsl.jinja"],"online_packed_rows_vec4_nosg": ["softmax-online-packed-rows.wgsl.jinja"],"online_packed_rows_nosg": ["softmax-online-packed-rows.wgsl.jinja"],"online_local_vec4_nosg": ["softmax-online.wgsl.jinja"],"online_local_nosg": ["softmax-online.wgsl.jinja"],"stable_3pass": ["softmax-normalize.wgsl.jinja", "softmax-row-stage.wgsl.jinja"],"strided_3pass_vec4": ["softmax-normalize.wgsl.jinja", "softmax-row-stage-strided-vec4.wgsl.jinja"],"strided_online_coop": ["softmax-strided-online-coop.wgsl.jinja"],"strided_online_packed4_tail": ["softmax-strided-packed4-tail.wgsl.jinja"],"strided_3pass": ["softmax-normalize.wgsl.jinja", "softmax-row-stage.wgsl.jinja"]}}}
46 unmodified lines474849505152531 unmodified line555657585960616246 unmodified lineslet m = rowMax[row];let d = rowSum[row];// NaN row (any NaN input, or +inf max) -> all-NaN row, with the quiet NaN// derived from the runtime value (a constant NaN bit pattern is rejected at// WGSL const-evaluation).let rowIsNan = m > FLT_MAX || is_nan_f32(d) || d == 0.0;let nanOut = bitcast<f32>(bitcast<u32>(d) | 0x7fc00000u);1 unmodified linefor (var col = colStart + lid.x; col < colEnd; col = col + WG) {let v = f32(x[rowBase + col]);// (x - m) - log(d). x == m gives exactly 0 - log(d) (IEEE subtraction of// equal finite values is +0), matching the serial kernel's shift trick.var out = shifted_value(v, m) - logD;if (rowIsNan) {out = nanOut;46 unmodified lines474849505152531 unmodified line555657585960616246 unmodified lineslet m = rowMax[row];let d = rowSum[row];// NaN row (any NaN input, or +inf max) -> all-NaN row, with the quiet NaN// derived from the row sum (a constant NaN bit pattern is rejected at// WGSL const-evaluation).let rowIsNan = m > FLT_MAX || is_nan_f32(d) || d == 0.0;let nanOut = bitcast<f32>(bitcast<u32>(d) | 0x7fc00000u);1 unmodified linefor (var col = colStart + lid.x; col < colEnd; col = col + WG) {let v = f32(x[rowBase + col]);// Evaluate (x - m) - log(d). When x equals finite m, the first subtraction// produces +0 before log(d) is subtracted.var out = shifted_value(v, m) - logD;if (rowIsNan) {out = nanOut;
2 unmodified lines345678910111213141526 unmodified lines42434445464748495051525354555657585960614 unmodified lines666768697071727374757677787980818283848586878889909192939495968 unmodified lines10510610710810911011111211355 unmodified lines16917017117217317417525 unmodified lines2012022032042052062072 unmodified lines// The block stage assigns one workgroup to each (block, row), merges per-thread// online pairs, and writes one partial pair. The row stage assigns one// workgroup per row and folds those block partials into rowMax and rowSum.{% if source.stage == "block" and T == "f16" %}enable f16;{% endif %}{{ env.wgsl.resourceDeclarations }}const WG: u32 = {{ tunables.WORKGROUP_SIZE }}u;{% if source.stage == "block" %}const BLOCK_COLS: u32 = {{ tunables.BLOCK_COLS }}u;{% endif %}// FLT_MAX, not -inf, as the online (m, d) accumulator init: merges must keep26 unmodified lines// calls before their shared partial storage is reused.{% set combineSubgroups = combineSubgroups is defined and combineSubgroups %}{% if combineSubgroups %}// Per-subgroup partials are published into a deterministic slot: the subgroup's// ordinal index within the workgroup (lidx / sgSize). The online (m, d) merge// is not float-associative, so thread 0 must fold partials in a fixed order.// Subgroups partition a workgroup into contiguous ordinal ranges on supported// backends, so the ordinal slot is unique per subgroup and every slot in// [0, subgroupCount) is written (each subgroup elects one leader).// Sized for the worst case of one partial per invocation.var<workgroup> partialM: array<f32, WG>;var<workgroup> partialD: array<f32, WG>;var<workgroup> combinedMD: vec2<f32>;// When the whole workgroup is one subgroup the subgroup reduce already covers// it (no barriers, no shared state); otherwise subgroup leaders publish// partials through shared memory and thread 0 folds them in ordinal order.fn combine_partials(m: f32, d: f32, lidx: u32, sgSize: u32) -> vec2<f32> {let sgM = subgroupMax(m);// A lane with no elements contributes d == 0 (exact identity). A +inf4 unmodified linesif (sgSize == WG) {return vec2<f32>(sgM, sgD);}let subgroupCount = (WG + sgSize - 1u) / sgSize;// Pre-seed every fold slot with the (max, denom) identity. The fold below reads a// fixed subgroupCount slots in ordinal order (for determinism), but a slot whose// subgroup elects no leader this call — e.g. a fully out-of-window key tile in the// flash-attention loop that re-uses this shared memory each iteration — would// otherwise read stale shared memory. Identity makes such a slot a no-op.// (max identity = -FLT_MAX, denom identity = 0.)if (lidx < subgroupCount) {partialM[lidx] = -FLT_MAX;partialD[lidx] = 0.0;}workgroupBarrier();if (subgroupElect()) {let slot = lidx / sgSize;partialM[slot] = sgM;partialD[slot] = sgD;}workgroupBarrier();if (lidx == 0u) {var accM = -FLT_MAX;var accD = 0.0;for (var i = 0u; i < subgroupCount; i = i + 1u) {let mNew = max(accM, partialM[i]);accD = accD * exp_shift(accM, mNew) + partialD[i] * exp_shift(partialM[i], mNew);accM = mNew;}combinedMD = vec2<f32>(accM, accD);}8 unmodified linesvar<workgroup> partialD: array<f32, {{ mdExtent }}>;{% if mdStreamed %}// In-place fold of {{ mdStreams }} streams. The caller stores its per-thread// partials into partialM/partialD first and reads the merged pair of stream s// from slot s * WG afterwards.fn combine_partials_streams(lidx: u32) {workgroupBarrier();var stride = WG / 2u;55 unmodified lines@compute @workgroup_size(WG)fn main(@builtin(workgroup_id) wg: vec3<u32>,@builtin(local_invocation_id) lid: vec3<u32>) {{% if source.stage == "block" %}let block = wg.x;let row = wg.y;let rowBase = row * params.cols;25 unmodified lineslet merged = combine_partials(m, d, lid.x);if (lid.x == 0u) {{% if source.stage == "block" %}let out = row * params.blocks + block;blockMax[out] = merged.x;blockSum[out] = merged.y;2 unmodified lines345678910111213141526 unmodified lines424344454647484950515253545556575859606162634 unmodified lines6869707172737475767778798081828384858687888990918 unmodified lines10010110210310410510610755 unmodified lines16316416516616716816925 unmodified lines1951961971981992002012 unmodified lines// The block stage assigns one workgroup to each (block, row), merges per-thread// online pairs, and writes one partial pair. The row stage assigns one// workgroup per row and folds those block partials into rowMax and rowSum.{% if stage == "block" and T == "f16" %}enable f16;{% endif %}{{ env.wgsl.resourceDeclarations }}const WG: u32 = {{ tunables.WORKGROUP_SIZE }}u;{% if stage == "block" %}const BLOCK_COLS: u32 = {{ tunables.BLOCK_COLS }}u;{% endif %}// FLT_MAX, not -inf, as the online (m, d) accumulator init: merges must keep26 unmodified lines// calls before their shared partial storage is reused.{% set combineSubgroups = combineSubgroups is defined and combineSubgroups %}{% if combineSubgroups %}// Cross-subgroup merge that assumes nothing about which invocations share a// subgroup or how many subgroups there are: each subgroup's elected lane// publishes the subgroup pair in the slot at its OWN invocation index and sets// that index's bit in a workgroup bitmask; thread 0 then folds exactly the// published slots, in ascending index order (the online (m, d) merge is not// float-associative, so the order is fixed), and clears the mask for the next// call as it reads it. Workgroup memory starts zeroed, so the mask needs no// setup. Same three collectives as a single-subgroup reduce, two barriers.var<workgroup> partialM: array<f32, WG>;var<workgroup> partialD: array<f32, WG>;var<workgroup> leaderMask: array<atomic<u32>, (WG + 31u) / 32u>;var<workgroup> combinedMD: vec2<f32>;// When the whole workgroup is one subgroup the subgroup reduce already covers// it (no barriers, no shared state). `subgroup_size` is the size of the current// subgroup and uniform, so the test is exact and may guard the barriers below.fn combine_partials(m: f32, d: f32, lidx: u32, sgSize: u32) -> vec2<f32> {let sgM = subgroupMax(m);// A lane with no elements contributes d == 0 (exact identity). A +inf4 unmodified linesif (sgSize == WG) {return vec2<f32>(sgM, sgD);}if (subgroupElect()) {partialM[lidx] = sgM;partialD[lidx] = sgD;atomicOr(&leaderMask[lidx / 32u], 1u << (lidx % 32u));}workgroupBarrier();if (lidx == 0u) {var accM = -FLT_MAX;var accD = 0.0;for (var w = 0u; w < (WG + 31u) / 32u; w = w + 1u) {var bits = atomicExchange(&leaderMask[w], 0u);while (bits != 0u) {let slot = w * 32u + firstTrailingBit(bits);bits = bits & (bits - 1u);let mNew = max(accM, partialM[slot]);accD = accD * exp_shift(accM, mNew) + partialD[slot] * exp_shift(partialM[slot], mNew);accM = mNew;}}combinedMD = vec2<f32>(accM, accD);}8 unmodified linesvar<workgroup> partialD: array<f32, {{ mdExtent }}>;{% if mdStreamed %}// In-place fold of {{ mdStreams }} streams. Input partials occupy// partialM/partialD; stream s returns its merged pair in slot s * WG.fn combine_partials_streams(lidx: u32) {workgroupBarrier();var stride = WG / 2u;55 unmodified lines@compute @workgroup_size(WG)fn main(@builtin(workgroup_id) wg: vec3<u32>,@builtin(local_invocation_id) lid: vec3<u32>) {{% if stage == "block" %}let block = wg.x;let row = wg.y;let rowBase = row * params.cols;25 unmodified lineslet merged = combine_partials(m, d, lid.x);if (lid.x == 0u) {{% if stage == "block" %}let out = row * params.blocks + block;blockMax[out] = merged.x;blockSum[out] = merged.y;
1234567891011121314151617181920212223242569 unmodified lines95969798991001011021031041051061071081 unmodified line110111112113114115116117118119120// Element-parallel pass 3 of three-pass softmax/log-softmax. Strided-axis mode// changes only how an element finds its row. Softmax divides the exponential// values already in y by the row sum. Log-softmax rereads x against the finished// row statistics and writes (x - rowMax) - log(rowSum), so entries whose// exponentials underflow remain finite.{% if T == "f16" %}enable f16;{% endif %}{{ env.wgsl.resourceDeclarations }}{% if source.strided %}{% set stridedAxisUses = ["row_for_offset"] %}// Compiled indexing for row-wise reductions over a non-last axis. A row is one// slice along the reduction axis, indexed as outer * INNER_SIZE + inner.{% set reduce_size = source.xShape[source.axis] %}{% set inner_size = namespace(value=1) %}{% for i in range(source.axis + 1, source.xShape | length) %}{% set inner_size.value = inner_size.value * source.xShape[i] %}{% endfor %}{% set outer_size = namespace(value=1) %}{% for i in range(source.axis) %}{% set outer_size.value = outer_size.value * source.xShape[i] %}{% endfor %}{% set usesAll = stridedAxisUses is not defined %}{% set usesElementOffset = usesAll or "element_offset" in stridedAxisUses %}69 unmodified lines@compute @workgroup_size({{ tunables.WORKGROUP_SIZE }})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// maxComputeWorkgroupsPerDimension dispatch limit (outputs > 16.7M elements).let i = gid.x + gid.y * nwg.x * {{ tunables.WORKGROUP_SIZE }}u;if (i >= params.count) {return;}{% if source.strided %}let row = row_for_offset(i);{% else %}let row = i / params.cols;1 unmodified linelet m = rowMax[row];let d = rowSum[row];// NaN row (any NaN input, or +inf max) -> all-NaN row, quiet NaN derived from// the runtime value (a constant NaN bit pattern is rejected at const-eval).let rowIsNan = m > FLT_MAX || is_nan_f32(d) || d == 0.0;let nanOut = bitcast<f32>(bitcast<u32>(d) | 0x7fc00000u);// (x - m) - log(d). x == m gives exactly 0 - log(d) (IEEE subtraction of equal// finite values is +0), matching the serial kernel's shift trick.var out = shifted_value(f32(x[i]), m) - log(d);if (rowIsNan) {out = nanOut;123456789101112131415161718192069 unmodified lines909192939495969798991001011021031041051 unmodified line107108109110111112113114115116117{% if T == "f16" %}enable f16;{% endif %}{{ env.wgsl.resourceDeclarations }}{% if strided %}{% set stridedAxisUses = ["row_for_offset"] %}// Compiled indexing for row-wise reductions over a non-last axis. A row is one// slice along the reduction axis, indexed as outer * INNER_SIZE + inner.{% set reduce_size = xShape[axisSpec] %}{% set inner_size = namespace(value=1) %}{% for i in range(axisSpec + 1, xShape | length) %}{% set inner_size.value = inner_size.value * xShape[i] %}{% endfor %}{% set outer_size = namespace(value=1) %}{% for i in range(axisSpec) %}{% set outer_size.value = outer_size.value * xShape[i] %}{% endfor %}{% set usesAll = stridedAxisUses is not defined %}{% set usesElementOffset = usesAll or "element_offset" in stridedAxisUses %}69 unmodified lines@compute @workgroup_size({{ tunables.WORKGROUP_SIZE }})fn main(@builtin(global_invocation_id) gid : vec3<u32>) {// 2D-folded flat index: gid.y carries the high bits past the// per-axis dispatch fold width (outputs > 16.7M elements).let i = gid.x + gid.y * {{ DISPATCH_FOLD_WIDTH }}u * {{ tunables.WORKGROUP_SIZE }}u;if (i >= params.count) {return;}// Final element-parallel log-softmax pass. Each element rereads x and writes// (x - rowMax) - log(rowSum); strided mode changes only the row map.{% if strided %}let row = row_for_offset(i);{% else %}let row = i / params.cols;1 unmodified linelet m = rowMax[row];let d = rowSum[row];// NaN row (any NaN input, or +inf max) -> all-NaN row, quiet NaN derived from// the row sum (a constant NaN bit pattern is rejected at const-eval).let rowIsNan = m > FLT_MAX || is_nan_f32(d) || d == 0.0;let nanOut = bitcast<f32>(bitcast<u32>(d) | 0x7fc00000u);// (x - m) - log(d). x == m gives exactly 0 - log(d) (IEEE subtraction of equal// finite values is +0).var out = shifted_value(f32(x[i]), m) - log(d);if (rowIsNan) {out = nanOut;
123456789101112131431 unmodified lines4647484950515214 unmodified lines6768697071723 unmodified lines76777879808125 unmodified lines1071081091101111121131141151161178 unmodified lines126127128129130131// Portable many-short-row online softmax / log-softmax. A 256-thread// workgroup is partitioned into independent fixed-width row groups (normally// 32 rows x 8 vec4 lanes). This preserves fully coalesced 32-column traffic// while one workgroup covers many short rows.{% if usesF16 %}enable f16;{% endif %}{{ env.wgsl.resourceDeclarations }}const LANES_PER_ROW: u32 = {{ source.lanesPerRow }}u;const ROWS_PER_WORKGROUP: u32 = {{ source.rowsPerWorkgroup }}u;const WG: u32 = LANES_PER_ROW * ROWS_PER_WORKGROUP;// FLT_MAX, not -inf, as the online (m, d) accumulator init: merges must keep31 unmodified linesvar<workgroup> partialM: array<f32, WG>;var<workgroup> partialD: array<f32, WG>;@compute @workgroup_size({{ source.lanesPerRow * source.rowsPerWorkgroup }})fn main(@builtin(workgroup_id) wid: vec3<u32>,@builtin(num_workgroups) nwg: vec3<u32>,14 unmodified linesvar m = -FLT_MAX;var d = 0.0;if (validRow) {let rowBase = row * params.vecCols;for (var c = lane; c < params.vecCols; c += LANES_PER_ROW) {let v = vec4<f32>(x[rowBase + c]);3 unmodified lines+ exp_shift(v.z, mNew) + exp_shift(v.w, mNew);m = mNew;}}let partialIndex = partialBase + lane;25 unmodified lines// result to private values before any lane can start the next row group.let finalM = partialM[partialBase];let finalD = partialD[partialBase];let dBits = bitcast<u32>(finalD);let rowIsNan = finalM > FLT_MAX || is_nan_f32(finalD) || finalD == 0.0;let nanOut = bitcast<f32>(dBits | 0x7fc00000u);if (validRow) {let rowBase = row * params.vecCols;let logD = log(finalD);for (var c = lane; c < params.vecCols; c += LANES_PER_ROW) {8 unmodified lines}y[rowBase + c] = vec4<{{ scalar }}>(o);}}}}12345678910111213141531 unmodified lines4748495051525314 unmodified lines686970717273743 unmodified lines7879808182838485868788899091929325 unmodified lines1191201211221231241251261271281291301311321331341351361378 unmodified lines146147148149150151152153154155156157158159160161162163// Many-short-row online normalization. A 256-thread// workgroup is partitioned into independent fixed-width row groups (normally{% if useVec4 %}// 32 rows x 8 vec4 lanes). Each group accesses 32 consecutive columns{% else %}// 32 rows x 8 scalar lanes). Each group accesses 8 consecutive columns{% endif %}// while one workgroup covers many short rows.{{ env.wgsl.resourceDeclarations }}const LANES_PER_ROW: u32 = {{ lanesPerRow }}u;const ROWS_PER_WORKGROUP: u32 = {{ rowsPerWorkgroup }}u;const WG: u32 = LANES_PER_ROW * ROWS_PER_WORKGROUP;// FLT_MAX, not -inf, as the online (m, d) accumulator init: merges must keep31 unmodified linesvar<workgroup> partialM: array<f32, WG>;var<workgroup> partialD: array<f32, WG>;@compute @workgroup_size({{ lanesPerRow * rowsPerWorkgroup }})fn main(@builtin(workgroup_id) wid: vec3<u32>,@builtin(num_workgroups) nwg: vec3<u32>,14 unmodified linesvar m = -FLT_MAX;var d = 0.0;if (validRow) {{% if useVec4 %}let rowBase = row * params.vecCols;for (var c = lane; c < params.vecCols; c += LANES_PER_ROW) {let v = vec4<f32>(x[rowBase + c]);3 unmodified lines+ exp_shift(v.z, mNew) + exp_shift(v.w, mNew);m = mNew;}{% else %}// Scalar row walk for widths that are not divisible by four.let rowBase = row * params.cols;for (var c = lane; c < params.cols; c += LANES_PER_ROW) {let v = f32(x[rowBase + c]);let mNew = max(m, v);d = d * exp_shift(m, mNew) + exp_shift(v, mNew);m = mNew;}{% endif %}}let partialIndex = partialBase + lane;25 unmodified lines// result to private values before any lane can start the next row group.let finalM = partialM[partialBase];let finalD = partialD[partialBase];// That copy is itself the hazard this barrier closes. Lane 0 of a row writes the// slot the other seven read here, and its next write is the FIRST statement of the// next row group -- no barrier stands between them. A workgroup that grid-strides// (rowGroups above the dispatch width, so 2097152 rows over 65535 workgroups) let// lane 0 run ahead and republish slot zero while its siblings were still reading the// previous group's total, normalizing part of a row by another row's sum.workgroupBarrier();let dBits = bitcast<u32>(finalD);let rowIsNan = finalM > FLT_MAX || is_nan_f32(finalD) || finalD == 0.0;let nanOut = bitcast<f32>(dBits | 0x7fc00000u);if (validRow) {{% if useVec4 %}let rowBase = row * params.vecCols;let logD = log(finalD);for (var c = lane; c < params.vecCols; c += LANES_PER_ROW) {8 unmodified lines}y[rowBase + c] = vec4<{{ scalar }}>(o);}{% else %}let rowBase = row * params.cols;let logD = log(finalD);for (var c = lane; c < params.cols; c += LANES_PER_ROW) {let v = f32(x[rowBase + c]);var o = shifted_value(v, finalM) - logD;if (rowIsNan) {o = nanOut;}y[rowBase + c] = {{ scalar }}(o);}{% endif %}}}}
12345678910111213141516171819202132 unmodified lines54555657585960616263646566676869707172734 unmodified lines787980818283848586878889909192939495969798991001011021031041051061071088 unmodified lines11711811912012112212312412554 unmodified lines1801811821831841851861871881891901911921931941952 unmodified lines19819920020120220320414 unmodified lines2192202212222232242252 unmodified lines228229230231232233234235236{% if usesF16 %}enable f16;{% endif %}{% if combineSubgroups %}enable subgroups;{% endif %}{{ env.wgsl.resourceDeclarations }}// Workgroup-level online softmax / log-softmax over one contiguous last-axis// row per workgroup. Each thread keeps an online (max, denom) pair over its// strided chunk, partials merge with the online-softmax rule (see// the shared online-softmax combiner) and a fused second sweep writes// the result. The epilogue is either softmax or log-softmax, and vec4 row access// is used when rows are vectorized.//// `workgroupSize` is a variant constant, not the op-wide tunable: the merge tree// costs a barrier per level whatever the row length, so a short row wants fewer,// busier lanes and a long row wants the widest workgroup the device allows.const WG: u32 = {{ workgroupSize }}u;// FLT_MAX, not -inf, as the online (m, d) accumulator init: merges must keep// `m - m` finite so an empty lane / all--inf row contributes the exact32 unmodified lines// calls before their shared partial storage is reused.{% set combineSubgroups = combineSubgroups is defined and combineSubgroups %}{% if combineSubgroups %}// Per-subgroup partials are published into a deterministic slot: the subgroup's// ordinal index within the workgroup (lidx / sgSize). The online (m, d) merge// is not float-associative, so thread 0 must fold partials in a fixed order.// Subgroups partition a workgroup into contiguous ordinal ranges on supported// backends, so the ordinal slot is unique per subgroup and every slot in// [0, subgroupCount) is written (each subgroup elects one leader).// Sized for the worst case of one partial per invocation.var<workgroup> partialM: array<f32, WG>;var<workgroup> partialD: array<f32, WG>;var<workgroup> combinedMD: vec2<f32>;// When the whole workgroup is one subgroup the subgroup reduce already covers// it (no barriers, no shared state); otherwise subgroup leaders publish// partials through shared memory and thread 0 folds them in ordinal order.fn combine_partials(m: f32, d: f32, lidx: u32, sgSize: u32) -> vec2<f32> {let sgM = subgroupMax(m);// A lane with no elements contributes d == 0 (exact identity). A +inf4 unmodified linesif (sgSize == WG) {return vec2<f32>(sgM, sgD);}let subgroupCount = (WG + sgSize - 1u) / sgSize;// Pre-seed every fold slot with the (max, denom) identity. The fold below reads a// fixed subgroupCount slots in ordinal order (for determinism), but a slot whose// subgroup elects no leader this call — e.g. a fully out-of-window key tile in the// flash-attention loop that re-uses this shared memory each iteration — would// otherwise read stale shared memory. Identity makes such a slot a no-op.// (max identity = -FLT_MAX, denom identity = 0.)if (lidx < subgroupCount) {partialM[lidx] = -FLT_MAX;partialD[lidx] = 0.0;}workgroupBarrier();if (subgroupElect()) {let slot = lidx / sgSize;partialM[slot] = sgM;partialD[slot] = sgD;}workgroupBarrier();if (lidx == 0u) {var accM = -FLT_MAX;var accD = 0.0;for (var i = 0u; i < subgroupCount; i = i + 1u) {let mNew = max(accM, partialM[i]);accD = accD * exp_shift(accM, mNew) + partialD[i] * exp_shift(partialM[i], mNew);accM = mNew;}combinedMD = vec2<f32>(accM, accD);}8 unmodified linesvar<workgroup> partialD: array<f32, {{ mdExtent }}>;{% if mdStreamed %}// In-place fold of {{ mdStreams }} streams. The caller stores its per-thread// partials into partialM/partialD first and reads the merged pair of stream s// from slot s * WG afterwards.fn combine_partials_streams(lidx: u32) {workgroupBarrier();var stride = WG / 2u;54 unmodified lines@compute @workgroup_size({{ workgroupSize }})fn main(@builtin(workgroup_id) wid: vec3<u32>,@builtin(num_workgroups) nwg: vec3<u32>,@builtin(local_invocation_id) lid: vec3<u32>{% if combineSubgroups %},@builtin(subgroup_size) sgSize: u32{% endif %}) {// 2D-folded row index: wid.y carries the high bits past the// maxComputeWorkgroupsPerDimension dispatch limit (rows > maxComputeWorkgroupsPerDimension).let row = wid.x + wid.y * nwg.x;if (row >= params.rows) {return;}{% if source.useVec4 %}let rowBase = row * params.vecCols;{% else %}let rowBase = row * params.cols;2 unmodified lines// Thread-local online (m, d) over a strided chunk; f32 accumulation.var m = -FLT_MAX;var d = 0.0;{% if source.useVec4 %}for (var c = lid.x; c < params.vecCols; c = c + WG) {let v = vec4<f32>(x[rowBase + c]);let mNew = max(m, max(max(v.x, v.y), max(v.z, v.w)));14 unmodified lineslet finalM = rowMD.x;let finalD = rowMD.y;// Runtime-derived quiet NaN + bit-exact NaN test, as in the 1-pass kernel:// `m - m` (Inf - Inf) and `d != d` are both legal fast-math folds (to 0 and// false), and a constant NaN bit pattern is rejected at WGSL// const-evaluation.2 unmodified lineslet nanOut = bitcast<f32>(dBits | 0x7fc00000u);// (x - m) - log(d). x == m gives exactly 0 - log(d) (IEEE subtraction of// equal finite values is +0), matching the serial kernel's shift trick.let logD = log(finalD);{% if source.useVec4 %}for (var c = lid.x; c < params.vecCols; c = c + WG) {let v = vec4<f32>(x[rowBase + c]);var o = vec4<f32>(123456789101112131432 unmodified lines474849505152535455565758596061626364656667684 unmodified lines7374757677787980818283848586878889909192939495968 unmodified lines10510610710810911011111254 unmodified lines1671681691701711721731741751761771781791801812 unmodified lines18418518618718818919014 unmodified lines2052062072082092102112 unmodified lines214215216217218219220221222{% if combineSubgroups %}enable subgroups;{% endif %}{{ env.wgsl.resourceDeclarations }}// Workgroup-level online normalization over one contiguous last-axis row per// workgroup. Each thread keeps an online (maximum, denominator) pair over its// strided chunk. The workgroup merges those pairs, then a fused second sweep// writes the normalized result. Vectorized rows use vec4 accesses.//// `workgroupSize` fixes the merge-tree width for this specialization.const WG: u32 = {{ workgroupSize }}u;// FLT_MAX, not -inf, as the online (m, d) accumulator init: merges must keep// `m - m` finite so an empty lane / all--inf row contributes the exact32 unmodified lines// calls before their shared partial storage is reused.{% set combineSubgroups = combineSubgroups is defined and combineSubgroups %}{% if combineSubgroups %}// Cross-subgroup merge that assumes nothing about which invocations share a// subgroup or how many subgroups there are: each subgroup's elected lane// publishes the subgroup pair in the slot at its OWN invocation index and sets// that index's bit in a workgroup bitmask; thread 0 then folds exactly the// published slots, in ascending index order (the online (m, d) merge is not// float-associative, so the order is fixed), and clears the mask for the next// call as it reads it. Workgroup memory starts zeroed, so the mask needs no// setup. Same three collectives as a single-subgroup reduce, two barriers.var<workgroup> partialM: array<f32, WG>;var<workgroup> partialD: array<f32, WG>;var<workgroup> leaderMask: array<atomic<u32>, (WG + 31u) / 32u>;var<workgroup> combinedMD: vec2<f32>;// When the whole workgroup is one subgroup the subgroup reduce already covers// it (no barriers, no shared state). `subgroup_size` is the size of the current// subgroup and uniform, so the test is exact and may guard the barriers below.fn combine_partials(m: f32, d: f32, lidx: u32, sgSize: u32) -> vec2<f32> {let sgM = subgroupMax(m);// A lane with no elements contributes d == 0 (exact identity). A +inf4 unmodified linesif (sgSize == WG) {return vec2<f32>(sgM, sgD);}if (subgroupElect()) {partialM[lidx] = sgM;partialD[lidx] = sgD;atomicOr(&leaderMask[lidx / 32u], 1u << (lidx % 32u));}workgroupBarrier();if (lidx == 0u) {var accM = -FLT_MAX;var accD = 0.0;for (var w = 0u; w < (WG + 31u) / 32u; w = w + 1u) {var bits = atomicExchange(&leaderMask[w], 0u);while (bits != 0u) {let slot = w * 32u + firstTrailingBit(bits);bits = bits & (bits - 1u);let mNew = max(accM, partialM[slot]);accD = accD * exp_shift(accM, mNew) + partialD[slot] * exp_shift(partialM[slot], mNew);accM = mNew;}}combinedMD = vec2<f32>(accM, accD);}8 unmodified linesvar<workgroup> partialD: array<f32, {{ mdExtent }}>;{% if mdStreamed %}// In-place fold of {{ mdStreams }} streams. Input partials occupy// partialM/partialD; stream s returns its merged pair in slot s * WG.fn combine_partials_streams(lidx: u32) {workgroupBarrier();var stride = WG / 2u;54 unmodified lines@compute @workgroup_size({{ workgroupSize }})fn main(@builtin(workgroup_id) wid: vec3<u32>,@builtin(local_invocation_id) lid: vec3<u32>{% if combineSubgroups %},@builtin(subgroup_size) sgSize: u32{% endif %}) {// 2D-folded row index: wid.y carries the high bits past the// per-axis dispatch fold width (rows > the per-axis dispatch fold width).let row = wid.x + wid.y * {{ DISPATCH_FOLD_WIDTH }}u;if (row >= params.rows) {return;}{% if useVec4 %}let rowBase = row * params.vecCols;{% else %}let rowBase = row * params.cols;2 unmodified lines// Thread-local online (m, d) over a strided chunk; f32 accumulation.var m = -FLT_MAX;var d = 0.0;{% if useVec4 %}for (var c = lid.x; c < params.vecCols; c = c + WG) {let v = vec4<f32>(x[rowBase + c]);let mNew = max(m, max(max(v.x, v.y), max(v.z, v.w)));14 unmodified lineslet finalM = rowMD.x;let finalD = rowMD.y;// Runtime-derived quiet NaN and bit-exact NaN test:// `m - m` (Inf - Inf) and `d != d` are both legal fast-math folds (to 0 and// false), and a constant NaN bit pattern is rejected at WGSL// const-evaluation.2 unmodified lineslet nanOut = bitcast<f32>(dBits | 0x7fc00000u);// (x - m) - log(d). x == m gives exactly 0 - log(d) (IEEE subtraction of// equal finite values is +0).let logD = log(finalD);{% if useVec4 %}for (var c = lid.x; c < params.vecCols; c = c + WG) {let v = vec4<f32>(x[rowBase + c]);var o = vec4<f32>(
10 unmodified lines111213141516171819202122232440 unmodified lines656667686970718 unmodified lines80818283848586878889909192935 unmodified lines991001011021031041051061071081091101111121131141151161173 unmodified lines12112212312412512612710 unmodified lines{% set stridedAxisUses = ["REDUCE_SIZE", "INNER_SIZE", "STRIDED_ROWS"] %}// Compiled indexing for row-wise reductions over a non-last axis. A row is one// slice along the reduction axis, indexed as outer * INNER_SIZE + inner.{% set reduce_size = source.xShape[source.axis] %}{% set inner_size = namespace(value=1) %}{% for i in range(source.axis + 1, source.xShape | length) %}{% set inner_size.value = inner_size.value * source.xShape[i] %}{% endfor %}{% set outer_size = namespace(value=1) %}{% for i in range(source.axis) %}{% set outer_size.value = outer_size.value * source.xShape[i] %}{% endfor %}{% set usesAll = stridedAxisUses is not defined %}{% set usesElementOffset = usesAll or "element_offset" in stridedAxisUses %}40 unmodified linesreturn outer * INNER_SIZE_SAFE + inner;}{%- endif -%}{% if source.stage == "max" %}// max(1u,..) so an empty strided tensor (INNER_SIZE 0) still compiles — the kernel// returns before any divide (VEC4_ROWS 0 -> guard), this only avoids a const `/0`.const INNER4: u32 = max(1u, INNER_SIZE / 4u); // vec4 groups of inner positions per outer8 unmodified lines{% endif %}var<workgroup> partial: array<vec4<f32>, WGS>;{% set reduce_fn = "reduce_max_vec4" if source.stage == "max" else "reduce_add_vec4" %}fn {{ reduce_fn }}(value: vec4<f32>, tid: u32) -> vec4<f32> {partial[tid] = value;workgroupBarrier();var stride: u32 = WGS / 2u;loop {if (stride == 0u) { break; }{% if source.stage == "max" %}if (tid < stride) { partial[tid] = max(partial[tid], partial[tid + stride]); }{% else %}if (tid < stride) { partial[tid] = partial[tid] + partial[tid + stride]; }5 unmodified lines}@compute @workgroup_size(WGS)fn main(@builtin(workgroup_id) wg: vec3<u32>, @builtin(local_invocation_id) lid: vec3<u32>,@builtin(num_workgroups) nwg: vec3<u32>) {let rg = wg.x + wg.y * nwg.x; // vec4-row-group indexif (rg >= VEC4_ROWS) { return; }let outer = rg / INNER4;let inner_group = rg % INNER4;{% if source.stage == "max" %}// vec4 index of element k=0 for this group (offset is a multiple of 4 since// INNER_SIZE % 4 == 0 and inner_group*4 is too).{% endif %}let base4 = (outer * REDUCE_SIZE * INNER_SIZE + inner_group * 4u) / 4u;{% if source.stage == "max" %}var acc = vec4<f32>(-3.4028234663852886e38);for (var k = lid.x; k < REDUCE_SIZE; k = k + WGS) {acc = max(acc, x[base4 + k * STRIDE4]);3 unmodified lines{% else %}let m = rowMax[rg];// +Inf row max -> NaN row (ONNX). Derive the quiet NaN per-component from the// runtime bits (a constant NaN pattern is rejected at const-eval); m - m folds// to 0 for finite m so the exp arg stays correct on the non-Inf lanes.let nanv = bitcast<vec4<f32>>(bitcast<vec4<u32>>(m) | vec4<u32>(0x7fc00000u));let isInf = m > vec4<f32>(3.4028234663852886e38);10 unmodified lines111213141516171819202122232440 unmodified lines656667686970718 unmodified lines80818283848586878889909192935 unmodified lines991001011021031041051061071081091101111121131141151163 unmodified lines12012112212312412512610 unmodified lines{% set stridedAxisUses = ["REDUCE_SIZE", "INNER_SIZE", "STRIDED_ROWS"] %}// Compiled indexing for row-wise reductions over a non-last axis. A row is one// slice along the reduction axis, indexed as outer * INNER_SIZE + inner.{% set reduce_size = xShape[axisSpec] %}{% set inner_size = namespace(value=1) %}{% for i in range(axisSpec + 1, xShape | length) %}{% set inner_size.value = inner_size.value * xShape[i] %}{% endfor %}{% set outer_size = namespace(value=1) %}{% for i in range(axisSpec) %}{% set outer_size.value = outer_size.value * xShape[i] %}{% endfor %}{% set usesAll = stridedAxisUses is not defined %}{% set usesElementOffset = usesAll or "element_offset" in stridedAxisUses %}40 unmodified linesreturn outer * INNER_SIZE_SAFE + inner;}{%- endif -%}{% if stage == "max" %}// max(1u,..) so an empty strided tensor (INNER_SIZE 0) still compiles — the kernel// returns before any divide (VEC4_ROWS 0 -> guard), this only avoids a const `/0`.const INNER4: u32 = max(1u, INNER_SIZE / 4u); // vec4 groups of inner positions per outer8 unmodified lines{% endif %}var<workgroup> partial: array<vec4<f32>, WGS>;{% set reduce_fn = "reduce_max_vec4" if stage == "max" else "reduce_add_vec4" %}fn {{ reduce_fn }}(value: vec4<f32>, tid: u32) -> vec4<f32> {partial[tid] = value;workgroupBarrier();var stride: u32 = WGS / 2u;loop {if (stride == 0u) { break; }{% if stage == "max" %}if (tid < stride) { partial[tid] = max(partial[tid], partial[tid + stride]); }{% else %}if (tid < stride) { partial[tid] = partial[tid] + partial[tid + stride]; }5 unmodified lines}@compute @workgroup_size(WGS)fn main(@builtin(workgroup_id) wg: vec3<u32>, @builtin(local_invocation_id) lid: vec3<u32>) {let rg = wg.x + wg.y * {{ DISPATCH_FOLD_WIDTH }}u; // vec4-row-group indexif (rg >= VEC4_ROWS) { return; }let outer = rg / INNER4;let inner_group = rg % INNER4;{% if stage == "max" %}// vec4 index of element k=0 for this group (offset is a multiple of 4 since// INNER_SIZE % 4 == 0 and inner_group*4 is too).{% endif %}let base4 = (outer * REDUCE_SIZE * INNER_SIZE + inner_group * 4u) / 4u;{% if stage == "max" %}var acc = vec4<f32>(-3.4028234663852886e38);for (var k = lid.x; k < REDUCE_SIZE; k = k + WGS) {acc = max(acc, x[base4 + k * STRIDE4]);3 unmodified lines{% else %}let m = rowMax[rg];// +Inf row max -> NaN row (ONNX). Derive the quiet NaN per-component from the// bits of m (a constant NaN pattern is rejected at const-eval); m - m folds// to 0 for finite m so the exp arg stays correct on the non-Inf lanes.let nanv = bitcast<vec4<f32>>(bitcast<vec4<u32>>(m) | vec4<u32>(0x7fc00000u));let isInf = m > vec4<f32>(3.4028234663852886e38);
6 unmodified lines78910111213141516171819202122232476 unmodified lines1011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441458 unmodified lines1541551561571581591606 unmodified lines{{ env.wgsl.resourceDeclarations }}const WGS: u32 = {{ tunables.WORKGROUP_SIZE }}u;{% if source.strided %}{% set stridedAxisUses = ["STRIDED_ROWS", "element_offset"] %}// Compiled indexing for row-wise reductions over a non-last axis. A row is one// slice along the reduction axis, indexed as outer * INNER_SIZE + inner.{% set reduce_size = source.xShape[source.axis] %}{% set inner_size = namespace(value=1) %}{% for i in range(source.axis + 1, source.xShape | length) %}{% set inner_size.value = inner_size.value * source.xShape[i] %}{% endfor %}{% set outer_size = namespace(value=1) %}{% for i in range(source.axis) %}{% set outer_size.value = outer_size.value * source.xShape[i] %}{% endfor %}{% set usesAll = stridedAxisUses is not defined %}{% set usesElementOffset = usesAll or "element_offset" in stridedAxisUses %}76 unmodified lines{% endmacro %}var<workgroup> partial: array<f32, WGS>;{% if source.stage == "max" %}{{ wgsl_tree_reduce_f32("reduce_max_f32", "max", "partial", "WGS") }}{% else %}{{ wgsl_tree_reduce_f32("reduce_add_f32", "add", "partial", "WGS") }}{% endif %}{% set count = "REDUCE_SIZE" if source.strided else "params.cols" %}{% set offset_of = "element_offset(row, k)" if source.strided else "row * params.cols + k" %}@compute @workgroup_size(WGS)fn main(@builtin(workgroup_id) wg: vec3<u32>, @builtin(local_invocation_id) lid: vec3<u32>,@builtin(num_workgroups) nwg: vec3<u32>) {{% if source.strided %}// Strided mode has no `params` uniform (offsets come from compile-time// constants), so it folds against the compile-time STRIDED_ROWS instead of// params.rows. wg.y carries the high bits of the row past the maxComputeWorkgroupsPerDimension limit;{% if source.stage == "max" %}// the guard drops the over-dispatched tail before any rowMax[row] store.{% else %}// the guard drops the over-dispatched tail before any rowSum[row]/y[offset]// store.{% endif %}let row = wg.x + wg.y * nwg.x;if (row >= STRIDED_ROWS) { return; }{% else %}// 2D-folded row index: wg.y carries the high bits past the maxComputeWorkgroupsPerDimension{% if source.stage == "max" %}// workgroup-per-dimension dispatch limit (rows > maxComputeWorkgroupsPerDimension). The guard returns// the whole over-dispatched workgroup before any read/write — without it the// clamped OOB rowMax[row] store would corrupt the last real row. wg.x/wg.y/{% else %}// workgroup-per-dimension dispatch limit (rows > maxComputeWorkgroupsPerDimension). Return the whole// over-dispatched workgroup before any read/write — without it the clamped// OOB rowSum[row]/y[offset] stores would corrupt the last real row. wg.x/wg.y/{% endif %}// nwg.x are workgroup-uniform, so the return cannot diverge across a barrier.let row = wg.x + wg.y * nwg.x;if (row >= params.rows) { return; }{% endif %}{% if source.stage == "max" %}var acc = -3.4028234663852886e38;for (var k = lid.x; k < {{ count }}; k = k + WGS) {acc = max(acc, f32(x[{{ offset_of }}]));8 unmodified lines// +Inf row max must yield NaN (ONNX semantics). `m - m` (Inf - Inf) is// folded to 0 by fast-math backends, and a constant NaN bit pattern is// rejected at WGSL const-evaluation — so derive the quiet NaN from the// runtime value (any bits | 0x7fc00000 is a NaN).let e = select(exp(f32(x[offset]) - m), bitcast<f32>(bitcast<u32>(m) | 0x7fc00000u), m > 3.4028234663852886e38);y[offset] = {{ T }}(e);acc = acc + e;6 unmodified lines78910111213141516171819202122232476 unmodified lines1011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371388 unmodified lines1471481491501511521536 unmodified lines{{ env.wgsl.resourceDeclarations }}const WGS: u32 = {{ tunables.WORKGROUP_SIZE }}u;{% if strided %}{% set stridedAxisUses = ["STRIDED_ROWS", "element_offset"] %}// Compiled indexing for row-wise reductions over a non-last axis. A row is one// slice along the reduction axis, indexed as outer * INNER_SIZE + inner.{% set reduce_size = xShape[axisSpec] %}{% set inner_size = namespace(value=1) %}{% for i in range(axisSpec + 1, xShape | length) %}{% set inner_size.value = inner_size.value * xShape[i] %}{% endfor %}{% set outer_size = namespace(value=1) %}{% for i in range(axisSpec) %}{% set outer_size.value = outer_size.value * xShape[i] %}{% endfor %}{% set usesAll = stridedAxisUses is not defined %}{% set usesElementOffset = usesAll or "element_offset" in stridedAxisUses %}76 unmodified lines{% endmacro %}var<workgroup> partial: array<f32, WGS>;{% if stage == "max" %}{{ wgsl_tree_reduce_f32("reduce_max_f32", "max", "partial", "WGS") }}{% else %}{{ wgsl_tree_reduce_f32("reduce_add_f32", "add", "partial", "WGS") }}{% endif %}{% set count = "REDUCE_SIZE" if strided else "params.cols" %}{% set offset_of = "element_offset(row, k)" if strided else "row * params.cols + k" %}@compute @workgroup_size(WGS)fn main(@builtin(workgroup_id) wg: vec3<u32>, @builtin(local_invocation_id) lid: vec3<u32>) {{% if strided %}// Strided mode has no `params` uniform (offsets come from compile-time// constants), so it folds against the compile-time STRIDED_ROWS instead of// params.rows. wg.y carries the high bits of the row past the per-axis dispatch fold width;{% if stage == "max" %}// the guard drops the over-dispatched tail before any rowMax[row] store.{% else %}// the guard drops the over-dispatched tail before any rowSum[row]/y[offset]// store.{% endif %}let row = wg.x + wg.y * {{ DISPATCH_FOLD_WIDTH }}u;if (row >= STRIDED_ROWS) { return; }{% else %}// 2D-folded row index: wg.y carries the high bits once the row count passes the// per-axis dispatch fold width. The guard returns the whole over-dispatched// workgroup before any read or write — without it this stage's clamped OOB store// would corrupt the last real row. wg.x and wg.y are workgroup-uniform, so the// return cannot diverge across a barrier.let row = wg.x + wg.y * {{ DISPATCH_FOLD_WIDTH }}u;if (row >= params.rows) { return; }{% endif %}{% if stage == "max" %}var acc = -3.4028234663852886e38;for (var k = lid.x; k < {{ count }}; k = k + WGS) {acc = max(acc, f32(x[{{ offset_of }}]));8 unmodified lines// +Inf row max must yield NaN (ONNX semantics). `m - m` (Inf - Inf) is// folded to 0 by fast-math backends, and a constant NaN bit pattern is// rejected at WGSL const-evaluation — so derive the quiet NaN from the// bits of m (any bits | 0x7fc00000 is a NaN).let e = select(exp(f32(x[offset]) - m), bitcast<f32>(bitcast<u32>(m) | 0x7fc00000u), m > 3.4028234663852886e38);y[offset] = {{ T }}(e);acc = acc + e;
1234567891011122 unmodified lines151617181920212223242526272864 unmodified lines939495969798991001011021031041051061071081091101111121131141151161171181191201211228 unmodified lines131132133134135136137138139140141142// Cooperative online softmax/log-softmax for a non-last reduction axis. A// workgroup owns TILE_COLS consecutive (outer, inner) rows and splits the// reduction walk across AXIS_LANES invocations per row, so short-row shapes// still fill the machine and every load stays coalesced across the column// lanes regardless of whether the inner extent divides four. Per-lane online// partials merge in workgroup memory with the same update form as the serial// walk, so NaN and +Inf rows reproduce the single-lane kernel's outputs.{% set operation = source.op if source.op is defined else "softmax" %}{% set tileCols = source.tileCols %}{% set axisLanes = (256 / tileCols) | int %}{% if T == "f16" %}enable f16;2 unmodified lines{% set stridedAxisUses = ["STRIDED_ROWS", "element_offset"] %}// Compiled indexing for row-wise reductions over a non-last axis. A row is one// slice along the reduction axis, indexed as outer * INNER_SIZE + inner.{% set reduce_size = source.xShape[source.axis] %}{% set inner_size = namespace(value=1) %}{% for i in range(source.axis + 1, source.xShape | length) %}{% set inner_size.value = inner_size.value * source.xShape[i] %}{% endfor %}{% set outer_size = namespace(value=1) %}{% for i in range(source.axis) %}{% set outer_size.value = outer_size.value * source.xShape[i] %}{% endfor %}{% set usesAll = stridedAxisUses is not defined %}{% set usesElementOffset = usesAll or "element_offset" in stridedAxisUses %}64 unmodified linesconst AXIS_LANES: u32 = {{ axisLanes }}u;{% set negInit = "-FLT_MAX" if operation == "logsoftmax" else "-F32_MAX" %}var<workgroup> part_max: array<f32, TILE_COLS * AXIS_LANES>;var<workgroup> part_sum: array<f32, TILE_COLS * AXIS_LANES>;@compute @workgroup_size(TILE_COLS, AXIS_LANES, 1)fn main(@builtin(workgroup_id) wg: vec3<u32>,@builtin(num_workgroups) nwg: vec3<u32>,@builtin(local_invocation_id) lid: vec3<u32>) {let tile = wg.x + wg.y * nwg.x;let row = tile * TILE_COLS + lid.x;let row_live = row < STRIDED_ROWS;var lane_max = {{ negInit }};var lane_sum = 0.0;if (row_live) {for (var k = lid.y; k < REDUCE_SIZE; k += AXIS_LANES) {let value = f32(x[element_offset(row, k)]);if (value > lane_max) {lane_sum = lane_sum * exp(lane_max - value) + 1.0;lane_max = value;} else {lane_sum += exp(value - lane_max);}}}part_max[lid.y * TILE_COLS + lid.x] = lane_max;part_sum[lid.y * TILE_COLS + lid.x] = lane_sum;workgroupBarrier();8 unmodified linesfor (var t = 1u; t < AXIS_LANES; t += 1u) {let m2 = part_max[t * TILE_COLS + lid.x];let s2 = part_sum[t * TILE_COLS + lid.x];if (m2 > merged_max) {merged_sum = merged_sum * exp(merged_max - m2) + s2;merged_max = m2;} else {merged_sum += s2 * exp(m2 - merged_max);}}part_max[lid.x] = merged_max;part_sum[lid.x] = merged_sum;1234567891011122 unmodified lines151617181920212223242526272864 unmodified lines939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611628 unmodified lines171172173174175176177// Cooperative online softmax/log-softmax for a non-last reduction axis. A// workgroup owns TILE_COLS consecutive (outer, inner) rows and splits the// reduction walk across AXIS_LANES invocations per row. Column lanes access// consecutive addresses even when the inner extent is not divisible by four.// Each invocation maintains the manifest-selected number of independent// online streams. Their partials and the per-lane partials merge in workgroup memory with the same update form as the serial// walk, so NaN and +Inf rows reproduce the single-lane kernel's outputs.{% set operation = op if op is defined else "softmax" %}{% set tileCols = tileCols %}{% set axisLanes = (256 / tileCols) | int %}{% if T == "f16" %}enable f16;2 unmodified lines{% set stridedAxisUses = ["STRIDED_ROWS", "element_offset"] %}// Compiled indexing for row-wise reductions over a non-last axis. A row is one// slice along the reduction axis, indexed as outer * INNER_SIZE + inner.{% set reduce_size = xShape[axisSpec] %}{% set inner_size = namespace(value=1) %}{% for i in range(axisSpec + 1, xShape | length) %}{% set inner_size.value = inner_size.value * xShape[i] %}{% endfor %}{% set outer_size = namespace(value=1) %}{% for i in range(axisSpec) %}{% set outer_size.value = outer_size.value * xShape[i] %}{% endfor %}{% set usesAll = stridedAxisUses is not defined %}{% set usesElementOffset = usesAll or "element_offset" in stridedAxisUses %}64 unmodified linesconst AXIS_LANES: u32 = {{ axisLanes }}u;{% set negInit = "-FLT_MAX" if operation == "logsoftmax" else "-F32_MAX" %}{% macro update_partial(maxName, sumName, valueName, sumValue) %}if ({{ valueName }} > {{ maxName }}) {{{ sumName }} = {{ sumName }} * exp({{ maxName }} - {{ valueName }}) + {{ sumValue }};{{ maxName }} = {{ valueName }};} else {{% if sumValue == "1.0" %}{{ sumName }} += exp({{ valueName }} - {{ maxName }});{% else %}{{ sumName }} += {{ sumValue }} * exp({{ valueName }} - {{ maxName }});{% endif %}}{% endmacro %}var<workgroup> part_max: array<f32, TILE_COLS * AXIS_LANES>;var<workgroup> part_sum: array<f32, TILE_COLS * AXIS_LANES>;@compute @workgroup_size(TILE_COLS, AXIS_LANES, 1)fn main(@builtin(workgroup_id) wg: vec3<u32>,@builtin(local_invocation_id) lid: vec3<u32>) {let tile = wg.x + wg.y * {{ DISPATCH_FOLD_WIDTH }}u;let row = tile * TILE_COLS + lid.x;let row_live = row < STRIDED_ROWS;{% if onlineStreams == 1 %}var lane_max = {{ negInit }};var lane_sum = 0.0;if (row_live) {for (var k = lid.y; k < REDUCE_SIZE; k += AXIS_LANES) {let value = f32(x[element_offset(row, k)]);{{ update_partial("lane_max", "lane_sum", "value", "1.0") }}}}{% else %}{% set streamCount = onlineStreams %}// Independent online streams expose several exp/accumulate dependency// chains per invocation while preserving the existing axis-lane partition.{% for stream in range(streamCount) %}var stream_max_{{ stream }} = {{ negInit }};var stream_sum_{{ stream }} = 0.0;{% endfor %}if (row_live) {for (var base_k = lid.y; base_k < REDUCE_SIZE; base_k += AXIS_LANES * {{ streamCount }}u) {{% for stream in range(streamCount) %}{let k = base_k + {{ stream }}u * AXIS_LANES;{% if xShape[axisSpec] % (axisLanes * streamCount) != 0 %}if (k < REDUCE_SIZE) {{% endif %}let value = f32(x[element_offset(row, k)]);{{ update_partial("stream_max_" ~ stream, "stream_sum_" ~ stream, "value", "1.0") }}{% if xShape[axisSpec] % (axisLanes * streamCount) != 0 %}}{% endif %}}{% endfor %}}}var lane_max = stream_max_0;var lane_sum = stream_sum_0;{% for stream in range(1, streamCount) %}{{ update_partial("lane_max", "lane_sum", "stream_max_" ~ stream, "stream_sum_" ~ stream) }}{% endfor %}{% endif %}part_max[lid.y * TILE_COLS + lid.x] = lane_max;part_sum[lid.y * TILE_COLS + lid.x] = lane_sum;workgroupBarrier();8 unmodified linesfor (var t = 1u; t < AXIS_LANES; t += 1u) {let m2 = part_max[t * TILE_COLS + lid.x];let s2 = part_sum[t * TILE_COLS + lid.x];{{ update_partial("merged_max", "merged_sum", "m2", "s2") }}}part_max[lid.x] = merged_max;part_sum[lid.x] = merged_sum;
8 unmodified lines910111213141516171819202122113 unmodified lines1361371381391401411421431441458 unmodified lines{% set stridedAxisUses = ["REDUCE_SIZE", "INNER_SIZE", "STRIDED_ROWS", "INNER_SIZE_SAFE"] %}// Compiled indexing for row-wise reductions over a non-last axis. A row is one// slice along the reduction axis, indexed as outer * INNER_SIZE + inner.{% set reduce_size = source.xShape[source.axis] %}{% set inner_size = namespace(value=1) %}{% for i in range(source.axis + 1, source.xShape | length) %}{% set inner_size.value = inner_size.value * source.xShape[i] %}{% endfor %}{% set outer_size = namespace(value=1) %}{% for i in range(source.axis) %}{% set outer_size.value = outer_size.value * source.xShape[i] %}{% endfor %}{% set usesAll = stridedAxisUses is not defined %}{% set usesElementOffset = usesAll or "element_offset" in stridedAxisUses %}113 unmodified lines@compute @workgroup_size(WGS)fn main(@builtin(workgroup_id) wg: vec3<u32>,@builtin(local_invocation_id) lid: vec3<u32>,@builtin(num_workgroups) nwg: vec3<u32>) {let group = wg.x + wg.y * nwg.x;if (group >= PACKED_ROWS) {return;}8 unmodified lines910111213141516171819202122113 unmodified lines1361371381391401411421431448 unmodified lines{% set stridedAxisUses = ["REDUCE_SIZE", "INNER_SIZE", "STRIDED_ROWS", "INNER_SIZE_SAFE"] %}// Compiled indexing for row-wise reductions over a non-last axis. A row is one// slice along the reduction axis, indexed as outer * INNER_SIZE + inner.{% set reduce_size = xShape[axisSpec] %}{% set inner_size = namespace(value=1) %}{% for i in range(axisSpec + 1, xShape | length) %}{% set inner_size.value = inner_size.value * xShape[i] %}{% endfor %}{% set outer_size = namespace(value=1) %}{% for i in range(axisSpec) %}{% set outer_size.value = outer_size.value * xShape[i] %}{% endfor %}{% set usesAll = stridedAxisUses is not defined %}{% set usesElementOffset = usesAll or "element_offset" in stridedAxisUses %}113 unmodified lines@compute @workgroup_size(WGS)fn main(@builtin(workgroup_id) wg: vec3<u32>,@builtin(local_invocation_id) lid: vec3<u32>) {let group = wg.x + wg.y * {{ DISPATCH_FOLD_WIDTH }}u;if (group >= PACKED_ROWS) {return;}
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121enable subgroups;{{ env.wgsl.resourceDeclarations }}
// Subgroup-per-row online normalization over a contiguous last axis of// moderate width. One SUBGROUP owns each row and a workgroup carries as many// rows as it has subgroups, so the (max, denom) merge is one pair of subgroup// collectives: no workgroup memory, no barriers. Each lane keeps its vec4 words// in registers between the statistics sweep and the normalizing store, so the// row is read from memory once. Each lane forms an online (maximum,// denominator) pair, and subgroup collectives merge those pairs.const WG: u32 = {{ workgroupSize }}u;// FLT_MAX, not -inf, as the online (m, d) accumulator init: merges must keep// `m - m` finite so an empty lane / all--inf row contributes the exact// accumulator identity (m, d) = (-FLT_MAX, 0). Operator epilogues interpret// a zero final denominator according to their public semantics. Using -inf// here changes +inf-row behavior.const FLT_MAX: f32 = 3.4028234663852886e38;
fn is_finite_f32(value: f32) -> bool { return select(false, value <= FLT_MAX, value >= -FLT_MAX);}
// x - m that is exactly 0 when x equals a finite m, so exp(shifted) == 1// exactly at the row max. `x - x` on an infinite max is a legal fast-math// fold to 0, which would silently turn +inf rows finite — the explicit// equality test keeps the NaN propagation of the serial kernels.fn shifted_value(value: f32, maxValue: f32) -> f32 { let equalFiniteMax = select(false, value == maxValue, is_finite_f32(maxValue)); return select(value - maxValue, 0.0, equalFiniteMax);}fn exp_shift(value: f32, maxValue: f32) -> f32 { return exp(shifted_value(value, maxValue));}// Bit-exact NaN test: `v != v` can be folded to false by fast-math backends,// and a constant NaN bit pattern is rejected at WGSL const-evaluation.fn is_nan_f32(value: f32) -> bool { let bits = bitcast<u32>(value); return (bits & 0x7f800000u) == 0x7f800000u && (bits & 0x007fffffu) != 0u;}
var<workgroup> sgLaneClaims: atomic<u32>;
struct SubgroupLogicalLanes { ltid: u32, ord: u32, rank: u32, count: u32,}
fn subgroup_logical_lanes() -> SubgroupLogicalLanes { let rank = subgroupExclusiveAdd(1u); let count = subgroupAdd(1u); // Every lane performs the atomic so no collective follows a lane guard (a // subgroup op after a closed `if (rank == 0u)` block is the reconvergence // hazard the render gate flags): only the rank-0 lane adds its subgroup's // claim, every other lane adds 0 and discards its snapshot. The rank-0 lane is // the lowest active lane, which is the lane `subgroupBroadcastFirst` reads. let ticket = atomicAdd(&sgLaneClaims, select(0u, count | (1u << 16u), rank == 0u)); let claim = subgroupBroadcastFirst(ticket); return SubgroupLogicalLanes((claim & 0xffffu) + rank, claim >> 16u, rank, count);}
@compute @workgroup_size({{ workgroupSize }})fn main(@builtin(workgroup_id) wid: vec3<u32>, @builtin(subgroup_size) sgSize: u32) { // Rows tile the folded workgroup grid; the lanes of one subgroup share a row. // Which subgroup owns which row, and which lane holds which columns, come from // the logical lane coordinates, so no assumption is made about which // invocations share a subgroup. let L = subgroup_logical_lanes(); let sgLane = L.rank; let rowsPerWorkgroup = WG / sgSize; let row = (wid.x + wid.y * {{ DISPATCH_FOLD_WIDTH }}u) * rowsPerWorkgroup + L.ord; // A subgroup past the last row runs the collectives on an empty row and // stores nothing, so every collective stays in uniform control flow. let rowValid = row < params.rows; let vecLimit = select(0u, params.vecCols, rowValid); let rowBase = row * params.vecCols;
// Lane-local online (m, d) over the lane's strided words; f32 accumulation. var m = -FLT_MAX; var d = 0.0;{% for i in range(vecsPerLane) %} var v{{ i }} = vec4<f32>(0.0); let c{{ i }} = sgLane + {{ i }}u * sgSize; if (c{{ i }} < vecLimit) { v{{ i }} = vec4<f32>(x[rowBase + c{{ i }}]); let mNew{{ i }} = max(m, max(max(v{{ i }}.x, v{{ i }}.y), max(v{{ i }}.z, v{{ i }}.w))); d = d * exp_shift(m, mNew{{ i }}) + exp_shift(v{{ i }}.x, mNew{{ i }}) + exp_shift(v{{ i }}.y, mNew{{ i }}) + exp_shift(v{{ i }}.z, mNew{{ i }}) + exp_shift(v{{ i }}.w, mNew{{ i }}); m = mNew{{ i }}; }{% endfor %}
// Subgroup merge: a lane with no words contributes d == 0 (exact identity). let finalM = subgroupMax(m); let finalD = subgroupAdd(d * exp_shift(m, finalM));
// Runtime-derived quiet NaN and bit-exact NaN test. let dBits = bitcast<u32>(finalD); let rowIsNan = finalM > FLT_MAX || is_nan_f32(finalD) || finalD == 0.0; let nanOut = bitcast<f32>(dBits | 0x7fc00000u);
// (x - m) - log(d): x == m gives exactly 0 - log(d). let logD = log(finalD);{% for i in range(vecsPerLane) %} if (c{{ i }} < vecLimit) { var o{{ i }} = vec4<f32>( shifted_value(v{{ i }}.x, finalM), shifted_value(v{{ i }}.y, finalM), shifted_value(v{{ i }}.z, finalM), shifted_value(v{{ i }}.w, finalM)) - logD; if (rowIsNan) { o{{ i }} = vec4<f32>(nanOut); } y[rowBase + c{{ i }}] = vec4<{{ scalar }}>(o{{ i }}); }{% endfor %}}1234517 unmodified lines2324252627282959 unmodified lines899091929394955 unmodified lines10110210310410510668 unmodified lines17517617717817918018115 unmodified lines19719819920020120220347 unmodified lines251252253254255256257258259260261262263264265266267281 unmodified lines54955055155255355455587 unmodified lines64364464564664764864965065165265365437 unmodified lines69269369469569669769816 unmodified lines715716717718719720{"op": "ai.onnx.LogSoftmax","fixtureArrays": {"ort_seed_123_input_x": [1.0856307, 0.99734545, 0.2829785, 1.5062947, 0.5786002, 1.6514366, 2.4266791, 0.42891264, 1.2659363, 0.8667404, 0.6788862, 0.09470897, 1.4913896, 0.638902, 0.44398195, 0.43435127, 2.20593, 2.1867862, 1.004054, 0.3861864, 0.7373686, 1.4907321, 0.9358339, 1.175829, 1.2538806, 0.6377515, 0.9071052, 1.4286807, 0.14006872, 0.8617549, 0.25561938, 2.798589, 1.7715331, 0.69987726, 0.92746246, 0.17363568, 0.002845916, 0.6882227, 0.87953633, 0.28362733, 0.8053665, 1.7276695, 0.3908998, 0.57380587, 0.33858904, 0.011830495, 2.3923652, 0.41291216, 0.978736, 2.2381434, 1.2940853, 1.0387882, 1.7437122, 0.79806274, 0.02968323, 1.0693159, 0.8907064, 1.7548862, 1.4956441, 1.0693927],"onnx_backend_logsoftmax_input_x": [1.764052391052246, 0.40015721321105957, 0.978738009929657, 2.2408931255340576, 1.8675580024719238, 0.9772778749465942, 0.9500884413719177, 0.15135720372200012, 0.10321885347366333, 0.4105985164642334, 0.14404356479644775, 1.4542734622955322, 0.7610377073287964, 0.12167501449584961, 0.44386324286460876, 0.3336743414402008, 1.4940791130065918, 0.2051582634449005, 0.3130677044391632, 0.8540957570075989, 2.5529897212982178, 0.653618574142456, 0.8644362092018127, 0.7421650290489197, 2.269754648208618, 1.4543657302856445, 0.04575851559638977, 0.18718385696411133, 1.5327792167663574, 1.4693588018417358, 0.154947429895401, 0.37816253304481506, 0.8877857327461243, 1.980796456336975, 0.34791216254234314, 0.15634897351264954, 1.2302906513214111, 1.202379822731018, 0.38732680678367615, 0.302302747964859, 1.0485529899597168, 1.420017957687378, 1.7062702178955078, 1.950775384902954, 0.5096521973609924, 0.4380742907524109, 1.2527953386306763, 0.7774903774261475, 1.6138978004455566, 0.21274028718471527, 0.8954665660858154, 0.38690251111984253, 0.5108051300048828, 1.18063223361969, 0.02818222902715206, 0.4283318817615509, 0.06651721894741058, 0.30247190594673157, 0.6343221068382263, 0.3627411723136902]17 unmodified lines{"name": "strided_capacity_large_axis_tail_boundary","provenance": {"notes": "Compact correctness sibling for the large-inner selector crossover. The case-local threshold selects the capacity path while axis length 2048 and inner=6 retain the production gate and non-multiple-of-four tail."},"tunables": { "STRIDED_CAPACITY_MIN_ROWS": 1 },"attrs": { "axis": 1 },59 unmodified lines{"name": "many_short_rows_axis1_64x32","provenance": {"notes": "Compact correctness sibling for many-short-row LogSoftmax benchmarking; keeps the reduced axis short without making the correctness suite benchmark-sized."},"attrs": { "axis": 1 },"inputs": {5 unmodified lines},"outputs": { "y": { "dtype": "float32", "shape": [64, 32], "tolerance": 0.00001, "relTolerance": 0.00001 } }},{"name": "ort_simple_axis1","provenance": {68 unmodified lines"x": {"dtype": "float32","shape": [2, 4],"data": { "kind": "values", "values": ["Infinity", 1.0, 2.0, -3.0, "Infinity", "Infinity", 5.0, 5.0] }}},"outputs": { "y": { "dtype": "float32", "shape": [2, 4], "tolerance": 0.000001, "allowNaN": true } }15 unmodified lines"provenance": {"source": "onnxruntime/test/providers/cpu/math/softmax_test.cc","test": "SoftmaxOperator.DimWithZero","notes": "LogSoftmax analogue of ORT's zero-dimension Softmax coverage; the output is empty, so the framework plans the op as a no-op (zero dispatch) per ONNX zero-dimension semantics."},"attrs": { "axis": -1 },"inputs": { "x": { "dtype": "float32", "shape": [1, 0], "data": { "kind": "values", "values": [] } } },47 unmodified lines"provenance": {"source": "onnxruntime/test/providers/cpu/math/logsoftmax_test.cc","test": "LogSoftmaxOperator.ThreeDimsAxis0","notes": "Positive infinity must poison the whole reduction group even when the reduced axis is strided instead of contiguous."},"attrs": { "axis": 0 },"inputs": {"x": {"dtype": "float32","shape": [2, 2, 2],"data": { "kind": "values", "values": ["Infinity", 1.0, 2.0, "Infinity", 3.0, "Infinity", "Infinity", 4.0] }}},"outputs": { "y": { "dtype": "float32", "shape": [2, 2, 2], "tolerance": 0, "allowNaN": true } }},{"name": "rank6_last_axis",281 unmodified lines{"name": "dispatch_cliff_strided_rows_140000","provenance": {"notes": "Non-last (strided) axis log-softmax over 140000 outer rows (>65535) forces the folded one-workgroup-per-row dispatch in the strided_3pass reduce_max/exp_sum passes (shared with Softmax). Validates the wg.x + wg.y*nwg.x reconstruction guarded by the compile-time STRIDED_ROWS const. Before the 2D fold the plan-time dispatch-limit guard throws."},"attrs": { "axis": 1 },"inputs": {87 unmodified lines},{"name": "vec4_combine_positive_infinity_poisons_row_2x68","attrs": { "axis": -1 },"inputs": {"x": {"dtype": "float32","shape": [2, 68],"data": { "kind": "cycle", "values": ["Infinity", 0.25, -1.5, 2.0, 0.5, -0.75, 1.75, -2.25] }}},"outputs": { "y": { "dtype": "float32", "shape": [2, 68], "tolerance": 0.000001, "allowNaN": true } }37 unmodified lines{"name": "strided_rowmax_scratch_over_128mib_f16_capacity_fallback","provenance": {"notes": "Row-scratch capacity cliff: 33554433 strided rows need a 128 MiB+1 f32 rowMax buffer, so strided_3pass fails axisRowScratchFits and only the single-pass online fallback remains. f16 keeps the 64 MiB input inside the same spec-minimum storage-binding limit the f32 scratch overflows (and rejects the two f32-only strided routes), which is exactly the device situation the fallback exists for."},"attrs": { "axis": 0 },"inputs": {16 unmodified lines}},"outputs": { "y": { "dtype": "float32", "shape": [2, 1, 2, 1, 2, 1, 2, 3], "tolerance": 0.000001 } }}]}123417 unmodified lines2223242526272859 unmodified lines888990919293945 unmodified lines10010110210310410510610710810911011111211311411511611711811912068 unmodified lines18919019119219319419515 unmodified lines21121221321421521621747 unmodified lines265266267268269270271272273274275276277278279280281281 unmodified lines56356456556656756856987 unmodified lines65765865966066166266366466566666766866967067167267367437 unmodified lines71271371471571671771816 unmodified lines735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923{"fixtureArrays": {"ort_seed_123_input_x": [1.0856307, 0.99734545, 0.2829785, 1.5062947, 0.5786002, 1.6514366, 2.4266791, 0.42891264, 1.2659363, 0.8667404, 0.6788862, 0.09470897, 1.4913896, 0.638902, 0.44398195, 0.43435127, 2.20593, 2.1867862, 1.004054, 0.3861864, 0.7373686, 1.4907321, 0.9358339, 1.175829, 1.2538806, 0.6377515, 0.9071052, 1.4286807, 0.14006872, 0.8617549, 0.25561938, 2.798589, 1.7715331, 0.69987726, 0.92746246, 0.17363568, 0.002845916, 0.6882227, 0.87953633, 0.28362733, 0.8053665, 1.7276695, 0.3908998, 0.57380587, 0.33858904, 0.011830495, 2.3923652, 0.41291216, 0.978736, 2.2381434, 1.2940853, 1.0387882, 1.7437122, 0.79806274, 0.02968323, 1.0693159, 0.8907064, 1.7548862, 1.4956441, 1.0693927],"onnx_backend_logsoftmax_input_x": [1.764052391052246, 0.40015721321105957, 0.978738009929657, 2.2408931255340576, 1.8675580024719238, 0.9772778749465942, 0.9500884413719177, 0.15135720372200012, 0.10321885347366333, 0.4105985164642334, 0.14404356479644775, 1.4542734622955322, 0.7610377073287964, 0.12167501449584961, 0.44386324286460876, 0.3336743414402008, 1.4940791130065918, 0.2051582634449005, 0.3130677044391632, 0.8540957570075989, 2.5529897212982178, 0.653618574142456, 0.8644362092018127, 0.7421650290489197, 2.269754648208618, 1.4543657302856445, 0.04575851559638977, 0.18718385696411133, 1.5327792167663574, 1.4693588018417358, 0.154947429895401, 0.37816253304481506, 0.8877857327461243, 1.980796456336975, 0.34791216254234314, 0.15634897351264954, 1.2302906513214111, 1.202379822731018, 0.38732680678367615, 0.302302747964859, 1.0485529899597168, 1.420017957687378, 1.7062702178955078, 1.950775384902954, 0.5096521973609924, 0.4380742907524109, 1.2527953386306763, 0.7774903774261475, 1.6138978004455566, 0.21274028718471527, 0.8954665660858154, 0.38690251111984253, 0.5108051300048828, 1.18063223361969, 0.02818222902715206, 0.4283318817615509, 0.06651721894741058, 0.30247190594673157, 0.6343221068382263, 0.3627411723136902]17 unmodified lines{"name": "strided_capacity_large_axis_tail_boundary","provenance": {"notes": "At the large-inner crossover, axis length 2,048 and inner size 6 select the capacity path with a non-multiple-of-four tail."},"tunables": { "STRIDED_CAPACITY_MIN_ROWS": 1 },"attrs": { "axis": 1 },59 unmodified lines{"name": "many_short_rows_axis1_64x32","provenance": {"notes": "A compact collection of many 32-element rows exercises short-row LogSoftmax without benchmark-scale storage."},"attrs": { "axis": 1 },"inputs": {5 unmodified lines},"outputs": { "y": { "dtype": "float32", "shape": [64, 32], "tolerance": 0.00001, "relTolerance": 0.00001 } }},{"name": "many_rows_axis1_2048x32","provenance": {"notes": "Many 32-column rows exercise the packed-rows path below the 64-column subgroup-per-row threshold."},"attrs": { "axis": 1 },"inputs": {"x": {"dtype": "float32","shape": [2048, 32],"data": { "kind": "fillFloat32", "sinStep": 0.037, "cosStep": 0.019, "scale": 2.0 }}},"outputs": { "y": { "dtype": "float32", "shape": [2048, 32], "tolerance": 0.00001, "relTolerance": 0.00001 } }},{"name": "ort_simple_axis1","provenance": {68 unmodified lines"x": {"dtype": "float32","shape": [2, 4],"data": { "kind": "values", "values": ["Infinity", 1.0, 2.0, -3.0, 4.0, 1.0, 5.0, 2.0] }}},"outputs": { "y": { "dtype": "float32", "shape": [2, 4], "tolerance": 0.000001, "allowNaN": true } }15 unmodified lines"provenance": {"source": "onnxruntime/test/providers/cpu/math/softmax_test.cc","test": "SoftmaxOperator.DimWithZero","notes": "A zero-length dimension produces an empty output and therefore requires no GPU dispatch, consistent with ONNX zero-dimension semantics."},"attrs": { "axis": -1 },"inputs": { "x": { "dtype": "float32", "shape": [1, 0], "data": { "kind": "values", "values": [] } } },47 unmodified lines"provenance": {"source": "onnxruntime/test/providers/cpu/math/logsoftmax_test.cc","test": "LogSoftmaxOperator.ThreeDimsAxis0","notes": "Diverges from the upstream test's inputs (inputs.x values [\"Infinity\", 1.0, 2.0, \"Infinity\", 3.0, \"Infinity\", \"Infinity\", 4.0] -> values [\"Infinity\", 0.0, 2.0, \"Infinity\", 3.0, \"-Infinity\", \"Infinity\", 4.0]); the expected output is recomputed by the CPU reference for the new inputs. Positive infinity must poison the whole reduction group even when the reduced axis is strided instead of contiguous, while a group whose only non-finite member is negative infinity stays exact."},"attrs": { "axis": 0 },"inputs": {"x": {"dtype": "float32","shape": [2, 2, 2],"data": { "kind": "values", "values": ["Infinity", 0.0, 2.0, "Infinity", 3.0, "-Infinity", "Infinity", 4.0] }}},"outputs": { "y": { "dtype": "float32", "shape": [2, 2, 2], "tolerance": 0.000001, "allowNaN": true } }},{"name": "rank6_last_axis",281 unmodified lines{"name": "dispatch_cliff_strided_rows_140000","provenance": {"notes": "A strided-axis LogSoftmax over 140,000 rows requires a folded one-workgroup-per-row dispatch. Distinct rows make incorrect two-dimensional row reconstruction observable in both maximum and exponential-sum passes."},"attrs": { "axis": 1 },"inputs": {87 unmodified lines},{"name": "vec4_combine_positive_infinity_poisons_row_2x68","provenance": {"notes": "One positive infinity inside a vec4 group must poison every group of its own row through the vec4 combine, and must leave the neighbouring finite row untouched."},"attrs": { "axis": -1 },"inputs": {"x": {"dtype": "float32","shape": [2, 68],"data": {"kind": "values","values": [0.25, -1.5, 2.0, 0.5, -0.75, "Infinity", -2.25, 0.25, -1.5, 2.0, 0.5, -0.75, 1.75, -2.25, 0.25, -1.5, 2.0, 0.5, -0.75, 1.75, -2.25, 0.25, -1.5, 2.0, 0.5, -0.75, 1.75, -2.25, 0.25, -1.5, 2.0, 0.5, -0.75, 1.75, -2.25, 0.25, -1.5, 2.0, 0.5, -0.75, 1.75, -2.25, 0.25, -1.5, 2.0, 0.5, -0.75, 1.75, -2.25, 0.25, -1.5, 2.0, 0.5, -0.75, 1.75, -2.25, 0.25, -1.5, 2.0, 0.5, -0.75, 1.75, -2.25, 0.25, -1.5, 2.0, 0.5, -0.75, 0.5, -0.75, 1.75, -2.25, 0.25, -1.5, 2.0, 0.5, -0.75, 1.75, -2.25, 0.25, -1.5, 2.0, 0.5, -0.75, 1.75, -2.25, 0.25, -1.5, 2.0, 0.5, -0.75, 1.75, -2.25, 0.25, -1.5, 2.0, 0.5, -0.75, 1.75, -2.25, 0.25, -1.5, 2.0, 0.5, -0.75, 1.75, -2.25, 0.25, -1.5, 2.0, 0.5, -0.75, 1.75, -2.25, 0.25, -1.5, 2.0, 0.5, -0.75, 1.75, -2.25, 0.25, -1.5, 2.0, 0.5, -0.75, 1.75, -2.25, 0.25, -1.5, 2.0, 0.5, -0.75, 1.75, -2.25, 0.25]}}},"outputs": { "y": { "dtype": "float32", "shape": [2, 68], "tolerance": 0.000001, "allowNaN": true } }37 unmodified lines{"name": "strided_rowmax_scratch_over_128mib_f16_capacity_fallback","provenance": {"notes": "With 33,554,433 strided rows, a float32 row-maximum buffer would exceed 128 MiB. Float16 keeps the input within the minimum storage-binding limit and selects the single-pass online path without row scratch."},"attrs": { "axis": 0 },"inputs": {16 unmodified lines}},"outputs": { "y": { "dtype": "float32", "shape": [2, 1, 2, 1, 2, 1, 2, 3], "tolerance": 0.000001 } }},{"name": "subgroup_rows_f16_96x512","attrs": { "axis": -1 },"inputs": {"x": {"dtype": "float16","shape": [96, 512],"data": { "kind": "fillFloat32", "sinStep": 0.21, "cosStep": 0.09, "scale": 2.0 }}},"outputs": { "y": { "dtype": "float16", "shape": [96, 512], "tolerance": 0.01 } }},{"name": "subgroup_rows_f32_64x1024","attrs": { "axis": -1 },"inputs": {"x": {"dtype": "float32","shape": [64, 1024],"data": { "kind": "fillFloat32", "sinStep": 0.013, "cosStep": 0.029, "scale": 3.0 }}},"outputs": { "y": { "dtype": "float32", "shape": [64, 1024], "tolerance": 0.0001, "relTolerance": 0.0001 } }},{"name": "subgroup_rows_f32_65x64_tail_row","attrs": { "axis": -1 },"inputs": {"x": {"dtype": "float32","shape": [65, 64],"data": { "kind": "fillFloat32", "sinStep": 0.31, "cosStep": 0.11, "scale": 4.0 }}},"outputs": { "y": { "dtype": "float32", "shape": [65, 64], "tolerance": 0.0001, "relTolerance": 0.0001 } }},{"name": "packed_rows_scalar_lane_tail_2081x33","provenance": {"notes": "With 33 columns and 2,081 rows, the scalar packed-rows path has both a ragged lane tail and a short final row group, exercising the log-denominator epilogue on full and partial groups."},"attrs": { "axis": 1 },"inputs": {"x": {"dtype": "float32","shape": [2081, 33],"data": { "kind": "fillFloat32", "sinStep": 0.041, "cosStep": 0.023, "scale": 2.0 }}},"outputs": { "y": { "dtype": "float32", "shape": [2081, 33], "tolerance": 0.000001, "relTolerance": 0.000001 } }},{"name": "online_stream_axis31_f32","provenance": {"notes": "Exercises the per-lane stream-count boundary, reduction tail, or column tail. f16 comparison includes its storage rounding; existing fixtures and tolerances are unchanged."},"attrs": { "axis": 1 },"inputs": {"x": {"dtype": "float32","shape": [2, 31, 8],"data": { "kind": "fillFloat32", "sinStep": 0.017, "cosStep": 0.029, "scale": 4.0 }}},"outputs": { "y": { "dtype": "float32", "shape": [2, 31, 8], "tolerance": 0.00001, "relTolerance": 0.00001 } }},{"name": "online_stream_axis32_f32","provenance": {"notes": "Exercises the per-lane stream-count boundary, reduction tail, or column tail. f16 comparison includes its storage rounding; existing fixtures and tolerances are unchanged."},"attrs": { "axis": 1 },"inputs": {"x": {"dtype": "float32","shape": [2, 32, 8],"data": { "kind": "fillFloat32", "sinStep": 0.017, "cosStep": 0.029, "scale": 4.0 }}},"outputs": { "y": { "dtype": "float32", "shape": [2, 32, 8], "tolerance": 0.00001, "relTolerance": 0.00001 } }},{"name": "online_stream_axis33_f32","provenance": {"notes": "Exercises the per-lane stream-count boundary, reduction tail, or column tail. f16 comparison includes its storage rounding; existing fixtures and tolerances are unchanged."},"attrs": { "axis": 1 },"inputs": {"x": {"dtype": "float32","shape": [2, 33, 8],"data": { "kind": "fillFloat32", "sinStep": 0.017, "cosStep": 0.029, "scale": 4.0 }}},"outputs": { "y": { "dtype": "float32", "shape": [2, 33, 8], "tolerance": 0.00001, "relTolerance": 0.00001 } }},{"name": "online_stream_axis64_f32","provenance": {"notes": "Exercises the per-lane stream-count boundary, reduction tail, or column tail. f16 comparison includes its storage rounding; existing fixtures and tolerances are unchanged."},"attrs": { "axis": 1 },"inputs": {"x": {"dtype": "float32","shape": [2, 64, 8],"data": { "kind": "fillFloat32", "sinStep": 0.017, "cosStep": 0.029, "scale": 4.0 }}},"outputs": { "y": { "dtype": "float32", "shape": [2, 64, 8], "tolerance": 0.00001, "relTolerance": 0.00001 } }},{"name": "online_stream_axis65_f32","provenance": {"notes": "Exercises the per-lane stream-count boundary, reduction tail, or column tail. f16 comparison includes its storage rounding; existing fixtures and tolerances are unchanged."},"attrs": { "axis": 1 },"inputs": {"x": {"dtype": "float32","shape": [2, 65, 8],"data": { "kind": "fillFloat32", "sinStep": 0.017, "cosStep": 0.029, "scale": 4.0 }}},"outputs": { "y": { "dtype": "float32", "shape": [2, 65, 8], "tolerance": 0.00001, "relTolerance": 0.00001 } }},{"name": "online_stream_columns_tail_f32","provenance": {"notes": "Exercises the per-lane stream-count boundary, reduction tail, or column tail. f16 comparison includes its storage rounding; existing fixtures and tolerances are unchanged."},"attrs": { "axis": 1 },"inputs": {"x": {"dtype": "float32","shape": [129, 67, 130],"data": { "kind": "fillFloat32", "sinStep": 0.017, "cosStep": 0.029, "scale": 4.0 }}},"outputs": { "y": { "dtype": "float32", "shape": [129, 67, 130], "tolerance": 0.00001, "relTolerance": 0.00001 } }},{"name": "online_stream_nonfinite_f32","provenance": {"notes": "Mixes NaNs with large finite maxima across independent streams, alongside positive infinity, all-negative-infinity, and finite groups. The tail crosses both the stream period and the input recipe period."},"attrs": { "axis": 1 },"inputs": {"x": {"dtype": "float32","shape": [2, 67, 8],"data": {"kind": "cycle","values": ["NaN", 1.0, "-Infinity", "Infinity", 0.0, "NaN", 5.0, -1000.0, 0.0, 3.0, "-Infinity", 2.0, 5.0, -1000.0, "-Infinity", 0.0, 1000.0, 5.0, "-Infinity", 4.0, "NaN", 1000.0, 7.0, "-Infinity"]}}},"outputs": {"y": {"dtype": "float32","shape": [2, 67, 8],"tolerance": 0.00001,"relTolerance": 0.00001,"allowNaN": true}}},{"name": "online_stream_four_way_tail_f32","provenance": {"notes": "Exercises the per-lane stream-count boundary, reduction tail, or column tail. f16 comparison includes its storage rounding; existing fixtures and tolerances are unchanged."},"attrs": { "axis": 1 },"inputs": {"x": {"dtype": "float32","shape": [2, 129, 8],"data": { "kind": "fillFloat32", "sinStep": 0.017, "cosStep": 0.029, "scale": 4.0 }}},"outputs": { "y": { "dtype": "float32", "shape": [2, 129, 8], "tolerance": 0.00001, "relTolerance": 0.00001 } },"tunables": { "STRIDED_ONLINE_STREAMS": 4 }}]}
README.md+16-7
build/webgpu/bench.json+77-4
build/webgpu/manifest.json+308-355
build/webgpu/metadata.json+33-15
build/webgpu/softmax-longrow-normalize.wgsl.jinja+3-3
build/webgpu/softmax-longrow-stats.wgsl.jinja+29-35
build/webgpu/softmax-normalize.wgsl.jinja+14-17
build/webgpu/softmax-online-packed-rows.wgsl.jinja+40-8
build/webgpu/softmax-online.wgsl.jinja+37-51
build/webgpu/softmax-row-stage-strided-vec4.wgsl.jinja+13-14
build/webgpu/softmax-row-stage.wgsl.jinja+22-29
build/webgpu/softmax-strided-online-coop.wgsl.jinja+59-24
build/webgpu/softmax-strided-packed4-tail.wgsl.jinja+7-8
build/webgpu/softmax-subgroup-rows.wgsl.jinjaAdded+121
build/webgpu/test.json+214-11