fix(isa): wave32 VGPRs allocate in 24s, not 8s

res.sh rounded the VGPR count up to a multiple of 8 before dividing the SIMD's
1536 registers, so 128 VGPRs reported 12 waves where the hardware allows 10, and
256 reported 6 where it allows 5. gfx1201 wave32 allocates in multiples of 24;
wave64 keeps the 8 the script used for both, which nothing measured says is
wrong.

gfx1201 Wave32, 1536 VGPRs/SIMD, measured over every kernel this tree builds
(3369 rows, ROCm 7.15 / clang 23, -O3) -- 755 rows change:

    6 -> 5   214 rows   (256 VGPRs)
    11 -> 10 119 rows
    14 -> 12 118 rows
    10 -> 9  112 rows
    13 -> 12  96 rows
    12 -> 10  96 rows

The parse moved into rows.awk so selftest.sh can check it at the boundaries
(96/97, 120/121, 144/145, 240/241) without a build tree. Five of those nine
boundary checks fail on the arithmetic this replaces.
This commit is contained in:
orca authored and StillDeadcode committed 2026-10-27 17:57:10 +01:00
1 parent 68468fc957
commit b56139a96a
2 files changed
+34 -19

No files matched your search

+3 -19
View File
@@ -7,12 +7,8 @@
# SPILL IS THE LOUD COLUMN, and SCRATCH after it: spilled registers are a memory round trip the
# source does not show, and scratch without spills is a private array the compiler could not keep
# in registers. WAVES is the other one: on gfx1201 a SIMD has 1536 VGPRs in wave32 allocated in
# groups of 8, so 256 VGPRs is 6 waves and 128 is 12 -- and LDS can cut it further, which this
# column does NOT model.
#
# The metadata is msgpack printed as YAML and its keys are ALPHABETICAL, so .vgpr_count comes after
# .symbol and .sgpr_count before it. Emitting a row at .symbol prints the previous kernel's VGPR
# count. The row is flushed at .wavefront_size, which is last.
# groups of 24, so 96 VGPRs is 16 waves, 97 is 12 and 256 is 5 -- and LDS can cut it further, which
# this column does NOT model. The parse is rows.awk, which selftest.sh checks at those boundaries.
: "${ROCM:=/opt/rocm}"
: "${BUILD:=build}"
: "${ISA_OUT:=/tmp/r4disa}"
@@ -24,16 +20,4 @@ for o in $(find "$BUILD" -name '*.hip.o'); do
"$ROCM/llvm/bin/llvm-readelf" --notes "$D/$n.co" 2>/dev/null > "$D/$n.md"
done
printf '%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n' vgpr sgpr lds scratch spill waves wg kernel
awk -v OFS='\t' '
/^ *\.group_segment_fixed_size:/ { lds = $2 }
/^ *\.private_segment_fixed_size:/ { sc = $2 }
/^ *\.sgpr_count:/ { s = $2 }
/^ *\.sgpr_spill_count:/ { ss = $2 }
/^ *\.vgpr_count:/ { v = $2 }
/^ *\.vgpr_spill_count:/ { vs = $2 }
/^ *\.max_flat_workgroup_size:/ { wg = $2 }
/^ *\.name:/ { nm = $2 }
/^ *\.wavefront_size:/ { if (nm != "") { g = int((v + 7) / 8) * 8; w = (g > 0) ? int(1536 / g) : 16
if (w > 16) w = 16
print v, s, lds, sc, vs + ss, w, wg, nm; nm = "" } }
' "$D"/*.md | sort -k5,5nr -k4,4nr -k1,1nr
awk -f "$here/rows.awk" "$D"/*.md | sort -k5,5nr -k4,4nr -k1,1nr
+31
View File
@@ -0,0 +1,31 @@
# One row per device kernel from llvm-readelf --notes of one code object.
#
# The metadata is msgpack printed as YAML and its keys are ALPHABETICAL, so .vgpr_count comes after
# .symbol and .sgpr_count before it. Emitting a row at .symbol prints the previous kernel's VGPR
# count. The row is flushed at .wavefront_size, which is last.
#
# WAVES is register-limited: on gfx1201 a SIMD has 1536 VGPRs, a wave32 allocates them in groups of
# 24 and a wave64 in groups of 8. So 96 VGPRs is 16 waves, 97 is 12, 128 is 10 and 241 is 5 -- the
# rounding is the whole point of the column, not a rounding error in it. LDS can cut it further and
# this does not model that. The 8 for wave64 is the quantum the script used for both before there
# was a wave-size column to tell them apart; nothing measured says it is wrong.
BEGIN { OFS = "\t" }
/^ *\.group_segment_fixed_size:/ { lds = $2 }
/^ *\.private_segment_fixed_size:/ { sc = $2 }
/^ *\.sgpr_count:/ { s = $2 }
/^ *\.sgpr_spill_count:/ { ss = $2 }
/^ *\.vgpr_count:/ { v = $2 }
/^ *\.vgpr_spill_count:/ { vs = $2 }
/^ *\.max_flat_workgroup_size:/ { wg = $2 }
/^ *\.name:/ { nm = $2 }
/^ *\.wavefront_size:/ {
wf = $2
if (nm != "") {
q = (wf == 64) ? 8 : 24
g = int((v + q - 1) / q) * q
w = (g > 0) ? int(1536 / g) : 16
if (w > 16) w = 16
print v, s, lds, sc, vs + ss, w, wg, nm
nm = ""
}
}