java.lang.Object
com.ibm.cuda.CudaStream
- All Implemented Interfaces:
AutoCloseable
The
CudaStream
class represents an independent queue of work for a
specific CudaDevice
.
When no longer required, a stream must be close
d.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
Default stream creation flag.static final int
Stream creation flag requesting no implicit synchronization with the default stream. -
Constructor Summary
ConstructorDescriptionCudaStream
(CudaDevice device) Creates a new stream on the specified device, with the default flags and the default priority.CudaStream
(CudaDevice device, int flags, int priority) Creates a new stream on the specified device, with the specified flags and priority. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addCallback
(Runnable callback) Enqueues a callback to be run after all previous work on this stream has been completed.void
close()
Closes this stream.int
getFlags()
Returns the flags of this stream.int
Returns the priority of this stream.int
query()
Queries the state of this stream.void
Synchronizes with this stream.void
Makes all future work submitted to this stream wait for the specified event to occur.
-
Field Details
-
FLAG_DEFAULT
public static final int FLAG_DEFAULTDefault stream creation flag.- See Also:
-
FLAG_NON_BLOCKING
public static final int FLAG_NON_BLOCKINGStream creation flag requesting no implicit synchronization with the default stream.- See Also:
-
-
Constructor Details
-
CudaStream
Creates a new stream on the specified device, with the default flags and the default priority.- Parameters:
device
- the specified device- Throws:
CudaException
- if a CUDA exception occurs
-
CudaStream
Creates a new stream on the specified device, with the specified flags and priority.- Parameters:
device
- the specified deviceflags
- the desired flagspriority
- the desired priority- Throws:
CudaException
- if a CUDA exception occurs
-
-
Method Details
-
addCallback
Enqueues a callback to be run after all previous work on this stream has been completed.Note that the callback will occur on a distinct thread. Further, any attempts to interact with CUDA devices will fail with a CudaException with code
CudaError.NotPermitted
.- Parameters:
callback
- the runnable to be run- Throws:
CudaException
- if a CUDA exception occurs
-
close
Closes this stream. Any work queued on this stream will be allowed to complete: this method does not wait for that work (if any) to complete.- Specified by:
close
in interfaceAutoCloseable
- Throws:
CudaException
- if a CUDA exception occurs
-
getFlags
Returns the flags of this stream.- Returns:
- the flags of this stream
- Throws:
CudaException
- if a CUDA exception occursIllegalStateException
- if this stream has been closed (seeclose()
)
-
getPriority
Returns the priority of this stream.- Returns:
- the priority of this stream
- Throws:
CudaException
- if a CUDA exception occursIllegalStateException
- if this stream has been closed (seeclose()
)
-
query
public int query()Queries the state of this stream. The common normally occurring states are:- CudaError.Success - stream has no pending work
- CudaError.NotReady - stream has pending work
- Returns:
- the state of this stream
- Throws:
IllegalStateException
- if this stream has been closed (seeclose()
)
-
synchronize
Synchronizes with this stream. This method blocks until all work queued on this stream has completed.- Throws:
CudaException
- if a CUDA exception occursIllegalStateException
- if this stream has been closed (seeclose()
)
-
waitFor
Makes all future work submitted to this stream wait for the specified event to occur.- Parameters:
event
- the specified event- Throws:
CudaException
- if a CUDA exception occursIllegalStateException
- if this stream has been closed (seeclose()
), or the event has been closed (seeCudaEvent.close()
)
-