Turn the per-card prompt switch rule on by default for NVIDIA sm_86 cards

The prompt path now picks, per card, the chunk size from which every expert
the card does not hold is streamed (the floor), and sets the CPU share's
limit to 1.6 times it. It is on with nothing set for one class of card: CUDA,
NVIDIA discrete on PCIe, a single GPU, the start-up link probe ran, compute
capability 8.6. Every other card keeps the fixed 1,024 floor and the fixed
share limit.

STRATA_SWITCH_POINT=0 turns it off; STRATA_SWITCH_POINT=1 asks for it on any
other CUDA card. An explicit STRATA_PREFILL_STREAM_MIN or
STRATA_PREFILL_CPU_SHARE_MAX still wins over the rule.

On an RTX A6000 (UD-Q4_K_XL) the floor is 3,584 and the limit 5,632 against
1,024 and 3,072. With the tail-sized loan in the same build the rule equals
the old default above its limit.

The start-up line no longer calls the rule an opt-in and is printed only when
the floor moved. The rule's unit test covers the class (and every compute
capability, multi-GPU, no probe, integrated and HIP outside it) and the
variable. The settings register entry becomes a rollback switch.
This commit is contained in:
Niko1221 committed 2026-11-13 10:35:14 +01:00
1 parent dbe76e32de
commit 216af487d7
8 files changed
+244 -150

No files matched your search

+1 -1
View File
@@ -424,7 +424,7 @@ if(STRATA_BUILD_TESTS)
target_include_directories(staged_fo_rule_test PRIVATE include)
add_test(NAME staged_fo_rule_test COMMAND staged_fo_rule_test)
# STRATA_SWITCH_POINT (research): the floor from the card's share of non-resident experts, a cost estimate of the staged and the streamed walk (header-only, no GPU)
# STRATA_SWITCH_POINT (on by default for NVIDIA sm_86, one GPU): the floor from the card's share of non-resident experts, a cost estimate of the staged and the streamed walk (header-only, no GPU)
add_executable(switch_point_rule_test tests/prefill/switch_point_rule_test.cpp)
target_include_directories(switch_point_rule_test PRIVATE include)
add_test(NAME switch_point_rule_test COMMAND switch_point_rule_test)
File diff suppressed because it is too large. Load diff
+2 -1
View File
@@ -289,7 +289,7 @@ Off unless you set them. The last column says where each one is described.
| `STRATA_WDDM_BUDGET` | number | AMD, Intel Arc | [AMD_HIP.md](AMD_HIP.md) |
| `STRATA_WS_FAST` | number | NVIDIA and AMD | [OLDER_GPUS.md](OLDER_GPUS.md) |
## Switches that go back to earlier behaviour (68)
## Switches that go back to earlier behaviour (69)
These behaviours are on by default. Setting the switch returns the earlier behaviour; the notes in the register say which
version made it the default.
@@ -356,6 +356,7 @@ version made it the default.
| `STRATA_SM60_TABLE` | number | NVIDIA and AMD | v0.1.43 | [OLDER_GPUS.md](OLDER_GPUS.md) |
| `STRATA_SPLIT_CHUNK16K` | number | NVIDIA and AMD | v0.1.44 | [MULTI_GPU.md](MULTI_GPU.md) |
| `STRATA_SPLIT_OWN` | on / off | NVIDIA and AMD, Intel Arc | v0.1.40.1 | [MULTI_GPU.md](MULTI_GPU.md) |
| `STRATA_SWITCH_POINT` | on / off | NVIDIA and AMD | - | - |
| `STRATA_SYCL_BF16_DET` | number | Intel Arc | v0.2.13 | - |
| `STRATA_TOPK_SAMPLE` | number | NVIDIA and AMD | v0.1.45 | [DETAILS.md](DETAILS.md) |
| `STRATA_TOPK_SPLIT` | number | NVIDIA and AMD | v0.1.45 | [DETAILS.md](DETAILS.md) |
+2 -2
View File
@@ -108,8 +108,8 @@ public:
/// (staged_fo_rule.hpp: Windows gfx1151, every layer without an MMQ tile and on the fused kernels, entry on), the measured crossing of the verify windows and that entry.
/// A `--short-read` given on the command line is not asked. Call once the expert layout is known.
static int64_t short_read_default(int64_t base);
/// STRATA_SWITCH_POINT=1 (research): the expert cache's live slots and layers x experts of the single card's own model, before the first lend; the floor above is then
/// chosen from the share of experts the card does not hold, scaled by the cache's mean blob (MB), the start-up link probe (GB/s) and the card's SM count (switch_point_rule.hpp; 0 = unknown: the default floor). Without the switch this changes nothing.
/// STRATA_SWITCH_POINT (on by default for the class in switch_point_rule.hpp, =0 off): the expert cache's live slots and layers x experts of the single card's own model, before the first lend; the floor above is then
/// chosen from the share of experts the card does not hold, scaled by the cache's mean blob (MB), the start-up link probe (GB/s) and the card's SM count (switch_point_rule.hpp; 0 = unknown: the default floor). With STRATA_SWITCH_POINT=0 this changes nothing.
static void set_card_expert_share(int64_t resident_slots, int64_t total_pairs, double blob_mb = 0.0, double link_gbps = 0.0);
/// --prefill-pipe (opt-in): the chunk a layer split's first stage reads an `n`-token prompt in, for `stages`
/// stages, chunks of at most `cap` (the buffers' size) and a stage-chunk cost of b + a C with b/a = `ratio` tokens
+28 -1
View File
@@ -1,6 +1,8 @@
// include/strata/prefill/switch_point_rule.hpp - the chunk size below which a prompt chunk takes the STAGED walk and from which it takes the STREAMED walk
// (src/prefill/prefill.cpp stream_all_min()), chosen by estimated cost from the card's share of non-resident experts instead of the fixed 1,024.
// Research switch STRATA_SWITCH_POINT=1, default off. Pure: no GPU, no environment read here.
// ON BY DEFAULT for one class of card (enabled() below): CUDA, NVIDIA discrete card on PCIe, one GPU, the start-up link probe ran, compute capability 8.6 (RTX A6000 and
// RTX A4000 measured). STRATA_SWITCH_POINT=0 is the way back; STRATA_SWITCH_POINT=1 asks for the rule on any other CUDA card (not measured there).
// Pure: no GPU, no environment read here.
//
// The two walks (prefill.cpp):
// streamed: every expert the card does not hold is copied through a ring in layer order, whatever the chunk routes; the copy runs through the attention
@@ -94,4 +96,29 @@ inline int64_t share_limit_for(int64_t floor) {
return std::min<int64_t>(2 * kFloorMax, ((int64_t) ((double) floor * kShareRatio) / kGrid) * kGrid);
}
// ---- the class the rule is on for by default ----
// The device facts the engine reads once the card's expert cache is built (src/prefill/prefill.cpp, Prefill::set_card_expert_share).
struct DeviceClass {
bool cuda = false; // a CUDA build (HIP builds: never)
bool discrete = false; // a discrete card, not an integrated / shared-memory GPU
bool single_gpu = false; // the engine runs on one card: no layer split, no second card
bool link_probed = false; // the start-up host-to-device probe ran and gave a rate (the PCIe cost the rule scales with)
int cc_major = 0, cc_minor = 0; // compute capability
};
/// Measured: RTX A6000 (Boston) and RTX A4000 (z440), both 8.6. Every other compute capability (6.0, 7.0, 7.5, 8.0, 8.9, 12.0, 12.1) is outside the class until it is measured.
inline constexpr int kClassCcMajor = 8, kClassCcMinor = 6;
inline bool in_default_class(const DeviceClass& d) {
return d.cuda && d.discrete && d.single_gpu && d.link_probed && d.cc_major == kClassCcMajor && d.cc_minor == kClassCcMinor;
}
/// STRATA_SWITCH_POINT as the engine reads it: -1 unset (or empty), 1 for exactly "1", 0 for any other value.
inline int env_state(const char* v) {
if (v == nullptr || v[0] == '\0') return -1;
return (v[0] == '1' && v[1] == '\0') ? 1 : 0;
}
/// Whether the rule runs: HIP never; STRATA_SWITCH_POINT=0 (or any value but 1) never; =1 on every CUDA card; unset: the class above.
inline bool enabled(const DeviceClass& d, int env) {
if (!d.cuda || env == 0) return false;
return env == 1 || in_default_class(d);
}
} // namespace strata::prefill::switch_point
+38 -11
View File
@@ -390,19 +390,38 @@ inline bool staged_fo_on() {
cached.store(v ? 1 : 0, std::memory_order_release);
return v;
}
// STRATA_SWITCH_POINT=1 (research, default off; CUDA builds only): the floor of a card that streams part of the experts comes from switch_point_rule.hpp's cost estimate.
// STRATA_SWITCH_POINT (CUDA builds only): the floor of a card that streams part of the experts comes from switch_point_rule.hpp's cost estimate. ON BY DEFAULT for the class
// in_default_class() names (NVIDIA discrete card on PCIe, one GPU, link probe ran, compute capability 8.6); STRATA_SWITCH_POINT=0 is the way back, =1 asks for it on any other CUDA card.
// The card's counts arrive from Prefill::set_card_expert_share (the cache's slots and layers x experts, known before the first lend); until then the default answers.
std::atomic<int64_t> g_sp_resident{-1}, g_sp_total{0};
double g_sp_blob_mb = 0.0, g_sp_link_gbps = 0.0; // the cache's mean blob (MB) and the start-up probe (GB/s), from Prefill::set_card_expert_share
int g_sp_sm = 0; // the card's multiprocessor count
int g_sp_cc_major = 0, g_sp_cc_minor = 0; // the card's compute capability
bool g_sp_integrated = true; // not known as discrete until the card answered
// STRATA_SWITCH_POINT as set: -1 unset, 1 for "1", 0 for any other value (the way back)
inline int switch_point_env() {
static const int e = [] {
const char* v = std::getenv("STRATA_SWITCH_POINT");
return v != nullptr && v[0] != '\0' ? strata::prefill::switch_point::env_state(v) : -1;
}();
return e;
}
// the card's counts have arrived (set_card_expert_share ran: a single card, no batch slots)
inline bool switch_point_known() { return g_sp_resident.load(std::memory_order_acquire) >= 0; }
inline bool switch_point_on() {
#if defined(STRATA_USE_HIP) || defined(__HIPCC__) || defined(STRATA_HIP_GFX906)
return false; // measured on CUDA only
#else
static const bool on = [] { const char* e = std::getenv("STRATA_SWITCH_POINT"); return e != nullptr && e[0] == '1' && e[1] == '\0'; }();
return on;
if (!switch_point_known()) return false;
strata::prefill::switch_point::DeviceClass d;
d.cuda = true;
d.discrete = !g_sp_integrated;
d.single_gpu = true; // set_card_expert_share is called from the single-card, no-batch paths only
d.link_probed = g_sp_link_gbps > 0.0;
d.cc_major = g_sp_cc_major; d.cc_minor = g_sp_cc_minor;
return strata::prefill::switch_point::enabled(d, switch_point_env());
#endif
}
std::atomic<int64_t> g_sp_resident{-1}, g_sp_total{0};
double g_sp_blob_mb = 0.0, g_sp_link_gbps = 0.0; // the cache's mean blob (MB) and the start-up probe (GB/s), from Prefill::set_card_expert_share
int g_sp_sm = 0; // the card's multiprocessor count
// the card as the rule scales it; a field not set gives card_known() == false and the default floor
inline strata::prefill::switch_point::Card sp_card() {
strata::prefill::switch_point::Card c;
@@ -418,14 +437,18 @@ inline int64_t default_stream_floor() {
if (!lay.native || lay.fmt.empty()) return strata::prefill::kStreamFloorDefault;
const bool cls = stream_floor_class_measured();
int64_t v = strata::prefill::stream_floor_default(cls, cls && layers_all_fused_only(), staged_fo_on());
#if !defined(STRATA_USE_HIP) && !defined(__HIPCC__) && !defined(STRATA_HIP_GFX906)
// the card's counts are not known yet (set_card_expert_share has not run) and the rule is not switched off: the default, not cached
if (v == strata::prefill::kStreamFloorDefault && switch_point_env() != 0 && !switch_point_known()) return v;
#endif
if (v == strata::prefill::kStreamFloorDefault && switch_point_on()) {
const int64_t res = g_sp_resident.load(std::memory_order_acquire), tot = g_sp_total.load(std::memory_order_acquire);
if (res < 0) return v; // the card's counts are not known yet: the default, not cached
const auto card = sp_card();
if (!strata::prefill::switch_point::card_known(card)) return v; // the link or the card is not known: the default, not cached
v = strata::prefill::switch_point::floor_for_card(res, tot, card);
std::fprintf(stderr, "prefill: STRATA_SWITCH_POINT=1: prompt chunks of %lld tokens or more stream every expert the card does not hold (%lld of %lld experts resident; %.2f MB experts, %.1f GB/s link, %d SMs); a shorter chunk stages only the routed ones\n",
(long long) v, (long long) res, (long long) tot, card.blob_mb, card.link_gbps, card.sm);
if (v != strata::prefill::kStreamFloorDefault)
std::fprintf(stderr, "prefill: prompt chunks of %lld tokens or more stream every expert the card does not hold (%lld of %lld experts resident; %.2f MB experts, %.1f GB/s link, %d SMs); a shorter chunk stages only the routed ones. STRATA_SWITCH_POINT=0 keeps the fixed 1,024.\n",
(long long) v, (long long) res, (long long) tot, card.blob_mb, card.link_gbps, card.sm);
cached.store(v, std::memory_order_release);
return v;
}
@@ -3050,7 +3073,11 @@ void Prefill::set_card_expert_share(int64_t resident_slots, int64_t total_pairs,
#if !defined(STRATA_USE_HIP) && !defined(STRATA_HIP_GFX906)
int dev = 0;
cudaDeviceProp prop;
g_sp_sm = (cudaGetDevice(&dev) == cudaSuccess && cudaGetDeviceProperties(&prop, dev) == cudaSuccess) ? prop.multiProcessorCount : 0;
const bool got = cudaGetDevice(&dev) == cudaSuccess && cudaGetDeviceProperties(&prop, dev) == cudaSuccess;
g_sp_sm = got ? prop.multiProcessorCount : 0;
g_sp_cc_major = got ? prop.major : 0;
g_sp_cc_minor = got ? prop.minor : 0;
g_sp_integrated = got ? prop.integrated != 0 : true;
#endif
g_sp_blob_mb = blob_mb;
g_sp_link_gbps = link_gbps;
@@ -3263,7 +3290,7 @@ void Prefill::arm_cpu_share(bool applies, bool by_default) {
if (applies && by_default && cpu_share_explicit() == -2.0 && !g_share_default) {
g_share_default = true;
if (switch_point_on() && g_sp_resident.load(std::memory_order_acquire) >= 0 && strata::prefill::switch_point::card_known(sp_card())) {
// STRATA_SWITCH_POINT=1 (research): the share's limit scales with the card's own floor (floor x kShareRatio), not the fixed 3,072
// STRATA_SWITCH_POINT (on by default for its class, 0 = off): the share's limit scales with the card's own floor (floor x kShareRatio), not the fixed 3,072
const int64_t lim = strata::prefill::switch_point::share_limit_for(strata::prefill::switch_point::floor_for_card(
g_sp_resident.load(std::memory_order_acquire), g_sp_total.load(std::memory_order_acquire), sp_card()));
if (lim > 0) g_share_limit_arch = lim;
+2 -2
View File
@@ -11146,7 +11146,7 @@ int main(int argc, char** argv) {
"nothing to take, so it is not armed by default (STRATA_PREFILL_CPU_SHARE=auto forces it)\n",
(long long) xcache.slots(), (long long) (g.n_layers * g.n_expert));
if (share_pool && stages.empty() && !multi_gpu && share_has_work && !share_default_ok()) share_has_work = false; // H11
if (stages.empty() && !multi_gpu && o.batch <= 0) // STRATA_SWITCH_POINT (research): one card, no batch slots; before any bytes_needed, like the share
if (stages.empty() && !multi_gpu && o.batch <= 0) // STRATA_SWITCH_POINT: one card, no batch slots; before any bytes_needed, like the share
strata::prefill::Prefill::set_card_expert_share((int64_t) xcache.slots(), (int64_t) (g.n_layers * g.n_expert), xcache.slots() > 0 ? (double) xcache.bytes() / (double) xcache.slots() / 1e6 : 0.0, o.pcie_probe_gbps);
strata::prefill::Prefill::arm_cpu_share(share_pool, share_pool && stages.empty() && !multi_gpu && share_has_work);
void* borrow = nullptr;
@@ -20829,7 +20829,7 @@ int main(int argc, char** argv) {
int64_t pos_start = 0;
int64_t spec_pos = strata::spec::kSpecNotStarted; // plan v0.3 P6: where the speculative loop starts (0 is a real position: a 1-token prompt on a native pack)
strata::prefill::Prefill prefill;
if (!multi_gpu && o.batch <= 0) // STRATA_SWITCH_POINT (research): before any bytes_needed, like the share
if (!multi_gpu && o.batch <= 0) // STRATA_SWITCH_POINT: before any bytes_needed, like the share
strata::prefill::Prefill::set_card_expert_share((int64_t) xcache.slots(), (int64_t) (g.n_layers * g.n_expert), xcache.slots() > 0 ? (double) xcache.bytes() / (double) xcache.slots() / 1e6 : 0.0, o.pcie_probe_gbps);
// #1595: not by default when the cache holds every expert (nothing to take)
strata::prefill::Prefill::arm_cpu_share(!multi_gpu && !o.no_pool,
+39
View File
@@ -92,6 +92,45 @@ int main() {
CHECK(sp::share_limit_for(2048) == 3072); // A4000: measured break-even about 2,900
CHECK(sp::share_limit_for(3840) % sp::kGrid == 0 && sp::share_limit_for(3840) > 3840);
// the class the rule is on for by default: CUDA, discrete, one GPU, link probe ran, compute capability 8.6; STRATA_SWITCH_POINT=0 is the way back, =1 asks for it elsewhere
{
sp::DeviceClass in;
in.cuda = true; in.discrete = true; in.single_gpu = true; in.link_probed = true; in.cc_major = 8; in.cc_minor = 6;
CHECK(sp::in_default_class(in));
CHECK(sp::enabled(in, -1)); // nothing set: on
CHECK(!sp::enabled(in, 0)); // STRATA_SWITCH_POINT=0 (or any value but 1): the way back
CHECK(sp::enabled(in, 1)); // STRATA_SWITCH_POINT=1: on
// every other compute capability is out of the class with nothing set
const int other[][2] = {{6, 0}, {6, 1}, {7, 0}, {7, 5}, {8, 0}, {8, 7}, {8, 9}, {9, 0}, {10, 0}, {12, 0}, {12, 1}, {0, 0}};
for (const auto& cc : other) {
sp::DeviceClass d = in;
d.cc_major = cc[0]; d.cc_minor = cc[1];
CHECK(!sp::in_default_class(d));
CHECK(!sp::enabled(d, -1));
CHECK(sp::enabled(d, 1)); // the explicit opt-in still works on another CUDA card
CHECK(!sp::enabled(d, 0));
}
// each other condition on its own takes a card out of the class
{ sp::DeviceClass d = in; d.single_gpu = false; CHECK(!sp::enabled(d, -1)); CHECK(!sp::enabled(d, 0)); } // two cards / a layer split
{ sp::DeviceClass d = in; d.link_probed = false; CHECK(!sp::enabled(d, -1)); } // no probe
{ sp::DeviceClass d = in; d.discrete = false; CHECK(!sp::enabled(d, -1)); } // integrated / shared memory
{ sp::DeviceClass d = in; d.cuda = false; CHECK(!sp::enabled(d, -1)); CHECK(!sp::enabled(d, 1)); CHECK(!sp::enabled(d, 0)); } // HIP: never, whatever the cc says
{ sp::DeviceClass d; CHECK(!sp::enabled(d, -1)); CHECK(!sp::enabled(d, 1)); } // nothing known
// the variable: unset or empty = default, exactly "1" = on, anything else = off
CHECK(sp::env_state(nullptr) == -1);
CHECK(sp::env_state("") == -1);
CHECK(sp::env_state("1") == 1);
CHECK(sp::env_state("0") == 0);
CHECK(sp::env_state("off") == 0);
CHECK(sp::env_state("11") == 0);
// the class gives the measured floors: the A6000 and the A4000 are both 8.6
CHECK(sp::kClassCcMajor == 8 && sp::kClassCcMinor == 6);
CHECK(sp::floor_for_card(13580, total, sp::Card{3.14, 12.2, 84}) == 3584);
CHECK(sp::share_limit_for(3584) == 5632);
CHECK(sp::floor_for_card(7836, total, sp::Card{1.44, 11.0, 48}) == 2048);
CHECK(sp::share_limit_for(2048) == 3072);
}
if (failed) {
std::fprintf(stderr, "switch_point_rule_test: %d check(s) failed\n", failed);
return 1;