Class CyCLBuffer


  • public class CyCLBuffer
    extends Object
    Provides functionality associated with an OpenCL memory object.
    Author:
    Dimitry Tegunov
    • Constructor Summary

      Constructors 
      Constructor Description
      CyCLBuffer​(CyCLContext context, byte[] data)
      Allocates device memory to fit all elements in data, and copies its contents
      CyCLBuffer​(CyCLContext context, double[] data)
      Allocates device memory to fit all elements in data, and copies its contents
      CyCLBuffer​(CyCLContext context, float[] data)
      Allocates device memory to fit all elements in data, and copies its contents
      CyCLBuffer​(CyCLContext context, int[] data)
      Allocates device memory to fit all elements in data, and copies its contents
      CyCLBuffer​(CyCLContext context, long[] data)
      Allocates device memory to fit all elements in data, and copies its contents
      CyCLBuffer​(CyCLContext context, short[] data)
      Allocates device memory to fit all elements in data, and copies its contents
      CyCLBuffer​(CyCLContext context, Class<?> type, int elements)
      Allocates [sizeof(type) * elements] bytes in device memory without copying any host data
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int elementSize()
      Returns the number of bytes associated with the CyCLBuffer's element type.
      protected void finalize()
      Frees all device memory associated with the buffer.
      void free()
      Frees all device memory associated with the buffer.
      void getFromDevice​(byte[] data)
      Copies data from device to host memory.
      void getFromDevice​(byte[] data, int length, int offset)
      Copies data from device to host memory.
      void getFromDevice​(double[] data)
      Copies data from device to host memory.
      void getFromDevice​(double[] data, int length, int offset)
      Copies data from device to host memory.
      void getFromDevice​(float[] data)
      Copies data from device to host memory.
      void getFromDevice​(float[] data, int length, int offset)
      Copies data from device to host memory.
      void getFromDevice​(int[] data)
      Copies data from device to host memory.
      void getFromDevice​(int[] data, int length, int offset)
      Copies data from device to host memory.
      void getFromDevice​(long[] data)
      Copies data from device to host memory.
      void getFromDevice​(long[] data, int length, int offset)
      Copies data from device to host memory.
      void getFromDevice​(short[] data)
      Copies data from device to host memory.
      void getFromDevice​(short[] data, int length, int offset)
      Copies data from device to host memory.
      org.lwjgl.opencl.CLMem getMemObject()
      Gets the underlying memory object.
      void setFromDevice​(CyCLBuffer src)
      Copies data from another device buffer to this one.
      void setFromDevice​(CyCLBuffer src, long bytes, long offsetSrc, long offsetDst)
      Copies data from another device buffer to this one.
      void setFromHost​(byte[] data)
      Copies data from host to device memory.
      void setFromHost​(byte[] data, int length, int offset)
      Copies data from host to device memory.
      void setFromHost​(double[] data)
      Copies data from host to device memory.
      void setFromHost​(double[] data, int length, int offset)
      Copies data from host to device memory.
      void setFromHost​(float[] data)
      Copies data from host to device memory.
      void setFromHost​(float[] data, int length, int offset)
      Copies data from host to device memory.
      void setFromHost​(int[] data)
      Copies data from host to device memory.
      void setFromHost​(int[] data, int length, int offset)
      Copies data from host to device memory.
      void setFromHost​(long[] data)
      Copies data from host to device memory.
      void setFromHost​(long[] data, int length, int offset)
      Copies data from host to device memory.
      void setFromHost​(short[] data)
      Copies data from host to device memory.
      void setFromHost​(short[] data, int length, int offset)
      Copies data from host to device memory.
      int sizeInBytes()
      Returns the overall buffer size in bytes.
    • Constructor Detail

      • CyCLBuffer

        public CyCLBuffer​(CyCLContext context,
                          Class<?> type,
                          int elements)
        Allocates [sizeof(type) * elements] bytes in device memory without copying any host data
        Parameters:
        context - The context of the device where the memory should be allocated
        type - Element type
        elements - Number of elements
      • CyCLBuffer

        public CyCLBuffer​(CyCLContext context,
                          byte[] data)
        Allocates device memory to fit all elements in data, and copies its contents
        Parameters:
        context - The context of the device where the memory should be allocated
        data - Data to be copied into device memory
      • CyCLBuffer

        public CyCLBuffer​(CyCLContext context,
                          short[] data)
        Allocates device memory to fit all elements in data, and copies its contents
        Parameters:
        context - The context of the device where the memory should be allocated
        data - Data to be copied into device memory
      • CyCLBuffer

        public CyCLBuffer​(CyCLContext context,
                          int[] data)
        Allocates device memory to fit all elements in data, and copies its contents
        Parameters:
        context - The context of the device where the memory should be allocated
        data - Data to be copied into device memory
      • CyCLBuffer

        public CyCLBuffer​(CyCLContext context,
                          long[] data)
        Allocates device memory to fit all elements in data, and copies its contents
        Parameters:
        context - The context of the device where the memory should be allocated
        data - Data to be copied into device memory
      • CyCLBuffer

        public CyCLBuffer​(CyCLContext context,
                          float[] data)
        Allocates device memory to fit all elements in data, and copies its contents
        Parameters:
        context - The context of the device where the memory should be allocated
        data - Data to be copied into device memory
      • CyCLBuffer

        public CyCLBuffer​(CyCLContext context,
                          double[] data)
        Allocates device memory to fit all elements in data, and copies its contents
        Parameters:
        context - The context of the device where the memory should be allocated
        data - Data to be copied into device memory
    • Method Detail

      • elementSize

        public int elementSize()
        Returns the number of bytes associated with the CyCLBuffer's element type.
        Returns:
        sizeof(type)
      • sizeInBytes

        public int sizeInBytes()
        Returns the overall buffer size in bytes.
        Returns:
        sizeof(type) * elements
      • setFromHost

        public void setFromHost​(byte[] data,
                                int length,
                                int offset)
        Copies data from host to device memory.
        Parameters:
        data - Data to be copied
        length - Number of elements to be copied
        offset - Offset in bytes from the device memory's start
      • setFromHost

        public void setFromHost​(short[] data,
                                int length,
                                int offset)
        Copies data from host to device memory.
        Parameters:
        data - Data to be copied
        length - Number of elements to be copied
        offset - Offset in bytes from the device memory's start
      • setFromHost

        public void setFromHost​(int[] data,
                                int length,
                                int offset)
        Copies data from host to device memory.
        Parameters:
        data - Data to be copied
        length - Number of elements to be copied
        offset - Offset in bytes from the device memory's start
      • setFromHost

        public void setFromHost​(long[] data,
                                int length,
                                int offset)
        Copies data from host to device memory.
        Parameters:
        data - Data to be copied
        length - Number of elements to be copied
        offset - Offset in bytes from the device memory's start
      • setFromHost

        public void setFromHost​(float[] data,
                                int length,
                                int offset)
        Copies data from host to device memory.
        Parameters:
        data - Data to be copied
        length - Number of elements to be copied
        offset - Offset in bytes from the device memory's start
      • setFromHost

        public void setFromHost​(double[] data,
                                int length,
                                int offset)
        Copies data from host to device memory.
        Parameters:
        data - Data to be copied
        length - Number of elements to be copied
        offset - Offset in bytes from the device memory's start
      • setFromHost

        public void setFromHost​(byte[] data)
        Copies data from host to device memory.
        Parameters:
        data - Data to be copied
      • setFromHost

        public void setFromHost​(short[] data)
        Copies data from host to device memory.
        Parameters:
        data - Data to be copied
      • setFromHost

        public void setFromHost​(int[] data)
        Copies data from host to device memory.
        Parameters:
        data - Data to be copied
      • setFromHost

        public void setFromHost​(long[] data)
        Copies data from host to device memory.
        Parameters:
        data - Data to be copied
      • setFromHost

        public void setFromHost​(float[] data)
        Copies data from host to device memory.
        Parameters:
        data - Data to be copied
      • setFromHost

        public void setFromHost​(double[] data)
        Copies data from host to device memory.
        Parameters:
        data - Data to be copied
      • setFromDevice

        public void setFromDevice​(CyCLBuffer src,
                                  long bytes,
                                  long offsetSrc,
                                  long offsetDst)
        Copies data from another device buffer to this one.
        Parameters:
        src - Device buffer with the source data
        bytes - Amount of bytes to be copied
        offsetSrc - Offset in bytes from the start of the source buffer
        offsetDst - Offset in bytes from the start of the destination buffer
      • setFromDevice

        public void setFromDevice​(CyCLBuffer src)
        Copies data from another device buffer to this one.
        Parameters:
        src - Device buffer with the source data
      • getFromDevice

        public void getFromDevice​(byte[] data,
                                  int length,
                                  int offset)
        Copies data from device to host memory.
        Parameters:
        data - Array that the data will be copied to
        length - Number of elements
        offset - Offset in bytes from the start of the device buffer
      • getFromDevice

        public void getFromDevice​(short[] data,
                                  int length,
                                  int offset)
        Copies data from device to host memory.
        Parameters:
        data - Array that the data will be copied to
        length - Number of elements
        offset - Offset in bytes from the start of the device buffer
      • getFromDevice

        public void getFromDevice​(int[] data,
                                  int length,
                                  int offset)
        Copies data from device to host memory.
        Parameters:
        data - Array that the data will be copied to
        length - Number of elements
        offset - Offset in bytes from the start of the device buffer
      • getFromDevice

        public void getFromDevice​(long[] data,
                                  int length,
                                  int offset)
        Copies data from device to host memory.
        Parameters:
        data - Array that the data will be copied to
        length - Number of elements
        offset - Offset in bytes from the start of the device buffer
      • getFromDevice

        public void getFromDevice​(float[] data,
                                  int length,
                                  int offset)
        Copies data from device to host memory.
        Parameters:
        data - Array that the data will be copied to
        length - Number of elements
        offset - Offset in bytes from the start of the device buffer
      • getFromDevice

        public void getFromDevice​(double[] data,
                                  int length,
                                  int offset)
        Copies data from device to host memory.
        Parameters:
        data - Array that the data will be copied to
        length - Number of elements
        offset - Offset in bytes from the start of the device buffer
      • getFromDevice

        public void getFromDevice​(byte[] data)
        Copies data from device to host memory.
        Parameters:
        data - Array that the data will be copied to
      • getFromDevice

        public void getFromDevice​(short[] data)
        Copies data from device to host memory.
        Parameters:
        data - Array that the data will be copied to
      • getFromDevice

        public void getFromDevice​(int[] data)
        Copies data from device to host memory.
        Parameters:
        data - Array that the data will be copied to
      • getFromDevice

        public void getFromDevice​(long[] data)
        Copies data from device to host memory.
        Parameters:
        data - Array that the data will be copied to
      • getFromDevice

        public void getFromDevice​(float[] data)
        Copies data from device to host memory.
        Parameters:
        data - Array that the data will be copied to
      • getFromDevice

        public void getFromDevice​(double[] data)
        Copies data from device to host memory.
        Parameters:
        data - Array that the data will be copied to
      • getMemObject

        public org.lwjgl.opencl.CLMem getMemObject()
        Gets the underlying memory object.
        Returns:
        LWJGL memory object
      • free

        public void free()
        Frees all device memory associated with the buffer. CyCLBuffer cannot be used anymore once this method has been executed.
      • finalize

        protected void finalize()
        Frees all device memory associated with the buffer. CyCLBuffer cannot be used anymore once this method has been executed.
        Overrides:
        finalize in class Object