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++

ple: --ple-io ram: refused on Windows (no mlock), 'locked' only when mlock succeeded else 'loaded (not locked)', neutral comments + --help (review)

Andybe41a09e5bd2
diff --git a/include/strata/kernels/ngram.hpp b/include/strata/kernels/ngram.hpp
index 8e6702a2b..29698422c 100644
--- a/include/strata/kernels/ngram.hpp
+++ b/include/strata/kernels/ngram.hpp
@@ -110,8 +110,8 @@ struct PleIoOptions {
uint32_t max_inflight = 64; ///< outstanding SSD reads (decode needs 16; prefill chunks use more)
uint64_t cache_rows = 1u << 20; ///< bounded row cache: 1,048,576 rows x 90 B ~ 95 MB; 0 disables
bool io_thread = true; ///< reads submitted by a worker thread, not the caller
- /// dual-3090 (--ple-io ram): mmap mode with the whole table locked in RAM at open (a box with RAM to spare:
- /// no SSD read ever sits on the prompt or token path)
+ /// Mmap mode only (`--ple-io ram`): lock the whole mapped table in RAM at open, so no SSD read ever sits on
+ /// the prompt or token path. Needs RAM for the full table. POSIX only (mlock); `locked()` reports the outcome.
bool lock = false;
};
@@ -147,6 +147,8 @@ public:
bool open(const std::string& gguf_path, std::string& err);
void close();
bool is_open() const;
+ /// True when `PleIoOptions::lock` was asked for and mlock succeeded (false: pages only pre-touched).
+ bool locked() const;
uint64_t rows() const;
/// 16 row indices -> 2560 floats. The gathered rows are flattened HEAD-SLOWEST: row h's 160 values
diff --git a/src/kernels/ngram.cpp b/src/kernels/ngram.cpp
index d90768884..9def33097 100644
--- a/src/kernels/ngram.cpp
+++ b/src/kernels/ngram.cpp
@@ -123,6 +123,7 @@ struct PleTable::Impl {
strata::ngram::PleReader reader;
strata::ngram::PleReader::Ticket ticket;
bool pending = false;
+ bool locked = false;
uint32_t rows[PLE_N_HEADS] = {};
uint8_t raw[PLE_N_HEADS * PLE_ROW_BYTES] = {};
};
@@ -205,8 +206,11 @@ bool PleTable::open(const std::string& gguf_path, std::string& err, const PleIoO
const uintptr_t a0 = (uintptr_t) impl_->data & ~(uintptr_t) (page - 1);
const uintptr_t a1 = (uintptr_t) impl_->data + (uintptr_t) need;
madvise((void*) a0, a1 - a0, MADV_WILLNEED);
- if (mlock((const void*) a0, a1 - a0) != 0) {
- std::fprintf(stderr, "strata: PLE table mlock failed (%s): touching its pages instead\n", std::strerror(errno));
+ if (mlock((const void*) a0, a1 - a0) == 0) {
+ impl_->locked = true;
+ } else {
+ std::fprintf(stderr, "strata: PLE table mlock failed (%s; raise `ulimit -l`): touching its pages instead\n",
+ std::strerror(errno));
volatile uint8_t sink = 0;
for (uintptr_t p = a0; p < a1; p += page) sink = sink + *(const volatile uint8_t*) p;
(void) sink;
@@ -220,6 +224,7 @@ bool PleTable::open(const std::string& gguf_path, std::string& err, const PleIoO
void PleTable::close() {
impl_->reader.close();
impl_->pending = false;
+ impl_->locked = false; // the unmap below releases the lock
impl_->mode = PleIo::Mmap;
delete impl_->file;
impl_->file = nullptr;
@@ -228,6 +233,7 @@ void PleTable::close() {
}
bool PleTable::is_open() const { return impl_->data != nullptr || impl_->reader.is_open(); }
+bool PleTable::locked() const { return impl_->locked; }
PleIo PleTable::mode() const { return impl_->mode; }
uint64_t PleTable::rows() const { return impl_->n_rows; }
uint64_t PleTable::bytes_read() const { return impl_->bytes_read; }
diff --git a/src/program/generate.cpp b/src/program/generate.cpp
index 0bc03bc66..092327c0a 100644
--- a/src/program/generate.cpp
+++ b/src/program/generate.cpp
@@ -319,8 +319,9 @@ void usage() {
" --tokens-file PATH pretokenized prompt, commas or whitespace (alternative to --tokens)\n"
" --ple-gguf PATH required PLE table (original second GGUF shard)\n"
" --no-ple explicit diagnostic ablation of the PLE layer\n"
- " --ple-io direct|mmap|ram n-gram table reads (ram = mmap, locked in RAM at start); (plan v0.3 P2). direct (default): unbuffered SSD\n"
- " reads, the table never enters RAM or the file cache; mmap: A/B arm\n"
+ " --ple-io direct|mmap|ram n-gram table reads (plan v0.3 P2). direct (default): unbuffered SSD\n"
+ " reads, the table never enters RAM or the file cache; mmap: A/B arm;\n"
+ " ram: mmap with the whole table locked in RAM at start (Linux/macOS)\n"
" --ple-row-cache N bounded cache of fetched rows, 90 B each (default 1048576; 0 = off)\n"
" --ple-inflight N outstanding SSD reads (default 64)\n"
" --ple-delay-us U fault injection: each row read completes no earlier than U us\n"
@@ -1200,6 +1201,12 @@ int main(int argc, char** argv) {
std::fprintf(stderr, "strata generate: invalid --ple-io/--ple-row-cache/--ple-inflight/--ple-delay-us\n");
return 2;
}
+#if defined(_WIN32)
+ if (o.ple_io == "ram") {
+ std::fprintf(stderr, "strata generate: --ple-io ram is not available on Windows (no mlock); use --ple-io mmap\n");
+ return 2;
+ }
+#endif
if (o.kv == "q4") o.kv = "q4_0";
if (o.kv != "fp16" && o.kv != "int8" && o.kv != "q4_0" && o.kv != "k8v4") {
std::fprintf(stderr, "strata generate: --kv must be fp16, int8, q4_0 or k8v4\n");
@@ -1565,7 +1572,7 @@ int main(int argc, char** argv) {
if (!o.ple_gguf.empty()) {
strata::kernels::PleIoOptions pio;
pio.mode = o.ple_io == "mmap" || o.ple_io == "ram" ? strata::kernels::PleIo::Mmap : strata::kernels::PleIo::Direct;
- pio.lock = o.ple_io == "ram"; // dual-3090: the whole table locked in RAM
+ pio.lock = o.ple_io == "ram";
const auto tpl = Clock::now();
pio.max_inflight = (uint32_t) o.ple_inflight;
pio.cache_rows = (uint64_t) o.ple_row_cache;
@@ -1575,7 +1582,8 @@ int main(int argc, char** argv) {
return 1;
}
if (pio.lock)
- std::fprintf(stderr, "strata generate: PLE table locked in RAM (--ple-io ram) in %.1f s\n",
+ std::fprintf(stderr, "strata generate: PLE table %s (--ple-io ram) in %.1f s\n",
+ ple_table.locked() ? "locked in RAM" : "loaded (not locked)",
std::chrono::duration<double>(Clock::now() - tpl).count());
const strata::core::WeightRef* wk = wt.find("blk.1.ple_key.weight");
const strata::core::WeightRef* wv = wt.find("blk.1.ple_value.weight");