Xenova HF Staff commited on
Commit
bfb3ab3
·
verified ·
1 Parent(s): 4eec196

sync 4385228f788d

Browse files
README.md CHANGED
@@ -56,47 +56,54 @@ Default values (overridable per request):
56
 
57
  One implementation is selected per call from the device capabilities, the request shapes and the dtypes; these notes say what each one covers.
58
 
59
- - `unit_plain` — Direct single-token sequence convolution with contiguous vector state traffic and fused capture writes. Strictly increasing schedules with `total_tokens == batch_size` imply one token per sequence. Channel divisibility selects the vector width; the workgroup respects device limits. Dilated and f16 requests retain their existing paths.
60
- - `unit_bias` — Direct single-token sequence convolution with contiguous vector state traffic and fused capture writes. Strictly increasing schedules with `total_tokens == batch_size` imply one token per sequence. Channel divisibility selects the vector width; the workgroup respects device limits. Dilated and f16 requests retain their existing paths.
61
- - `unit_state_update` — Direct single-token sequence convolution with contiguous vector state traffic and fused capture writes. Strictly increasing schedules with `total_tokens == batch_size` imply one token per sequence. Channel divisibility selects the vector width; the workgroup respects device limits. Dilated and f16 requests retain their existing paths.
62
- - `unit_bias_state_update` — Direct single-token sequence convolution with contiguous vector state traffic and fused capture writes. Strictly increasing schedules with `total_tokens == batch_size` imply one token per sequence. Channel divisibility selects the vector width; the workgroup respects device limits. Dilated and f16 requests retain their existing paths.
63
- - `capture_copy_state_update_stream` — Copy the capture prefix in contiguous channel vectors while preserving the convolution path and exact zero-fill semantics. The existing copy template operates on vector groups; no extra storage bindings or optional GPU features are needed.
64
- - `capture_copy_state_update` — Copy the capture prefix in contiguous channel vectors while preserving the convolution path and exact zero-fill semantics. The existing copy template operates on vector groups; no extra storage bindings or optional GPU features are needed.
65
- - `capture_copy_bias_state_update_stream` — Copy the capture prefix in contiguous channel vectors while preserving the convolution path and exact zero-fill semantics. The existing copy template operates on vector groups; no extra storage bindings or optional GPU features are needed.
66
- - `capture_copy_bias_state_update` — Copy the capture prefix in contiguous channel vectors while preserving the convolution path and exact zero-fill semantics. The existing copy template operates on vector groups; no extra storage bindings or optional GPU features are needed.
67
 
68
  ## Files
69
 
70
- - [`metadata.json`](build/webgpu/metadata.json) — kernel metadata (id, digests, per-variant templates, provenance)
71
- - [`manifest.json`](build/webgpu/manifest.json) — the op contract (source of truth)
72
- - [`test.json`](build/webgpu/test.json) — correctness cases
73
- - [`bench.json`](build/webgpu/bench.json) — benchmark cases
74
- - [`varlen-causal-conv-stream.wgsl.jinja`](build/webgpu/varlen-causal-conv-stream.wgsl.jinja)
75
- - [`varlen-causal-conv.wgsl.jinja`](build/webgpu/varlen-causal-conv.wgsl.jinja)
76
- - [`varlen-state-update.wgsl.jinja`](build/webgpu/varlen-state-update.wgsl.jinja)
77
- - [`varlen-unit-sequence.wgsl.jinja`](build/webgpu/varlen-unit-sequence.wgsl.jinja)
78
 
79
  ## Use with `@huggingface/kernels`
80
 
81
  ```sh
82
- npm install --save-exact @huggingface/kernels@0.0.1-preview.3
83
  ```
84
 
 
 
85
  Required output shapes and logical data types are inferred from the supplied inputs and attributes; result tensors are allocated automatically.
86
 
87
  The `version: 1` option selects the published kernel contract; it is independent of any operator opset, contrib `since_version`, or model version.
88
  It follows the `v1` branch as fixes land. To pin exact artifact bytes, pass a 40-character commit `revision` instead of `version`.
89
 
90
- Replace each `*Data` placeholder with a typed array containing the corresponding input data.
91
-
92
  ```js
93
  import { getKernel } from "@huggingface/kernels";
94
 
95
  const kernel = await getKernel("webgpu-kernels/com.microsoft.VarlenCausalConvWithState", { version: 1 });
 
 
 
 
 
 
 
 
 
 
 
96
  const { outputT, finalStateT } = await kernel({
97
  inputT: { data: inputTData, shape: [1, 4] },
98
  weightT: { data: weightTData, shape: [4, 1, 4] },
99
  cumulativeSequenceLengthT: { data: cumulativeSequenceLengthTData, shape: [2] },
100
  initialStateT: { data: initialStateTData, shape: [1, 4, 3] },
101
  });
 
102
  ```
 
56
 
57
  One implementation is selected per call from the device capabilities, the request shapes and the dtypes; these notes say what each one covers.
58
 
59
+ - `unit` — Direct single-token sequence convolution with contiguous vector state traffic and fused capture writes. Strictly increasing schedules with `total_tokens == batch_size` imply one token per sequence. Channel divisibility selects the vector width; the workgroup respects device limits. Dilated and f16 requests use other variants.
60
+ - `capture_copy_stream` — Writes the `state_update` slots in a separate pass over contiguous 2- or 4-channel vectors, zero-filling inactive slots, then convolves with the streaming pass: one invocation walks a block of consecutive tokens of one channel. Requires float32, an even channel count, dilation 1 and kernel size 2 to 8.
61
+ - `capture_copy` — Writes the `state_update` slots in a separate pass over contiguous 2- or 4-channel vectors, zero-filling inactive slots, then convolves with one invocation per output element. Requires float32 and an even channel count.
 
 
 
 
 
62
 
63
  ## Files
64
 
65
+ - [`metadata.json`](https://huggingface.co/kernels/webgpu-kernels/com.microsoft.VarlenCausalConvWithState/blob/v1/build/webgpu/metadata.json) — kernel metadata (id, file digests, manifest spec, provenance)
66
+ - [`manifest.json`](https://huggingface.co/kernels/webgpu-kernels/com.microsoft.VarlenCausalConvWithState/blob/v1/build/webgpu/manifest.json) — the op contract (source of truth)
67
+ - [`test.json`](https://huggingface.co/kernels/webgpu-kernels/com.microsoft.VarlenCausalConvWithState/blob/v1/build/webgpu/test.json) — correctness cases
68
+ - [`bench.json`](https://huggingface.co/kernels/webgpu-kernels/com.microsoft.VarlenCausalConvWithState/blob/v1/build/webgpu/bench.json) — benchmark cases
69
+ - [`varlen-causal-conv-stream.wgsl.jinja`](https://huggingface.co/kernels/webgpu-kernels/com.microsoft.VarlenCausalConvWithState/blob/v1/build/webgpu/varlen-causal-conv-stream.wgsl.jinja)
70
+ - [`varlen-causal-conv.wgsl.jinja`](https://huggingface.co/kernels/webgpu-kernels/com.microsoft.VarlenCausalConvWithState/blob/v1/build/webgpu/varlen-causal-conv.wgsl.jinja)
71
+ - [`varlen-state-update.wgsl.jinja`](https://huggingface.co/kernels/webgpu-kernels/com.microsoft.VarlenCausalConvWithState/blob/v1/build/webgpu/varlen-state-update.wgsl.jinja)
72
+ - [`varlen-unit-sequence.wgsl.jinja`](https://huggingface.co/kernels/webgpu-kernels/com.microsoft.VarlenCausalConvWithState/blob/v1/build/webgpu/varlen-unit-sequence.wgsl.jinja)
73
 
74
  ## Use with `@huggingface/kernels`
75
 
76
  ```sh
77
+ npm install --save-exact @huggingface/kernels@0.0.1-preview.4
78
  ```
79
 
80
+ Paste the example into a browser app that resolves npm imports. Serve the app over HTTPS or localhost with WebGPU available.
81
+
82
  Required output shapes and logical data types are inferred from the supplied inputs and attributes; result tensors are allocated automatically.
83
 
84
  The `version: 1` option selects the published kernel contract; it is independent of any operator opset, contrib `since_version`, or model version.
85
  It follows the `v1` branch as fixes land. To pin exact artifact bytes, pass a 40-character commit `revision` instead of `version`.
86
 
 
 
87
  ```js
88
  import { getKernel } from "@huggingface/kernels";
89
 
90
  const kernel = await getKernel("webgpu-kernels/com.microsoft.VarlenCausalConvWithState", { version: 1 });
91
+
92
+ const inputTData = Float32Array.of(-1.125, -1.0625, -1, -0.9375);
93
+ const weightTData = Float32Array.of(
94
+ -0.28125, -0.25, -0.21875, -0.1875, -0.15625, -0.125, -0.09375, -0.0625, -0.03125, 0,
95
+ 0.03125, 0.0625, 0.09375, 0.125, 0.15625, 0.1875,
96
+ );
97
+ const cumulativeSequenceLengthTData = Int32Array.of(0, 1);
98
+ const initialStateTData = Float32Array.of(
99
+ -1.375, -1.25, -1.125, -1, -0.875, -0.75, -0.625, -0.5, -0.375, -0.25, -0.125, 0,
100
+ );
101
+
102
  const { outputT, finalStateT } = await kernel({
103
  inputT: { data: inputTData, shape: [1, 4] },
104
  weightT: { data: weightTData, shape: [4, 1, 4] },
105
  cumulativeSequenceLengthT: { data: cumulativeSequenceLengthTData, shape: [2] },
106
  initialStateT: { data: initialStateTData, shape: [1, 4, 3] },
107
  });
108
+ console.log({ outputT, finalStateT });
109
  ```
build/webgpu/bench.json CHANGED
@@ -4,9 +4,6 @@
4
  "streamWorkgroupSize": [64, 128, 256],
5
  "streamChunk": [16, 32, 64, 128, 256]
6
  },
7
- "fixtureArrays": {
8
- "varlenconv-unit-capture-b64-c4096-k4-cap4_input_captureCountT": [2, 0, -3, 99, 2, 0, -3, 99, 2, 0, -3, 99, 2, 0, -3, 99, 2, 0, -3, 99, 2, 0, -3, 99, 2, 0, -3, 99, 2, 0, -3, 99, 2, 0, -3, 99, 2, 0, -3, 99, 2, 0, -3, 99, 2, 0, -3, 99, 2, 0, -3, 99, 2, 0, -3, 99, 2, 0, -3, 99, 2, 0, -3, 99]
9
- },
10
  "cases": [
11
  {
12
  "name": "varlenconv-decode-b32-c4096-k4",
@@ -315,14 +312,7 @@
315
  },
316
  "biasT": { "shape": [4096], "dtype": "float32", "dist": "normal", "seed": 4102, "scale": 1 },
317
  "initialStateT": { "shape": [64, 4096, 3], "dtype": "float32", "dist": "normal", "seed": 4103, "scale": 1 },
318
- "captureCountT": {
319
- "dtype": "int32",
320
- "shape": [64],
321
- "data": {
322
- "kind": "values",
323
- "values": { "$ref": "#/fixtureArrays/varlenconv-unit-capture-b64-c4096-k4-cap4_input_captureCountT" }
324
- }
325
- }
326
  },
327
  "outputs": {
328
  "outputT": { "shape": [64, 4096], "dtype": "float32" },
@@ -358,14 +348,7 @@
358
  },
359
  "biasT": { "shape": [4098], "dtype": "float32", "dist": "normal", "seed": 4102, "scale": 1 },
360
  "initialStateT": { "shape": [64, 4098, 2], "dtype": "float32", "dist": "normal", "seed": 4103, "scale": 1 },
361
- "captureCountT": {
362
- "dtype": "int32",
363
- "shape": [64],
364
- "data": {
365
- "kind": "values",
366
- "values": { "$ref": "#/fixtureArrays/varlenconv-unit-capture-b64-c4096-k4-cap4_input_captureCountT" }
367
- }
368
- }
369
  },
370
  "outputs": {
371
  "outputT": { "shape": [64, 4098], "dtype": "float32" },
@@ -401,14 +384,7 @@
401
  },
402
  "biasT": { "shape": [4097], "dtype": "float32", "dist": "normal", "seed": 4102, "scale": 1 },
403
  "initialStateT": { "shape": [64, 4097, 7], "dtype": "float32", "dist": "normal", "seed": 4103, "scale": 1 },
404
- "captureCountT": {
405
- "dtype": "int32",
406
- "shape": [64],
407
- "data": {
408
- "kind": "values",
409
- "values": { "$ref": "#/fixtureArrays/varlenconv-unit-capture-b64-c4096-k4-cap4_input_captureCountT" }
410
- }
411
- }
412
  },
413
  "outputs": {
414
  "outputT": { "shape": [64, 4097], "dtype": "float32" },
@@ -444,14 +420,7 @@
444
  },
445
  "biasT": { "shape": [4096], "dtype": "float32", "dist": "normal", "seed": 4102, "scale": 1 },
446
  "initialStateT": { "shape": [64, 4096, 3], "dtype": "float32", "dist": "normal", "seed": 4103, "scale": 1 },
447
- "captureCountT": {
448
- "dtype": "int32",
449
- "shape": [64],
450
- "data": {
451
- "kind": "values",
452
- "values": { "$ref": "#/fixtureArrays/varlenconv-unit-capture-b64-c4096-k4-cap4_input_captureCountT" }
453
- }
454
- }
455
  },
456
  "outputs": {
457
  "outputT": { "shape": [128, 4096], "dtype": "float32" },
@@ -487,14 +456,7 @@
487
  },
488
  "biasT": { "shape": [4096], "dtype": "float32", "dist": "normal", "seed": 4102, "scale": 1 },
489
  "initialStateT": { "shape": [64, 4096, 6], "dtype": "float32", "dist": "normal", "seed": 4103, "scale": 1 },
490
- "captureCountT": {
491
- "dtype": "int32",
492
- "shape": [64],
493
- "data": {
494
- "kind": "values",
495
- "values": { "$ref": "#/fixtureArrays/varlenconv-unit-capture-b64-c4096-k4-cap4_input_captureCountT" }
496
- }
497
- }
498
  },
499
  "outputs": {
500
  "outputT": { "shape": [128, 4096], "dtype": "float32" },
 
4
  "streamWorkgroupSize": [64, 128, 256],
5
  "streamChunk": [16, 32, 64, 128, 256]
6
  },
 
 
 
7
  "cases": [
8
  {
9
  "name": "varlenconv-decode-b32-c4096-k4",
 
312
  },
313
  "biasT": { "shape": [4096], "dtype": "float32", "dist": "normal", "seed": 4102, "scale": 1 },
314
  "initialStateT": { "shape": [64, 4096, 3], "dtype": "float32", "dist": "normal", "seed": 4103, "scale": 1 },
315
+ "captureCountT": { "dtype": "int32", "shape": [64], "data": { "kind": "cycle", "values": [2, 0, -3, 99] } }
 
 
 
 
 
 
 
316
  },
317
  "outputs": {
318
  "outputT": { "shape": [64, 4096], "dtype": "float32" },
 
348
  },
349
  "biasT": { "shape": [4098], "dtype": "float32", "dist": "normal", "seed": 4102, "scale": 1 },
350
  "initialStateT": { "shape": [64, 4098, 2], "dtype": "float32", "dist": "normal", "seed": 4103, "scale": 1 },
351
+ "captureCountT": { "dtype": "int32", "shape": [64], "data": { "kind": "cycle", "values": [2, 0, -3, 99] } }
 
 
 
 
 
 
 
352
  },
353
  "outputs": {
354
  "outputT": { "shape": [64, 4098], "dtype": "float32" },
 
384
  },
385
  "biasT": { "shape": [4097], "dtype": "float32", "dist": "normal", "seed": 4102, "scale": 1 },
386
  "initialStateT": { "shape": [64, 4097, 7], "dtype": "float32", "dist": "normal", "seed": 4103, "scale": 1 },
387
+ "captureCountT": { "dtype": "int32", "shape": [64], "data": { "kind": "cycle", "values": [2, 0, -3, 99] } }
 
 
 
 
 
 
 
388
  },
389
  "outputs": {
390
  "outputT": { "shape": [64, 4097], "dtype": "float32" },
 
420
  },
421
  "biasT": { "shape": [4096], "dtype": "float32", "dist": "normal", "seed": 4102, "scale": 1 },
422
  "initialStateT": { "shape": [64, 4096, 3], "dtype": "float32", "dist": "normal", "seed": 4103, "scale": 1 },
423
+ "captureCountT": { "dtype": "int32", "shape": [64], "data": { "kind": "cycle", "values": [2, 0, -3, 99] } }
 
 
 
 
 
 
 
424
  },
425
  "outputs": {
426
  "outputT": { "shape": [128, 4096], "dtype": "float32" },
 
456
  },
457
  "biasT": { "shape": [4096], "dtype": "float32", "dist": "normal", "seed": 4102, "scale": 1 },
458
  "initialStateT": { "shape": [64, 4096, 6], "dtype": "float32", "dist": "normal", "seed": 4103, "scale": 1 },
459
+ "captureCountT": { "dtype": "int32", "shape": [64], "data": { "kind": "cycle", "values": [2, 0, -3, 99] } }
 
 
 
 
 
 
 
460
  },
461
  "outputs": {
462
  "outputT": { "shape": [128, 4096], "dtype": "float32" },
build/webgpu/manifest.json CHANGED
@@ -1,616 +1 @@
1
- {
2
- "domain": "com.microsoft",
3
- "name": "VarlenCausalConvWithState",
4
- "sinceVersion": 1,
5
- "inputs": {
6
- "inputT": { "onnx": "input", "dtype": "T", "rank": 2 },
7
- "weightT": { "onnx": "weight", "dtype": "T", "rank": 3 },
8
- "cumulativeSequenceLengthT": { "onnx": "cumulative_sequence_length", "dtype": "M", "rank": 1, "storage": "int32" },
9
- "biasT": { "onnx": "bias", "dtype": "T", "rank": 1, "optional": true },
10
- "initialStateT": { "onnx": "initial_state", "dtype": "T", "rank": 3 },
11
- "captureCountT": { "onnx": "capture_count", "dtype": "M", "rank": 1, "optional": true, "storage": "int32" }
12
- },
13
- "outputs": {
14
- "outputT": { "onnx": "output", "dtype": "T", "rank": "ranks.inputT", "shape": "shapes.inputT" },
15
- "finalStateT": { "onnx": "final_state", "dtype": "T", "rank": 3, "shape": "[batchSize, channels, stateLength]" },
16
- "stateUpdateT": {
17
- "onnx": "state_update",
18
- "dtype": "T",
19
- "rank": 3,
20
- "optional": true,
21
- "shape": "[batchSize, stateUpdateCapacity, channels]"
22
- }
23
- },
24
- "attributes": {
25
- "activation": { "default": "none" },
26
- "dilation": { "default": 1 },
27
- "state_update_capacity": { "default": 0 }
28
- },
29
- "attributeConstraints": { "activation": { "values": ["none", "silu", "swish"] } },
30
- "typeConstraints": { "T": ["float32", "float16"], "M": ["int32"] },
31
- "tunables": {
32
- "workgroupSize": { "default": 256 },
33
- "streamWorkgroupSize": { "default": 64 },
34
- "streamChunk": { "default": 16 }
35
- },
36
- "derive": {
37
- "totalTokens": "dim(shapes.inputT, 0)",
38
- "channels": "dim(shapes.inputT, 1)",
39
- "batchSize": "dim(shapes.cumulativeSequenceLengthT, 0) - 1",
40
- "weightRankOk": "ranks.weightT == 3 and dim(shapes.weightT, 1) == 1",
41
- "kernelSize": "dim(shapes.weightT, 2)",
42
- "stateLength": "(kernelSize - 1) * attrs.dilation",
43
- "stateUpdateCapacity": "attrs.state_update_capacity",
44
- "capturePairOk": "present.captureCountT == (stateUpdateCapacity > 0)",
45
- "stateShape": "ranks.initialStateT == 3 and dim(shapes.initialStateT, 0) == batchSize and dim(shapes.initialStateT, 1) == channels and dim(shapes.initialStateT, 2) == stateLength",
46
- "finalStateShape": "ranks.finalStateT == 3 and dim(shapes.finalStateT, 0) == batchSize and dim(shapes.finalStateT, 1) == channels and dim(shapes.finalStateT, 2) == stateLength",
47
- "captureShape": "not present.captureCountT or (ranks.captureCountT == 1 and dim(shapes.captureCountT, 0) == batchSize and tensorDtypes.captureCountT == \"int32\")",
48
- "stateUpdateShape": "not present.stateUpdateT or (ranks.stateUpdateT == 3 and dim(shapes.stateUpdateT, 0) == batchSize and dim(shapes.stateUpdateT, 1) == stateUpdateCapacity and dim(shapes.stateUpdateT, 2) == channels and tensorDtypes.stateUpdateT == tensorDtypes.inputT)",
49
- "commonContract": "ranks.inputT == 2 and weightRankOk and ranks.outputT == 2 and ranks.cumulativeSequenceLengthT == 1 and channels >= 1 and kernelSize >= 1 and batchSize >= 1 and totalTokens >= batchSize and stateUpdateCapacity >= 0 and stateUpdateCapacity <= 8 and floor(stateUpdateCapacity) == stateUpdateCapacity and capturePairOk and captureShape and stateUpdateShape and (tensorDtypes.inputT == \"float32\" or tensorDtypes.inputT == \"float16\") and tensorDtypes.weightT == tensorDtypes.inputT and tensorDtypes.outputT == tensorDtypes.inputT and tensorDtypes.initialStateT == tensorDtypes.inputT and tensorDtypes.finalStateT == tensorDtypes.inputT and tensorDtypes.cumulativeSequenceLengthT == \"int32\" and f16Ok(dtypes.T) and dim(shapes.weightT, 0) == channels and dim(shapes.outputT, 0) == totalTokens and dim(shapes.outputT, 1) == channels and stateShape and finalStateShape and attrs.dilation >= 1 and floor(attrs.dilation) == attrs.dilation",
50
- "biasOk": "ranks.biasT == 1 and tensorDtypes.biasT == tensorDtypes.inputT and dim(shapes.biasT, 0) == channels",
51
- "plainContract": "commonContract and not present.biasT and (not present.stateUpdateT or stateUpdateCapacity == 0)",
52
- "biasContract": "commonContract and present.biasT and biasOk and (not present.stateUpdateT or stateUpdateCapacity == 0)",
53
- "stateUpdateContract": "commonContract and not present.biasT and present.stateUpdateT and stateUpdateCapacity > 0",
54
- "biasStateUpdateContract": "commonContract and present.biasT and biasOk and present.stateUpdateT and stateUpdateCapacity > 0",
55
- "causalDilation": "attrs.dilation",
56
- "unitWg": "min(tunables.streamWorkgroupSize, device.limits.maxComputeInvocationsPerWorkgroup, device.limits.maxComputeWorkgroupSizeX)",
57
- "useSilu": "attrs.activation != \"none\""
58
- },
59
- "bindings": {
60
- "input": { "arg": "inputT", "elementType": "$inputScalar" },
61
- "weight": { "arg": "weightT", "elementType": "$inputScalar" },
62
- "cumulative_sequence_length": { "arg": "cumulativeSequenceLengthT", "elementType": "i32" },
63
- "initial_state": { "arg": "initialStateT", "elementType": "$inputScalar" },
64
- "output": { "arg": "outputT", "elementType": "$outputScalar" },
65
- "final_state": { "arg": "finalStateT", "elementType": "$outputScalar" },
66
- "params": {
67
- "struct": [
68
- { "name": "batchSize", "type": "u32", "value": "batchSize" },
69
- { "name": "channels", "type": "u32", "value": "channels" },
70
- { "name": "totalTokens", "type": "u32", "value": "totalTokens" },
71
- { "name": "kernelSize", "type": "u32", "value": "kernelSize" }
72
- ]
73
- },
74
- "bias": { "arg": "biasT", "elementType": "$inputScalar" },
75
- "capture_count": { "arg": "captureCountT", "elementType": "i32" },
76
- "state_update": { "arg": "stateUpdateT", "elementType": "$outputScalar" },
77
- "params__uniform": {
78
- "name": "params",
79
- "struct": [
80
- { "name": "batchSize", "type": "u32", "value": "batchSize" },
81
- { "name": "channels", "type": "u32", "value": "channels" },
82
- { "name": "totalTokens", "type": "u32", "value": "totalTokens" },
83
- { "name": "stateUpdateCapacity", "type": "u32", "value": "stateUpdateCapacity" }
84
- ]
85
- },
86
- "input_unit": { "arg": "inputT", "name": "input", "elementType": "$unitStorageType" },
87
- "bias_unit": { "arg": "biasT", "name": "bias", "elementType": "$unitStorageType" },
88
- "output_unit": { "arg": "outputT", "name": "output", "elementType": "$unitStorageType" },
89
- "state_update_unit": { "arg": "stateUpdateT", "name": "state_update", "elementType": "$unitStorageType" },
90
- "params_unit": {
91
- "name": "params",
92
- "struct": [
93
- { "name": "channels", "type": "u32", "value": "channels" },
94
- { "name": "totalTokens", "type": "u32", "value": "totalTokens" }
95
- ]
96
- },
97
- "weight_unit": { "arg": "weightT", "elementType": "$unitStorageType", "name": "weight" },
98
- "initial_state_unit": { "arg": "initialStateT", "elementType": "$unitStorageType", "name": "initial_state" },
99
- "final_state_unit": { "arg": "finalStateT", "elementType": "$unitStorageType", "name": "final_state" },
100
- "input_capture": { "arg": "inputT", "name": "input", "elementType": "$captureStorageType" },
101
- "state_update_capture": { "arg": "stateUpdateT", "name": "state_update", "elementType": "$captureStorageType" },
102
- "params_capture": {
103
- "name": "params",
104
- "struct": [
105
- { "name": "batchSize", "type": "u32", "value": "batchSize" },
106
- { "name": "channels", "type": "u32", "value": "channels / captureVectorWidth" },
107
- { "name": "totalTokens", "type": "u32", "value": "totalTokens" },
108
- { "name": "stateUpdateCapacity", "type": "u32", "value": "stateUpdateCapacity" }
109
- ]
110
- }
111
- },
112
- "variants": [
113
- {
114
- "id": "unit_plain",
115
- "priority": 50,
116
- "when": ["plainContract", "tensorDtypes.inputT == \"float32\"", "totalTokens == batchSize", "attrs.dilation == 1", "kernelSize >= 2", "kernelSize <= 8", "unitWg >= 1", "floor(unitWg) == unitWg"],
117
- "derive": {
118
- "hasBias": false,
119
- "hasCapture": false,
120
- "unitVectorWidth": "4 if channels % 4 == 0 else (2 if channels % 2 == 0 else 1)",
121
- "unitStorageType": "dtypes.T if unitVectorWidth == 1 else \"vec\" ~ unitVectorWidth ~ \"<\" ~ dtypes.T ~ \">\"",
122
- "unitValueType": "\"f32\" if unitVectorWidth == 1 else \"vec\" ~ unitVectorWidth ~ \"<f32>\""
123
- },
124
- "passes": [
125
- {
126
- "id": "main",
127
- "name": "VarlenCausalConvWithState.UnitSequence",
128
- "shader": "varlen-unit-sequence.wgsl.jinja",
129
- "bindings": ["input_unit", "weight_unit", "initial_state_unit", "output_unit", "final_state_unit", "params_unit"],
130
- "dispatch": {
131
- "x": "min(ceilDiv((totalTokens * channels / unitVectorWidth), (unitWg)), 65535)",
132
- "y": "ceilDiv(ceilDiv((totalTokens * channels / unitVectorWidth), (unitWg)), 65535)",
133
- "z": 1
134
- }
135
- }
136
- ]
137
- },
138
- {
139
- "id": "unit_bias",
140
- "priority": 50,
141
- "when": ["biasContract", "tensorDtypes.inputT == \"float32\"", "totalTokens == batchSize", "attrs.dilation == 1", "kernelSize >= 2", "kernelSize <= 8", "unitWg >= 1", "floor(unitWg) == unitWg"],
142
- "derive": {
143
- "hasBias": true,
144
- "hasCapture": false,
145
- "unitVectorWidth": "4 if channels % 4 == 0 else (2 if channels % 2 == 0 else 1)",
146
- "unitStorageType": "dtypes.T if unitVectorWidth == 1 else \"vec\" ~ unitVectorWidth ~ \"<\" ~ dtypes.T ~ \">\"",
147
- "unitValueType": "\"f32\" if unitVectorWidth == 1 else \"vec\" ~ unitVectorWidth ~ \"<f32>\""
148
- },
149
- "passes": [
150
- {
151
- "id": "main",
152
- "name": "VarlenCausalConvWithState.UnitSequence",
153
- "shader": "varlen-unit-sequence.wgsl.jinja",
154
- "bindings": ["input_unit", "weight_unit", "initial_state_unit", "bias_unit", "output_unit", "final_state_unit", "params_unit"],
155
- "dispatch": {
156
- "x": "min(ceilDiv((totalTokens * channels / unitVectorWidth), (unitWg)), 65535)",
157
- "y": "ceilDiv(ceilDiv((totalTokens * channels / unitVectorWidth), (unitWg)), 65535)",
158
- "z": 1
159
- }
160
- }
161
- ]
162
- },
163
- {
164
- "id": "unit_state_update",
165
- "priority": 50,
166
- "when": ["stateUpdateContract", "tensorDtypes.inputT == \"float32\"", "totalTokens == batchSize", "attrs.dilation == 1", "kernelSize >= 2", "kernelSize <= 8", "unitWg >= 1", "floor(unitWg) == unitWg"],
167
- "derive": {
168
- "hasBias": false,
169
- "hasCapture": true,
170
- "unitVectorWidth": "4 if channels % 4 == 0 else (2 if channels % 2 == 0 else 1)",
171
- "unitStorageType": "dtypes.T if unitVectorWidth == 1 else \"vec\" ~ unitVectorWidth ~ \"<\" ~ dtypes.T ~ \">\"",
172
- "unitValueType": "\"f32\" if unitVectorWidth == 1 else \"vec\" ~ unitVectorWidth ~ \"<f32>\""
173
- },
174
- "passes": [
175
- {
176
- "id": "main",
177
- "name": "VarlenCausalConvWithState.UnitSequence",
178
- "shader": "varlen-unit-sequence.wgsl.jinja",
179
- "bindings": ["input_unit", "weight_unit", "initial_state_unit", "output_unit", "final_state_unit", "params_unit", "capture_count", "state_update_unit"],
180
- "dispatch": {
181
- "x": "min(ceilDiv((totalTokens * channels / unitVectorWidth), (unitWg)), 65535)",
182
- "y": "ceilDiv(ceilDiv((totalTokens * channels / unitVectorWidth), (unitWg)), 65535)",
183
- "z": 1
184
- }
185
- }
186
- ]
187
- },
188
- {
189
- "id": "unit_bias_state_update",
190
- "priority": 50,
191
- "when": ["biasStateUpdateContract", "tensorDtypes.inputT == \"float32\"", "totalTokens == batchSize", "attrs.dilation == 1", "kernelSize >= 2", "kernelSize <= 8", "unitWg >= 1", "floor(unitWg) == unitWg"],
192
- "derive": {
193
- "hasBias": true,
194
- "hasCapture": true,
195
- "unitVectorWidth": "4 if channels % 4 == 0 else (2 if channels % 2 == 0 else 1)",
196
- "unitStorageType": "dtypes.T if unitVectorWidth == 1 else \"vec\" ~ unitVectorWidth ~ \"<\" ~ dtypes.T ~ \">\"",
197
- "unitValueType": "\"f32\" if unitVectorWidth == 1 else \"vec\" ~ unitVectorWidth ~ \"<f32>\""
198
- },
199
- "passes": [
200
- {
201
- "id": "main",
202
- "name": "VarlenCausalConvWithState.UnitSequence",
203
- "shader": "varlen-unit-sequence.wgsl.jinja",
204
- "bindings": ["input_unit", "weight_unit", "initial_state_unit", "bias_unit", "output_unit", "final_state_unit", "params_unit", "capture_count", "state_update_unit"],
205
- "dispatch": {
206
- "x": "min(ceilDiv((totalTokens * channels / unitVectorWidth), (unitWg)), 65535)",
207
- "y": "ceilDiv(ceilDiv((totalTokens * channels / unitVectorWidth), (unitWg)), 65535)",
208
- "z": 1
209
- }
210
- }
211
- ]
212
- },
213
- {
214
- "id": "capture_copy_state_update_stream",
215
- "priority": 25,
216
- "when": ["stateUpdateContract", "kernelSize >= 2", "kernelSize <= 8", "tunables.streamChunk >= 1", "floor(tunables.streamChunk) == tunables.streamChunk", "tunables.streamWorkgroupSize >= 1", "floor(tunables.streamWorkgroupSize) == tunables.streamWorkgroupSize", "tunables.streamWorkgroupSize <= device.limits.maxComputeInvocationsPerWorkgroup", "tunables.streamWorkgroupSize <= device.limits.maxComputeWorkgroupSizeX", "attrs.dilation == 1", "tensorDtypes.inputT == \"float32\"", "channels % 2 == 0"],
217
- "derive": {
218
- "hasBias": false,
219
- "inputScalar": "dtypes.T",
220
- "outputScalar": "dtypes.T",
221
- "workgroupSize": "tunables.streamWorkgroupSize",
222
- "chunkSize": "min(tunables.streamChunk, ceilDiv(totalTokens, batchSize))"
223
- },
224
- "passes": [
225
- {
226
- "id": "state_update",
227
- "name": "VarlenCausalConvWithState.StateUpdate",
228
- "shader": "varlen-state-update.wgsl.jinja",
229
- "bindings": ["input_capture", "cumulative_sequence_length", "capture_count", "state_update_capture", "params_capture"],
230
- "dispatch": {
231
- "x": "min(ceilDiv((batchSize * stateUpdateCapacity * channels / captureVectorWidth), (workgroupSize)), 65535)",
232
- "y": "ceilDiv(ceilDiv((batchSize * stateUpdateCapacity * channels / captureVectorWidth), (workgroupSize)), 65535)",
233
- "z": 1
234
- },
235
- "derive": {
236
- "captureVectorWidth": "4 if channels % 4 == 0 else 2",
237
- "captureStorageType": "\"vec\" ~ captureVectorWidth ~ \"<\" ~ dtypes.T ~ \">\"",
238
- "outputScalar": "captureStorageType"
239
- }
240
- },
241
- {
242
- "id": "main",
243
- "name": "VarlenCausalConvWithState.Stream",
244
- "shader": "varlen-causal-conv-stream.wgsl.jinja",
245
- "bindings": ["input", "weight", "cumulative_sequence_length", "initial_state", "output", "final_state", "params"],
246
- "dispatch": {
247
- "x": "min(ceilDiv((ceilDiv(totalTokens, chunkSize) * channels), (workgroupSize)), 65535)",
248
- "y": "ceilDiv(ceilDiv((ceilDiv(totalTokens, chunkSize) * channels), (workgroupSize)), 65535)",
249
- "z": 1
250
- }
251
- }
252
- ]
253
- },
254
- {
255
- "id": "capture_copy_state_update",
256
- "priority": 5,
257
- "when": ["stateUpdateContract", "tunables.workgroupSize >= 1", "floor(tunables.workgroupSize) == tunables.workgroupSize", "tunables.workgroupSize <= device.limits.maxComputeInvocationsPerWorkgroup", "tunables.workgroupSize <= device.limits.maxComputeWorkgroupSizeX", "tensorDtypes.inputT == \"float32\"", "channels % 2 == 0"],
258
- "derive": {
259
- "hasBias": false,
260
- "inputScalar": "dtypes.T",
261
- "outputScalar": "dtypes.T",
262
- "workgroupSize": "tunables.workgroupSize"
263
- },
264
- "passes": [
265
- {
266
- "id": "state_update",
267
- "name": "VarlenCausalConvWithState.StateUpdate",
268
- "shader": "varlen-state-update.wgsl.jinja",
269
- "bindings": ["input_capture", "cumulative_sequence_length", "capture_count", "state_update_capture", "params_capture"],
270
- "dispatch": {
271
- "x": "min(ceilDiv((batchSize * stateUpdateCapacity * channels / captureVectorWidth), (workgroupSize)), 65535)",
272
- "y": "ceilDiv(ceilDiv((batchSize * stateUpdateCapacity * channels / captureVectorWidth), (workgroupSize)), 65535)",
273
- "z": 1
274
- },
275
- "derive": {
276
- "captureVectorWidth": "4 if channels % 4 == 0 else 2",
277
- "captureStorageType": "\"vec\" ~ captureVectorWidth ~ \"<\" ~ dtypes.T ~ \">\"",
278
- "outputScalar": "captureStorageType"
279
- }
280
- },
281
- {
282
- "id": "main",
283
- "name": "VarlenCausalConvWithState",
284
- "shader": "varlen-causal-conv.wgsl.jinja",
285
- "bindings": ["input", "weight", "cumulative_sequence_length", "initial_state", "output", "final_state", "params"],
286
- "dispatch": {
287
- "x": "min(ceilDiv((totalTokens * channels), (workgroupSize)), 65535)",
288
- "y": "ceilDiv(ceilDiv((totalTokens * channels), (workgroupSize)), 65535)",
289
- "z": 1
290
- }
291
- }
292
- ]
293
- },
294
- {
295
- "id": "capture_copy_bias_state_update_stream",
296
- "priority": 25,
297
- "when": ["biasStateUpdateContract", "kernelSize >= 2", "kernelSize <= 8", "tunables.streamChunk >= 1", "floor(tunables.streamChunk) == tunables.streamChunk", "tunables.streamWorkgroupSize >= 1", "floor(tunables.streamWorkgroupSize) == tunables.streamWorkgroupSize", "tunables.streamWorkgroupSize <= device.limits.maxComputeInvocationsPerWorkgroup", "tunables.streamWorkgroupSize <= device.limits.maxComputeWorkgroupSizeX", "attrs.dilation == 1", "tensorDtypes.inputT == \"float32\"", "channels % 2 == 0"],
298
- "derive": {
299
- "hasBias": true,
300
- "inputScalar": "dtypes.T",
301
- "outputScalar": "dtypes.T",
302
- "workgroupSize": "tunables.streamWorkgroupSize",
303
- "chunkSize": "min(tunables.streamChunk, ceilDiv(totalTokens, batchSize))"
304
- },
305
- "passes": [
306
- {
307
- "id": "state_update",
308
- "name": "VarlenCausalConvWithState.StateUpdate",
309
- "shader": "varlen-state-update.wgsl.jinja",
310
- "bindings": ["input_capture", "cumulative_sequence_length", "capture_count", "state_update_capture", "params_capture"],
311
- "dispatch": {
312
- "x": "min(ceilDiv((batchSize * stateUpdateCapacity * channels / captureVectorWidth), (workgroupSize)), 65535)",
313
- "y": "ceilDiv(ceilDiv((batchSize * stateUpdateCapacity * channels / captureVectorWidth), (workgroupSize)), 65535)",
314
- "z": 1
315
- },
316
- "derive": {
317
- "captureVectorWidth": "4 if channels % 4 == 0 else 2",
318
- "captureStorageType": "\"vec\" ~ captureVectorWidth ~ \"<\" ~ dtypes.T ~ \">\"",
319
- "outputScalar": "captureStorageType"
320
- }
321
- },
322
- {
323
- "id": "main",
324
- "name": "VarlenCausalConvWithState.Stream",
325
- "shader": "varlen-causal-conv-stream.wgsl.jinja",
326
- "bindings": ["input", "weight", "cumulative_sequence_length", "initial_state", "bias", "output", "final_state", "params"],
327
- "dispatch": {
328
- "x": "min(ceilDiv((ceilDiv(totalTokens, chunkSize) * channels), (workgroupSize)), 65535)",
329
- "y": "ceilDiv(ceilDiv((ceilDiv(totalTokens, chunkSize) * channels), (workgroupSize)), 65535)",
330
- "z": 1
331
- }
332
- }
333
- ]
334
- },
335
- {
336
- "id": "capture_copy_bias_state_update",
337
- "priority": 5,
338
- "when": ["biasStateUpdateContract", "tunables.workgroupSize >= 1", "floor(tunables.workgroupSize) == tunables.workgroupSize", "tunables.workgroupSize <= device.limits.maxComputeInvocationsPerWorkgroup", "tunables.workgroupSize <= device.limits.maxComputeWorkgroupSizeX", "tensorDtypes.inputT == \"float32\"", "channels % 2 == 0"],
339
- "derive": {
340
- "hasBias": true,
341
- "inputScalar": "dtypes.T",
342
- "outputScalar": "dtypes.T",
343
- "workgroupSize": "tunables.workgroupSize"
344
- },
345
- "passes": [
346
- {
347
- "id": "state_update",
348
- "name": "VarlenCausalConvWithState.StateUpdate",
349
- "shader": "varlen-state-update.wgsl.jinja",
350
- "bindings": ["input_capture", "cumulative_sequence_length", "capture_count", "state_update_capture", "params_capture"],
351
- "dispatch": {
352
- "x": "min(ceilDiv((batchSize * stateUpdateCapacity * channels / captureVectorWidth), (workgroupSize)), 65535)",
353
- "y": "ceilDiv(ceilDiv((batchSize * stateUpdateCapacity * channels / captureVectorWidth), (workgroupSize)), 65535)",
354
- "z": 1
355
- },
356
- "derive": {
357
- "captureVectorWidth": "4 if channels % 4 == 0 else 2",
358
- "captureStorageType": "\"vec\" ~ captureVectorWidth ~ \"<\" ~ dtypes.T ~ \">\"",
359
- "outputScalar": "captureStorageType"
360
- }
361
- },
362
- {
363
- "id": "main",
364
- "name": "VarlenCausalConvWithState",
365
- "shader": "varlen-causal-conv.wgsl.jinja",
366
- "bindings": ["input", "weight", "cumulative_sequence_length", "initial_state", "bias", "output", "final_state", "params"],
367
- "dispatch": {
368
- "x": "min(ceilDiv((totalTokens * channels), (workgroupSize)), 65535)",
369
- "y": "ceilDiv(ceilDiv((totalTokens * channels), (workgroupSize)), 65535)",
370
- "z": 1
371
- }
372
- }
373
- ]
374
- },
375
- {
376
- "id": "plain_stream",
377
- "priority": 20,
378
- "when": ["plainContract", "kernelSize >= 2", "kernelSize <= 8", "tunables.streamChunk >= 1", "floor(tunables.streamChunk) == tunables.streamChunk", "tunables.streamWorkgroupSize >= 1", "floor(tunables.streamWorkgroupSize) == tunables.streamWorkgroupSize", "tunables.streamWorkgroupSize <= device.limits.maxComputeInvocationsPerWorkgroup", "tunables.streamWorkgroupSize <= device.limits.maxComputeWorkgroupSizeX", "attrs.dilation == 1"],
379
- "derive": {
380
- "hasBias": "present.biasT",
381
- "inputScalar": "dtypes.T",
382
- "outputScalar": "dtypes.T",
383
- "workgroupSize": "tunables.streamWorkgroupSize",
384
- "chunkSize": "min(tunables.streamChunk, ceilDiv(totalTokens, batchSize))"
385
- },
386
- "passes": [
387
- {
388
- "id": "main",
389
- "name": "VarlenCausalConvWithState.Stream",
390
- "shader": "varlen-causal-conv-stream.wgsl.jinja",
391
- "bindings": ["input", "weight", "cumulative_sequence_length", "initial_state", "output", "final_state", "params"],
392
- "dispatch": {
393
- "x": "min(ceilDiv((ceilDiv(totalTokens, chunkSize) * channels), (workgroupSize)), 65535)",
394
- "y": "ceilDiv(ceilDiv((ceilDiv(totalTokens, chunkSize) * channels), (workgroupSize)), 65535)",
395
- "z": 1
396
- }
397
- }
398
- ]
399
- },
400
- {
401
- "id": "plain",
402
- "priority": 0,
403
- "when": ["plainContract", "tunables.workgroupSize >= 1", "floor(tunables.workgroupSize) == tunables.workgroupSize", "tunables.workgroupSize <= device.limits.maxComputeInvocationsPerWorkgroup", "tunables.workgroupSize <= device.limits.maxComputeWorkgroupSizeX"],
404
- "derive": {
405
- "hasBias": "present.biasT",
406
- "inputScalar": "dtypes.T",
407
- "outputScalar": "dtypes.T",
408
- "workgroupSize": "tunables.workgroupSize"
409
- },
410
- "passes": [
411
- {
412
- "id": "main",
413
- "name": "VarlenCausalConvWithState",
414
- "shader": "varlen-causal-conv.wgsl.jinja",
415
- "bindings": ["input", "weight", "cumulative_sequence_length", "initial_state", "output", "final_state", "params"],
416
- "dispatch": {
417
- "x": "min(ceilDiv((totalTokens * channels), (workgroupSize)), 65535)",
418
- "y": "ceilDiv(ceilDiv((totalTokens * channels), (workgroupSize)), 65535)",
419
- "z": 1
420
- }
421
- }
422
- ]
423
- },
424
- {
425
- "id": "bias_stream",
426
- "priority": 20,
427
- "when": ["biasContract", "kernelSize >= 2", "kernelSize <= 8", "tunables.streamChunk >= 1", "floor(tunables.streamChunk) == tunables.streamChunk", "tunables.streamWorkgroupSize >= 1", "floor(tunables.streamWorkgroupSize) == tunables.streamWorkgroupSize", "tunables.streamWorkgroupSize <= device.limits.maxComputeInvocationsPerWorkgroup", "tunables.streamWorkgroupSize <= device.limits.maxComputeWorkgroupSizeX", "attrs.dilation == 1"],
428
- "derive": {
429
- "hasBias": "present.biasT",
430
- "inputScalar": "dtypes.T",
431
- "outputScalar": "dtypes.T",
432
- "workgroupSize": "tunables.streamWorkgroupSize",
433
- "chunkSize": "min(tunables.streamChunk, ceilDiv(totalTokens, batchSize))"
434
- },
435
- "passes": [
436
- {
437
- "id": "main",
438
- "name": "VarlenCausalConvWithState.Stream",
439
- "shader": "varlen-causal-conv-stream.wgsl.jinja",
440
- "bindings": ["input", "weight", "cumulative_sequence_length", "initial_state", "bias", "output", "final_state", "params"],
441
- "dispatch": {
442
- "x": "min(ceilDiv((ceilDiv(totalTokens, chunkSize) * channels), (workgroupSize)), 65535)",
443
- "y": "ceilDiv(ceilDiv((ceilDiv(totalTokens, chunkSize) * channels), (workgroupSize)), 65535)",
444
- "z": 1
445
- }
446
- }
447
- ]
448
- },
449
- {
450
- "id": "bias",
451
- "priority": 0,
452
- "when": ["biasContract", "tunables.workgroupSize >= 1", "floor(tunables.workgroupSize) == tunables.workgroupSize", "tunables.workgroupSize <= device.limits.maxComputeInvocationsPerWorkgroup", "tunables.workgroupSize <= device.limits.maxComputeWorkgroupSizeX"],
453
- "derive": {
454
- "hasBias": "present.biasT",
455
- "inputScalar": "dtypes.T",
456
- "outputScalar": "dtypes.T",
457
- "workgroupSize": "tunables.workgroupSize"
458
- },
459
- "passes": [
460
- {
461
- "id": "main",
462
- "name": "VarlenCausalConvWithState",
463
- "shader": "varlen-causal-conv.wgsl.jinja",
464
- "bindings": ["input", "weight", "cumulative_sequence_length", "initial_state", "bias", "output", "final_state", "params"],
465
- "dispatch": {
466
- "x": "min(ceilDiv((totalTokens * channels), (workgroupSize)), 65535)",
467
- "y": "ceilDiv(ceilDiv((totalTokens * channels), (workgroupSize)), 65535)",
468
- "z": 1
469
- }
470
- }
471
- ]
472
- },
473
- {
474
- "id": "state_update_stream",
475
- "priority": 20,
476
- "when": ["stateUpdateContract", "kernelSize >= 2", "kernelSize <= 8", "tunables.streamChunk >= 1", "floor(tunables.streamChunk) == tunables.streamChunk", "tunables.streamWorkgroupSize >= 1", "floor(tunables.streamWorkgroupSize) == tunables.streamWorkgroupSize", "tunables.streamWorkgroupSize <= device.limits.maxComputeInvocationsPerWorkgroup", "tunables.streamWorkgroupSize <= device.limits.maxComputeWorkgroupSizeX", "attrs.dilation == 1"],
477
- "derive": {
478
- "hasBias": "present.biasT",
479
- "inputScalar": "dtypes.T",
480
- "outputScalar": "dtypes.T",
481
- "workgroupSize": "tunables.streamWorkgroupSize",
482
- "chunkSize": "min(tunables.streamChunk, ceilDiv(totalTokens, batchSize))"
483
- },
484
- "passes": [
485
- {
486
- "id": "state_update",
487
- "name": "VarlenCausalConvWithState.StateUpdate",
488
- "shader": "varlen-state-update.wgsl.jinja",
489
- "bindings": ["input", "cumulative_sequence_length", "capture_count", "state_update", "params__uniform"],
490
- "dispatch": {
491
- "x": "min(ceilDiv((batchSize * stateUpdateCapacity * channels), (workgroupSize)), 65535)",
492
- "y": "ceilDiv(ceilDiv((batchSize * stateUpdateCapacity * channels), (workgroupSize)), 65535)",
493
- "z": 1
494
- }
495
- },
496
- {
497
- "id": "main",
498
- "name": "VarlenCausalConvWithState.Stream",
499
- "shader": "varlen-causal-conv-stream.wgsl.jinja",
500
- "bindings": ["input", "weight", "cumulative_sequence_length", "initial_state", "output", "final_state", "params"],
501
- "dispatch": {
502
- "x": "min(ceilDiv((ceilDiv(totalTokens, chunkSize) * channels), (workgroupSize)), 65535)",
503
- "y": "ceilDiv(ceilDiv((ceilDiv(totalTokens, chunkSize) * channels), (workgroupSize)), 65535)",
504
- "z": 1
505
- }
506
- }
507
- ]
508
- },
509
- {
510
- "id": "state_update",
511
- "priority": 0,
512
- "when": ["stateUpdateContract", "tunables.workgroupSize >= 1", "floor(tunables.workgroupSize) == tunables.workgroupSize", "tunables.workgroupSize <= device.limits.maxComputeInvocationsPerWorkgroup", "tunables.workgroupSize <= device.limits.maxComputeWorkgroupSizeX"],
513
- "derive": {
514
- "hasBias": "present.biasT",
515
- "inputScalar": "dtypes.T",
516
- "outputScalar": "dtypes.T",
517
- "workgroupSize": "tunables.workgroupSize"
518
- },
519
- "passes": [
520
- {
521
- "id": "state_update",
522
- "name": "VarlenCausalConvWithState.StateUpdate",
523
- "shader": "varlen-state-update.wgsl.jinja",
524
- "bindings": ["input", "cumulative_sequence_length", "capture_count", "state_update", "params__uniform"],
525
- "dispatch": {
526
- "x": "min(ceilDiv((batchSize * stateUpdateCapacity * channels), (workgroupSize)), 65535)",
527
- "y": "ceilDiv(ceilDiv((batchSize * stateUpdateCapacity * channels), (workgroupSize)), 65535)",
528
- "z": 1
529
- }
530
- },
531
- {
532
- "id": "main",
533
- "name": "VarlenCausalConvWithState",
534
- "shader": "varlen-causal-conv.wgsl.jinja",
535
- "bindings": ["input", "weight", "cumulative_sequence_length", "initial_state", "output", "final_state", "params"],
536
- "dispatch": {
537
- "x": "min(ceilDiv((totalTokens * channels), (workgroupSize)), 65535)",
538
- "y": "ceilDiv(ceilDiv((totalTokens * channels), (workgroupSize)), 65535)",
539
- "z": 1
540
- }
541
- }
542
- ]
543
- },
544
- {
545
- "id": "bias_state_update_stream",
546
- "priority": 20,
547
- "when": ["biasStateUpdateContract", "kernelSize >= 2", "kernelSize <= 8", "tunables.streamChunk >= 1", "floor(tunables.streamChunk) == tunables.streamChunk", "tunables.streamWorkgroupSize >= 1", "floor(tunables.streamWorkgroupSize) == tunables.streamWorkgroupSize", "tunables.streamWorkgroupSize <= device.limits.maxComputeInvocationsPerWorkgroup", "tunables.streamWorkgroupSize <= device.limits.maxComputeWorkgroupSizeX", "attrs.dilation == 1"],
548
- "derive": {
549
- "hasBias": "present.biasT",
550
- "inputScalar": "dtypes.T",
551
- "outputScalar": "dtypes.T",
552
- "workgroupSize": "tunables.streamWorkgroupSize",
553
- "chunkSize": "min(tunables.streamChunk, ceilDiv(totalTokens, batchSize))"
554
- },
555
- "passes": [
556
- {
557
- "id": "state_update",
558
- "name": "VarlenCausalConvWithState.StateUpdate",
559
- "shader": "varlen-state-update.wgsl.jinja",
560
- "bindings": ["input", "cumulative_sequence_length", "capture_count", "state_update", "params__uniform"],
561
- "dispatch": {
562
- "x": "min(ceilDiv((batchSize * stateUpdateCapacity * channels), (workgroupSize)), 65535)",
563
- "y": "ceilDiv(ceilDiv((batchSize * stateUpdateCapacity * channels), (workgroupSize)), 65535)",
564
- "z": 1
565
- }
566
- },
567
- {
568
- "id": "main",
569
- "name": "VarlenCausalConvWithState.Stream",
570
- "shader": "varlen-causal-conv-stream.wgsl.jinja",
571
- "bindings": ["input", "weight", "cumulative_sequence_length", "initial_state", "bias", "output", "final_state", "params"],
572
- "dispatch": {
573
- "x": "min(ceilDiv((ceilDiv(totalTokens, chunkSize) * channels), (workgroupSize)), 65535)",
574
- "y": "ceilDiv(ceilDiv((ceilDiv(totalTokens, chunkSize) * channels), (workgroupSize)), 65535)",
575
- "z": 1
576
- }
577
- }
578
- ]
579
- },
580
- {
581
- "id": "bias_state_update",
582
- "priority": 0,
583
- "when": ["biasStateUpdateContract", "tunables.workgroupSize >= 1", "floor(tunables.workgroupSize) == tunables.workgroupSize", "tunables.workgroupSize <= device.limits.maxComputeInvocationsPerWorkgroup", "tunables.workgroupSize <= device.limits.maxComputeWorkgroupSizeX"],
584
- "derive": {
585
- "hasBias": "present.biasT",
586
- "inputScalar": "dtypes.T",
587
- "outputScalar": "dtypes.T",
588
- "workgroupSize": "tunables.workgroupSize"
589
- },
590
- "passes": [
591
- {
592
- "id": "state_update",
593
- "name": "VarlenCausalConvWithState.StateUpdate",
594
- "shader": "varlen-state-update.wgsl.jinja",
595
- "bindings": ["input", "cumulative_sequence_length", "capture_count", "state_update", "params__uniform"],
596
- "dispatch": {
597
- "x": "min(ceilDiv((batchSize * stateUpdateCapacity * channels), (workgroupSize)), 65535)",
598
- "y": "ceilDiv(ceilDiv((batchSize * stateUpdateCapacity * channels), (workgroupSize)), 65535)",
599
- "z": 1
600
- }
601
- },
602
- {
603
- "id": "main",
604
- "name": "VarlenCausalConvWithState",
605
- "shader": "varlen-causal-conv.wgsl.jinja",
606
- "bindings": ["input", "weight", "cumulative_sequence_length", "initial_state", "bias", "output", "final_state", "params"],
607
- "dispatch": {
608
- "x": "min(ceilDiv((totalTokens * channels), (workgroupSize)), 65535)",
609
- "y": "ceilDiv(ceilDiv((totalTokens * channels), (workgroupSize)), 65535)",
610
- "z": 1
611
- }
612
- }
613
- ]
614
- }
615
- ]
616
- }
 
1
+ {"domain":"com.microsoft","name":"VarlenCausalConvWithState","sinceVersion":1,"inputs":{"inputT":{"onnx":"input","dtype":"T","rank":2},"weightT":{"onnx":"weight","dtype":"T","rank":3},"cumulativeSequenceLengthT":{"onnx":"cumulative_sequence_length","dtype":"M","rank":1,"storage":"int32"},"biasT":{"onnx":"bias","dtype":"T","rank":1,"optional":true},"initialStateT":{"onnx":"initial_state","dtype":"T","rank":3},"captureCountT":{"onnx":"capture_count","dtype":"M","rank":1,"optional":true,"storage":"int32"}},"outputs":{"outputT":{"onnx":"output","dtype":"T","rank":"ranks.inputT","shape":"shapes.inputT"},"finalStateT":{"onnx":"final_state","dtype":"T","rank":3,"shape":"[batchSize, channels, stateLength]"},"stateUpdateT":{"onnx":"state_update","dtype":"T","rank":3,"optional":true,"shape":"[batchSize, stateUpdateCapacity, channels]"}},"attributes":{"activation":{"default":"none"},"dilation":{"default":1},"state_update_capacity":{"default":0}},"attributeConstraints":{"activation":{"values":["none","silu","swish"]}},"typeConstraints":{"T":["float32","float16"],"M":["int32"]},"tunables":{"workgroupSize":{"default":256},"streamWorkgroupSize":{"default":64},"streamChunk":{"default":16}},"derive":{"totalTokens":"dim(shapes.inputT, 0)","channels":"dim(shapes.inputT, 1)","batchSize":"dim(shapes.cumulativeSequenceLengthT, 0) - 1","weightRankOk":"ranks.weightT == 3 and dim(shapes.weightT, 1) == 1","kernelSize":"dim(shapes.weightT, 2)","stateLength":"(kernelSize - 1) * attrs.dilation","stateUpdateCapacity":"attrs.state_update_capacity","capturePairOk":"present.captureCountT == (stateUpdateCapacity > 0)","stateShape":"ranks.initialStateT == 3 and dim(shapes.initialStateT, 0) == batchSize and dim(shapes.initialStateT, 1) == channels and dim(shapes.initialStateT, 2) == stateLength","finalStateShape":"ranks.finalStateT == 3 and dim(shapes.finalStateT, 0) == batchSize and dim(shapes.finalStateT, 1) == channels and dim(shapes.finalStateT, 2) == stateLength","captureShape":"not present.captureCountT or (ranks.captureCountT == 1 and dim(shapes.captureCountT, 0) == batchSize and tensorDtypes.captureCountT == \"int32\")","stateUpdateShape":"not present.stateUpdateT or (ranks.stateUpdateT == 3 and dim(shapes.stateUpdateT, 0) == batchSize and dim(shapes.stateUpdateT, 1) == stateUpdateCapacity and dim(shapes.stateUpdateT, 2) == channels and tensorDtypes.stateUpdateT == tensorDtypes.inputT)","biasOk":"not present.biasT or (ranks.biasT == 1 and tensorDtypes.biasT == tensorDtypes.inputT and dim(shapes.biasT, 0) == channels)","contract":"ranks.inputT == 2 and weightRankOk and ranks.outputT == 2 and ranks.cumulativeSequenceLengthT == 1 and channels >= 1 and kernelSize >= 1 and batchSize >= 1 and totalTokens >= batchSize and stateUpdateCapacity >= 0 and stateUpdateCapacity <= 8 and floor(stateUpdateCapacity) == stateUpdateCapacity and capturePairOk and captureShape and stateUpdateShape and (tensorDtypes.inputT == \"float32\" or tensorDtypes.inputT == \"float16\") and tensorDtypes.weightT == tensorDtypes.inputT and tensorDtypes.outputT == tensorDtypes.inputT and tensorDtypes.initialStateT == tensorDtypes.inputT and tensorDtypes.finalStateT == tensorDtypes.inputT and tensorDtypes.cumulativeSequenceLengthT == \"int32\" and f16Ok(dtypes.T) and dim(shapes.weightT, 0) == channels and dim(shapes.outputT, 0) == totalTokens and dim(shapes.outputT, 1) == channels and stateShape and finalStateShape and attrs.dilation >= 1 and floor(attrs.dilation) == attrs.dilation and biasOk","hasBias":"present.biasT","hasCapture":"present.stateUpdateT and stateUpdateCapacity > 0","causalDilation":"attrs.dilation","unitWg":"min(tunables.streamWorkgroupSize, device.limits.maxComputeInvocationsPerWorkgroup, device.limits.maxComputeWorkgroupSizeX)","useSilu":"attrs.activation != \"none\""},"bindings":{"input":{"arg":"inputT","elementType":"$inputScalar"},"weight":{"arg":"weightT","elementType":"$inputScalar"},"cumulative_sequence_length":{"arg":"cumulativeSequenceLengthT","elementType":"i32"},"initial_state":{"arg":"initialStateT","elementType":"$inputScalar"},"output":{"arg":"outputT","elementType":"$outputScalar"},"final_state":{"arg":"finalStateT","elementType":"$outputScalar"},"params":{"struct":[{"name":"batchSize","type":"u32","value":"batchSize"},{"name":"channels","type":"u32","value":"channels"},{"name":"totalTokens","type":"u32","value":"totalTokens"},{"name":"kernelSize","type":"u32","value":"kernelSize"}]},"bias":{"arg":"biasT","elementType":"$inputScalar","when":"hasBias"},"capture_count":{"arg":"captureCountT","elementType":"i32","when":"hasCapture"},"state_update":{"arg":"stateUpdateT","elementType":"$outputScalar"},"params__uniform":{"name":"params","struct":[{"name":"batchSize","type":"u32","value":"batchSize"},{"name":"channels","type":"u32","value":"channels"},{"name":"totalTokens","type":"u32","value":"totalTokens"},{"name":"stateUpdateCapacity","type":"u32","value":"stateUpdateCapacity"}]},"input_unit":{"arg":"inputT","name":"input","elementType":"$unitStorageType"},"bias_unit":{"arg":"biasT","name":"bias","elementType":"$unitStorageType","when":"hasBias"},"output_unit":{"arg":"outputT","name":"output","elementType":"$unitStorageType"},"state_update_unit":{"arg":"stateUpdateT","name":"state_update","elementType":"$unitStorageType","when":"hasCapture"},"params_unit":{"name":"params","struct":[{"name":"channels","type":"u32","value":"channels"},{"name":"totalTokens","type":"u32","value":"totalTokens"}]},"weight_unit":{"arg":"weightT","elementType":"$unitStorageType","name":"weight"},"initial_state_unit":{"arg":"initialStateT","elementType":"$unitStorageType","name":"initial_state"},"final_state_unit":{"arg":"finalStateT","elementType":"$unitStorageType","name":"final_state"},"input_capture":{"arg":"inputT","name":"input","elementType":"$captureStorageType"},"state_update_capture":{"arg":"stateUpdateT","name":"state_update","elementType":"$captureStorageType"},"params_capture":{"name":"params","struct":[{"name":"batchSize","type":"u32","value":"batchSize"},{"name":"channels","type":"u32","value":"channels / captureVectorWidth"},{"name":"totalTokens","type":"u32","value":"totalTokens"},{"name":"stateUpdateCapacity","type":"u32","value":"stateUpdateCapacity"}]}},"variants":[{"id":"unit","priority":50,"when":["contract","tensorDtypes.inputT == \"float32\"","totalTokens == batchSize","attrs.dilation == 1","kernelSize >= 2","kernelSize <= 8","unitWg >= 1","floor(unitWg) == unitWg"],"derive":{"unitVectorWidth":"4 if channels % 4 == 0 else (2 if channels % 2 == 0 else 1)","unitStorageType":"dtypes.T if unitVectorWidth == 1 else \"vec\" ~ unitVectorWidth ~ \"<\" ~ dtypes.T ~ \">\"","unitValueType":"\"f32\" if unitVectorWidth == 1 else \"vec\" ~ unitVectorWidth ~ \"<f32>\""},"passes":[{"id":"main","name":"VarlenCausalConvWithState.UnitSequence","shader":"varlen-unit-sequence.wgsl.jinja","bindings":["input_unit","weight_unit","initial_state_unit","bias_unit","output_unit","final_state_unit","params_unit","capture_count","state_update_unit"],"dispatch":{"x":"min(ceilDiv((totalTokens * channels / unitVectorWidth), (unitWg)), 65535)","y":"ceilDiv(ceilDiv((totalTokens * channels / unitVectorWidth), (unitWg)), 65535)","z":1}}]},{"id":"capture_copy_stream","priority":25,"when":["contract","hasCapture","kernelSize >= 2","kernelSize <= 8","tunables.streamChunk >= 1","floor(tunables.streamChunk) == tunables.streamChunk","tunables.streamWorkgroupSize >= 1","floor(tunables.streamWorkgroupSize) == tunables.streamWorkgroupSize","tunables.streamWorkgroupSize <= device.limits.maxComputeInvocationsPerWorkgroup","tunables.streamWorkgroupSize <= device.limits.maxComputeWorkgroupSizeX","attrs.dilation == 1","tensorDtypes.inputT == \"float32\"","channels % 2 == 0"],"derive":{"inputScalar":"dtypes.T","outputScalar":"dtypes.T","workgroupSize":"tunables.streamWorkgroupSize","chunkSize":"min(tunables.streamChunk, ceilDiv(totalTokens, batchSize))"},"passes":[{"id":"state_update","name":"VarlenCausalConvWithState.StateUpdate","shader":"varlen-state-update.wgsl.jinja","bindings":["input_capture","cumulative_sequence_length","capture_count","state_update_capture","params_capture"],"dispatch":{"x":"min(ceilDiv((batchSize * stateUpdateCapacity * channels / captureVectorWidth), (workgroupSize)), 65535)","y":"ceilDiv(ceilDiv((batchSize * stateUpdateCapacity * channels / captureVectorWidth), (workgroupSize)), 65535)","z":1},"derive":{"captureVectorWidth":"4 if channels % 4 == 0 else 2","captureStorageType":"\"vec\" ~ captureVectorWidth ~ \"<\" ~ dtypes.T ~ \">\"","outputScalar":"captureStorageType"}},{"id":"main","name":"VarlenCausalConvWithState.Stream","shader":"varlen-causal-conv-stream.wgsl.jinja","bindings":["input","weight","cumulative_sequence_length","initial_state","bias","output","final_state","params"],"dispatch":{"x":"min(ceilDiv((ceilDiv(totalTokens, chunkSize) * channels), (workgroupSize)), 65535)","y":"ceilDiv(ceilDiv((ceilDiv(totalTokens, chunkSize) * channels), (workgroupSize)), 65535)","z":1}}]},{"id":"capture_copy","priority":5,"when":["contract","hasCapture","tunables.workgroupSize >= 1","floor(tunables.workgroupSize) == tunables.workgroupSize","tunables.workgroupSize <= device.limits.maxComputeInvocationsPerWorkgroup","tunables.workgroupSize <= device.limits.maxComputeWorkgroupSizeX","tensorDtypes.inputT == \"float32\"","channels % 2 == 0"],"derive":{"inputScalar":"dtypes.T","outputScalar":"dtypes.T","workgroupSize":"tunables.workgroupSize"},"passes":[{"id":"state_update","name":"VarlenCausalConvWithState.StateUpdate","shader":"varlen-state-update.wgsl.jinja","bindings":["input_capture","cumulative_sequence_length","capture_count","state_update_capture","params_capture"],"dispatch":{"x":"min(ceilDiv((batchSize * stateUpdateCapacity * channels / captureVectorWidth), (workgroupSize)), 65535)","y":"ceilDiv(ceilDiv((batchSize * stateUpdateCapacity * channels / captureVectorWidth), (workgroupSize)), 65535)","z":1},"derive":{"captureVectorWidth":"4 if channels % 4 == 0 else 2","captureStorageType":"\"vec\" ~ captureVectorWidth ~ \"<\" ~ dtypes.T ~ \">\"","outputScalar":"captureStorageType"}},{"id":"main","name":"VarlenCausalConvWithState","shader":"varlen-causal-conv.wgsl.jinja","bindings":["input","weight","cumulative_sequence_length","initial_state","bias","output","final_state","params"],"dispatch":{"x":"min(ceilDiv((totalTokens * channels), (workgroupSize)), 65535)","y":"ceilDiv(ceilDiv((totalTokens * channels), (workgroupSize)), 65535)","z":1}}]},{"id":"stream","priority":20,"when":["contract","kernelSize >= 2","kernelSize <= 8","tunables.streamChunk >= 1","floor(tunables.streamChunk) == tunables.streamChunk","tunables.streamWorkgroupSize >= 1","floor(tunables.streamWorkgroupSize) == tunables.streamWorkgroupSize","tunables.streamWorkgroupSize <= device.limits.maxComputeInvocationsPerWorkgroup","tunables.streamWorkgroupSize <= device.limits.maxComputeWorkgroupSizeX","attrs.dilation == 1"],"derive":{"inputScalar":"dtypes.T","outputScalar":"dtypes.T","workgroupSize":"tunables.streamWorkgroupSize","chunkSize":"min(tunables.streamChunk, ceilDiv(totalTokens, batchSize))"},"passes":[{"repeat":{"index":"capture","count":"1 if hasCapture else 0"},"passes":[{"id":"state_update","name":"VarlenCausalConvWithState.StateUpdate","shader":"varlen-state-update.wgsl.jinja","bindings":["input","cumulative_sequence_length","capture_count","state_update","params__uniform"],"dispatch":{"x":"min(ceilDiv((batchSize * stateUpdateCapacity * channels), (workgroupSize)), 65535)","y":"ceilDiv(ceilDiv((batchSize * stateUpdateCapacity * channels), (workgroupSize)), 65535)","z":1}}]},{"id":"main","name":"VarlenCausalConvWithState.Stream","shader":"varlen-causal-conv-stream.wgsl.jinja","bindings":["input","weight","cumulative_sequence_length","initial_state","bias","output","final_state","params"],"dispatch":{"x":"min(ceilDiv((ceilDiv(totalTokens, chunkSize) * channels), (workgroupSize)), 65535)","y":"ceilDiv(ceilDiv((ceilDiv(totalTokens, chunkSize) * channels), (workgroupSize)), 65535)","z":1}}]},{"id":"direct","priority":0,"when":["contract","tunables.workgroupSize >= 1","floor(tunables.workgroupSize) == tunables.workgroupSize","tunables.workgroupSize <= device.limits.maxComputeInvocationsPerWorkgroup","tunables.workgroupSize <= device.limits.maxComputeWorkgroupSizeX"],"derive":{"inputScalar":"dtypes.T","outputScalar":"dtypes.T","workgroupSize":"tunables.workgroupSize"},"passes":[{"repeat":{"index":"capture","count":"1 if hasCapture else 0"},"passes":[{"id":"state_update","name":"VarlenCausalConvWithState.StateUpdate","shader":"varlen-state-update.wgsl.jinja","bindings":["input","cumulative_sequence_length","capture_count","state_update","params__uniform"],"dispatch":{"x":"min(ceilDiv((batchSize * stateUpdateCapacity * channels), (workgroupSize)), 65535)","y":"ceilDiv(ceilDiv((batchSize * stateUpdateCapacity * channels), (workgroupSize)), 65535)","z":1}}]},{"id":"main","name":"VarlenCausalConvWithState","shader":"varlen-causal-conv.wgsl.jinja","bindings":["input","weight","cumulative_sequence_length","initial_state","bias","output","final_state","params"],"dispatch":{"x":"min(ceilDiv((totalTokens * channels), (workgroupSize)), 65535)","y":"ceilDiv(ceilDiv((totalTokens * channels), (workgroupSize)), 65535)","z":1}}]}]}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
build/webgpu/metadata.json CHANGED
@@ -1,41 +1 @@
1
- {
2
- "name": "com.microsoft.VarlenCausalConvWithState",
3
- "id": "_com_microsoft_varlencausalconvwithstate_webgpu_a11f8c1",
4
- "version": 1,
5
- "license": "Apache-2.0",
6
- "backend": { "type": "webgpu" },
7
- "digest": {
8
- "algorithm": "sha256",
9
- "files": {
10
- "bench.json": "0VIH7EDZLjXt1ZgOmAA4oDeWfhadYrY8VJOkvCIbDlg=",
11
- "manifest.json": "uEm8UogYuIyHJRhVKAebGdlv7yxdEIRJs7rLubPctf0=",
12
- "test.json": "o32EnBOjkjEdcFA/wkWFt1ywXTCCN20uEndKoBIoYB8=",
13
- "varlen-causal-conv-stream.wgsl.jinja": "th2IihEJq0gHEpdRm2PNN8MleOvgSZlAstRE0W6wXmo=",
14
- "varlen-causal-conv.wgsl.jinja": "t9K8tccFYN5I9uDeOAUs+gtNaHrQS6iy2S0IbQtp4ik=",
15
- "varlen-state-update.wgsl.jinja": "aTGir5h/LQkg5ami41pKaH4EG8ybaltnnM0oJSJ6Neg=",
16
- "varlen-unit-sequence.wgsl.jinja": "g2tYe2vdYUlDWySCvrljSsqUAuodUmjYnOW/6tr51jw="
17
- }
18
- },
19
- "provenance": { "kernel": { "sha": "6fdf6301e2bbcc2f03bf1eaf493b7ad55ef33afc", "dirty": false } },
20
- "webgpu": {
21
- "manifestSpec": "2.1",
22
- "variants": {
23
- "unit_plain": ["varlen-unit-sequence.wgsl.jinja"],
24
- "unit_bias": ["varlen-unit-sequence.wgsl.jinja"],
25
- "unit_state_update": ["varlen-unit-sequence.wgsl.jinja"],
26
- "unit_bias_state_update": ["varlen-unit-sequence.wgsl.jinja"],
27
- "capture_copy_state_update_stream": ["varlen-causal-conv-stream.wgsl.jinja", "varlen-state-update.wgsl.jinja"],
28
- "capture_copy_state_update": ["varlen-causal-conv.wgsl.jinja", "varlen-state-update.wgsl.jinja"],
29
- "capture_copy_bias_state_update_stream": ["varlen-causal-conv-stream.wgsl.jinja", "varlen-state-update.wgsl.jinja"],
30
- "capture_copy_bias_state_update": ["varlen-causal-conv.wgsl.jinja", "varlen-state-update.wgsl.jinja"],
31
- "plain_stream": ["varlen-causal-conv-stream.wgsl.jinja"],
32
- "plain": ["varlen-causal-conv.wgsl.jinja"],
33
- "bias_stream": ["varlen-causal-conv-stream.wgsl.jinja"],
34
- "bias": ["varlen-causal-conv.wgsl.jinja"],
35
- "state_update_stream": ["varlen-causal-conv-stream.wgsl.jinja", "varlen-state-update.wgsl.jinja"],
36
- "state_update": ["varlen-causal-conv.wgsl.jinja", "varlen-state-update.wgsl.jinja"],
37
- "bias_state_update_stream": ["varlen-causal-conv-stream.wgsl.jinja", "varlen-state-update.wgsl.jinja"],
38
- "bias_state_update": ["varlen-causal-conv.wgsl.jinja", "varlen-state-update.wgsl.jinja"]
39
- }
40
- }
41
- }
 
1
+ {"name":"com.microsoft.VarlenCausalConvWithState","id":"_com_microsoft_varlencausalconvwithstate_webgpu_bf93fa0","version":1,"license":"Apache-2.0","backend":{"type":"webgpu"},"digest":{"algorithm":"sha256","files":{"bench.json":"fzbn1CEwNY9qslBg/jaMtG+mCb5cWc1X8Z9xQTNPYZQ=","manifest.json":"9nBfXacC0cwhxGo9xthQ74ZqXhJ9GdPbfWlIugHCO4Y=","test.json":"C4/xN3rKE+4cZdq5ZapeLjRRmiqpex/av4+Nuw5aRFg=","varlen-causal-conv-stream.wgsl.jinja":"UhwxMkPAi1ZuNYC4KYZ6Al5YwnHoavAiiODSKor/LtE=","varlen-causal-conv.wgsl.jinja":"Ywk+Zkhm2xUyG4TiV+usQPTGbFeH/VJQaF9UyCJeRoY=","varlen-state-update.wgsl.jinja":"aTGir5h/LQkg5ami41pKaH4EG8ybaltnnM0oJSJ6Neg=","varlen-unit-sequence.wgsl.jinja":"g2tYe2vdYUlDWySCvrljSsqUAuodUmjYnOW/6tr51jw="}},"provenance":{"kernel":{"sha":"4385228f788ddaa1bd7aec6a80a20f3ddffd8011","dirty":false}},"webgpu":{"manifestSpec":"2.2"}}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
build/webgpu/test.json CHANGED
@@ -4,7 +4,6 @@
4
  "vector-boundary-float32-c4-k4-b5-t30-cap4_input_weightT": [-0.28125, -0.25, -0.21875, -0.1875, -0.15625, -0.125, -0.09375, -0.0625, -0.03125, 0, 0.03125, 0.0625, 0.09375, 0.125, 0.15625, 0.1875, 0.21875, 0.25, 0.28125],
5
  "vector-boundary-float32-c4-k4-b5-t30-cap4_input_initialStateT": [-1.375, -1.25, -1.125, -1, -0.875, -0.75, -0.625, -0.5, -0.375, -0.25, -0.125, 0, 0.125, 0.25, 0.375, 0.5, 0.625, 0.75, 0.875, 1, 1.125, 1.25, 1.375],
6
  "vector-boundary-float32-c33-k2-b17-t17-cap8_input_cumulativeSequenceLengthT": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17],
7
- "vector-boundary-float32-c33-k2-b17-t17-cap8_input_captureCountT": [-3, 0, 99, 2, 1, -3, 0, 99, 2, 1, -3, 0, 99, 2, 1, -3, 0],
8
  "unit-packed-all-taps-float32-c5-k2-cap1_input_weightT": [-0.5, -0.4375, -0.375, -0.3125, -0.25, -0.1875, -0.125, -0.0625, 0, 0.0625, 0.125, 0.1875, 0.25, 0.3125, 0.375, 0.4375, 0.5],
9
  "unit-packed-all-taps-float32-c5-k2-cap1_input_initialStateT": [-1.125, -1, -0.875, -0.75, -0.625, -0.5, -0.375, -0.25, -0.125, 0, 0.125, 0.25, 0.375, 0.5, 0.625, 0.75, 0.875, 1, 1.125]
10
  },
@@ -12,7 +11,7 @@
12
  {
13
  "name": "k4_varlen_plain",
14
  "provenance": {
15
- "notes": "Three packed sequences of different lengths on the streaming kernel, without bias or state_update. The uneven lengths are the point: every sequence starts its window from its own initial_state, so a kernel that walked the packed axis would read its neighbour's tail."
16
  },
17
  "inputs": {
18
  "inputT": {
@@ -44,7 +43,7 @@
44
  {
45
  "name": "k4_varlen_bias_silu",
46
  "provenance": {
47
- "notes": "Streaming kernel with a per-channel bias and the fused SiLU. Bias enters before the activation, so it is not a post-hoc add."
48
  },
49
  "inputs": {
50
  "inputT": {
@@ -151,7 +150,7 @@
151
  {
152
  "name": "k4_varlen_empty_state_update",
153
  "provenance": {
154
- "notes": "Requests the optional state_update at its default zero capacity. Its exact shape is (batch_size, 0, channels), capture_count remains absent, and convolution outputs are unchanged."
155
  },
156
  "inputs": {
157
  "inputT": {
@@ -228,9 +227,7 @@
228
  },
229
  {
230
  "name": "k3_varlen_plain",
231
- "provenance": {
232
- "notes": "Kernel extent 3 falls off the streaming variant onto the portable one, which walks the window per output element for any extent."
233
- },
234
  "inputs": {
235
  "inputT": {
236
  "dtype": "float32",
@@ -261,7 +258,7 @@
261
  {
262
  "name": "k2_varlen_bias_silu",
263
  "provenance": {
264
- "notes": "Portable kernel at extent 2 with bias and SiLU: the shortest window that still carries state across a call."
265
  },
266
  "inputs": {
267
  "inputT": {
@@ -379,7 +376,7 @@
379
  {
380
  "name": "k1_stateless_plain",
381
  "provenance": {
382
- "notes": "Kernel extent 1: state_length is 0, so initial_state and final_state are empty tensors and the convolution degenerates to a per-channel scale. The loops must survive a zero extent."
383
  },
384
  "inputs": {
385
  "inputT": {
@@ -410,9 +407,7 @@
410
  },
411
  {
412
  "name": "k4_single_long_sequence",
413
- "provenance": {
414
- "notes": "One sequence of 64 tokens -- the prefill shape, where the streaming kernel has only channels-many threads and each walks the whole sequence."
415
- },
416
  "inputs": {
417
  "inputT": {
418
  "dtype": "float32",
@@ -600,7 +595,7 @@
600
  {
601
  "name": "f16_k4_bias_silu",
602
  "provenance": {
603
- "notes": "float16 tensors on the streaming kernel. Taps and accumulation stay in f32 and only the store narrows, which is what the f32 path already did."
604
  },
605
  "inputs": {
606
  "inputT": {
@@ -1547,7 +1542,7 @@
1547
  "shape": [4, 1, 2],
1548
  "data": {
1549
  "kind": "cycle",
1550
- "values": { "$ref": "#/fixtureArrays/vector-boundary-float32-c4-k4-b5-t30-cap4_input_weightT" }
1551
  }
1552
  },
1553
  "initialStateT": {
@@ -1588,7 +1583,7 @@
1588
  "shape": [8, 1, 1],
1589
  "data": {
1590
  "kind": "cycle",
1591
- "values": { "$ref": "#/fixtureArrays/vector-boundary-float32-c4-k4-b5-t30-cap4_input_weightT" }
1592
  }
1593
  },
1594
  "initialStateT": {
@@ -1796,10 +1791,7 @@
1796
  "inputT": {
1797
  "dtype": "float32",
1798
  "shape": [1, 4],
1799
- "data": {
1800
- "kind": "cycle",
1801
- "values": { "$ref": "#/fixtureArrays/vector-boundary-float32-c4-k4-b5-t30-cap4_input_inputT" }
1802
- }
1803
  },
1804
  "weightT": {
1805
  "dtype": "float32",
@@ -1814,7 +1806,7 @@
1814
  "shape": [1, 4, 3],
1815
  "data": {
1816
  "kind": "cycle",
1817
- "values": { "$ref": "#/fixtureArrays/vector-boundary-float32-c4-k4-b5-t30-cap4_input_initialStateT" }
1818
  }
1819
  },
1820
  "cumulativeSequenceLengthT": { "dtype": "int32", "shape": [2], "data": { "kind": "values", "values": [0, 1] } }
@@ -1867,14 +1859,7 @@
1867
  "shape": [33],
1868
  "data": { "kind": "cycle", "values": [-0.1875, -0.125, -0.0625, 0.0, 0.0625, 0.125, 0.1875] }
1869
  },
1870
- "captureCountT": {
1871
- "dtype": "int32",
1872
- "shape": [17],
1873
- "data": {
1874
- "kind": "values",
1875
- "values": { "$ref": "#/fixtureArrays/vector-boundary-float32-c33-k2-b17-t17-cap8_input_captureCountT" }
1876
- }
1877
- }
1878
  },
1879
  "outputs": {
1880
  "outputT": { "dtype": "float32", "shape": [17, 33], "tolerance": 0.00001, "relTolerance": 0.00001 },
@@ -2127,7 +2112,7 @@
2127
  "shape": [4, 1, 2],
2128
  "data": {
2129
  "kind": "cycle",
2130
- "values": { "$ref": "#/fixtureArrays/vector-boundary-float32-c4-k4-b5-t30-cap4_input_weightT" }
2131
  }
2132
  },
2133
  "initialStateT": {
@@ -2168,7 +2153,7 @@
2168
  "shape": [8, 1, 1],
2169
  "data": {
2170
  "kind": "cycle",
2171
- "values": { "$ref": "#/fixtureArrays/vector-boundary-float32-c4-k4-b5-t30-cap4_input_weightT" }
2172
  }
2173
  },
2174
  "initialStateT": {
@@ -2376,10 +2361,7 @@
2376
  "inputT": {
2377
  "dtype": "float16",
2378
  "shape": [1, 4],
2379
- "data": {
2380
- "kind": "cycle",
2381
- "values": { "$ref": "#/fixtureArrays/vector-boundary-float32-c4-k4-b5-t30-cap4_input_inputT" }
2382
- }
2383
  },
2384
  "weightT": {
2385
  "dtype": "float16",
@@ -2394,7 +2376,7 @@
2394
  "shape": [1, 4, 3],
2395
  "data": {
2396
  "kind": "cycle",
2397
- "values": { "$ref": "#/fixtureArrays/vector-boundary-float32-c4-k4-b5-t30-cap4_input_initialStateT" }
2398
  }
2399
  },
2400
  "cumulativeSequenceLengthT": { "dtype": "int32", "shape": [2], "data": { "kind": "values", "values": [0, 1] } }
@@ -2447,14 +2429,7 @@
2447
  "shape": [33],
2448
  "data": { "kind": "cycle", "values": [-0.1875, -0.125, -0.0625, 0.0, 0.0625, 0.125, 0.1875] }
2449
  },
2450
- "captureCountT": {
2451
- "dtype": "int32",
2452
- "shape": [17],
2453
- "data": {
2454
- "kind": "values",
2455
- "values": { "$ref": "#/fixtureArrays/vector-boundary-float32-c33-k2-b17-t17-cap8_input_captureCountT" }
2456
- }
2457
- }
2458
  },
2459
  "outputs": {
2460
  "outputT": { "dtype": "float16", "shape": [17, 33], "tolerance": 0.00001, "relTolerance": 0.00048828125 },
@@ -2528,7 +2503,7 @@
2528
  "shape": [5, 1, 2],
2529
  "data": {
2530
  "kind": "cycle",
2531
- "values": { "$ref": "#/fixtureArrays/unit-packed-all-taps-float32-c5-k2-cap1_input_weightT" }
2532
  }
2533
  },
2534
  "initialStateT": {
@@ -3459,7 +3434,7 @@
3459
  "shape": [5, 1, 2],
3460
  "data": {
3461
  "kind": "cycle",
3462
- "values": { "$ref": "#/fixtureArrays/unit-packed-all-taps-float32-c5-k2-cap1_input_weightT" }
3463
  }
3464
  },
3465
  "initialStateT": {
 
4
  "vector-boundary-float32-c4-k4-b5-t30-cap4_input_weightT": [-0.28125, -0.25, -0.21875, -0.1875, -0.15625, -0.125, -0.09375, -0.0625, -0.03125, 0, 0.03125, 0.0625, 0.09375, 0.125, 0.15625, 0.1875, 0.21875, 0.25, 0.28125],
5
  "vector-boundary-float32-c4-k4-b5-t30-cap4_input_initialStateT": [-1.375, -1.25, -1.125, -1, -0.875, -0.75, -0.625, -0.5, -0.375, -0.25, -0.125, 0, 0.125, 0.25, 0.375, 0.5, 0.625, 0.75, 0.875, 1, 1.125, 1.25, 1.375],
6
  "vector-boundary-float32-c33-k2-b17-t17-cap8_input_cumulativeSequenceLengthT": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17],
 
7
  "unit-packed-all-taps-float32-c5-k2-cap1_input_weightT": [-0.5, -0.4375, -0.375, -0.3125, -0.25, -0.1875, -0.125, -0.0625, 0, 0.0625, 0.125, 0.1875, 0.25, 0.3125, 0.375, 0.4375, 0.5],
8
  "unit-packed-all-taps-float32-c5-k2-cap1_input_initialStateT": [-1.125, -1, -0.875, -0.75, -0.625, -0.5, -0.375, -0.25, -0.125, 0, 0.125, 0.25, 0.375, 0.5, 0.625, 0.75, 0.875, 1, 1.125]
9
  },
 
11
  {
12
  "name": "k4_varlen_plain",
13
  "provenance": {
14
+ "notes": "Three packed sequences of different lengths (8 tokens, 8 channels, kernel size 4) without bias or state update. Every sequence starts its window from its own initial state, so reading the neighbouring sequence's tail gives wrong values."
15
  },
16
  "inputs": {
17
  "inputT": {
 
43
  {
44
  "name": "k4_varlen_bias_silu",
45
  "provenance": {
46
+ "notes": "Kernel size 4 with a per-channel bias and SiLU (8 tokens, 6 channels): the bias is added before the activation."
47
  },
48
  "inputs": {
49
  "inputT": {
 
150
  {
151
  "name": "k4_varlen_empty_state_update",
152
  "provenance": {
153
+ "notes": "Requests the optional state_update at its default zero capacity. Its exact shape is (batch_size, 0, channels), capture_count remains absent and convolution outputs are unaffected."
154
  },
155
  "inputs": {
156
  "inputT": {
 
227
  },
228
  {
229
  "name": "k3_varlen_plain",
230
+ "provenance": { "notes": "Kernel size 3 over two packed sequences (6 tokens, 8 channels), without bias." },
 
 
231
  "inputs": {
232
  "inputT": {
233
  "dtype": "float32",
 
258
  {
259
  "name": "k2_varlen_bias_silu",
260
  "provenance": {
261
+ "notes": "Kernel size 2 with bias and SiLU over three packed sequences (8 tokens, 5 channels): the shortest window that still carries state across a call."
262
  },
263
  "inputs": {
264
  "inputT": {
 
376
  {
377
  "name": "k1_stateless_plain",
378
  "provenance": {
379
+ "notes": "Kernel size 1: the state length is 0, so initial and final state are empty tensors and the convolution reduces to a per-channel scale."
380
  },
381
  "inputs": {
382
  "inputT": {
 
407
  },
408
  {
409
  "name": "k4_single_long_sequence",
410
+ "provenance": { "notes": "One sequence of 64 tokens with 16 channels, kernel size 4, a bias and SiLU." },
 
 
411
  "inputs": {
412
  "inputT": {
413
  "dtype": "float32",
 
595
  {
596
  "name": "f16_k4_bias_silu",
597
  "provenance": {
598
+ "notes": "Float16 tensors with kernel size 4, bias and SiLU: taps and accumulation stay in float32 and only the store narrows to float16."
599
  },
600
  "inputs": {
601
  "inputT": {
 
1542
  "shape": [4, 1, 2],
1543
  "data": {
1544
  "kind": "cycle",
1545
+ "values": [-0.28125, -0.25, -0.21875, -0.1875, -0.15625, -0.125, -0.09375, -0.0625]
1546
  }
1547
  },
1548
  "initialStateT": {
 
1583
  "shape": [8, 1, 1],
1584
  "data": {
1585
  "kind": "cycle",
1586
+ "values": [-0.28125, -0.25, -0.21875, -0.1875, -0.15625, -0.125, -0.09375, -0.0625]
1587
  }
1588
  },
1589
  "initialStateT": {
 
1791
  "inputT": {
1792
  "dtype": "float32",
1793
  "shape": [1, 4],
1794
+ "data": { "kind": "cycle", "values": [-1.125, -1.0625, -1.0, -0.9375] }
 
 
 
1795
  },
1796
  "weightT": {
1797
  "dtype": "float32",
 
1806
  "shape": [1, 4, 3],
1807
  "data": {
1808
  "kind": "cycle",
1809
+ "values": [-1.375, -1.25, -1.125, -1.0, -0.875, -0.75, -0.625, -0.5, -0.375, -0.25, -0.125, 0.0]
1810
  }
1811
  },
1812
  "cumulativeSequenceLengthT": { "dtype": "int32", "shape": [2], "data": { "kind": "values", "values": [0, 1] } }
 
1859
  "shape": [33],
1860
  "data": { "kind": "cycle", "values": [-0.1875, -0.125, -0.0625, 0.0, 0.0625, 0.125, 0.1875] }
1861
  },
1862
+ "captureCountT": { "dtype": "int32", "shape": [17], "data": { "kind": "cycle", "values": [-3, 0, 99, 2, 1] } }
 
 
 
 
 
 
 
1863
  },
1864
  "outputs": {
1865
  "outputT": { "dtype": "float32", "shape": [17, 33], "tolerance": 0.00001, "relTolerance": 0.00001 },
 
2112
  "shape": [4, 1, 2],
2113
  "data": {
2114
  "kind": "cycle",
2115
+ "values": [-0.28125, -0.25, -0.21875, -0.1875, -0.15625, -0.125, -0.09375, -0.0625]
2116
  }
2117
  },
2118
  "initialStateT": {
 
2153
  "shape": [8, 1, 1],
2154
  "data": {
2155
  "kind": "cycle",
2156
+ "values": [-0.28125, -0.25, -0.21875, -0.1875, -0.15625, -0.125, -0.09375, -0.0625]
2157
  }
2158
  },
2159
  "initialStateT": {
 
2361
  "inputT": {
2362
  "dtype": "float16",
2363
  "shape": [1, 4],
2364
+ "data": { "kind": "cycle", "values": [-1.125, -1.0625, -1.0, -0.9375] }
 
 
 
2365
  },
2366
  "weightT": {
2367
  "dtype": "float16",
 
2376
  "shape": [1, 4, 3],
2377
  "data": {
2378
  "kind": "cycle",
2379
+ "values": [-1.375, -1.25, -1.125, -1.0, -0.875, -0.75, -0.625, -0.5, -0.375, -0.25, -0.125, 0.0]
2380
  }
2381
  },
2382
  "cumulativeSequenceLengthT": { "dtype": "int32", "shape": [2], "data": { "kind": "values", "values": [0, 1] } }
 
2429
  "shape": [33],
2430
  "data": { "kind": "cycle", "values": [-0.1875, -0.125, -0.0625, 0.0, 0.0625, 0.125, 0.1875] }
2431
  },
2432
+ "captureCountT": { "dtype": "int32", "shape": [17], "data": { "kind": "cycle", "values": [-3, 0, 99, 2, 1] } }
 
 
 
 
 
 
 
2433
  },
2434
  "outputs": {
2435
  "outputT": { "dtype": "float16", "shape": [17, 33], "tolerance": 0.00001, "relTolerance": 0.00048828125 },
 
2503
  "shape": [5, 1, 2],
2504
  "data": {
2505
  "kind": "cycle",
2506
+ "values": [-0.5, -0.4375, -0.375, -0.3125, -0.25, -0.1875, -0.125, -0.0625, 0.0, 0.0625]
2507
  }
2508
  },
2509
  "initialStateT": {
 
3434
  "shape": [5, 1, 2],
3435
  "data": {
3436
  "kind": "cycle",
3437
+ "values": [-0.5, -0.4375, -0.375, -0.3125, -0.25, -0.1875, -0.125, -0.0625, 0.0, 0.0625]
3438
  }
3439
  },
3440
  "initialStateT": {
build/webgpu/varlen-causal-conv-stream.wgsl.jinja CHANGED
@@ -1,4 +1,4 @@
1
- {% macro varlen_sequence_of_token(buffer="cumulative_sequence_length") %}
2
  fn sequence_of_token(token: u32, batch_size: u32) -> u32 {
3
  for (var b: u32 = 0u; b < batch_size; b = b + 1u) {
4
  if (token < u32({{ buffer }}[b + 1u])) {
@@ -30,11 +30,12 @@ fn activate(value: {{ valueType }}) -> {{ valueType }} {
30
  {% endif %}
31
  }{% endmacro %}
32
  {% set stateLength = kernelSize - 1 %}
33
- {% macro flat_index_2d(workgroupSize, name="i", bound="params.count", guardInline=false) %}
34
  {% set wgTerm = workgroupSize ~ "u" if workgroupSize is number else workgroupSize %}
35
  // 2D-folded flat index: gid.y carries the high bits past the dispatch's
36
  // per-axis workgroup fold width.
37
- let {{ name }} = gid.x + gid.y * {{ DISPATCH_FOLD_WIDTH }}u * {{ wgTerm }};{% endmacro %}
 
38
  {{ env.wgsl.resourceDeclarations }}
39
 
40
  // com.microsoft.VarlenCausalConvWithState, streaming pass.
 
1
+ {% macro varlen_sequence_of_token(buffer="cumulative_sequence_length", binarySearch=false) %}
2
  fn sequence_of_token(token: u32, batch_size: u32) -> u32 {
3
  for (var b: u32 = 0u; b < batch_size; b = b + 1u) {
4
  if (token < u32({{ buffer }}[b + 1u])) {
 
30
  {% endif %}
31
  }{% endmacro %}
32
  {% set stateLength = kernelSize - 1 %}
33
+ {% macro flat_index_2d(workgroupSize, name="i", bound="params.count") %}
34
  {% set wgTerm = workgroupSize ~ "u" if workgroupSize is number else workgroupSize %}
35
  // 2D-folded flat index: gid.y carries the high bits past the dispatch's
36
  // per-axis workgroup fold width.
37
+ let {{ name }} = gid.x + gid.y * {{ DISPATCH_FOLD_WIDTH }}u * {{ wgTerm }};
38
+ {% endmacro %}
39
  {{ env.wgsl.resourceDeclarations }}
40
 
41
  // com.microsoft.VarlenCausalConvWithState, streaming pass.
build/webgpu/varlen-causal-conv.wgsl.jinja CHANGED
@@ -1,4 +1,4 @@
1
- {% macro varlen_sequence_of_token(buffer="cumulative_sequence_length") %}
2
  fn sequence_of_token(token: u32, batch_size: u32) -> u32 {
3
  for (var b: u32 = 0u; b < batch_size; b = b + 1u) {
4
  if (token < u32({{ buffer }}[b + 1u])) {
@@ -29,14 +29,15 @@ fn activate(value: {{ valueType }}) -> {{ valueType }} {
29
  return value;
30
  {% endif %}
31
  }{% endmacro %}
32
- {% macro flat_index_2d(workgroupSize, name="i", bound="params.count", guardInline=false) %}
33
  {% set wgTerm = workgroupSize ~ "u" if workgroupSize is number else workgroupSize %}
34
  // 2D-folded flat index: gid.y carries the high bits past the dispatch's
35
  // per-axis workgroup fold width.
36
  let {{ name }} = gid.x + gid.y * {{ DISPATCH_FOLD_WIDTH }}u * {{ wgTerm }};
37
  if ({{ name }} >= {{ bound }}) {
38
  return;
39
- }{% endmacro %}
 
40
  {{ env.wgsl.resourceDeclarations }}
41
 
42
  // com.microsoft.VarlenCausalConvWithState, portable pass.
 
1
+ {% macro varlen_sequence_of_token(buffer="cumulative_sequence_length", binarySearch=false) %}
2
  fn sequence_of_token(token: u32, batch_size: u32) -> u32 {
3
  for (var b: u32 = 0u; b < batch_size; b = b + 1u) {
4
  if (token < u32({{ buffer }}[b + 1u])) {
 
29
  return value;
30
  {% endif %}
31
  }{% endmacro %}
32
+ {% macro flat_index_2d(workgroupSize, name="i", bound="params.count") %}
33
  {% set wgTerm = workgroupSize ~ "u" if workgroupSize is number else workgroupSize %}
34
  // 2D-folded flat index: gid.y carries the high bits past the dispatch's
35
  // per-axis workgroup fold width.
36
  let {{ name }} = gid.x + gid.y * {{ DISPATCH_FOLD_WIDTH }}u * {{ wgTerm }};
37
  if ({{ name }} >= {{ bound }}) {
38
  return;
39
+ }
40
+ {% endmacro %}
41
  {{ env.wgsl.resourceDeclarations }}
42
 
43
  // com.microsoft.VarlenCausalConvWithState, portable pass.