Skip to content

Conversation

Gasoonjia
Copy link
Contributor

@Gasoonjia Gasoonjia commented Oct 8, 2025

Stack from ghstack (oldest at bottom):

Introduce CudaGuard and CudaStreamGuard

This diff introduces CudaGuard and CudaStreamGuard in the Executorch CUDA runtime. These classes provide a convenient way to manage CUDA device and stream selection.

Changes

  • Added CudaGuard and CudaStreamGuard classes in fbcode/executorch/backends/cuda/runtime/guard.h.
  • Implemented CudaGuard and CudaStreamGuard in fbcode/executorch/backends/cuda/runtime/guard.cpp.
  • Added unit tests for CudaStreamGuard in fbcode/executorch/backends/cuda/runtime/tests/test_cuda_stream_guard.cpp.
  • Updated TARGETS file to include the new files.

Purpose

The CudaGuard class provides a way to select a CUDA device and ensure that it is properly released when the guard goes out of scope. The CudaStreamGuard class provides a way to select a CUDA stream and ensure that it is properly synchronized when the guard goes out of scope.

Usage

They will be further used and controled by their shim layer functions.

Differential Revision: D84126481

### Introduce CudaGuard and CudaStreamGuard

This diff introduces `CudaGuard` and `CudaStreamGuard` in the Executorch CUDA runtime. These classes provide a convenient way to manage CUDA device and stream selection.

#### Changes

*   Added `CudaGuard` and `CudaStreamGuard` classes in `fbcode/executorch/backends/cuda/runtime/guard.h`.
*   Implemented `CudaGuard` and `CudaStreamGuard` in `fbcode/executorch/backends/cuda/runtime/guard.cpp`.
*   Added unit tests for `CudaStreamGuard` in `fbcode/executorch/backends/cuda/runtime/tests/test_cuda_stream_guard.cpp`.
*   Updated `TARGETS` file to include the new files.

#### Purpose

The `CudaGuard` class provides a way to select a CUDA device and ensure that it is properly released when the guard goes out of scope. The `CudaStreamGuard` class provides a way to select a CUDA stream and ensure that it is properly synchronized when the guard goes out of scope.


#### Usage
They will be further used and controled by their shim layer functions.

Differential Revision: [D84126481](https://our.internmc.facebook.com/intern/diff/D84126481/)

[ghstack-poisoned]
Copy link

pytorch-bot bot commented Oct 8, 2025

🔗 Helpful Links

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

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

✅ No Failures

As of commit a0077ff with merge base fb87fa6 (image):
💚 Looks good so far! There are no failures yet. 💚

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

Copy link

github-actions bot commented Oct 8, 2025

This PR needs a release notes: label

If your change should be included in the release notes (i.e. would users of this library care about this change?), please use a label starting with release notes:. This helps us keep track and include your important work in the next release notes.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "release notes: none"

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

Copy link
Contributor

@larryliu0820 larryliu0820 left a comment

Choose a reason for hiding this comment

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

Thank you for adding tests

@meta-codesync meta-codesync bot merged commit 7f63c1e into gh/gasoonjia/46/base Oct 8, 2025
137 of 147 checks passed
@meta-codesync meta-codesync bot deleted the gh/gasoonjia/46/head branch October 8, 2025 20:14
@meta-codesync meta-codesync bot temporarily deployed to cherry-pick-bot October 8, 2025 20:14 Inactive
Gasoonjia added a commit that referenced this pull request Oct 8, 2025
This PR was created by the merge bot to help merge the original PR into
the main branch.
ghstack PR number: #14901 by
@Gasoonjia
^ Please use this as the source of truth for the PR details, comments,
and reviews
ghstack PR base:
https://github.com/pytorch/executorch/tree/gh/gasoonjia/46/base
ghstack PR head:
https://github.com/pytorch/executorch/tree/gh/gasoonjia/46/head
Merge bot PR base:
https://github.com/pytorch/executorch/tree/gh/gasoonjia/45/orig
Merge bot PR head:
https://github.com/pytorch/executorch/tree/gh/gasoonjia/46/orig
Differential Revision:
[D84126481](https://our.internmc.facebook.com/intern/diff/D84126481/)
@diff-train-skip-merge

---------

Co-authored-by: gasoonjia <gasoonjia@icloud.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported meta-exported

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants