Skip to content

hk.lds

Stability: stable, except where an entry says otherwise (stability).

hk.lds: shared memory -- allocation, and the wait that retires reads.

hk.lds.alloc

hk.lds.alloc(tile: SharedTileType, name: str = 'smem', count: Optional[int] = None, *, shape: Optional[str] = None) -> SharedTile

Reserve an LDS tile, or count of them in one size-aligned block (the two buffers of a pair must differ in one address bit for the XOR swap). Offsets and the 64 KB check come from the hk-lds-alloc pass. An allocation inside a runtime branch is part of the launch's LDS (the two arms of an if start at the same offset); one inside a runtime loop is refused.

shape (gfx950) lays the allocation out as include/cdna4's st_ rather than the layout its reads' fragment picks: "16x64" for tiles read as 16x32 row operands, "32x32" for 32x16 stride-4 col ones. A DMA copy into it reads each row in 128- or 64-byte runs instead of 64 or 32 (the paged decode's copies: 6.15 to 6.9 TB/s with nontemporal), and its reads may conflict on banks more; a read of another fragment is refused. "16x128" (byte tiles): what an fp8 16x128 operand read would pick, named for an allocation only load_fp4_frags_lds reads.

hk.lds.alloc_vec

hk.lds.alloc_vec(ty: SharedVecType, name: str = 'svec') -> SharedVec

Reserve an LDS vector stack of type ty (hk.lds.shared_vec(...) or hk.SV): what hk.collective.cross_warp combines through.

hk.lds.shared_vec

hk.lds.shared_vec(vt: RegVecType, count: int = 1) -> SharedVecType

The LDS type a register vector round-trips through.

hk.lds.reserve

hk.lds.reserve(nbytes: int, name: str = 'reserve') -> None

Take nbytes of LDS and use none of it: an occupancy cap.

A WGP has 128 KB of LDS, so a workgroup holding 30 KB leaves room for four of them, 60 KB for two. A kernel that streams HBM can run faster with fewer rows in flight than its registers would allow (chapter 27); this is the knob, at the granularity LDS gives it.

hk.lds.wait_for

hk.lds.wait_for(*tiles: Tile) -> None

Retire the outstanding LDS reads of tiles and re-bind their registers. The lgkmcnt is derived by hk-lds-pipeline; there is no bare wait, because a wait that names nothing puts back no dependence.

hk.lds.lds_loads

hk.lds.lds_loads(tile: RegTileType, src: SharedTileType, arch: str = 'gfx1100') -> int

ds_read instructions load_shared issues for this pair; 0 when it misses the vectorised path.

On a wave64 (CDNA) target the count depends on the matrix-core fragment, which hk-fragments assigns after tracing, so this only says whether the pair is asynchronous at all; hk-lds-pipeline sets the real count.