Archived
libr4d: step past the full-card launch cliff in qkv_norm_rope and the row norms
On gfx1201 a launch whose wavefronts fall in the last 32 before a multiple of 2048 (every wave slot of the R9700's 64 CUs x 2 SIMDs x 16) runs about five times slower than the same work one workgroup wider, whatever the kernel does. A launch-count sweep on one card (2026-10-17): 256-thread workgroups take 27.6 us at 253 to 256 of them and 5.2 us at 252 or 257, for a norm, an LDS-only kernel and a plain copy alike; 128- and 512-thread workgroups hit it at the same wavefront counts. An empty kernel does not, and moving the data does not move it. The 31B lands on it: qkv_norm_rope at a tp-4 verify is 16 rows x 16 heads of 8 wavefronts, exactly a full card (21 us a call against ~6 expected; kbench's one-card 4-row point, 256 workgroups, 17.4 us against 5.3 at 8 rows), and a drafter's 256-row head norm through rmsnorm likewise (21.9 us). r4d_cliff_rows(rows, per_row, waves) is the row count to launch: `rows` when clear of the window, else the first count past it. qkv_norm_rope, rmsnorm and rmsnorm_p launch that many and return at once in a row at or past the real count, so every result is the same bytes. r4d_selftest's qkv_norm_rope case gains 8 rows of the head-256 class (32 heads a row: 256 workgroups, padded). The window's two numbers are the R9700's, named as such in r4d_common.h, and apply on every target libr4d builds for (RDNA4 only). They are not derived from the device: no other card has been measured, and HIP's multiProcessorCount counts WGPs, not CUs, on RDNA. On an RDNA4 part with fewer CUs a launch padded here costs one idle row and gives the same bytes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
13a917910f
commit
dffec0b770
4 files changed
+52
-11
No files matched your search
@@ -282,3 +282,31 @@ __host__ __device__ __forceinline__ int r4d_act_threads(int M, int K) {
|
||||
const int lim = K >= 8192 ? (1 << 24) : (K >= 4096 ? 120 : 72);
|
||||
return M <= lim ? 512 : 256;
|
||||
}
|
||||
|
||||
// The full-card cliff, measured on the R9700 (gfx1201, 64 CUs). A launch whose wavefronts fall
|
||||
// in the last 32 before a multiple of 2048 runs about five times slower than the same work one
|
||||
// workgroup wider, whatever the kernel does: 256-thread workgroups take 27.6 us at 253 to 256 of
|
||||
// them and 5.2 us at 252 or 257, a norm, an LDS-only kernel and a copy alike. The 31B's
|
||||
// qkv_norm_rope at a tp-4 verify is exactly 256 such workgroups (16 rows x 16 heads), and a
|
||||
// drafter's 256-row head norm too.
|
||||
//
|
||||
// 2048 is every wave slot of the R9700 (64 CUs x 2 SIMDs x 16). Both numbers are that card's and
|
||||
// apply on every target libr4d builds for; they are not derived from the device, since no other
|
||||
// card has been measured and HIP's multiProcessorCount counts WGPs, not CUs, on RDNA. On an RDNA4
|
||||
// part with fewer CUs a launch padded here costs one idle row and gives the same bytes, and a
|
||||
// cliff at that part's own full-card size, if it has one, is not stepped past.
|
||||
//
|
||||
// r4d_cliff_rows() is the row count to launch for a grid of `rows` x `per_row` workgroups of
|
||||
// `waves` wavefronts each: `rows` where that is clear of the window, else the first count past it.
|
||||
// The kernel returns at once in a row at or past `rows`, so the result is unchanged.
|
||||
constexpr uint32_t kR4dCliffWaves = 2048; // the R9700's wave slots: 64 CUs x 2 SIMDs x 16
|
||||
constexpr uint32_t kR4dCliffWindow = 32; // the slow window, below each multiple of it
|
||||
__host__ __device__ __forceinline__ uint32_t r4d_cliff_rows(uint32_t rows, uint32_t per_row,
|
||||
uint32_t waves) {
|
||||
uint32_t r = rows;
|
||||
for (int i = 0; i < 64; ++i, ++r) {
|
||||
const uint64_t w = (uint64_t)r * per_row * waves % kR4dCliffWaves;
|
||||
if (w != 0 && w <= kR4dCliffWaves - kR4dCliffWindow) break;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
Reference in new issue
Block a user