prefill: a build without MMQ reads chunks of 64 tokens or more on the fused kernels for a trellis pack on a CUDA card that runs them

Same rule as the gfx12 one (685186efc), for a CUDA card: in a build without MMQ, a native pack whose every layer is a trellis pair (Gyro-S TQK6 / TQK7) that the fused kernels take, the floor of the streamed walk is 64 tokens instead of 1,024. Below the floor such a layer runs every routed expert on the dequantize + FP16 path.

stream_floor_default gets a sixth argument (trellis_cuda_fused) and the constant kTrellisCudaFloor; prefill.cpp trellis_cuda_all_fused() is layers_all_fused_only() plus a trellis gate/up in every layer, in a build with STRATA_PF_OWN_ONLY and not HIP, so the floor is lowered exactly where fused::native_supported takes the layers on CUDA (the sm_86 class with 80 or more SMs by default, any sm_80+ card with STRATA_PF_FUSED_TQ=1). The gfx12 rule is unchanged. STRATA_PREFILL_STREAM_MIN=1024 restores the old rule. Unit rows in stream_floor_rule_test.cpp.

RTX A6000, Gyro-S, prompt ms with floor 1,024 / 64 at 128 / 256 / 512 / 1,000 tokens: 555 / 233, 731 / 277, 1,031 / 370, 1,331 / 520 (sweep over floors 64 to 1,024, two rounds, rounds within 2 %).
This commit is contained in:
Niko1221 committed 2026-11-13 18:04:41 +01:00
1 parent 970a92972e
commit 1d633aadf7
3 files changed
+39 -3

No files matched your search

+12 -2
View File
@@ -20,6 +20,8 @@ namespace strata::prefill {
inline constexpr int64_t kStreamFloorDefault = 1024;
inline constexpr int64_t kFusedOnlyFloor = 64; // the streamed walk is faster than the FP16 path at every size measured from 96 up (par/RESULTS-STRIX-SHORT.md); the server reads pieces of up to --short-read tokens through the verify windows and longer ones batched
inline constexpr int64_t kTrellisCudaFloor = 64; // sweep on an RTX A6000 (sm_86, Gyro-S, floors 64 / 128 / 256 / 512 / 1,024 at 128 to 1,000 tokens, two rounds, par/RESULTS-MMQ-TAIL.md): 64 is the fastest at every size (a prompt of N tokens streams from a floor of N - 1 down, so 128 / 256 / 512 token prompts need 64 / 128 / 256 or lower)
/// `class_measured`: the device class this default was measured on (Windows gfx1151). `all_layers_fused_only`: the layer set has no MMQ tile and the fused kernels take every layer.
/// `staged_entry`: the staged walk takes such layers on its fused group entry (staged_fo_rule.hpp), so the old FP16 path below the floor is gone and the floor needs no lowering.
///
@@ -30,8 +32,16 @@ inline constexpr int64_t kFusedOnlyFloor = 64; // the streamed walk is faster
/// `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;
///
/// `trellis_cuda_fused`: the same layer set (a native pack whose every layer is a trellis pair on the fused kernels) in a build without MMQ on a CUDA card on which those kernels run (prefill.cpp
/// trellis_cuda_all_fused(): layers_all_fused_only() is true only where fused::native_supported takes every layer, which for the trellis pair on CUDA means the sm_86 class with 80 or more SMs by
/// default, or any sm_80+ card with STRATA_PF_FUSED_TQ=1; every other CUDA card keeps the layers off the fused kernels and this flag is false). Below the floor such a layer runs each routed expert on
/// the dequantize + FP16 path (RTX A6000, Gyro-S: 128 / 512 / 1,000 tokens 550 / 1,026 / 1,322 ms against 204 / 456 / 674 ms with MMQ, par/RESULTS-MMQ-TAIL.md); the floor is kTrellisCudaFloor.
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,
bool trellis_cuda_fused = false) {
return (class_measured && all_layers_fused_only && !staged_entry) || plain_pack_fused || trellis_gfx12_fused ? kFusedOnlyFloor
: trellis_cuda_fused ? kTrellisCudaFloor
: kStreamFloorDefault;
}
} // namespace strata::prefill
+15 -1
View File
@@ -440,6 +440,20 @@ inline bool trellis_gfx12_all_fused() {
return false;
#endif
}
// The same layer set on a CUDA card (a build without MMQ, STRATA_PF_OWN_ONLY, not HIP): a native pack whose every layer is a trellis pair (Gyro-S TQK6 / TQK7) that the fused kernels take (layers_all_fused_only()).
// No card query here: on CUDA fused::native_supported takes the trellis pair only where the kernels are set up (the sm_86 class, compute capability 8.0 / 8.6 / 8.9, with 80 or more SMs by default; any
// sm_80+ card with STRATA_PF_FUSED_TQ=1; none with STRATA_PF_FUSED=0 or _TQ=0), so the floor is lowered exactly where those kernels run. False in a build with MMQ, on HIP, and without a loaded layout.
inline bool trellis_cuda_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
return 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<int64_t> cached{-1};
@@ -449,7 +463,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, trellis_gfx12_all_fused());
const int64_t v = strata::prefill::stream_floor_default(cls, cls && layers_all_fused_only(), staged_fo_on(), plain, trellis_gfx12_all_fused(), trellis_cuda_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);
+12
View File
@@ -6,6 +6,7 @@
using strata::prefill::kFusedOnlyFloor;
using strata::prefill::kStreamFloorDefault;
using strata::prefill::kTrellisCudaFloor;
using strata::prefill::stream_floor_default;
static int failed = 0;
@@ -35,6 +36,17 @@ int main() {
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);
// a build without MMQ on a CUDA card on which the fused trellis kernels run (Gyro-S on an RTX A6000, sm_86 with 84 SMs): the floor is kTrellisCudaFloor whatever the class and the staged entry say
CHECK(stream_floor_default(false, false, false, false, false, true) == kTrellisCudaFloor);
CHECK(stream_floor_default(false, false, true, false, false, true) == kTrellisCudaFloor);
CHECK(stream_floor_default(true, true, true, false, false, true) == kTrellisCudaFloor);
CHECK(kTrellisCudaFloor >= 1 && kTrellisCudaFloor <= kStreamFloorDefault);
// the gfx12 rows stay as gated: the CUDA flag adds nothing to them (the two flags are never both true in one build)
CHECK(stream_floor_default(false, false, false, false, true, false) == kFusedOnlyFloor);
CHECK(stream_floor_default(false, false, false, false, true, true) == kFusedOnlyFloor);
// no CUDA flag (a build with MMQ, a card whose trellis kernels are off, another format set): every row above stands
CHECK(stream_floor_default(false, false, true, false, false, false) == kStreamFloorDefault);
CHECK(stream_floor_default(true, false, false, false, false, false) == kStreamFloorDefault);
// 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);