fix(isa): fail closed, and count a back-edge, not any exec branch

Both instruments could report a clean tree after inspecting nothing.
res.sh and waterfall.sh skipped an object whose code object would not extract
(`|| continue`), skipped a disassembly that failed, and then printed a header
and a short table and exited 0. waterfall.sh additionally counted every
s_cbranch_exec* after a movrel -- a forward branch is not the loop that re-runs
the movrel -- and carried that flag across kernels, because flush() reset n and
loops but not seen.

Now: no .hip.o under BUILD, a code object that will not extract, a
llvm-readelf/llvm-objdump that fails, or not one kernel inspected all exit 1. A
HIP translation unit with no kernels carries no .hip_fatbin and is skipped, not
failed -- one exists in this tree (r4d_ar_entry), which is why "every object must
extract" was not an option. The parse is waterfall.awk, and a branch counts only
when its target label was already defined above it, i.e. is a back-edge.

Measured over every kernel this tree builds (761 movrels): 199 loops become 101,
19 rows change, and 12 of them are r4d_ar_twoshot_Nrank_exact reporting 7 where
it has no back-edge at all:

    r4d_ar_twoshot_Nrank_exact  7 -> 0   (x12)
    r4d_hc_bf16                 6 -> 1
    xprefetch                   4 -> 3
    r4d_ple_gate_bf16           3 -> 0
    r4d_ngram_ids               2 -> 1
    spechub                     9 -> 8, 2 -> 0
    r4d_encoder_bf16            1 -> 0
This commit is contained in:
orca authored and StillDeadcode committed 2026-10-27 18:23:49 +01:00
1 parent 74e701ea17
commit f406c4dafc
3 files changed
+79 -19

No files matched your search

+26 -13
View File
@@ -22,25 +22,38 @@
# back-edge around it, which the second column reports. And a waterfall in a cold kernel is worth
# nothing: most of what this finds is far below the noise of a step. Check the kernel against a
# trace before touching it.
#
# It fails rather than printing a short table: no .hip.o under BUILD, a code object that will not
# extract, a disassembly that fails, or not one kernel seen all exit 1. An instrument that reports
# "no waterfalls" because it looked at nothing reads like a clean tree.
: "${ROCM:=/opt/rocm}"
: "${BUILD:=build}"
: "${ISA_OUT:=/tmp/r4disa}"
here=$(cd "$(dirname "$0")" && pwd)
mkdir -p "$ISA_OUT"
objs=$(find "$BUILD" -name '*.hip.o' 2>/dev/null | sort)
[ -n "$objs" ] || {
echo "waterfall.sh: no .hip.o under $BUILD" >&2
echo "waterfall.sh: BUILD wants a configured build tree with device kernels (RAD_WITH_HIP=ON)" >&2
exit 1
}
printf "%-22s %6s %6s %s\n" "translation unit" "movrel" "loops" "kernel"
for o in $(find "$BUILD" -name '*.hip.o' | sort); do
kernels=0
for o in $objs; do
tu=$(basename "$o" .hip.o)
"$here/co.sh" "$o" >/dev/null 2>&1 || continue
# A HIP translation unit with no kernels carries no .hip_fatbin; that is not a broken object.
"$ROCM/llvm/bin/llvm-readelf" -S "$o" 2>/dev/null | grep -q '\.hip_fatbin' || continue
"$here/co.sh" "$o" >/dev/null || {
echo "waterfall.sh: no gfx1201 code object in $o" >&2; exit 1; }
"$ROCM/llvm/bin/llvm-objdump" -d --symbolize-operands --no-show-raw-insn \
"$ISA_OUT/$tu.co" 2>/dev/null > "$ISA_OUT/$tu.scan.s" || continue
awk -v tu="$tu" '
function flush( ) {
if (n > 0) printf "%-22s %6d %6d %s\n", tu, n, loops, k
n = 0; loops = 0
}
/^[0-9a-f]+ <.*>:$/ { if ($2 !~ /^<L[0-9]+>:$/) { flush(); k = $2 } }
/movrel/ { n++; seen = 1 }
/s_cbranch_exec(nz|z)/ { if (seen) { loops++; seen = 0 } }
END { flush() }
' "$ISA_OUT/$tu.scan.s"
"$ISA_OUT/$tu.co" > "$ISA_OUT/$tu.scan.s" 2>/dev/null || {
echo "waterfall.sh: llvm-objdump failed on $ISA_OUT/$tu.co" >&2; exit 1; }
awk -f "$here/waterfall.awk" -v tu="$tu" "$ISA_OUT/$tu.scan.s" || exit 1
# Empty output is a real answer here -- no kernel has a movrel -- so the check is that kernels
# were disassembled at all.
kernels=$((kernels + $(grep -cE '^[0-9a-f]+ <[^L]' "$ISA_OUT/$tu.scan.s" || true)))
done
[ "$kernels" -gt 0 ] || {
echo "waterfall.sh: no kernel disassembled (every object was host-only, or ISA_ARCH is absent)" >&2
exit 1
}