Repository navigation
Add KernelBench L1–L3 torch2hip tasks - #47
Conversation
sharareh-y
left a comment
There was a problem hiding this comment.
Thanks for adding these — nice to have KernelBench coverage in the torch2hip set. The generated tasks are wired up correctly (naming, functional/module split, eval_tools all check out). A few things I'd like to sort out before merging:
1. Multiple input configs per task.
Right now each KernelBench task has a single-case get_inputs() (return [x]), whereas our existing gpumode torch2hip tasks yield ~5 different shapes. This matters because both the correctness check and the perf harness iterate over every case get_inputs() yields:
- Correctness only runs on one shape, so a HIP kernel hard-coded to that exact shape/launch config still passes. The multi-shape pattern is what guards against that overfitting.
- The speedup is measured on a single shape (no averaging across sizes), so it's noisier and less representative.
Could we have these emit a few shape variants like the gpumode tasks do? (The converter appends KernelBench's get_inputs verbatim, and upstream only ships one case — so it'd be a small change in the generator to produce a multi-shape generator.)
2. Please don't commit the migration tooling.
tools/kernelbench_to_torch2hip.py, tools/validate_functional_cpu.py, and tools/kernelbench_src/ are essentially a one-time migration tool that converted KernelBench into our task format. Once the tasks are generated we don't need it living in the main repo (and it also drags in the vendored KernelBench sources + their licensing/attribution question). Suggest keeping it in your fork and only committing the generated tasks/ + the config.yaml registration here. If we ever want to regen, the tool's still in your fork.
3. Group tasks into l1/l2/l3 subdirectories.
Instead of flat l1n1_..., l2n6_..., l3n44_... names, could we nest them as kernelbench/level1/..., kernelbench/level2/..., kernelbench/level3/...? Cleaner to browse and the level grouping is more obvious. (Just note the eval_tools kernel_name derivation splits on _, so we'd want to keep the per-task folder/file naming consistent with however that's resolved.)
|
Thanks for the detailed review! I've pushed commits addressing all three points.
Every KernelBench task's get_inputs() is now a generator yielding 5 geometrically-escalating shape cases (following the gpumode torch2hip style), so correctness runs across multiple shapes and the speedup is averaged across sizes instead of a single one. I kept dimensions that are baked into the weights/init (channels, in_features, embed_dim/n_embd, LayerNorm normalized shape, etc.) fixed, and only varied the free dims (batch, spatial H/W, sequence length, matmul outer dims) — varying an init-tied dim would break the functional model's parameter alignment with the reference module. A few task-specific notes following the gpumode logic: l1n26_GELU_ spans multiple ranks (1D→4D), mirroring its gpumode twin 14539_GELU.
Dropped tools/kernelbench_to_torch2hip.py, tools/validate_functional_cpu.py, and tools/kernelbench_src/ from the PR.
Tasks are now nested under kernelbench/level1/, level2/, level3/ (moved via git mv, history preserved). I intentionally kept the per-task folder/file names unchanged (e.g. level1/l1n26_GELU_/hip/hip_l1n26_GELU_.hip) so the eval_tools kernel_name derivation (hip_file.split('.hip')[0].split('_', 2)[-1]) still resolves to the class name. config.yaml registration updated to the nested paths; all 33 resolve via task discovery. Happy to strip the now-redundant l1n/l2n/l3n prefixes (e.g. level1/26_GELU_/) if you'd prefer — works either way. |
|
Hi, quick heads-up: we are currently working on a larger refactor #48 that moves the benchmark/runtime flow to a Docker-first environment. This touches a lot of shared infrastructure, so reviews and merges may be slower than usual for a bit. Once that refactor lands, I’ll help rebase open PRs onto that one. Sorry for the delay, and thanks for your patience. |
Add 33 KernelBench-derived torch2hip tasks (Levels 1-3) under tasks/torch2hip/kernelbench/ with realistic shapes, plus the generator and CPU-equivalence tooling under tools/. Fix the 14539_GELU task, which previously computed ReLU instead of GELU.
Add the level1/2/3 torch2hip/kernelbench tasks to the task selection list, matching the existing convention of listing all available tasks.
…oling - get_inputs() now yields multiple shape variants per KernelBench task (mirrors gpumode torch2hip pattern) so correctness guards against shape-hardcoded kernels and speedup is averaged across sizes. Dims tied to weights/init are held fixed; only free dims (batch/spatial/seq/matmul outer) vary. Validated module==functional on MI300X for all 33 tasks. - Nest tasks under kernelbench/level1|level2|level3/ for clearer browsing; per-task folder/file names kept so eval_tools kernel_name derivation is unchanged. config.yaml registration updated to nested paths. - Remove one-time migration tooling (kernelbench_to_torch2hip.py, validate_functional_cpu.py, kernelbench_src/) from the repo.
Aligns KernelBench get_inputs() with the gpumode torch2hip style while keeping KernelBench's large, perf-relevant scale: - ~5 geometrically-escalating cases per task with explanatory comments - init-tied dims pinned to module constants (channels/features/embed) - rank diversity where the op allows: l1n26_GELU_ spans 1D-4D (cf. gpumode 14539_GELU) - l1n95_CrossEntropyLoss now varies num_classes as well as batch (no init -> class dim free) Validated module==functional on MI300X for all 33 tasks (5 cases each).
90a9372 to
4ffd373
Compare
Summary
tasks/torch2hip/kernelbench/, each with itsconfig.yamland eval harness(
eval_tools/), PyTorch module/functional references, and HIP kernel stub.14539_GELU, which previously computed ReLU instead of GELU.tools/kernelbench_to_torch2hip.py),the upstream KernelBench reference sources (
tools/kernelbench_src/), and aCPU functional-equivalence checker (
tools/validate_functional_cpu.py).Test plan
python main.py(config targeting atorch2hip/kernelbenchtask)task_validatoragent