[ROCm 10.0 / gfx1151] Pipeline-parallel coordinator segfaults in libhsa-runtime64 on a large D2H hipMemcpy (bare-HIP control is fine)

Aperta
#1,141 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
25/100
Tipo di issue
Bug
Chiarezza
Da chiarire
Stato di attività
Attiva
Stack tecnologico
c

Direzione di ricerca

Start with rocm/ds4_rocm_runtime.cuh:6048 and ds4.c:55032, then trace the coordinator path through ds4_distributed.c:2733 and :3815. Reproduce the coordinator/worker commands on gfx1151 with ROCm 10.0 and compare the failing ds4 process with the passing bare-HIP controls. Done means identifying the ds4 process state that triggers the runtime crash or documenting a validated ds4-side workaround.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Summary

Pipeline parallelism (2 ranks, 2× Strix Halo / gfx1151, ROCm 10.0) segfaults in ROCm's
libhsa-runtime64
as soon as the coordinator prefills the prompt. The route is established
correctly; the crash happens inside a device→host hipMemcpy.

Localized with gdb to a crash that, within the ds4 coordinator process, follows a size boundary:

In the ds4 PP coordinator process, a single D2H hipMemcpy of more than 1 MiB (2^20 bytes)
crashes inside hsa_amd_memory_unlock → MemoryRegion::Unlock → KfdDriver::MakeMemoryUnresident → hsaKmtUnmapMemoryToGPU → hsakmt_fmm_unmap_from_gpu → vm_find_object (NULL/garbage
dereference). Copies ≤ 1 MiB from the same device address succeed.

⚠ Important correction (added same day): this is NOT a general HIP/ROCm size limit. A bare HIP
program on the same machine, same ROCm, does D2H copies of up to 16 MiB fine — including with 85 GiB
of GTT already committed. So the "1 MiB" boundary is a property of the ds4 process state, not of
hipMemcpy itself. See the "Update" section right below; read that before drawing conclusions from
the threshold table.

The copy is in-bounds (the source pointer is the base of a 128 MiB device allocation and only
~1.5 MiB are read). Within the ds4 process the trigger tracks the copy size, not the buffer: the
same 1,638,400-byte copy also crashes when taken from an unrelated, known-good workspace buffer.

I am reporting it here because it makes the PP coordinator unusable on this platform, and because
the ds4 side can work around it. I believe the defect itself is in ROCm; details for a robust
workaround and for a ROCm report are at the bottom. (I built from kyuz0/ds4, branch
main-gfx1151, which has issues disabled — hence this report.)


Update — what the "1 MiB" threshold is not

Two controls added after the initial report:

1) A bare HIP program does not reproduce it. Same machine, same ROCm 10.0, same gfx1151:

hipGetDeviceCount -> hipSuccess, ndev=1
hipMalloc(268435456) -> hipSuccess
--- pageable destination ---
  D2H       4096 B ... hipSuccess (0)
  D2H      65536 B ... hipSuccess (0)
  D2H    1048576 B ... hipSuccess (0)
  D2H    1245184 B ... hipSuccess (0)
  D2H    1638400 B ... hipSuccess (0)
  D2H    4194304 B ... hipSuccess (0)
  D2H   16777216 B ... hipSuccess (0)
--- pinned (hipHostMalloc) destination ---
  ... all sizes up to 16 MiB: hipSuccess (0)
ALL OK

…and it still passes when the process first commits a large GTT allocation, i.e. GTT pressure alone
is not the trigger:

hipMalloc(32 GiB) -> hipSuccess ; hipMemset -> hipSuccess ; D2H up to 4 MiB -> all OK
hipMalloc(64 GiB) -> hipSuccess ; hipMemset -> hipSuccess ; D2H up to 4 MiB -> all OK
hipMalloc(85 GiB) -> hipSuccess ; hipMemset -> hipSuccess ; D2H up to 4 MiB -> all OK

2) ds4's zero-copy host-registration path is not involved. ds4_rocm_runtime.cuh has a
cudaHostRegister(..., cudaHostRegisterMapped | cudaHostRegisterReadOnly) fallback for
non-device-cached model ranges (ds4_rocm_runtime.cuh:4651), which would be a natural suspect for
hsa_amd_memory_unlock. Counting hits at that exact line while reproducing the crash:

readback hits        = 1
hostRegister attempts = 0

So the crash reproduces without any cudaHostRegister call. That hypothesis is out.

Net effect on the diagnosis: the reproducible facts are (a) the crash site/backtrace,
(b) the crash happens in the ds4 coordinator process and not in a bare HIP program, (c) inside that
process it is deterministic and size-tracking (≤1 MiB OK, >1 MiB crash, same address). What ds4-side
process state
makes it fatal is not yet identified — treat the 1 MiB figure as an observed
boundary inside that process, not as a root cause. Any hint you have about ROCm-specific state that
ds4 sets up (streams, device flags, allocation flags, per-thread HIP contexts) would help narrow it.


Environment

Hardware 2× AMD Strix Halo (Radeon 8060S), gfx1151, 128 GB unified memory
OS Ubuntu 24.04.5 LTS (Noble Numbat) on both ranks — kernel 6.17.0-23-generic, x86_64
ROCm 10.0.0 — 46 amdrocm* packages incl. amdrocm-core-dev10.0-gfx1151 10.0.0-4, installed at /opt/rocm/core-10.0
ROCm apt track deb [arch=amd64 trusted=yes] https://stable.repo.amd.com/rocm/core/packages/ubuntu2404 stable main
Runtime libs in the crash libhsa-runtime64.so.1 → libhsa-runtime64.so.1.21.0; libamdhip64.so.7 → libamdhip64.so.7.15.26333-0000000
Install layout /opt/rocm is a symlink to /opt/rocm-7.2.4, so ROCm 10.0 physically lives at /opt/rocm-7.2.4/core-10.0 (side-by-side with a pre-existing ROCm 7.2.4)
Interconnect USB4 / Thunderbolt direct link, 10.10.11.1 ↔ 10.10.11.3
Build make strix-halo -j4 ROCM_ARCH=gfx1151 HIPCC=/opt/rocm/core-10.0/bin/hipcc
Source kyuz0/ds4, branch main-gfx1151 (tarball codeload.github.com/kyuz0/ds4/tar.gz/refs/heads/main-gfx1151)
Model GLM-5.3-Flash-Q4_K.gguf, 190,875,526,464 bytes, sha256 c7a0d950363238dd7804782c88340d737775aba53a15f8d4fdcc34e984f25221 (identical on both ranks)
Ranks coordinator = rank holding layers 0:22 (+ output head), worker = 23:output

Notes on the environment, in case they matter:

  • Our hosts are 24.04.5 (noble), not the Ubuntu 26.04 setup mentioned in
    docs/STRIX_HALO.md; we consume the ubuntu2404 ROCm 10 track. Flagging this because it is the
    one place where our environment differs from the documented gfx1151 reference.
  • The model is the same artifact that ./download_model.sh glm53-q4 resolves to. We fetched it
    with aria2c from an HF mirror rather than through the script's hf CLI path (the mirror has no
    Xet endpoint, so the CLI path cannot handle a 178 GiB file); size and sha256 were verified on
    both ranks.
  • glm5-next.block_count = 45 transformer blocks, so --layers 0:22 is 23 blocks and
    23:output is 22 blocks plus the output head.

Reproduction

Both ranks use the same binary and the same GGUF.

# ---- worker (station C, 10.10.11.3) ----
cd ~/ds4
export LD_LIBRARY_PATH=/opt/rocm/core-10.0/lib/rocm_sysdeps/lib:/opt/rocm/core-10.0/lib
./ds4 --rocm --role worker --layers 23:output --coordinator 10.10.11.1 9911 \
      -m gguf/GLM-5.3-Flash-Q4_K.gguf -c 4096

# ---- coordinator (station B, 10.10.11.1) ----
cd ~/ds4
export LD_LIBRARY_PATH=/opt/rocm/core-10.0/lib/rocm_sysdeps/lib:/opt/rocm/core-10.0/lib
./ds4 --rocm --role coordinator --layers 0:22 --listen 10.10.11.1 9911 \
      -m gguf/GLM-5.3-Flash-Q4_K.gguf -c 4096 -p "Hi"

The worker is started first (as documented) and retries while the coordinator loads.

Reproduced in every attempt — 6 runs total: launched through our orchestrator, a plain CLI
run, a ds4-server --role coordinator run, with -c 4096 and -c 8192, and in the gdb sessions
below.


Observed

The route forms normally, then the coordinator dies with SIGSEGV (exit status 139, core dumped):

ds4: ROCm backend initialized on AMD Radeon 8060S Graphics (sm_115)
ds4: restricting rocm model map to layers 0:22+output (48 spans, 84.64 GiB tensor span)
ds4: startup model preparation covered 84.64 GiB of tensor spans in 0.000s
ds4: memory: KV 0.04 GiB (raw 0.00 + compressed 0.04) + buffers 2.86 GiB + resident model 84.64 GiB = 87.55 GiB planned
ds4: GLM graph using compact DSA KV only; expanded full-attention KV cache is skipped
ds4: GLM graph allocating compact DSA cache: rows=4096 logical_ctx=4096 kv_layers=23 indexer_layers=5 f16 0.02 GiB
ds4: distributed coordinator API: listening on 10.10.11.1:9911 model_id=3 layers=45 local=0:22 activation_bits=32
ds4: waiting for distributed route: distributed route incomplete: missing layer 23
ds4: distributed coordinator: registered worker 10.10.11.3:37436 data_port=35969 model_id=3 quant=Q4 layers=23:output hidden=1 ctx=8192
ds4: distributed coordinator: complete route ready: local 0:22 -> 10.10.11.3:35969 Q4 23:output
ds4: distributed route ready
--- SIGSEGV ---
timeout: the monitored command dumped core

(The excerpt is representative; the ctx=8192 on the "registered worker" line is from the
-c 8192 run — everything else is identical for -c 4096.)

The worker then logs distributed worker: coordinator disconnected; reconnecting.


Backtrace (gdb, symbolized build)

Thread 1 "ds4" received signal SIGSEGV, Segmentation fault.
0x00007fffe5ddd66d in vm_find_object () from /opt/rocm/core-10.0/lib/libhsa-runtime64.so.1

#0  vm_find_object                                  libhsa-runtime64.so.1
#1  hsakmt_fmm_unmap_from_gpu                       libhsa-runtime64.so.1
#2  hsaKmtUnmapMemoryToGPU                          libhsa-runtime64.so.1
#3  rocr::AMD::KfdDriver::MakeMemoryUnresident(void const*) const
#4  rocr::AMD::MemoryRegion::Unlock(void*) const
#5  rocr::AMD::hsa_amd_memory_unlock(void*)
#6..#20  libamdhip64.so.7 (hipMemcpy internals)
#20 hipMemcpy                                        libamdhip64.so.7
#21 ds4_gpu_tensor_read        rocm/ds4_rocm_runtime.cuh:6048
#22 glm_graph_forward_indexed_tokens                   ds4.c:55032
#23 ds4_session_eval_layer_slice                       ds4.c:74518
#24 dist_coordinator_eval_span                         ds4_distributed.c:2733
#25 dist_coordinator_prefill_prompt                    ds4_distributed.c:3815
#26 ds4_dist_session_sync                              ds4_distributed.c:5620
#27 ds4_session_sync_internal                          ds4.c:75263
#28 ds4_session_sync                                   ds4.c:75108
#29 run_sampled_generation                             ds4_cli.c:575

The faulting instruction is a table walk with a corrupted base pointer:

vm_find_object+500: mov (%rax,%r10,1),%rax
rax = 0xbd08a4c4bb55ca79      <-- not a valid pointer

So vm_find_object is asked to look up an address that is not in the GPU VM map, and the lookup
path dereferences a bad pointer instead of returning "not found".


Where the copy comes from, and that it is in-bounds

At ds4.c:55032:

if (ok && output_hc) {
    ok = ds4_gpu_tensor_read(g->glm53 ? hc_cur : cur,
                             0,
                             output_hc,
                             (uint64_t)n_tokens * DS4_N_EMBD *
                                 (g->glm53 ? DS4_N_HC : 1u) *
                                 sizeof(float)) != 0;
}

ds4_gpu_tensor_read (DS4 ROCm runtime) is a plain D2H copy:

extern "C" int ds4_gpu_tensor_read(const ds4_gpu_tensor *tensor, uint64_t offset, void *data, uint64_t bytes) {
    if (!tensor || !data || offset > tensor->bytes || bytes > tensor->bytes - offset) return 0;
    return cuda_ok(cudaMemcpy(data, (const char *)tensor->ptr + offset, (size_t)bytes,
                              cudaMemcpyDeviceToHost), "tensor read");
}

Values read at the breakpoint (-c 4096 -p "Hi"):

Symbol Value
n_tokens 19 (the chat template makes even "Hi" 19 tokens)
hc_cur->bytes (requested bytes) 1,245,184 = 19 × 4096 × 4 × 4
hc_cur->ptr 0x7fbc8d000000
g->batch_hc_next->ptr 0x7fbc8d000000 (delta 0x0 — the view is not stale/dangling)
g->batch_hc_next->bytes 134,217,728 (128 MiB; the read uses < 1 % of it)
output_hc (host destination) 0x55555809f660 (plain malloc in dist_coordinator_eval_span, ds4_distributed.c:2708)

So: valid device source, in-bounds length, ordinary pageable host destination.


Localization: manual hipMemcpy at the breakpoint

Rather than guess, I stopped at ds4.c:55032 and called hipMemcpy(dst, src, n, 2 /*D2H*/)
directly from gdb.

Copy size Source Result
4,096 B batch_hc_cur->ptr OK (returned 0)
4,096 B hc_cur->ptr OK (returned 0)
65,536 B batch_hc_cur->ptr OK (returned 0)
262,144 B batch_hc_cur->ptr OK (returned 0)
524,288 B batch_hc_cur->ptr OK (returned 0)
1,048,576 B batch_hc_cur->ptr OK (returned 0)
1,245,184 B hc_cur->ptr SIGSEGV (19-token prompt readback)
1,638,400 B hc_cur->ptr SIGSEGV (25-token prompt readback)
1,638,400 B batch_hc_cur->ptr (a different, known-good buffer) SIGSEGV

Conclusion: within the ds4 process, the fault is a function of the single-copy size (> 1 MiB),
not of the source buffer, not of the tensor bookkeeping, and not of alignment. 4 KiB from the exact
address that fails at 1.5 MiB succeeds. (Remember the Update section: a bare HIP program is fine at
16 MiB, so this table characterizes the ds4 process, not hipMemcpy.)


Why single-rank GLM 5.3 Flash works and PP does not

The coordinator reads back the entire prompt's hidden state to ship it over TCP:

bytes = n_tokens * DS4_N_EMBD * DS4_N_HC * 4 = n_tokens * 65,536

so any prompt longer than 16 tokens exceeds 1 MiB. A chat-templated "Hi" is already 19
tokens → 1,245,184 B → crash. Longer prompts are proportionally worse.

Note this is about the readback size, and more fundamentally about the fact that single-rank
inference never performs this readback at all
: output_hc is only passed on the layer-slice /
distributed path (ds4_session_eval_layer_slice). Single-rank generation calls
glm_graph_forward_indexed_tokens with output_hc = NULL and only reads back logits
(~593 KiB), which is why the same build/ROCm/machine is fine single-rank — independent of where the
size boundary happens to sit.

Single-rank GLM 5.3 Flash is fine on the very same build, same ROCm, same machine:

$ ./ds4 --rocm -m gguf/GLM-5.3-Flash-Q4_K.gguf --ssd-streaming --ctx 4096 -p "Say hello in one short sentence."
...
processing 25 input tokens: 25/25 (100.0%)
Hello there!
ds4: prefill: 0.41 t/s, generation: 0.44 t/s

Ruled out

  • Context size — crashes at -c 4096 and -c 8192.
  • Server layer — ds4 --role coordinator (CLI) crashes identically to ds4-server.
  • Race / concurrency — AMD_SERIALIZE_KERNEL=3 HIP_LAUNCH_BLOCKING=1 HSA_ENABLE_SDMA=0
    changes nothing.
  • Pinned vs pageable host — ds4.c contains no cudaMallocHost for this path; single-rank
    readbacks are pageable too and work.
  • Bad pointer / OOB in ds4 — source pointer equals the base of a live 128 MiB allocation
    (delta 0x0); requested bytes are 1.5 MiB.
  • Managed memory — batch_hc_* workspace buffers come from ds4_gpu_tensor_alloc
    (cudaMalloc), not ..._alloc_managed.

Likely mechanism (hypothesis)

The crash is in the unlock / make-unresident path, i.e. HIP's hipMemcpy appears to switch to a
different implementation above ~1 MiB that locks/unlocks the host region (or reshapes residency),
and that path mismatches with the KFD/VM bookkeeping on gfx1151 under ROCm 10.0. Two candidate
directions:

  1. hsa_amd_memory_unlock() / MakeMemoryUnresident() should not fault when the region was never
    GPU-mapped — vm_find_object() should return NULL and the caller should handle it, rather than
    walking a corrupted table.
  2. The >1 MiB hipMemcpy D2H path may be picking a copy engine / staging sequence that leaves the
    FMM map inconsistent on this APU.

I have not disassembled libamdhip64.so.7 and, after the Update controls above, I can no longer
claim a specific HIP-side trigger — a bare HIP program does 16 MiB D2H without issue, so the fatal
part is some ds4-process-specific state. What is solid: the crash site (ROCr's host-unlock /
make-unresident path), and the fact that it is deterministic inside the ds4 process. Treat the
mechanism as open.


Suggested fixes

ds4 side (workaround, unblocks PP today):

  • Chunk the coordinator's hidden-state readback in
    glm_graph_forward_indexed_tokens / ds4_gpu_tensor_read call site into pieces of ≤ 1 MiB
    (e.g. per ≤16 tokens), or
  • Stage the readback through a pinned host buffer (may also select a different HIP path), or
  • Read back with several smaller hipMemcpy calls / a stream-ordered sequence.

Because the threshold is exactly at a power-of-two boundary (2^20), chunking at 1 MiB should be
sufficient, and it is a small, local change.

ROCm side: the unlock/unmap path should be robust to unmapped regions (see hypothesis above).


Honest caveat about support status

I am aware that the docs describe GLM 5.3 Flash on ROCm via the single-rank SSD-streaming path
(STRIX_HALO.md: "Flash's ROCm resident and pipeline paths should not be confused with the GLM
SSD-streaming path"
), that glm53-q2 is the artifact marked "ROCm also supported", and that
two-machine GLM is documented as ownership-aware TP (Metal) while ROCm TP is rejected by the
source gate. So glm53-q4 + ROCm pipeline parallelism is very likely an untested combination — this
report is not a complaint about a promised feature being broken. I am filing it because:

  • the failure mode is silent-ish and drastic (SIGSEGV with core, after a healthy-looking
    start-up and a complete route), which is expensive to diagnose, and
  • the root cause is not specific to GLM: I was able to reproduce it as a pure
    hipMemcpy D2H > 1 MiB crash, independent of the model and of the source buffer, so it can bite
    any future ROCm PP path (or any readback of more than one token's hidden state).

Artifacts available on request

  • Full gdb transcripts (backtrace, registers, faulting instruction, the manual-copy matrix).
  • Coordinator and worker logs for the run (coordinator.log, worker.log).
  • Exact --help distributed output of the build.

Happy to run any additional experiment (e.g. a reduced repro, --dist-activation-bits, different
--layers split, or a two-rank test with a smaller model) — the cluster is idle and reproducible.


Update 2 — the two failure modes are mutually exclusive, and the ROCm side is avoidable from ds4

Further experiments. I swept the per-span readback size on the coordinator with the existing
--dist-prefill-chunk knob (same two ranks, same model, -c 4096, everything else unchanged):

--dist-prefill-chunk per-span readback result failure mode
default (≥ prompt) whole 19-token prompt = 1.22 MiB exit 139 ROCm HSA vm_find_object SIGSEGV (the original defect)
16 1.00 MiB exit 139 same
12 768 KiB exit 139 same
10 640 KiB exit 134 ds4 heap corruption: malloc(): unsorted double linked list corrupted
8 512 KiB exit 134 ds4 heap corruption — reproduced on both the pipelined path and the DS4_DIST_DISABLE_PREFILL_PIPELINE=1 fallback loop

Two conclusions:

  1. The HSA crash is avoidable from the ds4 side. Below ~768 KiB per span the hsa_amd_memory_unlock
    SIGSEGV no longer occurs, which suggests it is the large single D2H readback in this process
    that trips the host-unlock/unmap path, not "ROCm cannot do this".
  2. A second, independent defect shows up instead: ds4 corrupts its own heap on the chunked-span
    path.
    glibc aborts; the thread that actually trips is ROCr's AsyncEventsLoop, i.e. it is the
    victim of someone else's out-of-bounds write, not the culprit. Two different glibc messages seen
    (unsorted double linked list corrupted, malloc_consolidate(): invalid chunk size,
    unaligned fastbin chunk detected).

⇒ There is no flag combination that makes PP run: one failure mode brackets the other from
above and below. Getting PP working needs a source-level fix to the heap corruption (or to whatever
else in the distributed span machinery writes out of bounds), not a configuration change.

Why the default always takes the single-span path

From ds4_distributed.c:

static bool dist_coordinator_can_pipeline_prefill(..., uint32_t n_tokens, uint32_t chunk_cap) {
    if (getenv("DS4_DIST_DISABLE_PREFILL_PIPELINE")) return false;
    ...
    if (chunk_cap == 0 || n_tokens <= chunk_cap) return false;   /* <- chunk_cap defaults to the session prefill cap */

With the default, chunk_cap is the session prefill cap (thousands), so n_tokens <= chunk_cap is
always true for an ordinary prompt, the pipelined path is never taken, and
dist_coordinator_prefill_prompt falls through to the plain loop — which then evaluates the whole
prompt in one span, i.e. exactly one n_tokens * 65536-byte D2H readback. That is the copy
that dies.

A note on localising the heap corruption

An ASan build would be the obvious next step, but it does not link with this toolchain:

ld.lld: error: ds4_cli.o: SHT_STRTAB string table section [index 37] is non-null terminated
ld.lld: error: undefined symbol: __asan_report_store8        (and the other __asan_* symbols)

(i.e. ld.lld rejects clang's ASan-instrumented objects; the next attempt would be -fuse-ld=bfd
plus linking libasan). Minimal repro for whoever wants to chase it:
./ds4 --rocm --role coordinator --layers 0:22 --listen <ip> 9911 -m <glm53 q4> -c 4096 --dist-prefill-chunk 10 -p "Hi".

Lingua principale
C
Stelle
24.4k
Fork
2.4k
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di antirez/ds4

Tutte le issue di antirez/ds4

Issue simili

Altre issue su C

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.