[ROCm] Grant host access to VMM allocations in sleep-mode pool - #1
Open
xiaohong42 wants to merge 1 commit into
Open
[ROCm] Grant host access to VMM allocations in sleep-mode pool#1xiaohong42 wants to merge 1 commit into
xiaohong42 wants to merge 1 commit into
Conversation
xiaohong42
force-pushed
the
fix/rocm-vmm-host-access
branch
from
August 7, 2026 06:53
d6c2095 to
63318e7
Compare
On large-BAR devices (MI300X), PyTorch's ROCm backend (>= 7.2) reads scalar tensors via direct host-side pointer dereference instead of hipMemcpy. This optimization (in _local_scalar_dense_cuda) assumes all device memory is host-accessible. However, the sleep-mode VMM pool (hipMemCreate + hipMemMap) only grants GPU-side access via hipMemSetAccess, leaving the host without a valid mapping. When FP8 quantization triggers an implicit .item() on a KV-cache scale parameter allocated in this pool, the host dereference hits an unmapped address and the worker is killed by SIGSEGV -- with no Python traceback since faulthandler is not enabled by default. Fix: add a hipMemLocationTypeHost access descriptor alongside the existing device descriptor in create_and_map(). This gives the VMM range a host mapping, making PyTorch's large-BAR fast path valid for sleep-mode memory. Only the ROCm path is modified (guarded by #ifdef USE_ROCM); the CUDA path is unchanged. Tested: verl megatron e2e with ROLLOUT_QUANTIZATION=fp8 + sleep mode on MI300X (ROCm 7.14) passes end-to-end after this fix. Signed-off-by: xiaohong42 <940683523@qq.com>
xiaohong42
force-pushed
the
fix/rocm-vmm-host-access
branch
from
August 7, 2026 07:39
63318e7 to
0fdfc4a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
On large-BAR devices (MI300X), PyTorch ROCm (>=7.2) reads scalar tensors via direct host-side pointer dereference (
_local_scalar_dense_cuda) instead ofhipMemcpy. The sleep-mode VMM pool (hipMemCreate+hipMemMap) only grants GPU-side access, so the host dereference hits an unmapped address causing SIGSEGV that silently kills the worker with no Python traceback.Root Cause
create_and_map()incsrc/cumem_allocator.cppcallshipMemSetAccesswith only a device descriptor. PyTorch's large-BAR fast path assumes all allocator-managed memory is host-readable, which is true forhipMallocbut not for VMM allocations without an explicit host mapping.Fix
Add a
hipMemLocationTypeHostaccess descriptor alongside the existing device descriptor. This gives the VMM range a host mapping, making PyTorch's fast path valid.Only the ROCm path is modified (
#ifdef USE_ROCM); the CUDA path is unchanged.Why not fix at the read site?
We considered detecting at read time whether a given device pointer is host-accessible, but no HIP API on ROCm 6.x/7.x provides this information correctly. All candidates were tested with native HIP C++ probes (
probe_discriminator.cpp,probe_memgetaccess.cpp):hipPointerGetAttributes().hostPointerhipPointerGetAttribute(HOST_POINTER)hipPointerGetAttribute(MAPPED)hipMemGetAccess(location=Host)hipMemRetainAllocationHandleThe only API that differs (
hipMemRetainAllocationHandle) would false-positive on PyTorchexpandable_segmentsmemory — which is VMM-allocated but is host-accessible. Using it as a discriminator would regress performance by ~11× on those allocations (forcinghipMemcpyinstead of direct dereference).Conclusion: ROCm 7.14 has no API to query "is this pointer host-mapped?", so the correct fix is to grant host access at mapping time rather than trying to detect it at read time.
Performance (bench_discriminator.cpp, 20000 iterations)
The fix adds zero overhead — it simply makes the existing fast path valid for VMM memory.
Test
test_cumem_host_read_scalarintests/basic_correctness/test_mem.py(ROCm-only):.sum()→.item()verifies no segfaultROLLOUT_QUANTIZATION=fp8+--enable_sleep_modeon MI300X (ROCm 7.14): passes end-to-end..item()no longer segfaults on VMM memory after the fix.Additional notes
isLargeBar = 1confirmed on test machine (BAR0 = 256 GiB > physical VRAM 192 GiB)