Module openj9.cuda
Package com.ibm.cuda

Class 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 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.
    • 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 device
        flags - the desired flags
        priority - 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 interface AutoCloseable
        Throws:
        CudaException - if a CUDA exception occurs
      • 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())