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

sycl: size from the DRM fdinfo when the driver reports the whole card free (i915); STRATA_CHUNKED_FILL=0 toggle

Niko122193b129ad61a3
diff --git a/sycl/include/strata/sycl_queue.hpp b/sycl/include/strata/sycl_queue.hpp
index 6a221901f..69a55c48e 100644
--- a/sycl/include/strata/sycl_queue.hpp
+++ b/sycl/include/strata/sycl_queue.hpp
@@ -6,6 +6,7 @@
#pragma once
#include <sycl/sycl.hpp>
#include <dpct/dpct.hpp>
+#include <cstdlib>
namespace strata {
inline sycl::queue* q_of(const void* stream) {
@@ -18,6 +19,8 @@ namespace strata {
// queue.memset of many GiB runs on the blitter engine and times out ("Engine memory CAT error", GT reset); kernels do not.
// Small fills (<= chunk) and non-multiple-of-8 tails fall back to memset.
inline void big_fill_zero(sycl::queue& q, void* p, size_t bytes, size_t chunk = (size_t)256 << 20) {
+ static const bool plain = [] { const char* v = std::getenv("STRATA_CHUNKED_FILL"); return v && v[0] == '0'; }();
+ if (plain) { q.memset(p, 0, bytes); q.wait(); return; }
uint8_t* b = (uint8_t*)p;
size_t off = 0;
while (off < bytes) {
diff --git a/sycl/src/core/expert_cache.cpp b/sycl/src/core/expert_cache.cpp
index 2a9a72e32..15515cb75 100644
--- a/sycl/src/core/expert_cache.cpp
+++ b/sycl/src/core/expert_cache.cpp
@@ -18,6 +18,7 @@
#include <algorithm>
#include <atomic>
+#include <set>
#include <cstdio>
#include <filesystem>
#include <cstdlib>
@@ -26,6 +27,42 @@
namespace strata::core {
+// Local (card) memory this process holds, from the DRM clients' fdinfo (i915: drm-total-local0, xe: drm-total-vram0).
+// Level Zero's free-memory query reads the constant total on an Arc A750 (i915): the engine then sized its caches
+// from the whole card and over-allocated (UR_RESULT_ERROR_OUT_OF_HOST_MEMORY at the first launch). Other processes'
+// memory is not in this number, so it only ever LOWERS the figure the driver gave. 0 = not available.
+static unsigned long long own_drm_local_bytes() {
+#if defined(__linux__)
+ unsigned long long total = 0;
+ std::error_code ec;
+ std::set<unsigned long long> seen; // one DRM client may appear under several fds
+ for (const auto& e : std::filesystem::directory_iterator("/proc/self/fdinfo", ec)) {
+ std::FILE* f = std::fopen(e.path().string().c_str(), "r");
+ if (f == nullptr) continue;
+ char line[256];
+ bool drm = false;
+ unsigned long long client = 0, bytes = 0;
+ while (std::fgets(line, sizeof line, f)) {
+ unsigned long long v = 0;
+ char unit[8] = {0};
+ if (std::strncmp(line, "drm-driver:", 11) == 0) drm = true;
+ else if (std::sscanf(line, "drm-client-id: %llu", &client) == 1) {}
+ else if ((std::sscanf(line, "drm-total-local0: %llu %7s", &v, unit) >= 1 ||
+ std::sscanf(line, "drm-total-vram0: %llu %7s", &v, unit) >= 1) && v > 0) {
+ const unsigned long long mul = unit[0] == 'K' ? 1024ull : unit[0] == 'M' ? 1048576ull
+ : unit[0] == 'G' ? 1073741824ull : 1ull;
+ bytes += v * mul;
+ }
+ }
+ std::fclose(f);
+ if (drm && bytes > 0 && seen.insert(client).second) total += bytes;
+ }
+ return total;
+#else
+ return 0;
+#endif
+}
+
// See the header. NVIDIA's DGX Spark Porting Guide (section 5.5, "Memory reporting on UMA systems") recommends the same:
// not to rely on cudaMemGetInfo alone but to count the memory the OS can reclaim. Swap is not counted here (unlike
// NVIDIA's reference snippet): an expert cache that pushes the system into swap would be far slower than a smaller one.
@@ -37,6 +74,13 @@ size_t device_free_bytes() try {
You may need to adjust the code.
*/
dpct::get_current_device().get_memory_info(free_b, total_b);
+ if (const unsigned long long own = own_drm_local_bytes(); own > 0 && total_b > own && total_b - own < free_b) {
+ static std::atomic<bool> said{false};
+ if (free_b + (16ull << 20) >= total_b && !said.exchange(true))
+ std::fprintf(stderr, "strata: the driver reports the whole card as free although this process holds %.2f GiB of it (Arc A750/i915 does this); sizing from the DRM fdinfo instead
+", (double) own / 1073741824.0);
+ free_b = (size_t) (total_b - own);
+ }
#if defined(__linux__) && !defined(STRATA_HIP_GFX906) // (the gfx906 compat layer has no cudaDevAttrIntegrated; that GPU is discrete)
// per device: a box can mix an integrated GPU (an APU) with a discrete one, and the answer is the CURRENT device's
static std::atomic<int> uma_cache[64]; // 0 unknown, 1 integrated (unified memory), 2 discrete