aql: no packet-header acquire on chained launches whose kernels acquire for themselves

A chained kernel that has lost its barrier bit is launched ahead of the kernels
it depends on and reads nothing until its prologue wait has passed, where it
acquires itself (and, since the previous change, empties the scalar cache). The
acquire in its packet header runs when the packet processor launches the kernel,
before the launches in front have written, so it guards nothing the kernel
reads and only holds the packet processor: on an R9700, 2.1 us per launch with
the agent-scope acquire against 1.2 us without.

rad_kernel_chain may now answer 2 (libr4d's rows do): the chained forms' acquire
covers everything they read. The loader records it (KernelRow::chain_fenced);
the engine asks rad_dev_chain_infer(2) when chaining pays and every row that can
chain, from every loaded library, says 2 (one row answering 1 keeps the acquire
on all chained packets). The backend then issues a chained dispatch without its
barrier bit with no header acquire, live and in played passes, unless the ring,
the host epoch or a copy asks for one; releases, barrier packets, plain kernels
and the prefetch stream are untouched, and a card with its arguments in VRAM
and no HDP flush register keeps the acquire. RADIANCE_AQL_CHAIN_FENCE=1 puts it
back on every chained launch.

Qwen3.8-Flash-Next IQR-V4, TP2, MTP chain 3 with coupling, ABBA over 2 pairs:
+0.75% tok/s [0.73, 0.78], all 156 texts identical. The three device tests
added before now also run with the packets unacquired, and a shipped-plugins
test requires libr4d's chained rows to answer 2.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Code000andClaude Opus 5.5 committed 2026-11-17 19:21:59 +01:00
1 parent 304597970f
commit 01f08152dc
11 files changed
+214 -50

No files matched your search

+28 -16
View File
@@ -133,17 +133,25 @@ TEST(chained_launches_follow_the_plugins_ask_on_the_aql_backend_only) {
CHECK_EQ(rad_dev_chain_enabled(), 0);
rad_dev_chain_infer(1);
CHECK_EQ(rad_dev_chain_enabled(), aql ? 1 : 0);
/* Their packets go unfenced only where the engine says every chained form fences itself (2),
* and only where launches chain at all. */
CHECK_EQ(rad_dev_chain_unfenced(), 0);
rad_dev_chain_infer(2);
CHECK_EQ(rad_dev_chain_enabled(), aql ? 1 : 0);
CHECK_EQ(rad_dev_chain_unfenced(), aql ? 1 : 0);
rad_dev_chain_infer(0);
CHECK_EQ(rad_dev_chain_enabled(), 0);
CHECK_EQ(rad_dev_chain_unfenced(), 0);
}
/* A chained kernel reads behind its wait what the launch in front of it wrote, a value all its
* lanes share included. The compiler loads such a value through the scalar data cache, which no
* fence it emits empties: only the packet processor's acquire does, when the kernel is launched,
* before the launch in front has written. The wait must therefore empty that cache itself
* (chain_kernel.h): one reader in 1800 saw the value the reader before it loaded on an R9700
* before it did, with the packets' acquire on. Behind a gate, so the card has the readers launched
* ahead of the stores they wait for, as a played pass has them. */
* fence it emits empties: only the packet processor's acquire did, when the kernel was launched,
* before the launch in front had written. A chained launch whose packet goes unfenced
* (rad_dev_chain_infer(2)) must therefore empty that cache behind its wait (chain_kernel.h), or
* every reader here sees the value the reader before it loaded: 1797 launches in 1800 did on an
* R9700 before the wait emptied it. Behind a gate, so the card has the readers launched ahead of
* the stores they wait for, as a played pass has them. */
TEST(a_chained_kernel_sees_a_shared_value_the_launch_in_front_wrote) {
if (std::strcmp(rad::device_backend_name(), "aql") != 0) SKIP("launches chain on the AQL backend only");
const unsigned pairs = 400, blocks = 256;
@@ -152,8 +160,10 @@ TEST(a_chained_kernel_sees_a_shared_value_the_launch_in_front_wrote) {
DevBuf<unsigned> seen((int64_t)pairs * blocks * sizeof(unsigned), RAD_MEM_DEVICE);
REQUIRE(x && seen);
std::vector<unsigned> got((size_t)pairs * blocks);
{
rad_dev_chain_infer(1);
for (int fenced = 0; fenced < 2; ++fenced) {
/* 2: the packets go unfenced, as an engine whose libraries fence in the kernel issues
* them. 1: they keep the packet processor's fences, and the readers must see the same. */
rad_dev_chain_infer(fenced ? 1 : 2);
CHECK_OK(rad_memset_async(x, 0, 64 * sizeof(unsigned), st.s));
CHECK_OK(rad_memset_async(seen, 0, (int64_t)pairs * blocks * sizeof(unsigned), st.s));
CHECK_OK(rad_stream_sync(st.s));
@@ -176,7 +186,8 @@ TEST(a_chained_kernel_sees_a_shared_value_the_launch_in_front_wrote) {
/* A chained launch reads its own arguments and its chain record from a slot of the argument ring
* that the host wrote and that another launch read a lap of the ring ago; the L2 still holds what
* that launch read. Only a system-scope acquire of the packet processor's makes the card forget
* it: the one the ring asks for every half lap. Three laps of launches that each store where their own arguments say,
* it: the one the ring asks for every half lap, which a chained packet keeps while it goes
* without every other. Three laps of launches that each store where their own arguments say,
* with no host wait between them: without that acquire every launch past the first lap stores
* where the launch a lap before did (as they do on a prefetch stream, which never takes one and
* counts on the pass beside it to have turned the L2 over). */
@@ -187,8 +198,8 @@ TEST(a_chained_launch_reads_its_own_arguments_after_the_ring_has_lapped) {
DevBuf<unsigned> seen((int64_t)n * sizeof(unsigned), RAD_MEM_DEVICE);
REQUIRE(!!seen);
std::vector<unsigned> got(n);
{
rad_dev_chain_infer(1);
for (int fenced = 0; fenced < 2; ++fenced) {
rad_dev_chain_infer(fenced ? 1 : 2);
CHECK_OK(rad_memset_async(seen, 0, (int64_t)n * sizeof(unsigned), st.s));
CHECK_OK(rad_stream_sync(st.s));
CHECK_OK(rad::aql::chain_marks(st.s, seen, n));
@@ -209,9 +220,8 @@ TEST(a_chained_launch_reads_its_own_arguments_after_the_ring_has_lapped) {
* a lap of card-side copies with chaining off leaves every slot with their arguments and a record
* no kernel accepts; then the same copies chained and 50 us apart, the host quiet between them as
* the mover is between the copies of a loan recall, each saying whether it found a record. One
* that does not would count nothing and stall the queue; the probe counts for it. The packets
* keep the packet processor's acquire here, whose 0.9 us is all that gave the slot time to arrive
* before the flush in front of the doorbell. */
* that does not would count nothing and stall the queue; the probe counts for it. With the
* packets unacquired and with the packet processor's acquire on them. */
TEST(a_copy_issued_after_a_pause_finds_the_record_written_for_it) {
if (std::strcmp(rad::device_backend_name(), "aql") != 0) SKIP("the AQL backend's argument ring");
const unsigned lap = 4096 + 64, words = 8192;
@@ -222,14 +232,16 @@ TEST(a_copy_issued_after_a_pause_finds_the_record_written_for_it) {
DevBuf<uint8_t> src(bytes, RAD_MEM_DEVICE), dst(bytes, RAD_MEM_DEVICE);
REQUIRE(seen && src && dst);
std::vector<unsigned> got(words);
{
const unsigned n = 1500;
for (int fenced = 0; fenced < 2; ++fenced) {
/* Without the flush four runs in five of this many found unacquired launches that
* had read the old slot on an R9700, a few or tens of them at a time. */
const unsigned n = fenced ? 1500 : 6000;
Stream st;
rad_dev_chain_infer(0);
CHECK_OK(rad::aql::chain_asks(st.s, src, dst, (uint64_t)bytes, seen, lap));
CHECK_OK(rad_memset_async(seen, 0, (int64_t)words * sizeof(unsigned), st.s));
CHECK_OK(rad_stream_sync(st.s));
rad_dev_chain_infer(1);
rad_dev_chain_infer(fenced ? 1 : 2);
for (unsigned i = 0; i < n; ++i) {
/* In runs of eight with a host wait between them, as a recall ends in one. */
if (i % 8 == 0) CHECK_OK(rad_stream_sync(st.s));