ggml-cuda: read sysfs VRAM usage on ROCm to fix over-reported free memory - #25123
ggml-cuda: read sysfs VRAM usage on ROCm to fix over-reported free memory#25123liminfei-amd wants to merge 1 commit into
Conversation
…mory hipMemGetInfo only counts ROCm/KFD allocations and ignores DRM graphics (Vulkan/GL/compositor) usage, so reported free VRAM is too high and auto layer offload can OOM. On HIP+linux read mem_info_vram_total/used from sysfs (matched by PCI bus id, like rocm-smi) and take min(hip, sysfs) free; fall back to hipMemGetInfo when sysfs is unavailable. Signed-off-by: liminfei-amd <91481003+liminfei-amd@users.noreply.github.com>
331ced4 to
48bdbed
Compare
|
This is similar to the local patch I have been using to circumvent the issue. I have dropped my local version and switched to this one, it seems to work similarly and resolves the issue too. However, if this is confirmed to be a bug in the |
|
I agree that this seems like a HIP bug and should be fixed there. More generally since the default margin for |
|
Agreed it is a HIP/ROCm bug. I traced it: I prototyped the fix in ROCR-Runtime ( Since that fixes it for every HIP consumer with no application change, I'll take it upstream and close this PR. Thanks for the steer toward fixing it in HIP. Upstream fix: ROCm/rocm-systems#7990 (tracking issue ROCm/rocm-systems#7993). |
|
Closing in favor of an upstream ROCm fix. Root cause is Thanks @ardfork and @JohannesGaessler for the steer toward fixing it in HIP. |
It's quite easy to have more than 1 GiB of VRAM allocated on a desktop system, meaning llama.cpp will try to use all of it. If you run llama.cpp while a video game or something similar is open, the program is completely blind to it, you could have 5 GiB free, but llama.cpp will see your total VRAM and try to overfill it. It's very annoying because, on my system, it often results in a GPU reset or a total system freeze that requires a restart. I wish there were some kind of early OOM killer for VRAM. |
|
The code is using a margin of 1 GB on top of all of the memory that is already in use. |
The whole problem that I shared in #24906 is that currently llama.cpp is unable to see the VRAM in use because Idle
With a video game running
So, fit by default will try to fit more than what's available. The sysfs source reports correctly the VRAM in use. |
Fixes #24906.
Problem
On ROCm,
hipMemGetInfo(KFDAVAILABLE_MEMORY) only accounts for ROCm/KFD compute allocations and ignores DRM graphics usage (Vulkan/GL/compositor). Free VRAM is over-reported vsrocm-smi, so automatic layer offload can over-commit and OOM at load.Fix
On
GGML_USE_HIP && __linux__, readmem_info_vram_total/usedfrom sysfs (matched by PCI bus id, the same sourcerocm-smiuses) and reportfree = total - used. Reuses the existingctx->pci_bus_idand folds into the existing#if __linux__memory path (the UMA branch from #17368), so discrete cards take sysfs while UMA/APU stays on/proc/meminfo. Double safety: takemin(hip, sysfs)free, so the value can only get more conservative; fall back tohipMemGetInfoif sysfs is unavailable. Non-HIP / non-Linux paths unchanged.Verified (gfx1100 RX7900GRE, ROCm 7.2.1)
--list-devicesMatches
rocm-smi. APU falls back via the UMA branch; builds clean on ROCm 7.2.1.