Array Class
The Array class is the primary data structure class of the library.
It stores the pointer to the memory space in the Device, along with the necessary information to access and manipulate it.
The class is intended to be used through smart pointers defined as Array::Pointer and should not be accessed directly.
Hence, the creation of an Array object is done through Array::create() function.
The class provides a set of methods that describe the array, such as its size, width, dtype, among others.
It also provides methods to write/read data to and from the host, and to perform operations on the array, such as fill and copy.
This object is the main input and output of the library functions.
-
class Array
Array class.
This is the main data structure of the library. It is used to store data on the device and to perform operations on it. The Array class is holding a device memory pointer (void *), its size and its type. An Array is not manipulated directly, but through a smart pointer (Array::Pointer).
Public Functions
-
void allocate()
Print the Array as a matrix for debugging.
Allocate memory space of the array on the device
-
void writeFrom(const void *host_data)
Write host data into the Array.
- Parameters:
host_data – pointer to the host data
-
void writeFrom(const void *host_data, const std::array<size_t, 3> ®ion, const std::array<size_t, 3> &buffer_origin)
Write host data into the Array region.
- Parameters:
host_data – pointer to the host data
region – region of the array to write
buffer_origin – origin of the buffer to write
-
void writeFrom(const void *host_data, size_t x_coord, size_t y_coord, size_t z_coord)
Write host data into the Array at a specific position (x, y, z)
- Parameters:
host_data – pointer to the host data
x_coord – x coordinate
y_coord – y coordinate
z_coord – z coordinate
-
void readTo(void *host_data) const
Read the Array data into host memory.
- Parameters:
host_data – pointer to the host data
-
void readTo(void *host_data, const std::array<size_t, 3> ®ion, const std::array<size_t, 3> &buffer_origin) const
Read the Array region data into host memory.
- Parameters:
host_data – pointer to the host data
region – region of the array to read
buffer_origin – origin of the buffer to read
-
void readTo(void *host_data, size_t x_coord, size_t y_coord, size_t z_coord) const
Read the Array data at a specific position (x, y, z) into host memory.
- Parameters:
host_data – pointer to the host data
x_coord – x coordinate
y_coord – y coordinate
z_coord – z coordinate
-
void copyTo(const Array::Pointer &dst) const
Copy the Array data into another Array.
- Parameters:
dst – destination Array::Pointer
-
void copyTo(const Array::Pointer &dst, const std::array<size_t, 3> ®ion, const std::array<size_t, 3> &src_origin, const std::array<size_t, 3> &dst_origin) const
Copy the Array region data into another Array.
- Parameters:
dst – destination Array::Pointer
region – region of the array to copy
src_origin – origin of the source buffer
dst_origin – origin of the destination buffer
-
void fill(float value)
Fill the Array with a specific value.
- Parameters:
value – value to fill the array with
-
size_t bitsize() const
Get the total bitsize of the Array (number of elements * size of the data type)
- Returns:
size_t
-
Device::Pointer device() const
Get the device pointer where the Array is stored.
- Returns:
Device::Pointer
-
~Array()
destructor
Public Static Functions
-
static Array::Pointer create(size_t width, size_t height, size_t depth, size_t dimension, const dType &data_type, const mType &mem_type, const Device::Pointer &device_ptr)
Create an empty new Array::Pointer object.
- Parameters:
width – width of the array
height – height of the array
depth – depth of the array
dimension – dimension of the array (1, 2 or 3)
data_type – data type of the array
mem_type – memory type of the array
device_ptr – device where the array is stored
- Returns:
Array::Pointer
-
static Array::Pointer create(size_t width, size_t height, size_t depth, size_t dimension, const dType &data_type, const mType &mem_type, const void *host_data, const Device::Pointer &device_ptr)
Create a new Array::Pointer object from host data pointer.
- Parameters:
width – width of the array
height – height of the array
depth – depth of the array
dimension – dimension of the array (1, 2 or 3)
data_type – data type of the array
mem_type – memory type of the array
host_data – pointer to the host data
device_ptr – device where the array is stored
- Returns:
Array::Pointer
-
void allocate()