Skip to content

UCP/UCT/CUDA: Avoid gdr_copy for non gdr capable memory - #12039

Merged
tvegas1 merged 9 commits into
openucx:masterfrom
tvegas1:gdr_copy_peer_pin
Oct 9, 2026
Merged

tvegas1 merged 9 commits into
openucx:masterfrom
tvegas1:gdr_copy_peer_pin

Conversation

@tvegas1

@tvegas1 tvegas1 commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

What?

Do not use gdr_copy for memory it cannot pin: memory localized to a GPU locality domain, and stream-ordered (memory pool) allocations. Let the memory type endpoint pick another RMA lane instead of aborting.

Replaces #11759 and #12004.

No added memory type query on the proto v2 path, as the datatype iterator already carries the flags (confirmed performance gap is within noise, 0.3%).

Why?

Both abort on send:

gdr_copy_md.c:215 UCX  ERROR GPU memory pin failed. length 65536 ret 22
dt.c              Fatal: failed to register buffer with mem type domain cuda

gdr_copy pins through nvidia_p2p_get_pages, which refuses memory the driver did not place as GDR-capable. Registrability cannot discriminate them, as an exportable memory pool exports a dma_buf fd and stays registrable.

How?

  • Add UCS_MEM_FLAG_PEER_MEM_PINNABLE, cleared by cuda_copy for both cases and required by gdr_copy, as ib_md already does for UCS_MEM_FLAG_REGISTRABLE.
  • ucp_mem_type_pack() / unpack() pick the first mem type RMA lane whose required_mem_flags the buffer satisfies.

gdr_copy pinning fails with EINVAL for memory localized to a GPU
locality domain and for stream-ordered allocations, because
nvidia_p2p_get_pages refuses memory the driver did not place as
GDR-capable. Registrability cannot discriminate them, as an exportable
memory pool is registrable.

Add an orthogonal UCS_MEM_FLAG_PEER_MEM_PINNABLE flag, cleared by
cuda_copy for both cases and required by gdr_copy. Select the mem type
endpoint RMA lane by the buffer memory flags, instead of always taking
the first lane.

The datatype iterator already carries the flags, so the proto v2 path
adds no memory type query. The remaining callers pass NULL, and the
flags are resolved only if a memory domain requires them.
@svc-nvidia-pr-review

Copy link
Copy Markdown

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

Drop the registrability assertion from the localized memory test, as
exporting a dma_buf fd for such memory is platform dependent, and remove
the github reference from its comment.

Fix two comments in test_ucp_mem_type which still described selecting the
lane by a memtype cache lookup and a quiet registration attempt, instead
of resolving the memory flags once on the lane which requires them.

Update the copyright year of the modified files.
@tvegas1
tvegas1 force-pushed the gdr_copy_peer_pin branch from 7b23b60 to ed89e64 Compare October 7, 2026 14:05
@svc-nvidia-pr-review

Copy link
Copy Markdown

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

Comment thread src/uct/cuda/cuda_copy/cuda_copy_md.c Resolved
Comment thread src/ucp/dt/dt.c Resolved
Comment thread test/gtest/ucp/test_ucp_mem_type.cc Resolved
Comment thread src/ucs/memory/memory_type.h Resolved
@svc-nvidia-pr-review

Copy link
Copy Markdown

Residual coverage gaps worth noting: the gdr_copy_reg_async_cuda_fail test asserts a specific driver failure (UCS_ERR_IO_ERROR) for stream-ordered memory, which is hardware/driver dependent (though it mirrors the existing gdr_copy_reg_cuda_pcie_pin_fail pattern), and there is no test for the host-located VMM case in finding 1.

@tomerg-nvidia tomerg-nvidia left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Also address the bot comments

Comment thread src/ucp/dt/dt.c Resolved
Comment thread src/ucp/dt/dt.c Resolved
@svc-nvidia-pr-review

Copy link
Copy Markdown

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

@tvegas1
tvegas1 requested a review from tomerg-nvidia October 7, 2026 20:00
tomerg-nvidia
tomerg-nvidia previously approved these changes Oct 8, 2026
tomerg-nvidia
tomerg-nvidia previously approved these changes Oct 8, 2026
Several places fill in memory flags for a buffer whose capabilities were
never detected, and all of them hardcoded UCS_MEM_FLAG_REGISTRABLE. Now
that UCS_MEM_FLAG_PINNABLE gates gdr_copy, such a buffer would never be
considered pinnable, silently disabling gdr_copy.

Add UCS_MEM_FLAGS_DEFAULT with all capabilities a memory domain can
require, and use it as the undetected default. Detection results are
left untouched, so a buffer the cuda_copy MD identifies as localized or
mempool-backed still reports no PINNABLE flag.

UCS_MEM_FLAG_MEMTYPE_COPY_INTER_NODE is excluded from the default, as it
is not part of any required_mem_flags and must only be reported when
actually detected.
Comment thread src/uct/base/uct_md.c Resolved
Co-authored-by: tomerg-nvidia <tgilad@nvidia.com>
tomerg-nvidia
tomerg-nvidia previously approved these changes Oct 9, 2026
@svc-nvidia-pr-review

Copy link
Copy Markdown

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

Only gdr_copy requires the pinnable flag, and it only registers CUDA device
memory, so rename it to UCS_MEM_FLAG_GDR_CAPABLE and report it only when
cuda_copy detects it, instead of assuming it by default for every memory
type. All the defaults go back to UCS_MEM_FLAG_REGISTRABLE, so
UCS_MEM_FLAGS_DEFAULT is removed.

Detect the flag from what the driver reports: the gpuDirectRDMACapable flag
of VMM allocations, and the CU_POINTER_ATTRIBUTE_IS_GPU_DIRECT_RDMA_CAPABLE
attribute queried together with the other pointer attributes otherwise.
Guessing from the allocation kind missed device VMM allocated without
gpuDirectRDMACapable, host-located VMM, and all memory allocated under an MPS
MLOPart device, where localized memory is reported as plain device memory.
The memory pool query and the localized marker are no longer needed.
@svc-nvidia-pr-review

Copy link
Copy Markdown

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

@tvegas1 tvegas1 changed the title UCP/UCT/CUDA: Avoid gdr_copy for non-pinnable memory UCP/UCT/CUDA: Avoid gdr_copy for non gdr capable memory Oct 9, 2026
tomerg-nvidia
tomerg-nvidia previously approved these changes Oct 9, 2026
Comment thread src/ucs/memory/memory_type.h Resolved
Co-authored-by: tomerg-nvidia <tgilad@nvidia.com>
@svc-nvidia-pr-review

Copy link
Copy Markdown

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

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.

3 participants