Skip to content

hk-dsl documentation

hk-dsl makes vLLM and SGLang faster on Radeon GPUs, and is the Python DSL those kernels are written in, for RDNA and CDNA, with build-time gates against silent tile-level errors (spills, missing waits, MFMA hazards). What it is and is not has the comparison with Triton, FlyDSL and AITER, the supported hardware, and where the numbers come from (the scorecard).

Start here

To make vLLM or SGLang faster on a Radeon W7900 / RX 7900 or R9700 / RX 9070: pip install hk-dsl in the engine's environment, then hk in vLLM or hk in SGLang -- how to check it is on, which GPUs and models, how to turn it off.

To write kernels, five pages, in order, take you from nothing to a kernel that is checked for correctness and timed against torch.compile:

  1. Install, then the quickstart: a first kernel from a template, checking it, and a kernel written by hand.
  2. The templates: elementwise and rowwise (the math of an element or a row) and GEMM with an epilogue. Start here whenever one fits.
  3. hk.check: resources, correctness against torch and speed against torch.compile, in one command, after every edit.
  4. The language: what a kernel body is written in, for when no template fits.
  5. The API reference: every public name, generated from the code; hk.math is the list of elementwise functions.

Coding agents: start from llms.txt and the hk-kernel skill instead.

Every page

What it is

page
What it is and is not the positioning, the three layers (language, kernels, engine routes), the comparison with Triton, FlyDSL and AITER, supported hardware and toolchains
The scorecard the only performance numbers the project quotes: end-to-end serving results
How the numbers are taken the measurement rules: one process interleaved, checked first, past the cache, the median of rounds, verdict bands; end to end, same-session arms and compared outputs

Writing kernels

page
Install what you need, the tested toolchains, the wheel or a build from source, a clone for the examples and tests
Quickstart hk in vLLM or SGLang in one command; a first kernel from a template, hk.check, a kernel written by hand, the four entry points, timing
Supported hardware which GPUs, what the language and each engine route do on each (generated)
Templates: elementwise and rowwise hk.templates.elementwise / rowwise: hooks, operands, the per-GPU plan and how to override it, limits, and a dated record of what they measured
Templates: GEMM hk.templates.gemm(epilogue=...): writing an epilogue, the ready-made ones, how the plan follows hk.ops.matmul, limits, and a dated record of what it cost
Schedules hk.schedules: what hk runs for a GEMM shape, every knob of each kernel family as data, check() with reasons before compiling, the legal space around a schedule, records, hk.templates.gemm(schedule=)
How a kernel runs the pipeline: trace, the hk dialect and its passes, HipKittens C++, hipcc and the gates, the launch; who does what
Tiles, strips and LDS register tiles, register strips, LDS tiles and vectors: which one a kernel wants, and what the passes do for LDS
The correctness gates the tile-level traps that give no diagnostic, and the gate that stops each, by stage
XCDs, placement and hk.comm gfx950's eight L2s: placement, and hand-offs between XCDs and GPUs
Workgroup placement placement= on gfx950: when it pays, "auto" or a fixed placement, checking it, what it measured, turning it off
The language kernels and parameters, tiles and strips, operators, memory, control flow, hk.comm between XCDs and GPUs, workgroup placement, namespaces, @hk.func, errors, limits
Migrating: the DSL surface the deprecated spellings and their replacements, tools/surface/migrate.py, and the rule that keeps a migrated kernel byte-identical: bind inline loads to locals in the old argument order
Op catalog every kernel family hk.ops ships: the GPUs it runs on, what it takes, the engine routes that call it and its tests (generated)
API reference every public name's signature and docstring, generated by scripts/gen_api_docs.py, with what is newer than the 0.9.24 wheel marked
Examples which GPUs each runs on; eleven kernels written from scratch in the order they introduce the language, from a vector add to flash attention; two built from templates; two about gfx950's XCDs (hk.comm, placement); validate.py

Checking and measuring

page
hk.check the loop: build and resources without a GPU, correctness against a torch reference, interleaved timing against torch eager and torch.compile, --json
hk.profile why it runs at that speed: rocprofv3's counters and thread trace per kernel -- the roofline, matrix core busy, occupancy, the grid's tail, where the waves wait, the main loop's instructions -- and a verdict, --json for agents
Performance a dated record, not current claims: older measurements with their baselines, software stacks and source chapters, RDNA3 and CDNA4 apart, end to end, kernel for kernel, and the losses
Tuning a GEMM: hk.tune python -m hk.tune MxNxK or --model: search hk's GEMM schedules within a GPU-time budget, keep a winner only past the measured noise, as a record hk.ops.matmul reads
The tuning benchmark hidden real-model GEMM shapes per GPU, every baseline (hipBLASLt, TunableOp, aiter, FlyDSL, HipKittens, Triton), the scoreboard before and after hk.tune
The DX suite eight LLM kernel tasks with references and baselines on both GPUs, one command to a JSON scoreboard
What the DX suite found kernels written from the docs alone, and the doc gaps they hit, ranked

How it works

page
The IR the hk dialect's types and ops, the passes, the C++ translation, hk-opt / hk-translate
The runtime arch detection, hipcc and the cache, the resource gates, the code-object checker, the stream a kernel launches on, autotune, torch.ops
Toolchains which hipcc (AMD clang 20-24) builds and runs on which GPU, how each is checked, and and the issues fixed in each release
Building MLIR and the dialect, the wheels and what they carry, the repository layout
Testing the test tiers, CI and the GPU tier's self-hosted runners, the engine contract tests, the performance gate
Releasing the release steps, and the documentation sync that must pass before a tag
API stability what each release promises to keep: the stable names, the experimental ones, what no release promises, the platforms

Serving engines

page
hk in vLLM enable hk in vLLM in one command, check it is on, which GPUs and models, turn it off, troubleshooting
hk in SGLang the same for SGLang, and SGLang-Diffusion's one install command
hk in Megatron-LM training RDNA4 (gfx1201) FP8 training: one launcher, hk's attention and fc1 backward, the configuration, the measured A/B (draft)
Integration what applies to every engine: on by default and turning it off, --status, the plugins, Op / Patch / RouteTable, host time, routing tables, the CUDA-graph contract, supported versions and contract tests, your own kernel, the environment variables
Support matrix the engine versions, images and GPUs this release is tested with (generated)
Use a kernel as a PyTorch op hk.torch_op: your kernel as a torch.library op, eager, under torch.compile and in CUDA graphs, and what Inductor does not do with it
vLLM routes reference, each vLLM route: vision-tower SDPA, prefill attention on vLLM's cache, the decoder attention backend, linear layers (and a model no table measured), MoE, 4-bit, DeepSeek-V4.1's index launch
SGLang routes reference: SGLang's linear and MoE routes; SGLang-Diffusion's attention and linear
For agents: kernels in an engine headroom, new-op, ab --json: find a step's gap, add a kernel, prove it helped; the numbers not to trust

For coding agents

page
llms.txt the map, a ten-line kernel, the pitfalls
llms-full.txt the language, hk.check, the templates and the API reference in one file
The hk-kernel skill the write-check-iterate loop, as a Claude Code skill or a Cursor rule
Cross-architecture API audit where an hk.ops op's arguments or behaviour differ between gfx1100 and gfx950

Design and history

page
The end-to-end loop from "this model is slow" to "my engine runs hk's kernel": measure, attribute, check at the model's shapes, patch without editing the engine, check the output, profile again -- with Qwen-Image 2.1 on a W7900D as the worked example
The end-to-end goal after the tuning goal: a few kernels that are hot, under-optimised by every AMD library, and winnable -- chosen from measured opportunity tables -- and where they stand (K1, K2, K3 in main, on by default)
The DX goal the goal the templates, hk.check and these docs serve, and its acceptance criteria
Schedules as data hk.schedules' design: one type per kernel family, legality and how it was measured, the record formats, the byte-identical round trip
CDNA3/4 what is RDNA3-only, what HipKittens offers on gfx942/gfx950, and what runs on an MI355X
HipKittens on CDNA4 HipKittens' gfx950 GEMM and GQA forward as hk ops: constraints, measurements, the route table
Serving readiness what 0.6 lacked before hk went on by default in an LLM deployment (0.7.0): DSL capabilities and kernel validation apart, with evidence, cost and priority, and the minimum deployable set
hk.comm hand-offs between gfx950's XCDs and between GPUs: why the scope is the tensor's, the lowering a litmus suite found correct, what it measured, the roadmap
Workgroup placement which XCD runs which workgroup, as a pass: the analysis, the rewrite, the "auto" policy and the measurements behind it
The DSL surface approved design: every kernel-specific op and C++ helper inventoried and classified (merge / keep / delete), the general abstractions they fold into, a bit-identical migration, and the rule for new kernels (CONTRIBUTING.md)
Development record the chronological record, chapter by chapter, negative results included

In these pages, a path under <workspace>/ is in the maintainers' working directory on the development machines, outside the repository (reports, task workspaces, raw data); <dev-pod>, <vllm-pod>, <ci-pod>, <jump-host> and <prefix> stand for the names of the machines, pods and runners the work ran on, which belong to their configuration, not to this public repository.

Why this exists

Fast tile kernels for AMD GPUs can be written in C++, as HipKittens shows. Three things stood between that and a faster model. The serving engines do not use such kernels on a Radeon; at the tile level the kernels fail silently; and writing and tuning them by hand is slow. This section takes each in turn, with what hk-dsl does about it and where it stops.

The engines leave Radeon on slow paths

vLLM and SGLang are tuned for Instinct. On a W7900D (gfx1100), hk's routes replace these calls, each one only for the shapes where hk's kernel measured faster than what the engine runs:

  • SGLang's linear layers, which are F.linear on ROCm (hipBLASLt).
  • SGLang's MoE, which does not run on gfx1100: sgl_kernel's top-k faults. hk's patch replaces the top-k and the expert GEMMs.
  • vLLM's 4-bit linear layers, a Triton AWQ kernel on ROCm.
  • vLLM's MoE, Triton's fused_moe.
  • vLLM's decoder attention, Triton's unified_attention, through hk's attention backend. It is off by default (integration).

Each patch can be turned off by an environment variable, sends each shape to the kernel that measured fastest for it, and keeps to the CUDA-graph contract (integration). A model nobody tuned for gets its linear layers' routes measured at its first start. What the routes gain end to end on Radeon will be published with the RDNA scorecard.

On an MI355X (gfx950) the engines are tuned for the card through AITER. There hk's default routes give DeepSeek-V4.1-Flash on vLLM (TP2) about +5% on 8k-token prefill over a stock vLLM that already uses AITER's tuned paths (the scorecard).

Why not HipKittens' C++ directly

HipKittens' include/rdna3 is about 12,000 lines of tested C++. Using it meant writing C++: kernels/rdna3/attn/fwd/attn.cpp is 1108 lines with 18 #define knobs, and retuning meant editing macros, make clean, rebuild, remeasure. vLLM and SGLang could not touch it.

hk-dsl keeps HipKittens as the backend: its tiles, MMAs and waits, in the C++ it generates. In front of it are a typed Python layer, an MLIR dialect whose passes check and derive what the C++ left to the author, a tuner, and the engine layer. The knobs are Python parameters a tuner searches, and a kernel becomes a torch op, then an engine patch, in a few lines. A kernel written in hk-dsl compiles to that C++ and runs at its speed, no faster. One 59-line strip kernel is RMSNorm, LayerNorm, softmax, the weighted RMSNorm and the fused add + RMSNorm.

Why not only Triton or FlyDSL

Each covers part of the space:

  • FlyDSL has a GEMM dispatcher with instruction-level control. It has no attention on gfx11, because its flash attention stages K/V through a global-to-LDS load gfx11 does not have.
  • Triton schedules the tile itself, and is much cheaper to write. The attention torch runs on ROCm is aotriton.
  • hk-dsl gives tile-level control on RDNA3 and RDNA4 as well as CDNA, attention included, with the build-time gates below.

So hk-dsl is built to sit beside them. A route table may name FlyDSL's kernel, HipKittens' own or the engine's for the shapes where they measured fastest (FlyDSL on the routes).

The traps, and the gates against them

The tile-level mistakes that produce no diagnostic -- a matrix-core instruction hoisted above its wait, a spill reordered against hand-placed waits, a slow operand layout, a copy racing a barrier -- and the gate that stops each one are on the correctness gates.

Where it stops

  • One GPU of each kind. Every number is from one W7900D or one MI355X. The engine results are mostly the W7900D's; on the MI355X only vLLM has been measured end to end; gfx1201 runs the GPU tier on an R9700, and three vLLM routes are on by default there (integration), and gfx942 has only been compiled for (CDNA3/4).
  • Some kernels lose. Where hk's kernel is slower than the engine's for a shape, the routing leaves that call to the engine: on the W7900D the MoE GEMM above 256 tokens and the W4A16 GEMM at 1-4 tokens; on the MI355X most GEMMs, norms and bf16 MoE GEMMs against AITER's tuned ones, so hk's unquantized-linear and bf16 MoE routes do nothing there. Performance, a dated record, lists the losses as they were measured, for CDNA4 as well.