File size: 2,609 Bytes
1276a5c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# Brief: level-3 substrates (full architectures, multi-kernel)

Level-3 KernelBench problems are whole networks. Their substrate is a PIPELINE
of kernels — one `__global__` per layer — so that a mutation lands in a
specific layer and we can measure how far a fault propagates through depth.

Read `substrates/SPEC.md` first for the general contract, then the differences
below. Read `problems_batch2.py` for the CUDA style, and at least two accepted
substrates from `substrates/accepted/`.

## What changes vs a level-1/2 substrate

1. `cuda` holds SEVERAL `__global__` kernels, one per layer of the network
   (e.g. `mlp_gemm_relu_kernel`, `mlp_gemm_kernel`). Name them so the layer is
   identifiable.
2. `kernel_name` is a LIST of those symbol names, in pipeline order.
3. `launch` returns a DICT describing the sequence instead of a single tuple:

```python
def launch(inputs, torch):
    x = inputs[0]
    ...
    bufs = [torch.zeros(...), ...]        # intermediate activations
    seq = [
        # (kernel_name, grid3, block3, [tensor args in order], [(ctype, scalar), ...])
        ("layer0_kernel", (gx, gy, 1), (32, 32, 1), [x, w0, b0, bufs[0]],
         [(ctypes.c_int, M), (ctypes.c_int, K), (ctypes.c_int, N)]),
        ("layer1_kernel", ..., [bufs[0], w1, b1, out], [...]),
    ]
    return {"seq": seq, "out": out}
```

   Tensor arguments are passed as data pointers in the order listed; scalars
   follow. Allocate intermediates inside `launch`.

4. WEIGHTS: the reference `Model` owns nn.Parameters. Create them ONCE with a
   fixed seed inside the substrate module (module-level, lazily on first use),
   and have `ref` use THE SAME tensors, so reference and kernel see identical
   weights. Put them on the input's device.

5. `ref` must reproduce the KernelBench `Model.forward` exactly, using those
   same weights (e.g. `torch.nn.functional.linear(x, W0, b0).relu()` ...).

6. Suites: `T0_original` must reproduce the problem's `get_inputs()`; add 2-3
   targeted suites. Keep the legitimate-variance ceiling in mind: prefer
   same-sign large values over signed ones.

## Performance does not matter

Naive kernels are fine (one thread per output element, sequential loops). What
matters is: correct, readable, and rich in mutation sites (explicit bounds
guards, ceil-division, distinct `__syncthreads()` where relevant).

## Deliverable

`substrates/candidate_L3p<N>_<short>.py` with a `register(K, torch, ctypes)`
function exactly as in SPEC.md, plus `kernel_name` as a list and the dict-style
`launch` above. Import-safe, no GPU work at import time, do not modify other
files.