Download LEVEL3_BRIEF.md from Elfsong/KernelBench-M: direct link, hf CLI and curl.
- Browser
- Download file 2.61 kB
-
https://huggingface.co/datasets/Elfsong/KernelBench-M/resolve/main/LEVEL3_BRIEF.md
- Command line
-
hf download hf://datasets/Elfsong/KernelBench-M/LEVEL3_BRIEF.md
-
curl -L -o LEVEL3_BRIEF.md https://huggingface.co/datasets/Elfsong/KernelBench-M/resolve/main/LEVEL3_BRIEF.md
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
cudaholds 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.kernel_nameis a LIST of those symbol names, in pipeline order.launchreturns a DICT describing the sequence instead of a single tuple:
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.
WEIGHTS: the reference
Modelowns nn.Parameters. Create them ONCE with a fixed seed inside the substrate module (module-level, lazily on first use), and haverefuse THE SAME tensors, so reference and kernel see identical weights. Put them on the input's device.refmust reproduce the KernelBenchModel.forwardexactly, using those same weights (e.g.torch.nn.functional.linear(x, W0, b0).relu()...).Suites:
T0_originalmust reproduce the problem'sget_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.