Skip to content

UCT/CUDA: Match IPC cache release to the map bypass predicate - #12153

Closed
nbellalou wants to merge 1 commit into
openucx:masterfrom
nbellalou:fix/cuda-ipc-symmetric-release
Closed

nbellalou wants to merge 1 commit into
openucx:masterfrom
nbellalou:fix/cuda-ipc-symmetric-release

Conversation

@nbellalou

Copy link
Copy Markdown
Contributor

What? / Why?

Use the same PID, PID namespace, and GPU UUID predicate to decide whether CUDA IPC map and unmap bypass the remote cache. This removes address equality from the release decision and makes it match the path that acquired the reference.

Master already restricts the equal-address shortcut to the local process and PID namespace (#11291). Map also checks the GPU UUID; unmap still uses virtual-address equality. This change makes those decisions consistent for every mapping.

How?

  • Share the mapping-locality check between map and unmap, using the existing process-identity helper.
  • Copy the exporter GPU UUID into asynchronous scalar and SGL mapping metadata and device-memory-element release handles. Pass it directly from the live rkey when releasing its mapping.
  • Preserve the current cache locking and missing-cache handling, and return UUID-query failures from unmap.
  • Cover the locality predicate, invalid-device handling, local map/unmap, and completion that releases its rkey and clears the CUDA context.

Validation

  • CUDA-enabled developer builds on A100 (CUDA 13.3) and GB200 (R620/CUDA 13.5).
  • All five added tests execute and pass on both setups, including three shuffled repeats.
  • Selected existing CUDA IPC tests run with default same-process reachability; the loopback performance test runs separately with UCX_CUDA_IPC_ENABLE_SAME_PROCESS=y. The selection excludes mkey_pack_mempool and mnnvl_disabled.
  • The loopback endpoint-setup failure with same-process IPC disabled was reproduced on unmodified master source and passes with the required option enabled.

The selected IPC coverage is 613 cases per setup, split into 612 tests using default reachability and one loopback test with same-process IPC enabled: A100 has 278 executed passes / 335 skips; GB200 has 282 executed passes / 331 skips. Both final groups have zero failures.

CUDA-disabled developer build and gtest build pass; none of the five CUDA-only tests are registered in that build.

The tests verify the identity predicate and metadata lifetime; they do not establish a real same-process cross-GPU equal-VA import.

@svc-nvidia-pr-review

Copy link
Copy Markdown

🤖 Starting review — findings will be posted here when done.

const CUuuid *uuid, CUdevice cu_dev,
int *is_local_p)
{
CUuuid local_uuid;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pls check the pid first and query the UUID only when it matches - every unmap now makes a cuDeviceGetUuid() driver call from the completion path (and per sgl entry), while for a remote peer the pid/pid_ns alone already decides.

Suggested change
CUuuid local_uuid;
CUuuid local_uuid;
ucs_status_t status;
if (!uct_cuda_ipc_is_rkey_local(pid, pid_ns)) {
*is_local_p = 0;
return UCS_OK;
}
status = UCT_CUDADRV_FUNC_LOG_ERR(cuDeviceGetUuid(&local_uuid, cu_dev));
if (status != UCS_OK) {
return status;
}
*is_local_p = (memcmp(local_uuid.bytes, uuid->bytes,
sizeof(local_uuid.bytes)) == 0);
return UCS_OK;

(docs/OptimizationStyle.md: "Cache expensive capability queries when the result is stable"; this also keeps the map path from paying for it on every operation.)

return;
/* Match the cache bypass in uct_cuda_ipc_map_memhandle. */
status = uct_cuda_ipc_is_local_mapping(pid, pid_ns, uuid, cu_dev, &is_local);
if ((status != UCS_OK) || is_local) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on a cuDeviceGetUuid() failure we return before the cache lookup, so region->refcount is never decremented: the region stays pinned (uct_cuda_ipc_cache_evict_lru skips refcount>0) and is never closed, and all callers ignore the status. can we fall through to the cache path and treat a failed query as not-local, like uct_ze_ipc_unmap_memhandle which only returns early when there is nothing to release?

ucs_sys_ns_t pid_ns;
uintptr_t d_bptr;
const void *mapped_addr;
CUuuid uuid;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which case does the old (d_bptr == mapped_addr) && uct_cuda_ipc_is_rkey_local() check get wrong? a same-process import always lands on a fresh VA, so the two conditions look equivalent, and the UUID now has to be copied into the event desc, every sgl entry and the release handle.


status = UCT_CUDADRV_FUNC_LOG_ERR(cuDeviceGetUuid(&uuid, cu_dev));
status = uct_cuda_ipc_is_local_mapping(key->pid, ext_key->pid_ns,
&key->uuid, cu_dev, &is_local);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: pls align continuation args to the open parenthesis (one more space); same in the new uct_cuda_ipc_is_local_mapping() declaration and in the new tests.

@svc-nvidia-pr-review

Copy link
Copy Markdown

PR size and scope are fine (~200 added lines, fix + tests only).

The new tests only exercise the same-process/same-device bypass and the invalid-device error path. The behavior change for a real remote peer (where the UUID differs) is covered only indirectly by the existing cuda_ipc UCP/UCT suites; unmap_equal_address_invalid_device locks in the early-return behavior questioned in comment 2, so it would need updating if that is changed.

cuda_ipc_event->uuid is intentionally left unset in the sgl path (sgl_mapping != NULL short-circuits complete_event), consistent with pid_ns there - not worth a comment.

No secrets in the diff.

@nbellalou nbellalou closed this Oct 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants