Repository navigation
[ROCm][c10d] Enable NCCL2 windows and enforce allocator provenance - #193282
chinmaydk99 wants to merge 5 commits into
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/193282
Note: Links to docs will display an error until the docs builds have been completed. ❌ You can merge normally! (3 Unrelated Failures), 1 Unclassified FailureAs of commit ef87be2 with merge base 6745886 ( UNCLASSIFIED FAILURE - DrCI could not classify the following job because the workflow did not run on the merge base. The failure may be pre-existing on trunk or introduced by this PR:
FLAKY - The following jobs failed but were likely due to flakiness present on trunk:
BROKEN TRUNK - The following job failed but were present on the merge base:👉 Rebase onto the `viable/strict` branch to avoid these failures
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
|
|
|
47ce4a0 to
c247d4f
Compare
jeffdaily
left a comment
There was a problem hiding this comment.
Requesting changes for three things:
-
Enforcement scope. The check only guards
WindowNCCL::tensor_register, butregister_mem_pool(pool, symm=True)also window-registers segments viaensureSegmentWindow, and on ROCm the RCCL fallback will still accept ordinary HIP allocations there (after whichputaccepts them as sources, since it only checkslookupSegmentWindow). Consider moving the ROCm check intoensureSegmentWindow(returnncclInvalidUsagefor non-ncclMemAllocsegments): it covers both entry points, and the existingNCCL_CHECKmessage intensor_registeralready matches the test regex, soisWindowRegistrationSegmentand the newTORCH_CHECKbecome unnecessary. One thing to decide: inregisterMemPool,ncclInvalidUsagewarns and keeps the plain registration instead of throwing; please confirm that's the semantic you want (and whether it matches what NCCL returns for non-ncclMemAllocmemory on NVIDIA). If you'd rather keep the current scope, document why the symm mempool path intentionally keeps the permissive fallback. -
Naming.
isWindowRegistrationSegmentreads as "already window-registered", which is whatlookupSegmentWindowanswers. It actually checks allocator provenance; rename to something likeisWindowEligibleSegment. (Moot if you take suggestion 1.) -
Duplication. This adds a third copy of the
upper_bound+ step-back range lookup (also inlookupSegmentWindowandensureSegmentWindow). Factor it into one locked helper.
Testing note: the un-skipped tests only run when the runtime RCCL is >= 2.29, which current ROCm CI images don't have, so this stays manually validated for now. Please note in the PR when CI coverage will pick this up.
Review drafted with an AI assistant; I reviewed and agree with the content.
e936137 to
eaa3641
Compare
34b30ca to
862b195
Compare
@jeffdaily All three are in. The throw-vs-warn call and the CI note are in the PR description.
CI. The limiter is GIN, not RCCL 2.29. CI coverage in the description has the split: preview runs live windows; 7.14 trunk skips them; mem-pool provenance runs on both. |
RCCL accepts ordinary HIP allocations for window registration, so track live ranges issued by the backend's ncclMemAlloc allocator and enforce allocator provenance before registration. Keep the policy ROCm-only so NVIDIA and shared allocator registration behavior remain unchanged. Test Plan: ``` python -m pip install -e . -v --no-build-isolation python test/distributed/test_c10d_window.py Nccl2WindowTest python test/distributed/test_c10d_nccl2.py ProcessGroupNCCL2MemPoolTest python test/distributed/test_c10d_nccl2.py ProcessGroupNCCL2Test.test_reduction_semantics lintrunner <changed files> ``` Validated on MI355X with HIP 7.15 and RCCL 2.30.4. NVIDIA runtime coverage is left to CI because the implementation changes are guarded by USE_ROCM.
Validate ncclMemAlloc provenance in the shared segment-window path so register_mem_pool(symm=True) cannot bypass the NCCL2 allocator contract. Use ncclInvalidArgument for allocator violations while preserving ncclInvalidUsage for transport-unavailable fallback behavior. Factor the containing-segment lookup into one locked helper and cover the symmetric mempool entry point with a ROCm regression test.
Document the provenance helper's exact match contract and assert PyTorch's stable registration error instead of a vendor error string. Co-authored-by: Cursor <[email protected]>
…ests register_mem_pool(symm=True) on ROCm rejected a non-ncclMemAlloc pool only after it had already inserted the pool into registeredMemPools_ and plain-registered its segments, because the provenance check lived inside ensureSegmentWindow (reached mid-loop). For a default torch.cuda.MemPool() -- the expected ROCm failure, not a rare NCCL error -- the throw left the pool recorded and segments registered, leaking state into the shared worker of MultiProcContinuousTest. Root cause: the ncclMemAlloc-provenance check was enforced per segment during the upgrade loop, after mutation had begun. Fix: take the segment snapshot once and, on ROCm with symm=True, TORCH_CHECK isNcclAllocatorSegment for every segment up front, before touching registeredMemPools_ or registering any address. A rejected pool now leaves no residue and reports an actionable message pointing at MemPool(backend.mem_allocator). The in-loop check in ensureSegmentWindow stays as defense-in-depth for the WindowNCCL path. Because a rejected pool is no longer recorded, the nccl2 provenance test drops its now-invalid deregister_mem_pool cleanup and matches the new message. The window test's rank-local rejections (plain tensor, unrelated pool, pre-registration ops) move ahead of _probe_window_support so they run on hosts without a symmetric-memory transport instead of skipping. The ensureSegmentWindow declaration now documents the ROCm contract (invalidArgument = bad provenance, invalidUsage = missing transport). Test Plan: ``` python test/distributed/test_c10d_nccl2.py -k rejects_unrelated_allocator python test/distributed/test_c10d_nccl2.py -k test_register_mem_pool python test/distributed/test_c10d_window.py -k test_register_errors ``` Authored with the assistance of an AI coding assistant.
The rejection test only checked that register_mem_pool(symm=True) raises; it did not verify the actual bug the fix closes -- registeredMemPools_ left populated after the throw. A comment is not a regression test: a revert to insert-then-throw would still pass. Assert that deregister_mem_pool then fails with "not previously registered", proving the pool was never recorded. Test Plan: ``` python test/distributed/test_c10d_nccl2.py \ -k test_register_mem_pool_symmetric_rejects_unrelated_allocator ``` Authored with the assistance of an AI coding assistant.
4c272c6 to
ef87be2
Compare
jeffdaily
left a comment
There was a problem hiding this comment.
Approving. All three items from my 08-14 review are addressed at ef87be2: the provenance check now lives in ensureSegmentWindow covering both the tensor_register and symm mempool paths, the helper is renamed, and the range-walk duplication is collapsed into one locked helper. On the error-code question: choosing ncclInvalidArgument over ncclInvalidUsage is the right call given registerMemPool maps InvalidUsage to warn-and-keep-plain-registration; wrong-allocator-throws / missing-transport-warns is the semantic I wanted confirmed, and it is now documented in the header and description. The no-leftover-state pre-validation with its dedicated regression assertion is a nice addition beyond the ask.
I also verified live window coverage on this head rather than the pre-rebase links: the rocm-preview lane ran all 11 Nccl2WindowTest items and the full ProcessGroupNCCL2MemPoolTest including the new reject test, with no "GIN not supported" skips.
One optional comment fix, fine as a follow-up or a quick push: the note in test_c10d_window.py that the rejections "are rank-local and return before any transport work" is only true on ROCm; on CUDA builds the caching-allocator hook plain-registers those segments, so the register attempt proceeds to ncclCommWindowRegister before failing. The reordering is still safe on both; suggest scoping the comment to say so.
Analysis assisted by AI.
|
@pytorchbot merge -i Only 1 unclassified failure that was not related to this PR. |
Merge startedYour change will be merged while ignoring the following 4 checks: periodic-rocm-mi200 / linux-jammy-rocm-py3.10-mi200 / test (distributed, 2, 3, linux.rocm.gpu.mi210.2, module:rocm, oncall:distributed), rocm-mi300 / linux-noble-rocm-py3.12-mi300 / test (default, 5, 8, linux.rocm.gpu.mi300.1), inductor-rocm-mi300 / linux-noble-rocm-py3.12-mi300 / test (inductor, 2, 2, linux.rocm.gpu.mi300.1), inductor-rocm-mi300 / linux-noble-rocm-py3.12-mi300 / test (inductor, 1, 2, linux.rocm.gpu.mi300.1) Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
@jeffdaily noted. I will have a follow-up PR where I modify the comment clarifying that the behavior is scoped to ROCm-only. |
…ytorch#193282) ## Summary This PR enables ProcessGroupNCCL2 windows on ROCm, which compile-time guards previously disabled, and enforces the existing allocation contract: window memory must come from `torch.cuda.MemPool(backend.mem_allocator)` ( `ncclMemAlloc`). The NCCL/RCCL 2.29 version check is unchanged. ## Problem After the ROCm guards were removed, 10 of 11 window tests passed. `Nccl2WindowTest.test_register_errors` failed because RCCL accepted a tensor that should have been rejected, so the expected RuntimeError never fired. NVIDIA NCCL requires compatible symmetric memory for this window path and has no fallback for ordinary cudaMalloc buffers. RCCL does: a host-side RMA fallback can register ordinary HIP allocations. A private-pool id is not a substitute for the right allocator, because `torch.cuda.MemPool()` also has a valid id. The unit test is what surfaced this, but the same hole exists for every ROCm window registration, including `register_mem_pool(pool, symm=True)`. Leaving the fallback open is not a harmless extra. NCCL2 put and window lookup only check that a segment already has a window handle. If RCCL accepts ordinary HIP memory, those buffers become valid window sources. ROCm would then succeed on memory that the default path cannot use for this API, and the documented MemPool(backend.mem_allocator) contract would not actually be enforced. ## Solution On ROCm, the backend records the address and size of each live 'ncclMemAlloc' allocation and drops the record after `ncclMemFree` succeeds. Before a symmetric window upgrade, it checks that the storage segment falls in a recorded range: default-allocator memory and unrelated private pools are rejected; `MemPool(backend.mem_allocator)` is accepted. The check is ROCm-only. The shared allocator hook, ordinary collective registration, and NVIDIA behavior are unchanged. ## Design choices **Windows are enabled on ROCm, but still gated on NCCL/RCCL 2.29.** supportsWindow() no longer has && !defined(USE_ROCM). The old guard was a feature kill switch, not a version check. RCCL 2.29+ can create windows; older RCCL should still fail with a version error. **The host-RMA fallback is not a supported NCCL2 window.** The public contract is the NCCL allocator, and it should mean the same thing on CUDA and ROCm. **Provenance is enforced in ensureSegmentWindow**, which both `tensor_register` and `register_mem_pool(..., symm=True)` call. Guarding only `tensor_register` leaves the `mempool` path open. **Wrong allocator throws; missing transport does not.** Allocator violations return `ncclInvalidArgument` and become a Python RuntimeError. Missing symmetric transport stays `ncclInvalidUsage`: warn and keep plain `ncclCommRegister` registration, matching the stock NCCL backend. Those failures are different. A wrong allocator is a caller error and must not succeed. A missing transport is an environment limit. Mapping the allocator case onto `ncclInvalidUsage` would warn and leave the buffers registered as plain user buffers. **`register_mem_pool(symm=True)` is rejected before any state is mutated.** On ROCm the pool snapshot is taken once and every segment is checked with `isNcclAllocatorSegment` before `registeredMemPools_.insert` or `registerAddressLocked. ensureSegmentWindow` keeps the same check as a second barrier for `tensor_register`. Checking only inside the upgrade loop recorded the pool first, so a throw left leftover state in a shared test worker. **The extra tracking is #if defined(USE_ROCM).** NVIDIA NCCL already refuses ordinary allocations on this path; the extra check exists because RCCL is more permissive. **Segment lookup is one helper**, `findContainingRegistrationLocked`, used by both `lookupSegmentWindow` and `ensureSegmentWindow`. **The unsupported-window error no longer says windows are unavailable on ROCm.** It is now ProcessGroupNCCL windows require NCCL 2.29 or later. That is true after this PR; the old ROCm clause is not. Anything matching the old string will need an update. ## User-visible behavior on ROCm | Call | Wrong allocator (default or unrelated `MemPool`) | No symmetric transport | RCCL < 2.29 | | --- | --- | --- | --- | | `register_mem_pool(pool, symm=True)` | Throws; the pool is not recorded | Warns; keeps plain registration | Windows stay disabled by the version check | | `tensor_register` / `_new_window` | Throws (`mempool` / `MemPool` in the message) | Register can fail as unsupported | `supports_window` is false | `register_mem_pool(symm=True)` on `torch.cuda.MemPool()` is a behavior change: RCCL host-RMA could previously succeed. This treats that as a bug, not as API. Docs already require `MemPool(backend.mem_allocator)` (`docs/source/symmetric_memory.md`). ## Tests `Nccl2WindowTest.test_register_errors` rejects default-allocator tensors and unrelated private pools. Those cases run before `_probe_window_support` because they do not need a live symmetric transport. Double-registration still does, so it stays after the probe. `ProcessGroupNCCL2MemPoolTest.test_register_mem_pool_symmetric_rejects_unrelated_allocator` expects a throw mentioning `mem_allocator` or `ncclMemAlloc`, then asserts that `deregister_mem_pool` fails with `not previously registered`. The second assert is the leftover-state regression. ## CI coverage The limiter on current ROCm CI is GIN / symmetric transport, not RCCL 2.29. Trunk 7.14 and preview 10 both get past `supports_window`; `_probe_window_support` then tries a real `ncclCommWindowRegister`. On 7.14 CI that fails with `NCCL Last Error: GIN not supported`, so pytest reports the window file as skipped. The skip text also mentions mempool / `invalid usage`; that is PyTorch's mapping, not the RCCL reason. On HEAD `36cdb3f`: - **ciflow/rocm-preview** (this PR pins the preview image to ROCm 10.0.0rc4 / HIP Runtime 7.15.26333): live windows run. [distributed 2/3](https://github.com/pytorch/pytorch/actions/runs/32796615998/job/97673134522) is `Nccl2WindowTest` **11 passed**. [distributed 1/3](https://github.com/pytorch/pytorch/actions/runs/32796615998/job/97673134508) ran `ProcessGroupNCCL2MemPoolTest`, including `test_register_mem_pool_symmetric` and `test_register_mem_pool_symmetric_rejects_unrelated_allocator` (**PASSED**). - **ciflow/trunk** jammy ROCm 7.14 MI350 (HIP Runtime 7.14.60850): mem-pool / provenance tests run ([distributed 1/3](https://github.com/pytorch/pytorch/actions/runs/32796614990/job/97659566299), `test_c10d_nccl2` successful). The window suite is selected but internally skipped: [distributed 2/3](https://github.com/pytorch/pytorch/actions/runs/32796614990/job/97659566372) is **11 skipped** with `GIN not supported`. Rank-local rejects in `test_register_errors` still execute before the probe; pytest then skips the test because double-registration needs a live GIN window. - **ciflow/periodic-rocm-mi300** noble 7.14 is the same GIN skip for windows ([distributed 2/5](https://github.com/pytorch/pytorch/actions/runs/32796613834/job/97659332472), **11 skipped**). The shard reporting `test_c10d_window ... was successful` means the file completed with skips, not that put/signal ran. Live window coverage in CI is the preview lane. Trunk / periodic 7.14 are not environments where RCCL initializes a usable GIN plugin. ## Validation Manual run on MI355X with HIP 7.15 and RCCL 2.30.4: full NCCL2 window suite passed; mempool suite including the leftover-state reject test passed; reduction regression passed; targeted lint passed. CI on `36cdb3f` repeats that split: preview executes the window suite; 7.14 trunk / MI300 periodic execute mem-pool provenance and skip live windows on GIN. Authored with the assistance of an AI coding assistant. Pull Request resolved: pytorch#193282 Approved by: https://github.com/jeffdaily Co-authored-by: Cursor <[email protected]>
Summary
This PR enables ProcessGroupNCCL2 windows on ROCm, which compile-time guards previously disabled, and enforces the existing allocation contract: window memory must come from
torch.cuda.MemPool(backend.mem_allocator)(ncclMemAlloc). The NCCL/RCCL 2.29 version check is unchanged.Problem
After the ROCm guards were removed, 10 of 11 window tests passed.
Nccl2WindowTest.test_register_errorsfailed because RCCL accepted a tensor that should have been rejected, so the expected RuntimeError never fired.NVIDIA NCCL requires compatible symmetric memory for this window path and has no fallback for ordinary cudaMalloc buffers. RCCL does: a host-side RMA fallback can register ordinary HIP allocations. A private-pool id is not a substitute for the right allocator, because
torch.cuda.MemPool()also has a valid id. The unit test is what surfaced this, but the same hole exists for every ROCm window registration, includingregister_mem_pool(pool, symm=True).Leaving the fallback open is not a harmless extra. NCCL2 put and window lookup only check that a segment already has a window handle. If RCCL accepts ordinary HIP memory, those buffers become valid window sources. ROCm would then succeed on memory that the default path cannot use for this API, and the documented MemPool(backend.mem_allocator) contract would not actually be enforced.
Solution
On ROCm, the backend records the address and size of each live 'ncclMemAlloc' allocation and drops the record after
ncclMemFreesucceeds. Before a symmetric window upgrade, it checks that the storage segment falls in a recorded range: default-allocator memory and unrelated private pools are rejected;MemPool(backend.mem_allocator)is accepted.The check is ROCm-only. The shared allocator hook, ordinary collective registration, and NVIDIA behavior are unchanged.
Design choices
Windows are enabled on ROCm, but still gated on NCCL/RCCL 2.29. supportsWindow() no longer has && !defined(USE_ROCM). The old guard was a feature kill switch, not a version check. RCCL 2.29+ can create windows; older RCCL should still fail with a version error.
The host-RMA fallback is not a supported NCCL2 window. The public contract is the NCCL allocator, and it should mean the same thing on CUDA and ROCm.
Provenance is enforced in ensureSegmentWindow, which both
tensor_registerandregister_mem_pool(..., symm=True)call. Guarding onlytensor_registerleaves themempoolpath open.Wrong allocator throws; missing transport does not. Allocator violations return
ncclInvalidArgumentand become a Python RuntimeError. Missing symmetric transport staysncclInvalidUsage: warn and keep plainncclCommRegisterregistration, matching the stock NCCL backend. Those failures are different. A wrong allocator is a caller error and must not succeed. A missing transport is an environment limit. Mapping the allocator case ontoncclInvalidUsagewould warn and leave the buffers registered as plain user buffers.register_mem_pool(symm=True)is rejected before any state is mutated. On ROCm the pool snapshot is taken once and every segment is checked withisNcclAllocatorSegmentbeforeregisteredMemPools_.insertorregisterAddressLocked. ensureSegmentWindowkeeps the same check as a second barrier fortensor_register. Checking only inside the upgrade loop recorded the pool first, so a throw left leftover state in a shared test worker.The extra tracking is #if defined(USE_ROCM). NVIDIA NCCL already refuses ordinary allocations on this path; the extra check exists because RCCL is more permissive.
Segment lookup is one helper,
findContainingRegistrationLocked, used by bothlookupSegmentWindowandensureSegmentWindow.The unsupported-window error no longer says windows are unavailable on ROCm. It is now ProcessGroupNCCL windows require NCCL 2.29 or later. That is true after this PR; the old ROCm clause is not. Anything matching the old string will need an update.
User-visible behavior on ROCm
MemPool)register_mem_pool(pool, symm=True)tensor_register/_new_windowmempool/MemPoolin the message)supports_windowis falseregister_mem_pool(symm=True)ontorch.cuda.MemPool()is a behavior change: RCCL host-RMA could previously succeed. This treats that as a bug, not as API. Docs already requireMemPool(backend.mem_allocator)(docs/source/symmetric_memory.md).Tests
Nccl2WindowTest.test_register_errorsrejects default-allocator tensors and unrelated private pools. Those cases run before_probe_window_supportbecause they do not need a live symmetric transport. Double-registration still does, so it stays after the probe.ProcessGroupNCCL2MemPoolTest.test_register_mem_pool_symmetric_rejects_unrelated_allocatorexpects a throw mentioningmem_allocatororncclMemAlloc, then asserts thatderegister_mem_poolfails withnot previously registered. The second assert is the leftover-state regression.CI coverage
The limiter on current ROCm CI is GIN / symmetric transport, not RCCL 2.29. Trunk 7.14 and preview 10 both get past
supports_window;_probe_window_supportthen tries a realncclCommWindowRegister. On 7.14 CI that fails withNCCL Last Error: GIN not supported, so pytest reports the window file as skipped. The skip text also mentions mempool /invalid usage; that is PyTorch's mapping, not the RCCL reason.On HEAD
36cdb3f:Nccl2WindowTest11 passed. distributed 1/3 ranProcessGroupNCCL2MemPoolTest, includingtest_register_mem_pool_symmetricandtest_register_mem_pool_symmetric_rejects_unrelated_allocator(PASSED).test_c10d_nccl2successful). The window suite is selected but internally skipped: distributed 2/3 is 11 skipped withGIN not supported. Rank-local rejects intest_register_errorsstill execute before the probe; pytest then skips the test because double-registration needs a live GIN window.test_c10d_window ... was successfulmeans the file completed with skips, not that put/signal ran.Live window coverage in CI is the preview lane. Trunk / periodic 7.14 are not environments where RCCL initializes a usable GIN plugin.
Validation
Manual run on MI355X with HIP 7.15 and RCCL 2.30.4: full NCCL2 window suite passed; mempool suite including the leftover-state reject test passed; reduction regression passed; targeted lint passed.
CI on
36cdb3frepeats that split: preview executes the window suite; 7.14 trunk / MI300 periodic execute mem-pool provenance and skip live windows on GIN.Authored with the assistance of an AI coding assistant.
cc @jeffdaily @sunway513 @jithunnair-amd @pruthvistony @ROCmSupport @jataylo @hongxiayang @naromero77amd @pragupta @jerrymannil @xinyazhang