Skip to content

hk.target: the facts per architecture

Stability: experimental. These names may change in any release (stability).

Architecture facts, as data.

Every number here was measured on the part, not read off a datasheet. The provenance of each one is in the module that defines it. One definition, shared by the frontend, the autotuner and the runtime's occupancy arithmetic; the C++ passes read the same table from mlir/lib/Target/Target.cpp, and a test holds the two equal field by field -- these facts used to be scattered across RDNA.md, kernel comments and a notebook, and they drifted.

Targets

gfx1100 gfx1201 gfx942 gfx950
lanes a wave (wave) 32 32 64 64
waves a SIMD holds (max_waves_per_simd) 16 16 8 8
VGPRs a SIMD (vgprs_per_simd) 1536 1536 512 512
VGPR allocation granule (vgpr_granule) 24 24 8 8
LDS a workgroup may take (bytes) (lds_per_workgroup) 65536 65536 65536 160000
LDS shared by a pool (bytes) (lds_pool_bytes) 131072 131072 65536 163840
SIMDs sharing that pool (simds_per_lds_pool) 4 4 4 4
register strips (hk.RS) (strips) True True False True
tiles take a fragment shape (frag=) (tile_shapes) False False False True
global -> LDS DMA (g.load(..., wait=False)) (has_global_to_lds_dma) False False True True
AGPRs charged with the VGPRs (unified_agprs) False False True True
largest lgkmcnt (lgkmcnt_max) 63 63 15 15
measured on the part (verified) True True False True
matrix instructions (mma) bf16 16x16x16, fp16 16x16x16, i8 16x16x16 bf16 16x16x16, fp16 16x16x16, i8 16x16x16, fp8e4m3 16x16x16, fp8e5m2 16x16x16 bf16 16x16x16, fp16 16x16x16 bf16 16x16x32, fp16 16x16x32, fp8e4m3 16x16x128

gfx1100 (W7900D), gfx950 (MI355X) and gfx1201 (R9700) run; gfx942 is compile-only. hk.arch.target() is this record inside a kernel being traced, hk.target.current_arch() the arch a kernel that names none builds for ($HK_ARCH, else the GPU).

hk.target.current_arch

hk.target.current_arch() -> str

The arch a kernel that names none is built for, decided once per process.

hk.runtime.arch.detect's answer -- $HK_ARCH first, which is the only way to build for a part that is not in the machine and how the gfx1201 kernels get their compile gate here; then the GPU torch or rocminfo sees. Else gfx1100, the part this library was measured on: tracing and compiling need no GPU, and a box without one should get the source a W7900 would.

hk.target.get_target

hk.target.get_target(arch: str)

Look up a target by gfx name or by the GPU_TARGET name common.mk uses.

hk.target.Target

class hk.target.Target(arch: str, gpu_target: str, kittens_define: str, wave: int, max_waves_per_simd: int, vgprs_per_simd: int, vgpr_granule: int, sgprs_per_wave: int, lds_per_workgroup: int, lds_pool_bytes: int, simds_per_lds_pool: int, mma: Dict[str, hk.target.base.MmaShape] = <factory>, has_global_to_lds_dma: bool = False, mma_operands_mirrored: bool = False, fast_smem_layouts: Tuple[str, ...] = ('row',), verified: bool = True, unified_agprs: bool = False, tile_shapes: bool = False, lgkmcnt_max: int = 63, extra_includes: Tuple[str, ...] = (), strips: bool = False, kernarg_preload: bool = False) -> None

Target(arch: str, gpu_target: str, kittens_define: str, wave: int, max_waves_per_simd: int, vgprs_per_simd: int, vgpr_granule: int, sgprs_per_wave: int, lds_per_workgroup: int, lds_pool_bytes: int, simds_per_lds_pool: int, mma: Dict[str, hk.target.base.MmaShape] = , has_global_to_lds_dma: bool = False, mma_operands_mirrored: bool = False, fast_smem_layouts: Tuple[str, ...] = ('row',), verified: bool = True, unified_agprs: bool = False, tile_shapes: bool = False, lgkmcnt_max: int = 63, extra_includes: Tuple[str, ...] = (), strips: bool = False, kernarg_preload: bool = False)

Target.vgpr_rounded

Target.vgpr_rounded(self, vgprs: int) -> int

VGPRs actually charged for a kernel that uses vgprs.

Target.charged_vgprs

Target.charged_vgprs(self, vgprs: int, agprs: int = 0) -> int

The register count occupancy is computed from: the VGPRs, plus the AGPRs where they share the file (allocated from the next multiple of four). Rounding to the granule is vgpr_rounded's job, not this one's.

Target.occupancy

Target.occupancy(self, vgprs: int) -> int

Waves/SIMD the register footprint allows. Register-only: LDS can and does bind below this.

Target.vgpr_headroom

Target.vgpr_headroom(self, vgprs: int) -> int

VGPRs addable before occupancy drops a step. 0 means the kernel is sitting exactly on the edge.

Target.occupancy_by_lds

Target.occupancy_by_lds(self, lds_bytes: int, waves_per_workgroup: int) -> int

Waves/SIMD the LDS footprint allows, for comparison against occupancy(). The binding limit is the smaller of the two, and for the GEMM in this repo it was this one -- which is why a kernel is never judged on the compiler's register-only occupancy alone.

Worked example, the shipped attention config on gfx1100: two 8 KB tiles double buffered is 32 KB, so four workgroups of 12 waves fit the 128 KB pool -> 48 waves / 4 SIMDs = 12 waves/SIMD, so its 238 VGPRs (6 waves/SIMD) are what bind, not the LDS.

Target.tile_vgprs

Target.tile_vgprs(self, dtype_bits: int, rows: int, cols: int) -> int

VGPRs one register tile occupies, per lane.

A 16-bit tile is stored in the mma operand fragment layout and a 32-bit tile in the accumulator layout, so the cost follows from the mma shape rather than from the element count. On gfx1100 both come to 8 VGPRs per 16x16 base tile -- that is the mirrored-halves fact (1) restated: a bf16 operand tile is exactly as expensive as an fp32 accumulator tile, which is what bounds tile shapes on this architecture.

On CDNA the fragment is not 16x16 -- gfx950's bf16 operand is 16x32 -- so the price is scaled by the fragment's element count, not by a count of 16x16 bases. For every 16x16x16 target the two are the same number.

Target.occupancy_achieved

Target.occupancy_achieved(self, vgprs: int, lds_bytes: int, waves_per_workgroup: int) -> int

What the kernel actually gets: the smaller of the two limits.