diff --git a/include/strata/prefill/stream_floor_rule.hpp b/include/strata/prefill/stream_floor_rule.hpp index bb183133d1..c32393e57e 100644 --- a/include/strata/prefill/stream_floor_rule.hpp +++ b/include/strata/prefill/stream_floor_rule.hpp @@ -26,8 +26,12 @@ inline constexpr int64_t kFusedOnlyFloor = 64; // the streamed walk is faster /// `plain_pack_fused`: a build without llama.cpp's MMQ (prefill.cpp STRATA_PF_OWN_ONLY) loading a pack that is not a native one (the AVX-512 Q2_0 pack: no native_experts.txt) whose layers the plan marks /// fused (fused::enabled()). The staged entry and the int8 kernels read the native layout only, so below the floor such a layer would run each routed expert on the dequantize + FP16 path /// (Radeon 780M, Q2_0 pack: 367-token prompts 7,435 ms against 3,222 ms with MMQ); the floor is kFusedOnlyFloor there, on every card class. A build with MMQ passes false. -constexpr int64_t stream_floor_default(bool class_measured, bool all_layers_fused_only, bool staged_entry, bool plain_pack_fused = false) { - return (class_measured && all_layers_fused_only && !staged_entry) || plain_pack_fused ? kFusedOnlyFloor : kStreamFloorDefault; +/// +/// `trellis_gfx12_fused`: a build without MMQ on a gfx12 card (Radeon AI PRO R9700 / RX 9070) loading a native pack whose every layer is a trellis pair (Gyro-S TQK6 / TQK7) on the fused kernels. The staged +/// fused entry reads such layers about twice as slowly as MMQ does below the floor, the streamed walk 1.5 to 1.7 times faster than MMQ from 128 tokens up (R9700, Gyro-S: 128 tokens 252 ms with MMQ, 542 ms on the staged +/// entry, 167 ms on the streamed walk; par/RESULTS-MMQ-TAIL.md), so the floor is kFusedOnlyFloor there whatever the staged entry says. A build with MMQ passes false. +constexpr int64_t stream_floor_default(bool class_measured, bool all_layers_fused_only, bool staged_entry, bool plain_pack_fused = false, bool trellis_gfx12_fused = false) { + return (class_measured && all_layers_fused_only && !staged_entry) || plain_pack_fused || trellis_gfx12_fused ? kFusedOnlyFloor : kStreamFloorDefault; } } // namespace strata::prefill diff --git a/src/prefill/prefill.cpp b/src/prefill/prefill.cpp index 8f75ba9ade..4e8bab5ddb 100644 --- a/src/prefill/prefill.cpp +++ b/src/prefill/prefill.cpp @@ -13,6 +13,7 @@ #include "strata/prefill/own_only_line.hpp" #include "strata/prefill/stream_floor_rule.hpp" #include "strata/kernels/gfx_arch.hpp" +#include "strata/quant/types.hpp" #include "strata/prefill/fewrows.hpp" #include "strata/prefill/gp100_prompt_default.hpp" #if defined(STRATA_HAVE_DFLASH2) @@ -419,6 +420,26 @@ inline bool plain_pack_all_fused() { return false; #endif } +// A build without MMQ (STRATA_PF_OWN_ONLY) on a gfx12 card (R9700, RX 9070 / 9060) loading a native pack whose every layer is a trellis pair (Gyro-S TQK6 / TQK7 and the other trellis types) that the fused kernels +// take (layers_all_fused_only(): no layer on MMQ or on the FP16 path). Below the floor the staged fused entry reads these layers about twice as slowly as MMQ did (R9700, Gyro-S, 128 to 1,000 tokens: 542 to 1,241 ms +// against 252 to 659 ms), the streamed walk is faster than MMQ at every size (167 to 415 ms). False in a build with MMQ, on every other card, and without a loaded layout. +inline bool trellis_gfx12_all_fused() { +#if defined(STRATA_PF_OWN_ONLY) && defined(STRATA_USE_HIP) + const auto& lay = strata::kernels::cpu::expert_layout(); + if (!lay.native || lay.fmt.empty()) return false; + for (const auto& f : lay.fmt) + if (f.gu_type < (int) strata::quant::Type::TQ2_T || f.gu_type > (int) strata::quant::Type::TQP7) return false; // not a trellis gate/up + int dev = 0; + cudaDeviceProp prop; + if (cudaGetDevice(&dev) != cudaSuccess || cudaGetDeviceProperties(&prop, dev) != cudaSuccess) { + (void) cudaGetLastError(); + return false; + } + return strata::kernels::gfx_arch_is_gfx12_wmma(prop.gcnArchName) && layers_all_fused_only(); +#else + return false; +#endif +} // The floor without STRATA_PREFILL_STREAM_MIN and the CPU share: stream_floor_rule.hpp's answer, decided once when the expert layout is known (a call before that gets the default and is not cached). inline int64_t default_stream_floor() { static std::atomic cached{-1}; @@ -428,7 +449,7 @@ inline int64_t default_stream_floor() { const bool plain = plain_pack_all_fused(); // a build without MMQ and a non-native pack on the fused kernels: no staged entry or int8 path exists for its layout (stream_floor_rule.hpp) if ((!lay.native || lay.fmt.empty()) && !plain) return strata::prefill::kStreamFloorDefault; const bool cls = !plain && stream_floor_class_measured(); - const int64_t v = strata::prefill::stream_floor_default(cls, cls && layers_all_fused_only(), staged_fo_on(), plain); + const int64_t v = strata::prefill::stream_floor_default(cls, cls && layers_all_fused_only(), staged_fo_on(), plain, trellis_gfx12_all_fused()); cached.store(v, std::memory_order_release); if (v != strata::prefill::kStreamFloorDefault) std::fprintf(stderr, "prefill: prompt pieces of %lld tokens or more read on the fused kernels, as long prompts do. STRATA_PREFILL_STREAM_MIN=1024 keeps the old rule.\n", (long long) v); diff --git a/tests/prefill/stream_floor_rule_test.cpp b/tests/prefill/stream_floor_rule_test.cpp index edf9ff5819..4cbfde1802 100644 --- a/tests/prefill/stream_floor_rule_test.cpp +++ b/tests/prefill/stream_floor_rule_test.cpp @@ -31,6 +31,13 @@ int main() { // a build with MMQ, or a pack that is not plain-and-fused, passes false: the rows above are unchanged CHECK(stream_floor_default(false, false, false, false) == kStreamFloorDefault); CHECK(stream_floor_default(true, true, true, false) == kStreamFloorDefault); + // a build without MMQ on a gfx12 card with a native pack of trellis pairs on the fused kernels (Gyro-S on the R9700): the floor is 64 whatever the staged entry and the class say + CHECK(stream_floor_default(false, false, true, false, true) == kFusedOnlyFloor); + CHECK(stream_floor_default(false, false, false, false, true) == kFusedOnlyFloor); + CHECK(stream_floor_default(true, true, true, false, true) == kFusedOnlyFloor); + // without the flag (a build with MMQ, another card, another format set) the rows above stand + CHECK(stream_floor_default(false, false, true, false, false) == kStreamFloorDefault); + CHECK(stream_floor_default(false, true, true, false, false) == kStreamFloorDefault); if (failed) { std::fprintf(stderr, "stream_floor_rule_test: %d check(s) failed\n", failed); return 1;