cuda_buffer: device identity is the per-process CUDA ordinal, not the GPU UUID (wrong IPC decision under CUDA_VISIBLE_DEVICES)

Open
#39 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
cpp

Research direction

Start with cuda_buffer/src/host_endpoint_manager.cpp and cuda_buffer_backend/src/cuda_buffer_backend_plugin.cpp, then trace device identity through cuda_buffer_ipc_manager.cpp and the shared memory registry. Check how endpoint and descriptor device IDs are chosen, compared, and used for cuMemSetAccess; the issue describes two multi-GPU cases but notes they have not been reproduced. Done means IPC decisions use physical device identity and mismatches fall back without dropping message data.

Written by the indexing model from the issue text.

Description

Generated by Generative AI: drafted with Claude (Anthropic) from a human-reviewed code reading; the code references below were checked against main @ c0c9df3.

Operating System: Ubuntu 24.04.4 LTS, x86_64

ROS version or commit hash: Lyrical; ros-lyrical-cuda-buffer / cuda-buffer-backend 0.1.2, and source main @ c0c9df3

RMW implementation: any (observed paths are in the backend, not the RMW)

Hardware / CUDA: RTX 5090, driver 580.167.08, CUDA 13.2 runtime (minor-version compatibility)

Summary

cuda_buffer identifies a process's GPU by its CUDA runtime ordinal, and compares ordinals across processes to decide whether a peer can import a VMM descriptor. Ordinals are per-process: they depend on each process's CUDA_VISIBLE_DEVICES (and CUDA_DEVICE_ORDER), so the same ordinal can name different physical GPUs in two processes, and the same GPU can have different ordinals.

Note: this comes from code reading. I have not reproduced it, because I only have a single-GPU machine.

Code

  • cuda_buffer/src/host_endpoint_manager.cpp:171-175 stores the endpoint's device as cudaGetDevice(). The calling thread gets that value when the first HostEndpointManager is created, and it is then published in the shared-memory registry as device_id.
  • cuda_buffer_backend/src/cuda_buffer_backend_plugin.cpp:77 gives the same-host import decision: peer.device_id == manager.get_device_id() && peer.uid == manager.get_uid().
  • cuda_buffer_backend_plugin.cpp:194 sets descriptor->device_id = cuda_impl->get_device_id(), which is also an ordinal. :271 then compares it to the importer's cudaGetDevice().
  • cuda_buffer_ipc_manager.cpp:553-563 calls cuMemSetAccess for the importer's current ordinal.

Steps to reproduce (expected; needs 2 GPUs)

  1. On a 2-GPU host, start a publisher of a message with a CUDA-backed uint8[] under CUDA_VISIBLE_DEVICES=1, and a subscriber in another process (same uid) under CUDA_VISIBLE_DEVICES=0. Both report ordinal 0, but they are on different GPUs.
  2. Start a publisher with CUDA_VISIBLE_DEVICES=0,1 that calls cudaSetDevice(1) before creating its node, and a subscriber with CUDA_VISIBLE_DEVICES=1. The GPU is the same, but the ordinals are 1 and 0.

Expected behavior

The backend sends a CUDA descriptor only when both endpoints are on the same physical GPU (or on GPUs that can actually map each other's memory), and it falls back to CPU only when they cannot.

Actual behavior (from code)

  • Case 1 (different GPUs, both ordinal 0): can_import_descriptor returns true, so the publisher sends a descriptor. On the subscriber, descriptor->device_id == local_device_id also passes. The import then maps memory that belongs to the other GPU and calls cuMemSetAccess for the local GPU. Without P2P this should fail. The catch at cuda_buffer_backend_plugin.cpp:321-332 then logs IPC import failed, falling back to CPU / Dropping stale descriptor and hands the subscriber an empty buffer, so the message arrives with no data. With P2P it may instead succeed and silently read over the interconnect.
  • Case 2 (same GPU, different ordinals): :77 returns false, so create_descriptor_with_endpoint returns nullptr. Every message then takes the CPU wire format, with no warning. That is a full device-to-host copy per message, which for multi-camera 4K uint8 frames is tens of MB per message.
  • A related ambiguity: because the endpoint device is captured from the thread that first creates an endpoint, a process that publishes from buffers on several GPUs (or calls cudaSetDevice after node creation) advertises one ordinal that may not match the buffers it sends.

Suggested fix

Identify devices by GPU UUID (cudaDeviceProp::uuid / cuDeviceGetUuid) rather than by ordinal:

  • Store the UUID in the endpoint registry slot and in CudaBufferDescriptor, which can keep device_id for the local ordinal.
  • In can_import_descriptor, compare UUIDs, and map the descriptor's UUID to a local ordinal on import. Use that ordinal for cuMemSetAccess, or fall back cleanly when no local device matches.
  • Derive the descriptor's device from the buffer's allocation (pool->get_device_id() → UUID), not from the thread's current device.
  • Consider logging a one-time WARN when a same-host peer is downgraded to CPU because of a device mismatch, so that case 2 is visible.

The existing CUDA_BUFFER_DEVICE_ID_OVERRIDE test hook overrides the ordinal that is being compared, so it does not exercise either case. A UUID override hook would let both cases be tested on one GPU.

Dominant language
C++
Stars
27
Forks
13
Avg merge
21d 23h
Merged PRs (30d)
1

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from ros2/rosidl_buffer_backends

All issues in ros2/rosidl_buffer_backends

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.