Integrated gfx11 under Linux: no GPU work right after the big load allocations

On a Radeon 780M (p2006) both load resets fell in the hyper-connection check, which ran
right after the 7.7 GiB expert cache was allocated, while the kernel was still moving
pages (KFD queue eviction, MES gave no answer, MODE2 reset). Three moves, token-neutral:

- the check (fused_gr_check) runs right after the card is named and before the warm
  thread and the expert arena; Verifier::init then finds it done. Its result depends on
  the card and STRATA_HC_SPLIT only (random weights compared bit for bit; nothing it
  reads is set between the two places), so it chooses the same variant as before;
- one more KFD settle (kfd_settle.hpp: eviction counter quiet for 2 s, at most 10 s)
  between the expert cache allocation and the profile fill;
- the first prompt's lazy device buffers are made in Prefill::init: the int8 experts'
  q8_1 activations for a whole chunk (chunk x 80 x 36 B, 24 MB at 8192), the group
  record, and the K/V copy stream when STRATA_KV_PREFETCH=1. Same buffers and sizes the
  prompt path makes; a failure there is ignored and the prompt path tries as before.

Cost by reading: one settle per start (at least 2 s, at most 10 s), about 24 MB of GPU
memory at an 8192 chunk; nothing per request.

Scope: compiled only with STRATA_USE_HIP on __linux__ (CUDA, Metal, SYCL and Windows HIP
builds have no new code), and at run time only when kfd_quiet::class_flag() is set, from
the same rule as the existing settle (igpu_kfd_settle_default: every visible card an
integrated gfx1103 / gfx1150 / gfx1151). Every other card runs the old order.
STRATA_KFD_QUIET=0 or STRATA_KFD_QUIET_LOAD=0 is the old order on the same binary;
STRATA_TRACE prints one line when it is active. Test: tests/core/kfd_quiet_test.cpp.
This commit is contained in:
Niko1221 committed 2026-11-15 01:53:45 +01:00
1 parent 4e5eef6e37
commit f9932c6aee
5 files changed
+189

No files matched your search

+4
View File
@@ -332,6 +332,10 @@ if(STRATA_BUILD_TESTS)
add_executable(kfd_settle_test tests/core/kfd_settle_test.cpp)
target_include_directories(kfd_settle_test PRIVATE include)
add_test(NAME kfd_settle_test COMMAND kfd_settle_test)
# keeping the KFD quiet on an integrated gfx11 GPU: the switches, the load order's rule (no GPU)
add_executable(kfd_quiet_test tests/core/kfd_quiet_test.cpp)
target_include_directories(kfd_quiet_test PRIVATE include)
add_test(NAME kfd_quiet_test COMMAND kfd_quiet_test)
# the file-cache give-back during and after the expert load on an integrated AMD GPU (a temporary file; no GPU)
add_executable(page_cache_drop_test tests/core/page_cache_drop_test.cpp)
target_include_directories(page_cache_drop_test PRIVATE include)
+79
View File
@@ -0,0 +1,79 @@
// Keeping the KFD quiet while our GPU queues are busy, on an integrated gfx11 GPU under Linux (gfx1103, gfx1150, gfx1151).
//
// Radeon 780M (gfx1103), Linux, p2006: the GPU resets when the kernel evicts the process's queues while a dispatch is in flight.
// The eviction comes from page moves inside memory the GPU reaches as a userptr (the registered expert arena; pageable copies the
// HIP runtime pins in place) and from process exit with the arena still registered. What the engine controls is WHEN it provokes
// the kernel (its own allocations, frees and its exit) and that its queues are idle then. Three changes, one switch each:
// LOAD the load order: the hyper-connection check before the expert arena exists, one more KFD settle between the expert cache
// and the profile fill, the first prompt's lazy device buffers made in Prefill::init;
// EXIT SIGTERM / SIGINT / SIGHUP: stop the request, release the GPU waits, drain the GPU for at most 3 s, unregister the arena
// only when drained, then end by the same signal as before;
// XFER GPU_PINNED_MIN_XFER_SIZE set before HIP starts (pageable copies go through the runtime's staging buffers instead of
// pinning our pages in place); a value the caller set wins.
// None changes a kernel or what is computed. STRATA_KFD_QUIET=0 turns all of them off at run time (A/B with the same binary);
// STRATA_KFD_QUIET_LOAD / _EXIT / _XFER = 0 turn one off. STRATA_TRACE prints one line per change that is active.
//
// Pure pieces, testable without a GPU (tests/core/kfd_quiet_test.cpp): the switch rule, the topology rule (the device class
// from the KFD topology files, readable before HIP starts), and the teardown order with the GPU layer passed in.
#pragma once
#include <atomic>
#include <cstdint>
#include <cstdlib>
#include <string>
#include <vector>
#if defined(__linux__)
#include <dirent.h>
#include <cstdio>
#endif
namespace strata::core::kfd_quiet {
enum class Fix { Load, Exit, Xfer };
/// The device class, set by the engine once the card is named (the rule of igpu_kfd_settle_default: integrated gfx1103 / gfx1150 /
/// gfx1151, Linux, every visible card). Load and Exit do nothing while it is false.
inline std::atomic<bool>& class_flag() {
static std::atomic<bool> f{false};
return f;
}
/// The switch rule: `all` is STRATA_KFD_QUIET, `one` the fix's own variable (nullptr = unset). A value starting with '0' turns off;
/// unset, empty or anything else leaves it on.
inline bool switch_on(const char* all, const char* one) {
auto off = [](const char* v) { return v != nullptr && v[0] == '0'; };
return !off(all) && !off(one);
}
inline const char* fix_env(Fix f) {
switch (f) {
case Fix::Load: return "STRATA_KFD_QUIET_LOAD";
case Fix::Exit: return "STRATA_KFD_QUIET_EXIT";
case Fix::Xfer: return "STRATA_KFD_QUIET_XFER";
}
return "STRATA_KFD_QUIET_LOAD";
}
inline bool env_on(Fix f) { return switch_on(std::getenv("STRATA_KFD_QUIET"), std::getenv(fix_env(f))); }
/// Load and Exit: the device class and the switches.
inline bool on(Fix f) { return class_flag().load(std::memory_order_relaxed) && env_on(f); }
/// 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.
struct LoadMoves {
bool hc_check_early = false;
bool settle_after_cache = false;
bool first_prompt_buffers = 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);
return m;
}
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)));
}
} // namespace strata::core::kfd_quiet
+21
View File
@@ -26,6 +26,7 @@
#include "strata/prefill/warm_policy.hpp"
#include "strata/prefill/share_rules.hpp"
#include "strata/core/arch_defaults.hpp"
#include "strata/core/kfd_quiet.hpp" // LOAD: the first prompt's buffers at init (integrated gfx11, Linux HIP)
#include <atomic>
#if defined(__cpp_lib_atomic_wait)
#define STRATA_ATOMIC_WAIT 1 // #1488: std::atomic::wait / notify_all are a GCC 11 library feature; GCC 10 spins instead
@@ -2529,6 +2530,26 @@ bool Prefill::init(const core::WeightTable& wt, const core::ModelGeometry& g, co
m.owned.push_back(m.ident_table);
}
if (!ok) { err = "prefill: host buffers or events for a chunk of " + std::to_string(chunk) + " tokens"; return false; }
#if defined(STRATA_USE_HIP) && defined(__linux__)
// integrated gfx11 (kfd_quiet.hpp, LOAD): the device buffers the first prompt made at its first layer (the int8 experts' q8_1
// activations for a whole chunk, their group record; the K/V copy stream with STRATA_KV_PREFETCH=1) are made here, during
// the load, so the first request allocates nothing while its kernels run. The same buffers and sizes the prompt path makes
// (it keeps them while a chunk fits: fr_xq_rows >= T); a failure here is not an error, the prompt path then tries as before.
if (strata::core::kfd_quiet::load_moves().first_prompt_buffers && T > 0) {
if (m.fr_xq == nullptr && cudaMalloc(&m.fr_xq, T * (size_t) (N / 32) * 36) == cudaSuccess) m.fr_xq_rows = (int64_t) T;
else if (m.fr_xq == nullptr) { m.fr_xq = nullptr; (void) cudaGetLastError(); }
if (m.i8_rec == nullptr && cudaMalloc((void**) &m.i8_rec, strata::prefill::i8grp::kRecBytes) != cudaSuccess) {
m.i8_rec = nullptr;
(void) cudaGetLastError();
}
if (const char* kp = std::getenv("STRATA_KV_PREFETCH"); kp != nullptr && std::atoi(kp) != 0) {
if ((!m.kv_copy && cudaStreamCreateWithFlags(&m.kv_copy, cudaStreamNonBlocking) != cudaSuccess) ||
(!m.kv_released && cudaEventCreateWithFlags(&m.kv_released, cudaEventDisableTiming) != cudaSuccess) ||
(!m.kv_ready && cudaEventCreateWithFlags(&m.kv_ready, cudaEventDisableTiming) != cudaSuccess))
(void) cudaGetLastError(); // the request makes what is missing, and says so if it cannot
}
}
#endif
pf_mark("init: host buffers, PLE rows, identity table", tr_last);
Alloc o;
o.base = (uint8_t*) borrow;
+24
View File
@@ -22,6 +22,10 @@
#include "strata/core/reader_room.hpp"
#include "strata/core/residency_trim.hpp"
#include "strata/core/kfd_settle.hpp"
#include "strata/core/kfd_quiet.hpp"
#if defined(STRATA_USE_HIP) && defined(__linux__)
#include "strata/kernels/fused_gr.hpp" // fused_gr_check, called early on an integrated gfx11 (kfd_quiet.hpp, LOAD)
#endif
#include "strata/core/page_cache_drop.hpp"
#include "strata/core/gfx12_chunk.hpp"
#include "strata/core/nv_chunk.hpp"
@@ -4017,6 +4021,14 @@ int main(int argc, char** argv) {
// and before READY it waits until its own KFD eviction counter has been quiet for 2 s (kfd_settle.hpp)
if (strata::core::igpu_kfd_settle_default(ad.gcnArchName, all_igpu, win_host))
strata::core::kfd_settle_flag().store(true);
#if defined(STRATA_USE_HIP) && defined(__linux__)
// and the KFD is not provoked while our queues are busy (kfd_quiet.hpp): the same device class, HIP under Linux only
if (strata::core::igpu_kfd_settle_default(ad.gcnArchName, all_igpu, win_host)) {
strata::core::kfd_quiet::class_flag().store(true);
if (std::getenv("STRATA_TRACE") != nullptr && strata::core::kfd_quiet::on(strata::core::kfd_quiet::Fix::Load))
std::fprintf(stderr, "strata trace: kfd quiet: load order active (check first, settle after the expert cache, first prompt's buffers at init)\n");
}
#endif
// and the file cache of the model files is given back while the expert arena is read and after it (page_cache_drop.hpp):
// the little free memory left beside the arena, the GPU's buffers and that cache is what makes the kernel's proactive compaction run
if (strata::core::igpu_cache_drop_default(ad.gcnArchName, all_igpu, win_host))
@@ -7829,6 +7841,12 @@ int main(int argc, char** argv) {
const char* name = named && p.name[0] ? p.name : "(an unnamed GPU)";
#if defined(STRATA_USE_HIP)
std::fprintf(stderr, "strata generate: GPU %d: %s (%s)\n", dev, name, named ? p.gcnArchName : "?");
#if defined(__linux__)
// integrated gfx11 (kfd_quiet.hpp, LOAD): the hyper-connection check now, before the expert arena exists and before the warm
// thread starts, instead of in Verifier::init after the 7.7 GiB expert cache was allocated (it then finds it done). Its
// result depends on the card and STRATA_HC_SPLIT only (random weights, compared bit for bit), so it is the same here.
if (named && strata::core::kfd_quiet::load_moves().hc_check_early) strata::kernels::fused_gr_check();
#endif
// the first prompt's one-time hipBLAS library loads (about 2.5 s), done on a thread while the expert arena loads
if (named) g_warm_thr = std::thread([dev] { strata::prefill::warm_gemm_libraries(dev); });
// (RDNA4's matrix-core prompt attention is the default since 148-amd: the engine says so once, at its first prompt;
@@ -8883,6 +8901,12 @@ int main(int argc, char** argv) {
std::fprintf(stderr, " PROFILE, ranked by routing frequency, no eviction.\n");
}
}
#if defined(STRATA_USE_HIP) && defined(__linux__)
// integrated gfx11 (kfd_quiet.hpp, LOAD): the expert cache's GPU memory was just allocated (7.7 GiB on a 780M) and the kernel moves
// pages after such a step; the profile fill, the graph capture and the first GPU work wait until the process's KFD eviction
// counter has been quiet for 2 s (at most 10 s; nothing where the counter cannot be read; STRATA_NO_KFD_SETTLE=1 also turns it off)
if (strata::core::kfd_quiet::load_moves().settle_after_cache) strata::core::kfd_settle::settle_before_ready();
#endif
// ---- R4.2e: fill the tier from the profile. This is the only place the plan is applied, and it runs
// ONCE: with `slots` pairs and `slots` slots the cache is full when this returns, so the decode-time
// admission finds no room and every non-profiled expert stays a CPU miss. That is what makes the profile
+61
View File
@@ -0,0 +1,61 @@
// keeping the KFD quiet on an integrated gfx11 GPU under Linux (include/strata/core/kfd_quiet.hpp). No GPU: the switch rule and the
// load order's rule. (The device rule itself is igpu_kfd_settle_default, checked in src/core/arch_defaults_test.cpp.)
#include "strata/core/kfd_quiet.hpp"
#include <cstdio>
#include <string>
#include <utility>
using namespace strata::core::kfd_quiet;
namespace {
int failed = 0;
#define CHECK(x) do { if (!(x)) { std::fprintf(stderr, "FAIL %s:%d: %s\n", __FILE__, __LINE__, #x); ++failed; } } while (0)
void switches() {
CHECK(switch_on(nullptr, nullptr));
CHECK(switch_on("1", nullptr));
CHECK(switch_on("", "")); // empty = unset
CHECK(!switch_on("0", nullptr)); // the kill switch turns everything off
CHECK(!switch_on("0", "1")); // ... also when the fix's own switch says 1
CHECK(!switch_on(nullptr, "0")); // one fix off
CHECK(!switch_on("1", "0"));
CHECK(switch_on("yes", "on"));
CHECK(std::string(fix_env(Fix::Load)) == "STRATA_KFD_QUIET_LOAD");
CHECK(std::string(fix_env(Fix::Exit)) == "STRATA_KFD_QUIET_EXIT");
CHECK(std::string(fix_env(Fix::Xfer)) == "STRATA_KFD_QUIET_XFER");
}
void load_order() {
// not the class: none of the three moves, whatever the switches say (every other card keeps the old 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);
}
// the class, nothing set: all three
{
const LoadMoves m = load_moves(true, nullptr, nullptr);
CHECK(m.hc_check_early && m.settle_after_cache && m.first_prompt_buffers);
}
// the class, STRATA_KFD_QUIET=0 or STRATA_KFD_QUIET_LOAD=0: the old order (the A/B arm of the same binary)
for (const auto& p : {std::pair<const char*, const char*>{"0", nullptr}, {nullptr, "0"}, {"0", "0"}, {"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);
}
// the flag as the engine sets it: off until the card is named
CHECK(!class_flag().load());
CHECK(!on(Fix::Load) && !on(Fix::Exit));
}
} // namespace
int main() {
switches();
load_order();
if (failed) {
std::fprintf(stderr, "kfd_quiet_test: %d check(s) failed\n", failed);
return 1;
}
std::printf("kfd_quiet_test: ok\n");
return 0;
}