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

core: device_free_bytes caches the unified-memory check per device (#409 review), not in a process-wide static

Niko12218a0755a1da3a
diff --git a/src/core/expert_cache.cpp b/src/core/expert_cache.cpp
index 5eacb0eff..fed6c43a2 100644
--- a/src/core/expert_cache.cpp
+++ b/src/core/expert_cache.cpp
@@ -13,6 +13,7 @@
#endif
#include <algorithm>
+#include <atomic>
#include <cstdio>
#include <filesystem>
#include <cstdlib>
@@ -28,10 +29,20 @@ size_t device_free_bytes() {
size_t free_b = 0, total_b = 0;
cudaMemGetInfo(&free_b, &total_b);
#if defined(__linux__)
- static const bool unified_memory = [] {
+ // 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
+ bool unified_memory = false;
+ {
int dev = 0, v = 0;
- return cudaGetDevice(&dev) == cudaSuccess && cudaDeviceGetAttribute(&v, cudaDevAttrIntegrated, dev) == cudaSuccess && v;
- }();
+ if (cudaGetDevice(&dev) == cudaSuccess && dev >= 0 && dev < 64) {
+ int c = uma_cache[dev].load(std::memory_order_acquire);
+ if (c == 0) {
+ c = cudaDeviceGetAttribute(&v, cudaDevAttrIntegrated, dev) == cudaSuccess && v ? 1 : 2;
+ uma_cache[dev].store(c, std::memory_order_release);
+ }
+ unified_memory = c == 1;
+ }
+ }
if (unified_memory) {
if (FILE* m = std::fopen("/proc/meminfo", "r")) {
char line[256];