File size: 2,755 Bytes
b5d19c4
 
 
 
5e78980
 
b5d19c4
5e78980
b5d19c4
 
 
5e78980
 
 
b5d19c4
5e78980
b5d19c4
 
 
 
5e78980
 
b5d19c4
 
 
 
 
 
5e78980
 
 
 
 
b5d19c4
5e78980
 
 
 
 
b5d19c4
 
 
 
 
 
5e78980
b5d19c4
 
 
 
 
5e78980
b5d19c4
5e78980
 
 
 
 
b5d19c4
5e78980
 
 
 
 
b5d19c4
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
{
  "domain": "com.microsoft",
  "name": "GatedAdd",
  "sinceVersion": 1,
  "inputs": { "X": { "dtype": "T" }, "Y": { "dtype": "T" }, "gate": { "dtype": "T" } },
  "outputs": { "output": { "dtype": "T", "rank": "ranks.X", "shape": "shapes.X" } },
  "typeConstraints": { "T": ["float32", "float16"] },
  "tunables": { "WORKGROUP_SIZE": { "default": 256 } },
  "derive": {
    "channels": "dim(shapes.X, ranks.X - 1)",
    "gateContract": "ranks.X >= 1 and channels > 0 and ranks.Y == ranks.X and ranks.gate == ranks.X and sameShape(shapes.Y, shapes.X) and sameShape(shapes.output, shapes.X) and dim(shapes.gate, ranks.gate - 1) == 1 and sameShape(prefix(shapes.gate, ranks.gate - 1), prefix(shapes.X, ranks.X - 1)) and f16Ok(dtypes.T)",
    "vec4Rows": "channels % 4 == 0 and numel(shapes.X) % 4 == 0",
    "scalar": "dtypes.T",
    "hidden": "channels if channels > 0 else 1"
  },
  "when": ["gateContract"],
  "variants": [
    {
      "id": "vec4",
      "priority": 30,
      "when": ["vec4Rows", "numel(shapes.X) > 0"],
      "derive": { "vec4": true, "vectorScalar": "\"vec4<\" ~ dtypes.T ~ \">\"" },
      "passes": [
        {
          "id": "main",
          "name": "GatedAdd.vec4",
          "shader": "gated-add.wgsl.jinja",
          "bindings": [
            { "arg": "X", "name": "x", "elementType": "$vectorScalar" },
            { "arg": "Y", "name": "y", "elementType": "$vectorScalar" },
            "gate",
            { "arg": "output", "elementType": "$vectorScalar" },
            { "name": "params", "struct": [{ "name": "count", "type": "u32", "value": "numel(shapes.X) / 4" }] }
          ],
          "dispatch": {
            "x": "min(ceilDiv((numel(shapes.X) / 4), (tunables.WORKGROUP_SIZE)), 65535)",
            "y": "ceilDiv(ceilDiv((numel(shapes.X) / 4), (tunables.WORKGROUP_SIZE)), 65535)",
            "z": 1
          }
        }
      ]
    },
    {
      "id": "scalar",
      "priority": 0,
      "derive": { "vec4": false },
      "passes": [
        {
          "id": "main",
          "name": "GatedAdd.scalar",
          "shader": "gated-add.wgsl.jinja",
          "derive": { "itemsPerInvocation": 4 },
          "bindings": [
            { "arg": "X", "name": "x", "elementType": "$scalar" },
            { "arg": "Y", "name": "y", "elementType": "$scalar" },
            "gate",
            "output",
            { "name": "params", "struct": [{ "name": "count", "type": "u32", "value": "numel(shapes.X)" }] }
          ],
          "dispatch": {
            "x": "min(ceilDiv((ceilDiv(numel(shapes.X), 4)), (tunables.WORKGROUP_SIZE)), 65535)",
            "y": "ceilDiv(ceilDiv((ceilDiv(numel(shapes.X), 4)), (tunables.WORKGROUP_SIZE)), 65535)",
            "z": 1
          }
        }
      ]
    }
  ]
}