Entropic 2.14.3
Local-first agentic inference engine
Loading...
Searching...
No Matches
device_memory.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
8#include "device_memory.h"
9
11
12#include <ggml-backend.h>
13
14#include "partial_offload.h" // kMemlockUnlimited
15
16#include <sys/resource.h>
17
18#include <atomic>
19
20namespace {
21auto logger = entropic::log::get("inference.device_memory");
22
24std::atomic<uint64_t> s_query_count{0};
25} // namespace
26
27namespace entropic {
28
42 s_query_count.fetch_add(1, std::memory_order_relaxed);
45 if (device == nullptr) {
46 logger->info("[residency] no GPU device registered — "
47 "VRAM budget unknown, admission gate disabled");
48 return 0;
49 }
50 size_t free_bytes = 0;
51 size_t total_bytes = 0;
53 logger->info("[residency] device '{}' reports {} MiB free of {} MiB total",
55 free_bytes / (1024 * 1024), total_bytes / (1024 * 1024));
56 return static_cast<uint64_t>(free_bytes);
57}
58
70 struct rlimit rl {};
71 if (getrlimit(RLIMIT_MEMLOCK, &rl) != 0
72 || rl.rlim_cur == RLIM_INFINITY) {
73 return kMemlockUnlimited;
74 }
75 return static_cast<uint64_t>(rl.rlim_cur);
76}
77
85 return s_query_count.load(std::memory_order_relaxed);
86}
87
88} // namespace entropic
gh#142: ask the GPU how much VRAM is actually free.
spdlog initialization and logger access.
ENTROPIC_EXPORT std::shared_ptr< spdlog::logger > get(const std::string &name)
Get or create a named logger.
Definition logging.cpp:211
Activate model on GPU (WARM → ACTIVE).
uint64_t host_memlock_limit_bytes()
This process's RLIMIT_MEMLOCK soft limit (gh#148).
@ optional
optional: every escape asks the host's path approver
constexpr uint64_t kMemlockUnlimited
Sentinel for an unlimited RLIMIT_MEMLOCK (gh#148).
uint64_t query_device_free_vram_bytes()
Free VRAM on the first GPU device ggml reports, in bytes.
uint64_t device_memory_query_count()
How many device free-VRAM queries this process has made (gh#198).
How many layers of an oversized GGUF fit the free VRAM, purely.