diff --git a/CMakeLists.txt b/CMakeLists.txt index 66c94575aa..af91af95d8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -395,6 +395,12 @@ if(STRATA_BUILD_TESTS) target_include_directories(fused_tile_rule_test PRIVATE include) add_test(NAME fused_tile_rule_test COMMAND fused_tile_rule_test) + # whether the staged walk (chunks below 1,024 tokens) takes the batched group entry: on by default in a CUDA build, opt-in in a HIP build, STRATA_PF_FUSED=1 / =0 both ways + # (header-only, no GPU) + add_executable(staged_group_rule_test tests/prefill/staged_group_rule_test.cpp) + target_include_directories(staged_group_rule_test PRIVATE include) + add_test(NAME staged_group_rule_test COMMAND staged_group_rule_test) + # whether the CUDA fused prompt kernels take the Gyro trellis experts by default (STRATA_PF_FUSED_TQ unset: the sm_86 cards with 80+ SMs; =1 any card; =0 off): the pure # rule, pinned for every card class (header-only, no GPU) add_executable(fused_tq_default_test tests/prefill/fused_tq_default_test.cpp) diff --git a/include/strata/prefill/staged_group_rule.hpp b/include/strata/prefill/staged_group_rule.hpp new file mode 100644 index 0000000000..f9ea726e32 --- /dev/null +++ b/include/strata/prefill/staged_group_rule.hpp @@ -0,0 +1,17 @@ +// include/strata/prefill/staged_group_rule.hpp - whether the staged walk (prompt chunks below stream_all_min(), 1,024 tokens) runs a layer's MMQ groups through +// the batched group entry (fused::group_bounds + experts_native, prefill.cpp fz_staged) in place of MMQ's per-row quantize / gather / gate-up / SwiGLU / down. +// +// Owner, 2026-11-12 ("8 yes for nvidia"): on NVIDIA the entry is the default wherever the card's own fused rule takes the expert formats (fused::native_supported: +// the 80-SM sm_120 / sm_86 rule, STRATA_PF_FUSED=1 on any sm_80+ card); on AMD (a HIP build) it is not yet: a HIP build keeps MMQ's staged walk unless STRATA_PF_FUSED=1 +// is named. STRATA_PF_FUSED=0 turns it off in both builds (native_supported answers false then as well). STRATA_PF_FUSED set to anything else non-empty reads as +// off, as moe_fused_iq.cu's native_supported reads it. Pure function: no GPU, no environment read here (the caller passes getenv's answer). +#pragma once + +namespace strata::prefill { + +inline bool staged_group_entry_default(bool hip_build, const char* pf_fused) { + if (pf_fused != nullptr && pf_fused[0] != '\0') return pf_fused[0] == '1'; + return !hip_build; +} + +} // namespace strata::prefill diff --git a/src/prefill/prefill.cpp b/src/prefill/prefill.cpp index 2244e74006..cd7afead2e 100644 --- a/src/prefill/prefill.cpp +++ b/src/prefill/prefill.cpp @@ -7,6 +7,7 @@ #include "strata/core/run_manifest.hpp" #include "strata/artifact/gguf_reader.hpp" #include "strata/prefill/pf_fused_override.hpp" +#include "strata/prefill/staged_group_rule.hpp" #if defined(STRATA_HAVE_DFLASH2) #include "strata/kernels/dflash2.hpp" #endif @@ -266,6 +267,19 @@ constexpr int STAGE = 8; // host->device expert staging ring (chunks b // the group that read it was gathered (the walk stages at most STAGE_GRP - MMQ_GROUP - 1 entries ahead) constexpr int STAGE_GRP = 32; constexpr int kSplitHelpRing = 48; // layer split help: the helper stage's ring slots it streams through (at most) +// The staged walk's batched group entry (fz_staged below): on by default in a CUDA build, opt-in (STRATA_PF_FUSED=1) in a HIP build (owner 2026-11-12, "8 yes for +// nvidia"; staged_group_rule.hpp). The card's own fused rule (fused::native_supported) still has to take the layer's formats. +inline bool staged_group_entry_on() { + static const bool on = [] { +#if defined(STRATA_USE_HIP) || defined(__HIPCC__) || defined(STRATA_HIP_GFX906) + constexpr bool hip = true; +#else + constexpr bool hip = false; +#endif + return strata::prefill::staged_group_entry_default(hip, std::getenv("STRATA_PF_FUSED")); + }(); + return on; +} // STRATA_PREFILL_GROUP_GATHER (unset or not 0): the staged walk's resident groups (read again here for P4-SMALL's fused groups, which // need that staging: the same variable, the same answer) inline bool staged_group_gather() { @@ -5346,7 +5360,7 @@ bool Prefill::run_impl(const int64_t* tokens, int64_t n, int64_t pos0, std::stri // STRATA_MMQ_DIRECT / _WS, the WMMA tiles, STRATA_PF_GROUP_SCRATCH, NVFP4 tails, Hadamard-folded or nibble layers. const bool fz_staged = !stream_all && use_mmq && lay.native && !fused_l && !wmma_l && !had_gu && !had_d && rows_cpu == 0 && on_peer.empty() && !m.pp && m.group_cap == 0 && !lay.fmt[(size_t) l].tail_off && ws::mode() == 0 && - !(m.cache && mmq_plan().direct[(size_t) l]) && staged_group_gather() && + !(m.cache && mmq_plan().direct[(size_t) l]) && staged_group_gather() && staged_group_entry_on() && MMQ_GROUP <= mmq::kGatherGroupMax && MMQ_GROUP <= fused::kMaxBatch && #if STRATA_EXPERT_NIBBLE_BUILT !nib_l.on && diff --git a/tests/prefill/staged_group_rule_test.cpp b/tests/prefill/staged_group_rule_test.cpp new file mode 100644 index 0000000000..15d7f81adc --- /dev/null +++ b/tests/prefill/staged_group_rule_test.cpp @@ -0,0 +1,34 @@ +// staged_group_entry_default (include/strata/prefill/staged_group_rule.hpp): whether the staged walk (prompt chunks below 1,024 tokens) takes the batched group entry. +// CUDA build: on with nothing set; HIP build: off with nothing set (owner 2026-11-12, "8 yes for nvidia"); STRATA_PF_FUSED=1 turns it on and STRATA_PF_FUSED=0 off in +// both builds; any other non-empty value reads as off (as native_supported reads it); empty reads as unset. No GPU, no model. +#include + +#include "strata/prefill/staged_group_rule.hpp" + +using strata::prefill::staged_group_entry_default; + +static int failed = 0; +#define CHECK(x) do { if (!(x)) { std::fprintf(stderr, "FAIL %s:%d: %s\n", __FILE__, __LINE__, #x); ++failed; } } while (0) + +int main() { + // nothing set + CHECK(staged_group_entry_default(false, nullptr) == true); // CUDA: default on + CHECK(staged_group_entry_default(true, nullptr) == false); // HIP: default off (yesterday's path) + CHECK(staged_group_entry_default(false, "") == true); // an empty variable is unset + CHECK(staged_group_entry_default(true, "") == false); + // the switch, both ways, both builds + CHECK(staged_group_entry_default(false, "1") == true); + CHECK(staged_group_entry_default(true, "1") == true); // HIP opt-in + CHECK(staged_group_entry_default(false, "0") == false); // CUDA opt-out + CHECK(staged_group_entry_default(true, "0") == false); + // any other non-empty value reads as off + CHECK(staged_group_entry_default(false, "2") == false); + CHECK(staged_group_entry_default(true, "yes") == false); + CHECK(staged_group_entry_default(false, "10") == true); // first character, as native_supported's v[0] == '1' + if (failed) { + std::fprintf(stderr, "staged_group_rule_test: %d check(s) failed\n", failed); + return 1; + } + std::printf("staged_group_rule_test passed\n"); + return 0; +}