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

+13 -8
View File
@@ -949,21 +949,24 @@ extern "C" int64_t rad_dev_resident_scratch_bytes(const RadDeviceProps* p) {
* serves several models, each with its own plugin's answer; a single answer for the process was
* the answer of whichever model started last. Owner 0 is a thread outside every engine (a tool, a
* test). Only where the backend chains: the AQL backend writes the record a chained form reads,
* while a HIP launch carries only the kernel's own arguments. */
* while a HIP launch carries only the kernel's own arguments. The answer is 2 where every chained
* form the engine can launch fences itself (RadKernelChainFn saying 2), which
* rad_dev_chain_unfenced reads. */
static std::mutex g_chain_mu;
static std::map<int, int> g_chain_pays; /* by owner */
static std::map<int, int> g_chain_pays; /* by owner: 0, 1, or 2 (their packets unacquired) */
static std::atomic<uint64_t> g_chain_gen{1};
void rad_dev_chain_infer(int pays) {
{
std::lock_guard<std::mutex> lk(g_chain_mu);
g_chain_pays[rad::engine_owner()] = pays ? 1 : 0;
g_chain_pays[rad::engine_owner()] = pays == 2 ? 2 : pays ? 1 : 0;
}
g_chain_gen.fetch_add(1, std::memory_order_release);
}
int rad_dev_chain_enabled(void) {
/* Asked on every launch: a thread keeps its engine's answer until some answer changes. */
/* The calling thread's engine's answer where the backend chains, else 0: asked on every launch,
* so a thread keeps it until some answer changes. */
static int chain_mode() {
thread_local uint64_t seen = 0;
thread_local int owner = -1, on = 0;
thread_local int owner = -1, mode = 0;
const uint64_t gen = g_chain_gen.load(std::memory_order_acquire);
const int o = rad::engine_owner();
if (seen != gen || owner != o) {
@@ -973,12 +976,14 @@ int rad_dev_chain_enabled(void) {
const auto it = g_chain_pays.find(o);
if (it != g_chain_pays.end()) pays = it->second;
}
on = pays && std::strcmp(rad::device_backend_name(), "aql") == 0 ? 1 : 0;
mode = pays && std::strcmp(rad::device_backend_name(), "aql") == 0 ? pays : 0;
seen = gen;
owner = o;
}
return on;
return mode;
}
int rad_dev_chain_enabled(void) { return chain_mode() != 0; }
int rad_dev_chain_unfenced(void) { return chain_mode() == 2; }
int rad_event_elapsed_ms(RadEvent a, RadEvent b, float* out) {
return dev()->event_elapsed_ms(a, b, out);