Repository navigation
Conversation
ROCr reports memory mapped through its virtual memory API (hipMemCreate + hipMemMap, hsa_amd_vmem_map) as HSA_EXT_POINTER_TYPE_HSA_VMEM, with the GPU as its owner. Memory type detection and mem_query only accepted HSA_EXT_POINTER_TYPE_HSA, so VMM device memory was reported as host memory and rocm_copy tried to lock it as host memory, which fails with UCS_ERR_IO_ERROR. This mirrors the CUDA VMM (cuMemMap) support in cuda_copy. Detect the enum value at configure time, since older ROCm headers lack it. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Signed-off-by: Nick Hill <nickhill123@gmail.com>
hsa_amd_ipc_memory_create does not support memory mapped with hipMemMap (HSA_EXT_POINTER_TYPE_HSA_VMEM), so rocm_ipc failed to register it. Since ucp_mem_map registers on every MD that supports the memory type, this failed the whole registration whenever rocm_ipc was enabled. Share VMM allocations the way cuda_ipc shares CUDA VMM memory: export the allocation mapped at the registered address as a dma-buf fd with hsa_amd_vmem_export_shareable_handle, and have peers import, map and grant access to it. Instead of pidfd_getfd, which needs ptrace access to the exporter and is denied by Yama's default ptrace_scope for unrelated processes, the exporter passes the fd with SCM_RIGHTS over an abstract unix socket that the UCS async thread serves, to processes of the same user. Registrations of the same allocation share one export, so that peers map it once. Fall back to registering VMM memory without an IPC handle when it cannot be exported, or when the ROCm runtime cannot share VMM allocations: older releases report the queried address rather than the mapping base in hsa_amd_pointer_info, and crash on imported allocations. Peers report such keys as unreachable and select another transport. When the local buffer is VMM memory, do not call hsa_amd_agents_allow_access on it, which only applies to memory pool allocations, and copy with the local agent, which has access. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Signed-off-by: Nick Hill <nickhill123@gmail.com>
|
🤖 Starting review — findings will be posted here when done. |
|
@njhill thank you for your work. As a heads up, we are having similar PRs also in the works at AMD, which we plan to file shortly. There are really three things that we need to fix :
Our approach is slightly different though, we do not want to intermerge everything in a single TL (rocm_ipc), we plan to introduce a new TL (rocm_fabric) and new memory types UCS_MEMORY_ROCM_VMM |
Thanks @edgargabriel! I'm curious do you have any eta for a UCX release containing these fixes? |
|
@edgargabriel @mshanthagit Routing this for review as the ROCm CODEOWNERs. This is part of the VMM-on-ROCm series (#12137 to #12140) that vLLM extensible KV cache (vllm-project/vllm#56492) needs for NIXL registration on ROCm. Edgar, your note above says AMD plans a rocm_fabric TL and UCS_MEMORY_ROCM_VMM instead of extending rocm_ipc. Could you say whether you want to review this rocm_ipc dma-buf path, or whether the AMD PR should supersede it? Any ETA for a release with these fixes would also help. |
What?
rocm_ipcshares VMM memory by exporting its allocation as a dma-buf file descriptor. Peers import it, map it and grant access to it, ascuda_ipcdoes for CUDA VMM memory. When VMM memory can't be shared, it is registered without an IPC handle, and peers report the key as unreachable. Addsrocm_ipc/test_rocm_ipc_vmm.share.Why?
Device memory mapped with the HIP virtual memory API (
hipMemCreate+hipMemMap,hsa_amd_vmem_*in ROCr) can't be used with UCX today, while the equivalent CUDA VMM memory (cuMemCreate+cuMemMap) can. Frameworks that grow GPU buffers in place reserve an address range and map memory into it on demand. vLLM's extensible KV cache (vllm-project/vllm#56492) does this, and its NIXL KV connector registers that memory with UCX. On ROCm that fails at registration, then crashes inrocm_copy, androcm_ipccan't share the memory at all.hsa_amd_ipc_memory_createdoesn't support VMM memory, sorocm_ipcfailed to register it.ucp_mem_mapregisters on every MD that supports the memory type, so this failed the whole registration wheneverrocm_ipcwas enabled.This is one of four PRs that make VMM memory work on ROCm:
rocm_copyhsa_amd_vmem_map/unmaprocm_ipc(this PR)This PR includes the commit of #12137 ("UCT/ROCM: Treat HSA_EXT_POINTER_TYPE_HSA_VMEM as ROCm memory"), which it depends on. Only the last commit is new here.
How?
hsa_amd_vmem_export_shareable_handle. The packed key carries a handle type, a server id and an fd id.ptrace_scope=1denies for unrelated processes. Instead, the exporter passes the fd withSCM_RIGHTSover an abstract unix socket, served from the UCS async thread. Only processes of the same user are served, checked withSO_PEERCRED(rocm_ipc_fd.c). Registrations of the same allocation share one export, so peers map it once.hsa_amd_pointer_info, and crash on imported allocations. A probe on a small local mapping detects this once. On such runtimes, and when an allocation can't be exported, VMM memory is registered without an IPC handle, so UCP selects another transport.hsa_amd_agents_allow_accessisn't called on it, since that applies only to pool allocations.rocm_ipc.Real sharing needs these ROCr fixes: ROCm/rocm-systems#13990, ROCm/rocm-systems#13991, ROCm/rocm-systems#13992 and ROCm/rocm-systems#11449, which is merged.
Testing
The new test registers, packs and unpacks VMM memory in a second mapping. Without this change it fails at
mem_reg("Address not valid"). With it:put_zcopyandget_zcopythroughrocm_ipcmove data correctly, and the trace shows the fd export, the import mapping and cache hits.Tested on MI350X (gfx950) with the vLLM ROCm CI image (ROCm 10.0 TheRock wheels, ROCr 1.21.0). The existing
rocm_ipctests pass.End to end: vLLM's NIXL prefill/decode accuracy test ran with VMM KV caches on both sides. With patched ROCr, the KV reads use zero-copy
rocm_ipc, with steady-state transfers of 14–16 ms average and 23–24 ms P90. With stockhipMalloccaches over the staging path they were 20–26 ms average and 35–42 ms P90. Accuracy matches the non-VMM baseline. With stock ROCr the test passes over the fallback.🤖 Generated with Claude Code