KernelBench-M / rules /BRIEF.md
Elfsong's picture
KernelBench-M artifact: rules, substrates, witnesses, pipeline, summaries
1276a5c verified
|
Raw History Blame Contribute Delete
3.8 kB

Rule-mining brief: new CUDA mutation operators

Context

We run mutation testing on CUDA kernels to measure how strong a benchmark's correctness check is. Mutants are produced by DETERMINISTIC rewrite rules applied to correct kernel source (see ../mutator.py for the 35 current rules and the Rule dataclass). Each rule is (name, category, regex pattern, replacement template). Every match site yields one mutant.

What makes a rule VALUABLE (this is the objective)

A mutant is "high value" when it (a) compiles, (b) SURVIVES the benchmark's original test inputs — which are aligned shapes, torch.rand[0,1) values, compared with allclose(atol=rtol=1e-2) — and (c) IS killable by some targeted input (misaligned shape, signed values, large magnitude, structured spikes).

Measured value rates of existing rules on our pool: ceil2floor 100%, const0to1 62%, sync2syncwarp 40%, loop-bound-minus1 39%, loop-start-1 35%, sync-remove 36%, lt2le 21%, store-fp16 24%, mul2plus 15%, mul2div 12% <- good plus2minus 3%, guard-drop-ternary 0%, expf-fast 0%, smem-index-off1 0%, fmin2fmax 0%, negate-store 0%, fdividef-fast 0% <- bad, being retired

Pattern: rules that break BOUNDARY handling, SYNCHRONIZATION, or PRECISION produce faults invisible under aligned shapes and small positive values. Rules that break gross semantics (a+b -> a-b) are caught immediately by any input and are near-worthless.

Known expressiveness gaps (highest priority)

Our regex rules CANNOT express these, yet they are the most valuable faults:

  1. Identity substitution: replacing a call with its own argument, e.g. fmaxf(val, 0.0f) -> val (removes a ReLU; invisible on positive inputs). Generalize: any activation/clamp/saturation wrapper removal.
  2. Numerical-stability removal: dropping the max-subtraction in softmax-like code, dropping epsilon in a denominator, dropping Kahan compensation.
  3. Partial-tail faults: processing only a prefix of a reduction, off-by-one in the LAST iteration only, dropping the remainder loop after a vectorized main loop.
  4. Accumulator staging: using the shared-memory value before the barrier, re-initializing an accumulator inside the loop, double-counting an element.
  5. Index arithmetic that is wrong only at edges: swapping row/col strides in ONE of several index expressions, using the wrong bound variable (M vs N), using blockDim where gridDim is meant.

Your task

Write NEW rules into a fresh file: rules/mined_rules.py

Format (import-safe, no side effects):

from mutator import Rule   # dataclass(name, category, pattern, replacement, note)

MINED_RULES = [
    Rule("name", "category", r"regex", r"replacement", "one-line rationale"),
    ...
]

Requirements:

  • 25+ new rules, none duplicating an existing rule in ../mutator.py.
  • Categories: boundary | sync | precision | indexing | arithmetic | semantic.
  • Patterns must be robust regexes that match the CUDA style used in ../problems_batch2.py and ../substrates/accepted/*.py (read several of them — that is the corpus these rules must fire on).
  • Prefer rules targeting the five gap families above; a regex CAN express identity substitution when the call and its first argument are both simple (e.g. r"fmaxf((\w+), 0.0f)" -> r"\1"). Write several such families.
  • Every rule must produce COMPILABLE code (mind types and parens).
  • Avoid rules whose mutants would be caught by any input (gross semantics).
  • Add a short comment block at the top summarizing your reasoning.

Verify before finishing: run python3 -c "import sys; sys.path.insert(0,'.'); from rules.mined_rules import MINED_RULES; print(len(MINED_RULES))" from the experiment directory, and also verify each pattern compiles as a regex. Do not modify any existing file.