Skip to content

Add -DGGML_USE_VMM=ON to build workflow to fix ROCm VRAM retention / OOM on RDNA 3.5/4 #87

Description

@Aaronontheweb

Operating System

Ubuntu 24.04

OS Details

Kernel 6.14.0-37-generic

GPU Model

AMD Radeon AI PRO R9700 (gfx1201, RDNA 4), two of them in the same host.

llamacpp-rocm Build Version

b1245

Model Used

unsloth/gemma-4-26B-A4B-it-GGUF (gemma-4-26B-A4B-it-UD-Q4_K_XL.gguf plus the BF16 mmproj).

Does this issue also occur with Vulkan on upstream llama.cpp?

Not tested locally. Issue #79 does report that switching to Vulkan fixes the same class of OOM on an RX 9060 XT (gfx1200), which suggests the ROCm allocator path is the problem, not the model or flash-attention code.

Issue Description

Your binaries print NO_VMM = 1 in system_info on every startup, regardless of GPU:

system_info: ... | ROCm : NO_VMM = 1 | PEER_MAX_BATCH_SIZE = 128 | ...
  Device 0: AMD Radeon AI PRO R9700, gfx1201 (0x1201), VMM: no, Wave Size: 32, VRAM: 32624 MiB

That's because build-llamacpp-rocm.yml doesn't pass -DGGML_USE_VMM=ON to cmake. Without it, the VMM-backed pool allocator (ggml_cuda_pool_vmm in ggml/src/ggml-cuda/ggml-cuda.cu) gets #if defined(GGML_USE_VMM)'d out of libggml-hip.so. The NO_VMM = 1 string is literally printed from the matching #ifndef block in the same file.

The fallback pool (which is what you're actually shipping) runs on direct hipMalloc. It grows on demand but never gives pages back, so each new peak in flash-attn scratch or KV cache permanently raises the process's resident VRAM floor. Leave it running long enough with varied load and a routine allocation trips the ceiling:

/path/to/ggml-cuda.cu:97: ROCm error
ROCm error: out of memory
  current device: 0, in function alloc at .../ggml-cuda.cu:430
  ggml_cuda_device_malloc(&ptr, look_ahead_size, device)

Our stack traces go through ggml_cuda_flash_attn_ext_tile_case<512, 512>, which is Gemma 4's 512-dim global attention kernel.

Reproduction on our 2x R9700 box under real agent traffic: fresh process is sitting at 17 GB of VRAM (model + mmproj, which is what we'd expect). After roughly 170 requests have come and gone with zero slots currently active, the process is still parked on 24 GB. That's 7 GB the allocator is holding with nothing actually running. Next concurrent long-prompt burst asks for another 4-8 GB, blows past 32 GB, process core-dumps. systemd restart brings it back to 17 GB and we repeat the cycle every 60-90 minutes.

This seems to be the same underlying problem as issues #79, #52, and #81.

Additional Information

The fix is one line in both the Linux and Windows cmake blocks of build-llamacpp-rocm.yml:

   -DGGML_HIP=ON \
+  -DGGML_USE_VMM=ON \
   -DGGML_CUDA_FORCE_CUBLAS=OFF \

It shouldn't be a breaking change. Even when VMM is compiled in, llama.cpp does a per-device runtime check against hipDeviceAttributeVirtualMemoryManagementSupported and falls back to the legacy pool if the device doesn't claim support, so older GPUs that can't do VMM keep their current behavior.

I wrote a small HIP probe to make sure the runtime actually supports VMM on our hardware before suggesting this:

hipDeviceGetAttribute(&v, hipDeviceAttributeVirtualMemoryManagementSupported, 0);
// hipSuccess, v = 1
hipMemGetAllocationGranularity(&g, &prop, hipMemAllocationGranularityRecommended);
// hipSuccess, g = 4096

Both R9700s report VMM supported with 4096-byte granularity on ROCm 7.2.26015. So the flag flip should help RDNA 3.5/4 targets (gfx1151, gfx1150, gfx120X) right away, which is where most of the memory-pressure reports seem to be coming from.

For reference, the VMM pool in llama.cpp reserves a 32 GB virtual address range per device with cuMemAddressReserve, then maps physical pages on demand via cuMemCreate / cuMemMap and returns them with cuMemRelease. That's the behaviour your current builds don't have access to.

Happy to open the PR if you want it.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions