sync 4385228f788d
Browse filesFiles changed (12)
- README.md+37-25
- build/webgpu/bench.json+159-53
- build/webgpu/manifest.json+1-530
- build/webgpu/metadata.json+1-44
- build/webgpu/softmax-normalize.wgsl.jinja+3-2
- build/webgpu/softmax-online.wgsl.jinja+43-12
- build/webgpu/softmax-row-stage-strided-vec4.wgsl.jinja+10-4
- build/webgpu/softmax-row-stage.wgsl.jinja+2-3
- build/webgpu/softmax-strided-online-coop.wgsl.jinja+41-13
- build/webgpu/softmax-strided-resident.wgsl.jinjaAdded+120
- build/webgpu/softmax-subgroup-rows.wgsl.jinja+46-24
- build/webgpu/test.json
17 unmodified lines1819202122232425262728293031329 unmodified lines4243444546474849505152535455565758596061626364656667686970717273747576777879808182838417 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 cases- [`softmax-longrow-normalize.wgsl.jinja`](build/webgpu/softmax-longrow-normalize.wgsl.jinja)- [`softmax-longrow-stats.wgsl.jinja`](build/webgpu/softmax-longrow-stats.wgsl.jinja)- [`softmax-normalize.wgsl.jinja`](build/webgpu/softmax-normalize.wgsl.jinja)- [`softmax-online-packed-rows.wgsl.jinja`](build/webgpu/softmax-online-packed-rows.wgsl.jinja)- [`softmax-online.wgsl.jinja`](build/webgpu/softmax-online.wgsl.jinja)- [`softmax-row-stage-strided-vec4.wgsl.jinja`](build/webgpu/softmax-row-stage-strided-vec4.wgsl.jinja)- [`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.3```Required output shapes and logical data types are inferred from the supplied inputs and attributes; result tensors are allocated automatically.The `version: 1` option selects the published kernel contract; it is independent of any operator opset, contrib `since_version`, or model version.It follows the `v1` branch as fixes land. To pin exact artifact bytes, pass a 40-character commit `revision` instead of `version`.Replace each `*Data` placeholder with a typed array containing the corresponding input data.```jsimport { getKernel } from "@huggingface/kernels";const kernel = await getKernel("webgpu-kernels/ai.onnx.LogSoftmax", { version: 1 });const { y } = await kernel({ x: { data: xData, shape: [1, 3] } });```17 unmodified lines1819202122232425262728293031329 unmodified lines4243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959617 unmodified lines## Inputs| Name | Logical dtype | Rank | Shape | Description | Presence || --- | --- | --- | --- | --- | --- || `input` | `T` | — | — | The input tensor of rank >= 1. | required |## Outputs| Name | Logical dtype | Rank | Shape | Description | Presence || --- | --- | --- | --- | --- | --- || `output` | `T` | same as `input` | same as `input` | The log-softmax values; same shape as the input. | required |## Attributes9 unmodified lines| --- | --- || `T` | `float32`, `float16` |## Implementation variantsOne implementation is selected per call from the device capabilities, the request shapes and the dtypes; these notes say what each one covers.- `ragged_resident` — Keeps one strided normalization slice per column of the workgroup in registers across both reductions.- `online_wg_scalar_vec4_tail` — Normalizes unaligned contiguous f32 rows with grouped-four arithmetic over guarded scalar storage; every load/store remains inside its logical row.## Device requirementsSome implementation variants require `subgroups`. Other variants run without it; which variant runs also depends on the request's shapes and dtypes.## Files- [`metadata.json`](https://huggingface.co/kernels/webgpu-kernels/ai.onnx.LogSoftmax/blob/v1/build/webgpu/metadata.json) — kernel metadata (id, file digests, manifest spec, provenance)- [`manifest.json`](https://huggingface.co/kernels/webgpu-kernels/ai.onnx.LogSoftmax/blob/v1/build/webgpu/manifest.json) — the op contract (source of truth)- [`test.json`](https://huggingface.co/kernels/webgpu-kernels/ai.onnx.LogSoftmax/blob/v1/build/webgpu/test.json) — correctness cases- [`bench.json`](https://huggingface.co/kernels/webgpu-kernels/ai.onnx.LogSoftmax/blob/v1/build/webgpu/bench.json) — benchmark cases- [`softmax-longrow-normalize.wgsl.jinja`](https://huggingface.co/kernels/webgpu-kernels/ai.onnx.LogSoftmax/blob/v1/build/webgpu/softmax-longrow-normalize.wgsl.jinja)- [`softmax-longrow-stats.wgsl.jinja`](https://huggingface.co/kernels/webgpu-kernels/ai.onnx.LogSoftmax/blob/v1/build/webgpu/softmax-longrow-stats.wgsl.jinja)- [`softmax-normalize.wgsl.jinja`](https://huggingface.co/kernels/webgpu-kernels/ai.onnx.LogSoftmax/blob/v1/build/webgpu/softmax-normalize.wgsl.jinja)- [`softmax-online-packed-rows.wgsl.jinja`](https://huggingface.co/kernels/webgpu-kernels/ai.onnx.LogSoftmax/blob/v1/build/webgpu/softmax-online-packed-rows.wgsl.jinja)- [`softmax-online.wgsl.jinja`](https://huggingface.co/kernels/webgpu-kernels/ai.onnx.LogSoftmax/blob/v1/build/webgpu/softmax-online.wgsl.jinja)- [`softmax-row-stage-strided-vec4.wgsl.jinja`](https://huggingface.co/kernels/webgpu-kernels/ai.onnx.LogSoftmax/blob/v1/build/webgpu/softmax-row-stage-strided-vec4.wgsl.jinja)- [`softmax-row-stage.wgsl.jinja`](https://huggingface.co/kernels/webgpu-kernels/ai.onnx.LogSoftmax/blob/v1/build/webgpu/softmax-row-stage.wgsl.jinja)- [`softmax-strided-online-coop.wgsl.jinja`](https://huggingface.co/kernels/webgpu-kernels/ai.onnx.LogSoftmax/blob/v1/build/webgpu/softmax-strided-online-coop.wgsl.jinja)- [`softmax-strided-packed4-tail.wgsl.jinja`](https://huggingface.co/kernels/webgpu-kernels/ai.onnx.LogSoftmax/blob/v1/build/webgpu/softmax-strided-packed4-tail.wgsl.jinja)- [`softmax-strided-resident.wgsl.jinja`](https://huggingface.co/kernels/webgpu-kernels/ai.onnx.LogSoftmax/blob/v1/build/webgpu/softmax-strided-resident.wgsl.jinja)- [`softmax-subgroup-rows.wgsl.jinja`](https://huggingface.co/kernels/webgpu-kernels/ai.onnx.LogSoftmax/blob/v1/build/webgpu/softmax-subgroup-rows.wgsl.jinja)## Use with `@huggingface/kernels````shnpm install --save-exact @huggingface/kernels@0.0.1-preview.4```Paste the example into a browser app that resolves npm imports. Serve the app over HTTPS or localhost with WebGPU available.Required output shapes and logical data types are inferred from the supplied inputs and attributes; result tensors are allocated automatically.The `version: 1` option selects the published kernel contract; it is independent of any operator opset, contrib `since_version`, or model version.It follows the `v1` branch as fixes land. To pin exact artifact bytes, pass a 40-character commit `revision` instead of `version`.```jsimport { getKernel } from "@huggingface/kernels";const kernel = await getKernel("webgpu-kernels/ai.onnx.LogSoftmax", { version: 1 });const inputData = Float32Array.of(-1, 0, 1);const { output } = await kernel({ input: { data: inputData, shape: [1, 3] } });console.log({ output });```
2 unmodified lines34567891011121314151617184 unmodified lines23242526272829301 unmodified line32333435363738391 unmodified line41424344454647483 unmodified lines52535455565758591 unmodified line61626364656667681 unmodified line70717273747576771 unmodified line79808182838485862 unmodified lines89909192939495968 unmodified lines1051061071081091101111129 unmodified lines1221231241251261271281296 unmodified lines1361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182 unmodified lines"cases": [{"name": "attention_scores","inputs": { "x": { "dtype": "float32", "shape": [32, 128] } },"outputs": { "y": { "dtype": "float32", "shape": [32, 128] } }},{"name": "logsoftmax-f32-1024x2048","preset": "smoke","vars": { "dtype": "float32", "rows": 1024, "cols": 2048 },"attrs": { "axis": 1 },"inputs": { "x": { "shape": [1024, 2048], "dtype": "float32", "dist": "normal", "seed": 211, "scale": 2 } },"outputs": { "y": { "shape": [1024, 2048], "dtype": "float32" } },"bench": {"primary": true,"metrics": [{ "type": "bandwidth", "value": "args.rows * args.cols * dtypeBytes(args.dtype) * 2" }]4 unmodified lines"preset": "stress","vars": { "dtype": "float32", "rows": 16384, "cols": 512 },"attrs": { "axis": 1 },"inputs": { "x": { "shape": [16384, 512], "dtype": "float32", "dist": "normal", "seed": 212, "scale": 2 } },"outputs": { "y": { "shape": [16384, 512], "dtype": "float32" } },"bench": { "metrics": [{ "type": "bandwidth", "value": "args.rows * args.cols * dtypeBytes(args.dtype) * 2" }] }},{1 unmodified line"preset": "model","vars": { "dtype": "float32", "rows": 1, "cols": 262144 },"attrs": { "axis": 1 },"inputs": { "x": { "shape": [1, 262144], "dtype": "float32", "dist": "normal", "seed": 213, "scale": 4 } },"outputs": { "y": { "shape": [1, 262144], "dtype": "float32" } },"bench": { "metrics": [{ "type": "bandwidth", "value": "args.rows * args.cols * dtypeBytes(args.dtype) * 2" }] }},{1 unmodified line"preset": "stress","vars": { "dtype": "float32", "rows": 64, "mid": 1024, "inner": 64 },"attrs": { "axis": 1 },"inputs": { "x": { "shape": [64, 1024, 64], "dtype": "float32", "dist": "normal", "seed": 311, "scale": 2 } },"outputs": { "y": { "shape": [64, 1024, 64], "dtype": "float32" } },"bench": {"metrics": [{ "type": "bandwidth", "value": "args.rows * args.mid * args.inner * dtypeBytes(args.dtype) * 2" }]}3 unmodified lines"preset": "stress","vars": { "dtype": "float16", "rows": 1024, "cols": 2048 },"attrs": { "axis": 1 },"inputs": { "x": { "shape": [1024, 2048], "dtype": "float16", "dist": "normal", "seed": 312, "scale": 2 } },"outputs": { "y": { "shape": [1024, 2048], "dtype": "float16" } },"bench": { "metrics": [{ "type": "bandwidth", "value": "args.rows * args.cols * dtypeBytes(args.dtype) * 2" }] }},{1 unmodified line"preset": "stress","vars": { "dtype": "float32", "rows": 1024, "cols": 2046 },"attrs": { "axis": 1 },"inputs": { "x": { "shape": [1024, 2046], "dtype": "float32", "dist": "normal", "seed": 313, "scale": 2 } },"outputs": { "y": { "shape": [1024, 2046], "dtype": "float32" } },"bench": { "metrics": [{ "type": "bandwidth", "value": "args.rows * args.cols * dtypeBytes(args.dtype) * 2" }] }},{1 unmodified line"preset": "model","vars": { "dtype": "float32", "rows": 70000, "cols": 2048 },"attrs": { "axis": 1 },"inputs": { "x": { "shape": [70000, 2048], "dtype": "float32", "dist": "normal", "seed": 314, "scale": 2 } },"outputs": { "y": { "shape": [70000, 2048], "dtype": "float32" } },"bench": { "metrics": [{ "type": "bandwidth", "value": "args.rows * args.cols * dtypeBytes(args.dtype) * 2" }] }},{1 unmodified line"preset": "stress","vars": { "dtype": "float32", "rows": 131072, "cols": 32 },"attrs": { "axis": 1 },"inputs": { "x": { "shape": [131072, 32], "dtype": "float32", "dist": "normal", "seed": 411, "scale": 2 } },"outputs": { "y": { "shape": [131072, 32], "dtype": "float32" } },"bench": { "metrics": [{ "type": "bandwidth", "value": "args.rows * args.cols * dtypeBytes(args.dtype) * 2" }] }},{2 unmodified lines"provenance": { "notes": "Measures LogSoftmax over 8,320 independent strided rows with an inner extent of 130." },"vars": { "dtype": "float32", "outer": 64, "axisDim": 2048, "inner": 130 },"attrs": { "axis": 1 },"inputs": { "x": { "shape": [64, 2048, 130], "dtype": "float32", "dist": "normal", "seed": 414, "scale": 2 } },"outputs": { "y": { "shape": [64, 2048, 130], "dtype": "float32", "dist": "empty" } },"bench": {"metrics": [{ "type": "bandwidth", "value": "args.outer * args.axisDim * args.inner * dtypeBytes(args.dtype) * 2" }8 unmodified lines},"vars": { "dtype": "float32", "outer": 96, "axisDim": 2048, "inner": 130 },"attrs": { "axis": 1 },"inputs": { "x": { "shape": [96, 2048, 130], "dtype": "float32", "dist": "normal", "seed": 413, "scale": 2 } },"outputs": { "y": { "shape": [96, 2048, 130], "dtype": "float32", "dist": "empty" } },"bench": {"metrics": [{ "type": "bandwidth", "value": "args.outer * args.axisDim * args.inner * dtypeBytes(args.dtype) * 2" }9 unmodified lines},"vars": { "dtype": "float32", "outer": 120, "axisDim": 2048, "inner": 130 },"attrs": { "axis": 1 },"inputs": { "x": { "shape": [120, 2048, 130], "dtype": "float32", "dist": "normal", "seed": 412, "scale": 2 } },"outputs": { "y": { "shape": [120, 2048, 130], "dtype": "float32", "dist": "empty" } },"bench": {"metrics": [{ "type": "bandwidth", "value": "args.outer * args.axisDim * args.inner * dtypeBytes(args.dtype) * 2" }6 unmodified lines"preset": "smoke","vars": { "dtype": "float32", "rows": 8192, "cols": 512 },"attrs": { "axis": 1 },"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": "Measures log-softmax over GPT-2's 50,257-token vocabulary width, which is not a multiple of four; its 50,260-wide sibling in this file is the nearest four-aligned control at nearly the same byte count."},"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": "The next multiple-of-four vocabulary width above the paired 50,257-column case, with nearly the same input bytes."},"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 }}]}2 unmodified lines34567891011121314151617184 unmodified lines23242526272829301 unmodified line32333435363738391 unmodified line41424344454647484950515253545556575859606162636465666768697071727374757677787980813 unmodified lines85868788899091921 unmodified line9495969798991001011 unmodified line1031041051061071081091101 unmodified line1121131141151161171181192 unmodified lines1221231241251261271281298 unmodified lines1381391401411421431441459 unmodified lines1551561571581591601611621631646 unmodified lines1711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233242 unmodified lines"cases": [{"name": "attention_scores","inputs": { "input": { "dtype": "float32", "shape": [32, 128] } },"outputs": { "output": { "dtype": "float32", "shape": [32, 128] } }},{"name": "logsoftmax-f32-1024x2048","preset": "smoke","vars": { "dtype": "float32", "rows": 1024, "cols": 2048 },"attrs": { "axis": 1 },"inputs": { "input": { "shape": [1024, 2048], "dtype": "float32", "dist": "normal", "seed": 211, "scale": 2 } },"outputs": { "output": { "shape": [1024, 2048], "dtype": "float32" } },"bench": {"primary": true,"metrics": [{ "type": "bandwidth", "value": "args.rows * args.cols * dtypeBytes(args.dtype) * 2" }]4 unmodified lines"preset": "stress","vars": { "dtype": "float32", "rows": 16384, "cols": 512 },"attrs": { "axis": 1 },"inputs": { "input": { "shape": [16384, 512], "dtype": "float32", "dist": "normal", "seed": 212, "scale": 2 } },"outputs": { "output": { "shape": [16384, 512], "dtype": "float32" } },"bench": { "metrics": [{ "type": "bandwidth", "value": "args.rows * args.cols * dtypeBytes(args.dtype) * 2" }] }},{1 unmodified line"preset": "model","vars": { "dtype": "float32", "rows": 1, "cols": 262144 },"attrs": { "axis": 1 },"inputs": { "input": { "shape": [1, 262144], "dtype": "float32", "dist": "normal", "seed": 213, "scale": 4 } },"outputs": { "output": { "shape": [1, 262144], "dtype": "float32" } },"bench": { "metrics": [{ "type": "bandwidth", "value": "args.rows * args.cols * dtypeBytes(args.dtype) * 2" }] }},{1 unmodified line"preset": "stress","vars": { "dtype": "float32", "rows": 64, "mid": 1024, "inner": 64 },"attrs": { "axis": 1 },"inputs": { "input": { "shape": [64, 1024, 64], "dtype": "float32", "dist": "normal", "seed": 311, "scale": 2 } },"outputs": { "output": { "shape": [64, 1024, 64], "dtype": "float32" } },"bench": {"metrics": [{ "type": "bandwidth", "value": "args.rows * args.mid * args.inner * dtypeBytes(args.dtype) * 2" }]}},{"name": "logsoftmax-f32-strided-axis1-32x1024x64","preset": "stress","vars": { "dtype": "float32", "rows": 32, "mid": 1024, "inner": 64 },"attrs": { "axis": 1 },"inputs": { "input": { "shape": [32, 1024, 64], "dtype": "float32", "dist": "normal", "seed": 321, "scale": 2 } },"outputs": { "output": { "shape": [32, 1024, 64], "dtype": "float32" } },"bench": {"metrics": [{ "type": "bandwidth", "value": "args.rows * args.mid * args.inner * dtypeBytes(args.dtype) * 2" }]}},{"name": "logsoftmax-f32-strided-axis1-4x1536x80","preset": "stress","vars": { "dtype": "float32", "rows": 4, "mid": 1536, "inner": 80 },"attrs": { "axis": 1 },"inputs": { "input": { "shape": [4, 1536, 80], "dtype": "float32", "dist": "normal", "seed": 322, "scale": 2 } },"outputs": { "output": { "shape": [4, 1536, 80], "dtype": "float32" } },"bench": {"metrics": [{ "type": "bandwidth", "value": "args.rows * args.mid * args.inner * dtypeBytes(args.dtype) * 2" }]}},{"name": "logsoftmax-f32-strided-axis1-8x2048x128","preset": "stress","vars": { "dtype": "float32", "rows": 8, "mid": 2048, "inner": 128 },"attrs": { "axis": 1 },"inputs": { "input": { "shape": [8, 2048, 128], "dtype": "float32", "dist": "normal", "seed": 323, "scale": 2 } },"outputs": { "output": { "shape": [8, 2048, 128], "dtype": "float32" } },"bench": {"metrics": [{ "type": "bandwidth", "value": "args.rows * args.mid * args.inner * dtypeBytes(args.dtype) * 2" }]}3 unmodified lines"preset": "stress","vars": { "dtype": "float16", "rows": 1024, "cols": 2048 },"attrs": { "axis": 1 },"inputs": { "input": { "shape": [1024, 2048], "dtype": "float16", "dist": "normal", "seed": 312, "scale": 2 } },"outputs": { "output": { "shape": [1024, 2048], "dtype": "float16" } },"bench": { "metrics": [{ "type": "bandwidth", "value": "args.rows * args.cols * dtypeBytes(args.dtype) * 2" }] }},{1 unmodified line"preset": "stress","vars": { "dtype": "float32", "rows": 1024, "cols": 2046 },"attrs": { "axis": 1 },"inputs": { "input": { "shape": [1024, 2046], "dtype": "float32", "dist": "normal", "seed": 313, "scale": 2 } },"outputs": { "output": { "shape": [1024, 2046], "dtype": "float32" } },"bench": { "metrics": [{ "type": "bandwidth", "value": "args.rows * args.cols * dtypeBytes(args.dtype) * 2" }] }},{1 unmodified line"preset": "model","vars": { "dtype": "float32", "rows": 70000, "cols": 2048 },"attrs": { "axis": 1 },"inputs": { "input": { "shape": [70000, 2048], "dtype": "float32", "dist": "normal", "seed": 314, "scale": 2 } },"outputs": { "output": { "shape": [70000, 2048], "dtype": "float32" } },"bench": { "metrics": [{ "type": "bandwidth", "value": "args.rows * args.cols * dtypeBytes(args.dtype) * 2" }] }},{1 unmodified line"preset": "stress","vars": { "dtype": "float32", "rows": 131072, "cols": 32 },"attrs": { "axis": 1 },"inputs": { "input": { "shape": [131072, 32], "dtype": "float32", "dist": "normal", "seed": 411, "scale": 2 } },"outputs": { "output": { "shape": [131072, 32], "dtype": "float32" } },"bench": { "metrics": [{ "type": "bandwidth", "value": "args.rows * args.cols * dtypeBytes(args.dtype) * 2" }] }},{2 unmodified lines"provenance": { "notes": "Measures LogSoftmax over 8,320 independent strided rows with an inner extent of 130." },"vars": { "dtype": "float32", "outer": 64, "axisDim": 2048, "inner": 130 },"attrs": { "axis": 1 },"inputs": { "input": { "shape": [64, 2048, 130], "dtype": "float32", "dist": "normal", "seed": 414, "scale": 2 } },"outputs": { "output": { "shape": [64, 2048, 130], "dtype": "float32", "dist": "empty" } },"bench": {"metrics": [{ "type": "bandwidth", "value": "args.outer * args.axisDim * args.inner * dtypeBytes(args.dtype) * 2" }8 unmodified lines},"vars": { "dtype": "float32", "outer": 96, "axisDim": 2048, "inner": 130 },"attrs": { "axis": 1 },"inputs": { "input": { "shape": [96, 2048, 130], "dtype": "float32", "dist": "normal", "seed": 413, "scale": 2 } },"outputs": { "output": { "shape": [96, 2048, 130], "dtype": "float32", "dist": "empty" } },"bench": {"metrics": [{ "type": "bandwidth", "value": "args.outer * args.axisDim * args.inner * dtypeBytes(args.dtype) * 2" }9 unmodified lines},"vars": { "dtype": "float32", "outer": 120, "axisDim": 2048, "inner": 130 },"attrs": { "axis": 1 },"inputs": {"input": { "shape": [120, 2048, 130], "dtype": "float32", "dist": "normal", "seed": 412, "scale": 2 }},"outputs": { "output": { "shape": [120, 2048, 130], "dtype": "float32", "dist": "empty" } },"bench": {"metrics": [{ "type": "bandwidth", "value": "args.outer * args.axisDim * args.inner * dtypeBytes(args.dtype) * 2" }6 unmodified lines"preset": "smoke","vars": { "dtype": "float32", "rows": 8192, "cols": 512 },"attrs": { "axis": 1 },"inputs": { "input": { "shape": [8192, 512], "dtype": "float32", "dist": "normal", "seed": 215, "scale": 2 } },"outputs": { "output": { "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": "Measures log-softmax over 50,257 columns, which is not divisible by four; 50,260 is the nearest four-aligned width at nearly the same byte count."},"vars": { "dtype": "float32", "rows": 64, "cols": 50257 },"attrs": { "axis": 1 },"inputs": { "input": { "shape": [64, 50257], "dtype": "float32", "dist": "normal", "seed": 415, "scale": 4 } },"outputs": { "output": { "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": "A 50,260-column vocabulary width is the next multiple of four above 50,257, with nearly the same input bytes."},"vars": { "dtype": "float32", "rows": 64, "cols": 50260 },"attrs": { "axis": 1 },"inputs": { "input": { "shape": [64, 50260], "dtype": "float32", "dist": "normal", "seed": 416, "scale": 4 } },"outputs": { "output": { "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": { "input": { "dtype": "float32", "shape": [2, 31, 8], "dist": "normal", "seed": 913, "scale": 2 } },"outputs": { "output": { "dtype": "float32", "shape": [2, 31, 8] } },"bench": { "metrics": [{ "type": "bandwidth", "value": "numel(shapes.input) * 8" }] }},{"name": "online_stream_axis32_f32","attrs": { "axis": 1 },"inputs": { "input": { "dtype": "float32", "shape": [2, 32, 8], "dist": "normal", "seed": 913, "scale": 2 } },"outputs": { "output": { "dtype": "float32", "shape": [2, 32, 8] } },"bench": { "metrics": [{ "type": "bandwidth", "value": "numel(shapes.input) * 8" }] }},{"name": "online_stream_axis33_f32","attrs": { "axis": 1 },"inputs": { "input": { "dtype": "float32", "shape": [2, 33, 8], "dist": "normal", "seed": 913, "scale": 2 } },"outputs": { "output": { "dtype": "float32", "shape": [2, 33, 8] } },"bench": { "metrics": [{ "type": "bandwidth", "value": "numel(shapes.input) * 8" }] }},{"name": "online_stream_axis64_f32","attrs": { "axis": 1 },"inputs": { "input": { "dtype": "float32", "shape": [2, 64, 8], "dist": "normal", "seed": 913, "scale": 2 } },"outputs": { "output": { "dtype": "float32", "shape": [2, 64, 8] } },"bench": { "metrics": [{ "type": "bandwidth", "value": "numel(shapes.input) * 8" }] }},{"name": "online_stream_axis65_f32","attrs": { "axis": 1 },"inputs": { "input": { "dtype": "float32", "shape": [2, 65, 8], "dist": "normal", "seed": 913, "scale": 2 } },"outputs": { "output": { "dtype": "float32", "shape": [2, 65, 8] } },"bench": { "metrics": [{ "type": "bandwidth", "value": "numel(shapes.input) * 8" }] }},{"name": "online_stream_columns_tail_f32","attrs": { "axis": 1 },"inputs": { "input": { "dtype": "float32", "shape": [129, 67, 130], "dist": "normal", "seed": 913, "scale": 2 } },"outputs": { "output": { "dtype": "float32", "shape": [129, 67, 130] } },"bench": { "metrics": [{ "type": "bandwidth", "value": "numel(shapes.input) * 8" }] }},{"name": "online_stream_four_way_tail_f32","attrs": { "axis": 1 },"inputs": { "input": { "dtype": "float32", "shape": [2, 129, 8], "dist": "normal", "seed": 913, "scale": 2 } },"outputs": { "output": { "dtype": "float32", "shape": [2, 129, 8] } },"bench": { "metrics": [{ "type": "bandwidth", "value": "numel(shapes.input) * 8" }] },"tunables": { "STRIDED_ONLINE_STREAMS": 4 }},{"name": "logsoftmax-f32-ragged-32x1920x65","preset": "stress","vars": { "dtype": "float32", "outer": 32, "axisDim": 1920, "inner": 65 },"attrs": { "axis": 1 },"inputs": { "input": { "shape": [32, 1920, 65], "dtype": "float32", "dist": "normal", "seed": 6620, "scale": 2 } },"outputs": { "output": { "shape": [32, 1920, 65], "dtype": "float32", "dist": "empty" } },"bench": {"metrics": [{ "type": "bandwidth", "value": "args.outer * args.axisDim * args.inner * dtypeBytes(args.dtype) * 2" }]}},{"name": "logsoftmax-f32-ragged-33x1984x131","preset": "stress","vars": { "dtype": "float32", "outer": 33, "axisDim": 1984, "inner": 131 },"attrs": { "axis": 1 },"inputs": {"input": { "shape": [33, 1984, 131], "dtype": "float32", "dist": "normal", "seed": 6621, "scale": 2 }},"outputs": { "output": { "shape": [33, 1984, 131], "dtype": "float32", "dist": "empty" } },"bench": {"metrics": [{ "type": "bandwidth", "value": "args.outer * args.axisDim * args.inner * dtypeBytes(args.dtype) * 2" }]}},{"name": "logsoftmax-f32-ragged-32x2048x134","preset": "stress","vars": { "dtype": "float32", "outer": 32, "axisDim": 2048, "inner": 134 },"attrs": { "axis": 1 },"inputs": {"input": { "shape": [32, 2048, 134], "dtype": "float32", "dist": "normal", "seed": 6622, "scale": 2 }},"outputs": { "output": { "shape": [32, 2048, 134], "dtype": "float32", "dist": "empty" } },"bench": {"metrics": [{ "type": "bandwidth", "value": "args.outer * args.axisDim * args.inner * dtypeBytes(args.dtype) * 2" }]}},{"name": "logsoftmax-f32-ragged-32x1024x130","preset": "stress","vars": { "dtype": "float32", "outer": 32, "axisDim": 1024, "inner": 130 },"attrs": { "axis": 1 },"inputs": {"input": { "shape": [32, 1024, 130], "dtype": "float32", "dist": "normal", "seed": 6623, "scale": 2 }},"outputs": { "output": { "shape": [32, 1024, 130], "dtype": "float32", "dist": "empty" } },"bench": {"metrics": [{ "type": "bandwidth", "value": "args.outer * args.axisDim * args.inner * dtypeBytes(args.dtype) * 2" }]}},{"name": "logsoftmax-f32-ragged-3x1984x131","preset": "stress","vars": { "dtype": "float32", "outer": 3, "axisDim": 1984, "inner": 131 },"attrs": { "axis": 1 },"inputs": { "input": { "shape": [3, 1984, 131], "dtype": "float32", "dist": "normal", "seed": 6624, "scale": 2 } },"outputs": { "output": { "shape": [3, 1984, 131], "dtype": "float32", "dist": "empty" } },"bench": {"metrics": [{ "type": "bandwidth", "value": "args.outer * args.axisDim * args.inner * dtypeBytes(args.dtype) * 2" }]}}]}
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530{"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)","axisInner": "inner(shapes.x, axis)","axisOuter": "outer(shapes.x, axis)","axisRows": "axisOuter * axisInner","longrowBlocks": "ceilDiv(lastCols, tunables.BLOCK_COLS)","lastRowScratchFits": "4 * lastRows <= 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","stridedCoopDispatchFits": "min(ceilDiv(axisRows, stridedCoopTileCols), DISPATCH_FOLD_WIDTH) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) and ceilDiv(ceilDiv(axisRows, stridedCoopTileCols), DISPATCH_FOLD_WIDTH) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535)","axisRowScratchFits": "4 * axisRows <= storageBufferLimit","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": {"x_scalar": { "name": "x", "elementType": "$scalar" },"y_scalar": { "name": "y", "elementType": "$scalar" },"x_exp_sum": { "name": "x", "elementType": "vec4<f32>" },"params_count": { "name": "params", "struct": [{ "name": "count", "type": "u32", "value": "numel(shapes.x)" }] },"rowMax": { "buffer": "storage", "elementType": "f32" },"rowSum": { "buffer": "storage", "elementType": "f32" },"rowMax_f32": { "name": "rowMax", "buffer": "read-only-storage", "elementType": "f32" },"rowSum_f32": { "name": "rowSum", "buffer": "read-only-storage", "elementType": "f32" },"x_main": { "name": "x", "elementType": "$vectorScalar" },"y_main": { "name": "y", "elementType": "$vectorScalar" },"params": {"struct": [{ "name": "rows", "type": "u32", "value": "lastRows" },{ "name": "vecCols", "type": "u32", "value": "lastCols / 4" }]},"params_main": {"name": "params","struct": [{ "name": "rows", "type": "u32", "value": "lastRows" },{ "name": "cols", "type": "u32", "value": "lastCols" }]}},"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","dtype": "float32","shape": "[rows(shapes.x, ranks.x - 1) * ceilDiv(dim(shapes.x, ranks.x - 1), tunables.BLOCK_COLS)]"},{"id": "blockSum","dtype": "float32","shape": "[rows(shapes.x, ranks.x - 1) * ceilDiv(dim(shapes.x, ranks.x - 1), tunables.BLOCK_COLS)]"},{ "id": "rowMax", "dtype": "float32", "shape": "[rows(shapes.x, ranks.x - 1)]" },{ "id": "rowSum", "dtype": "float32", "shape": "[rows(shapes.x, ranks.x - 1)]" }],"passes": [{"id": "block_stats","name": "LogSoftmax.LongRowBlockStats","shader": "softmax-longrow-stats.wgsl.jinja","derive": { "stage": "\"block\"", "combineSubgroups": false },"bindings": ["x",{ "name": "blockMax", "elementType": "f32" },{ "name": "blockSum", "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)"}},{"id": "row_stats","name": "LogSoftmax.LongRowStats","shader": "softmax-longrow-stats.wgsl.jinja","derive": { "stage": "\"row\"", "combineSubgroups": false },"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_f32","rowSum_f32","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)"}}]},{"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_main", "y_main", "params"],"dispatch": {"x": "min(ceilDiv(lastRows, subgroupRowsWorkgroup / device.adapterInfo.subgroupMaxSize), 65535)","y": "ceilDiv(ceilDiv(lastRows, subgroupRowsWorkgroup / device.adapterInfo.subgroupMaxSize), 65535)","z": 1}}]},{"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","derive": { "op": "\"logsoftmax\"", "useVec4": "true" },"bindings": ["x_main", "y_main", "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","derive": { "op": "\"logsoftmax\"", "useVec4": "false" },"bindings": ["x_scalar", "y_scalar", "params_main"],"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},"passes": [{"id": "main","name": "LogSoftmax.OnlinePackedRowsVec4NoSg","shader": "softmax-online-packed-rows.wgsl.jinja","derive": {"op": "\"logsoftmax\"","lanesPerRow": "lanesPerRow","rowsPerWorkgroup": "rowsPerWorkgroup","useVec4": "true"},"bindings": ["x_main", "y_main", "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_scalar", "y_scalar", "params_main"],"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_main", "y_main", "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_scalar", "y_scalar", "params_main"],"dispatch": {"x": "min(rows(shapes.x, ranks.x - 1), 65535)","y": "ceilDiv(rows(shapes.x, ranks.x - 1), 65535)","z": 1}}]},{"id": "stable_3pass","priority": 8,"when": ["lastAxisOk", "lastDispatchFits", "lastRowScratchFits"],"intermediates": [{ "id": "rowMax", "dtype": "float32", "shape": "[numel(shapes.x) / dim(shapes.x, ranks.x - 1)]" },{ "id": "rowSum", "dtype": "float32", "shape": "[numel(shapes.x) / dim(shapes.x, ranks.x - 1)]" }],"passes": [{"id": "reduce_max","name": "LogSoftmax.ReduceMax","shader": "softmax-row-stage.wgsl.jinja","derive": { "stage": "\"max\"", "strided": "false" },"bindings": ["x", "rowMax", "params_main"],"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_f32", "y", "rowSum", "params_main"],"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_f32","rowSum_f32","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"],"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)]" }],"passes": [{"id": "reduce_max","name": "LogSoftmax.StridedReduceMaxVec4","shader": "softmax-row-stage-strided-vec4.wgsl.jinja","derive": { "stage": "\"max\"", "xShape": "shapes.x", "axisSpec": "axis" },"bindings": ["x_exp_sum", { "name": "rowMax", "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_exp_sum",{ "name": "rowMax", "buffer": "read-only-storage", "elementType": "vec4<f32>" },{ "arg": "y", "elementType": "vec4<f32>" },{ "name": "rowSum", "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_f32", "rowSum_f32", "y", "params_count"],"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_online_coop","priority": 19,"when": ["stridedAxisOk", "f16Ok(dtypes.T)", "stridedCoopDispatchFits"],"passes": [{"id": "main","name": "LogSoftmax.StridedOnlineCoop","shader": "softmax-strided-online-coop.wgsl.jinja","derive": {"xShape": "shapes.x","axisSpec": "axis","tileCols": "stridedCoopTileCols","onlineStreams": "stridedOnlineStreams","op": "\"logsoftmax\""},"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"],"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}}]},{"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"],"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)]" }],"passes": [{"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_f32", "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_f32", "rowSum_f32", "y", "params_count"],"dispatch": {"x": "min(ceilDiv((numel(shapes.x)), (tunables.WORKGROUP_SIZE)), 65535)","y": "ceilDiv(ceilDiv((numel(shapes.x)), (tunables.WORKGROUP_SIZE)), 65535)","z": 1}}]}]}1{"domain":"ai.onnx","name":"LogSoftmax","sinceVersion":13,"inputs":{"input":{"dtype":"T"}},"outputs":{"output":{"dtype":"T","rank":"ranks.input","shape":"shapes.input"}},"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.input","lastCols":"dim(shapes.input, ranks.input - 1)","lastRows":"rows(shapes.input, ranks.input - 1)","axisInner":"inner(shapes.input, axis)","axisOuter":"outer(shapes.input, axis)","axisRows":"axisOuter * axisInner","longrowBlocks":"ceilDiv(lastCols, tunables.BLOCK_COLS)","lastRowScratchFits":"4 * lastRows <= 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.input) == numel(shapes.output) and ranks.input >= 1 and (attrs.axis == -1 or attrs.axis == ranks.input - 1) and f16Ok(dtypes.T)","stridedAxisOk":"numel(shapes.input) == numel(shapes.output) and ranks.input >= 2 and attrs.axis + ranks.input >= 0 and attrs.axis < ranks.input and not (attrs.axis == -1 or attrs.axis == ranks.input - 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","stridedCoopDispatchFits":"min(ceilDiv(axisRows, stridedCoopTileCols), DISPATCH_FOLD_WIDTH) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) and ceilDiv(ceilDiv(axisRows, stridedCoopTileCols), DISPATCH_FOLD_WIDTH) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535)","sliceTile":8,"reductionLanes":32,"tileThreads":"sliceTile * reductionLanes","axisLength":"dim(shapes.input, axis)","itemsPerLane":"ceilDiv(axisLength, reductionLanes)","residentAxisFits":"axisLength % reductionLanes == 0 and itemsPerLane >= 32 and itemsPerLane <= 64","residentTileFits":"axisRows > 0 and tileThreads <= deviceWorkgroupCap and sliceTile <= device.limits.maxComputeWorkgroupSizeX and reductionLanes <= device.limits.maxComputeWorkgroupSizeY and tileThreads * 4 <= device.limits.maxComputeWorkgroupStorageSize and ceilDiv(axisRows, sliceTile) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535)","axisRowScratchFits":"4 * axisRows <= storageBufferLimit","stridedOnlineStreams":"min(4, pow2ceil(max(1, tunables.STRIDED_ONLINE_STREAMS)), max(1, ceilDiv(dim(shapes.input, axis), 256 / stridedCoopTileCols))) if dtypes.T == \"f32\" else 1","scalarVec4CombineSubgroups":"device.features.has(\"subgroups\")","scalarVec4SharedBytes":"ceilDiv(rowWorkgroupSize, 4) * 32 + (ceilDiv(ceilDiv(rowWorkgroupSize, 32), 4) * 16 + 16 if scalarVec4CombineSubgroups else 0)"},"bindings":{"x_scalar":{"name":"x","arg":"input","elementType":"$scalar"},"y_scalar":{"name":"y","arg":"output","elementType":"$scalar"},"x_exp_sum":{"name":"x","arg":"input","elementType":"vec4<f32>"},"params_count":{"name":"params","struct":[{"name":"count","type":"u32","value":"numel(shapes.input)"}],"when":"not lastAxisOk"},"params_main":{"name":"params","struct":[{"name":"rows","type":"u32","value":"lastRows"},{"name":"cols","type":"u32","value":"lastCols"}],"when":"lastAxisOk"},"params_count_cols":{"name":"params","struct":[{"name":"count","type":"u32","value":"numel(shapes.input)"},{"name":"cols","type":"u32","value":"lastCols"}],"when":"lastAxisOk"},"y":{"arg":"output"},"x":{"arg":"input"},"rowMax":{"buffer":"storage","elementType":"f32"},"rowSum":{"buffer":"storage","elementType":"f32"},"rowMax_f32":{"name":"rowMax","buffer":"read-only-storage","elementType":"f32"},"rowSum_f32":{"name":"rowSum","buffer":"read-only-storage","elementType":"f32"},"x_main":{"name":"x","arg":"input","elementType":"$vectorScalar"},"y_main":{"name":"y","arg":"output","elementType":"$vectorScalar"},"params":{"struct":[{"name":"rows","type":"u32","value":"lastRows"},{"name":"vecCols","type":"u32","value":"lastCols / 4"}]}},"variants":[{"id":"ragged_resident","priority":30,"when":["stridedAxisOk","dtypes.T == \"f32\"","f16Ok(dtypes.T)","has(device.adapterInfo, \"architecture\") and device.adapterInfo.architecture in [\"blackwell\", \"xe-3lpg\"]","axisInner >= 2 * reductionLanes","(axisInner % 4 != 0 and axisInner <= 4 * reductionLanes + sliceTile) or (dtypes.T == \"f32\" and device.adapterInfo.architecture == \"blackwell\" and axisInner % sliceTile == 0 and axisInner <= 4 * reductionLanes)","residentAxisFits","residentTileFits"],"demoteWhen":["axisInner % 4 != 0 and axisRows < sliceTile * tileThreads","dtypes.T == \"f16\" and device.adapterInfo.architecture == \"xe-3lpg\" and axisInner < 4 * reductionLanes"],"passes":[{"id":"main","name":"LogSoftmax.RaggedResident","shader":"softmax-strided-resident.wgsl.jinja","derive":{"xShape":"shapes.input","axisSpec":"axis","needsRowMask":"axisInner % 4 != 0 and axisRows % sliceTile != 0"},"bindings":["x","y"],"dispatch":{"x":"ceilDiv(axisRows, sliceTile)"}}]},{"id":"longrow_split","priority":30,"when":["lastCols >= tunables.LONGROW_SPLIT_MIN_COLS","rows(shapes.input, ranks.input - 1) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535)","ceilDiv(dim(shapes.input, ranks.input - 1), tunables.BLOCK_COLS) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535)","lastRowScratchFits","longrowBlockScratchFits","lastAxisOk"],"intermediates":[{"id":"blockMax","dtype":"float32","shape":"[rows(shapes.input, ranks.input - 1) * ceilDiv(dim(shapes.input, ranks.input - 1), tunables.BLOCK_COLS)]"},{"id":"blockSum","dtype":"float32","shape":"[rows(shapes.input, ranks.input - 1) * ceilDiv(dim(shapes.input, ranks.input - 1), tunables.BLOCK_COLS)]"},{"id":"rowMax","dtype":"float32","shape":"[rows(shapes.input, ranks.input - 1)]"},{"id":"rowSum","dtype":"float32","shape":"[rows(shapes.input, ranks.input - 1)]"}],"passes":[{"id":"block_stats","name":"LogSoftmax.LongRowBlockStats","shader":"softmax-longrow-stats.wgsl.jinja","derive":{"stage":"\"block\"","combineSubgroups":false},"bindings":["x",{"name":"blockMax","elementType":"f32"},{"name":"blockSum","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.input, ranks.input - 1), tunables.BLOCK_COLS)","y":"rows(shapes.input, ranks.input - 1)"}},{"id":"row_stats","name":"LogSoftmax.LongRowStats","shader":"softmax-longrow-stats.wgsl.jinja","derive":{"stage":"\"row\"","combineSubgroups":false},"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.input, ranks.input - 1)"}},{"id":"normalize","name":"LogSoftmax.LongRowNormalize","shader":"softmax-longrow-normalize.wgsl.jinja","derive":{"op":"\"logsoftmax\""},"bindings":["x","rowMax_f32","rowSum_f32","y",{"name":"params","struct":[{"name":"cols","type":"u32","value":"lastCols"}]}],"dispatch":{"x":"ceilDiv(dim(shapes.input, ranks.input - 1), tunables.BLOCK_COLS)","y":"rows(shapes.input, ranks.input - 1)"}}]},{"id":"online_subgroup_rows_vec4","priority":18,"when":["dim(shapes.input, ranks.input - 1) % 4 == 0","has(device.adapterInfo, \"subgroupMinSize\")","device.adapterInfo.subgroupMinSize >= 16","dim(shapes.input, ranks.input - 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","subgroupRowsPerWorkgroup":"subgroupRowsWorkgroup / device.adapterInfo.subgroupMaxSize"},"passes":[{"id":"main","name":"LogSoftmax.OnlineSubgroupRowsVec4","shader":"softmax-subgroup-rows.wgsl.jinja","derive":{"op":"\"logsoftmax\""},"bindings":["x_main","y_main","params"],"dispatch":{"x":"min(ceilDiv(lastRows, subgroupRowsWorkgroup / device.adapterInfo.subgroupMaxSize), 65535)","y":"ceilDiv(ceilDiv(lastRows, subgroupRowsWorkgroup / device.adapterInfo.subgroupMaxSize), 65535)","z":1}}]},{"id":"online_wg_vec4","priority":16,"when":["(device.features.has(\"subgroups\") and dim(shapes.input, ranks.input - 1) >= 1024) or (not device.features.has(\"subgroups\") and dim(shapes.input, ranks.input - 1) > 32)","dim(shapes.input, ranks.input - 1) % 4 == 0","ceilDiv(rows(shapes.input, ranks.input - 1), min(device.limits.maxComputeWorkgroupsPerDimension, 65535)) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535)","lastAxisOk"],"derive":{"combineSubgroups":"device.features.has(\"subgroups\") and dim(shapes.input, ranks.input - 1) >= 1024","scalar":"dtypes.T","vectorScalar":"\"vec4<\" ~ dtypes.T ~ \">\"","workgroupSize":"rowWorkgroupSize"},"passes":[{"id":"main","name":"LogSoftmax.OnlineWorkgroupVec4","shader":"softmax-online.wgsl.jinja","derive":{"op":"\"logsoftmax\"","useVec4":"true"},"bindings":["x_main","y_main","params"],"dispatch":{"x":"min(rows(shapes.input, ranks.input - 1), 65535)","y":"ceilDiv(rows(shapes.input, ranks.input - 1), 65535)","z":1}}]},{"id":"online_wg","priority":15,"when":["(device.features.has(\"subgroups\") and dim(shapes.input, ranks.input - 1) > 0) or dim(shapes.input, ranks.input - 1) > 32","ceilDiv(rows(shapes.input, ranks.input - 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","derive":{"op":"\"logsoftmax\"","useVec4":"false"},"bindings":["x_scalar","y_scalar","params_main"],"dispatch":{"x":"min(rows(shapes.input, ranks.input - 1), 65535)","y":"ceilDiv(rows(shapes.input, ranks.input - 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},"passes":[{"id":"main","name":"LogSoftmax.OnlinePackedRowsVec4NoSg","shader":"softmax-online-packed-rows.wgsl.jinja","derive":{"op":"\"logsoftmax\"","lanesPerRow":"lanesPerRow","rowsPerWorkgroup":"rowsPerWorkgroup","useVec4":"true"},"bindings":["x_main","y_main","params"],"dispatch":{"x":"min(ceilDiv(rows(shapes.input, ranks.input - 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_scalar","y_scalar","params_main"],"dispatch":{"x":"min(ceilDiv(rows(shapes.input, ranks.input - 1), rowsPerWorkgroup), min(device.limits.maxComputeWorkgroupsPerDimension, 65535))","y":1,"z":1}}]},{"id":"online_local_vec4_nosg","priority":16,"when":["dim(shapes.input, ranks.input - 1) > 0","dim(shapes.input, ranks.input - 1) <= 32","dim(shapes.input, ranks.input - 1) % 4 == 0","ceilDiv(rows(shapes.input, ranks.input - 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_main","y_main","params"],"dispatch":{"x":"min(rows(shapes.input, ranks.input - 1), 65535)","y":"ceilDiv(rows(shapes.input, ranks.input - 1), 65535)","z":1}}]},{"id":"online_local_nosg","priority":14,"when":["dim(shapes.input, ranks.input - 1) > 0","dim(shapes.input, ranks.input - 1) <= 32","ceilDiv(rows(shapes.input, ranks.input - 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_scalar","y_scalar","params_main"],"dispatch":{"x":"min(rows(shapes.input, ranks.input - 1), 65535)","y":"ceilDiv(rows(shapes.input, ranks.input - 1), 65535)","z":1}}]},{"id":"strided_3pass_vec4","priority":14,"when":["dtypes.T == \"f32\"","stridedAxisOk","inner(shapes.input, attrs.axis if attrs.axis >= 0 else attrs.axis + ranks.input) % 4 == 0","axisDispatchFits","axisRowScratchFits"],"intermediates":[{"id":"rowMax","dtype":"float32","shape":"[numel(shapes.input) / dim(shapes.input, axis)]"},{"id":"rowSum","dtype":"float32","shape":"[numel(shapes.input) / dim(shapes.input, axis)]"}],"passes":[{"id":"reduce_max","name":"LogSoftmax.StridedReduceMaxVec4","shader":"softmax-row-stage-strided-vec4.wgsl.jinja","derive":{"stage":"\"max\"","xShape":"shapes.input","axisSpec":"axis"},"bindings":["x_exp_sum",{"name":"rowMax","elementType":"vec4<f32>"}],"dispatch":{"x":"min(numel(shapes.input) / dim(shapes.input, axis) / 4, 65535)","y":"ceilDiv(numel(shapes.input) / dim(shapes.input, 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.input","axisSpec":"axis"},"bindings":["x_exp_sum",{"name":"rowMax","buffer":"read-only-storage","elementType":"vec4<f32>"},{"arg":"output","name":"y","elementType":"vec4<f32>"},{"name":"rowSum","elementType":"vec4<f32>"}],"dispatch":{"x":"min(numel(shapes.input) / dim(shapes.input, axis) / 4, 65535)","y":"ceilDiv(numel(shapes.input) / dim(shapes.input, axis) / 4, 65535)","z":1}},{"id":"normalize","name":"LogSoftmax.StridedNormalize","shader":"softmax-normalize.wgsl.jinja","derive":{"strided":"true","xShape":"shapes.input","axisSpec":"axis","op":"\"logsoftmax\""},"bindings":["x","rowMax_f32","rowSum_f32","y","params_count"],"dispatch":{"x":"min(ceilDiv((numel(shapes.input)), (tunables.WORKGROUP_SIZE)), 65535)","y":"ceilDiv(ceilDiv((numel(shapes.input)), (tunables.WORKGROUP_SIZE)), 65535)","z":1}}]},{"id":"strided_online_coop","priority":19,"when":["stridedAxisOk","f16Ok(dtypes.T)","stridedCoopDispatchFits","3072 <= device.limits.maxComputeWorkgroupStorageSize","256 <= device.limits.maxComputeInvocationsPerWorkgroup","stridedCoopTileCols <= device.limits.maxComputeWorkgroupSizeX","256 / stridedCoopTileCols <= device.limits.maxComputeWorkgroupSizeY"],"passes":[{"id":"main","name":"LogSoftmax.StridedOnlineCoop","shader":"softmax-strided-online-coop.wgsl.jinja","derive":{"xShape":"shapes.input","axisSpec":"axis","tileCols":"stridedCoopTileCols","onlineStreams":"stridedOnlineStreams","op":"\"logsoftmax\""},"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.input, attrs.axis if attrs.axis >= 0 else attrs.axis + ranks.input) >= 4","inner(shapes.input, attrs.axis if attrs.axis >= 0 else attrs.axis + ranks.input) % 4 != 0","dim(shapes.input, axis) < 2048 or axisRows < tunables.STRIDED_CAPACITY_MIN_ROWS","axisDispatchFits"],"passes":[{"id":"main","name":"LogSoftmax.StridedOnlinePacked4Tail","shader":"softmax-strided-packed4-tail.wgsl.jinja","derive":{"xShape":"shapes.input","axisSpec":"axis"},"bindings":[{"arg":"input","name":"x","elementType":"f32"},{"arg":"output","name":"y","elementType":"f32"}],"dispatch":{"x":"min(numel(shapes.input) / dim(shapes.input, axis) / inner(shapes.input, axis) * ceilDiv(inner(shapes.input, axis), 4), 65535)","y":"ceilDiv(numel(shapes.input) / dim(shapes.input, axis) / inner(shapes.input, axis) * ceilDiv(inner(shapes.input, axis), 4), 65535)","z":1}}]},{"id":"stable_3pass","priority":12,"when":["lastAxisOk or stridedAxisOk","f16Ok(dtypes.T)","axisDispatchFits","axisRowScratchFits"],"demoteWhen":["dtypes.T == \"f32\" and inner(shapes.input, attrs.axis if attrs.axis >= 0 else attrs.axis + ranks.input) >= 4 and inner(shapes.input, attrs.axis if attrs.axis >= 0 else attrs.axis + ranks.input) % 4 != 0"],"intermediates":[{"id":"rowMax","dtype":"float32","shape":"[numel(shapes.input) / dim(shapes.input, axis)]"},{"id":"rowSum","dtype":"float32","shape":"[numel(shapes.input) / dim(shapes.input, axis)]"}],"passes":[{"id":"reduce_max","name":"LogSoftmax.ReduceMax","shader":"softmax-row-stage.wgsl.jinja","derive":{"stage":"\"max\"","strided":"stridedAxisOk","xShape":"shapes.input","axisSpec":"axis"},"bindings":["x","rowMax","params_main"],"dispatch":{"x":"min(numel(shapes.input) / dim(shapes.input, axis), 65535)","y":"ceilDiv(numel(shapes.input) / dim(shapes.input, axis), 65535)","z":1}},{"id":"exp_sum","name":"LogSoftmax.ExpSum","shader":"softmax-row-stage.wgsl.jinja","derive":{"stage":"\"exp_sum\"","strided":"stridedAxisOk","xShape":"shapes.input","axisSpec":"axis"},"bindings":["x","rowMax_f32","y","rowSum","params_main"],"dispatch":{"x":"min(numel(shapes.input) / dim(shapes.input, axis), 65535)","y":"ceilDiv(numel(shapes.input) / dim(shapes.input, axis), 65535)","z":1}},{"id":"normalize","name":"LogSoftmax.Normalize","shader":"softmax-normalize.wgsl.jinja","derive":{"strided":"stridedAxisOk","xShape":"shapes.input","axisSpec":"axis","op":"\"logsoftmax\""},"bindings":["x","rowMax_f32","rowSum_f32","y","params_count","params_count_cols"],"dispatch":{"x":"min(ceilDiv((numel(shapes.input)), (tunables.WORKGROUP_SIZE)), 65535)","y":"ceilDiv(ceilDiv((numel(shapes.input)), (tunables.WORKGROUP_SIZE)), 65535)","z":1}}]},{"id":"online_wg_scalar_vec4_tail","priority":16,"when":["dtypes.T == \"f32\"","lastAxisOk","lastCols % 4 != 0","lastCols >= rowWorkgroupSize * 4","rowWorkgroupSize >= 1 and rowWorkgroupSize == floor(rowWorkgroupSize) and pow2ceil(rowWorkgroupSize) == rowWorkgroupSize","rowWorkgroupSize <= min(device.limits.maxComputeInvocationsPerWorkgroup, device.limits.maxComputeWorkgroupSizeX)","scalarVec4SharedBytes <= device.limits.maxComputeWorkgroupStorageSize","numel(shapes.input) <= 4294967295 and ceilDiv(lastCols, 4) + rowWorkgroupSize <= 4294967295","min(lastRows, DISPATCH_FOLD_WIDTH) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) and ceilDiv(lastRows, DISPATCH_FOLD_WIDTH) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535)"],"derive":{"combineSubgroups":"scalarVec4CombineSubgroups","scalar":"\"f32\"","workgroupSize":"rowWorkgroupSize","scalarVec4":true},"passes":[{"id":"main","name":"LogSoftmax.OnlineWorkgroupScalarVec4Tail","shader":"softmax-online.wgsl.jinja","derive":{"op":"\"logsoftmax\"","useVec4":true},"bindings":[{"arg":"input","name":"x","elementType":"f32"},{"arg":"output","name":"y","elementType":"f32"},{"name":"params","struct":[{"name":"rows","type":"u32","value":"lastRows"},{"name":"cols","type":"u32","value":"lastCols"},{"name":"vecCols","type":"u32","value":"ceilDiv(lastCols, 4)"}]}],"dispatch":{"x":"min(lastRows, 65535)","y":"ceilDiv(lastRows, 65535)","z":1}}]}]}
1234567891011121314151617181920212223242526272829303132333435363738394041424344{"name": "ai.onnx.LogSoftmax","id": "_ai_onnx_logsoftmax_webgpu_4896bd3","version": 1,"license": "Apache-2.0","backend": { "type": "webgpu" },"digest": {"algorithm": "sha256","files": {"bench.json": "SvuAkJFufs4pJCvvQl68ccv1olqep5tmHlqxCp4Dd/s=","manifest.json": "agl/2kS1pO7NsCz4/7uItvvoLvoK5flm7PTJ89i8bHw=","softmax-longrow-normalize.wgsl.jinja": "jy4t+YROOPczKJwk1qn7dgbA4TFpslDRX4CLql5Ychk=","softmax-longrow-stats.wgsl.jinja": "S8w3EVvJXQavrn/79+OYm6yMZWERwlyJiZhYF8HkAj0=","softmax-normalize.wgsl.jinja": "MRBOzfP0VMvC2H8uWhMJ3wm5RckrdGxMneOy88Y92b4=","softmax-online-packed-rows.wgsl.jinja": "8SJM2qyv5RnJK/nzoif+8RZBcIIovrtcCVq+tQQ6n0k=","softmax-online.wgsl.jinja": "kspDFq+qGAmhnhKKcOmOWTLOQ2vX6y54NHbUlPnxhHY=","softmax-row-stage-strided-vec4.wgsl.jinja": "zTL9bEcqInxFgFd5V2HamSyPqzPzZyEcuW87QlO4aU4=","softmax-row-stage.wgsl.jinja": "Uv2knZMUyaueKOSxAhn7Vko2N0QajW/vyOJWSNbyux4=","softmax-strided-online-coop.wgsl.jinja": "ZMjzbUYJpr/AI6VDYIoPvqIt2vOadAtKxkfc/eFcvNE=","softmax-strided-packed4-tail.wgsl.jinja": "16AesZJMCqOU7HANkDNZlJdjpkohzbOk/M7pQu/vMNQ=","softmax-subgroup-rows.wgsl.jinja": "l8/ApzifNWPXI4+nQlz+dJ4ZI+t7IeiDqLrRj/XmmQw=","test.json": "Purex4g7SQtnFKtBVaRg6FkZWPLvCWGk/5pQ1aol1iI="}},"provenance": { "kernel": { "sha": "6fdf6301e2bbcc2f03bf1eaf493b7ad55ef33afc", "dirty": false } },"webgpu": {"manifestSpec": "2.1","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"]}}}1{"name":"ai.onnx.LogSoftmax","id":"_ai_onnx_logsoftmax_webgpu_a6eda14","version":1,"license":"Apache-2.0","backend":{"type":"webgpu"},"digest":{"algorithm":"sha256","files":{"bench.json":"jm/HVlpBymi9WgoxOqgWuI/WX4XYiL9XmD0/ub+slZo=","manifest.json":"g6++5XnjpGvkcevPsW3bnsj7VI7gk5Q8Rf4281dNMhk=","softmax-longrow-normalize.wgsl.jinja":"jy4t+YROOPczKJwk1qn7dgbA4TFpslDRX4CLql5Ychk=","softmax-longrow-stats.wgsl.jinja":"S8w3EVvJXQavrn/79+OYm6yMZWERwlyJiZhYF8HkAj0=","softmax-normalize.wgsl.jinja":"T0V1eIy+KgdkBoYPGL0bbV5YLZ4Go7eedqnTgkNU75g=","softmax-online-packed-rows.wgsl.jinja":"8SJM2qyv5RnJK/nzoif+8RZBcIIovrtcCVq+tQQ6n0k=","softmax-online.wgsl.jinja":"ROTDlUFE6kBvMtABAW1v5dH+YhLX3nIed7yQdV4hsGU=","softmax-row-stage-strided-vec4.wgsl.jinja":"U0XHoNplc5AiojzMO7xkzFhQCLRfYNgUMZVLA70RxVg=","softmax-row-stage.wgsl.jinja":"ijrvMOMx/BkMOK98RaWY0jPOvNb5MWtaLC9T609Ycbc=","softmax-strided-online-coop.wgsl.jinja":"P7lupuu6qgFISR2D7EFIFrfWn+pk58p/AOcUfZjPohI=","softmax-strided-packed4-tail.wgsl.jinja":"16AesZJMCqOU7HANkDNZlJdjpkohzbOk/M7pQu/vMNQ=","softmax-strided-resident.wgsl.jinja":"VRhvtxLsWqE9yluAJ+nEiTTZcnUU/B+kMzK5rM1sRXw=","softmax-subgroup-rows.wgsl.jinja":"6esHf2nRPjnD9j8qiQg2knnH0AidMJOZ9EyjFFP2GbM=","test.json":"Qj5YLfyUK1TNM8Qt5mWiCDu1mW9Ig587T3BNGaLYLWA="}},"provenance":{"kernel":{"sha":"4385228f788ddaa1bd7aec6a80a20f3ddffd8011","dirty":false}},"webgpu":{"manifestSpec":"2.2"}}
1234567891011{% macro flat_index_2d(workgroupSize, name="i", bound="params.count", guardInline=false) %}{% set wgTerm = workgroupSize ~ "u" if workgroupSize is number else workgroupSize %}// 2D-folded flat index: gid.y carries the high bits past the dispatch's// per-axis workgroup fold width.let {{ name }} = gid.x + gid.y * {{ DISPATCH_FOLD_WIDTH }}u * {{ wgTerm }};if ({{ name }} >= {{ bound }}) {return;}{% endmacro %}{{ env.wgsl.resourceDeclarations }}{% if strided %}{% set stridedAxisUses = ["row_for_offset"] %}123456789101112{% macro flat_index_2d(workgroupSize, name="i", bound="params.count") %}{% set wgTerm = workgroupSize ~ "u" if workgroupSize is number else workgroupSize %}// 2D-folded flat index: gid.y carries the high bits past the dispatch's// per-axis workgroup fold width.let {{ name }} = gid.x + gid.y * {{ DISPATCH_FOLD_WIDTH }}u * {{ wgTerm }};if ({{ name }} >= {{ bound }}) {return;}{% endmacro %}{{ env.wgsl.resourceDeclarations }}{% if strided %}{% set stridedAxisUses = ["row_for_offset"] %}
10 unmodified lines111213141516171819202145 unmodified lines6768697071727374757677787980818283848551 unmodified lines1371381391401411421431441451461471 unmodified line1491501511521531541555 unmodified lines1611621631641651661671685 unmodified lines17417517617717817918010 unmodified lines// f32 bias and reduction math.//// `workgroupSize` fixes the merge-tree width for this specialization.// `scalarVec4` selects scalar storage for fused bias rows only.{% macro read_vec4(c) %}vec4<f32>(x[rowBase + {{ c }}]){% endmacro %}{% macro store_vec4(value, c) %}y[rowBase + {{ c }}] = vec4<{{ scalar }}>({{ value }});{% endmacro %}const WG: u32 = {{ workgroupSize }}u;// FLT_MAX, not -inf, as the online (m, d) accumulator init: merges must keep45 unmodified linesvar<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 +inf// element made exp(inf - inf) = NaN stick in that lane's d; a NaN element// landed in d via exp(NaN); both survive the merge and are detected by the// code after the reduction.let sgD = subgroupAdd(d * exp_shift(m, sgM));if (sgSize == WG) {return vec2<f32>(sgM, sgD);}if (subgroupElect()) {partialM[lidx] = sgM;partialD[lidx] = sgD;51 unmodified linesreturn merged;}{% endif %}@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;1 unmodified linereturn;}{% if useVec4 %}let rowBase = row * params.vecCols;{% else %}let rowBase = row * params.cols;{% endif %}5 unmodified linesfor (var c = lid.x; c < params.vecCols; c = c + WG) {let v = {{ read_vec4("c") }};let mNew = max(m, max(max(v.x, v.y), max(v.z, v.w)));d = d * exp_shift(m, mNew)+ exp_shift(v.x, mNew) + exp_shift(v.y, mNew) + exp_shift(v.z, mNew) + exp_shift(v.w, mNew);m = mNew;}{% else %}5 unmodified lines}{% endif %}let rowMD = combine_partials(m, d, lid.x{% if combineSubgroups %}, sgSize{% endif %});let finalM = rowMD.x;let finalD = rowMD.y;10 unmodified lines1112131415161718192021222324252627282930313233343545 unmodified lines8182838485868788899091929351 unmodified lines1451461471481491501511521531541551561571581591601611621631641651661671681691 unmodified line1711721731741751761775 unmodified lines1831841851861871881891901911921931941951961971981995 unmodified lines20520620720820921021110 unmodified lines// f32 bias and reduction math.//// `workgroupSize` fixes the merge-tree width for this specialization.{% if scalarVec4 is defined and scalarVec4 %}// `scalarVec4` assembles guarded scalar loads into four-value arithmetic.{% else %}// `scalarVec4` selects scalar storage for fused bias rows only.{% endif %}{% set scalarVec4 = scalarVec4 if scalarVec4 is defined else false %}{% macro read_vec4(c) %}{% if scalarVec4 %}load_word(rowBase, {{ c }}){% else %}vec4<f32>(x[rowBase + {{ c }}]){% endif %}{% endmacro %}{% macro store_vec4(value, c) %}{% if scalarVec4 %}{% for i in range(4) %}if ({{ c }} * 4u + {{ i }}u < params.cols) {y[rowBase + {{ c }} * 4u + {{ i }}u] = {{ scalar }}({{ value }}[{{ i }}]);}{% endfor %}{% else %}y[rowBase + {{ c }}] = vec4<{{ scalar }}>({{ value }});{% endif %}{% endmacro %}const WG: u32 = {{ workgroupSize }}u;// FLT_MAX, not -inf, as the online (m, d) accumulator init: merges must keep45 unmodified linesvar<workgroup> leaderMask: array<atomic<u32>, (WG + 31u) / 32u>;var<workgroup> combinedMD: vec2<f32>;fn combine_partials(m: f32, d: f32, lidx: u32) -> vec2<f32> {let sgM = subgroupMax(m);// A lane with no elements contributes d == 0 (exact identity). A +inf// element made exp(inf - inf) = NaN stick in that lane's d; a NaN element// landed in d via exp(NaN); both survive the merge and are detected by the// code after the reduction.let sgD = subgroupAdd(d * exp_shift(m, sgM));if (subgroupElect()) {partialM[lidx] = sgM;partialD[lidx] = sgD;51 unmodified linesreturn merged;}{% endif %}{% if useVec4 and scalarVec4 %}fn load_word(rowBase: u32, c: u32) -> vec4<f32> {let col = c * 4u;if (col + 3u < params.cols) {return vec4<f32>({% for i in range(4) %}f32(x[rowBase + col + {{ i }}u]){% if not loop.last %}, {% endif %}{% endfor %});}var v = vec4<f32>(-FLT_MAX);{% for i in range(4) %}if (col + {{ i }}u < params.cols) {v[{{ i }}] = f32(x[rowBase + col + {{ i }}u]);}{% endfor %}return v;}{% endif %}@compute @workgroup_size({{ workgroupSize }})fn main(@builtin(workgroup_id) wid: vec3<u32>,@builtin(local_invocation_id) lid: vec3<u32>) {// 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;1 unmodified linereturn;}{% if useVec4 %}let rowBase = row * params.{% if scalarVec4 %}cols{% else %}vecCols{% endif %};{% else %}let rowBase = row * params.cols;{% endif %}5 unmodified linesfor (var c = lid.x; c < params.vecCols; c = c + WG) {let v = {{ read_vec4("c") }};let mNew = max(m, max(max(v.x, v.y), max(v.z, v.w)));{% if scalarVec4 %}// Padding is an identity even when valid values equal -FLT_MAX.// Its exponential must contribute zero, not exp(0).let valid = vec4<u32>(c * 4u) + vec4<u32>(0u, 1u, 2u, 3u) < vec4<u32>(params.cols);let terms = vec4<f32>(exp_shift(v.x, mNew), exp_shift(v.y, mNew), exp_shift(v.z, mNew), exp_shift(v.w, mNew));let masked = select(vec4<f32>(0.0), terms, valid);d = d * exp_shift(m, mNew) + masked.x + masked.y + masked.z + masked.w;{% else %}d = d * exp_shift(m, mNew)+ exp_shift(v.x, mNew) + exp_shift(v.y, mNew) + exp_shift(v.z, mNew) + exp_shift(v.w, mNew);{% endif %}m = mNew;}{% else %}5 unmodified lines}{% endif %}let rowMD = combine_partials(m, d, lid.x);let finalM = rowMD.x;let finalD = rowMD.y;
88 unmodified lines899091929394959697989910010110210388 unmodified lines{% if op == "max" or op == "min" %}{{ a }}[{{ idx }}] = {{ op }}({{ a }}[{{ idx }}], {{ a }}[{{ idx }} + {{ svar }}]);{% else %}{{ a }}[{{ idx }}] = {{ a }}[{{ idx }}] {{ "*" if op == "prod" else "+" }} {{ a }}[{{ idx }} + {{ svar }}];{% endif %}{% endmacro %}{% macro wgsl_tree_fold(arrays, op="add", idx="lid", wg="WORKGROUP_SIZE", svar="stride", typed=false, form="tail", breakInline=false, bodyInline=false, barrierFirst=false, reuse=false) %}var {{ svar }}{{ ": u32 " if typed else " " }}= {{ wg }} / 2u;loop {if ({{ svar }} == 0u) { break; }if ({{ idx }} < {{ svar }}) { {{ wgsl_tree_fold_stmt(arrays[0], op, idx, svar) }} }{{ svar }} = {{ svar }} / 2u;workgroupBarrier();}{% endmacro %}{{ wgsl_tree_fold(["partial"], op=stage, idx="tid", wg="WGS", typed=true, form="head", breakInline=true, bodyInline=true) }}return partial[0];}88 unmodified lines899091929394959697989910010110210310410510610710810988 unmodified lines{% if op == "max" or op == "min" %}{{ a }}[{{ idx }}] = {{ op }}({{ a }}[{{ idx }}], {{ a }}[{{ idx }} + {{ svar }}]);{% else %}{{ a }}[{{ idx }}] = {{ a }}[{{ idx }}] {{ "*" if op == "prod" else "+" }} {{ a }}[{{ idx }} + {{ svar }}];{% endif %}{% endmacro %}{% macro wgsl_tree_fold(arrays, op="add", idx="lid", wg="WORKGROUP_SIZE", svar="stride", typed=false, form="tail", barrierFirst=false, reuse=false) %}var {{ svar }}{{ ": u32 " if typed else " " }}= {{ wg }} / 2u;loop {if ({{ svar }} == 0u) {break;}if ({{ idx }} < {{ svar }}) {{% for a in arrays %}{{ wgsl_tree_fold_stmt(a, op, idx, svar) }}{% endfor %}}{{ svar }} = {{ svar }} / 2u;workgroupBarrier();}{% endmacro %}{{ wgsl_tree_fold(["partial"], op=stage, idx="tid", wg="WGS", typed=true, form="head") }}return partial[0];}
85 unmodified lines8687888990919293949585 unmodified linesbreak;}}// The default trailing barrier makes this helper safe for back-to-back calls: every lane reads// slot 0 here, so the next call's first store must not run until all lanes have read it.// `trailingBarrier=false` is safe only when the buffer is never written again before kernel exit.let reduced = {{ buffer }}[0];workgroupBarrier();return reduced;}85 unmodified lines86878889909192939485 unmodified linesbreak;}}let reduced = {{ buffer }}[0];// Every lane reads slot 0 above, so a following reduction's first store must not run until// all lanes have read it.workgroupBarrier();return reduced;}
1 unmodified line2345678974 unmodified lines8485868788899091929394959697981 unmodified line1001011021031041051061071 unmodified line1091101111121131141 unmodified line1161171181191201211221231241251261271288 unmodified lines1371381391401411421439 unmodified lines1531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871 unmodified line// 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 axisLanes = (256 / tileCols) | int %}{{ env.wgsl.resourceDeclarations }}74 unmodified linesreturn select(value - maxValue, 0.0, equalFiniteMax);}{% set negInit = "-FLT_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 %}1 unmodified lineconst TILE_COLS: u32 = {{ tileCols }}u;const AXIS_LANES: u32 = {{ axisLanes }}u;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>,1 unmodified linelet 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 }};1 unmodified lineif (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 }};8 unmodified linesif (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 %}9 unmodified lines{% endif %}part_max[lid.y * TILE_COLS + lid.x] = lane_max;part_sum[lid.y * TILE_COLS + lid.x] = lane_sum;workgroupBarrier();// One lane per column merges the axis partials serially, in the same// (max, rescale, add) form as the walk above: an empty partial// ({{ negInit }}, 0) is the identity, a NaN partial poisons the sum the// way a NaN element does, and +Inf carries into the merged max.if (lid.y == 0u) {var merged_max = part_max[lid.x];var merged_sum = part_sum[lid.x];for (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;}workgroupBarrier();let row_max = part_max[lid.x];let row_sum = part_sum[lid.x];let sum_bits = bitcast<u32>(row_sum);let sum_is_nan = (sum_bits & 0x7f800000u) == 0x7f800000u && (sum_bits & 0x007fffffu) != 0u;if (row_live) {for (var k = lid.y; k < REDUCE_SIZE; k += AXIS_LANES) {let offset = element_offset(row, k);var out = shifted_value(f32(x[offset]), row_max) - log(row_sum);if (row_max > FLT_MAX || sum_is_nan) {out = bitcast<f32>(bitcast<u32>(row_sum) | 0x7fc00000u);}y[offset] = {{ T }}(out);}1 unmodified line2345678974 unmodified lines848586878889909192939495969798991001011021031041051 unmodified line1071081091101111121131141151161171181191201211 unmodified line1231241251261271281291 unmodified line1311321331341351361371381391401411421431441451461471481498 unmodified lines1581591601611621631641651661671689 unmodified lines1781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142151 unmodified line// 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 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 axisLanes = (256 / tileCols) | int %}{{ env.wgsl.resourceDeclarations }}74 unmodified linesreturn select(value - maxValue, 0.0, equalFiniteMax);}{% set negInit = "-FLT_MAX" %}fn finite_exp_difference(value: f32, maximum: f32) -> f32 {if (value == maximum) { return 1.0; }// A separation beyond 128 rounds exp to zero even with f32 subnormals.if (value < maximum - 128.0) { return 0.0; }return exp(value - maximum);}{% macro update_partial(maxName, sumName, valueName, sumValue) %}if ({{ valueName }} > {{ maxName }}) {{{ sumName }} = {{ sumName }} * finite_exp_difference({{ maxName }}, {{ valueName }}) + {{ sumValue }};{{ maxName }} = {{ valueName }};} else {{% if sumValue == "1.0" %}{{ sumName }} += finite_exp_difference({{ valueName }}, {{ maxName }});{% else %}{{ sumName }} += {{ sumValue }} * finite_exp_difference({{ valueName }}, {{ maxName }});{% endif %}}{% endmacro %}1 unmodified lineconst TILE_COLS: u32 = {{ tileCols }}u;const AXIS_LANES: u32 = {{ axisLanes }}u;fn nonfinite_input_flags(value: f32) -> u32 {let bits = bitcast<u32>(value);let nan = (bits & 0x7fffffffu) > 0x7f800000u;return select(0u, 1u, nan) | select(0u, 2u, bits == 0x7f800000u);}var<workgroup> part_max: array<f32, TILE_COLS * AXIS_LANES>;var<workgroup> part_sum: array<f32, TILE_COLS * AXIS_LANES>;var<workgroup> part_flags: array<u32, TILE_COLS * AXIS_LANES>;@compute @workgroup_size(TILE_COLS, AXIS_LANES, 1)fn main(@builtin(workgroup_id) wg: vec3<u32>,1 unmodified linelet tile = wg.x + wg.y * {{ DISPATCH_FOLD_WIDTH }}u;let row = tile * TILE_COLS + lid.x;let row_live = row < STRIDED_ROWS;var lane_flags = 0u;{% if onlineStreams == 1 %}var lane_max = {{ negInit }};1 unmodified lineif (row_live) {for (var k = lid.y; k < REDUCE_SIZE; k += AXIS_LANES) {let value = f32(x[element_offset(row, k)]);// -Inf adds exactly 0 and never raises the max; skipping it by its bits// keeps exp(-Inf - max), which WGSL leaves indeterminate, out of the sum.let input_flags = nonfinite_input_flags(value);lane_flags |= input_flags;if (input_flags == 0u && bitcast<u32>(value) != 0xff800000u) {{{ update_partial("lane_max", "lane_sum", "value", "1.0") }}}}}{% else %}{% set streamCount = onlineStreams %}// Independent online streams expose several exp/accumulate dependency// chains per invocation; the axis-lane partition is the same as with one stream.{% for stream in range(streamCount) %}var stream_max_{{ stream }} = {{ negInit }};8 unmodified linesif (k < REDUCE_SIZE) {{% endif %}let value = f32(x[element_offset(row, k)]);let input_flags = nonfinite_input_flags(value);lane_flags |= input_flags;if (input_flags == 0u && bitcast<u32>(value) != 0xff800000u) {{{ update_partial("stream_max_" ~ stream, "stream_sum_" ~ stream, "value", "1.0") }}}{% if xShape[axisSpec] % (axisLanes * streamCount) != 0 %}}{% endif %}9 unmodified lines{% endif %}part_max[lid.y * TILE_COLS + lid.x] = lane_max;part_sum[lid.y * TILE_COLS + lid.x] = lane_sum;part_flags[lid.y * TILE_COLS + lid.x] = lane_flags;workgroupBarrier();// One lane per column merges the axis partials serially, in the same// (max, rescale, add) form as the walk above: an empty partial// ({{ negInit }}, 0) is the numeric identity. Inf/NaN membership// is folded separately so exp/rescale never carries row-poison flags.if (lid.y == 0u) {var merged_max = part_max[lid.x];var merged_sum = part_sum[lid.x];var merged_flags = part_flags[lid.x];for (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];merged_flags |= part_flags[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;part_flags[lid.x] = merged_flags;}workgroupBarrier();let row_max = part_max[lid.x];let row_sum = part_sum[lid.x];let row_flags = part_flags[lid.x];if (row_live) {for (var k = lid.y; k < REDUCE_SIZE; k += AXIS_LANES) {let offset = element_offset(row, k);var out = bitcast<f32>(row_flags | 0x7fc00000u);if (row_flags == 0u && row_sum != 0.0) {out = shifted_value(f32(x[offset]), row_max) - log(row_sum);}y[offset] = {{ T }}(out);}
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120{{ env.wgsl.resourceDeclarations }}{% set stridedAxisUses = ["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 %}{% set usesRowForOffset = usesAll or "row_for_offset" in stridedAxisUses %}{% set usesReduceSize = usesAll or usesElementOffset or "REDUCE_SIZE" in stridedAxisUses %}{% set usesInnerSize = usesAll or usesElementOffset or "INNER_SIZE" in stridedAxisUses %}{% set usesStridedRows = usesAll or "STRIDED_ROWS" in stridedAxisUses %}{% set usesInnerSizeSafe = usesAll or usesElementOffset or usesRowForOffset or "INNER_SIZE_SAFE" in stridedAxisUses %}{% set usesAxisStrideSafe = usesAll or usesRowForOffset or "AXIS_STRIDE_SAFE" in stridedAxisUses %}{% if usesReduceSize %}const REDUCE_SIZE: u32 = {{ reduce_size }}u;{% endif %}{% if usesInnerSize %}const INNER_SIZE: u32 = {{ inner_size.value }}u;{% endif %}{% if usesStridedRows %}// Total one-per-row workgroup count (product of every non-axis dim). Lets the// row-wise reduce kernels 2D-fold their dispatch past the maxComputeWorkgroupsPerDimension limit and guard// the over-dispatched tail without a runtime `params` uniform.const STRIDED_ROWS: u32 = {{ outer_size.value * inner_size.value }}u;{% endif %}{% if usesInnerSizeSafe %}const INNER_SIZE_SAFE: u32 = {{ inner_size.value if inner_size.value > 0 else 1 }}u;{% endif %}{% if usesAxisStrideSafe %}const AXIS_STRIDE_SAFE: u32 = {{ (reduce_size * inner_size.value) if (reduce_size * inner_size.value) > 0 else 1 }}u;{% endif %}{% if usesElementOffset %}
// Flat offset of element k (along the reduce axis) of `row`.fn element_offset(row: u32, k: u32) -> u32 { let outer = row / INNER_SIZE_SAFE; let inner = row % INNER_SIZE_SAFE; return outer * REDUCE_SIZE * INNER_SIZE + k * INNER_SIZE + inner;}{% endif %}{% if usesRowForOffset %}
// Row that owns the flat element `offset` (inverse of element_offset over// the non-axis coordinates).fn row_for_offset(offset: u32) -> u32 { let outer = offset / AXIS_STRIDE_SAFE; let inner = offset % INNER_SIZE_SAFE; return outer * INNER_SIZE_SAFE + inner;}{% endif %}const COLS: u32 = {{ sliceTile }}u;const LANES: u32 = {{ reductionLanes }}u;const ITEMS: u32 = {{ itemsPerLane }}u;var<workgroup> partial: array<u32, {{ tileThreads }}>;
fn order_key(x: f32) -> u32 { let bits = bitcast<u32>(x); let key = select(~bits, bits ^ 0x80000000u, (bits & 0x80000000u) == 0u); return select(key, 0xffffffffu, (bits & 0x7fffffffu) > 0x7f800000u);}
@compute @workgroup_size(COLS, LANES)fn main(@builtin(workgroup_id) group: vec3<u32>, @builtin(local_invocation_id) lid: vec3<u32>, @builtin(local_invocation_index) lane: u32) { let row = group.x * COLS + lid.x;{% if needsRowMask %} let base = element_offset(min(row, {{ axisRows - 1 }}u), lid.y);{% else %} let base = element_offset(row, lid.y);{% endif %} const STEP: u32 = LANES * INNER_SIZE; var values: array<f32, ITEMS>; // The ordering places NaN above +infinity and preserves the sign of finite values. var maxKey = 0x007fffffu; for (var i = 0u; i < ITEMS; i++) { let value = f32(x[base + i * STEP]); values[i] = value; maxKey = max(maxKey, order_key(value)); } partial[lane] = maxKey; workgroupBarrier(); if (lid.y == 0u) { for (var y = 1u; y < LANES; y++) { maxKey = max(maxKey, partial[y * COLS + lid.x]); } partial[lid.x] = maxKey; } workgroupBarrier(); let key = partial[lid.x]; let maximum = bitcast<f32>(select(~key, key ^ 0x80000000u, (key & 0x80000000u) != 0u)); let finite = key > 0x007fffffu && key < 0xff800000u; var sum = 0.0; if (finite) { for (var i = 0u; i < ITEMS; i++) { let v = values[i]; // Exponents below -128 round to zero. Guard the subtraction for opposite extremes. var w = 0.0; if (v >= maximum - 128.0 && bitcast<u32>(v) != 0xff800000u) { w = exp(v - maximum); } sum += w; } } workgroupBarrier(); partial[lane] = bitcast<u32>(sum); workgroupBarrier(); if (lid.y == 0u) { for (var y = 1u; y < LANES; y++) { sum += bitcast<f32>(partial[y * COLS + lid.x]); } partial[lid.x] = bitcast<u32>(log(max(sum, 1.0))); } workgroupBarrier();{% if needsRowMask %} if (row >= {{ axisRows }}u) { return; }{% endif %} let normalizer = bitcast<f32>(partial[lid.x]); for (var i = 0u; i < ITEMS; i++) { let shifted = select(values[i] - maximum, 0.0, values[i] == maximum); let out = shifted - normalizer; y[base + i * STEP] = {{ T }}(select(bitcast<f32>(key | 0x7fc00000u), out, finite)); }}123456789101112131432 unmodified lines4748495051525354555657585960616263646566676869707172737475767778792 unmodified lines828384858687884 unmodified lines93949596979818 unmodified lines117118119120enable 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 interpret32 unmodified linescount: u32,}fn subgroup_logical_lanes(rank: u32, count: u32) -> SubgroupLogicalLanes {// Every lane performs the atomic so no collective follows a lane guard: a// subgroup op after a closed `if (rank == 0u)` block is a reconvergence// hazard, since every subgroup operation must be reached in uniform control// flow. Only the lane-0 lane adds its subgroup's claim, every other lane// adds 0 and discards its snapshot. Lane 0 is the lowest 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_invocation_id) sgLaneId: 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(sgLaneId, sgSize);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;2 unmodified linesvar 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)));4 unmodified lines}{% 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));18 unmodified linesy[rowBase + c{{ i }}] = vec4<{{ scalar }}>(o{{ i }});}{% endfor %}}123456789101132 unmodified lines4445464748495051525354555657585960616263646566676869707172737475767778798081822 unmodified lines858687888990914 unmodified lines9697989910010110210310410510610710810911011111218 unmodified lines131132133134135136137138139140141142enable subgroups;{{ env.wgsl.resourceDeclarations }}// Each of the guaranteed minimum number of subgroups owns one row. Extra// subgroups run neutral collectives and store nothing. Dense active ranks cover// all columns; full populations retain the register tile and partial populations// stream its overflow without increasing private storage.const ROWS_PER_WORKGROUP: u32 = {{ subgroupRowsPerWorkgroup }}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 interpret32 unmodified linescount: u32,}fn subgroup_logical_lanes(lane: u32) -> SubgroupLogicalLanes {{% macro active_lanes(lane, prefix="active") %}let {{ prefix }}Mask = subgroupBallot(true);let {{ prefix }}Word = {{ lane }} / 32u;let {{ prefix }}Lower = (1u << ({{ lane }} % 32u)) - 1u;let {{ prefix }}Count = max(countOneBits({{ prefix }}Mask.x) + countOneBits({{ prefix }}Mask.y)+ countOneBits({{ prefix }}Mask.z) + countOneBits({{ prefix }}Mask.w), 1u);var {{ prefix }}Rank = countOneBits({{ prefix }}Mask[{{ prefix }}Word] & {{ prefix }}Lower);for (var word = 0u; word < {{ prefix }}Word; word++) {{{ prefix }}Rank += countOneBits({{ prefix }}Mask[word]);}{% endmacro %}{{ active_lanes("lane") }}// Dense rank zero is the first ACTIVE lane, exactly the BroadcastFirst source.// All lanes execute the atomic and collective in uniform control flow.let ticket = atomicAdd(&sgLaneClaims, select(0u, activeCount | (1u << 16u), activeRank == 0u));let claim = subgroupBroadcastFirst(ticket);return SubgroupLogicalLanes((claim & 0xffffu) + activeRank, claim >> 16u, activeRank, activeCount);}@compute @workgroup_size({{ workgroupSize }})fn main(@builtin(workgroup_id) wid: vec3<u32>,@builtin(subgroup_invocation_id) sgLaneId: 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(sgLaneId);let sgLane = L.rank;let row = (wid.x + wid.y * {{ DISPATCH_FOLD_WIDTH }}u) * ROWS_PER_WORKGROUP + 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 = L.ord < ROWS_PER_WORKGROUP && row < params.rows;let vecLimit = select(0u, params.vecCols, rowValid);let rowBase = row * params.vecCols;2 unmodified linesvar d = 0.0;{% for i in range(vecsPerLane) %}var v{{ i }} = vec4<f32>(0.0);let c{{ i }} = sgLane + {{ i }}u * L.count;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)));4 unmodified lines}{% endfor %}// Partial subgroups may need more words than the full-population register tile.// Process that tile as for a full population and stream only its tail.for (var col = sgLane + {{ vecsPerLane }}u * L.count; col < vecLimit; col += L.count) {let value = vec4<f32>(x[rowBase + col]);let mNew = max(m, max(max(value.x, value.y), max(value.z, value.w)));d = d * exp_shift(m, mNew)+ exp_shift(value.x, mNew) + exp_shift(value.y, mNew)+ exp_shift(value.z, mNew) + exp_shift(value.w, mNew);m = mNew;}// Subgroup merge: a lane with no words contributes d == 0 (exact identity).let finalM = subgroupMax(m);let finalD = subgroupAdd(d * exp_shift(m, finalM));18 unmodified linesy[rowBase + c{{ i }}] = vec4<{{ scalar }}>(o{{ i }});}{% endfor %}for (var col = sgLane + {{ vecsPerLane }}u * L.count; col < vecLimit; col += L.count) {let value = vec4<f32>(x[rowBase + col]);var result = vec4<f32>(shifted_value(value.x, finalM), shifted_value(value.y, finalM),shifted_value(value.z, finalM), shifted_value(value.w, finalM)) - logD;if (rowIsNan) { result = vec4<f32>(nanOut); }y[rowBase + col] = vec4<{{ scalar }}>(result);}}
README.md+37-25
build/webgpu/bench.json+159-53
build/webgpu/manifest.json+1-530
build/webgpu/metadata.json+1-44
build/webgpu/softmax-normalize.wgsl.jinja+3-2
build/webgpu/softmax-online.wgsl.jinja+43-12
build/webgpu/softmax-row-stage-strided-vec4.wgsl.jinja+10-4
build/webgpu/softmax-row-stage.wgsl.jinja+2-3
build/webgpu/softmax-strided-online-coop.wgsl.jinja+41-13
build/webgpu/softmax-strided-resident.wgsl.jinjaAdded+120
build/webgpu/softmax-subgroup-rows.wgsl.jinja+46-24
build/webgpu/test.json