device_memory.cpp¶
src/inference/device_memory.cpp
@file device_memory.cpp @brief gh#142: ggml-backed free-VRAM query.
Owners: @tvanfossen
device_memory_query_count
uint64_t entropic::device_memory_query_count()
How many device free-VRAM queries this process has made (gh#198).
src/inference/device_memory.cpp:84
Source · 3 lines
uint64_t device_memory_query_count() {
return s_query_count.load(std::memory_order_relaxed);
}Activity · 1 steps
Requirements
host_memlock_limit_bytes
uint64_t entropic::host_memlock_limit_bytes()
This process's RLIMIT_MEMLOCK soft limit (gh#148).
src/inference/device_memory.cpp:69
Source · 8 lines
uint64_t host_memlock_limit_bytes() {
struct rlimit rl {};
if (getrlimit(RLIMIT_MEMLOCK, &rl) != 0
|| rl.rlim_cur == RLIM_INFINITY) {
return kMemlockUnlimited;
}
return static_cast<uint64_t>(rl.rlim_cur);
}Activity · 4 steps
Requirements
query_device_free_vram_bytes
uint64_t entropic::query_device_free_vram_bytes()
Free VRAM on the first GPU device ggml reports, in bytes.
src/inference/device_memory.cpp:41
Called by fit_context_length, resolve_auto_for_backend_test, resolve_vram_budget_bytes, sample_pre_load_vram
Calls none
Source · 17 lines
uint64_t query_device_free_vram_bytes() {
s_query_count.fetch_add(1, std::memory_order_relaxed);
ggml_backend_dev_t device =
ggml_backend_dev_by_type(GGML_BACKEND_DEVICE_TYPE_GPU);
if (device == nullptr) {
logger->info("[residency] no GPU device registered — "
"VRAM budget unknown, admission gate disabled");
return 0;
}
size_t free_bytes = 0;
size_t total_bytes = 0;
ggml_backend_dev_memory(device, &free_bytes, &total_bytes);
logger->info("[residency] device '{}' reports {} MiB free of {} MiB total",
ggml_backend_dev_name(device),
free_bytes / (1024 * 1024), total_bytes / (1024 * 1024));
return static_cast<uint64_t>(free_bytes);
}