Module openj9.cuda
Package com.ibm.cuda

Class CudaStream

java.lang.Object
com.ibm.cuda.CudaStream
All Implemented Interfaces:
AutoCloseable

public final class CudaStream extends Object implements AutoCloseable
The CudaStream class represents an independent queue of work for a specific CudaDevice.

When no longer required, a stream must be closed.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    Default stream creation flag.
    static final int
    Stream creation flag requesting no implicit synchronization with the default stream.
  • Constructor Summary

    Constructors
    Constructor
    Description
    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 Type
    Method
    Description
    void
    Enqueues a callback to be run after all previous work on this stream has been completed.
    void
    Closes this stream.
    int
    Returns the flags of this stream.
    int
    Returns the priority of this stream.
    int
    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.

    Methods declared in class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • FLAG_DEFAULT

      public static final int FLAG_DEFAULT
      Default stream creation flag.
      See Also:
    • FLAG_NON_BLOCKING

      public static final int FLAG_NON_BLOCKING
      Stream creation flag requesting no implicit synchronization with the default stream.
      See Also:
  • Constructor Details

    • 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 device
      flags - the desired flags
      priority - the desired priority
      Throws:
      CudaException - if a CUDA exception occurs
  • Method Details

    • 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 interface AutoCloseable
      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 occurs
      IllegalStateException - if this stream has been closed (see close())
    • getPriority

      public int getPriority() throws CudaException
      Returns the priority of this stream.
      Returns:
      the priority of this stream
      Throws:
      CudaException - if a CUDA exception occurs
      IllegalStateException - if this stream has been closed (see close())
    • 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 (see close())
    • 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 occurs
      IllegalStateException - if this stream has been closed (see close())
    • 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 occurs
      IllegalStateException - if this stream has been closed (see close()), or the event has been closed (see CudaEvent.close())