Files
Strata/include/strata/program/adaptive_range.hpp
T
40849df0a8 Transfer completion: flag B stays behind queued copies, and the adaptive-copy range covers the whole round (P1.1)
Correctness (class E): kept even without a speedup.

Flag B (PR #5096): the graph waits for "flag B >= layer + 1" and flag B is one counter that only rises. A non-empty
plan raises it from a host function on the copy stream, after its uploads. An empty plan (n <= 0) raised it on the
spot, even when the copy stream still held an earlier layer's, or the other token group's, uploads: the counter
jumped past a layer whose bytes had not landed. Verifier::raise_flag_b_ordered() now raises it through the copy
stream whenever copies were queued in this window, and directly only when none were. The same ordering is used at
the four places that publish an empty plan when the pool did not (run, run_slot_rows, batch_serve, service), which
had the same hazard. A failed host-function launch used to be ignored (flag B never rose and the window hung); it
now stops the engine like a failed upload does, after releasing the GPU waits.

Adaptive-copy bookkeeping (PR #4844): a round planned on the pipelined loop whose loop drained before step 3 is
marked resident on the serial rule, which used the lo/hi/bi of an earlier round, so only that range of swaps was
marked and the others were lost (the slot held the new expert, the table still named the old one). The pipelined plan
now names the whole round. The range arithmetic moved into AdaptiveCopyRange (adaptive_range.hpp) so a host test can
walk the rounds.

Tests: tests/core/flag_order_test.cu (delayed host-function copy standing in for a slow DMA, a consumer kernel that
reads staging once flag B allows it, a negative control that shows the old direct raise releases it early, flag only
rises, nothing queued, graph replay twice, every device; passes on both A4000s of z440), tests/program/
adaptive_range_test.cpp (serial batches for 0, 1, many swaps and several caps, the stale-range loss, empty round).

Co-authored-by: AlanJager <8843214+AlanJager@users.noreply.github.com>
Co-authored-by: uvlad23 <19749374+uvlad23@users.noreply.github.com>
2026-11-05 23:39:06 +01:00

48 lines
2.3 KiB
C++

// include/strata/program/adaptive_range.hpp - which swaps of an adaptive-tier round have had their copy in (PR #4844, @uvlad23).
//
// A round of the adaptive tier moves a list of swaps (aswaps) into the GPU expert caches. Step 2 copies them in, step 3
// marks the ones that landed as resident. On the serial loop the copies go in batches (the arena may cap one), and step 3
// marks the batch that just landed, [lo, hi). On the pipelined loop every swap is copied at its card's next gap and
// step 3 marks the whole list. Which loop runs is decided per tick: the pipelined loop can drain after step 2 has been
// planned, and the next tick then takes step 3 on the serial rule. lo/hi/bi then still named the last batch of an earlier
// round, so step 3 marked only that range and every other swap of the round was lost (its slot held the new expert, the
// table still said the old one). The pipelined plan therefore sets the range to the whole round. Plain arithmetic, so a
// host test can walk the rounds without a GPU.
#pragma once
#include <algorithm>
#include <cstddef>
namespace strata::program {
struct AdaptiveCopyRange {
size_t lo = 0, hi = 0; ///< the batch being copied in / just landed
size_t bi = 0; ///< where the next batch starts
void clear() { lo = hi = bi = 0; }
/// Serial loop, step 2: the next batch is [bi, bi + batch) of `total` swaps (all the rest when batch == 0, the arena's
/// cap otherwise). Never past `total`, and an overflowing sum is the end.
void next_batch(size_t total, size_t batch) {
lo = std::min(bi, total);
hi = total;
if (batch > 0 && batch < total - lo) hi = lo + batch;
bi = hi;
}
/// Pipelined loop, step 2: the whole round is one batch, whatever an earlier round left here.
void whole_round(size_t total) {
lo = 0;
hi = bi = total;
}
/// Step 3 on the serial rule: more batches of the round still to copy in.
bool more(size_t total) const { return bi < total; }
/// Step 3: the swaps that landed. `pipelined` is this tick's rule; the range is the whole round on that one.
size_t landed_begin(bool pipelined) const { return pipelined ? 0 : lo; }
size_t landed_end(bool pipelined, size_t total) const { return pipelined ? total : hi; }
};
} // namespace strata::program