M2XFP4 (MXFP4v2): quantiser, gfx1201 WMMA kernels, host rows, df2 wiring, .rad packer (Import::ParoM2), stability fixes (counters-in-scratch x3, aql publish fences), kbench rows, runbook (REMAINING.md)

This commit is contained in:
hugypufy committed 2026-10-23 12:25:59 +01:00
1 parent 9eaf10da6e
commit ea0908596b
60 files changed
+4619 -193

No files matched your search

+32 -3
View File
@@ -598,6 +598,8 @@ struct Stream {
bool agent_only = false; /* rad_xp_stream_create: never a system-scope acquire */
std::atomic<int> gates{0}; /* closed gates (rad_stream_gate) on this queue */
std::atomic<int> fault{0};
int unordered_run = 0; /* played packets in a row without the barrier bit */
bool unordered_warned = false;
char* bounce = nullptr; /* pinned, for pageable copies */
std::mutex bounce_mu;
/* Chained launches (RadKernelChainFn): the completion counter every block of a chained kernel
@@ -933,12 +935,18 @@ inline int reserve(Stream* s, uint64_t* out) {
inline void publish(Stream* s, uint64_t idx, uint16_t header, uint16_t setup) {
s->wr = idx + 1;
hsa_queue_store_write_index_relaxed(s->q, idx + 1);
_mm_sfence(); /* the argument slot, written before the header */
s->unordered_run = 0; /* an offered packet: every reclamation proof holds */
_mm_sfence(); /* the packet body and the argument slot are write-combined
VRAM: globally visible before the index below exposes
the packet to the GPU (a torn kernarg read faults on the
device with a stripped high pointer bit) */
__atomic_store_n(reinterpret_cast<uint32_t*>(
static_cast<hsa_kernel_dispatch_packet_t*>(s->q->base_address) +
(idx & s->mask)),
(uint32_t)header | ((uint32_t)setup << 16), __ATOMIC_RELEASE);
/* The index is what exposes the packet to the GPU: only after the fence and the
* header, or the packet processor can read a half-written argument block. */
hsa_queue_store_write_index_relaxed(s->q, idx + 1);
hsa_signal_store_relaxed(s->q->doorbell_signal, (hsa_signal_value_t)idx);
}
@@ -1163,6 +1171,17 @@ struct PlayRun {
uint64_t next = 0; /* the write index after the last packet written */
int unrung = 0;
bool foreign = true; /* the next packet's queue has packets this thread did not play */
uint32_t seen[4] = {UINT32_MAX, UINT32_MAX, UINT32_MAX, UINT32_MAX};
int n_seen = 0;
/* True for the first dispatch this play writes on each queue, whatever its record says.
* reserve()'s argument-slot proof needs an ordered packet after any the reuse may race:
* a slot is reused once the read index passes the packet that held it, and only an
* ordered packet after that one makes the index mean "it completed". */
bool first_on(const Stream* q) {
for (int i = 0; i < n_seen; ++i) if (seen[i] == q->id) return false;
if (n_seen < 4) seen[n_seen++] = q->id;
return true;
}
void ring() {
if (!unrung) return;
@@ -1235,12 +1254,22 @@ struct PlayRun {
/* A dispatch carrying a record keeps the bit: its completion must cover everything before
* it on the queue, which an unordered dispatch's does not. A chained kernel behind another chained one
* on this queue waits in its prologue instead. */
bool ordered = foreign || !r.overlap || done.handle;
bool ordered = first_on(s) || foreign || !r.overlap || done.handle;
/* Not while a plain packet may still run: a played plain kernel the overlap analysis let
* start early (it touched nothing in flight) adds nothing to the counter, so a chained
* kernel that reads its output and sits behind a chained one (a cache read beside a
* collective, say) would wait for the chained blocks only. */
if (chain && s->prev_chained && !s->plain_inflight && !foreign && !done.handle) ordered = false;
/* The bound the slot proof rests on. Say so once if it is ever crossed, rather than tear
* an argument block silently. */
if (ordered) {
s->unordered_run = 0;
} else if (++s->unordered_run > kTapeOverlapRun && !s->unordered_warned) {
s->unordered_warned = true;
RAD_WARN("queue %u: %d played packets in a row carry no barrier bit, past the %d the "
"argument-slot proof tolerates; a kernarg block may be reused while a kernel "
"still reads it", s->id, s->unordered_run, kTapeOverlapRun);
}
const uint16_t h = header(HSA_PACKET_TYPE_KERNEL_DISPATCH, acq, rel, ordered);
__atomic_store_n(reinterpret_cast<uint32_t*>(p), (uint32_t)h | ((uint32_t)r.pkt.setup << 16),
__ATOMIC_RELEASE);