Module openj9.cuda
Package com.ibm.cuda

Class CudaBuffer

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

public final class CudaBuffer extends Object implements AutoCloseable
The CudaBuffer class represents a region of memory on a specific device.

Data may be transferred between the device and the Java host via the various copyTo or copyFrom methods. A buffer may be filled with a specific pattern through use of one of the fillXxx methods.

When no longer required, a buffer must be closed.

  • Constructor Summary

    Constructors
    Constructor
    Description
    CudaBuffer(CudaDevice device, long byteCount)
    Allocates a new region on the specified device of size byteCount bytes.
  • Method Summary

    Modifier and Type
    Method
    Description
    atOffset(long fromOffset)
    Returns a sub-region of this buffer.
    void
    Releases the region of device memory backing this buffer.
    void
    copyFrom(byte[] array)
    Copies all data from the specified array (on the Java host) to this buffer (on the device).
    void
    copyFrom(byte[] array, int fromIndex, int toIndex)
    Copies data from the specified array (on the Java host) to this buffer (on the device).
    void
    copyFrom(char[] array)
    Copies all data from the specified array (on the Java host) to this buffer (on the device).
    void
    copyFrom(char[] array, int fromIndex, int toIndex)
    Copies data from the specified array (on the Java host) to this buffer (on the device).
    void
    copyFrom(double[] array)
    Copies all data from the specified array (on the Java host) to this buffer (on the device).
    void
    copyFrom(double[] array, int fromIndex, int toIndex)
    Copies data from the specified array (on the Java host) to this buffer (on the device).
    void
    copyFrom(float[] array)
    Copies all data from the specified array (on the Java host) to this buffer (on the device).
    void
    copyFrom(float[] array, int fromIndex, int toIndex)
    Copies data from the specified array (on the Java host) to this buffer (on the device).
    void
    copyFrom(int[] array)
    Copies all data from the specified array (on the Java host) to this buffer (on the device).
    void
    copyFrom(int[] array, int fromIndex, int toIndex)
    Copies data from the specified array (on the Java host) to this buffer (on the device).
    void
    copyFrom(long[] array)
    Copies all data from the specified array (on the Java host) to this buffer (on the device).
    void
    copyFrom(long[] array, int fromIndex, int toIndex)
    Copies data from the specified array (on the Java host) to this buffer (on the device).
    void
    copyFrom(short[] array)
    Copies all data from the specified array (on the Java host) to this buffer (on the device).
    void
    copyFrom(short[] array, int fromIndex, int toIndex)
    Copies data from the specified array (on the Java host) to this buffer (on the device).
    void
    copyFrom(CudaBuffer source, long fromOffset, long toOffset)
    Copies data from the specified source buffer (on a device) to this buffer (on the device).
    void
    Copies data from the specified source buffer (on the Java host) to this buffer (on the device).
    void
    Copies data from the specified source buffer (on the Java host) to this buffer (on the device).
    void
    Copies data from the specified source buffer (on the Java host) to this buffer (on the device).
    void
    Copies data from the specified source buffer (on the Java host) to this buffer (on the device).
    void
    Copies data from the specified source buffer (on the Java host) to this buffer (on the device).
    void
    Copies data from the specified source buffer (on the Java host) to this buffer (on the device).
    void
    Copies data from the specified source buffer (on the Java host) to this buffer (on the device).
    void
    copyTo(byte[] array)
    Copies data from this buffer (on the device) to the specified array (on the Java host).
    void
    copyTo(byte[] array, int fromIndex, int toIndex)
    Copies data from this buffer (on the device) to the specified array (on the Java host).
    void
    copyTo(char[] array)
    Copies data from this buffer (on the device) to the specified array (on the Java host).
    void
    copyTo(char[] array, int fromIndex, int toIndex)
    Copies data from this buffer (on the device) to the specified array (on the Java host).
    void
    copyTo(double[] array)
    Copies data from this buffer (on the device) to the specified array (on the Java host).
    void
    copyTo(double[] array, int fromIndex, int toIndex)
    Copies data from this buffer (on the device) to the specified array (on the Java host).
    void
    copyTo(float[] array)
    Copies data from this buffer (on the device) to the specified array (on the Java host).
    void
    copyTo(float[] array, int fromIndex, int toIndex)
    Copies data from this buffer (on the device) to the specified array (on the Java host).
    void
    copyTo(int[] array)
    Copies data from this buffer (on the device) to the specified array (on the Java host).
    void
    copyTo(int[] array, int fromIndex, int toIndex)
    Copies data from this buffer (on the device) to the specified array (on the Java host).
    void
    copyTo(long[] array)
    Copies data from this buffer (on the device) to the specified array (on the Java host).
    void
    copyTo(long[] array, int fromIndex, int toIndex)
    Copies data from this buffer (on the device) to the specified array (on the Java host).
    void
    copyTo(short[] array)
    Copies data from this buffer (on the device) to the specified array (on the Java host).
    void
    copyTo(short[] array, int fromIndex, int toIndex)
    Copies data from this buffer (on the device) to the specified array (on the Java host).
    void
    Copies data from this buffer (on the device) to the specified target buffer (on the Java host).
    void
    Copies data from this buffer (on the device) to the specified target buffer (on the Java host).
    void
    Copies data from this buffer (on the device) to the specified target buffer (on the Java host).
    void
    Copies data from this buffer (on the device) to the specified target buffer (on the Java host).
    void
    copyTo(IntBuffer target)
    Copies data from this buffer (on the device) to the specified target buffer (on the Java host).
    void
    Copies data from this buffer (on the device) to the specified target buffer (on the Java host).
    void
    Copies data from this buffer (on the device) to the specified target buffer (on the Java host).
    void
    fillByte(byte value, long count)
    Stores count copies of value in this buffer.
    void
    fillChar(char value, long count)
    Stores count copies of value in this buffer.
    void
    fillFloat(float value, long count)
    Stores count copies of value in this buffer.
    void
    fillInt(int value, long count)
    Stores count copies of value in this buffer.
    void
    fillShort(short value, long count)
    Stores count copies of value in this buffer.
    long
    Returns the length in bytes of this buffer.
    slice(long fromOffset, long toOffset)
    Returns a sub-region of this buffer.

    Methods declared in class java.lang.Object

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

    • CudaBuffer

      public CudaBuffer(CudaDevice device, long byteCount) throws CudaException
      Allocates a new region on the specified device of size byteCount bytes.
      Parameters:
      device - the device on which the region is to be allocated
      byteCount - the allocation size in bytes
      Throws:
      CudaException - if a CUDA exception occurs
  • Method Details

    • atOffset

      public CudaBuffer atOffset(long fromOffset)
      Returns a sub-region of this buffer. The new buffer begins at the specified offset and extends to the end of this buffer.
      Parameters:
      fromOffset - the byte offset of the sub-region within this buffer
      Returns:
      the specified sub-region
      Throws:
      IllegalStateException - if this buffer has been closed (see close())
      IndexOutOfBoundsException - if the specified offset is negative or larger than the length of this buffer
    • close

      public void close() throws CudaException
      Releases the region of device memory backing this buffer.

      Closing a buffer created via atOffset(long) with a non-zero offset has no effect: the memory is still accessible via the parent buffer which must be closed separately.

      Specified by:
      close in interface AutoCloseable
      Throws:
      CudaException - if a CUDA exception occurs
    • copyFrom

      public void copyFrom(byte[] array) throws CudaException
      Copies all data from the specified array (on the Java host) to this buffer (on the device). Equivalent to
       copyFrom(array, 0, array.length);
       
      Parameters:
      array - the source array
      Throws:
      CudaException - if a CUDA exception occurs
      IllegalStateException - if this buffer has been closed (see close())
      IndexOutOfBoundsException - if the number of source bytes is larger than the length of this buffer
    • copyFrom

      public void copyFrom(byte[] array, int fromIndex, int toIndex) throws CudaException
      Copies data from the specified array (on the Java host) to this buffer (on the device). Elements are read from array beginning at fromIndex continuing up to, but excluding, toIndex storing them in the same order in this buffer.

      A sub-buffer may be created (see atOffset(long)) when the data are to be copied somewhere other than the beginning of this buffer.

      Parameters:
      array - the source array
      fromIndex - the source starting offset (inclusive)
      toIndex - the source ending offset (exclusive)
      Throws:
      CudaException - if a CUDA exception occurs
      IllegalArgumentException - if fromIndex > toIndex
      IllegalStateException - if this buffer has been closed (see close())
      IndexOutOfBoundsException - if fromIndex is negative, toIndex > array.length, or the number of source bytes is larger than the length of this buffer
    • copyFrom

      public void copyFrom(ByteBuffer source) throws CudaException
      Copies data from the specified source buffer (on the Java host) to this buffer (on the device). Elements are read from source beginning at position() continuing up to, but excluding, limit() storing them in the same order in this buffer. The source buffer position is set to limit().

      A sub-buffer may be created (see atOffset(long)) when the data are to be copied somewhere other than the beginning of this buffer.

      Parameters:
      source - the source buffer
      Throws:
      CudaException - if a CUDA exception occurs
      IllegalStateException - if this buffer has been closed (see close())
      IndexOutOfBoundsException - if the number of source bytes is larger than the length of this buffer
    • copyFrom

      public void copyFrom(char[] array) throws CudaException
      Copies all data from the specified array (on the Java host) to this buffer (on the device). Equivalent to
       copyFrom(array, 0, array.length);
       
      Parameters:
      array - the source array
      Throws:
      CudaException - if a CUDA exception occurs
      IllegalStateException - if this buffer has been closed (see close())
      IndexOutOfBoundsException - if the number of source bytes is larger than the length of this buffer
    • copyFrom

      public void copyFrom(char[] array, int fromIndex, int toIndex) throws CudaException
      Copies data from the specified array (on the Java host) to this buffer (on the device). Elements are read from array beginning at fromIndex continuing up to, but excluding, toIndex storing them in the same order in this buffer.

      A sub-buffer may be created (see atOffset(long)) when the data are to be copied somewhere other than the beginning of this buffer.

      Parameters:
      array - the source array
      fromIndex - the source starting offset (inclusive)
      toIndex - the source ending offset (exclusive)
      Throws:
      CudaException - if a CUDA exception occurs
      IllegalArgumentException - if fromIndex > toIndex
      IllegalStateException - if this buffer has been closed (see close())
      IndexOutOfBoundsException - if fromIndex is negative, toIndex > array.length, or the number of source bytes is larger than the length of this buffer
    • copyFrom

      public void copyFrom(CharBuffer source) throws CudaException
      Copies data from the specified source buffer (on the Java host) to this buffer (on the device). Elements are read from source beginning at position() continuing up to, but excluding, limit() storing them in the same order in this buffer. The source buffer position is set to limit().

      A sub-buffer may be created (see atOffset(long)) when the data are to be copied somewhere other than the beginning of this buffer.

      Parameters:
      source - the source buffer
      Throws:
      CudaException - if a CUDA exception occurs
      IllegalStateException - if this buffer has been closed (see close())
      IndexOutOfBoundsException - if the number of source bytes is larger than the length of this buffer
    • copyFrom

      public void copyFrom(CudaBuffer source, long fromOffset, long toOffset) throws CudaException
      Copies data from the specified source buffer (on a device) to this buffer (on the device). Elements are read from source beginning at position() continuing up to, but excluding, limit() storing them in the same order in this buffer.

      A sub-buffer may be created (see atOffset(long)) when the data are to be copied somewhere other than the beginning of this buffer.

      Parameters:
      source - the source buffer
      fromOffset - the source starting offset (inclusive)
      toOffset - the source ending offset (exclusive)
      Throws:
      CudaException - if a CUDA exception occurs
      IllegalStateException - if this buffer has been closed (see close())
      IndexOutOfBoundsException - if either fromOffset or toOffset is not a legal offset within the source buffer or the number of source bytes is larger than the length of this buffer
    • copyFrom

      public void copyFrom(double[] array) throws CudaException
      Copies all data from the specified array (on the Java host) to this buffer (on the device). Equivalent to
       copyFrom(array, 0, array.length);
       
      Parameters:
      array - the source array
      Throws:
      CudaException - if a CUDA exception occurs
      IllegalStateException - if this buffer has been closed (see close())
      IndexOutOfBoundsException - if the number of source bytes is larger than the length of this buffer
    • copyFrom

      public void copyFrom(double[] array, int fromIndex, int toIndex) throws CudaException
      Copies data from the specified array (on the Java host) to this buffer (on the device). Elements are read from array beginning at fromIndex continuing up to, but excluding, toIndex storing them in the same order in this buffer.

      A sub-buffer may be created (see atOffset(long)) when the data are to be copied somewhere other than the beginning of this buffer.

      Parameters:
      array - the source array
      fromIndex - the source starting offset (inclusive)
      toIndex - the source ending offset (exclusive)
      Throws:
      CudaException - if a CUDA exception occurs
      IllegalArgumentException - if fromIndex > toIndex
      IllegalStateException - if this buffer has been closed (see close())
      IndexOutOfBoundsException - if fromIndex is negative, toIndex > array.length, or the number of source bytes is larger than the length of this buffer
    • copyFrom

      public void copyFrom(DoubleBuffer source) throws CudaException
      Copies data from the specified source buffer (on the Java host) to this buffer (on the device). Elements are read from source beginning at position() continuing up to, but excluding, limit() storing them in the same order in this buffer. The source buffer position is set to limit().

      A sub-buffer may be created (see atOffset(long)) when the data are to be copied somewhere other than the beginning of this buffer.

      Parameters:
      source - the source buffer
      Throws:
      CudaException - if a CUDA exception occurs
      IllegalStateException - if this buffer has been closed (see close())
      IndexOutOfBoundsException - if the number of source bytes is larger than the length of this buffer
    • copyFrom

      public void copyFrom(float[] array) throws CudaException
      Copies all data from the specified array (on the Java host) to this buffer (on the device). Equivalent to
       copyFrom(array, 0, array.length);
       
      Parameters:
      array - the source array
      Throws:
      CudaException - if a CUDA exception occurs
      IllegalStateException - if this buffer has been closed (see close())
      IndexOutOfBoundsException - if the number of source bytes is larger than the length of this buffer
    • copyFrom

      public void copyFrom(float[] array, int fromIndex, int toIndex) throws CudaException
      Copies data from the specified array (on the Java host) to this buffer (on the device). Elements are read from array beginning at fromIndex continuing up to, but excluding, toIndex storing them in the same order in this buffer.

      A sub-buffer may be created (see atOffset(long)) when the data are to be copied somewhere other than the beginning of this buffer.

      Parameters:
      array - the source array
      fromIndex - the source starting offset (inclusive)
      toIndex - the source ending offset (exclusive)
      Throws:
      CudaException - if a CUDA exception occurs
      IllegalArgumentException - if fromIndex > toIndex
      IllegalStateException - if this buffer has been closed (see close())
      IndexOutOfBoundsException - if fromIndex is negative, toIndex > array.length, or the number of source bytes is larger than the length of this buffer
    • copyFrom

      public void copyFrom(FloatBuffer source) throws CudaException
      Copies data from the specified source buffer (on the Java host) to this buffer (on the device). Elements are read from source beginning at position() continuing up to, but excluding, limit() storing them in the same order in this buffer. The source buffer position is set to limit().

      A sub-buffer may be created (see atOffset(long)) when the data are to be copied somewhere other than the beginning of this buffer.

      Parameters:
      source - the source buffer
      Throws:
      CudaException - if a CUDA exception occurs
      IllegalStateException - if this buffer has been closed (see close())
      IndexOutOfBoundsException - if the number of source bytes is larger than the length of this buffer
    • copyFrom

      public void copyFrom(int[] array) throws CudaException
      Copies all data from the specified array (on the Java host) to this buffer (on the device). Equivalent to
       copyFrom(array, 0, array.length);
       
      Parameters:
      array - the source array
      Throws:
      CudaException - if a CUDA exception occurs
      IllegalStateException - if this buffer has been closed (see close())
      IndexOutOfBoundsException - if the number of source bytes is larger than the length of this buffer
    • copyFrom

      public void copyFrom(int[] array, int fromIndex, int toIndex) throws CudaException
      Copies data from the specified array (on the Java host) to this buffer (on the device). Elements are read from array beginning at fromIndex continuing up to, but excluding, toIndex storing them in the same order in this buffer.

      A sub-buffer may be created (see atOffset(long)) when the data are to be copied somewhere other than the beginning of this buffer.

      Parameters:
      array - the source array
      fromIndex - the source starting offset (inclusive)
      toIndex - the source ending offset (exclusive)
      Throws:
      CudaException - if a CUDA exception occurs
      IllegalArgumentException - if fromIndex > toIndex
      IllegalStateException - if this buffer has been closed (see close())
      IndexOutOfBoundsException - if fromIndex is negative, toIndex > array.length, or the number of source bytes is larger than the length of this buffer
    • copyFrom

      public void copyFrom(IntBuffer source) throws CudaException
      Copies data from the specified source buffer (on the Java host) to this buffer (on the device). Elements are read from source beginning at position() continuing up to, but excluding, limit() storing them in the same order in this buffer. The source buffer position is set to limit().

      A sub-buffer may be created (see atOffset(long)) when the data are to be copied somewhere other than the beginning of this buffer.

      Parameters:
      source - the source buffer
      Throws:
      CudaException - if a CUDA exception occurs
      IllegalStateException - if this buffer has been closed (see close())
      IndexOutOfBoundsException - if the number of source bytes is larger than the length of this buffer
    • copyFrom

      public void copyFrom(long[] array) throws CudaException
      Copies all data from the specified array (on the Java host) to this buffer (on the device). Equivalent to
       copyFrom(array, 0, array.length);
       
      Parameters:
      array - the source array
      Throws:
      CudaException - if a CUDA exception occurs
      IllegalStateException - if this buffer has been closed (see close())
      IndexOutOfBoundsException - if the number of source bytes is larger than the length of this buffer
    • copyFrom

      public void copyFrom(long[] array, int fromIndex, int toIndex) throws CudaException
      Copies data from the specified array (on the Java host) to this buffer (on the device). Elements are read from array beginning at fromIndex continuing up to, but excluding, toIndex storing them in the same order in this buffer.

      A sub-buffer may be created (see atOffset(long)) when the data are to be copied somewhere other than the beginning of this buffer.

      Parameters:
      array - the source array
      fromIndex - the source starting offset (inclusive)
      toIndex - the source ending offset (exclusive)
      Throws:
      CudaException - if a CUDA exception occurs
      IllegalArgumentException - if fromIndex > toIndex
      IllegalStateException - if this buffer has been closed (see close())
      IndexOutOfBoundsException - if fromIndex is negative, toIndex > array.length, or the number of source bytes is larger than the length of this buffer
    • copyFrom

      public void copyFrom(LongBuffer source) throws CudaException
      Copies data from the specified source buffer (on the Java host) to this buffer (on the device). Elements are read from source beginning at position() continuing up to, but excluding, limit() storing them in the same order in this buffer. The source buffer position is set to limit().

      A sub-buffer may be created (see atOffset(long)) when the data are to be copied somewhere other than the beginning of this buffer.

      Parameters:
      source - the source buffer
      Throws:
      CudaException - if a CUDA exception occurs
      IllegalStateException - if this buffer has been closed (see close())
      IndexOutOfBoundsException - if the number of source bytes is larger than the length of this buffer
    • copyFrom

      public void copyFrom(short[] array) throws CudaException
      Copies all data from the specified array (on the Java host) to this buffer (on the device). Equivalent to
       copyFrom(array, 0, array.length);
       
      Parameters:
      array - the source array
      Throws:
      CudaException - if a CUDA exception occurs
      IllegalStateException - if this buffer has been closed (see close())
      IndexOutOfBoundsException - if the number of source bytes is larger than the length of this buffer
    • copyFrom

      public void copyFrom(short[] array, int fromIndex, int toIndex) throws CudaException
      Copies data from the specified array (on the Java host) to this buffer (on the device). Elements are read from array beginning at fromIndex continuing up to, but excluding, toIndex storing them in the same order in this buffer.

      A sub-buffer may be created (see atOffset(long)) when the data are to be copied somewhere other than the beginning of this buffer.

      Parameters:
      array - the source array
      fromIndex - the source starting offset (inclusive)
      toIndex - the source ending offset (exclusive)
      Throws:
      CudaException - if a CUDA exception occurs
      IllegalArgumentException - if fromIndex > toIndex
      IllegalStateException - if this buffer has been closed (see close())
      IndexOutOfBoundsException - if fromIndex is negative, toIndex > array.length, or the number of source bytes is larger than the length of this buffer
    • copyFrom

      public void copyFrom(ShortBuffer source) throws CudaException
      Copies data from the specified source buffer (on the Java host) to this buffer (on the device). Elements are read from source beginning at position() continuing up to, but excluding, limit() storing them in the same order in this buffer. The source buffer position is set to limit().

      A sub-buffer may be created (see atOffset(long)) when the data are to be copied somewhere other than the beginning of this buffer.

      Parameters:
      source - the source buffer
      Throws:
      CudaException - if a CUDA exception occurs
      IllegalStateException - if this buffer has been closed (see close())
      IndexOutOfBoundsException - if the number of source bytes is larger than the length of this buffer
    • copyTo

      public void copyTo(byte[] array) throws CudaException
      Copies data from this buffer (on the device) to the specified array (on the Java host). Equivalent to
       copyTo(array, 0, array.length);
       
      Parameters:
      array - the destination array
      Throws:
      CudaException - if a CUDA exception occurs
      IllegalStateException - if this buffer has been closed (see close())
      IndexOutOfBoundsException - if the number of required source bytes is larger than the length of this buffer
    • copyTo

      public void copyTo(byte[] array, int fromIndex, int toIndex) throws CudaException
      Copies data from this buffer (on the device) to the specified array (on the Java host). Elements are read starting at the beginning of this buffer and stored in array beginning at fromIndex continuing up to, but excluding, toIndex.

      A sub-buffer may be created (see atOffset(long)) when the source data are not located at the beginning of this buffer.

      Parameters:
      array - the destination array
      fromIndex - the destination starting offset (inclusive)
      toIndex - the destination ending offset (exclusive)
      Throws:
      CudaException - if a CUDA exception occurs
      IllegalArgumentException - if fromIndex > toIndex
      IllegalStateException - if this buffer has been closed (see close())
      IndexOutOfBoundsException - if fromIndex is negative, toIndex > array.length, or the number of required source bytes is larger than the length of this buffer
    • copyTo

      public void copyTo(ByteBuffer target) throws CudaException
      Copies data from this buffer (on the device) to the specified target buffer (on the Java host). Elements are read starting at the beginning of this buffer and stored in target beginning at position() continuing up to, but excluding, limit(). The target buffer position is set to limit().

      A sub-buffer may be created (see atOffset(long)) when the source data are not located at the beginning of this buffer.

      Parameters:
      target - the destination buffer
      Throws:
      CudaException - if a CUDA exception occurs
      IllegalStateException - if this buffer has been closed (see close())
      IndexOutOfBoundsException - if the number of required source bytes is larger than the length of this buffer
    • copyTo

      public void copyTo(char[] array) throws CudaException
      Copies data from this buffer (on the device) to the specified array (on the Java host). Equivalent to
       copyTo(array, 0, array.length);
       
      Parameters:
      array - the destination array
      Throws:
      CudaException - if a CUDA exception occurs
      IllegalStateException - if this buffer has been closed (see close())
      IndexOutOfBoundsException - if the number of required source bytes is larger than the length of this buffer
    • copyTo

      public void copyTo(char[] array, int fromIndex, int toIndex) throws CudaException
      Copies data from this buffer (on the device) to the specified array (on the Java host). Elements are read starting at the beginning of this buffer and stored in array beginning at fromIndex continuing up to, but excluding, toIndex.

      A sub-buffer may be created (see atOffset(long)) when the source data are not located at the beginning of this buffer.

      Parameters:
      array - the destination array
      fromIndex - the destination starting offset (inclusive)
      toIndex - the destination ending offset (exclusive)
      Throws:
      CudaException - if a CUDA exception occurs
      IllegalArgumentException - if fromIndex > toIndex
      IllegalStateException - if this buffer has been closed (see close())
      IndexOutOfBoundsException - if fromIndex is negative, toIndex > array.length, or the number of required source bytes is larger than the length of this buffer
    • copyTo

      public void copyTo(CharBuffer target) throws CudaException
      Copies data from this buffer (on the device) to the specified target buffer (on the Java host). Elements are read starting at the beginning of this buffer and stored in target beginning at position() continuing up to, but excluding, limit(). The target buffer position is set to limit().

      A sub-buffer may be created (see atOffset(long)) when the source data are not located at the beginning of this buffer.

      Parameters:
      target - the destination buffer
      Throws:
      CudaException - if a CUDA exception occurs
      IllegalStateException - if this buffer has been closed (see close())
      IndexOutOfBoundsException - if the number of required source bytes is larger than the length of this buffer
    • copyTo

      public void copyTo(double[] array) throws CudaException
      Copies data from this buffer (on the device) to the specified array (on the Java host). Equivalent to
       copyTo(array, 0, array.length);
       
      Parameters:
      array - the destination array
      Throws:
      CudaException - if a CUDA exception occurs
      IllegalStateException - if this buffer has been closed (see close())
      IndexOutOfBoundsException - if the number of required source bytes is larger than the length of this buffer
    • copyTo

      public void copyTo(double[] array, int fromIndex, int toIndex) throws CudaException
      Copies data from this buffer (on the device) to the specified array (on the Java host). Elements are read starting at the beginning of this buffer and stored in array beginning at fromIndex continuing up to, but excluding, toIndex.

      A sub-buffer may be created (see atOffset(long)) when the source data are not located at the beginning of this buffer.

      Parameters:
      array - the destination array
      fromIndex - the destination starting offset (inclusive)
      toIndex - the destination ending offset (exclusive)
      Throws:
      CudaException - if a CUDA exception occurs
      IllegalArgumentException - if fromIndex > toIndex
      IllegalStateException - if this buffer has been closed (see close())
      IndexOutOfBoundsException - if fromIndex is negative, toIndex > array.length, or the number of required source bytes is larger than the length of this buffer
    • copyTo

      public void copyTo(DoubleBuffer target) throws CudaException
      Copies data from this buffer (on the device) to the specified target buffer (on the Java host). Elements are read starting at the beginning of this buffer and stored in target beginning at position() continuing up to, but excluding, limit(). The target buffer position is set to limit().

      A sub-buffer may be created (see atOffset(long)) when the source data are not located at the beginning of this buffer.

      Parameters:
      target - the destination buffer
      Throws:
      CudaException - if a CUDA exception occurs
      IllegalStateException - if this buffer has been closed (see close())
      IndexOutOfBoundsException - if the number of required source bytes is larger than the length of this buffer
    • copyTo

      public void copyTo(float[] array) throws CudaException
      Copies data from this buffer (on the device) to the specified array (on the Java host). Equivalent to
       copyTo(array, 0, array.length);
       
      Parameters:
      array - the destination array
      Throws:
      CudaException - if a CUDA exception occurs
      IllegalStateException - if this buffer has been closed (see close())
      IndexOutOfBoundsException - if the number of required source bytes is larger than the length of this buffer
    • copyTo

      public void copyTo(float[] array, int fromIndex, int toIndex) throws CudaException
      Copies data from this buffer (on the device) to the specified array (on the Java host). Elements are read starting at the beginning of this buffer and stored in array beginning at fromIndex continuing up to, but excluding, toIndex.

      A sub-buffer may be created (see atOffset(long)) when the source data are not located at the beginning of this buffer.

      Parameters:
      array - the destination array
      fromIndex - the destination starting offset (inclusive)
      toIndex - the destination ending offset (exclusive)
      Throws:
      CudaException - if a CUDA exception occurs
      IllegalArgumentException - if fromIndex > toIndex
      IllegalStateException - if this buffer has been closed (see close())
      IndexOutOfBoundsException - if fromIndex is negative, toIndex > array.length, or the number of required source bytes is larger than the length of this buffer
    • copyTo

      public void copyTo(FloatBuffer target) throws CudaException
      Copies data from this buffer (on the device) to the specified target buffer (on the Java host). Elements are read starting at the beginning of this buffer and stored in target beginning at position() continuing up to, but excluding, limit(). The target buffer position is set to limit().

      A sub-buffer may be created (see atOffset(long)) when the source data are not located at the beginning of this buffer.

      Parameters:
      target - the destination buffer
      Throws:
      CudaException - if a CUDA exception occurs
      IllegalStateException - if this buffer has been closed (see close())
      IndexOutOfBoundsException - if the number of required source bytes is larger than the length of this buffer
    • copyTo

      public void copyTo(int[] array) throws CudaException
      Copies data from this buffer (on the device) to the specified array (on the Java host). Equivalent to
       copyTo(array, 0, array.length);
       
      Parameters:
      array - the destination array
      Throws:
      CudaException - if a CUDA exception occurs
      IllegalStateException - if this buffer has been closed (see close())
      IndexOutOfBoundsException - if the number of required source bytes is larger than the length of this buffer
    • copyTo

      public void copyTo(int[] array, int fromIndex, int toIndex) throws CudaException
      Copies data from this buffer (on the device) to the specified array (on the Java host). Elements are read starting at the beginning of this buffer and stored in array beginning at fromIndex continuing up to, but excluding, toIndex.

      A sub-buffer may be created (see atOffset(long)) when the source data are not located at the beginning of this buffer.

      Parameters:
      array - the destination array
      fromIndex - the destination starting offset (inclusive)
      toIndex - the destination ending offset (exclusive)
      Throws:
      CudaException - if a CUDA exception occurs
      IllegalArgumentException - if fromIndex > toIndex
      IllegalStateException - if this buffer has been closed (see close())
      IndexOutOfBoundsException - if fromIndex is negative, toIndex > array.length, or the number of required source bytes is larger than the length of this buffer
    • copyTo

      public void copyTo(IntBuffer target) throws CudaException
      Copies data from this buffer (on the device) to the specified target buffer (on the Java host). Elements are read starting at the beginning of this buffer and stored in target beginning at position() continuing up to, but excluding, limit(). The target buffer position is set to limit().

      A sub-buffer may be created (see atOffset(long)) when the source data are not located at the beginning of this buffer.

      Parameters:
      target - the destination buffer
      Throws:
      CudaException - if a CUDA exception occurs
      IllegalStateException - if this buffer has been closed (see close())
      IndexOutOfBoundsException - if the number of required source bytes is larger than the length of this buffer
    • copyTo

      public void copyTo(long[] array) throws CudaException
      Copies data from this buffer (on the device) to the specified array (on the Java host). Equivalent to
       copyTo(array, 0, array.length);
       
      Parameters:
      array - the destination array
      Throws:
      CudaException - if a CUDA exception occurs
      IllegalStateException - if this buffer has been closed (see close())
      IndexOutOfBoundsException - if the number of required source bytes is larger than the length of this buffer
    • copyTo

      public void copyTo(long[] array, int fromIndex, int toIndex) throws CudaException
      Copies data from this buffer (on the device) to the specified array (on the Java host). Elements are read starting at the beginning of this buffer and stored in array beginning at fromIndex continuing up to, but excluding, toIndex.

      A sub-buffer may be created (see atOffset(long)) when the source data are not located at the beginning of this buffer.

      Parameters:
      array - the destination array
      fromIndex - the destination starting offset (inclusive)
      toIndex - the destination ending offset (exclusive)
      Throws:
      CudaException - if a CUDA exception occurs
      IllegalArgumentException - if fromIndex > toIndex
      IllegalStateException - if this buffer has been closed (see close())
      IndexOutOfBoundsException - if fromIndex is negative, toIndex > array.length, or the number of required source bytes is larger than the length of this buffer
    • copyTo

      public void copyTo(LongBuffer target) throws CudaException
      Copies data from this buffer (on the device) to the specified target buffer (on the Java host). Elements are read starting at the beginning of this buffer and stored in target beginning at position() continuing up to, but excluding, limit(). The target buffer position is set to limit().

      A sub-buffer may be created (see atOffset(long)) when the source data are not located at the beginning of this buffer.

      Parameters:
      target - the destination buffer
      Throws:
      CudaException - if a CUDA exception occurs
      IllegalStateException - if this buffer has been closed (see close())
      IndexOutOfBoundsException - if the number of required source bytes is larger than the length of this buffer
    • copyTo

      public void copyTo(short[] array) throws CudaException
      Copies data from this buffer (on the device) to the specified array (on the Java host). Equivalent to
       copyTo(array, 0, array.length);
       
      Parameters:
      array - the destination array
      Throws:
      CudaException - if a CUDA exception occurs
      IllegalStateException - if this buffer has been closed (see close())
      IndexOutOfBoundsException - if the number of required source bytes is larger than the length of this buffer
    • copyTo

      public void copyTo(short[] array, int fromIndex, int toIndex) throws CudaException
      Copies data from this buffer (on the device) to the specified array (on the Java host). Elements are read starting at the beginning of this buffer and stored in array beginning at fromIndex continuing up to, but excluding, toIndex.

      A sub-buffer may be created (see atOffset(long)) when the source data are not located at the beginning of this buffer.

      Parameters:
      array - the destination array
      fromIndex - the destination starting offset (inclusive)
      toIndex - the destination ending offset (exclusive)
      Throws:
      CudaException - if a CUDA exception occurs
      IllegalArgumentException - if fromIndex > toIndex
      IllegalStateException - if this buffer has been closed (see close())
      IndexOutOfBoundsException - if fromIndex is negative, toIndex > array.length, or the number of required source bytes is larger than the length of this buffer
    • copyTo

      public void copyTo(ShortBuffer target) throws CudaException
      Copies data from this buffer (on the device) to the specified target buffer (on the Java host). Elements are read starting at the beginning of this buffer and stored in target beginning at position() continuing up to, but excluding, limit(). The target buffer position is set to limit().

      A sub-buffer may be created (see atOffset(long)) when the source data are not located at the beginning of this buffer.

      Parameters:
      target - the destination buffer
      Throws:
      CudaException - if a CUDA exception occurs
      IllegalStateException - if this buffer has been closed (see close())
      IndexOutOfBoundsException - if the number of required source bytes is larger than the length of this buffer
    • fillByte

      public void fillByte(byte value, long count) throws CudaException
      Stores count copies of value in this buffer.

      A sub-buffer may be created (see atOffset(long)) when the values are to be stored somewhere other than the beginning of this buffer.

      Parameters:
      value - the destination array
      count - the destination array
      Throws:
      CudaException - if a CUDA exception occurs
      IllegalStateException - if this buffer has been closed (see close())
      IndexOutOfBoundsException - if the space required is larger than the length of this buffer
    • fillChar

      public void fillChar(char value, long count) throws CudaException
      Stores count copies of value in this buffer.

      A sub-buffer may be created (see atOffset(long)) when the values are to be stored somewhere other than the beginning of this buffer.

      Parameters:
      value - the destination array
      count - the destination array
      Throws:
      CudaException - if a CUDA exception occurs
      IllegalStateException - if this buffer has been closed (see close())
      IndexOutOfBoundsException - if the space required is larger than the length of this buffer
    • fillFloat

      public void fillFloat(float value, long count) throws CudaException
      Stores count copies of value in this buffer.

      A sub-buffer may be created (see atOffset(long)) when the values are to be stored somewhere other than the beginning of this buffer.

      Parameters:
      value - the destination array
      count - the destination array
      Throws:
      CudaException - if a CUDA exception occurs
      IllegalStateException - if this buffer has been closed (see close())
      IndexOutOfBoundsException - if the space required is larger than the length of this buffer
    • fillInt

      public void fillInt(int value, long count) throws CudaException
      Stores count copies of value in this buffer.

      A sub-buffer may be created (see atOffset(long)) when the values are to be stored somewhere other than the beginning of this buffer.

      Parameters:
      value - the destination array
      count - the destination array
      Throws:
      CudaException - if a CUDA exception occurs
      IllegalStateException - if this buffer has been closed (see close())
      IndexOutOfBoundsException - if the space required is larger than the length of this buffer
    • fillShort

      public void fillShort(short value, long count) throws CudaException
      Stores count copies of value in this buffer.

      A sub-buffer may be created (see atOffset(long)) when the values are to be stored somewhere other than the beginning of this buffer.

      Parameters:
      value - the destination array
      count - the destination array
      Throws:
      CudaException - if a CUDA exception occurs
      IllegalStateException - if this buffer has been closed (see close())
      IndexOutOfBoundsException - if the space required is larger than the length of this buffer
    • getLength

      public long getLength()
      Returns the length in bytes of this buffer.
      Returns:
      the length in bytes of this buffer
    • slice

      public CudaBuffer slice(long fromOffset, long toOffset)
      Returns a sub-region of this buffer. The new buffer begins at the specified fromOffset and extends to the specified toOffset (exclusive).
      Parameters:
      fromOffset - the byte offset of the start of the sub-region within this buffer
      toOffset - the byte offset of the end of the sub-region within this buffer
      Returns:
      the specified sub-region
      Throws:
      IllegalArgumentException - if fromOffset > toOffset
      IllegalStateException - if this buffer has been closed (see close())
      IndexOutOfBoundsException - if fromOffset is negative, toOffset > length, or the number of source bytes is larger than the length of this buffer