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++
macOS platform guards in the host files (C2): every host source under src/ now compiles for Metal
Niko1221f1c5a6772ccd
diff --git a/src/core/expert_source.cpp b/src/core/expert_source.cppindex ad28f56f8..b11899f5e 100644--- a/src/core/expert_source.cpp+++ b/src/core/expert_source.cpp@@ -45,6 +45,9 @@#include <windows.h>#else#include <fcntl.h>+#if defined(__APPLE__)+#include <mach/mach.h> // host_statistics64: the available memory+#endif#include <sys/mman.h>#include <sys/stat.h>#include <unistd.h>@@ -411,6 +414,16 @@ bool host_available_memory(HostMemory& m, const std::string& meminfo, const std:}m.available = bytes;return true;+#elif defined(__APPLE__)+ // macOS: free + inactive + purgeable pages (what the OS can hand out without swapping), as vm_stat reports them+ (void) meminfo; (void) self_cgroup; (void) cgroup_root;+ vm_statistics64_data_t vs{};+ mach_msg_type_number_t count = HOST_VM_INFO64_COUNT;+ vm_size_t page_bytes = 0;+ if (host_page_size(mach_host_self(), &page_bytes) != KERN_SUCCESS ||+ host_statistics64(mach_host_self(), HOST_VM_INFO64, (host_info64_t) &vs, &count) != KERN_SUCCESS) return false;+ m.available = ((uint64_t) vs.free_count + vs.inactive_count + vs.purgeable_count) * (uint64_t) page_bytes;+ return m.available > 0;#else(void) meminfo; (void) self_cgroup; (void) cgroup_root;const long pages = sysconf(_SC_AVPHYS_PAGES);@@ -3107,10 +3120,12 @@ bool FileExpertSource::pin_cache_complement(fail("FileExpertSource: madvise could not release mapped expert layer " + std::to_string(layer));return;}+#if !defined(__APPLE__) // macOS has no posix_fadvise; the madvise above already released the mappingif (posix_fadvise(fd_, (off_t) layer_offset, (off_t) layer_bytes, POSIX_FADV_DONTNEED) != 0) {fail("FileExpertSource: posix_fadvise could not release expert layer " + std::to_string(layer));return;}+#endif}#endifconst int64_t done = layers_done.fetch_add(1) + 1;diff --git a/src/core/vmm.cpp b/src/core/vmm.cppindex e69d2b886..2ae5af6af 100644--- a/src/core/vmm.cpp+++ b/src/core/vmm.cpp@@ -1,6 +1,6 @@#include "strata/core/vmm.hpp"-#if !defined(STRATA_USE_HIP) && !defined(STRATA_HIP_GFX906)+#if !defined(STRATA_USE_HIP) && !defined(STRATA_HIP_GFX906) && !defined(STRATA_GPU_METAL)#include <cuda.h>#include <cuda_runtime.h>diff --git a/src/platform/direct_file.cpp b/src/platform/direct_file.cppindex 5f8d99624..b09536c28 100644--- a/src/platform/direct_file.cpp+++ b/src/platform/direct_file.cpp@@ -306,7 +306,12 @@ DirectFile::~DirectFile() { close(); delete impl_; }bool DirectFile::open(const std::string& path, std::string& err) {close();+#if defined(__APPLE__) // macOS has no O_DIRECT: F_NOCACHE keeps the reads out of the unified buffer cache+ impl_->fd = ::open(path.c_str(), O_RDONLY);+ if (impl_->fd >= 0 && fcntl(impl_->fd, F_NOCACHE, 1) != 0) { ::close(impl_->fd); impl_->fd = -1; }+#elseimpl_->fd = ::open(path.c_str(), O_RDONLY | O_DIRECT);+#endifif (impl_->fd < 0) { err = "DirectFile: cannot open " + path; return false; }struct stat st;if (fstat(impl_->fd, &st) != 0) { err = "DirectFile: cannot size " + path; close(); return false; }diff --git a/src/platform/memory.cpp b/src/platform/memory.cppindex c9f2a512a..4180bdf07 100644--- a/src/platform/memory.cpp+++ b/src/platform/memory.cpp@@ -166,7 +166,14 @@ void advise_willneed(const void* p, uint64_t bytes) {void advise_willneed(int fd, uint64_t offset, uint64_t bytes) {if (fd < 0 || !read_ahead_enabled()) return;for (uint64_t at = 0; at < bytes; at += kAdviseStep)+#if defined(__APPLE__) // macOS: F_RDADVISE is the read-ahead hint+ {+ radvisory ra{(off_t) (offset + at), (int) std::min(kAdviseStep, bytes - at)};+ (void) fcntl(fd, F_RDADVISE, &ra);+ }+#else(void) posix_fadvise(fd, (off_t) (offset + at), (off_t) std::min(kAdviseStep, bytes - at), POSIX_FADV_WILLNEED);+#endif}#endifdiff --git a/src/prefill/prefill.cpp b/src/prefill/prefill.cppindex d13fdd197..6c8672531 100644--- a/src/prefill/prefill.cpp+++ b/src/prefill/prefill.cpp@@ -1033,8 +1033,8 @@ struct MoeBufs { size_t gu, h, xq, hq; };MoeBufs moe_bufs(size_t T, int64_t n_expert, bool fused) {if (!fused) return {T * K * 1280, T * K * 640, mmq::q8_bytes((int64_t) (T * K), N), mmq::q8_bytes((int64_t) (T * K), 640)};const size_t ts = (size_t) std::min<int64_t>((int64_t) T, stream_all_min() - 1); // MMQ's last small chunk- return {std::max(ts * K * 1280, (fused::group_bytes((int64_t) (T * K), (int) n_expert) + 3) / 4),- std::max(ts * K * 640, (fused::act_bytes((int64_t) (T * K), 640) + 3) / 4),+ return {std::max<size_t>(ts * K * 1280, (fused::group_bytes((int64_t) (T * K), (int) n_expert) + 3) / 4),+ std::max<size_t>(ts * K * 640, (fused::act_bytes((int64_t) (T * K), 640) + 3) / 4),std::max(mmq::q8_bytes((int64_t) (ts * K), N), fused::act_bytes((int64_t) T, N)),mmq::q8_bytes((int64_t) (ts * K), 640)};}diff --git a/src/program/generate.cpp b/src/program/generate.cppindex b1ffd9439..649cdbdf5 100644--- a/src/program/generate.cpp+++ b/src/program/generate.cpp@@ -92,8 +92,10 @@#include <unistd.h>#include <cerrno>#include <sys/stat.h>+#if !defined(__APPLE__) // major() / minor(): <sys/types.h> on macOS#include <sys/sysmacros.h>#endif+#endif#include <cuda_runtime.h>@@ -4651,7 +4653,7 @@ int main(int argc, char** argv) {std::fprintf(stderr, "strata generate: GPU %d: %s, compute capability %d.%d%s\n", dev, name,strata::cc_major_of(p.major), strata::cc_minor_of(p.minor),strata::emulated_cc() ? " (STRATA_EMULATE_CC: a test mode, the card is emulated)" : "");-#if !defined(STRATA_HIP_GFX906) // a CUDA toolkit mismatch; the gfx906 HIP build has no CUDART_VERSION+#if !defined(STRATA_HIP_GFX906) && !defined(STRATA_GPU_METAL) // a CUDA toolkit mismatch; the gfx906 HIP build has no CUDART_VERSION{ // #542: a build whose libcudart is older than its headers (a CUDA 13 kit with a dangling libcudart.so that// CMake resolved to the system's CUDA 12 one) reads cudaDeviceProp shifted - silently, and slowlyint rt = 0;