diff --git a/src/dsv41/ds4_experts_rule.hpp b/src/dsv41/ds4_experts_rule.hpp index 79e9c4b9..af2b774b 100644 --- a/src/dsv41/ds4_experts_rule.hpp +++ b/src/dsv41/ds4_experts_rule.hpp @@ -176,10 +176,12 @@ inline bool copy_hugetlb_default(int env, double pool_free_bytes, double copy_by return pool_free_bytes > 0.0 && pool_free_bytes >= copy_bytes; } -// DS4_FAST_ATTN (the chunked prompt's attention on the matrix cores): env -1 unset, else 0 / 1; 0.2.6: opt-in; 0.2.7: on for gfx1200 / gfx1201. -inline bool fast_attn_default(int env, bool gfx12, bool v026 = false) { +// DS4_FAST_ATTN (the chunked prompt's attention on the matrix cores): env -1 unset, else 0 / 1; 0.2.6: opt-in; 0.2.7: on for +// gfx1200 / gfx1201, and (this change) on for gfx1151 on Windows, where it measured +43.6% on a 32K prompt (101.6 -> 70.8 s, +// sparse attention 38.3 -> 7.0 s), the same greedy first token and a first-token KL far under the 0.0228 bar. +inline bool fast_attn_default(int env, bool gfx12, bool gfx1151win = false, bool v026 = false) { if (env >= 0) return env != 0; - return !v026 && gfx12; + return !v026 && (gfx12 || gfx1151win); } // The drafter's cumulative confidence cut (STRATA_DS4_DSPARK_CUM, a request's dspark_cum): the variable when set; 0.2.6: 0; 0.2.7: 0.5 on gfx1200 / gfx1201. diff --git a/src/dsv41/ds4_kernels.cu b/src/dsv41/ds4_kernels.cu index 13bda6e8..f598f52d 100644 --- a/src/dsv41/ds4_kernels.cu +++ b/src/dsv41/ds4_kernels.cu @@ -2038,7 +2038,9 @@ bool split_enabled() { // 0.006 gate, ids identical); gfx11 and gfx1151 (Strix Halo) are untested and keep the scalar kernels. DS4_FAST_ATTN=0 is the // off switch (exactly the 0.2.6 arithmetic), DS4_FAST_ATTN=1 turns it on elsewhere. Decided per device (the first call there). // The Marlin stream measured it ON on 4x R9700 (gfx1201), 2.25 bpw, 8K code prompts: 1180 -> 1354 ppts (+14.7%), the same ids, -// KL 0.10833 against 0.10925 for the scalar path. It stays gfx12-only until Strix Halo (gfx1151) is tested. +// KL 0.10833 against 0.10925 for the scalar path. gfx1151 on Windows was the untested part; measured on Strix Halo 2026-10-28 +// (32K prompt, 2.00 bpw): 101.6 -> 70.8 s (+43.6%), the sparse-attention stage 38.3 -> 7.0 s, the same greedy first token +// (27408,), so it joins the default there and stays opt-in on every other gfx11 part. #if defined(STRATA_USE_HIP) bool device_is_gfx12() { static std::atomic cache[64]; // 0 unknown, 1 no, 2 yes @@ -2055,6 +2057,22 @@ bool device_is_gfx12() { } return c == 2; } +#if defined(_WIN32) +bool device_is_gfx1151win() { + static std::atomic cache[64]; // 0 unknown, 1 no, 2 yes + int dev = 0; + cudaGetDevice(&dev); + if (dev < 0 || dev >= 64) return false; + int c = cache[dev].load(); + if (c == 0) { + cudaDeviceProp prop{}; + const bool yes = cudaGetDeviceProperties(&prop, dev) == cudaSuccess && std::strncmp(prop.gcnArchName, "gfx1151", 7) == 0; + c = yes ? 2 : 1; + cache[dev].store(c); + } + return c == 2; +} +#endif #endif bool fast_attn_enabled() { static const int env = [] { @@ -2062,9 +2080,13 @@ bool fast_attn_enabled() { return e == nullptr ? -1 : (std::atoi(e) != 0 ? 1 : 0); }(); #if defined(STRATA_USE_HIP) - return strata::ds4::fast_attn_default(env, device_is_gfx12(), strata::ds4::defaults_026()); +#if defined(_WIN32) + return strata::ds4::fast_attn_default(env, device_is_gfx12(), device_is_gfx1151win(), strata::ds4::defaults_026()); #else - return strata::ds4::fast_attn_default(env, false, strata::ds4::defaults_026()); + return strata::ds4::fast_attn_default(env, device_is_gfx12(), false, strata::ds4::defaults_026()); +#endif +#else + return strata::ds4::fast_attn_default(env, false, false, strata::ds4::defaults_026()); #endif } attnsplit::AttnSplitScratch split_scratch(cudaStream_t s, int heads) { diff --git a/tests/dsv41/experts_rule_test.cpp b/tests/dsv41/experts_rule_test.cpp index 895df7f0..3e2c17fb 100644 --- a/tests/dsv41/experts_rule_test.cpp +++ b/tests/dsv41/experts_rule_test.cpp @@ -270,12 +270,14 @@ int main() { CHECK_EQ(copy_hugetlb_default(-1, 90 * GB, 100 * GB, false), 0); CHECK_EQ(copy_hugetlb_default(1, 0.0, 100 * GB, true), 1); CHECK_EQ(copy_hugetlb_default(0, 120 * GB, 100 * GB, false), 0); // the old DS4_COPY_HUGETLB=0 - // the matrix-core attention: opt-in again - CHECK_EQ(fast_attn_default(-1, true, true), 0); - CHECK_EQ(fast_attn_default(-1, true, false), 1); - CHECK_EQ(fast_attn_default(-1, false, false), 0); - CHECK_EQ(fast_attn_default(1, false, true), 1); - CHECK_EQ(fast_attn_default(0, true, false), 0); // the old DS4_FAST_ATTN=0 + // the matrix-core attention: opt-in again, except on gfx12 and (since 2026-10-28) on gfx1151 on Windows + CHECK_EQ(fast_attn_default(-1, true, false, true), 0); + CHECK_EQ(fast_attn_default(-1, true, false, false), 1); + CHECK_EQ(fast_attn_default(-1, false, false, false), 0); + CHECK_EQ(fast_attn_default(-1, false, true, false), 1); // gfx1151 on Windows + CHECK_EQ(fast_attn_default(-1, false, true, true), 0); // ... but never for 0.2.6's arithmetic + CHECK_EQ(fast_attn_default(1, false, false, true), 1); + CHECK_EQ(fast_attn_default(0, true, true, false), 0); // the old DS4_FAST_ATTN=0 // the drafter's cumulative cut: 0 again; STRATA_DS4_DSPARK_CUM wins CHECK_EQ((int) (dspark_cum_value(false, 0.0f, true, true) * 100), 0); CHECK_EQ((int) (dspark_cum_value(false, 0.0f, true, false) * 100), 50);