Skip to content

Qwen3.8-Flash-Next on any consumer hardware: one-click install for Windows / Linux. Strata inference engine, OpenAI/Anthropic API on localhost, optional image input.

C++

sycl: pinned host mirror for experts missing from VRAM, read by the device plan

maxfridbe7becf121d626
diff --git a/docs/INTEL.md b/docs/INTEL.md
index 38973b4ba..c961b89da 100644
--- a/docs/INTEL.md
+++ b/docs/INTEL.md
@@ -351,11 +351,19 @@ of drafts accepted), 30-39 tok/s on a chat answer with prose (55-72%); sampling
nothing measurable. The engine used to abort at exit in serve mode (a queue wait in a destructor after the
runtime's teardown began); it now exits directly once its requests are done.
-**Planned (2026-09-30), in order.** Ranked by payoff on this card; the first three are in progress.
+**Planned (2026-09-30), in order.** Ranked by payoff on this card; the first three were taken first.
1. Expert dot products on XMX in integer mode: a decode window (up to 6 tokens) fits one INT8 DPAS (1-8 rows), the
i-quant grids decode to small integers, the activations are already INT8. Today: scalar dp4a, ALU-bound (77%).
+ **Parked**: three `joint_matrix` versions (opt-in `STRATA_EXPERT_XMX=1`, do not enable) were 1.4x and 2-3x slower
+ than dp4a, and the third (B filled in place with `joint_matrix_apply`) hung the GPU. At 1-6 rows the grid decode
+ and the packed-B layout cost more than the DPAS saves.
2. Experts missing from VRAM read from pinned host memory over PCIe instead of the SSD (the 256K decode collapse).
+ **Done**: at start-up every expert without a VRAM slot is read into a pinned host mirror (`STRATA_MIRROR_MIB`, by
+ default free RAM less 4 GiB), and the device-built verify plan points the expert kernels straight at it. Before,
+ that plan dropped non-resident experts, so output with misses was wrong. Forced test (`--expert-cache 8000`,
+ 1,879 experts / 3.6 GiB out of VRAM): decode 2.6 -> 40.9 tok/s (full cache 43.3), prompt 451 -> 640 tok/s
+ (776), output tokens identical to the full-cache run. About 3.6 GiB of VRAM can go to context for ~6% of decode.
3. KV streaming (`--kv-resident`) from 64K up: only the attended window of the KV in VRAM. **Done**: 256K decodes at
31 tok/s (from 4-5).
4. QSA block selection on XMX: every query against every pooled block, a dense product that grows with the context.
diff --git a/sycl/include/strata/core/gguf_expert_source.hpp b/sycl/include/strata/core/gguf_expert_source.hpp
index 1e88fcb90..7ae36b53a 100644
--- a/sycl/include/strata/core/gguf_expert_source.hpp
+++ b/sycl/include/strata/core/gguf_expert_source.hpp
@@ -41,6 +41,19 @@ public:
bool read_into(int64_t layer, int64_t expert, uint8_t* dst, size_t bytes) const;
int64_t reads() const override { return reads_; }
+ /// SYCL port, plan item 2: the experts that did not fit the VRAM cache, read once into pinned host memory the
+ /// GPU can address (USM host). They are then `pinned()` with a `device_alias()`: the verify window reads them over
+ /// PCIe on the GPU (its "direct" mode) and the prompt path DMAs them, instead of an SSD read each time they are
+ /// routed - what made decode collapse to 4-5 tok/s at 256K (docs/INTEL.md). At most `cap` bytes; returns the
+ /// number mirrored. Threads read in parallel.
+ int64_t mirror(const std::vector<std::pair<int64_t, int64_t>>& pairs, uint64_t cap, int threads, std::string& err);
+ bool pinned(int64_t layer, int64_t expert) const override;
+ /// The mirrored blob's address, which the device can read. For a layer that has any mirrored expert, an
+ /// unmirrored one answers that layer's first mirrored blob: the verify plan asks `device_alias(layer, 0)` only as
+ /// "does this source have device-readable experts", and dereferences an alias only for `pinned()` experts.
+ const uint8_t* device_alias(int64_t layer, int64_t expert) const override;
+ uint64_t mirrored_bytes() const { return mirror_bytes_; }
+
private:
int fd_of(int64_t layer, std::string& err);
@@ -56,6 +69,10 @@ private:
std::mutex mu_;
int64_t n_layers_ = 0, n_expert_ = 0;
int64_t reads_ = 0;
+ uint8_t* mirror_ = nullptr; ///< USM host (pinned, device-readable)
+ uint64_t mirror_bytes_ = 0;
+ std::vector<int64_t> mirror_off_; ///< per (layer, expert): offset in mirror_, -1 = not mirrored
+ std::vector<int64_t> layer_first_; ///< per layer: offset of its first mirrored blob, -1 = none
};
} // namespace strata::core
diff --git a/sycl/include/strata/kernels/resident_plan_mirror.hpp b/sycl/include/strata/kernels/resident_plan_mirror.hpp
new file mode 100644
index 000000000..b28a089a3
--- /dev/null
+++ b/sycl/include/strata/kernels/resident_plan_mirror.hpp
@@ -0,0 +1,10 @@
+// SYCL port: experts mirrored in pinned host memory (GgufExpertSource::mirror) in the device-built verify plan.
+#pragma once
+#include <cstdint>
+namespace strata::kernels {
+/// From now on (and in every graph captured after this call) the device-built plan (resident_plan) treats an expert
+/// that is not in the VRAM cache but has a non-zero entry in `mirror_table` ([n_layers][n_expert] device-readable
+/// addresses, 0 = none) as planned: the expert kernels read it from that address, over PCIe. `d_res` is the residency
+/// table whose per-layer slices resident_plan receives, so the layer of a call is found from its pointer.
+void resident_plan_set_mirror(const int32_t* d_res, const unsigned long long* mirror_table);
+}
diff --git a/sycl/src/core/gguf_expert_source.cpp b/sycl/src/core/gguf_expert_source.cpp
index 99c34dcf3..70ba763c4 100644
--- a/sycl/src/core/gguf_expert_source.cpp
+++ b/sycl/src/core/gguf_expert_source.cpp
@@ -5,6 +5,10 @@
#include <cstring>
#include <fcntl.h>
#include <unistd.h>
+#include <dpct/dpct.hpp>
+#include <sycl/sycl.hpp>
+#include <thread>
+#include <atomic>
namespace strata::core {
@@ -15,6 +19,8 @@ constexpr size_t kRing = 512; // blobs alive at once: the prompt path holds a
GgufExpertSource::~GgufExpertSource() { close(); }
void GgufExpertSource::close() {
+ if (mirror_) { sycl::free(mirror_, dpct::get_in_order_queue()); mirror_ = nullptr; }
+ mirror_bytes_ = 0; mirror_off_.clear(); layer_first_.clear();
for (int fd : fds_) if (fd >= 0) ::close(fd);
fds_.clear(); names_.clear(); layer_fd_.clear(); ring_.clear(); ring_key_.clear(); where_.clear();
ring_next_ = 0;
@@ -64,6 +70,10 @@ int GgufExpertSource::fd_of(int64_t layer, std::string& err) {
const uint8_t* GgufExpertSource::blob(int64_t layer, int64_t expert) {
if (layer < 0 || layer >= n_layers_ || expert < 0 || expert >= n_expert_ || ring_.empty()) return nullptr;
+ if (mirror_ != nullptr) {
+ const int64_t o = mirror_off_[(size_t) (layer * n_expert_ + expert)];
+ if (o >= 0) return mirror_ + o;
+ }
const auto& lay = strata::kernels::cpu::expert_layout();
const auto& fm = lay.fmt[(size_t) layer];
const uint64_t blob = lay.bytes[(size_t) layer];
@@ -97,6 +107,75 @@ const uint8_t* GgufExpertSource::blob(int64_t layer, int64_t expert) {
return buf.data();
}
+int64_t GgufExpertSource::mirror(const std::vector<std::pair<int64_t, int64_t>>& pairs, uint64_t cap, int threads,
+ std::string& err) {
+ const auto& lay = strata::kernels::cpu::expert_layout();
+ std::vector<std::pair<int64_t, int64_t>> take;
+ std::vector<uint64_t> offs;
+ uint64_t total = 0;
+ for (const auto& [l, e] : pairs) {
+ if (l < 0 || l >= n_layers_ || e < 0 || e >= n_expert_) continue;
+ const uint64_t b = (lay.bytes[(size_t) l] + 255) / 256 * 256;
+ if (total + b > cap) break;
+ take.push_back({l, e});
+ offs.push_back(total);
+ total += b;
+ }
+ if (take.empty()) return 0;
+ uint8_t* base = nullptr;
+ try {
+ base = (uint8_t*) sycl::malloc_host(total, dpct::get_in_order_queue());
+ } catch (const sycl::exception& ex) {
+ err = std::string("mirror: ") + ex.what();
+ }
+ if (base == nullptr) {
+ if (err.empty()) err = "mirror: no pinned host memory for " + std::to_string(total >> 20) + " MiB";
+ return -1;
+ }
+ std::atomic<size_t> next{0};
+ std::atomic<bool> bad{false};
+ std::vector<std::thread> ts;
+ for (int i = 0; i < std::max(1, threads); ++i)
+ ts.emplace_back([&] {
+ for (size_t j; (j = next.fetch_add(1)) < take.size() && !bad.load();) {
+ const auto [l, e] = take[j];
+ if (!read_into(l, e, base + offs[j], (size_t) lay.bytes[(size_t) l])) bad.store(true);
+ }
+ });
+ for (auto& th : ts) th.join();
+ if (bad.load()) {
+ sycl::free(base, dpct::get_in_order_queue());
+ err = "mirror: reading an expert from the GGUF failed";
+ return -1;
+ }
+ if (mirror_) sycl::free(mirror_, dpct::get_in_order_queue());
+ mirror_ = base;
+ mirror_bytes_ = total;
+ mirror_off_.assign((size_t) (n_layers_ * n_expert_), -1);
+ layer_first_.assign((size_t) n_layers_, -1);
+ for (size_t j = 0; j < take.size(); ++j) {
+ const auto [l, e] = take[j];
+ mirror_off_[(size_t) (l * n_expert_ + e)] = (int64_t) offs[j];
+ if (layer_first_[(size_t) l] < 0) layer_first_[(size_t) l] = (int64_t) offs[j];
+ }
+ return (int64_t) take.size();
+}
+
+bool GgufExpertSource::pinned(int64_t layer, int64_t expert) const {
+ if (mirror_ == nullptr || layer < 0 || layer >= n_layers_ || expert < 0 || expert >= n_expert_) return false;
+ return mirror_off_[(size_t) (layer * n_expert_ + expert)] >= 0;
+}
+
+const uint8_t* GgufExpertSource::device_alias(int64_t layer, int64_t expert) const {
+ if (mirror_ == nullptr || layer < 0 || layer >= n_layers_) return nullptr;
+ if (expert >= 0 && expert < n_expert_) {
+ const int64_t o = mirror_off_[(size_t) (layer * n_expert_ + expert)];
+ if (o >= 0) return mirror_ + o;
+ }
+ const int64_t f = layer_first_[(size_t) layer];
+ return f >= 0 ? mirror_ + f : nullptr;
+}
+
bool GgufExpertSource::read_into(int64_t layer, int64_t expert, uint8_t* dst, size_t bytes) const {
if (layer < 0 || layer >= n_layers_ || expert < 0 || expert >= n_expert_ || dst == nullptr) return false;
const auto& lay = strata::kernels::cpu::expert_layout();
diff --git a/sycl/src/kernels/cuda/verify_kernels.dp.cpp b/sycl/src/kernels/cuda/verify_kernels.dp.cpp
index b556c82a1..9d51ecee0 100644
--- a/sycl/src/kernels/cuda/verify_kernels.dp.cpp
+++ b/sycl/src/kernels/cuda/verify_kernels.dp.cpp
@@ -8,6 +8,7 @@
#include "strata/sycl_queue.hpp"
#include "strata/sycl_doorbell.hpp"
#include "strata/kernels/verify_kernels.hpp"
+#include "strata/kernels/resident_plan_mirror.hpp"
#include <cstdio>
#include <cstdlib>
@@ -930,7 +931,8 @@ __dpct_inline__ void resident_plan_kernel(
const int32_t *__restrict__ ids, int n, int k,
const int32_t *__restrict__ res, int n_expert, const uint8_t *cache_base,
const unsigned long long *slot_off, long long blob,
- int32_t *__restrict__ pl, long long capx, uint32_t *skip, uint32_t ring) {
+ int32_t *__restrict__ pl, long long capx, uint32_t *skip, uint32_t ring,
+ const unsigned long long *__restrict__ mir) {
#if STRATA_PLAN_LOCAL
// SYCL port: the host's exact loop, but over a local copy of the ids and their slots. One thread reading global
// memory for every compare (n^2 of them) took 87 us per layer on the B70 - 4% of a decode round; a work-group
@@ -939,15 +941,19 @@ __dpct_inline__ void resident_plan_kernel(
auto &s_ids = *sycl::ext::oneapi::group_local_memory_for_overwrite<int32_t[64]>(item.get_group());
auto &s_res = *sycl::ext::oneapi::group_local_memory_for_overwrite<int32_t[64]>(item.get_group());
auto &s_bad = *sycl::ext::oneapi::group_local_memory_for_overwrite<int>(item.get_group());
+ auto &s_mir = *sycl::ext::oneapi::group_local_memory_for_overwrite<unsigned long long[64]>(item.get_group());
const int tid = (int) item.get_local_id(2);
if (tid == 0) s_bad = 0;
item.barrier(sycl::access::fence_space::local_space);
for (int i = tid; i < n && i < 64; i += 64) {
const int32_t e = ids[i];
- const bool ok = e >= 0 && e < n_expert && res[e] >= 0;
+ const bool valid = e >= 0 && e < n_expert;
+ const int32_t sl = valid ? res[e] : -1;
+ const unsigned long long ma = (valid && sl < 0 && mir != nullptr) ? mir[e] : 0ull; // mirrored in host memory
s_ids[i] = e;
- s_res[i] = ok ? res[e] : -1;
- if (!ok) s_bad = 1;
+ s_res[i] = sl;
+ s_mir[i] = ma;
+ if (!valid || (sl < 0 && ma == 0)) s_bad = 1;
}
item.barrier(sycl::access::fence_space::local_space);
if (tid != 0) return;
@@ -980,7 +986,12 @@ __dpct_inline__ void resident_plan_kernel(
}
if (!first) continue;
const int32_t slot = S_RES(i0);
+#if STRATA_PLAN_LOCAL
+ ptr[groups] = slot >= 0 ? (unsigned long long) (cache_base + (slot_off ? (size_t) slot_off[slot] : (size_t) slot * (size_t) blob))
+ : s_mir[i0]; // not in VRAM: its pinned host mirror, read by the expert kernels over PCIe
+#else
ptr[groups] = (unsigned long long) (cache_base + (slot_off ? (size_t) slot_off[slot] : (size_t) slot * (size_t) blob));
+#endif
start[groups] = entries;
for (int i = i0; i < n; ++i)
if (s_ids[i] == s_ids[i0]) {
@@ -1054,9 +1065,20 @@ __dpct_inline__ void copy_or_zero_kernel(sycl::float4 *__restrict__ dst,
}
} // namespace
+namespace {
+const int32_t* g_mirror_res = nullptr;
+const unsigned long long* g_mirror_table = nullptr;
+}
+void resident_plan_set_mirror(const int32_t* d_res, const unsigned long long* mirror_table) {
+ g_mirror_res = d_res;
+ g_mirror_table = mirror_table;
+}
void resident_plan(const int32_t* ids, int n_entries, int k, const int32_t* res_layer, int n_expert,
const uint8_t* cache_base, const unsigned long long* slot_off, long long blob, int32_t* plan,
long long capx, uint32_t* skip, uint32_t ring, void* stream) {
+ const unsigned long long* mir = nullptr; // SYCL port: the layer's slice of the host-mirror table, if any
+ if (g_mirror_table != nullptr && g_mirror_res != nullptr && res_layer >= g_mirror_res)
+ mir = g_mirror_table + (res_layer - g_mirror_res);
{
auto exp_props = sycl::ext::oneapi::experimental::properties{
sycl::ext::oneapi::experimental::use_root_sync};
@@ -1067,7 +1089,7 @@ void resident_plan(const int32_t* ids, int n_entries, int k, const int32_t* res_
exp_props, [=](sycl::nd_item<3> item_ct1) [[sycl::reqd_sub_group_size(32)]] {
resident_plan_kernel(ids, n_entries, k, res_layer, n_expert,
cache_base, slot_off, blob, plan, capx,
- skip, ring);
+ skip, ring, mir);
});
}
check("resident_plan");
diff --git a/sycl/src/program/generate.cpp b/sycl/src/program/generate.cpp
index 9f5ac4b84..34a605989 100644
--- a/sycl/src/program/generate.cpp
+++ b/sycl/src/program/generate.cpp
@@ -21,6 +21,7 @@
#include "strata/core/expert_cache.hpp"
#include "strata/core/expert_source.hpp"
#include "strata/core/gguf_expert_source.hpp"
+#include "strata/kernels/resident_plan_mirror.hpp"
#include "strata/core/remote_experts.hpp"
#include "strata/core/on_device.hpp"
#include "strata/core/layer.hpp"
@@ -2443,6 +2444,58 @@ int main(int argc, char** argv) {
std::fprintf(stderr, "strata generate: pre-filled %lld of %lld slots from the profile; slot 0 verified\n",
(long long) prefilled, (long long) want);
}
+ // SYCL port, plan item 2: the experts that did not fit VRAM, mirrored once in pinned host memory the GPU reads
+ // over PCIe (--stream-experts has no host copy otherwise: each routed miss was an SSD read). The share of misses
+ // the GPU takes is --pcie-frac; STRATA_MIRROR_MIB caps the mirror (default: MemAvailable less 4 GiB), 0 = off.
+ unsigned long long* mirror_table_d = nullptr; // [n_layers][n_expert] device-readable mirror addresses (0 = none)
+ int64_t unmirrored_misses = 0;
+ if (o.stream_experts && srcp == &gguf_src && o.expert_cache > 0) {
+ std::vector<std::pair<int64_t, int64_t>> miss;
+ for (const auto& pr : profile) // the profile's order: the most-routed misses first, if the cap is reached
+ if (xcache.slot_of(pr.first, pr.second) == strata::core::kNotResident) miss.push_back({pr.first, pr.second});
+ for (int64_t l = 0; l < g.n_layers; ++l) // pairs the profile does not list at all
+ for (int64_t e = 0; e < g.n_expert; ++e)
+ if (xcache.slot_of(l, e) == strata::core::kNotResident &&
+ std::find(miss.begin(), miss.end(), std::pair<int64_t, int64_t>{l, e}) == miss.end())
+ miss.push_back({l, e});
+ uint64_t avail = 0;
+ if (FILE* f = std::fopen("/proc/meminfo", "r")) {
+ char key[64]; unsigned long long kb = 0;
+ while (std::fscanf(f, "%63s %llu kB", key, &kb) == 2)
+ if (std::strcmp(key, "MemAvailable:") == 0) { avail = kb << 10; break; }
+ std::fclose(f);
+ }
+ const char* mv = std::getenv("STRATA_MIRROR_MIB");
+ const uint64_t cap = mv ? (uint64_t) std::atoll(mv) << 20 : (avail > (4ull << 30) ? avail - (4ull << 30) : 0);
+ if (!miss.empty() && cap > 0) {
+ const auto tm = Clock::now();
+ const int64_t got = gguf_src.mirror(miss, cap, 8, err);
+ if (got < 0) {
+ std::fprintf(stderr, "strata generate: mirroring the experts missing from VRAM: %s (they stay on the SSD)\n",
+ err.c_str());
+ err.clear();
+ } else {
+ std::fprintf(stderr, "strata generate: %lld of %zu experts missing from VRAM mirrored in pinned host memory "
+ "(%.2f GiB, %.1f s); the GPU reads them over PCIe\n", (long long) got, miss.size(),
+ (double) gguf_src.mirrored_bytes() / 1073741824.0,
+ std::chrono::duration<double>(Clock::now() - tm).count());
+ // the device-built verify plan's view of it: each (layer, expert) -> its mirror address, 0 = none
+ std::vector<unsigned long long> tab((size_t) (g.n_layers * g.n_expert), 0ull);
+ for (int64_t l = 0; l < g.n_layers; ++l)
+ for (int64_t e = 0; e < g.n_expert; ++e)
+ if (gguf_src.pinned(l, e))
+ tab[(size_t) (l * g.n_expert + e)] = (unsigned long long) gguf_src.device_alias(l, e);
+ mirror_table_d = sycl::malloc_device<unsigned long long>(tab.size(), dpct::get_in_order_queue());
+ dpct::get_in_order_queue().memcpy(mirror_table_d, tab.data(), tab.size() * sizeof(unsigned long long)).wait();
+ }
+ }
+ unmirrored_misses = (int64_t) miss.size() - (int64_t) (gguf_src.mirrored_bytes() ? std::count_if(miss.begin(), miss.end(),
+ [&](const std::pair<int64_t, int64_t>& pr) { return gguf_src.pinned(pr.first, pr.second); }) : 0);
+ if (unmirrored_misses > 0 && std::getenv("STRATA_VERIFY_NO_HOST") != nullptr)
+ std::fprintf(stderr, "strata generate: WARNING: %lld experts are neither in VRAM nor mirrored; with STRATA_VERIFY_NO_HOST "
+ "the device plan cannot run them and their layers' windows fall back slowly - raise "
+ "STRATA_MIRROR_MIB or the free RAM, or lower --max-context\n", (long long) unmirrored_misses);
+ }
if (o.resident_cpu_experts) {
if (!src.pin_cache_complement(xcache, err, /*pin=*/false)) {
@@ -3479,6 +3532,7 @@ int main(int argc, char** argv) {
strata::core::Verifier ver;
strata::core::VerifyHits vh;
vh.d_res = thits.d_res;
+ if (mirror_table_d) strata::kernels::resident_plan_set_mirror(thits.d_res, mirror_table_d);
vh.cache_base = thits.cache_base;
vh.blob = thits.blob;
vh.slot_off = xcache.slot_offsets(); // E-6: the device plan's pointers
@@ -5229,6 +5283,7 @@ int main(int argc, char** argv) {
strata::core::Verifier ver;
strata::core::VerifyHits vh;
vh.d_res = thits.d_res;
+ if (mirror_table_d) strata::kernels::resident_plan_set_mirror(thits.d_res, mirror_table_d);
vh.cache_base = thits.cache_base;
vh.blob = thits.blob;
vh.slot_off = xcache.slot_offsets(); // E-6: the device plan's pointers