libr3d: the wave-matrix record -- the six 16x16x16 variants, the MAC-core measurement, the i8-x4 gap
RDNA3's ISA lists exactly six wave-matrix instructions (f16, bf16, int8 and int4 in; f32, f16, bf16 and i32 accumulating) and the toolchain emits them on every gfx11 target; they run over multiple cycles driving the DOT pipeline internally, and the MAC-core measurement on the 16-CU gfx1102 part confirms it: f32-acc f16 19.11, f32-acc bf16 19.24, f16-acc f16 19.44, i32-acc i8 19.29 against the paired dot2 path's 18.86 TFLOP/s -- the same pipe within three percent, matching the full-kernel 1.99-vs-1.97 already in r3d_common.h. The i32-acc i4 tile is the exception at 25.68 TFLOP/s, 35% above, but it takes i4 in both operands and the grids served here pair i8 activations against i4 and i2 weights: there is no mixed-precision integer WMMA on RDNA3, so that pipe is unreachable from the w4a8 and w2a8 rows. Commentary only -- the rationale passages in the README, CMakeLists.txt, r3d_rows.cpp, r3d_plugin.h and r3d_selftest.cpp now state the measured record; no kernel, lane map or numeric path changes, and the rebuilt library is byte-identical (selftest 78 rows, 0 failed, 0 skipped).
This commit is contained in:
1 parent
6cb9826975
commit
890715fd96
5 files changed
+49
-31
No files matched your search
@@ -1,8 +1,9 @@
|
||||
# libr3d serves RDNA3 only, declared here and nowhere else. Its kernels rely on wave32 and on
|
||||
# instructions RDNA3 has: v_dot2acc_f32_f16 for the matrix work, v_cvt_pkrtz_f16_f32, DPP16 and
|
||||
# v_permlanex16. They do not use the gfx12 WMMA fragment layouts or gfx12-only instructions such as
|
||||
# global_load_tr_b128, and they decode every quantised weight in software, because RDNA3 has no
|
||||
# fp8 conversion instruction and this ROCm declares no WMMA builtin for any gfx11 target.
|
||||
# v_permlanex16. They do not use the WMMA fragment layouts (RDNA3's 16x16x16 wave-matrix family is
|
||||
# a re-tile of the dot2 lane map, not a drop-in) or gfx12-only instructions such as
|
||||
# global_load_tr_b128, and they decode every quantised weight in software: the lane map, not a
|
||||
# missing instruction, is the reason.
|
||||
#
|
||||
# A build targeting other cards skips libr3d. The engine then has no device kernel library for that
|
||||
# card and refuses ops only a reference library implements, unless
|
||||
|
||||
+36
-18
@@ -8,10 +8,11 @@ ABI ([`r3d.h`](r3d.h)) plus the kernel-plugin rows the engine selects from
|
||||
|
||||
It claims `^gfx11` where [`libr4d`](../libr4d/README.md) claims `^gfx12`: a card gets
|
||||
one device library, picked by the rows and never by the name. The kernels are not
|
||||
libr4d's ported — RDNA3 has no matrix instruction a compiler will emit, no fp8
|
||||
conversion, no bf16 pack, no VOPD — so every arithmetic path is its own:
|
||||
`v_dot2acc_f32_f16` for products, software codecs for every format, a weight read in
|
||||
the order the container stores it. The contract is shared: the same op schemas (copied
|
||||
libr4d's ported: the matrix work runs on the dot2 path — RDNA3's 16×16 wave-matrix
|
||||
family is a fragment layout these kernels' lane map does not use, and gfx11 has no
|
||||
bf16 pack and no VOPD — so every arithmetic path is its own: `v_dot2acc_f32_f16` for
|
||||
products, software codecs for every format, a weight read in the order the container
|
||||
stores it. The contract is shared: the same op schemas (copied
|
||||
slot for slot from libref, as the loader requires), the same numerics rules, the same
|
||||
geometry in constraints. Family parts differ in CU count and clock, never in these
|
||||
instructions, so one code object per family suffices — and every number here is quoted
|
||||
@@ -166,16 +167,33 @@ Measured by reading emitted assembly for the gfx11 targets (`__has_builtin` off
|
||||
tree builds against; where a claim was taken on one chip it says which. Nothing here
|
||||
changes between gfx110x and gfx115x — which is what makes the family one code object.
|
||||
|
||||
**No matrix instructions a compiler will emit.** Every `v_wmma_*` mnemonic is rejected
|
||||
by the assembler on gfx1100, gfx1102 and gfx1151 (and on gfx12, where libr4d does
|
||||
carry a WMMA path: the feature is the target's, not the assembler's); inline asm
|
||||
clears the frontend and dies in `amdgcn-link`. The tile builtin that *does* compile
|
||||
for gfx1100/1102/1151 measured 1.99 against the dot path's 1.97 TFLOP/s at four
|
||||
occupancies, so the tile buys a fragment layout and a block-alignment requirement and
|
||||
no throughput. Products go through `__builtin_amdgcn_fdot2` → `v_dot2acc_f32_f16` on
|
||||
every gfx11 target, paired as `v_dual_dot2acc_f32_f16` where the scheduler can — about
|
||||
a quarter of RDNA4's matrix rate. No fragment layouts, so no repacked weights, so no
|
||||
layout hook except the container's own planes force.
|
||||
**The dot2 path, and the wave-matrix instructions it does not use.** RDNA3 carries
|
||||
exactly six wave-matrix instructions, all 16×16×16 wave32: f16, bf16, int8 and int4
|
||||
in, f32, f16, bf16 and i32 accumulating, and the toolchain emits them on every gfx11
|
||||
target. They are not a separate matrix unit: the ISA states the WMMA ops run over
|
||||
multiple cycles and drive the DOT pipeline internally, and the MAC-core measurement
|
||||
on this part confirms it (512 waves, K depth 4096, operands preloaded: f32-acc f16
|
||||
19.11, f32-acc bf16 19.24, f16-acc f16 19.44, i32-acc i8 19.29, dot2 paired as
|
||||
`v_dual_dot2acc_f32_f16` 18.86 TFLOP/s — the f16/bf16/i8 tiles and the dot path sit
|
||||
on the same pipe within three percent, matching the full-kernel 1.99-vs-1.97 of
|
||||
r3d_common.h). The i32-acc i4 tile is the exception at 25.68 TFLOP/s, 35% above the
|
||||
dot path, but that instruction takes i4 in *both* operands and the grids this
|
||||
library serves pair i8 activations against i4 and i2 weights — there is no
|
||||
mixed-precision integer WMMA on RDNA3, so that pipe is unreachable from the w4a8
|
||||
and w2a8 rows. The i8 tile's only edge over the current w8a8 path is a decode, and
|
||||
the kernel-level measurement closes the question: the w8a8 m16 row runs 0.850
|
||||
TFLOP/s and w4a8 m16 0.789 (M=16, N=11008, K=4096, weights in device memory) --
|
||||
twenty-two times below the i8 tile's own MAC core, weight-byte-bound at the decode
|
||||
band's geometry, where no re-tile of the arithmetic moves the number. These
|
||||
kernels run
|
||||
the dot2 path: one wave a weight row, a k-split per lane, the group's exact sub-sum
|
||||
folded with one shfl. The WMMA fragment layout (lanes 0..15 replicated into 16..31,
|
||||
A one row a lane, B one column a lane, the accumulator's row i at lane (i%2)·16+j
|
||||
VGPR i/2) is a re-tile, not a drop-in, and no measured variant earns it. Products
|
||||
go through `__builtin_amdgcn_fdot2` → `v_dot2acc_f32_f16` on every gfx11 target,
|
||||
paired as `v_dual_dot2acc_f32_f16` where the scheduler can — about a quarter of
|
||||
RDNA4's matrix rate. No fragment layouts, so no repacked weights, so no layout hook
|
||||
except the container's own planes force.
|
||||
|
||||
**No int8 dot.** `__builtin_amdgcn_s32sd4`, `__builtin_amdgcn_s32ud4`, `__dp4a`,
|
||||
`__builtin_amdgcn_madocx_i32_i8` / `_u32_u8` are all undeclared for gfx1102, and all
|
||||
@@ -1055,10 +1073,10 @@ walked — because a ranking is a property of the shape, not of the model.
|
||||
Three properties are assumed throughout and not restated per kernel: **wave32 with a
|
||||
1024-entry VGPR file a SIMD**, so every lane map has a lane owning whole dwords and
|
||||
every budget is computed against 1024; **64 KiB of LDS a workgroup**, which sets the
|
||||
candidate kernels' `n_cand <= 1024` and the tile sizes; **no matrix instruction**,
|
||||
which is why the tile is a dot loop over LDS with an 8-element XOR swizzle, shared by
|
||||
every tiled row in [`r3d_tiling.h`](r3d_tiling.h) and proven byte-identical between
|
||||
them.
|
||||
candidate kernels' `n_cand <= 1024` and the tile sizes; **the dot2 path** (the
|
||||
wave-matrix fragment layout is a re-tile, not a drop-in for these lane maps), which is
|
||||
why the tile is a dot loop over LDS with an 8-element XOR swizzle, shared by every
|
||||
tiled row in [`r3d_tiling.h`](r3d_tiling.h) and proven byte-identical between them.
|
||||
|
||||
**A staged chunk of 8 bytes against a row pitch of 512 is the 2-bit grid moving 8× the
|
||||
bytes it uses** at `kKC` 32: 24.151 ms at M=64, N=130560, K=2048 against a 0.449 ms
|
||||
|
||||
+4
-5
@@ -18,11 +18,10 @@
|
||||
* can match a geometry, it decides which serves. Each group states the reason for its order.
|
||||
* Values are spaced by ten so a row can be slipped between two without renumbering.
|
||||
*
|
||||
* libr3d ships one row per (op, dtype) pair far more often than libr4d does: on RDNA3 there is no
|
||||
* matrix instruction whose fragment layout, tile shape or operand width a kernel has to design
|
||||
* around, so the dot2 kernel that serves bf16 serves f16 with a template argument, and there is
|
||||
* nothing to specialise a second row for. Where two rows of one op do exist, the reason is the
|
||||
* geometry, and it is written next to the pair.
|
||||
* libr3d ships one row per (op, dtype) pair far more often than libr4d does: the matrix work runs
|
||||
* on the dot2 path, whose lane map takes a dtype as a template argument, so the kernel that serves
|
||||
* bf16 serves f16 as is, and there is nothing to specialise a second row for. Where two rows of
|
||||
* one op do exist, the reason is the geometry, and it is written next to the pair.
|
||||
*/
|
||||
enum {
|
||||
/* The common case: this op, these dtypes, one row. Nothing competes with it. */
|
||||
|
||||
+2
-2
@@ -43,8 +43,8 @@
|
||||
* joined operands they store -- the w2a8 row's `b_scale`, the fp8 weight's codes and scale, the
|
||||
* logits head -- and repack nothing, so a container converted on this card keeps row-major codes
|
||||
* against row-major scales. A dot2 GEMM reads a weight in the order it is stored; libr4d's fragment
|
||||
* permutations are a WMMA fact, and RDNA3's tensor cores are not reachable from this toolchain
|
||||
* (r3d_common.h has the measurements).
|
||||
* permutations are a WMMA fact, and RDNA3's wave-matrix instructions use a 16x16 fragment layout
|
||||
* this table's dot2 kernels do not (r3d_common.h has the measurements).
|
||||
*
|
||||
* Pure host C++: no r3d.h, no HIP, so this table compiles and can be read and tested without ROCm.
|
||||
*/
|
||||
|
||||
@@ -21,9 +21,9 @@
|
||||
* over all 256 codes and the encoder over the saturating, subnormal, signed-zero and NaN cases,
|
||||
* int8 against `rad_round_even_sat` over every tie in its band. This is the check `rad-kbench`
|
||||
* cannot do: it compares whole ops, so a codec's disagreement appears as a diffuse percentage.
|
||||
* libr3d's codecs are software -- RDNA3 has no fp8 conversion instruction, and its bf16 packing is
|
||||
* `v_perm` and not `v_cvt_pk_bf16_f32` -- so they are the plugin's own arithmetic and belong to the
|
||||
* tests.
|
||||
* libr3d's codecs are software -- the lane map, not a missing instruction, is the reason, and its
|
||||
* bf16 packing is `v_perm` and not `v_cvt_pk_bf16_f32` -- so they are the plugin's own
|
||||
* arithmetic and belong to the tests.
|
||||
*
|
||||
* Then, on a device, every launch is called with a minimal valid input built from the row's own
|
||||
* `opd_shape`, and every output plane is read back and checked to be finite. That catches the class
|
||||
|
||||
Reference in new issue
Block a user