Skip to content

[ROCm][c10d] Enable NCCL2 windows and enforce allocator provenance - #193282

Closed
chinmaydk99 wants to merge 5 commits into
pytorch:mainfrom
chinmaydk99:ck-nccl2-rocm-window-provenance
Closed

chinmaydk99 wants to merge 5 commits into
pytorch:mainfrom
chinmaydk99:ck-nccl2-rocm-window-provenance

Conversation

@chinmaydk99

@chinmaydk99 chinmaydk99 commented Aug 13, 2026 •

Copy link
Copy Markdown
Contributor

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 is Nccl2WindowTest 11 passed. distributed 1/3 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, test_c10d_nccl2 successful). The window suite is selected but internally skipped: distributed 2/3 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, 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.

cc @jeffdaily @sunway513 @jithunnair-amd @pruthvistony @ROCmSupport @jataylo @hongxiayang @naromero77amd @pragupta @jerrymannil @xinyazhang

@pytorch-bot

pytorch-bot Bot commented Aug 13, 2026 •

Copy link
Copy Markdown

🔗 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 Failure

As of commit ef87be2 with merge base 6745886 (image):

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.

@pytorch-bot pytorch-bot Bot added module: rocm AMD GPU support for Pytorch release notes: distributed (c10d) release notes category labels Aug 13, 2026
@jithunnair-amd jithunnair-amd added ciflow/trunk Trigger trunk jobs on your pull request keep-going Don't stop on first failure, keep running tests until the end ci-no-td Do not run TD on this PR labels Aug 13, 2026
@pytorch-bot

pytorch-bot Bot commented Aug 13, 2026 •

Copy link
Copy Markdown

Workflows were awaiting approval. CI has now been triggered for the ciflow labels on this PR.

@linux-foundation-easycla

linux-foundation-easycla Bot commented Aug 13, 2026 •

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: chinmaydk99 / name: Chinmay Kuchinad (47ce4a0)

@chinmaydk99
chinmaydk99 force-pushed the ck-nccl2-rocm-window-provenance branch 2 times, most recently from 47ce4a0 to c247d4f Compare August 13, 2026 23:20
@chinmaydk99 chinmaydk99 changed the title [ROCm][c10d] Enforce NCCL allocator provenance for windows [ROCm][c10d] Enable NCCL2 windows on ROCm Aug 14, 2026
@chinmaydk99 chinmaydk99 changed the title [ROCm][c10d] Enable NCCL2 windows on ROCm [ROCm][c10d] Enable NCCL2 windows and enforce allocator provenance Aug 14, 2026
@chinmaydk99
chinmaydk99 marked this pull request as ready for review August 14, 2026 16:27

@jeffdaily jeffdaily left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Requesting changes for three things:

  1. Enforcement scope. The check only guards WindowNCCL::tensor_register, but register_mem_pool(pool, symm=True) also window-registers segments via ensureSegmentWindow, and on ROCm the RCCL fallback will still accept ordinary HIP allocations there (after which put accepts them as sources, since it only checks lookupSegmentWindow). Consider moving the ROCm check into ensureSegmentWindow (return ncclInvalidUsage for non-ncclMemAlloc segments): it covers both entry points, and the existing NCCL_CHECK message in tensor_register already matches the test regex, so isWindowRegistrationSegment and the new TORCH_CHECK become unnecessary. One thing to decide: in registerMemPool, ncclInvalidUsage warns 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-ncclMemAlloc memory on NVIDIA). If you'd rather keep the current scope, document why the symm mempool path intentionally keeps the permissive fallback.

  2. Naming. isWindowRegistrationSegment reads as "already window-registered", which is what lookupSegmentWindow answers. It actually checks allocator provenance; rename to something like isWindowEligibleSegment. (Moot if you take suggestion 1.)

  3. Duplication. This adds a third copy of the upper_bound + step-back range lookup (also in lookupSegmentWindow and ensureSegmentWindow). 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.

@albanD albanD added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label Aug 15, 2026
@chinmaydk99
chinmaydk99 requested a review from a team as a code owner August 18, 2026 00:54
@chinmaydk99
chinmaydk99 marked this pull request as draft August 18, 2026 00:55
@jithunnair-amd jithunnair-amd added ciflow/rocm-preview Trigger unit tests CI on a preview build of ROCm from theRock on MI300 ciflow/rocm-mi300 Trigger "default" config CI on ROCm MI300 ciflow/periodic-rocm-mi300 Trigger "distributed" config CI on ROCm MI300/MI325 ciflow/inductor-rocm-mi300 Trigger "inductor" config CI on ROCm MI300/MI325 labels Aug 18, 2026
@chinmaydk99
chinmaydk99 force-pushed the ck-nccl2-rocm-window-provenance branch from e936137 to eaa3641 Compare August 21, 2026 21:26
@chinmaydk99
chinmaydk99 force-pushed the ck-nccl2-rocm-window-provenance branch from 34b30ca to 862b195 Compare August 25, 2026 00:56
@chinmaydk99

Copy link
Copy Markdown
Contributor Author

Requesting changes for three things:

  1. Enforcement scope. The check only guards WindowNCCL::tensor_register, but register_mem_pool(pool, symm=True) also window-registers segments via ensureSegmentWindow, and on ROCm the RCCL fallback will still accept ordinary HIP allocations there (after which put accepts them as sources, since it only checks lookupSegmentWindow). Consider moving the ROCm check into ensureSegmentWindow (return ncclInvalidUsage for non-ncclMemAlloc segments): it covers both entry points, and the existing NCCL_CHECK message in tensor_register already matches the test regex, so isWindowRegistrationSegment and the new TORCH_CHECK become unnecessary. One thing to decide: in registerMemPool, ncclInvalidUsage warns 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-ncclMemAlloc memory on NVIDIA). If you'd rather keep the current scope, document why the symm mempool path intentionally keeps the permissive fallback.
  2. Naming. isWindowRegistrationSegment reads as "already window-registered", which is what lookupSegmentWindow answers. It actually checks allocator provenance; rename to something like isWindowEligibleSegment. (Moot if you take suggestion 1.)
  3. Duplication. This adds a third copy of the upper_bound + step-back range lookup (also in lookupSegmentWindow and ensureSegmentWindow). 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.

@jeffdaily All three are in. The throw-vs-warn call and the CI note are in the PR description.

  1. Scope. Provenance is in ensureSegmentWindow, so it covers tensor_register and register_mem_pool(symm=True). Wrong allocator is ncclInvalidArgument (throw). Missing transport stays ncclInvalidUsage (warn, keep plain registration). Mapping a bad allocator onto ncclInvalidUsage would warn and leave ordinary HIP buffers registered. register_mem_pool(symm=True) also checks every segment before mutating state. See Design choices and User-visible behavior on ROCm in the description.

  2. Naming. Renamed to isNcclAllocatorSegment.

  3. Duplication. findContainingRegistrationLocked is the shared lookup.

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.

chinmaydk99 and others added 5 commits August 31, 2026 23:50
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.
@chinmaydk99
chinmaydk99 force-pushed the ck-nccl2-rocm-window-provenance branch from 4c272c6 to ef87be2 Compare August 31, 2026 23:50
@jithunnair-amd jithunnair-amd added ciflow/rocm-mi200 Trigger "default" config CI on ROCm MI200 ciflow/periodic-rocm-mi200 Trigger "distributed" config CI on ROCm MI200 ciflow/inductor-rocm-mi200 Trigger "inductor" config CI on ROCm MI200 labels Aug 31, 2026
@chinmaydk99
chinmaydk99 marked this pull request as ready for review September 1, 2026 05:57

@jeffdaily jeffdaily left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

@jeffdaily

Copy link
Copy Markdown
Collaborator

@pytorchbot merge -i

Only 1 unclassified failure that was not related to this PR.

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

@chinmaydk99

Copy link
Copy Markdown
Contributor Author

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.

@jeffdaily noted. I will have a follow-up PR where I modify the comment clarifying that the behavior is scoped to ROCm-only.

Sanskaaar1 pushed a commit to Sanskaaar1/pytorch that referenced this pull request Sep 8, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci-no-td Do not run TD on this PR ciflow/docker ciflow/inductor-rocm-mi200 Trigger "inductor" config CI on ROCm MI200 ciflow/inductor-rocm-mi300 Trigger "inductor" config CI on ROCm MI300/MI325 ciflow/periodic-rocm-mi200 Trigger "distributed" config CI on ROCm MI200 ciflow/periodic-rocm-mi300 Trigger "distributed" config CI on ROCm MI300/MI325 ciflow/rocm-mi200 Trigger "default" config CI on ROCm MI200 ciflow/rocm-mi300 Trigger "default" config CI on ROCm MI300 ciflow/rocm-preview Trigger unit tests CI on a preview build of ROCm from theRock on MI300 ciflow/trunk Trigger trunk jobs on your pull request keep-going Don't stop on first failure, keep running tests until the end Merged module: rocm AMD GPU support for Pytorch open source release notes: distributed (c10d) release notes category triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants