Archived
A complete row set for the gfx11 family (1100/1101/1102/1103/1150/1151 plus gfx11-generic), mirroring libr4d's structure: the quantised GEMM rows (m16, tiled, gated, the bf16 logits gemm), the paged and ragged attention for decode and prefill, the KV store, the sampler spine and the spec rows, with the recorded-fixture, board, selftest and comparison-driver gates for each. The gates are the record. Every row is measured against libref on the shape matrix: the recorded fixture at 1153 cases with worst rel_l2 1.362e-03, the board's five modes with bit-identical decision lines, the selftest at 74 rows, and the 233-case served-shape pairing at 0 divergent against the tree libref. End-to-end on a 2B fp8 checkpoint served on the card, coherent through prefix-cache adoption. Two platform laws each shape the design. A kernel that calls device printf takes the implicit hidden_hostcall_buffer argument and is undispatchable by the AQL backend, so the trace records are plain stores behind a budget. And a plugin-owned __device__ global is not a channel into the engine's dispatch path: in a dlopened plugin the runtime's symbol stub is not the address the kernel's module writes, so the served trace channel is a hipMalloc'd record slot passed as a kernel argument, with the device-global ring kept for the board. kv_store bounds its slots at the pool's own plane (n_blocks x block_size), the span the cache operand declares, not at the step's own span: a request that adopts a cached prefix writes its new tokens at the allocator's global block indices, which sit past any bound built from the step's token count, and a slot lost there is KV that attention then reads stale. A corrupt slot map is dropped at the same bound.
58 lines
3.0 KiB
C
58 lines
3.0 KiB
C
/* r3d_tiling.h -- the tiled rows' LDS row law, in one place.
|
|
*
|
|
* Every tiled row in libr3d stages an [rows x pitch] f16 tile in LDS and then reads it back two
|
|
* elements at a time for dot2_f16x2. Two functions spell that out and they must agree exactly, so
|
|
* they live here and the rows include this file.
|
|
*
|
|
* srow(row, c8, pitch) the element offset of the c8-th run of EIGHT elements of `row`
|
|
* srow_pair(row, kc, pitch) the element offset of the pair (kc, kc+1) of `row`, kc even
|
|
*
|
|
* The law, and why it is shaped like this:
|
|
*
|
|
* - Granularity is EIGHT elements (16 bytes at f16): staging writes a uint4 a step, so the XOR has
|
|
* to move whole uint4s and never split one. A swizzle at pair granularity would make the store
|
|
* unaligned and the compiler would say so in bytes of spill.
|
|
* - The XOR is with (row & 7), so eight consecutive rows rotate the runs by one slot each. That is
|
|
* what kills the dot loop's bank conflict: a wavefront reads 32 rows at the same kc, and with the
|
|
* rotation the 32 reads land on 32 distinct 16-byte slots instead of the four a plain row-major
|
|
* tile puts them on.
|
|
* - The mask (pitch / 8 - 1) keeps the rotated index INSIDE the row. pitch is in elements, so a
|
|
* row has pitch/8 runs, and pitch/8 is a power of two for every tile in the library (32, 128).
|
|
* Without the mask a rotated index leaves the row and reads a neighbour's, which is the bug this
|
|
* header exists to prevent: it is silent, it is data-dependent, and it measures 30x off.
|
|
* - srow_pair takes the pair index kc>>3 -- the run the pair lives in -- and adds (kc & 7), the
|
|
* element inside the run. Reading pairs through srow is what keeps the store, the load and the
|
|
* swizzle one statement each.
|
|
*
|
|
* Measured law, in the family's numbers: a row that stages through srow and reads through
|
|
* srow_pair, with dot2_f16x2 accumulating into f32, lands at rel_l2 1.7e-03 against
|
|
* ref_gemm_nt_q's body at a bf16 output (the store's ulp binding, not the fold's) with 83% of
|
|
* outputs bit-exact. A row that gets the swizzle wrong, in either direction, lands at rel_l2 3e+01.
|
|
*
|
|
* Header-only, like the rest of libr3d. Include it in a .hip at file scope, before the kernels; the
|
|
* definitions are in an unnamed namespace, so each translation unit gets its own copy -- which is
|
|
* what the rows had before this header existed, spelled the same way, so the host pass does not see
|
|
* an unused static and the inliner sees the same function it always did.
|
|
*/
|
|
#ifndef R3D_TILING_H
|
|
#define R3D_TILING_H
|
|
|
|
namespace {
|
|
|
|
/* The element offset of run `c8` of `row`. pitch is a row's element count, a power of two. */
|
|
__device__ __forceinline__ int srow(int row, int c8, int pitch)
|
|
{
|
|
return row * pitch + (((c8 ^ (row & 7)) & (pitch / 8 - 1)) << 3);
|
|
}
|
|
|
|
/* The element offset of the f16 pair (kc, kc+1), kc even: the run the pair lives in, plus the
|
|
* element's place inside that run. */
|
|
__device__ __forceinline__ int srow_pair(int row, int kc, int pitch)
|
|
{
|
|
return srow(row, kc >> 3, pitch) + (kc & 7);
|
|
}
|
|
|
|
} // namespace
|
|
|
|
#endif /* R3D_TILING_H */
|