hk.group¶
Stability: experimental. These names may change in any release (stability).
hk.group(W): what a whole workgroup does together -- the global<->LDS
copies, synchronous and staged through registers.
g = hk.group(8)
As = hk.lds.alloc(hk.ST(hk.bf16, 128, 64), count=2, name="As")
buf = g.stage_buffer(As, name="buf_a")
g.load(As[0], a[idx]) # issue and wait
g.stage(buf, a[idx]) # issue into VGPRs
hk.arch.vm_wait(0)
g.commit(As[1], buf) # VGPRs -> LDS
g.load(As[1], a[idx], wait=False) # gfx950: the DMA, left in flight
g.wait_for(As[1]) # vmcnt, derived
hk.arch.barrier() # every warp's share has landed
hk.group.Group¶
class hk.group.Group(warps: int)
What hk.group(warps) returns: copies between global memory and LDS
done by warps warps together.
Group.threads (property)¶
warps x the wave of the kernel being traced (32 on RDNA, 64 on CDNA).
Group.load¶
Group.load(self, dst: SharedTile, src: View, *, wait: bool = True, rows=None, nontemporal: bool = False, gather=None, staged: Optional[int] = None) -> None
Surface: staged=: deprecated, removed in the release after the last call from outside the repository is migrated, at most two minor releases after its deprecation; use Group.load(gather=).
Global -> LDS by the whole group, issued and waited. Rows of the tile past the tensor's last read zero and touch no memory, on every target (gfx950's copy used to span the tile's whole rows: a last, partial tile read past the tensor).
wait=False (gfx950) issues the DMA, buffer_load ... lds, and returns
with it in flight: name the tile in g.wait_for and put a barrier
after that before any warp reads it. dst is a whole allocation or
one buffer of a stack picked by a Python int, so hk-lds-pipeline can
check every read of it and every later copy into it. rows (with
wait=False) ends the copy that many rows from the tile's first, as
the tensor's last row does: rows past it read zero. nontemporal
(with wait=False) reads past the caches' keeping, sc0 nt, for data
read once -- in runs of a whole line it streams faster; in the
half-line runs of a 16x32 tile it fetched lines twice (4.8 against
6.15 TB/s in the paged decode). gather=ix (with wait=False), an
hk.RowIndex: the tile's rows come by index, row r being the source's
row ids[at + r] & 0xFFFFFF -- AITER's MoE sort ids (token | choice <<
24; its padding is a row past the tensor, which reads zero); src's
coordinate gives the column. With rows (or, left out, the index's
count: rows = count - at), the tile's rows from rows on read zero and
their ids are not read -- an index list that ends inside the tile (a
CSR's last row) is not read past. An index staged by
g.stage_rows(ix, N) is read from LDS, so a lane's row costs no vmcnt
wait (which, in order, would retire the whole prefetch).
gather=(ids, at) and staged=N are deprecated spellings of the
same.
Group.stage_rows¶
Group.stage_rows(self, ix: RowIndex, rows: Optional[int] = None, *, keep_choice: Optional[bool] = None) -> RowIndex
ix's positions [at, at + rows) copied into LDS, then a barrier (every warp must
call it); returns the staged index, which g.load(..., gather=) and
Global.scatter read from LDS -- no vmcnt wait for an index, which in order would
retire every load in flight. For gathers it holds the token rows (ids & 0xFFFFFF);
with keep_choice=True the ids themselves, which a scatter of sort ids needs (at a
multiple of rows). A consumer refuses the other form, and refuses a staged index whose
copy no stage_rows has made before it.
ix may already be described as staged (ix.staged(rows, keep_choice=...), made where
the copies that read it are written, e.g. outside the loop whose body stages it): then
this makes its copy, here.
Group.gather_prep¶
Group.gather_prep(self, ids, at, rows: int, *, raw: bool = False) -> None
Surface: deprecated, removed in the release after the last call from outside the repository is migrated, at most two minor releases after its deprecation; use Group.stage_rows.
Deprecated: g.stage_rows(hk.RowIndex(ids, at), rows, keep_choice=raw).
Group.wait_for¶
Group.wait_for(self, *tiles: SharedTile, exact: bool = False) -> None
s_waitcnt vmcnt(n): this warp's share of the asynchronous copies
into tiles has landed, n derived by hk-lds-pipeline. The other
warps' shares are visible only after a barrier (two inside an
hk.arch.pingpong), and the pass refuses a read before that.
Group.store¶
Group.store(self, dst: View, src: SharedTile) -> None
LDS -> global, by the whole group. Rows of the tile past the tensor's last are not written.
Group.stage_buffer¶
Group.stage_buffer(self, dst: SharedTile, depth: int = 1, name: str = 'buf') -> Stage
The register buffer for copies into dst, sized from it so the two
cannot disagree. Declare it outside any loop.
Group.stage¶
Group.stage(self, buf: Stage, src: View, slot: int = 0) -> None
Issue the global loads for one tile into buf. Does not wait.
Group.commit¶
Group.commit(self, dst: SharedTile, buf: Stage, slot: int = 0, wait: bool = False) -> None
Write a staged buffer to LDS. hk.arch.vm_wait must come first.
hk.group.group¶
hk.group.group(warps: int) -> Group
The workgroup's warps warps acting together: g = hk.group(8), then
g.load, g.store, g.stage/g.commit, g.wait_for. warps is the
kernel's warps= (or the part of it that copies).