File size: 11,414 Bytes
a2b6fb1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://huggingface.co/datasets/ZMC2019/KBench/schema/task.schema.json",
  "title": "KBench task",
  "description": "A kernel-generation task. DEFINITION (the maths, the graded interface, the correctness policy) is deliberately separate from WORKLOAD (the shapes it is graded at), so one definition can be graded at several workloads -- a synthetic regime sized for measurement, and shapes captured from a real serving or sampling run -- without duplicating the task.",
  "type": "object",
  "required": [
    "name",
    "family",
    "definition",
    "workloads",
    "grading"
  ],
  "additionalProperties": false,
  "properties": {
    "name": {
      "type": "string",
      "pattern": "^[a-z0-9]+(-[a-z0-9]+)*$"
    },
    "family": {
      "type": "string",
      "description": "Catalog grouping, e.g. 'Quantization & low-precision GEMM'."
    },
    "description": {
      "type": "string"
    },
    "keywords": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "difficulty": {
      "type": "object",
      "description": "How hard it is to IMPROVE on the best available implementation -- headroom x technique depth. NOT structural complexity: a dense GEMM is a one-liner and near-unbeatable.",
      "required": [
        "tier"
      ],
      "properties": {
        "tier": {
          "enum": [
            "T1",
            "T2",
            "T3",
            "T4"
          ],
          "description": "T1 fuse several passes into one. T2 shared-memory tiling, warp reductions, online single-pass reformulation. T3 async copy/TMA, double buffering, warp specialisation, hand-written MMA. T4 out-engineer a vendor kernel already at the hardware limit."
        },
        "rationale": {
          "type": "string"
        },
        "reviewed_by_hand": {
          "type": "boolean",
          "description": "T4 asserts near-unbeatability, so that set is hand-reviewed rather than left to a heuristic."
        }
      }
    },
    "definition": {
      "type": "object",
      "description": "The maths and the graded interface. Independent of any particular shape.",
      "required": [
        "entry_point",
        "inputs",
        "outputs",
        "reference"
      ],
      "additionalProperties": false,
      "properties": {
        "entry_point": {
          "type": "string",
          "description": "Function the grader imports from the submitted module."
        },
        "module": {
          "type": "string",
          "description": "File the agent edits, e.g. 'kda.py'."
        },
        "signature": {
          "type": "string"
        },
        "inputs": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/tensorSpec"
          }
        },
        "outputs": {
          "type": "array",
          "description": "In return order. For a tuple return this IS the tuple order.",
          "items": {
            "$ref": "#/$defs/tensorSpec"
          }
        },
        "reference": {
          "type": "object",
          "description": "The numerical specification: correct, deliberately unfused, and slow. Its speed has no bearing on the score.",
          "required": [
            "language",
            "source"
          ],
          "properties": {
            "language": {
              "const": "python/pytorch"
            },
            "source": {
              "type": "string"
            }
          }
        },
        "read_only_inputs": {
          "type": "boolean",
          "default": true
        },
        "in_place_outputs": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "Names of inputs mutated in place (e.g. a KV cache appended to)."
        }
      }
    },
    "workloads": {
      "type": "object",
      "description": "Named shape sets. 'synthetic' is sized so the kernel dominates rather than launch overhead; a 'captured' workload holds shapes recorded from a real run.",
      "minProperties": 1,
      "additionalProperties": {
        "$ref": "#/$defs/workload"
      }
    },
    "grading": {
      "type": "object",
      "required": [
        "metric",
        "reward",
        "tolerance"
      ],
      "additionalProperties": false,
      "properties": {
        "metric": {
          "enum": [
            "TFLOP/s",
            "GB/s",
            "tokens/s",
            "barriers/s",
            "instructions/s",
            "verified-positions/s"
          ]
        },
        "reward": {
          "type": "object",
          "properties": {
            "kind": {
              "const": "absolute-uncapped",
              "description": "reward = achieved metric, 0 if incorrect. Absolute rather than a speedup versus a baseline, so it is hardware-portable and there is no oracle to re-benchmark."
            },
            "canonical_work": {
              "type": "string",
              "description": "Work attributed to the kernel, from SHAPE ALONE -- never from the data, so every submission is credited identically."
            }
          }
        },
        "tolerance": {
          "type": "object",
          "required": [
            "value",
            "comparator"
          ],
          "properties": {
            "value": {
              "type": "number",
              "minimum": 0
            },
            "comparator": {
              "enum": [
                "relative-frobenius",
                "relative-frobenius-tuple-max",
                "rowwise",
                "exact"
              ]
            },
            "row_pass": {
              "type": "number",
              "description": "For 'rowwise': fraction of rows that must pass."
            },
            "measured_floor_E": {
              "type": "number",
              "description": "Relative error between the reference and an INDEPENDENT correct implementation. The tolerance must sit above this or it rejects correct kernels."
            },
            "measured_drop_D": {
              "type": "number",
              "description": "Relative error of a variant that ignores the task's distinguishing feature. The tolerance must sit far below this or the feature is not graded."
            },
            "basis": {
              "type": "string",
              "description": "How E and D were measured."
            }
          }
        },
        "extra_gates": {
          "type": "array",
          "description": "Additional measured gates, e.g. the megakernel family's kernels-per-step and dominant-share.",
          "items": {
            "type": "object",
            "properties": {
              "name": {
                "type": "string"
              },
              "limit": {
                "type": "number"
              },
              "direction": {
                "enum": [
                  "max",
                  "min"
                ]
              },
              "rationale": {
                "type": "string"
              }
            }
          }
        }
      }
    },
    "environment": {
      "type": "object",
      "properties": {
        "base_image": {
          "type": "string"
        },
        "gpus": {
          "type": "integer",
          "minimum": 1
        },
        "min_compute_capability": {
          "type": "string",
          "default": "9.0"
        },
        "offline": {
          "type": "boolean",
          "default": true
        },
        "note": {
          "type": "string",
          "description": "The exact GPU is deliberately NOT specified; tasks tell the agent to query the device."
        }
      }
    }
  },
  "$defs": {
    "tensorSpec": {
      "type": "object",
      "required": [
        "name",
        "shape",
        "dtype"
      ],
      "additionalProperties": false,
      "properties": {
        "name": {
          "type": "string"
        },
        "shape": {
          "type": "array",
          "description": "Symbolic dims are names bound by the workload, e.g. ['B','T','H','D'].",
          "items": {
            "type": [
              "string",
              "integer"
            ]
          }
        },
        "dtype": {
          "type": "string",
          "enum": [
            "bfloat16",
            "float16",
            "float32",
            "float64",
            "float8_e4m3fn",
            "float8_e5m2",
            "int8",
            "uint8",
            "int32",
            "int64",
            "bool"
          ]
        },
        "meaning": {
          "type": "string"
        },
        "layout": {
          "type": "string"
        },
        "quantized": {
          "type": "object",
          "description": "Pre-quantised input. The reference MUST dequantise these exact bytes -- charging the agent for quantisation error inflates the apparent error by ~10x.",
          "properties": {
            "format": {
              "type": "string"
            },
            "scale_granularity": {
              "enum": [
                "per-tensor",
                "per-row",
                "per-block",
                "per-channel"
              ],
              "description": "Per-tensor scales must be exactly representable: their rounding error multiplies the whole output coherently instead of averaging out."
            },
            "block_size": {
              "type": "integer"
            }
          }
        }
      }
    },
    "workload": {
      "type": "object",
      "required": [
        "dims",
        "graded",
        "correctness"
      ],
      "additionalProperties": false,
      "properties": {
        "source": {
          "enum": [
            "synthetic",
            "captured"
          ],
          "default": "synthetic"
        },
        "provenance": {
          "type": "string",
          "description": "For 'captured': what run these shapes came from."
        },
        "dims": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "Names of the symbolic dims, in the order the shape tuples list them."
        },
        "graded": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/shape"
          },
          "description": "Timed shapes. Sized so the roofline exceeds 250 us and the kernel dominates."
        },
        "correctness": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/shape"
          },
          "description": "Small shapes run many times; include ragged cases so tails are exercised."
        },
        "measure": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/shape"
          },
          "description": "Shapes for the agent's own self-assessment tool."
        },
        "roofline_us": {
          "type": "number",
          "description": "Implied runtime of a perfect kernel at the largest graded shape."
        }
      }
    },
    "shape": {
      "type": "array",
      "items": {
        "type": [
          "integer",
          "boolean",
          "array",
          "number"
        ]
      },
      "description": "Dim values in the order given by the workload's `dims`. May include config flags (e.g. a causal bool) or nested lists (e.g. per-group counts for a variable-M GEMM)."
    }
  }
}