Shortcuts

Struct OptionalCUDAStreamGuard

Page Contents

Struct Documentation

struct c10::cuda::OptionalCUDAStreamGuard

A variant of OptionalStreamGuard that is specialized for CUDA.

See CUDAGuard for when you can use this.

Public Functions

OptionalCUDAStreamGuard()

Create an uninitialized guard.

OptionalCUDAStreamGuard(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.

Errors if the Stream is not a CUDA stream.

OptionalCUDAStreamGuard(optional<Stream> stream_opt)

Set the current device to the device associated with the passed stream, and set the current stream on that device to the passed stream, if the passed stream is not nullopt.

OptionalCUDAStreamGuard(const OptionalCUDAStreamGuard&) = delete

Copy is disallowed.

OptionalCUDAStreamGuard &operator=(const OptionalCUDAStreamGuard&) = delete
OptionalCUDAStreamGuard(OptionalCUDAStreamGuard &&other) = delete
OptionalCUDAStreamGuard &operator=(OptionalCUDAStreamGuard &&other) = delete
void reset_stream(Stream stream)

Resets the currently set CUDA 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. Initializes the guard if it was not previously initialized.

optional<CUDAStream> original_stream() const

Returns the CUDA stream that was set at the time the guard was most recently initialized, or nullopt if the guard is uninitialized.

optional<CUDAStream> current_stream() const

Returns the most recent CUDA stream that was set using this stream guard, either from construction, or via reset_stream, if the guard is initialized, or nullopt if the guard is uninitialized.

void reset()

Restore the original CUDA device and stream, resetting this guard to uninitialized state.

Docs

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources