llama.cpp icon indicating copy to clipboard operation
llama.cpp copied to clipboard

Eval bug: HIP: VMM memory pool cannot grow on gfx1200 (cuMemSetAccess returns hipErrorInvalidValue)

Open fox5611 opened this issue 2 weeks ago • 2 comments

Name and Version

master 3549c274d, plus the local CU_CHECK fix from #32105 (required to reach this, see below)

Operating systems

Linux

GGML backends

HIP

Hardware

AMD Radeon RX 9060 XT (gfx1200), ROCm 7.1.1

Models

N/A, reproduced with test-backend-ops

Problem description & steps to reproduce

Command line

cmake -B build -DGGML_HIP_NO_VMM=OFF
./build/bin/test-backend-ops -o ADD

Problem description & steps to reproduce

The HIP VMM memory pool serves its first mapping correctly, but aborts as soon as the pool has to grow. No model is required.

This is not reachable on unpatched master, because #32105 hangs in CU_CHECK before this point. The CU_CHECK fix from that issue must be applied first.

With the unmodified call site: the first mapping is 4096 bytes at granularity 4096, and 9 cases pass. The 10th case needs more memory. cuMemCreate and cuMemMap both succeed for 45056 bytes at offset 4096, then cuMemSetAccess(pool_addr + 4096, 45056, ...) returns hipErrorInvalidValue and the process aborts at ggml-cuda.cu:707.

Calling over the whole mapped range instead does not help. cuMemSetAccess(pool_addr, 49152, ...) returns success, and hipMemGetAccess reports hipMemAccessFlagsProtReadWrite for the new region, but the next kernel to touch that memory faults the GPU with HSA_STATUS_ERROR_MEMORY_FAULT. HIP reports the memory as accessible and the hardware disagrees.

Control: forcing a single 64 MiB first mapping, so the pool never grows, makes the same code pass 173/173 ADD cases with the suite reporting OK. This isolates growth as the trigger. It is a diagnostic, not a proposed fix, since any fixed chunk size is eventually exhausted.

AMD documents these VMM entry points as Beta, which may be why GGML_HIP_NO_VMM defaults to ON.

No patch is proposed, because the call site cannot work around this: the correct-looking call is rejected and the whole-range call reports a success that does not hold. Would unmap-and-remap on growth be an acceptable direction, or should HIP VMM remain disabled with this behaviour documented?

First Bad Commit

Not a regression. git log -S"cuMemSetAccess" -- ggml/src/ggml-cuda/ggml-cuda.cu returns only #10256 (backends built as libraries, a file reorganization) and #24491 (Turing P2P access fix), so the call predates the current file layout. #30542 is not involved in this failure; it only introduced the #32105 hang that masks it.

Relevant log output

Relevant log output

Clean code plus the #32105 fix. Aborts on the first growth:

  ADD(type=iq3_s,n=256,m=16,r=4): OK
/home/rthacker/ai/llama.cpp/ggml/src/ggml-cuda/ggml-cuda.cu:707: HipVMM Failure: invalid argument

Instrumented to try both call shapes and query the result. The sub-range call is rejected only when its offset is nonzero, and hipMemGetAccess reports read/write on the new region after the whole-range call succeeds:

[vmm] setaccess sub  ptr=124519805091840 size=4096 -> 0
[vmm] setaccess full ptr=124519805091840 size=4096 -> 0
[vmm] getaccess new flags=3 ret=0 | base flags=3 ret=0
[vmm] setaccess sub  ptr=124519805095936 size=45056 -> 1
[vmm] setaccess full ptr=124519805091840 size=49152 -> 0
[vmm] getaccess new flags=3 ret=0 | base flags=3 ret=0

That instrumented run also reports ROCm error: invalid argument from a later hipGetLastError() at ggml-cuda.cu:113. That is an artifact of the instrumentation, not a separate failure: the rejected sub-range call leaves hipErrorInvalidValue latched, and the next hipGetLastError() picks it up.

With only the whole-range call and nothing swallowed, no latched error exists and the GPU still faults:

  ADD(type=iq3_s,n=256,m=16,r=4): OK
Queue error - HSA_STATUS_ERROR_MEMORY_FAULT

fox5611 avatar Nov 15 '26 17:11 fox5611

Re-verified on current master 8d60873df with the #32105 macro fix applied on top (rebased; the diff is one file, one hunk). Built with GGML_HIP=ON and GGML_HIP_NO_VMM=OFF; the run reports gfx1200 with VMM: yes.

11 ADD cases pass, then the abort.

~/ai/llama.cpp$ grep -E "HipVMM Failure|^#6 |^#7 |^#8 " /tmp/32350_recheck.log /home/rthacker/ai/llama.cpp/ggml/src/ggml-cuda/ggml-cuda.cu:783: HipVMM Failure: invalid argument #6 0x000073496739e111 in ggml_cuda_pool_vmm::alloc(unsigned long, unsigned long*) () from /home/rthacker/ai/llama.cpp/build/bin/libggml-hip.so.1 #7 0x00007349673b4e7f in ggml_cuda_mul_mat_q(ggml_backend_cuda_context&, ggml_tensor const*, ggml_tensor const*, ggml_tensor const*, ggml_tensor*, ggml_cuda_mm_fusion_args_host const*) () from /home/rthacker/ai/llama.cpp/build/bin/libggml-hip.so.1 #8 0x000073496738ffc1 in ggml_cuda_graph_evaluate_and_capture(ggml_backend_cuda_context*, ggml_cgraph*, bool, bool, void const*) () from /home/rthacker/ai/llama.cpp/build/bin/libggml-hip.so.1

Three differences from the original report. The failing call site moved from line 716 to 783 on upstream churn; git log -S"cuMemSetAccess" -- ggml/src/ggml-cuda/ggml-cuda.cu still shows nothing newer than 7a63fdede, so the code itself is unchanged. The ADD suite now has 11 cases rather than 9. And the allocation is reached through ggml_cuda_mul_mat_q this time rather than ggml_cuda_mul_mat_vec_q, so two different matmul dispatch paths hit the same pool-growth failure.

On why this has stayed unconfirmed: GGML_HIP_NO_VMM defaults to ON, so the VMM path is opt-in on HIP, and on a tree without #32105's fix the hang arrives first, which makes the pool-growth failure unreachable. Observing this bug at all requires VMM enabled and the macro fixed at the same time.

What would move this off bug-unconfirmed?

fox5611 avatar Nov 22 '26 17:11 fox5611

I tried to see whether this one shows up on Windows. I couldn't reproduce it there, but this is a stand-alone mimic of the pool and not llama.cpp itself, so please read it as a limited check.

Setup

  • Radeon RX 9070 XT (gfx1201), Windows 11 (10.0.26300), Adrenalin driver 32.0.32029.2010
  • HIP SDK 7.18.26466 (hipcc from the ROCm 10.3 Windows wheels), hipDeviceAttributeVirtualMemoryManagementSupported = 1
  • Allocation granularity here is 64 KiB minimum / 256 KiB recommended (the log in this issue shows 4096)

What I did I wrote a small HIP program that follows the same sequence as ggml_cuda_pool_vmm: reserve 32 GiB of VA, hipMemCreate + hipMemMap a first chunk at offset 0, hipMemSetAccess, then grow four times by 12x, 23x, 34x, 45x granules (the same shape as 4096 -> 45056), each time hipMemCreate/hipMemMap at the end of the mapped range and then hipMemSetAccess. After each step it calls hipMemGetAccess, then launches a kernel that writes the new region and reads it back to check it.

  • Sub-range hipMemSetAccess(pool + offset, size) on growth, first chunk of 64 KiB and also of 256 KiB: all five steps return success, hipMemGetAccess reports read/write (flags=3), and the kernel write/readback is correct on the new region (0 wrong words).
  • Whole-range hipMemSetAccess(pool, total) on growth: same, no errors, no faults.
  • 64 MiB first mapping followed by the same four growth steps: also fine, and 64 MiB with no growth.

No hipErrorInvalidValue, no HSA_STATUS_ERROR_MEMORY_FAULT.

So the nonzero-offset hipMemSetAccess rejection from this issue doesn't show up with this driver stack. Differences that could matter: I'm on gfx1201 not gfx1200, on Windows, the granularity is 64 KiB so I can't test 4096-byte chunks, and I didn't build llama.cpp with GGML_HIP_NO_VMM=OFF and run test-backend-ops -o ADD. I can try that next if it would be useful.

coryord15-ship-it avatar Nov 28 '26 03:11 coryord15-ship-it