PyTorch
Loading...
Searching...
No Matches
Public Member Functions | List of all members
c10::cuda::CUDAStreamGuard Struct Reference

A variant of StreamGuard that is specialized for CUDA. More...

#include <CUDAGuard.h>

Public Member Functions

 CUDAStreamGuard ()=delete
 No default constructor, see Note [Omitted default constructor from RAII]. More...
 
 CUDAStreamGuard (Stream stream)
 Set the current CUDA device to the device associated with the passed stream, and set the current CUDA stream on that device to the passed stream. More...
 
 CUDAStreamGuard (const CUDAStreamGuard &)=delete
 Copy is disallowed. More...
 
CUDAStreamGuardoperator= (const CUDAStreamGuard &)=delete
 
 CUDAStreamGuard (CUDAStreamGuard &&other)=delete
 Move is disallowed, as CUDAStreamGuard does not have an uninitialized state, which is required for moves on types with nontrivial destructors. More...
 
CUDAStreamGuardoperator= (CUDAStreamGuard &&other)=delete
 
void reset_stream (Stream stream)
 Resets the currently set stream to the original stream and the currently set device to the original device. More...
 
CUDAStream original_stream () const
 Returns the CUDA stream that was set at the time the guard was constructed. More...
 
CUDAStream current_stream () const
 Returns the most recent CUDA stream that was set using this device guard, either from construction, or via set_stream. More...
 
Device current_device () const
 Returns the most recent CUDA device that was set using this device guard, either from construction, or via set_device/reset_device/set_index. More...
 
Device original_device () const
 Returns the CUDA device that was set at the most recent reset_stream(), or otherwise the device at construction time. More...
 

Detailed Description

A variant of StreamGuard that is specialized for CUDA.

See CUDAGuard for when you can use this.

Constructor & Destructor Documentation

◆ CUDAStreamGuard() [1/4]

c10::cuda::CUDAStreamGuard::CUDAStreamGuard ( )
explicitdelete

No default constructor, see Note [Omitted default constructor from RAII].

◆ CUDAStreamGuard() [2/4]

c10::cuda::CUDAStreamGuard::CUDAStreamGuard ( Stream  stream)
inlineexplicit

Set the current CUDA device to the device associated with the passed stream, and set the current CUDA stream on that device to the passed stream.

Errors if the Stream is not a CUDA stream.

◆ CUDAStreamGuard() [3/4]

c10::cuda::CUDAStreamGuard::CUDAStreamGuard ( const CUDAStreamGuard )
delete

Copy is disallowed.

◆ CUDAStreamGuard() [4/4]

c10::cuda::CUDAStreamGuard::CUDAStreamGuard ( CUDAStreamGuard &&  other)
delete

Move is disallowed, as CUDAStreamGuard does not have an uninitialized state, which is required for moves on types with nontrivial destructors.

Member Function Documentation

◆ current_device()

Device c10::cuda::CUDAStreamGuard::current_device ( ) const
inline

Returns the most recent CUDA device that was set using this device guard, either from construction, or via set_device/reset_device/set_index.

◆ current_stream()

CUDAStream c10::cuda::CUDAStreamGuard::current_stream ( ) const
inline

Returns the most recent CUDA stream that was set using this device guard, either from construction, or via set_stream.

◆ operator=() [1/2]

CUDAStreamGuard & c10::cuda::CUDAStreamGuard::operator= ( const CUDAStreamGuard )
delete

◆ operator=() [2/2]

CUDAStreamGuard & c10::cuda::CUDAStreamGuard::operator= ( CUDAStreamGuard &&  other)
delete

◆ original_device()

Device c10::cuda::CUDAStreamGuard::original_device ( ) const
inline

Returns the CUDA device that was set at the most recent reset_stream(), or otherwise the device at construction time.

◆ original_stream()

CUDAStream c10::cuda::CUDAStreamGuard::original_stream ( ) const
inline

Returns the CUDA stream that was set at the time the guard was constructed.

◆ reset_stream()

void c10::cuda::CUDAStreamGuard::reset_stream ( Stream  stream)
inline

Resets the currently set stream to the original stream and the currently set device to the original device.

Then, set the current device to the device associated with the passed stream, and set the current stream on that device to the passed stream. Errors if the stream passed is not a CUDA stream.

NOTE: this implementation may skip some stream/device setting if it can prove that it is unnecessary.

WARNING: reset_stream does NOT preserve previously set streams on different devices. If you need to set streams on multiple devices on CUDA, use CUDAMultiStreamGuard instead.


The documentation for this struct was generated from the following file: