libr4d: skip the scalar-cache invalidate behind chained waits in kernels that make no scalar load after the wait

r4d_chain_wait() ends in r4d_chain_acquire(): the agent-scope fence for the
vector caches and s_dcache_inv for the scalar data cache. The latter is needed
only by a kernel that reads, behind the wait, something an earlier launch of the
chain wrote through a scalar load (a value all lanes share). s_dcache_inv also
costs the refetch of every kernel argument afterwards, on every wave.

New r4d_chain_wait_vec() waits with the fence alone. It is used at 41 wait
sites in 20 units (the IQR m16/m64, w2a8/w4a8/w8a8/bf16/i8_kpar and fp8a8
GEMMs, the activation quantisers, the attention decode and paged-window
kernels, hc_*, the norm and activation kernels of r4d_model_bf16, rowtopk,
ple_gate, prefetch, dflash_conv, the all-reduce). A wait site keeps the full
flush when any instantiation of its kernel has a scalar load after the acquire.
-DR4D_CHAIN_SCINV_ALWAYS puts the instruction behind every wait again.

tests/chain_scalar_audit.py (ctest chain_scalar_audit, label slow, no card)
keeps this honest: it compiles every chained HIP unit to gfx1201 assembly with
the flags of compile_commands.json and fails when a chained kernel without
s_dcache_inv has a scalar load, from a base other than the kernarg segment
s[0:1], behind its global_inv. Building the audit with
-DR4D_CHAIN_SURVEY_NO_SCALAR (every wait skips the flush) flags 1123 kernels,
so the check does detect the real cases; as committed it reports 0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Code000andClaude Opus 5.5 committed 2026-11-17 20:43:11 +01:00
1 parent ca7a7212ec
commit e912b04f5a
23 files changed
+209 -45

No files matched your search

+14
View File
@@ -455,6 +455,20 @@ if(RAD_HIP_FOUND AND TARGET r4d_selftest)
ENVIRONMENT "RADIANCE_HOME=${CMAKE_BINARY_DIR}/radiance_home")
endif()
# ================================================================== the chained waits' scalar-cache flush
#
# A chained kernel whose wait is r4d_chain_wait_vec skips `s_dcache_inv` (libr4d/r4d_chain.h). This
# compiles every unit with a chained kernel to gfx1201 assembly with the build's own flags and fails
# on a kernel that skips it and has a scalar load, from anything but its argument segment, behind
# its acquire. No card needed; it recompiles the kernels (minutes), hence `slow`.
find_package(Python3 QUIET COMPONENTS Interpreter)
if(RAD_HIP_FOUND AND Python3_FOUND AND CMAKE_EXPORT_COMPILE_COMMANDS)
add_test(NAME chain_scalar_audit
COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/chain_scalar_audit.py
${CMAKE_BINARY_DIR} ${CMAKE_BINARY_DIR}/chain_scalar_audit --check)
set_tests_properties(chain_scalar_audit PROPERTIES LABELS "slow" TIMEOUT 1800)
endif()
# ================================================================== libhalo's interface parity
#
# libhalo serves gfx1151 behind libr4d's exact interface (libhalo/halo_parity.cpp): the same op