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++
prefill: refill a prompt's lent expert slots from the GGUF mapping's pieces (STRATA_REFILL_PARTS=1, gfx1151's table)
libratechwd573332130a5
diff --git a/docs/STRIX_HALO.md b/docs/STRIX_HALO.mdindex a28df535d..f01875ebc 100644--- a/docs/STRIX_HALO.md+++ b/docs/STRIX_HALO.md@@ -92,6 +92,7 @@ they change speed, not answers. Nothing here applies to CUDA or to another AMD a| `STRATA_GDN_HEAD`, `STRATA_GDN_PP=2`, `STRATA_GDN_CONVL2`, `STRATA_GDN_NOY` | the prompt's gated-delta-net recurrence: four lanes per column, two columns per lane, the convolution and the norms fused || `STRATA_HCD_EXACT` | the hyper-connection down projection (N 320, K 10240) in a WMMA kernel that reproduces hipBLASLt solution 1176 / 1177's summation order (`hip_prefill_hcd_exact_parity` checks it bit for bit); it runs only where the table makes hipBLASLt pick one of those two, and says once if it cannot || `STRATA_CVEC_FUSE`, `STRATA_PF_PAD` | a steered layer's write, control vector and next norm in one pass; padded GEMM row strides |+| `STRATA_REFILL_PARTS` | after a prompt, the expert-cache slots it borrowed are refilled straight from the GGUF mapping (an expert's gate, up and down tensors) instead of through an assembled 4 MB copy per expert: the same bytes in the slot (checked against the assembled blob on 162 slots), 0.1 to 0.3 s less at the end of a prompt || `STRATA_Q8_PACKED`, `STRATA_Q6_PACKED`, `STRATA_MMVF_ROWS`, `STRATA_ATTN_LANECELL` | decode layouts and kernels (packed Q8_0 / Q6_K weights, 4-row BF16 GEMV, one-cell-per-thread attention scores) || `STRATA_EXPERT_V2`, `STRATA_TSUM`, `STRATA_LFUSE` | the grouped decode experts (IQ3_S / IQ4_NL), single-butterfly warp sums, fewer launches around the shared expert and the KV append || `STRATA_GDN_SPLIT`, `STRATA_QFUSE`, `STRATA_PLE_BATCH` | the GDN step over four blocks per head, activation images written by their producers, the PLE key / value projections of a verify window at once |diff --git a/include/strata/core/expert_cache.hpp b/include/strata/core/expert_cache.hppindex 17e277deb..d41a4ff98 100644--- a/include/strata/core/expert_cache.hpp+++ b/include/strata/core/expert_cache.hpp@@ -78,6 +78,9 @@ bool write_expert_profile(const std::string& path, int64_t n_layers, int64_t n_e/// and the engine's host side (STRATA_UMA_HEADROOM_GIB). Elsewhere it is cudaMemGetInfo's.size_t device_free_bytes();+/// One piece of an expert blob that lives contiguously in a source's own memory: `n` bytes at `p`, to land `at` bytes into the blob.+struct BlobPart { const uint8_t* p; uint64_t n; uint64_t at; };+class ExpertCache {public:ExpertCache() = default;@@ -191,6 +194,9 @@ public:/// perf-review D-4: `fill_slot_blocking`'s copy on the same (legacy) stream, but queued: many slots are refilled/// with one `sync_queued` at the end instead of a wait per slot. Same ordering against earlier work, same bytes.bool fill_slot_queued(int32_t slot, const uint8_t* host_blob, std::string& err, int64_t bytes = 0);+ /// `fill_slot_queued` for a blob that is not in one piece: each `parts[i].n` bytes at `parts[i].p` go to byte `parts[i].at`+ /// of the slot (the pieces tile the blob). Same queue, same `sync_queued`.+ bool fill_slot_queued_parts(int32_t slot, const BlobPart* parts, int n, std::string& err);bool sync_queued(std::string& err);/// Reads `slot` back to the host and compares it to `host_blob`, byte for byte. **THE ONLY THING THAT SAYSdiff --git a/include/strata/core/expert_source.hpp b/include/strata/core/expert_source.hppindex cf5176909..7ca3be963 100644--- a/include/strata/core/expert_source.hpp+++ b/include/strata/core/expert_source.hpp@@ -170,6 +170,11 @@ public:/// A blob pointer that stays valid (not recycled) for as long as the source is open: for a copy that runs/// asynchronously long after the call (the adaptive tier's swap-ins). Defaults to `blob`.virtual const uint8_t* blob_stable(int64_t layer, int64_t expert) { return blob(layer, expert); }+ /// The pieces (up to 3) a blob consists of when the source can hand them out where they already are - the GGUF+ /// mapped in place keeps an expert's gate, up and down in three tensors - so the caller can copy each straight to+ /// its destination instead of `blob_stable` assembling a staging copy first. 0: not available for this+ /// (layer, expert) - take `blob_stable`. The pointers stay valid as long as the source is open.+ virtual int blob_parts(int64_t layer, int64_t expert, BlobPart* out) { (void) layer; (void) expert; (void) out; return 0; }/// The caller has queued an asynchronous copy out of `blob` (a pointer this source handed out) on `stream` (a/// cudaStream_t): the source must not overwrite or recycle that memory until the copy has finished. A source whose/// pointers are never recycled ignores it. (#1237: a page-locked stage buffer is read by the DMA after the copy call@@ -692,6 +697,7 @@ public:const uint8_t* blob(int64_t layer, int64_t expert) override;/// With io prefetch in the experts.bin tier, the mapping itself (blob() may hand out a recycled staging buffer).const uint8_t* blob_stable(int64_t layer, int64_t expert) override;+ int blob_parts(int64_t layer, int64_t expert, BlobPart* out) override;void note_async_read(const uint8_t* blob, void* stream) override;/// Windows, opt-in with STRATA_FILE_RELEASE=1: trim the file mapping's full pages after their expert reaches/// VRAM. Never touches the resident complement or staging buffers. Disabled by default.diff --git a/include/strata/core/remote_experts.hpp b/include/strata/core/remote_experts.hppindex d499c0315..115d1dc8f 100644--- a/include/strata/core/remote_experts.hpp+++ b/include/strata/core/remote_experts.hpp@@ -128,6 +128,9 @@ public:const uint8_t* blob_stable(int64_t layer, int64_t expert) override {return fallback_.blob_stable(layer, expert);}+ int blob_parts(int64_t layer, int64_t expert, BlobPart* out) override {+ return from_helper(layer, expert) ? 0 : fallback_.blob_parts(layer, expert, out);+ }int64_t reads() const override { return fallback_.reads(); }bool pinned(int64_t layer, int64_t expert) const override {return from_helper(layer, expert) ? false : fallback_.pinned(layer, expert);diff --git a/src/core/arch_defaults.cpp b/src/core/arch_defaults.cppindex e8ca7c9b7..59d3f6a19 100644--- a/src/core/arch_defaults.cpp+++ b/src/core/arch_defaults.cpp@@ -42,6 +42,7 @@ std::vector<std::pair<std::string, std::string>> arch_default_env(const char* gc{"STRATA_CVEC_FUSE", "1"}, // a steered layer's write, control vector and next norm in one pass (S23){"STRATA_HCD_EXACT", "1"}, // the HC down GEMM in hipBLASLt solution 1176's k order: 64K +1.8% (stream S){"STRATA_PF_PAD", "1"}, // padded GEMM row strides (acts with STRATA_PF_GEMM; inert without it) (S23)+ {"STRATA_REFILL_PARTS", "1"}, // the prompt's lent slots refilled from the GGUF mapping's pieces, not an assembled copy: same bytes, refill 217 -> 105 ms at 4K, 589 -> 322 ms at 32K// decode{"STRATA_Q8_PACKED", "1"}, // the packed Q8_0 decode layout: +2.3% (S26){"STRATA_Q6_PACKED", "1"}, // the packed Q6_K heads (S26)diff --git a/src/core/expert_cache.cpp b/src/core/expert_cache.cppindex 1920fdb7f..ecd337a65 100644--- a/src/core/expert_cache.cpp+++ b/src/core/expert_cache.cpp@@ -7,6 +7,8 @@#define STRATA_EC_NO_VMM 1#endif+#include <thread>+#include <mutex>#include <cuda_runtime.h>#if !defined(STRATA_EC_NO_VMM)#include <cuda.h> // #533: the virtual memory management types (the functions come through the runtime's entry points)@@ -737,6 +739,30 @@ bool ExpertCache::fill_slot_queued(int32_t slot, const uint8_t* host_blob, std::return true;}+bool ExpertCache::fill_slot_queued_parts(int32_t slot, const BlobPart* parts, int n, std::string& err) {+ uint8_t* dst = device_slot(slot);+ if (dst == nullptr || parts == nullptr || n <= 0) {+ err = "ExpertCache::fill_slot_queued_parts: slot outside the arena or no pieces";+ return false;+ }+ uint64_t total = 0;+ for (int i = 0; i < n; ++i) total += parts[i].n;+ if (total > (uint64_t) blob_) {+ err = "ExpertCache::fill_slot_queued_parts: the pieces are larger than a slot";+ return false;+ }+ for (int i = 0; i < n; ++i) {+ const cudaError_t e = cudaMemcpyAsync(dst + parts[i].at, parts[i].p, (size_t) parts[i].n, cudaMemcpyHostToDevice,+ (cudaStream_t) 0);+ if (e != cudaSuccess) {+ err = std::string("ExpertCache::fill_slot_queued_parts: ") + cudaGetErrorString(e);+ return false;+ }+ }+ ++fills_;+ return true;+}+bool ExpertCache::sync_queued(std::string& err) {const cudaError_t e = cudaStreamSynchronize((cudaStream_t) 0);if (e != cudaSuccess) {diff --git a/src/core/expert_source.cpp b/src/core/expert_source.cppindex 4878c1113..0965d83a4 100644--- a/src/core/expert_source.cpp+++ b/src/core/expert_source.cpp@@ -3459,6 +3459,25 @@ const uint8_t* FileExpertSource::blob_stable(int64_t layer, int64_t expert) {return blob(layer, expert);}+int FileExpertSource::blob_parts(int64_t layer, int64_t expert, BlobPart* out) {+ // the GGUF mapped in place only (three tensors per expert); the RAM copy, an exchange override, the unbuffered+ // reads, a closed mapping and the I/O prefetch (STRATA_IO_PREFETCH: it preads the ranges the page cache lacks, which a copy out+ // of the mapping would fault in one page at a time) keep going through blob(), which knows them+ if (role_ptr_.empty() || !direct_.empty() || io_pf_ || unmapped_ || base_ == nullptr || layer < 0 || expert < 0 ||+ layer >= n_layers_ || expert >= n_expert_)+ return 0;+ const size_t index = (size_t) layer * (size_t) n_expert_ + (size_t) expert;+ if (complement_ready_ && (resident_blob(index) != nullptr || (!override_.empty() && override_[index] != nullptr))) return 0;+ Span sp[3];+ const int ns = spans(layer, expert, sp);+ for (int i = 0; i < ns; ++i) out[i] = {sp[i].p, sp[i].n, sp[i].at};+ if (ns > 0) {+ file_read_bytes_.fetch_add(layer_blob_bytes_[(size_t) layer], std::memory_order_relaxed);+ ++reads_;+ }+ return ns;+}+const uint8_t* FileExpertSource::blob(int64_t layer, int64_t expert) {if (base_ == nullptr || layer < 0 || expert < 0 || layer >= n_layers_ || expert >= n_expert_) return nullptr;const size_t index = (size_t) layer * (size_t) n_expert_ + (size_t) expert;diff --git a/src/program/generate.cpp b/src/program/generate.cppindex ba00f94d7..ef8965f29 100644--- a/src/program/generate.cpp+++ b/src/program/generate.cpp@@ -11413,10 +11413,20 @@ int main(int argc, char** argv) {// through its own cache and its own device - a slot refilled into the wrong cache would leave that// stage's cache holding an expert it does not own, which is silent and produces plausible tokens.// (split in two halves so a layer split can queue every stage's copies before it waits for any: #340)+ // STRATA_REFILL_PARTS=1 (gfx1151's table): a lent slot of a GGUF read in place is refilled from the pieces in the mapping.+ // The default assembles the blob in a staging buffer first (a 4 MB copy on this thread), then copies that.+ static const bool refill_parts = [] { const char* v = std::getenv("STRATA_REFILL_PARTS"); return v != nullptr && std::atoi(v) != 0; }();auto refill_issue = [&](PfPart& p, std::string& e) -> bool {tr("refill start", (long long) p.lent.size());const strata::core::OnDevice on(p.dev);for (const auto& [i, slot] : p.lent) { // D-4: queued, one wait (STRATA_REFILL_BLOCKING=1: each)+ strata::core::BlobPart parts[3];+ const int np = refill_parts && !refill_blocking() ? srcp->blob_parts(i / g.n_expert, i % g.n_expert, parts) : 0;+ if (np > 0) { // the GGUF read in place: the tensors' pieces go from the mapping to the slot, no assembled copy+ if (!p.cache->fill_slot_queued_parts(slot, parts, np, e)) return false;+ host_res[(size_t) i] = slot;+ continue;+ }const uint8_t* b = srcp->blob_stable(i / g.n_expert, i % g.n_expert);const int64_t nb = (int64_t) strata::kernels::cpu::expert_layout().blob_bytes(i / g.n_expert);if (b == nullptr || !(refill_blocking() ? p.cache->fill_slot_blocking(slot, b, e, nb)