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

Show on the map →

Called by SCENARIO

Calls none

Source · 3 lines
uint64_t device_memory_query_count() {
    return s_query_count.load(std::memory_order_relaxed);
}
Activity · 1 steps
lines 85–85return s_query_count.load(std::memory_order_relaxed);

Requirements

REQ-INFER-019

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
lines 70–70struct rlimit rl {};lines 71–72◇ if (getrlimit(RLIMIT_MEMLOCK, &rl) != 0 || rl.rlim_cur == RLIM_INFINITY)lines 73–73return kMemlockUnlimited;lines 75–75return static_cast<uint64_t>(rl.rlim_cur);

Requirements

REQ-INFER-019

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

Show on the map →

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);
}
Activity · 10 steps
lines 42–42s_query_count.fetch_add(1, std::memory_order_relaxed);lines 43–44ggml_backend_dev_t device = ggml_backend_dev_by_type(GGML_BACKEND_DEVICE_TYPE_GPU);lines 45–45◇ if (device == nullptr)lines 46–47logger->info("[residency] no GPU device registered — " "VRAM budget unknown, admission gate disabled");lines 48–48return 0;lines 50–50size_t free_bytes = 0;lines 51–51size_t total_bytes = 0;lines 52–52ggml_backend_dev_memory(device, &free_bytes, &total_bytes);lines 53–55logger->info("[residency] device '{}' reports {} MiB free of {} MiB total", ggml_backend_dev_name(device), free_bytes / (1024 * 1024), total_bytes / (1024 * 1024));lines 56–56return static_cast<uint64_t>(free_bytes);

Requirements

REQ-INFER-019