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: host memory a kernel polls comes from zeMemAllocHost BIAS_UNCACHED; null-allocation checks
Niko12210d4e82c6d8a9
diff --git a/sycl/CMakeLists.txt b/sycl/CMakeLists.txtindex bee31fe40..37c5d0f6c 100644--- a/sycl/CMakeLists.txt+++ b/sycl/CMakeLists.txt@@ -161,6 +161,11 @@ strata_resolve(_core src/core/device.cu src/core/pinned.cu src/platform/memory.csrc/core/weights.cpp src/core/layout.cpp)add_library(strata_core STATIC ${_core})target_link_libraries(strata_core PUBLIC strata_includes)+# zeMemAllocHost for the host memory a kernel polls (include/strata/sycl_queue.hpp, host_malloc_polled): only when libze-dev's header is there+find_library(STRATA_ZE_LOADER ze_loader)+if(STRATA_ZE_LOADER)+ target_link_libraries(strata_core PUBLIC ${STRATA_ZE_LOADER})+endif()set(_kernel_cu dequant_s2 s2_gemv s_gemv s2_gemv_quads s2_gemv_fast router_top10 quantize_act rope sampler s2_gemv_q8s2_expert_grouped shared_expert gr gdn qsa elementwise bf16_gemv native_mmvq native_bf16 native_gr_norm native_moediff --git a/sycl/include/strata/sycl_queue.hpp b/sycl/include/strata/sycl_queue.hppindex b272efb77..6a221901f 100644--- a/sycl/include/strata/sycl_queue.hpp+++ b/sycl/include/strata/sycl_queue.hpp@@ -35,3 +35,55 @@ inline void big_fill_zero(sycl::queue& q, void* p, size_t bytes, size_t chunk =}}} // namespace strata++// ---- host memory a running kernel polls for the host's stores (the doorbell flags, the CPU experts' result rows).+// On an Arc A750 (Alchemist, i915) a kernel never sees a host store to ordinary host USM, with or without+// system-scope atomics: every ring wait runs to its bound and the window reads stale rows (NaN logits). Host memory+// from zeMemAllocHost with ZE_HOST_MEM_ALLOC_FLAG_BIAS_UNCACHED does work there (sycl/probe/doorbell.cpp mode 2,+// "HANDSHAKE OK"), so those buffers come from it when the Level Zero headers are present (libze-dev), else from+// sycl::malloc_host. STRATA_HOST_UNCACHED=0 turns it off.+#if defined(__has_include)+#if __has_include(<level_zero/ze_api.h>) && __has_include(<sycl/ext/oneapi/backend/level_zero.hpp>)+#include <level_zero/ze_api.h>+#include <sycl/ext/oneapi/backend/level_zero.hpp>+#define STRATA_HAVE_ZE 1+#endif+#endif+#include <cstdlib>+#include <mutex>+#include <unordered_set>+namespace strata {+namespace detail {+inline std::unordered_set<void*>& uncached_set() { static std::unordered_set<void*> s; return s; }+inline std::mutex& uncached_mu() { static std::mutex m; return m; }+} // namespace detail+inline void* host_malloc_polled(size_t bytes, sycl::queue& q) {+#ifdef STRATA_HAVE_ZE+ static const bool on = [] { const char* v = std::getenv("STRATA_HOST_UNCACHED"); return !(v && v[0] == '0'); }();+ if (on && q.get_backend() == sycl::backend::ext_oneapi_level_zero) {+ auto ctx = sycl::get_native<sycl::backend::ext_oneapi_level_zero>(q.get_context());+ ze_host_mem_alloc_desc_t d{ZE_STRUCTURE_TYPE_HOST_MEM_ALLOC_DESC, nullptr, ZE_HOST_MEM_ALLOC_FLAG_BIAS_UNCACHED};+ void* p = nullptr;+ if (zeMemAllocHost(ctx, &d, bytes, 64, &p) == ZE_RESULT_SUCCESS && p != nullptr) {+ std::lock_guard<std::mutex> lk(detail::uncached_mu());+ detail::uncached_set().insert(p);+ return p;+ }+ }+#endif+ return sycl::malloc_host(bytes, q);+}+inline void host_free_polled(void* p, sycl::queue& q) {+ if (p == nullptr) return;+#ifdef STRATA_HAVE_ZE+ {+ std::lock_guard<std::mutex> lk(detail::uncached_mu());+ if (detail::uncached_set().erase(p)) {+ zeMemFree(sycl::get_native<sycl::backend::ext_oneapi_level_zero>(q.get_context()), p);+ return;+ }+ }+#endif+ sycl::free(p, q);+}+} // namespace stratadiff --git a/sycl/src/core/expert_cache.cpp b/sycl/src/core/expert_cache.cppindex cd1d50dbc..9d3697131 100644--- a/sycl/src/core/expert_cache.cpp+++ b/sycl/src/core/expert_cache.cpp@@ -596,7 +596,9 @@ bool ExpertCache::open(int64_t n_slots, int64_t n_layers, int64_t n_expert, int6vmm_ = std::move(r);} else if (DPCT_CHECK_ERROR(base_ = (uint8_t *)sycl::malloc_device(- (size_t)want, dpct::get_in_order_queue())) != 0) {+ (size_t)want, dpct::get_in_order_queue())) != 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;char buf[256];std::snprintf(diff --git a/sycl/src/core/mtp.cpp b/sycl/src/core/mtp.cppindex 56eaed0e2..8b535686a 100644--- a/sycl/src/core/mtp.cpp+++ b/sycl/src/core/mtp.cpp@@ -757,7 +757,8 @@ bool MtpDrafter::bind(const WeightTable &wt, const NativeHead *head,0 ||DPCT_CHECK_ERROR(dhead_ = (uint8_t *)sycl::malloc_device((size_t)(n_dvocab_ * row_bytes),- dpct::get_in_order_queue())) != 0) {+ dpct::get_in_order_queue())) != 0 ||+ dvocab_ == nullptr || dhead_ == nullptr) { // Level Zero returns null when the VRAM is fullerr = "mtp: the draft head does not fit";draft_head_hint(n_dvocab_, row_bytes);return false;diff --git a/sycl/src/core/session.cpp b/sycl/src/core/session.cppindex ecb690441..59fc6c729 100644--- a/sycl/src/core/session.cpp+++ b/sycl/src/core/session.cpp@@ -764,8 +764,8 @@ bool SessionLoopScratch::init(size_t parts_bytes_in, std::string &err) try {the migrated code and was removed or replaced with 0. You may need to checkthe migrated code.*/- if (DPCT_CHECK_ERROR(y_miss = (float *)sycl::malloc_host(- parts_bytes, dpct::get_in_order_queue())) != 0) {+ if (DPCT_CHECK_ERROR(y_miss = (float *)strata::host_malloc_polled(+ parts_bytes, dpct::get_in_order_queue())) != 0 || y_miss == nullptr) {err = "SessionLoopScratch: cudaHostAlloc for the pool's staging failed";return false;}@@ -811,7 +811,7 @@ void SessionLoopScratch::free() {}if (probe != nullptr) { dpct::destroy_event(probe); probe = nullptr; }if (y_miss != nullptr) {- sycl::free(y_miss, dpct::get_in_order_queue()); y_miss = nullptr;+ strata::host_free_polled(y_miss, dpct::get_in_order_queue()); y_miss = nullptr;}parts_bytes = 0;}diff --git a/sycl/src/core/verify.cpp b/sycl/src/core/verify.cppindex f0fc2a2e4..73f004170 100644--- a/sycl/src/core/verify.cpp+++ b/sycl/src/core/verify.cpp@@ -151,9 +151,9 @@ bool mapped(size_t bytes, void **h, void **d) try {migrated code and was removed or replaced with 0. You may need to check themigrated code.*/- if (DPCT_CHECK_ERROR(*h = (void *)sycl::malloc_host(+ if (DPCT_CHECK_ERROR(*h = strata::host_malloc_polled(bytes, dpct::get_in_order_queue())) !=- 0) return false;+ 0 || *h == nullptr) return false; // polled by the window's kernels: uncached host memory (sycl_queue.hpp)std::memset(*h, 0, bytes);return DPCT_CHECK_ERROR(*d = (void *)*h) == 0;}@@ -372,7 +372,7 @@ Verifier::~Verifier() try {void* hosts[] = {h_tok_, h_step_, h_pos_, h_commit_, h_ple_, h_out_, h_x_, h_ids_, h_w_, h_seq_, h_flag_, h_ymiss_,h_flagA_, h_plan_, h_flagB_, h_plan_err_};for (void* h : hosts)- if (h) sycl::free(h, dpct::get_in_order_queue());+ if (h) strata::host_free_polled(h, dpct::get_in_order_queue());} catch (...) {}diff --git a/sycl/src/kernels/cuda/verify_kernels.dp.cpp b/sycl/src/kernels/cuda/verify_kernels.dp.cppindex 69f6d12ad..957b8d0e8 100644--- a/sycl/src/kernels/cuda/verify_kernels.dp.cpp+++ b/sycl/src/kernels/cuda/verify_kernels.dp.cpp@@ -1177,7 +1177,7 @@ void gather_rows(const uint8_t* src, int64_t row_bytes, const int32_t* ids, int6sycl::nd_range<3>(sycl::range(1, 1, 48 * 8) *sycl::range(1, 1, 256),sycl::range(1, 1, 256)),- exp_props, [=](sycl::nd_item<3> item_ct1) {+ [=](sycl::nd_item<3> item_ct1) {gather_rows_kernel((const sycl::uint4 *)src, row_bytes_ct1,ids, n, (sycl::uint4 *)dst);});@@ -1195,7 +1195,7 @@ void gather_rows(const uint8_t* src, int64_t row_bytes, const int32_t* ids, int6sycl::nd_range<3>(sycl::range(1, 1, 48 * 8) *sycl::range(1, 1, 256),sycl::range(1, 1, 256)),- exp_props, [=](sycl::nd_item<3> item_ct1) {+ [=](sycl::nd_item<3> item_ct1) {gather_rows_kernel((const uint32_t *)src, row_bytes_ct1,ids, n, (uint32_t *)dst);});@@ -1209,7 +1209,7 @@ void gather_rows(const uint8_t* src, int64_t row_bytes, const int32_t* ids, int6sycl::nd_range<3>(sycl::range(1, 1, 48 * 8) *sycl::range(1, 1, 256),sycl::range(1, 1, 256)),- exp_props, [=](sycl::nd_item<3> item_ct1) {+ [=](sycl::nd_item<3> item_ct1) {gather_rows_kernel(src, row_bytes, ids, n, dst);});}diff --git a/sycl/src/program/generate.cpp b/sycl/src/program/generate.cppindex 511a5efd0..84fe7766e 100644--- a/sycl/src/program/generate.cpp+++ b/sycl/src/program/generate.cpp@@ -4390,9 +4390,7 @@ int main(int argc, char **argv) try {return 1;}if (!auto_cache || attempt - failed >= 6) break;- dpct::get_in_order_queue()- .memset(xcache.device_slot(0), 0, (size_t)xcache.bytes())- .wait();+ if (uint8_t* slot0 = xcache.device_slot(0)) strata::big_fill_zero(dpct::get_in_order_queue(), slot0, (size_t)xcache.bytes());dpct::get_current_device().queues_wait_and_throw();size_t free_b = 0, total_b = 0;free_b = strata::core::device_free_bytes(); (void) total_b;