From fb7a30cd848188a387a8cbf6220c06f4ab34aadf Mon Sep 17 00:00:00 2001 From: mici81 Date: Sun, 18 Oct 2026 14:13:45 +0000 Subject: [PATCH] libr4d: a refused IPC export is not fatal r4d_ar_ipc_alloc exports every collective buffer with hipIpcGetMemHandle. Beside another process holding the same cards it answers invalid argument while the allocation is fine, and HIPOK stopped the engine. libr4d's ranks are threads of one process and share the pointer itself, so the handle is never read: a refused export leaves it empty. Co-Authored-By: Claude Opus 5.5 --- libr4d/r4d_ar_oneshot_2rank_exact.hip | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/libr4d/r4d_ar_oneshot_2rank_exact.hip b/libr4d/r4d_ar_oneshot_2rank_exact.hip index 9d6a5137..37bbd373 100644 --- a/libr4d/r4d_ar_oneshot_2rank_exact.hip +++ b/libr4d/r4d_ar_oneshot_2rank_exact.hip @@ -300,10 +300,18 @@ long r4d_ar_ipc_alloc(long size, int finegrained, char* out_handle, int* out_len // The zeroes must land before the pointer reaches a peer, or its first push or flag store could // race the queued memset. HIPOK(hipStreamSynchronize(nullptr)); + // The handle is for an out-of-process peer. libr4d's ranks are threads of one process and share + // the pointer itself (r4d_ar_entry.hip), so a refused export is not fatal: beside another engine + // on the same cards hipIpcGetMemHandle answers invalid argument while the allocation is fine. hipIpcMemHandle_t h; - HIPOK(hipIpcGetMemHandle(&h, p)); - std::memcpy(out_handle, &h, sizeof(h)); - *out_len = (int)sizeof(h); + if (hipIpcGetMemHandle(&h, p) == hipSuccess) { + std::memcpy(out_handle, &h, sizeof(h)); + *out_len = (int)sizeof(h); + } else { + (void)hipGetLastError(); + std::memset(out_handle, 0, R4D_AR_HANDLE_BYTES); + *out_len = 0; + } return (long)p; } // r4d_p2p_copy2d as a kernel with a bounded workgroup count.