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: guard big device allocations against aliased pages on the xe driver (Arc Pro B70)
Niko122178f6174474e8
diff --git a/sycl/include/strata/sycl_queue.hpp b/sycl/include/strata/sycl_queue.hppindex e9986d82f..5728e8264 100644--- a/sycl/include/strata/sycl_queue.hpp+++ b/sycl/include/strata/sycl_queue.hpp@@ -115,3 +115,90 @@ inline const std::string& intel_gpu_driver() {return drv;}} // namespace strata++#include <cstdint>+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+// back with two of its 2 MiB pages mapped onto the same memory (a write to the page at +2 MiB showed up at +1022 MiB; the+// cache slots there then held other experts' bytes and the prompt came out NaN). The check writes a tag per 64 KiB of+// the range, then reads them back in a second kernel: it returns the number of 64 KiB blocks that do not hold their own tag+// (0 = clean) and the first such block's offset. The range's contents are destroyed.+inline uint64_t arena_alias_check(sycl::queue& q, void* base, size_t bytes, size_t* first_bad = nullptr) {+ constexpr size_t kBlock = 64 << 10;+ const size_t n = bytes / kBlock;+ if (n == 0) return 0;+ uint8_t* b = (uint8_t*) base;+ uint64_t* res = sycl::malloc_device<uint64_t>(2, q);+ uint64_t init[2] = {0, ~0ull};+ q.memcpy(res, init, sizeof init).wait();+ // chunked so that no single launch is huge (an xe job past a few seconds is timed out)+ const size_t chunk = (size_t) 1 << 20;+ for (size_t c0 = 0; c0 < n; c0 += chunk) {+ const size_t cn = n - c0 < chunk ? n - c0 : chunk;+ q.parallel_for(sycl::range<1>(cn), [=](sycl::id<1> i) {+ const size_t blk = c0 + i[0];+ *(volatile uint64_t*) (b + blk * kBlock) = (blk + 1) * 0x9E3779B97F4A7C15ull;+ });+ q.wait();+ }+ for (size_t c0 = 0; c0 < n; c0 += chunk) {+ const size_t cn = n - c0 < chunk ? n - c0 : chunk;+ q.parallel_for(sycl::range<1>(cn), [=](sycl::id<1> i) {+ const size_t blk = c0 + i[0];+ if (*(volatile uint64_t*) (b + blk * kBlock) != (blk + 1) * 0x9E3779B97F4A7C15ull) {+ sycl::atomic_ref<uint64_t, sycl::memory_order::relaxed, sycl::memory_scope::device> bad(res[0]);+ sycl::atomic_ref<uint64_t, sycl::memory_order::relaxed, sycl::memory_scope::device> lo(res[1]);+ bad.fetch_add(1);+ lo.fetch_min((uint64_t) blk * kBlock);+ }+ });+ q.wait();+ }+ uint64_t out[2] = {0, 0};+ q.memcpy(out, res, sizeof out).wait();+ sycl::free(res, q);+ if (first_bad) *first_bad = (size_t) out[1];+ return out[0];+}+} // namespace strata++namespace strata {+inline bool arena_alias_guard_enabled() {+ static const bool on = [] { const char* v = std::getenv("STRATA_ARENA_ALIAS_CHECK"); return v == nullptr || v[0] != '0'; }();+ return on;+}+} // namespace strata++#include <vector>+namespace strata {+// sycl::malloc_device for a big allocation, checked for aliased pages (arena_alias_check) and, when it has some, allocated+// again behind a growing spacer that moves it. Small allocations and STRATA_ARENA_ALIAS_CHECK=0 go straight to+// sycl::malloc_device. The memory comes back uninitialised, as from sycl::malloc_device.+inline void* malloc_device_guarded(size_t bytes, sycl::queue& q, const char* what = "device buffer") {+ void* p = sycl::malloc_device(bytes, q);+ if (p == nullptr || bytes < ((size_t) 32 << 20) || !arena_alias_guard_enabled()) return p;+ std::vector<void*> spacers;+ bool clean = false;+ for (int attempt = 0; attempt < 8 && p != nullptr; ++attempt) {+ size_t first = 0;+ const uint64_t bad = arena_alias_check(q, p, bytes, &first);+ if (bad == 0) {+ clean = true;+ if (attempt > 0)+ std::fprintf(stderr, "strata: %s (%.2f GiB) is clean after %d move(s)\n", what, (double) bytes / 1073741824.0, attempt);+ break;+ }+ std::fprintf(stderr,+ "strata: WARNING: %llu 64-KiB blocks of the %s (%.2f GiB) do not keep their own bytes (first at +%zu MiB): the GPU's "+ "page table maps them onto other pages; allocating it again behind a %d MiB spacer\n",+ (unsigned long long) bad, what, (double) bytes / 1073741824.0, first >> 20, 2 * (attempt + 1));+ sycl::free(p, q);+ spacers.push_back(sycl::malloc_device((size_t) (2 * (attempt + 1)) << 20, q));+ p = sycl::malloc_device(bytes, q);+ }+ for (void* sp : spacers) if (sp != nullptr) sycl::free(sp, q);+ if (p != nullptr && !clean)+ std::fprintf(stderr, "strata: WARNING: the %s still has aliased pages after 8 tries (STRATA_ARENA_ALIAS_CHECK=0 skips the check)\n", what);+ return p;+}+} // namespace stratadiff --git a/sycl/probe/alias_scan.cpp b/sycl/probe/alias_scan.cppnew file mode 100644index 000000000..19a5d4ab8--- /dev/null+++ b/sycl/probe/alias_scan.cpp@@ -0,0 +1,38 @@+// alias_scan: allocate device buffers of assorted sizes, keep them, and run strata::arena_alias_check on each: where does+// the xe page table alias pages (a write to one 2 MiB page showing at another)? Prints each buffer's address mod 1 GiB.+// alias_scan [n=40] [seed=1] [max_mib=6000]+#include <sycl/sycl.hpp>+#include <cstdio>+#include <cstdlib>+#include <random>+#include <vector>+#include "strata/sycl_queue.hpp"++int main(int argc, char** argv) {+ const int n = argc > 1 ? std::atoi(argv[1]) : 40;+ const unsigned seed = argc > 2 ? (unsigned) std::atoi(argv[2]) : 1;+ const size_t max_mib = argc > 3 ? (size_t) std::atoll(argv[3]) : 6000;+ sycl::queue q{sycl::gpu_selector_v, sycl::property::queue::in_order{}};+ std::mt19937_64 rng(seed);+ std::vector<void*> keep;+ size_t total = 0;+ int bad_bufs = 0;+ for (int i = 0; i < n; ++i) {+ size_t mib = (rng() % 4 == 0) ? 1 + rng() % 8 : 1 + rng() % max_mib;+ if (total + mib > 24000) break;+ const size_t bytes = mib << 20;+ void* p = sycl::malloc_device(bytes, q);+ if (!p) { std::printf("alloc %zu MiB failed\n", mib); break; }+ keep.push_back(p);+ total += mib;+ size_t first = 0;+ const uint64_t bad = strata::arena_alias_check(q, p, bytes, &first);+ std::printf("#%02d %6zu MiB at %p (mod 1GiB %5zu MiB, mod 2MiB %zu): %s", i, mib, p, (size_t) (((uintptr_t) p & ((1u << 30) - 1)) >> 20),+ (size_t) ((uintptr_t) p & ((2u << 20) - 1)), bad ? "ALIAS" : "ok");+ if (bad) { ++bad_bufs; std::printf(" %llu blocks, first at +%zu MiB", (unsigned long long) bad, first >> 20); }+ std::printf("\n");+ }+ std::printf("%d of %zu buffers aliased\n", bad_bufs, keep.size());+ for (void* p : keep) sycl::free(p, q);+ return bad_bufs ? 3 : 0;+}diff --git a/sycl/probe/arena_rw.cpp b/sycl/probe/arena_rw.cppnew file mode 100644index 000000000..072e2bd29--- /dev/null+++ b/sycl/probe/arena_rw.cpp@@ -0,0 +1,63 @@+// arena_rw: does a big device arena keep what is copied into it? The engine's expert-cache fill (pinned host batches of+// 64 blobs, queue.memcpy into odd-sized slots, the arena zeroed by chunked kernels first) read back with 2 MiB pages of the+// arena holding wrong bytes on an Arc Pro B70 (xe). This reproduces the shape without the engine.+// arena_rw GIB [slot_bytes=1971200] [batch=64] [zero=1] [verify_after_fill=1]+#include <sycl/sycl.hpp>+#include <chrono>+#include <cstdint>+#include <cstdio>+#include <cstdlib>+#include <cstring>+#include <vector>+#include "strata/sycl_queue.hpp"++static inline uint8_t pat(uint64_t off) {+ uint64_t x = off * 0x9E3779B97F4A7C15ull;+ x ^= x >> 29;+ return (uint8_t) (x >> 11);+}++int main(int argc, char** argv) {+ const double gib = argc > 1 ? std::atof(argv[1]) : 4.0;+ const size_t slot = argc > 2 ? (size_t) std::atoll(argv[2]) : 1971200;+ const size_t batch = argc > 3 ? (size_t) std::atoll(argv[3]) : 64;+ const int zero = argc > 4 ? std::atoi(argv[4]) : 1;+ const size_t total = (size_t) (gib * 1073741824.0);+ const size_t n_slots = total / ((slot + 255) / 256 * 256);+ const size_t stride = (slot + 255) / 256 * 256;+ sycl::queue q{sycl::gpu_selector_v, sycl::property::queue::in_order{}};+ std::printf("device %s\n", q.get_device().get_info<sycl::info::device::name>().c_str());+ uint8_t* arena = (uint8_t*) sycl::malloc_device(n_slots * stride + (2 << 20), q);+ if (!arena) { std::printf("alloc failed\n"); return 1; }+ arena = (uint8_t*) (((uintptr_t) arena + (2 << 20) - 1) & ~(uintptr_t) ((2 << 20) - 1)); // as the engine's: 2 MiB aligned+ std::printf("arena %p, %zu slots of %zu (stride %zu)\n", (void*) arena, n_slots, slot, stride);+ if (zero) strata::big_fill_zero(q, arena, n_slots * stride);+ uint8_t* pin = sycl::malloc_host<uint8_t>(2 * batch * stride, q);+ sycl::event done[2];+ size_t k = 0;+ for (size_t b0 = 0; b0 < n_slots; b0 += batch, ++k) {+ const size_t n = std::min(batch, n_slots - b0);+ uint8_t* set = pin + (k % 2) * batch * stride;+ done[k % 2].wait();+ for (size_t j = 0; j < n; ++j)+ for (size_t x = 0; x < slot; ++x) set[j * stride + x] = pat((b0 + j) * stride + x);+ for (size_t j = 0; j < n; ++j) done[k % 2] = q.memcpy(arena + (b0 + j) * stride, set + j * stride, slot);+ }+ q.wait();+ std::vector<uint8_t> got(stride);+ size_t bad = 0;+ for (size_t i = 0; i < n_slots; ++i) {+ q.memcpy(got.data(), arena + i * stride, slot).wait();+ size_t nd = 0, fd = slot;+ for (size_t x = 0; x < slot; ++x)+ if (got[x] != pat(i * stride + x)) { ++nd; if (fd == slot) fd = x; }+ if (nd) {+ ++bad;+ if (bad <= 10)+ std::printf("slot %zu at %p (offset %zu MiB): %zu of %zu bytes differ, first at %zu\n", i, (void*) (arena + i * stride),+ (i * stride) >> 20, nd, slot, fd);+ }+ }+ std::printf("%zu of %zu slots differ\n", bad, n_slots);+ return bad ? 3 : 0;+}diff --git a/sycl/src/core/device.dp.cpp b/sycl/src/core/device.dp.cppindex 45645f7a5..5905b3061 100644--- a/sycl/src/core/device.dp.cpp+++ b/sycl/src/core/device.dp.cpp@@ -2,6 +2,7 @@#define DPCT_PROFILING_ENABLED#include <sycl/sycl.hpp>#include <dpct/dpct.hpp>+#include "strata/sycl_queue.hpp"#include "strata/core/device.hpp"#include <cstdio>@@ -411,7 +412,7 @@ DeviceArena::DeviceArena(uint64_t bytes, int ordinal, bool poison)check(DPCT_CHECK_ERROR(dpct::select_device(ordinal)), "cudaSetDevice");// One allocation for the whole region. cudaMalloc of a large block is the thing that can fail late, so it// happens once, here, before anything depends on it.- check(DPCT_CHECK_ERROR(base_ = (void *)sycl::malloc_device(+ check(DPCT_CHECK_ERROR(base_ = (void *)strata::malloc_device_guarded((size_t)bytes, dpct::get_in_order_queue())),"cudaMalloc");if (poison_) {diff --git a/sycl/src/core/expert_cache.cpp b/sycl/src/core/expert_cache.cppindex fb8b519fd..ed1c87402 100644--- a/sycl/src/core/expert_cache.cpp+++ b/sycl/src/core/expert_cache.cpp@@ -638,8 +638,8 @@ bool ExpertCache::open(int64_t n_slots, int64_t n_layers, int64_t n_expert, int6base_ = r->base();vmm_ = std::move(r);} else if (DPCT_CHECK_ERROR(- base_ = (uint8_t *)sycl::malloc_device(- (size_t)want, dpct::get_in_order_queue())) != 0 ||+ base_ = (uint8_t *)strata::malloc_device_guarded(+ (size_t)want, dpct::get_in_order_queue(), "expert cache arena")) != 0 ||base_ == nullptr) { // Level Zero answers a too-large allocation with null, not an exception// (an Arc A750 caps one allocation at 4 GiB unless UR_L0_ENABLE_RELAXED_ALLOCATION_LIMITS=1)base_ = nullptr;diff --git a/sycl/src/core/mtp.cpp b/sycl/src/core/mtp.cppindex a5c4af8a6..3c0215742 100644--- a/sycl/src/core/mtp.cpp+++ b/sycl/src/core/mtp.cpp@@ -222,7 +222,7 @@ bool MtpDrafter::make_q4_dense(const std::vector<uint8_t>& blob, std::string& er}q4_off_.push_back({t->name, off});}- dense4_ = (uint8_t*) sycl::malloc_device((size_t) total, dpct::get_in_order_queue()); // SYCL port: cudaMalloc/cudaMemcpy+ dense4_ = (uint8_t*) strata::malloc_device_guarded((size_t) total, dpct::get_in_order_queue()); // SYCL port: cudaMalloc/cudaMemcpyif (dense4_ == nullptr) { err = "mtp: the Q4_0 projections do not fit"; return false; }dpct::get_in_order_queue().memcpy(dense4_, host.data(), (size_t) total).wait();vram_ += total;@@ -306,7 +306,7 @@ bool MtpDrafter::load(const std::string &rt_dir, const ModelGeometry &g,std::vector<uint8_t> blob;if (!read_file(rt_dir + "/dense.bin", blob)) { err = "mtp: cannot read dense.bin"; return false; }const dpct::err0 alloc =- DPCT_CHECK_ERROR(dense_ = (uint8_t *)sycl::malloc_device(+ DPCT_CHECK_ERROR(dense_ = (uint8_t *)strata::malloc_device_guarded(blob.size(), dpct::get_in_order_queue()));/*DPCT1000: Error handling if-stmt was detected but could not be@@ -353,7 +353,7 @@ bool MtpDrafter::load(const std::string &rt_dir, const ModelGeometry &g,FILE* f;~Closer() { if (f != nullptr) std::fclose(f); }} closer{f};- if (DPCT_CHECK_ERROR(experts_ = (uint8_t *)sycl::malloc_device(+ if (DPCT_CHECK_ERROR(experts_ = (uint8_t *)strata::malloc_device_guarded(bytes, dpct::get_in_order_queue())) != 0) {err = "mtp: the 512 experts do not fit in VRAM"; return false;}@@ -390,7 +390,7 @@ bool MtpDrafter::load(const std::string &rt_dir, const ModelGeometry &g,qsa_set_kv_hybrid(false);if (kv_hybrid_was) qsa_set_kv_int8(true); // the drafter under --kv k8v4: plain INT8uint64_t sb = qsa_state_bytes(g, max_cells, false, ring);- if (DPCT_CHECK_ERROR(state_arena_ = (void *)sycl::malloc_device(+ if (DPCT_CHECK_ERROR(state_arena_ = (void *)strata::malloc_device_guarded(sb, dpct::get_in_order_queue())) != 0) {err = "mtp: the K/V state does not fit"; return false;}@@ -405,7 +405,7 @@ bool MtpDrafter::load(const std::string &rt_dir, const ModelGeometry &g,st_ = QsaState{};ring = -1; // fully residentsb = qsa_state_bytes(g, max_cells, false, ring);- if (DPCT_CHECK_ERROR(state_arena_ = (void *)sycl::malloc_device(+ if (DPCT_CHECK_ERROR(state_arena_ = (void *)strata::malloc_device_guarded(sb, dpct::get_in_order_queue())) != 0) {err = "mtp: the K/V state does not fit"; return false;}@@ -465,7 +465,7 @@ bool MtpDrafter::load(const std::string &rt_dir, const ModelGeometry &g,};Bump count;carve(count);- if (DPCT_CHECK_ERROR(arena_ = (void *)sycl::malloc_device(+ if (DPCT_CHECK_ERROR(arena_ = (void *)strata::malloc_device_guarded(count.used, dpct::get_in_order_queue())) != 0) {err = "mtp: buffers do not fit"; return false;}diff --git a/sycl/src/core/native_dense.cpp b/sycl/src/core/native_dense.cppindex 4c9381085..3d6beca16 100644--- a/sycl/src/core/native_dense.cpp+++ b/sycl/src/core/native_dense.cpp@@ -1,6 +1,7 @@#define DPCT_PROFILING_ENABLED#include <sycl/sycl.hpp>#include <dpct/dpct.hpp>+#include "strata/sycl_queue.hpp"#include "strata/core/native_dense.hpp"#include <cstdlib>#include "strata/core/weights.hpp"@@ -245,7 +246,7 @@ bool NativeDense::load(const std::vector<std::string> &shards,tensor.type, (int) ref.ne0, (int) ref.ne1);void* allocation = nullptr;auto status =- DPCT_CHECK_ERROR(allocation = (void *)sycl::malloc_device(+ DPCT_CHECK_ERROR(allocation = (void *)strata::malloc_device_guarded(bytes, dpct::get_in_order_queue()));DevicePtr data(allocation);if (status == 0)@@ -284,7 +285,7 @@ bool NativeDense::load(const std::vector<std::string> &shards,(int) ref.ne1);void* packed_allocation = nullptr;auto packed_status = DPCT_CHECK_ERROR(- packed_allocation = (void *)sycl::malloc_device(+ packed_allocation = (void *)strata::malloc_device_guarded(bytes, dpct::get_in_order_queue()));packed.reset(packed_allocation);if (packed_status == 0)@@ -332,7 +333,7 @@ bool NativeDense::load(const std::vector<std::string> &shards,std::vector<uint8_t> q8;if (f32_inject) q8 = q8_0_of((const float*) gguf.tensor_data(tensor), (uint64_t) ref.ne0 * (uint64_t) ref.ne1);if (DPCT_CHECK_ERROR(- p = (void *)sycl::malloc_device(+ p = (void *)strata::malloc_device_guarded(bytes, dpct::get_in_order_queue())) != 0 ||/*DPCT1114: cudaMemcpy is migrated to@@ -356,7 +357,7 @@ bool NativeDense::load(const std::vector<std::string> &shards,if (pending.empty()) { err = "native dense: no supported GDN/QSA matrices in supplied shards"; return false; }void* allocation = nullptr;const auto status =- DPCT_CHECK_ERROR(allocation = (void *)sycl::malloc_device(+ DPCT_CHECK_ERROR(allocation = (void *)strata::malloc_device_guarded(strata::kernels::native_q8_1_bytes(max_in),dpct::get_in_order_queue()));DevicePtr scratch(allocation);diff --git a/sycl/src/core/native_head.cpp b/sycl/src/core/native_head.cppindex 9f4b270fd..9afd21995 100644--- a/sycl/src/core/native_head.cpp+++ b/sycl/src/core/native_head.cpp@@ -1,6 +1,7 @@#define DPCT_PROFILING_ENABLED#include <sycl/sycl.hpp>#include <dpct/dpct.hpp>+#include "strata/sycl_queue.hpp"#include "strata/core/native_head.hpp"#include "strata/artifact/gguf_reader.hpp"#include "strata/kernels/iq_kernels.hpp"@@ -50,11 +51,11 @@ bool NativeHead::load(const std::vector<std::string> &shards, int64_t n_in,void* weights = nullptr;void* scratch = nullptr;dpct::err0 status =- DPCT_CHECK_ERROR(weights = (void *)sycl::malloc_device(+ DPCT_CHECK_ERROR(weights = (void *)strata::malloc_device_guarded(bytes, dpct::get_in_order_queue()));if (status == 0)status = DPCT_CHECK_ERROR(- scratch = (void *)sycl::malloc_device(+ scratch = (void *)strata::malloc_device_guarded(strata::kernels::native_q8_1_bytes((int)n_in, 1),dpct::get_in_order_queue()));strata::platform::advise_willneed(gguf.tensor_data(*tensor), bytes);@@ -212,7 +213,7 @@ bool NativeEmbed::load(const std::vector<std::string> &shards, int64_t n_embd,*/host_ = nullptr;void* d = nullptr;- if (DPCT_CHECK_ERROR(d = (void *)sycl::malloc_device(+ if (DPCT_CHECK_ERROR(d = (void *)strata::malloc_device_guarded(bytes_, dpct::get_in_order_queue())) !=0 ||/*diff --git a/sycl/src/core/verify.cpp b/sycl/src/core/verify.cppindex 8e27634af..9d26b8804 100644--- a/sycl/src/core/verify.cpp+++ b/sycl/src/core/verify.cpp@@ -541,7 +541,7 @@ bool Verifier::init(const WeightTable &wt, const ModelGeometry &g,};Bump count;carve(count);- if (DPCT_CHECK_ERROR(arena_ = (void *)sycl::malloc_device(+ if (DPCT_CHECK_ERROR(arena_ = (void *)strata::malloc_device_guarded(count.used, dpct::get_in_order_queue())) != 0) {err = "verify: the device arena (" + std::to_string(count.used >> 20) + " MiB) does not fit";return false;diff --git a/sycl/src/prefill/prefill.cpp b/sycl/src/prefill/prefill.cppindex ae244c85c..edb089894 100644--- a/sycl/src/prefill/prefill.cpp+++ b/sycl/src/prefill/prefill.cpp@@ -316,7 +316,7 @@ struct Alloc {return p;}void* p = nullptr;- if (DPCT_CHECK_ERROR(p = (void *)sycl::malloc_device(+ if (DPCT_CHECK_ERROR(p = (void *)strata::malloc_device_guarded(bytes, dpct::get_in_order_queue())) != 0) {ok = false; failed_bytes = bytes; return nullptr;}@@ -1706,7 +1706,7 @@ bool Prefill::set_peer(core::PeerExperts *peer, int64_t cap_rows,try {void *p = nullptr;if (!ok ||- DPCT_CHECK_ERROR(p = (void *)sycl::malloc_device(+ DPCT_CHECK_ERROR(p = (void *)strata::malloc_device_guarded(bytes, dpct::get_in_order_queue())) != 0) {ok = false; return nullptr;}diff --git a/sycl/src/program/generate.cpp b/sycl/src/program/generate.cppindex eec2dc49d..17cb29957 100644--- a/sycl/src/program/generate.cpp+++ b/sycl/src/program/generate.cpp@@ -2723,7 +2723,7 @@ int main(int argc, char **argv) try {rewritten.*/if (const dpct::err0 ce =- DPCT_CHECK_ERROR(arena = (void *)sycl::malloc_device(+ DPCT_CHECK_ERROR(arena = (void *)strata::malloc_device_guarded(pool_bytes, dpct::get_in_order_queue()));ce != 0) {// #486: the arena is the first large allocation and its size does not depend on the context, so what is@@ -3154,7 +3154,7 @@ int main(int argc, char **argv) try {skip_s = skip;}void* arena_s = nullptr;- if (DPCT_CHECK_ERROR(arena_s = (void *)sycl::malloc_device(+ if (DPCT_CHECK_ERROR(arena_s = (void *)strata::malloc_device_guarded(pool_s, dpct::get_in_order_queue())) != 0 ||!st.wt.load(o.pack, arena_s, pool_s, err,skip_s.empty() ? nullptr : &skip_s)) {@@ -4511,6 +4511,7 @@ int main(int argc, char **argv) try {// admission finds no room and every non-profiled expert stays a CPU miss. That is what makes the profile// the policy rather than a hint.int64_t prefilled = 0;+ std::function<void(const char*)> verify_all_slots; // STRATA_VERIFY_ALL_SLOTS (debug), set by the pipelined fillif (!profile.empty() && srcp != nullptr) {// #369 (dag08): per layer, a full layer skips only its own pairs - each layer takes its hottest experts until// its range is full (one full layer used to end the whole fill, leaving most layers empty)@@ -4580,6 +4581,51 @@ int main(int argc, char **argv) try {return 1;}prefilled = (int64_t) fills.size();+ if (std::getenv("STRATA_VERIFY_ALL_SLOTS") != nullptr) { // debug: every filled slot read back and compared with the GGUF+ auto fl = std::make_shared<std::vector<Fill>>(fills);+ verify_all_slots = [&, fl, blob_cap](const char* when) {+ sycl::queue& vq = dpct::get_in_order_queue();+ vq.wait();+ std::vector<uint8_t> want_b(blob_cap), got_b(blob_cap);+ int64_t bad = 0, first_bad = -1;+ for (size_t i = 0; i < fl->size(); ++i) {+ const Fill& f = (*fl)[i];+ const size_t nb = (size_t) lay.blob_bytes(f.l);+ if (!gguf_src.read_into(f.l, f.e, want_b.data(), blob_cap)) { ++bad; continue; }+ vq.memcpy(got_b.data(), xcache.device_slot(f.slot), nb).wait();+ if (std::memcmp(want_b.data(), got_b.data(), nb) != 0) {+ if (first_bad < 0) first_bad = (int64_t) i;+ ++bad;+ size_t nd = 0, fd = nb, ld = 0;+ for (size_t x = 0; x < nb; ++x)+ if (want_b[x] != got_b[x]) { ++nd; if (fd == nb) fd = x; ld = x; }+ if (std::getenv("STRATA_VERIFY_FIND") != nullptr && bad <= 2 && fd + 4160 < nb) { // whose blob is the wrong data?+ const uint8_t* probe = got_b.data() + fd + 4096;+ std::vector<uint8_t> other(blob_cap);+ for (size_t j = 0; j < fl->size(); ++j) {+ const Fill& g2 = (*fl)[j];+ if (!gguf_src.read_into(g2.l, g2.e, other.data(), blob_cap)) continue;+ const size_t nb2 = (size_t) lay.blob_bytes(g2.l);+ const void* hit = memmem(other.data(), nb2, probe, 64);+ if (hit != nullptr)+ std::fprintf(stderr, " the wrong data at byte %zu is expert (layer %d, expert %d), slot %d (fill %zu), byte %zu of its blob\n",+ fd + 4096, (int) g2.l, (int) g2.e, (int) g2.slot, j, (size_t) ((const uint8_t*) hit - other.data()));+ }+ }+ if (const char* dd = std::getenv("STRATA_VERIFY_DUMP"); dd != nullptr && bad == 1) {+ const std::string base = std::string(dd) + "/slot" + std::to_string(f.slot);+ if (FILE* fo = std::fopen((base + ".got").c_str(), "wb")) { std::fwrite(got_b.data(), 1, nb, fo); std::fclose(fo); }+ if (FILE* fo = std::fopen((base + ".want").c_str(), "wb")) { std::fwrite(want_b.data(), 1, nb, fo); std::fclose(fo); }+ }+ std::fprintf(stderr, "strata generate: STRATA_VERIFY_ALL_SLOTS (%s): fill %zu (layer %d expert %d) slot %d at %p: %zu of %zu bytes differ, first at %zu, last at %zu\n",+ when, i, (int) f.l, (int) f.e, (int) f.slot, (const void*) xcache.device_slot(f.slot), nd, nb, fd, ld);+ }+ }+ std::fprintf(stderr, "strata generate: STRATA_VERIFY_ALL_SLOTS (%s): %lld of %zu slots differ from the GGUF (first at fill %lld)\n",+ when, (long long) bad, fl->size(), (long long) first_bad);+ };+ verify_all_slots("after the fill");+ }}// #286: an unbuffered file tier reads the pairs in batches of 64, the next batch while this one is copiedstd::future<void> ahead;@@ -5113,6 +5159,7 @@ int main(int argc, char **argv) try {mem_mark("the expert cache and the graphs");std::fprintf(stderr, "strata generate: session is up (engine %s)\n", STRATA_VERSION);+ if (verify_all_slots) verify_all_slots("session up");auto run_head = [&](void* stream) -> bool {if (!native_head.loaded())return strata::core::lm_head(wt, g, ss.block, d_logits, stream, err);