Stream#
- classtorch.cuda.Stream(device=None,priority=0,**kwargs)[source]#
Wrapper around a CUDA stream.
A CUDA stream is a linear sequence of execution that belongs to a specificdevice, independent from other streams. It supports with statement as acontext manager to ensure the operators within the with block are runningon the corresponding stream. SeeCUDA semantics for details.
- Parameters
device (torch.device orint,optional) – a device on which to allocatethe stream. If
deviceisNone(default) or a negativeinteger, this will use the current device.priority (int,optional) – priority of the stream, which can be positive, 0, or negative.A lower number indicates a higher priority. By default, the priority is set to 0.If the value falls outside of the allowed priority range, it will automatically bemapped to the nearest valid priority (lowest for large positive numbers orhighest for large negative numbers).
- query()[source]#
Check if all the work submitted has been completed.
- Returns
A boolean indicating if all kernels in this stream are completed.
- Return type
- record_event(event=None)[source]#
Record an event.
- Parameters
event (torch.cuda.Event,optional) – event to record. If not given, a new onewill be allocated.
- Returns
Recorded event.
- synchronize()[source]#
Wait for all the kernels in this stream to complete.
Note
This is a wrapper around
cudaStreamSynchronize(): seeCUDA Stream documentation for more info.
- wait_event(event)[source]#
Make all future work submitted to the stream wait for an event.
- Parameters
event (torch.cuda.Event) – an event to wait for.
Note
This is a wrapper around
cudaStreamWaitEvent(): seeCUDA Stream documentation for more info.This function returns without waiting for
event: only futureoperations are affected.
- wait_stream(stream)[source]#
Synchronize with another stream.
All future work submitted to this stream will wait until all kernelssubmitted to a given stream at the time of call complete.
- Parameters
stream (Stream) – a stream to synchronize.
Note
This function returns without waiting for currently enqueuedkernels in
stream: only future operations are affected.