Repository navigation
UCT/CUDA_IPC: Support VMM with multiple memory allocations - #11283
tomerg-nvidia wants to merge 3 commits into
Conversation
4920050 to
250e476
Compare
| uct_cuda_ipc_event_desc_t); | ||
| ucs_status_t status; | ||
|
|
||
| if (cuda_ipc_event->mapped_addr == NULL) { |
There was a problem hiding this comment.
Can we integrate VMM_MULTI in the cuda_ipc cache, releasing some refcnt here? This could enable LRU as implemented in #11245, to avoid VA exhaustion on some platforms?
There was a problem hiding this comment.
Done, now the unpack doesn't import the handles, it happens in the memhandle open path so it could be cached. This does have some drawbacks though: I'm using the first chunk's buffer id for the cache, so it could be that the mapping later changes but we still get a cache hit
| } | ||
|
|
||
| status = UCT_CUDADRV_FUNC_LOG_ERR( | ||
| cuMemcpyHtoD(meta_dev_ptr, host_chunks, meta_size)); |
There was a problem hiding this comment.
do we need to use one of our internal stream?
There was a problem hiding this comment.
I don't have access to the internal streams in this function, as the iface is needed to get the stream which I don't have at unpack. I can maybe create a new async stream for this, what do you think?
| #if HAVE_CUDA_FABRIC | ||
| if (unpacked->super.super.ph.handle_type == | ||
| UCT_CUDA_IPC_KEY_HANDLE_TYPE_VMM_MULTI) { | ||
| uct_cuda_ipc_vmm_contig_cleanup(unpacked); |
There was a problem hiding this comment.
I have doubts about the performance of this solution.
We do not unmap other types of handles in rkey release for this reason. Since opening a handle exported from another process is a time-consuming operation. Probably we should do the same way for this new handle type.
| goto err_pop_ctx; | ||
| } | ||
|
|
||
| status = uct_cuda_ipc_create_contig_mapping(unpacked, |
There was a problem hiding this comment.
Is it possible to unify the flow with existing types?
The mapping is done in get/put function. And unmapping is done via the event callback.
|
Make sure to update the copyright years at the top of all the changed files |
779a4c6 to
250e476
Compare
|
@tomerg-nvidia quick scope question. Does the multi-chunk VMM fix here benefit the IB transport, or is it scoped strictly to cuda_ipc / fabric memory? I'm hitting the same multi-chunk VMM failures on the IB side with |
e3b2860 to
ce5fc24
Compare
The arena's docs presented UCX_CUDA_COPY_REG_WHOLE_ALLOC=off as the complete deployment precondition and described multi-handle single-MR registration as validated without naming a transport. Both are true only on dmabuf/IB. On cuda_ipc a fabric handle names one cuMemCreate allocation, so a single MR over a multi-allocation arena publishes an rkey covering only the first chunk. - scope the cuda_copy knob in both env tables and in vmm/README.md - add a Transport support section and a cuda_ipc known limitation - fix the register_arena docstring, which asserted validation directly above the fallback that same function performs - point at openucx/ucx#11283 for the upstream cuda_ipc fix Signed-off-by: Nicolas 'Pixel' Noble <nicolas@nobis-crew.org>
| return status; | ||
| } | ||
|
|
||
| static ucs_status_t uct_cuda_ipc_open_memhandle_vmm_multi( |
There was a problem hiding this comment.
Observed cuda_ipc_cache.c:721 Assertion 'pgt_region != NULL' failed. when trying this PR, which could be related.
could put_region be calling cache_region_destroy / invalidate_regions on a mapping that still has refcount > 0 (same d_bptr + new buffer_id, or overlapping VMM_MULTI)? if so, can we keep in-use regions until last unmap, or at least assert on refcount when removing entries?
also, if we pack again with a wider range, vmm_multi_meta_cleanup rebuilds meta — is that safe for peers still holding the old rkey?
There was a problem hiding this comment.
Relevant not checking refcount: uct_cuda_ipc_cache_invalidate_regions , uct_cuda_ipc_cache_region_remove and uct_cuda_ipc_cache_region_destroy.
There was a problem hiding this comment.
Two cuda_ipc GETs use different VMM_MULTI rkeys made of 20MB chunks. They overlap, and the second ends after the first (30 chunks [0x3720000000, 0x3745800000) vs 2 chunks [0x3744400000, 0x3746c00000)).
The shared 20MB chunk is the same remote VA, so that chunk’s buffer_id should match; the cache still compares the sum of all chunk ids (30 vs 2), treats the second key as stale, destroys the first mapping without refcount check, and re-inserts only the shorter span. First GET completion then unmaps a d_bptr that is gone (cuda_ipc_cache.c:721).
I think ucp_rkey_pack/unpack with area that partly overlap is probably valid usage.
Could we cache the individual chunks with their buffer_id instead and adapt caching logic to check various buffer_id/add missing ones?
Factor the balancing mechanics of ucs_interval_tree_t into a reusable intrusive red-black tree, ucs_rbtree_t, and port the interval tree onto it. The caller performs its own descent and hands the attachment point to ucs_rbtree_insert_at, so the ordering key stays in the embedding struct. An optional augmentation callback recomputes data a node derives from its subtrees, which the interval tree does not use and leaves NULL. The only behavior that changes is node identity on removal: the successor is relinked rather than having its interval copied into the removed node, so the node object a caller names is the one removed. Interval tree nodes are pool allocated and never referenced from outside, so this is not observable here; it is what lets a later user hold node pointers across unrelated removals.
Add ucs_interval_map_t, a map of half-open intervals to caller-owned objects. Unlike ucs_interval_tree_t, which merges, it keeps overlapping intervals distinct: inserting [0,4) and [2,6) yields two entries, both findable. It is a ucs_rbtree_t ordered by interval start and augmented with each subtree's maximum end, so finding an interval that contains a given range costs O(log n). Nodes are intrusive and caller-allocated, and removal never relocates one, so removal by a held pointer needs no search.
A VMM buffer whose range spans more than one physical allocation could not be exported: the packed key described only the allocation containing its base, so a peer received a key covering less memory than was registered. Publish the chunk layout instead. At pack time the range is expanded to whole allocations, their descriptors are written to a GPU buffer, and its fabric handle travels in the key together with an inline description of the layout. At unpack the peer fetches the descriptors, and at import it reserves one contiguous address range and maps every chunk into its slot, so the rest of the transport sees a single base pointer. Imported views are cached per peer and indexed by remote range, which lets a key nested inside an already-imported range reuse it instead of re-importing. Views may overlap, so they are held in an interval map rather than the page table. A view is verified per chunk on every hit, by base address and buffer ID, so a recycled remote address is detected rather than reused. Teardown waits for outstanding references, since an operation in flight holds a pointer into the reservation.
ce5fc24 to
e4f418a
Compare
|
🤖 Starting review — findings will be posted here when done. |
| } | ||
| #endif | ||
| goto err_free_rkey_handle; | ||
| err_pop_ctx: |
There was a problem hiding this comment.
blocker: err_pop_ctx is only reachable from inside #if HAVE_CUDA_FABRIC, so a non-fabric CUDA build (CU_MEM_HANDLE_TYPE_FABRIC not declared) fails with -Wunused-label, and BASE_CFLAGS has -Wall -Werror.
| err_pop_ctx: | |
| goto err_free_rkey_handle; | |
| #if HAVE_CUDA_FABRIC | |
| err_pop_ctx: | |
| if (cuda_device != avail_cuda_device) { | |
| uct_cuda_ctx_primary_pop_and_release(avail_cuda_device); | |
| } | |
| #endif |
| return 0; | ||
| } | ||
|
|
||
| for (i = 0; i < unpacked->num_chunks; i++) { |
There was a problem hiding this comment.
uct_cuda_ipc_multi_cache_verify() runs on the data path — every put/get goes through uct_cuda_ipc_get_remote_address() -> uct_cuda_ipc_map_memhandle() -> _multi_cache_get() — and this loop is O(num_chunks) under the global cache write lock. docs/OptimizationStyle.md asks to keep such lookups O(1); can we validate staleness with a single value (e.g. a generation/id stored in the metadata) instead of comparing every chunk?
| } | ||
|
|
||
| /* Peers may unpack any published metadata until memh deregistration. */ | ||
| ucs_list_add_tail(&key->vmm_multi_list, &meta->list); |
There was a problem hiding this comment.
Each mkey_pack() for a range not contained in an already published meta allocates a new device buffer (rounded up to the allocation granularity), exports a fabric handle and does an HtoD copy, and the list is only released at mem_dereg(). What bounds the number of entries per lkey for an app that packs many different sub-ranges of the same registration?
| status = uct_cuda_ipc_mkey_pack_vmm_multi_chunk(memh, key, address, | ||
| length, &meta); | ||
| if (status == UCS_OK) { | ||
| packed->ph.handle_type = |
There was a problem hiding this comment.
does this break wire compatibility? An older peer that gets UCT_CUDA_IPC_KEY_HANDLE_TYPE_VMM_MULTI falls into the default: case of uct_cuda_ipc_open_memhandle() and logs ucs_error("unsupported key handle type") for every rkey before declaring the peer unreachable. Is there any negotiation, or should the packer keep the old VMM type when the new type cannot be understood?
| #if HAVE_CUDA_FABRIC | ||
| uct_cuda_ipc_multi_cache_purge(cache, close_handles); | ||
| #endif | ||
| ucs_list_head_init(&cache->lru_list); |
There was a problem hiding this comment.
uct_cuda_ipc_cache_purge() and uct_cuda_ipc_multi_cache_purge() already decrement num_regions/total_size and unlink every region from lru_list, so this reset has no distinct state transition to perform. Per the root AGENTS.md rule on repeated reset logic, pls drop it.
| ucs_interval_tree_find_overlap(ucs_rbtree_node_t *rb_node, | ||
| ucs_interval_tree_range_t range) | ||
| { | ||
| ucs_interval_node_t *node = ucs_interval_tree_node(rb_node); |
There was a problem hiding this comment.
minor: ucs_derived_of() is applied to rb_node before the NULL check below. It happens to work because super is at offset 0, but pls move the conversion after the check so the code does not rely on that.
| /** | ||
| * @brief Whether the tree holds no nodes | ||
| */ | ||
| static UCS_F_ALWAYS_INLINE int ucs_rbtree_is_empty(const ucs_rbtree_t *tree) |
There was a problem hiding this comment.
minor: ucs_rbtree_is_empty() has no callers; pls remove it until something needs it.
| rkey_a.super.pid = getpid() + 100000; | ||
| rkey_b.super.pid = rkey_a.super.pid; | ||
| rkey_request.super.pid = rkey_a.super.pid; | ||
| unpacked_a.super = rkey_a; |
There was a problem hiding this comment.
minor: these consecutive assignments are split into two alignment columns; pls align them all to the longest LHS (unpacked_request.super.pid_ns) per docs/CodeStyle.md.
|
This PR adds roughly 2,600 lines across two independent changes: a generic
The unrelated fixes bundled in (pgtable cleanup leak in
Coverage gap: Coverage gap: Coverage gap: the multi-chunk data path itself is only covered by |
|
🤖 CI Triage Agent — TL;DR: The Coverity gate failed (exit code 4) on 4 new defects introduced by this PR's own commit — 3 × CHECKED_RETURN for unchecked Full analysisSummary: Root cause: All 4 defects are in files last modified by the PR commit itself (
There is no infrastructure/timeout problem: compilation emitted 748/748 units successfully and analysis completed in 00:23:45 with continuous progress. Implicated commit: File: Suggested fix:
Related: PR #11283 (the failing PR); prior work on the same files: #11877, #11461, #11183; related rkey-release change #11288.
|
What?
Add support for CUDA VMM allocations that span multiple underlying physical allocations (cuMemCreate chunks) in the cuda_ipc transport.
Why?
A user-visible VA range may be backed by several independently created and mapped VMM chunks. Currently, cuda_ipc only exports a single fabric handle per region, which covers just the first chunk. This means transfers involving multi-chunk VMM regions silently access only the first chunk's memory, producing incorrect results for offsets beyond the first chunk boundary.
How?
Introduce
UCT_CUDA_IPC_KEY_HANDLE_TYPE_VMM_MULTI. Duringmkey_pack, cuda_ipc detects when the requested VMM range spans multiple allocation buffer IDs, discovers the chunks covering the expanded VA range, exports each chunk’s fabric handle, and writes the chunk descriptors into a GPU-resident metadata buffer. A small GPU-resident header points to that descriptor buffer, and the header fabric handle is packed in the rkey.During
rkey_unpack, the receiver imports the metadata header, performs a blocking DtoH copy of the header, imports the chunk-descriptor buffer, and performs another blocking DtoH copy to fetch all chunk handles. The VMM_MULTI memhandle open path then imports and maps the chunks into one contiguous local VA range, which is cached like other cuda_ipc mappings.Notes
cuMemcpyAsyncoverhead.