Repository navigation
[CUDA] Add localized CUDA allocator - #199127
MatthiasKohl wants to merge 8 commits into
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/199127
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit f6749c7 with merge base d0b8bbb ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
[ghstack-poisoned]
[ghstack-poisoned]
|
CC @ngimel @eqy @slayton58 for review (includes the full stack) |
Add a convenience custom MemPool to allow allocating memory in a given locality domain. > Authored with an AI assistant. > > Construction initializes CUDA before checking support so validation uses the actual device topology. Test Plan Tested on Rubin with driver R610 + CUDA 13.4 compat. 43 tests run: 40 passed, 3 skipped. ```sh python test/test_cuda.py TestMemPool TestLocalizedMemPoolCUDA TestLocalizedMemPoolAllocator -v ``` ghstack-source-id: d9d0693 Pull-Request: pytorch#199127
|
@claude are the failures from periodic tests related to this PR? Plus, did the 13.4 periodic jobs run successfully and successfully complete the green context / LocalizedMemPool tests? |
|
Claude finished @MatthiasKohl's task in 2m 40s —— View job None of the periodic failures come from this PR. All 39 CUDA 13.4 jobs passed, but they ran on L4 GPUs with driver R580, so the LocalizedMemPool tests that need real hardware were almost certainly skipped and nothing in CI actually exercised a localized allocation. Details1. Are the periodic failures related?No. They fall into three groups:
The This is a real bug, not a flake. 2. Did the 13.4 periodic jobs run the green context / LocalizedMemPool tests?All
The catch is the hardware. These runners are L4 GPUs (
I couldn't read the per-test pass/skip results: the console log only lists collected items, and downloading the XML test-report artifacts needs Bottom line: the 13.4 CI jobs show that the new code imports, the tests skip cleanly and the mocked allocator logic passes on 13.4. They do not test localized allocation on real multi-domain hardware. For now your Rubin + R610 run is the only real test of that. |
|
AI-assisted Expose localized allocation through the allocator interface.
The native allocator also receives only integer callback addresses. Its lifetime can exceed that of the Python pool and its callback objects: dropping the pool with a live tensor and running
|
[ghstack-poisoned]
|
@ngimel Thank you for the review, I tried to address everything in the latest update. Please let me know if further changes are required ! |
[ghstack-poisoned]
|
@claude analyze the remaining failures, are they likely due to periodic jobs we don't see on most PRs, are they related to this PR? |
|
Claude finished @eqy's task in 2m 28s —— View job None of the 7 remaining failures come from this PR. All of them are in DetailsFailing jobs
The slow-gradcheck job is the one DrCI lists as "unclassified" only because that workflow didn't run on the merge base. The log shows the usual timeout, not a crash. Compared with the last run
VerdictThese are all periodic-only failures that trunk has too: job timeouts, a valgrind/AVX-512 SIGILL, a CPU inductor numerics failure, and s390x CPU bugs. None of them should block this PR. |
|
@claude were the comments addressed? |
|
Claude finished @ngimel's task in 55s —— View job Yes. All six points from your review were addressed in the current head ( DetailsStatus of each point
Minor non-blocking notes
|
|
Claude finished @ngimel's task in 1m 7s —— View job Two of your three asks are done in Details1. Remove the extra subclassing: ✅ done
2. Harden the free path: ✅ done (minor gaps below)
Remaining points, none of them blocking:
3. GB200/GB300 + 13.4 cuda-compat CI: ❌ not in this PR@MatthiasKohl says the 13.4 B200/B300 runners are coming and will be wired up in a separate PR. Until then, CI runs only the mocked I only read the code. Nothing was run, since there is no multi-domain GPU here. |
|
note: PR #199593 should add the B200 based tests. |
ngimel
left a comment
There was a problem hiding this comment.
Small change to the example, and we'd need to harden device handling later, otherwise good to go.
[ghstack-poisoned]
|
@pytorchbot merge |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
Merge failedReason: 1 jobs have failed, first few of them are: periodic / linux-jammy-cuda13.2-py3.11-gcc11 / test (default, 1, 5, mt-l-x86aavx2-11-41-l4) Details for Dev Infra teamRaised by workflow job |
> AI-assisted: map-style stream execution, localized-output docs, trim redundant tests. [ghstack-poisoned]
|
@pytorchbot merge |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
> Authored with an AI assistant. > > Add `torch.cuda.execute_on_streams` for fork/join execution with ordinary > streams, green-context streams, or mixtures. Queued work is joined and > caller state restored even when a callback raises. Same-device execution switches directly between streams and restores the caller once to reduce host-side overheads. Cross-device execution uses stream context managers to restore device and stream state. Test Plan Tested on Rubin with driver R610 + CUDA 13.4 compat (56 tests passed) Pull Request resolved: #199128 Approved by: https://github.com/ngimel ghstack dependencies: #199127
Fix potential races in green context stream pool slot selection/creation/indexing. > Authored with an AI assistant. > > The lock covers creation through publication; failed creation leaves the index unchanged. Test Plan Tested on Rubin with driver R610 + CUDA 13.4 compat. All 3 focused stream-pool tests passed. ```sh python test/test_cuda.py TestGreenContextStreamPool -v ``` Pull Request resolved: #199129 Approved by: https://github.com/ngimel ghstack dependencies: #199127, #199128
….t. MPS (#199130) Improve documentation of the NVML based check for locality support: later attachment to MPS isn't supported. > Authored with an AI assistant. > > The limitation concerns the pre-initialization NVML estimate. Already attached clients use the CUDA driver path; query again after attachment rather than reusing an earlier estimate. These regression tests do not test dynamic MPS attachment. Test Plan Tested on Rubin with driver R610 + CUDA 13.4 compat. All 10 existing locality-query regression tests passed. ```sh python test/test_cuda.py TestCudaGreenContextsCUDA -k locality -v ``` Pull Request resolved: #199130 Approved by: https://github.com/ngimel ghstack dependencies: #199127, #199128, #199129
Initial locality domain support was added in pytorch#198279. This stack adds: 1. convenience functions to allocate localized memory 2. convenience function to execute operations in several green contexts through the fork/join pattern 3. minor fixes to green contexts discovered during testing of localized workloads 4. small fixes to docs > Authored with an AI assistant. > > Add `LocalizedAllocator` for use with the existing `MemPool` API. > Retain Python callback owners so tensors can outlive the pool, and wait > for allocation-stream work before unmapping reclaimed memory. Validate > domain types and document the current threading restriction. Test Plan Tested on Rubin with driver R610 + CUDA 13.4 compat (43 tests: 40 passed, 3 skipped) Pull Request resolved: pytorch#199127 Approved by: https://github.com/ngimel
> Authored with an AI assistant. > > Add `torch.cuda.execute_on_streams` for fork/join execution with ordinary > streams, green-context streams, or mixtures. Queued work is joined and > caller state restored even when a callback raises. Same-device execution switches directly between streams and restores the caller once to reduce host-side overheads. Cross-device execution uses stream context managers to restore device and stream state. Test Plan Tested on Rubin with driver R610 + CUDA 13.4 compat (56 tests passed) Pull Request resolved: pytorch#199128 Approved by: https://github.com/ngimel ghstack dependencies: pytorch#199127
…9129) Fix potential races in green context stream pool slot selection/creation/indexing. > Authored with an AI assistant. > > The lock covers creation through publication; failed creation leaves the index unchanged. Test Plan Tested on Rubin with driver R610 + CUDA 13.4 compat. All 3 focused stream-pool tests passed. ```sh python test/test_cuda.py TestGreenContextStreamPool -v ``` Pull Request resolved: pytorch#199129 Approved by: https://github.com/ngimel ghstack dependencies: pytorch#199127, pytorch#199128
….t. MPS (pytorch#199130) Improve documentation of the NVML based check for locality support: later attachment to MPS isn't supported. > Authored with an AI assistant. > > The limitation concerns the pre-initialization NVML estimate. Already attached clients use the CUDA driver path; query again after attachment rather than reusing an earlier estimate. These regression tests do not test dynamic MPS attachment. Test Plan Tested on Rubin with driver R610 + CUDA 13.4 compat. All 10 existing locality-query regression tests passed. ```sh python test/test_cuda.py TestCudaGreenContextsCUDA -k locality -v ``` Pull Request resolved: pytorch#199130 Approved by: https://github.com/ngimel ghstack dependencies: pytorch#199127, pytorch#199128, pytorch#199129
Stack from ghstack (oldest at bottom):
Initial locality domain support was added in #198279. This stack adds:
Test Plan
Tested on Rubin with driver R610 + CUDA 13.4 compat (43 tests: 40 passed, 3 skipped)