Repository navigation
[Bugfix] Bind load_hip_runtime to the HIP runtime already loaded - #6398
Conversation
ROCm 10 pip images ship the HIP runtime in _rocm_sdk_core and a second
copy in _rocm_sdk_devel. Torch maps the core copy. When -devel is on
LD_LIBRARY_PATH, CDLL("libamdhip64.so") maps the devel copy as a second
runtime. Other ctypes HIP users that take the copy from /proc/self/maps
can then bind the wrong one. Their launches fail with
hipErrorContextIsDestroyed.
Bind to the copy that is already in /proc/self/maps. Keep the soname
search as the fallback. Add a CPU-only test.
Co-authored-by: Cursor <[email protected]>
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
…ssing /proc/self/maps vmm_allocator called load_hip_runtime() at import. If the module is imported before torch maps its HIP runtime, /proc/self/maps has no libamdhip64 yet, so the call falls back to the soname and can still map a second runtime on ROCm 10 split-wheel images. The module now loads its handle on first use through a cached _hip(). load_hip_runtime() itself stays uncached, as before. An unreadable /proc/self/maps (no procfs) now falls back to the soname search instead of raising at import. Co-authored-by: Cursor <[email protected]>
There was a problem hiding this comment.
🟢 Approval recommended
The implementation is focused and its changed loader behaviors are directly covered by regression tests.
0 open findings
What changed in this PR
Updates HIP runtime loading to reuse Torch’s mapped runtime and avoid duplicate ROCm runtimes.
Changes:
- Prefer mapped
libamdhip64.so*paths with safe fallback. - Lazily cache the runtime handle.
- Add CPU-only loader regression tests.
| File | Description |
|---|---|
aiter/dist/device_communicators/vmm_allocator.py |
Implements mapped-runtime lookup and lazy loading. |
op_tests/test_vmm_allocator_load_hip.py |
Tests lookup, fallback, deleted paths, and import behavior. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
The kernel writes a newline in a maps path as "\012". Decode it before CDLL. Keep trailing spaces in the path. Add a CPU test for an escaped path. Co-authored-by: Cursor <[email protected]>
|
The fix itself looks reasonable, but Please remove this CPU-only test from |
op_tests holds operator tests, and the GPU Standard Test shards collect every op_tests/test_*.py. aiter has no CPU unit-test suite yet. Co-authored-by: Cursor <[email protected]>
There was a problem hiding this comment.
Copilot wasn't able to review any files in this pull request. Check if the Files changed in this pull request are included in default exclusions.
|
@zufayu thanks. I removed the CPU-only test in 77e7b41, so the PR now changes only I validated it on one MI355X GPU with the stock SGLang ROCm 10 image
With this PR only one A full server shows the same. A TP8 Qwen3.8 server on the same image, with a peer buffer allocated through repro.py import sys, unittest, torch
from sglang.srt.distributed.device_communicators.cuda_wrapper import find_loaded_library
torch.cuda.current_device()
if sys.argv[1] == "aiter":
from aiter.ops.flydsl.quick_allreduce_int4_ipc import UncachedIpcHeap
UncachedIpcHeap._load_hip()
mapped = sorted({l.split()[-1] for l in open("/proc/self/maps") if "libamdhip64" in l})
print(mapped, find_loaded_library("libamdhip64"))
sys.path.insert(0, "/sgl-workspace/sglang/test/registered/amd")
import test_vattn_segplan_mi35x as t
name = "TestVattnSegPlan.test_launches_on_a_side_stream_and_under_graph_capture"
unittest.TextTestRunner().run(unittest.defaultTestLoader.loadTestsFromName(name, t))
|
There was a problem hiding this comment.
Copilot wasn't able to review any files in this pull request. Check if the Files changed in this pull request are included in default exclusions.
There was a problem hiding this comment.
Copilot wasn't able to review any files in this pull request. Check if the Files changed in this pull request are included in default exclusions.
There was a problem hiding this comment.
Copilot wasn't able to review any files in this pull request. Check if the Files changed in this pull request are included in default exclusions.
There was a problem hiding this comment.
Copilot wasn't able to review any files in this pull request. Check if the Files changed in this pull request are included in default exclusions.
There was a problem hiding this comment.
Copilot wasn't able to review any files in this pull request. Check if the Files changed in this pull request are included in default exclusions.
|
@aiter-bot review |
[ROCm/aiter] PR #6398 — [Bugfix] Bind load_hip_runtime to the HIP runtime already loadedvmm_allocator's HIP runtime loader now binds to the libamdhip64 copy already mapped in /proc/self/maps (torch's) instead of dlopening a second runtime by soname, and the load moves from import time to the first VMM call. Review (advisory):
📝 [verified] In vmm_allocator.py, if the mapped |
If CDLL() of the mapped libamdhip64 path raises OSError, load_hip_runtime() falls back to the soname search. That search can map a second runtime. Log the error once, so that the fallback is visible. Co-authored-by: Cursor <[email protected]>
tests/ is the CPU unit-test suite, and CI runs it with "python3 -m pytest -q tests". Add a case for the fallback: the mapped path fails to load, and the loader logs a warning and tries the soname. Co-authored-by: Cursor <[email protected]>
A text-mode read decodes /proc/self/maps as strict UTF-8. One mapped file name that is not valid UTF-8 then raises UnicodeDecodeError, and load_hip_runtime() fails. Read the file as bytes and decode each line with os.fsdecode(). ctypes.CDLL encodes the path back to the same bytes. Co-authored-by: Cursor <[email protected]>
|
I repeated the single-GPU repro on 2026-10-21 with ce9f1e8: 20/20 pass, one |
zufayu
left a comment
There was a problem hiding this comment.
The targeted ROCm 10 duplicate-HIP-runtime failure is fixed, the loader regression tests are now under tests/, the final head was revalidated against the 709 reproducer and full TP8 server, and the required CI is green. LGTM.
On ROCm 10 images that ship the HIP runtime in both _rocm_sdk_core and _rocm_sdk_devel, with the devel copy on LD_LIBRARY_PATH, AITER before ROCm/aiter#6398 maps a second HIP runtime beside torch's. hipIpcGetMemHandle then rejects torch's allocation, and loading fails in SymmetricArena. The server-arguments row now names the requirement. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Rony Leppänen <[email protected]>
Motivation
This bug fix makes
load_hip_runtime()bind to the HIP runtime that torch already loaded. Today it openslibamdhip64.soby name, and on ROCm 10 images that adds a second HIP runtime to the process and breaks other ctypes HIP users. WithUncachedIpcHeapimported, two of three SGLang server starts of Qwen3.8 at TP8 on MI355X failed in decode graph capture:ROCm 10 ships the HIP runtime (
_rocm_sdk_core) and the toolchain (_rocm_sdk_devel) as separate wheels. Torch maps the corelibamdhip64.so.7. When_rocm_sdk_devel/libis onLD_LIBRARY_PATH,CDLL("libamdhip64.so")maps the devel copy as a second runtime.sgl-project/sglang#39513 fixed this 709 in SGLang's
vattn_asm. It binds to thelibamdhip64in/proc/self/mapsand assumes that only torch's copy is mapped.load_hip_runtime()breaks that assumption. SGLang'svattn_asm,smallm_moe_gfx950andengramcan then bind the devel copy and launch on a torch stream through the wrong runtime.In SGLang the failure shows up in
vattn_asm. It runs gfx950 decode, MTP verify and draft extend at page size 16, so runs without MTP hit it too. sgl-project/sglang#39513 reports that therocm720androcm724images map one runtime, so this change does nothing there.Technical Details
The fix is in
aiter/dist/device_communicators/vmm_allocator.py. Its CPU-only test istests/test_vmm_allocator_load_hip.py.load_hip_runtime()first looks for alibamdhip64.so*in/proc/self/mapsand returns aCDLLof that path. It reads the file as bytes and decodes each line withos.fsdecode(), so a mapped file name that is not valid UTF-8 does not stop the lookup. The kernel writes a newline in a maps path as\012, so the lookup decodes it. If none is mapped, or the mapped path fails to load, it runs the soname search as before (asasm_utils.load_hip()does).load_hip_runtime()logs a warning before the soname search, because that search can map a second runtime./proc/self/maps,load_hip_runtime()falls back to the soname search instead of raising.load_hip_runtime()at import. A cached_hip()loads its handle on the first VMM call. Before, an import ofvmm_allocatorthat ran before torch mapped its runtime found nothing in/proc/self/mapsand mapped the second copy by name.load_hip_runtime()itself stays uncached.UncachedIpcHeap._load_hip()and the two VMM paths incustom_all_reduce.pycallload_hip_runtime(). All three run after torch has initialized HIP, so they get torch's copy.Rocm/aiter5182 adds a shared loader in
aiter/jit/utils/hip_runtime.pyand movesvmm_allocator.py,chip_info.pyandrocm_version.pyonto it. That loader finds the loaded copy by soname withRTLD_NOLOAD. Whichever PR lands second should merge the two lookups in the shared loader.smi_monitor.pyalso loads by soname, but only the op-test harness (aiter/test_common.py) uses it.Test Plan
CPU:
python3 -m pytest -q tests/test_vmm_allocator_load_hip.py. The test fakes/proc/self/mapsand mocksctypes.CDLL. It covers the mapped lookup, the(deleted)suffix, the\012decode, a mapped file name that is not valid UTF-8, the fallback and its warning, a missing/proc/self/maps, and no load at import.GPU: one MI355X GPU, the stock SGLang ROCm 10 image
rocm/sgl-dev:v0.5.21-rocm10-mi35x-20261009(SGLang main, aitere7d2453f2), no other patches. Each run is a fresh process that runs SGLang'svattn_asmside-stream and graph-capture test, either alone or after aiter's HIP loader (UncachedIpcHeap._load_hip()). 20 runs per case, once with the image'svmm_allocator.pyand once with this PR's mounted over it. The table below is from 2026-10-21, withvmm_allocator.pyat ce9f1e8 (the final loader). The runs on 2026-10-14 with 1f30f43 gave the same result.repro.py:python3 repro.py stockruns the SGLang test without the aiter loader.python3 repro.py aiterruns the aiter loader first.Full server: a TP8 Qwen3.8 server on the same image, with a peer buffer allocated through
UncachedIpcHeap(sgl-project/sglang#43516), through decode graph capture and serving.Test Result
CPU: 8 passed.
GPU:
libamdhip64mappedvattn_asmbinds_rocm_sdk_core_rocm_sdk_develvattn_asm: hipModuleLaunchKernel failed: 709 (context is destroyed)_rocm_sdk_coreWith this PR only one
libamdhip64is mapped, and the 709 no longer reproduces. The first row is the control: SGLang alone maps one runtime and passes.The full server shows the same (run on 2026-10-14 with 1f30f43). Without this PR it hit the 709 in decode graph capture. With it, the server came up and served requests, and every rank mapped only
_rocm_sdk_core/lib/libamdhip64.so.7.Submission Checklist