From 6c9bbc81477faad15a8cf2329fb4e9d2706d79b4 Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Fri, 9 Oct 2026 03:14:18 +0200 Subject: [PATCH] sycl: spin bound for a B-series card found from the device (Windows/OpenCL has no sysfs driver): 20,000 reads, 2,000,000 when drafting without --mtp (#1473 #1397) --- sycl/include/strata/sycl_doorbell.hpp | 17 ++++++++++--- sycl/include/strata/sycl_queue.hpp | 36 +++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/sycl/include/strata/sycl_doorbell.hpp b/sycl/include/strata/sycl_doorbell.hpp index 36f71704..2f6e0861 100644 --- a/sycl/include/strata/sycl_doorbell.hpp +++ b/sycl/include/strata/sycl_doorbell.hpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -80,13 +81,20 @@ template inline void sys_store_mapped(T* p, T v) { // verifier's checks catch. ~2 M host-memory reads is a few seconds at PCIe latency. // The bound is per device, chosen at run time (spin_max below): 20,000 reads on a card under the xe driver (the B-series // on Linux), whose device-plan windows only spin in a failure and where a longer spin is what makes the driver reset the -// GT; 2,000,000 (a few seconds) elsewhere, Windows included (a JIT/OpenCL B-series build measured faster with the long -// bound, #1397). On an Arc A-series (i915) the CPU computes the experts the card does not hold and the GPU waits for it at +// GT; 2,000,000 (a few seconds) elsewhere. A B-series card with no sysfs driver (Windows / OpenCL) gets 20,000 too (#1473, +// measured +46-67% with --mtp), found from the device's architecture or name. On an Arc A-series (i915) the CPU computes the experts the card does not hold and the GPU waits for it at // every layer: 20,000 reads is a few tens of milliseconds, the first request after a start (cold pages, slow CPU // layers) is slower than that, the GPU gave up, went on with the experts' outputs missing, and the answer was token 0 // ("!!!!!") or the engine crashed in the CPU pool on the garbage routing it read next. // STRATA_SPIN_MAX= overrides both; a build's -DSTRATA_SYCL_SPIN_MAX= (CMake) fixes one bound for every // device. The device functions take the bound as an argument: the launchers pass spin_max(queue). +// Without a sysfs driver name (Windows, OpenCL) a B-series card is recognised from the device itself (intel_gpu_gen): +// its window waits are the xe kind (expected to expire, so 20,000 reads), EXCEPT in a run that drafts without the MTP +// layer (--spec N, no --mtp): the suffix drafter's own waits have to complete there, and 20,000 reads left it empty-handed +// (0 drafts, 21.8 vs 68.8 tok/s, #1473). generate calls spin_drafts_need_long_bound(true) for such a run, before any +// launch. A Linux xe card keeps 20,000 in every mode (unchanged). +inline std::atomic& spin_long_drafts_flag() { static std::atomic f{false}; return f; } +inline void spin_drafts_need_long_bound(bool on) { spin_long_drafts_flag() = on; } inline uint32_t spin_max(const sycl::queue& q) { static std::mutex mu; static std::unordered_map cache; @@ -99,7 +107,10 @@ inline uint32_t spin_max(const sycl::queue& q) { #ifdef STRATA_SYCL_SPIN_MAX else v = STRATA_SYCL_SPIN_MAX; #else - else v = intel_gpu_driver() == "xe" ? 20000u : 2000000u; + else if (intel_gpu_driver() == "xe") v = 20000u; + else if (intel_gpu_driver().empty() && intel_gpu_gen(d) == IntelGpuGen::Battlemage) + v = spin_long_drafts_flag().load() ? 2000000u : 20000u; + else v = 2000000u; #endif cache.emplace(d, v); return v; diff --git a/sycl/include/strata/sycl_queue.hpp b/sycl/include/strata/sycl_queue.hpp index 6928513e..eaf7434a 100644 --- a/sycl/include/strata/sycl_queue.hpp +++ b/sycl/include/strata/sycl_queue.hpp @@ -116,6 +116,42 @@ inline const std::string& intel_gpu_driver() { } } // namespace strata +namespace strata { +// Which Intel GPU generation a SYCL device is, from the device itself (so it also works on Windows / OpenCL, where +// intel_gpu_driver() has no sysfs to read): the architecture enum when the runtime knows it, else the marketing name +// ("Intel(R) Arc(TM) Pro B70", "... A750 ..."). Battlemage = Arc B-series / Pro B-series (B570 B580 B50 B60 B65 B70). +enum class IntelGpuGen { Unknown, Alchemist, Battlemage }; +inline IntelGpuGen intel_gpu_gen(const sycl::device& d) { + if (!d.is_gpu()) return IntelGpuGen::Unknown; + try { + { + namespace exp = sycl::ext::oneapi::experimental; + const auto a = d.get_info(); + if (a == exp::architecture::intel_gpu_bmg_g21 || a == exp::architecture::intel_gpu_bmg_g31) + return IntelGpuGen::Battlemage; + if (a == exp::architecture::intel_gpu_acm_g10 || a == exp::architecture::intel_gpu_acm_g11 || + a == exp::architecture::intel_gpu_acm_g12) + return IntelGpuGen::Alchemist; + } + } catch (...) { + } + std::string n; + try { n = d.get_info(); } catch (...) { return IntelGpuGen::Unknown; } + if (n.find("Intel") == std::string::npos) return IntelGpuGen::Unknown; + if (n.find("Battlemage") != std::string::npos) return IntelGpuGen::Battlemage; + if (n.find("Alchemist") != std::string::npos) return IntelGpuGen::Alchemist; + // "Arc(TM) Pro B70", "Arc(TM) B580", "Arc(TM) A750": a letter and 2-3 digits, as a whole word + for (size_t i = 0; i + 2 < n.size(); ++i) { + if ((i > 0 && n[i - 1] != ' ') || (n[i] != 'A' && n[i] != 'B')) continue; + size_t j = i + 1; + while (j < n.size() && n[j] >= '0' && n[j] <= '9') ++j; + if (j - i - 1 < 2 || j - i - 1 > 3 || (j < n.size() && n[j] != ' ' && n[j] != '(')) continue; + return n[i] == 'B' ? IntelGpuGen::Battlemage : IntelGpuGen::Alchemist; + } + return IntelGpuGen::Unknown; +} +} // namespace strata + #include namespace strata { // Does every page of a big device allocation keep its own bytes? On an Arc Pro B70 (xe) a 22 GiB expert-cache arena came