- java.lang.Object
-
- com.ibm.cuda.CudaStream
-
- All Implemented Interfaces:
AutoCloseable
public final class CudaStream extends Object implements AutoCloseable
TheCudaStream
class represents an independent queue of work for a specificCudaDevice
.When no longer required, a stream must be
close
d.
-
-
Field Summary
Fields Modifier and Type Field Description static int
FLAG_DEFAULT
Default stream creation flag.static int
FLAG_NON_BLOCKING
Stream creation flag requesting no implicit synchronization with the default stream.
-
Constructor Summary
Constructors Constructor Description CudaStream(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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
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
getPriority()
Returns the priority of this stream.int
query()
Queries the state of this stream.void
synchronize()
Synchronizes with this stream.void
waitFor(CudaEvent event)
Makes all future work submitted to this stream wait for the specified event to occur.
-
-
-
Field Detail
-
FLAG_DEFAULT
public static final int FLAG_DEFAULT
Default stream creation flag.- See Also:
- Constant Field Values
-
FLAG_NON_BLOCKING
public static final int FLAG_NON_BLOCKING
Stream creation flag requesting no implicit synchronization with the default stream.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
CudaStream
public CudaStream(CudaDevice device) throws CudaException
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
public CudaStream(CudaDevice device, int flags, int priority) throws CudaException
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 Detail
-
addCallback
public void addCallback(Runnable callback) throws CudaException
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
public void close() throws CudaException
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
public int getFlags() throws CudaException
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
public int getPriority() throws CudaException
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
public void synchronize() throws CudaException
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
public void waitFor(CudaEvent event) throws CudaException
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()
)
-
-