Skip to content

[CUDA] Add SM partitioning with cuDevSmResourceSplit - #198178

Closed
MatthiasKohl wants to merge 1 commit into
pytorch:mainfrom
MatthiasKohl:mjoux/green-context-sm-partition
Closed

MatthiasKohl wants to merge 1 commit into
pytorch:mainfrom
MatthiasKohl:mjoux/green-context-sm-partition

Conversation

@MatthiasKohl

@MatthiasKohl MatthiasKohl commented Sep 22, 2026 •

Copy link
Copy Markdown
Collaborator

Add reusable SMPartition resources and disjoint green-context SM allocation through cuDevSmResourceSplit.

This fixes issue #195378.

Additionally adds shared stream execution and lookup helpers, non-owning context wrappers, cached SM counts, and CUDA bindings version checks, and improve green context docs accordingly.

Locality-domain functionality and its NVML helpers are added separately on top of this PR.

Authored (partially) with an AI assistant.

Add reusable SMPartition resources and disjoint green-context SM allocation
through cuDevSmResourceSplit. Start review with SMPartition.split and its
broadcasting, discovery, co-scheduling, and backfill options, then follow
GreenContext construction and recursive subdivision through sm_partition.

Retain the shared stream execution and lookup helpers, non-owning context
wrappers, cached SM counts, and CUDA bindings version checks. Include their
documentation and test coverage; locality-domain functionality and its NVML
helpers are added separately on top of this commit.

Test Plan

Ran lint with autofixes through spin using the base_env environment:

```bash
PATH=/home/mjoux/base_env/bin:$PATH spin lint -a docs/source/cuda.md test/test_cuda.py torch/cuda/__init__.py torch/cuda/_utils.py torch/cuda/green_contexts.py torch/testing/_internal/common_utils.py
git diff --check
```

Tests were not run, as requested; live-system testing is left to the author.

Authored with an AI assistant.
@MatthiasKohl
MatthiasKohl requested review from a team, Aidyn-A, eqy and syed-ahmed as code owners September 22, 2026 10:36
@pytorch-bot

pytorch-bot Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/198178

Note: Links to docs will display an error until the docs builds have been completed.

❗ 1 Active SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

❌ 3 New Failures

As of commit f2cc896 with merge base 9b6e452 (image):

NEW FAILURES - The following jobs have failed:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@pytorch-bot

pytorch-bot Bot commented Sep 22, 2026

Copy link
Copy Markdown

This PR needs a release notes: label

If your changes are user facing and intended to be a part of release notes, please use a label starting with release notes:.

If not, please add the topic: not user facing label.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "topic: not user facing"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

workqueue_concurrency_limit: int | None = None,
sm_partition: SMPartition | None = None,
device_id: int | None = None,
green_context_obj: Any | None = None,

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.

remove this arg and related functionality, along with get_green_context_from_stream - the original PR didn't actually show that it's needed for fork-join functionality, when it's needed you'll add it in a separate PR. Also, remove _is_owning, we won't need it in this case

"""
self._ensure_alive()
curr_idx = self._curr_stream_idx + 1
self._curr_stream_idx += 1

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.

remove changes related to stream handling from this PR, put them in a separate PR. This is still not fixing the race correctly, an index can be reserved before its slot contains a stream. If A stalls creating slot 0 while B makes
another 32 requests, B wraps around and reads None from slot 0. A failed creation similarly leaves a hole. So, move the change to a separate PR (also remove tests related to this change)

"""
if not green_ctx_streams:
raise ValueError("Need at least one green context to execute in!")
if len(green_ctx_streams) == 1:

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.

this gives a materially different semantics to single stream vs multi-stream execution - multi-stream skips sync

):
torch.cuda.set_stream(green_ctx_stream)
green_ctx_stream.wait_event(main_event)
fn(i)

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.

if fn raises, event won't be recorded and synchronization will be bypassed

@MatthiasKohl

Copy link
Copy Markdown
Collaborator Author

closing as superseded by PR stacks #198279 and #199127

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants