/aklr:aklr-kbfrom aklr
Reference for writing fast AMD GPU kernels on gfx950/gfx942 in FlyDSL, Triton/Gluon, or HIP. Covers dense-GEMM, MoE, and attention packages with dispatch, pipelines, autotuning, debugging, and ISA reference.
Ships in aklr. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
What makes a kernel fast on AMD GPUs inside AKLR, by op and by symptom. The op cards (gemm/, moe/,
attention/) and the cases come from FlyDSL kernels: their mechanisms carry to other languages, their numbers were
measured on FlyDSL code unless a sentence says otherwise (re-derive them: § Rules that hold everywhere). How to write
it in a language is in that language's folder: flydsl/SKILL.md (with the FlyDSL side of each op card in
flydsl/<op>.md), triton/SKILL.md, hip/SKILL.md.
Paths below are relative to this folder, except those starting with aklr/, relative to the repository root, and
aiter/ or csrc/, relative to aiter's. File and line citations are to ROCm/FlyDSL v0.3.2 (dd8373349),
AMD-AGI/Primus-Turbo main 7615a5a2 (ca1fdd67 for the expert GEMM in moe/) and ROCm/aiter dbd8bf5
(AKLR_BASELINE_AITER); check out those revisions to follow them. FlyDSL's own skills are linked at v0.3.2, not
copied: flydsl/guides.md and profile.md give each link with what this repository corrects in it; a
§ marked as FlyDSL's is that skill's own numbering.
aklr/ops/README.md § The kernel section and ABI is the authority; where this skill disagrees, the README
wins. Check a plan against this table before writing code.
| Rule | What it rules out here |
|---|---|
Outputs pass the definition's compare block; under determinism: bitwise, the default, two runs are byte-identical (runs_agree, aklr/core/contract/semantics/_compare.py) | Reducing in arrival order (atomic split-K, stream-K fix-ups): reduce in a fixed order (gemm/correctness.md §8, gemm/grid_pricing.md §2) |
A Point is served by the file with the best measured speedup over the baseline, and only from AKLR_MIN_SPEEDUP (1.03) | Judging on a mean: compare each Point with the faster of the kernel AKLR serves there and the baseline |
Launch code (run and what it calls) does not synchronize, call .item() / .cpu(), print, read a clock or the environment, or change torch state (SA3) | Timing or racing configurations in run |
Compilation and the choice of configuration happen in a module-level @functools.cache function on a Point's first call; later calls may be inside a CUDA graph capture | The first-call race of gemm/autotune.md §1 as written: choose from the shape, with a table raced offline |
Inputs other than the mutable ones are read-only (SA2); nothing derived from an argument is kept across calls, and there is no global or nonlocal (SA1) | Caching a repacked weight: repack on every call, or serve the contract's shuffled layout variant where it has one |
Scratch is allocated in the call (torch.empty: contents undefined) or once per shape in the compile function and rewritten before it is read; no call depends on what an earlier call left | Counters that live across calls: zero workspaces in each call before any read (gemm/small_m.md §4). A slot stamped with this launch's 64-bit tag, queue bits included, needs no zeroing as long as no leftover word equals the tag: such a split-K fold is one launch on a torch.empty workspace (gemm/wait_free_fold.md § Folding without a counter) |
Not in the README or its audit, but keep to it: no workgroup waits for another without a way out: a launch's workgroups need not all be resident (a stream limited to part of the CUs, another kernel holding CUs), so a wait on a flag another workgroup writes is bounded, and on timeout hands its share to the last to arrive (attention/split_kv.md §2 Bounded wait); the driver's --stress passes at every Point the file lists | A split-K fold or split-KV merge whose owner polls its partners with no bound, or gives up and writes: merge in a separate launch, have each publish and count in on an atomic counter and the last to arrive merge, or wait bounded with hand-off, in a fixed order |
run(*, <kernel_call_keys>) writes the preallocated outputs and returns nothing; the entry file's docstring describes the kernel, with no history or speedup (SA4) | Allocating outputs; importing sibling files other than relatively (the package name is a hash) |
KB: matched <page> §<n> or
KB: no-match <question>. The no-match lines are what this skill is missing.| Task | Read in this order |
|---|---|
| Write or optimize a dense GEMM (fp8 / MXFP4 / MXFP8 / bf16) | gemm/INDEX.md → the card it routes to |
| A GEMM with M ≤ 256 (as in decode or speculative verify) | gemm/small_m.md |
| A GEMM on gfx942 (MI300X) | gemm/gfx942.md |
| A MoE layer at any token count (MXFP4 experts, routing sort, stage 1 / stage 2), or its expert GEMMs as a grouped GEMM: per-size configuration, tile and occupancy, XCD placement, low precision and scale preshuffle, sorted-token rows, K varying per group, correctness, measurement | moe/INDEX.md → the card § it routes the problem to; main loop and data path in gemm/ |
| Write or optimize an attention kernel: many query rows per head, the dQ dK dV gradients, or few query rows per head with split KV | attention/INDEX.md → the card it routes to |
| Dump a kernel's IR and final ISA; read registers, LDS, spills, waits and hot-loop counts | gemm/mainloop.md §10 (FlyDSL's FLYDSL_DUMP_IR=1: flydsl/gemm.md § mainloop §10); analysis/isa_diff.py compares two dumps |
| Capture a kernel trace and find the hotspot, or find the commit behind a performance regression | profile.md |
| EP dispatch/combine against TP for a MoE layer at a few tokens per GPU, or a collective's time in a multi-GPU trace | communication/INDEX.md |
| What an instruction, encoding, counter, wait state or hardware limit really is | hardware/gfx950/INDEX.md → hardware/gfx950/lookup.md, hardware/gfx950/matrix_core.md, hardware/gfx950/memory_and_sync.md; gfx942 (MI300X): hardware/gfx942/INDEX.md |
| The language: its API, compile errors, debugging, its own guides | the language's folder: flydsl/SKILL.md, triton/SKILL.md, hip/SKILL.md |
| A Triton or Gluon kernel: authoring, debugging, tuning, numerics, Gluon layouts, memory, MFMA and inline asm, AKLR's Triton kernels by family, its GEMM, MoE, attention and GatedDeltaNet kernels | triton/SKILL.md → the page its task table names |
| What the timings, trace or counters show | Read (then the symptom page, for what to rule out first) |
|---|---|
| Not yet known whether it is compute-, memory- or launch-bound | gemm/attribution.md §1–3 |
| Fewer workgroups than CUs, or a last dispatch round mostly empty | gemm/grid_pricing.md §1–2, §10; patterns/low_cu_utilization.md |
| M ≤ 256 on a row bound by launch, reduction and latency, not by reading B | gemm/small_m.md §2–3; patterns/launch_floor_small_m.md |
| LDS bank conflicts | gemm/datapath.md §3; patterns/lds_bank_conflicts.md |
| MFMAs wait on global loads; bytes / time near the measured stream bandwidth | gemm/datapath.md §5, §7; patterns/memory_bound.md |
| Spills, VGPR / AGPR pressure, one wave per SIMD | gemm/mainloop.md §4, §7, gemm/grid_pricing.md §4; patterns/register_pressure.md |
| The store costs more than expected | gemm/epilogue.md §2–3 |
| Memory-bound with a linear tile order: tiles that share a panel land on different XCDs | gemm/schedule_and_locality.md §2 |
Stalls on s_waitcnt | gemm/schedule_and_locality.md §4, hardware/gfx950/memory_and_sync.md §1 |
| A fixed cost per tile: time not proportional to K | gemm/attribution.md §7, gemm/grid_pricing.md §6 |
| Clocks drop under load; slower than the instruction count says | gemm/attribution.md §4 |
| A gain that does not reproduce, or an A/B inside the noise | gemm/measurement.md §1, §4 |
| Outputs that differ between runs | gemm/correctness.md §3, §8 |
| A change wins on some shapes and loses on others | gemm/autotune.md §1–2; patterns/shape_divergence.md |
## Evidence that gives the conditions.AKLR_BASELINE_AITER
(.github/workflows/ci.yaml): AKLR does not ship, patch or fall back to it, so its aiter/ paths are that
revision's, read as reference code. Price aiter through the op's <contract>_baseline
(aklr/ops/<op>/baseline.py), the call bench times. At a Point no kernel serves, the api returns a
FallbackReason and its caller runs its own path. AKLR's plugins route a model to plugin ops and to some
aklr/ops ops (vLLM's GEMM and MoE layers, sglang's DSA paged MQA logits; aklr/plugins/README.md), so an
aklr/ops kernel runs in a model only where such a route or the engine calls its api.aklr/ops/README.md § Workflow): export the Points, fill kernel.sources, then
python -m aklr export check and python -m aklr validate --base origin/main. The local result does not
count; CI measures. A platform_failure whose message names rocprofiler-sdk or the graph replays, or says "the
kernel tracer failed" or "calibration could not restore", is a tracer fault, already measured again in fresh
processes: rerun (aklr/core/validation/stages/_measure.py, pitfalls/profiler_misses_kernels.md).GPU_FORCE_QUEUE_PROFILING forced) AKLR read about 4 µs per kernel however little it did, so a short kernel and
its baseline read about the same. Main's profile 19 (its own rocprofiler-sdk tracer, queue profiling not forced)
still has that floor, about 4.4 µs: a bmm candidate 1.50× faster back to back read 1.13× on it. Time an empty
kernel, the baseline and your candidate on current main before deciding a Point has no headroom
(pitfalls/aklr_dispatch_floor.md § Root cause).CONTRIBUTING.md: what each folder holds, the page kinds, and how a page gets in.
CONTRIBUTING.md (opens in a new tab)analysis/budget.py (opens in a new tab)analysis/hotspot_analyzer.py (opens in a new tab)analysis/isa_diff.py (opens in a new tab)analysis/pmc_l2_analyzer.py (opens in a new tab)attention/INDEX.md (opens in a new tab)attention/attribution.md (opens in a new tab)attention/correctness.md (opens in a new tab)attention/gradients.md (opens in a new tab)attention/grid_dispatch.md (opens in a new tab)attention/lds.md (opens in a new tab)attention/measurement.md (opens in a new tab)attention/mfma_layout.md (opens in a new tab)attention/registers_occupancy.md (opens in a new tab)attention/schedule_sync.md (opens in a new tab)attention/softmax.md (opens in a new tab)attention/split_kv.md (opens in a new tab)attention/workflow.md (opens in a new tab)cases/INDEX.md (opens in a new tab)cases/a8w8_n4096_k_sweep.md (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub amd-agi/aklr --plugin aklr14 skills in this plugin
/aklr-bad-casesA list of mistakes agents have made in AKLR, with what to do instead and how to spot each one in a code change. Use when reviewing an AKLR change or opening its pull request. Add a case when a new mistake is found./aklr-build-runtime-imageBuild and validate a reproducible runtime image for an exact AKLR revision and declared ROCm stack. Use when kernel review, CI, or downstream qualification needs a traceable test environment./aklr-monitor-upstreamsMonitor configured upstream repositories for new kernels and optimizations, deduplicate candidates, and route them to the appropriate AKLR porting workflow. Use for scheduled or on-demand upstream change discovery./aklr-open-prOpen a AKLR pull request whose body carries the evidence each kind of change needs (contracts, kernels, code, withdrawn kernels, documents), following .github/pull_request_template.md and the review-tier check. Use when committing a AKLR change and opening or updating its PR./aklr-port-generated-kernelsPort agent-generated GPU kernels into AKLR with their provenance, dispatch, fallbacks, and review evidence. Use for kernels produced in generator repositories./aklr-qualify-downstreamQualify an exact AKLR build with supported SGLang, vLLM, and ATOM revisions for API compatibility, correctness, and performance. Use before release or when integration changes may affect downstream engines.Other plugins' skills for the same job