Integrated gfx11 under Linux: two more first-request allocations made during the load

What the box showed (p2006, Radeon 780M gfx1103, 11-15): in every mode, registered or not, the first request still grew the GPU's
GTT by 10-15 MiB in 3-5 steps (for example +3 MiB at 87 ms and +10 MiB at 487 ms into the first 512-token request), while its
kernels ran.

Two of the candidates are now made before READY, inside the existing LOAD move (fix 1):
- one staged copy each way (2 MiB, pageable host memory, the null stream: the stream of the lent refill and the blocking cache
  fills) just before the last KFD settle, so the HIP runtime makes its staging buffer and copy path during the load and the settle
  waits for what that provokes. The 2 MiB device buffer is kept for the run;
- the CPU prompt share's pinned buffers (activations, rows, row scales) in Prefill::init at the sizes the first sharing layer asks
  for, for the largest chunk that shares. Only where the share is armed: it is off by default on this class (HIP keeps it off
  except on a single gfx12 card), so the default path allocates nothing here.
The DFlash2 tap staging needs no change: the serve path reserves it at load (sp.reserve_taps) before the settle.

Scope: HIP builds under Linux, the kfd_quiet class (every visible card an integrated gfx1103 / gfx1150 / gfx1151), through
kfd_quiet::load_moves() like the other load moves; nothing changes elsewhere. Token-neutral: no kernel and no computed value
changes; the copy writes only its own buffer.

Switch: STRATA_KFD_QUIET_LOAD=0 (or STRATA_KFD_QUIET=0) turns these off with the rest of the load moves. No new user setting and no
new user-visible line (one STRATA_TRACE line).
This commit is contained in:
Niko1221 committed 2026-11-15 03:14:32 +01:00
1 parent c3f6978b10
commit 6069c9d0c4
4 files changed
+57 -5

No files matched your search

+10 -1
View File
@@ -68,16 +68,25 @@ inline bool on(Fix f) { return class_flag().load(std::memory_order_relaxed) && e
/// LOAD, as one rule for the three call sites (generate.cpp: the check after the card is named, the settle after the expert cache;
/// prefill.cpp: the first prompt's buffers in Prefill::init). `cls`: class_flag(); `all` / `one`: the switches.
/// (and since 11-15: the CPU prompt share's pinned buffers at init where the share is armed; one staged copy each way on the null
/// stream before the last settle, so the runtime makes its staging buffer and copy path during the load, not in the first request)
struct LoadMoves {
bool hc_check_early = false;
bool settle_after_cache = false;
bool first_prompt_buffers = false;
bool cpu_share_buffers = false;
bool staged_copy_warm = false;
};
inline LoadMoves load_moves(bool cls, const char* all, const char* one) {
LoadMoves m;
m.hc_check_early = m.settle_after_cache = m.first_prompt_buffers = cls && switch_on(all, one);
m.hc_check_early = m.settle_after_cache = m.first_prompt_buffers = m.cpu_share_buffers = m.staged_copy_warm =
cls && switch_on(all, one);
return m;
}
/// The staged copy before READY: bytes per direction. More than the 1 MiB below which the runtime always stages a pageable copy,
/// so the copy takes the path the lent refill's 1.3 MiB blobs take with GPU_PINNED_MIN_XFER_SIZE set (XFER).
inline constexpr size_t kStagedWarmBytes = 2u << 20;
inline LoadMoves load_moves() {
return load_moves(class_flag().load(std::memory_order_relaxed), std::getenv("STRATA_KFD_QUIET"), std::getenv(fix_env(Fix::Load)));
}
+23
View File
@@ -2549,6 +2549,29 @@ bool Prefill::init(const core::WeightTable& wt, const core::ModelGeometry& g, co
(void) cudaGetLastError(); // the request makes what is missing, and says so if it cannot
}
}
// and (11-15) the CPU prompt share's pinned buffers, only where the share is armed (STRATA_PREFILL_CPU_SHARE: off by default on
// this class): the activations, the rows and their scales at the sizes the first CPU-sharing layer asks for, for the largest chunk
// that shares (below cpu_share_max(), the floor of the full stream on an integrated GPU). The prompt path keeps a buffer that is
// large enough and regrows one that is not, as before; a failure here leaves it to the prompt path.
if (strata::core::kfd_quiet::load_moves().cpu_share_buffers && T > 0 && cpu_pool_ != nullptr && cpu_share_on()) {
const size_t ts = std::min<size_t>(T, (size_t) std::max<int64_t>(cpu_share_max(), 1));
const size_t rows = (size_t) std::min<int64_t>((int64_t) ts * K, (int64_t) strata::kernels::cpu::MAXT * g.n_expert);
auto pin = [](float*& p, size_t& n, size_t want) {
if (p != nullptr) return;
if (cudaHostAlloc((void**) &p, want * sizeof(float), cudaHostAllocDefault) == cudaSuccess) {
n = want;
} else {
p = nullptr;
n = 0;
(void) cudaGetLastError();
}
};
pin(m.cpu_x, m.cpu_x_n, ts * N);
pin(m.cpu_rows, m.cpu_rows_n, rows * N);
const bool ones_new = m.cpu_ones == nullptr;
pin(m.cpu_ones, m.cpu_ones_n, rows);
if (ones_new && m.cpu_ones != nullptr) std::fill(m.cpu_ones, m.cpu_ones + rows, 1.0f);
}
#endif
pf_mark("init: host buffers, PLE rows, identity table", tr_last);
Alloc o;
+19
View File
@@ -15135,6 +15135,25 @@ int main(int argc, char** argv) {
}
strata::core::pin_sim_report("at READY");
strata::core::pin_reserve_release_hard(); // the load is over: nothing else needs the headroom
#if defined(STRATA_USE_HIP) && defined(__linux__)
// integrated gfx11 (kfd_quiet.hpp, LOAD): one staged copy each way on the null stream (the stream of the lent refill and of
// the cache's blocking fills), from and into pageable memory, so that the runtime makes its staging buffer and copy path now,
// before the settle below, and not inside the first request (p2006: +10-15 MiB of GTT in 3-5 steps there, every mode). The
// device buffer is kept for the run (a free later would be one more driver event); nothing reads it. Failures are ignored.
if (strata::core::kfd_quiet::load_moves().staged_copy_warm) {
static void* warm_dev = nullptr;
const size_t wn = strata::core::kfd_quiet::kStagedWarmBytes;
if (warm_dev == nullptr && cudaMalloc(&warm_dev, wn) != cudaSuccess) warm_dev = nullptr;
if (warm_dev != nullptr) {
std::vector<unsigned char> wh(wn, 0);
if (cudaMemcpy(warm_dev, wh.data(), wn, cudaMemcpyHostToDevice) == cudaSuccess)
(void) cudaMemcpy(wh.data(), warm_dev, wn, cudaMemcpyDeviceToHost);
}
(void) cudaGetLastError();
if (std::getenv("STRATA_TRACE") != nullptr)
std::fprintf(stderr, "strata trace: kfd quiet: staged copy before READY %s\n", warm_dev != nullptr ? "done" : "skipped (no device memory)");
}
#endif
strata::core::kfd_settle::settle_before_ready(); // integrated gfx11 under Linux: until the kernel has stopped moving the registered arena (nothing elsewhere)
strata::core::manifest::instance().write("ready"); // STRATA_MANIFEST (a no-op unless it is set)
// ---- window warm-up (lane DRAFT-COSTS): the first run of a window width builds its graph / pipeline (srv118 CUDA: a capture; Metal: the first execution), so a
+5 -4
View File
@@ -38,18 +38,19 @@ void load_order() {
for (const char* all : {(const char*) nullptr, "1", "0"})
for (const char* one : {(const char*) nullptr, "1", "0"}) {
const LoadMoves m = load_moves(false, all, one);
CHECK(!m.hc_check_early && !m.settle_after_cache && !m.first_prompt_buffers);
CHECK(!m.hc_check_early && !m.settle_after_cache && !m.first_prompt_buffers && !m.cpu_share_buffers && !m.staged_copy_warm);
}
// the class, nothing set: all three
// the class, nothing set: all of them
{
const LoadMoves m = load_moves(true, nullptr, nullptr);
CHECK(m.hc_check_early && m.settle_after_cache && m.first_prompt_buffers);
CHECK(m.hc_check_early && m.settle_after_cache && m.first_prompt_buffers && m.cpu_share_buffers && m.staged_copy_warm);
}
CHECK(kStagedWarmBytes > (1u << 20)); // above the runtime's own staging threshold
// the class, STRATA_KFD_QUIET=0 or STRATA_KFD_QUIET_LOAD=0: the old order (the A/B arm of the same binary)
using P = std::pair<const char*, const char*>;
for (const P& p : std::vector<P>{P{"0", nullptr}, P{nullptr, "0"}, P{"0", "0"}, P{"0", "1"}}) {
const LoadMoves m = load_moves(true, p.first, p.second);
CHECK(!m.hc_check_early && !m.settle_after_cache && !m.first_prompt_buffers);
CHECK(!m.hc_check_early && !m.settle_after_cache && !m.first_prompt_buffers && !m.cpu_share_buffers && !m.staged_copy_warm);
}
// the flag as the engine sets it: off until the card is named
CHECK(!class_flag().load());