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++
Thread names: the Windows half lives in pool.cpp, not in a header every engine file includes
Niko12218c41d3611c62
diff --git a/include/strata/platform/thread_name.hpp b/include/strata/platform/thread_name.hppindex ec97533a4..4eb6a412d 100644--- a/include/strata/platform/thread_name.hpp+++ b/include/strata/platform/thread_name.hpp@@ -1,44 +1,42 @@// strata/platform/thread_name.hpp - names the engine's long-lived threads, so that a person (or a script) can tell the// pool workers from the host thread and the helpers when looking at where they run: Linux `ps -L -o tid,psr,comm` and// /proc/<pid>/task/<tid>/comm, Windows GetThreadDescription (Process Explorer, WinDbg, the tools/ probes).-// A name changes nothing the thread does. Header-only: the callers sit in several libraries that do not link each other.+// A name changes nothing the thread does.+//+// Linux and macOS: header-only. Windows: the function is defined in src/kernels/cpu/pool.cpp, because that file already+// includes <windows.h> and this header must not pull it into every file that includes aux_cpus.hpp (its macros, and+// WIN32_LEAN_AND_MEAN, change what those files see). The callers on Windows are the ones that link strata_kernels_cpu.#pragma once-#include <cstdio>--#if defined(_WIN32)-#ifndef WIN32_LEAN_AND_MEAN-#define WIN32_LEAN_AND_MEAN-#endif-#include <windows.h>-#elif defined(__linux__) || defined(__APPLE__)+#if defined(__linux__) || defined(__APPLE__)#include <pthread.h>++#include <cstdio>#endifnamespace strata::platform {/// Gives the calling thread a name: "strata-pool-3" for `name_this_thread("strata-pool", 3)`, "strata-host" for no index./// Linux keeps 15 characters, the rest is cut. Never fails loudly: a system that cannot name a thread leaves it unnamed.+#if defined(_WIN32)+void name_this_thread(const char* base, int index = -1);+#elseinline void name_this_thread(const char* base, int index = -1) {+#if defined(__linux__) || defined(__APPLE__)char name[64];if (index >= 0) std::snprintf(name, sizeof name, "%s-%d", base, index);else std::snprintf(name, sizeof name, "%s", base);-#if defined(_WIN32)- // SetThreadDescription (Windows 10 1607 and later) is looked up, not linked: older SDKs and toolchains lack the import- using SetDesc = HRESULT(WINAPI*)(HANDLE, PCWSTR);- static const SetDesc fn = (SetDesc) GetProcAddress(GetModuleHandleW(L"kernel32.dll"), "SetThreadDescription");- if (fn == nullptr) return;- wchar_t wide[64];- int i = 0;- for (; name[i] != '\0' && i < 63; ++i) wide[i] = (wchar_t) (unsigned char) name[i];- wide[i] = L'\0';- (void) fn(GetCurrentThread(), wide);-#elif defined(__linux__)+#if defined(__linux__)name[15] = '\0';(void) pthread_setname_np(pthread_self(), name);-#elif defined(__APPLE__)+#else(void) pthread_setname_np(name);#endif+#else+ (void) base;+ (void) index;+#endif}+#endif} // namespace strata::platformdiff --git a/src/kernels/cpu/pool.cpp b/src/kernels/cpu/pool.cppindex 6bc56e8e7..bb7d24898 100644--- a/src/kernels/cpu/pool.cpp+++ b/src/kernels/cpu/pool.cpp@@ -1446,3 +1446,23 @@ void ExpertPool::run(ExpertJob* jobs, int n) {}} // namespace strata::kernels::cpu++#if defined(_WIN32)+// strata/platform/thread_name.hpp: the Windows half lives here, where <windows.h> is already included. SetThreadDescription+// (Windows 10 1607 and later) is looked up, not linked: older SDKs and toolchains lack the import.+namespace strata::platform {+void name_this_thread(const char* base, int index) {+ char name[64];+ if (index >= 0) std::snprintf(name, sizeof name, "%s-%d", base, index);+ else std::snprintf(name, sizeof name, "%s", base);+ using SetDesc = HRESULT(WINAPI*)(HANDLE, PCWSTR);+ static const SetDesc fn = (SetDesc) GetProcAddress(GetModuleHandleW(L"kernel32.dll"), "SetThreadDescription");+ if (fn == nullptr) return;+ wchar_t wide[64];+ int i = 0;+ for (; name[i] != '\0' && i < 63; ++i) wide[i] = (wchar_t) (unsigned char) name[i];+ wide[i] = L'\0';+ (void) fn(GetCurrentThread(), wide);+}+} // namespace strata::platform+#endifdiff --git a/src/ngram/ple_reader.cpp b/src/ngram/ple_reader.cppindex 97b45ac45..9d2a05051 100644--- a/src/ngram/ple_reader.cpp+++ b/src/ngram/ple_reader.cpp@@ -364,7 +364,7 @@ bool PleReader::open(const std::string& path, uint64_t table_offset, uint64_t n_impl_->threaded = io_thread;if (io_thread) {try {- impl_->worker = std::thread([this] { strata::platform::name_this_thread("strata-ple"); strata::aux_cpus::pin_current_thread(); impl_->worker_loop(); });+ impl_->worker = std::thread([this] { strata::aux_cpus::pin_current_thread(); impl_->worker_loop(); });} catch (const std::exception& e) {err = std::string("PleReader: cannot create I/O worker: ") + e.what();close();diff --git a/src/platform/direct_file.cpp b/src/platform/direct_file.cppindex d3a0ede91..b09536c28 100644--- a/src/platform/direct_file.cpp+++ b/src/platform/direct_file.cpp@@ -185,7 +185,7 @@ bool DirectFile::open(const std::string& path, std::string& err) {// Completions of reads that finish synchronously are still queued to the port, so every issued read// produces exactly one packet; `wait` is the only completion path.const int n = io_threads(4);- for (int i = 0; i < n; ++i) impl_->pool.emplace_back([this] { strata::platform::name_this_thread("strata-dio"); strata::aux_cpus::pin_current_thread(); impl_->worker(); });+ for (int i = 0; i < n; ++i) impl_->pool.emplace_back([this] { strata::aux_cpus::pin_current_thread(); impl_->worker(); });return true;}@@ -317,7 +317,7 @@ bool DirectFile::open(const std::string& path, std::string& err) {if (fstat(impl_->fd, &st) != 0) { err = "DirectFile: cannot size " + path; close(); return false; }impl_->size = (uint64_t) st.st_size;const int n = io_threads(16);- for (int i = 0; i < n; ++i) impl_->pool.emplace_back([this] { strata::platform::name_this_thread("strata-dio"); strata::aux_cpus::pin_current_thread(); impl_->worker(); });+ for (int i = 0; i < n; ++i) impl_->pool.emplace_back([this] { strata::aux_cpus::pin_current_thread(); impl_->worker(); });return true;}