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> &region, 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> &region, 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> &region, 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 size() const

Get the size of the Array (number of elements)

Returns:

size_t

size_t bitsize() const

Get the total bitsize of the Array (number of elements * size of the data type)

Returns:

size_t

size_t width() const

Get the width of the Array.

Returns:

size_t

size_t height() const

Get the height of the Array.

Returns:

size_t

size_t depth() const

Get the depth of the Array.

Returns:

size_t

size_t itemSize() const

Get the item size of the Array (bytes)

Returns:

size_t

dType dtype() const

Get the data type of the Array.

Returns:

dType

mType mtype() const

Get the memory type of the Array.

Returns:

mType

Device::Pointer device() const

Get the device pointer where the Array is stored.

Returns:

Device::Pointer

unsigned int dim() const

Get the dimension of the Array (1, 2 or 3)

Returns:

unsigned int

unsigned int dimension() const

Get the dimension of the Array (1, 2 or 3)

Returns:

unsigned int

bool initialized() const

Check if the Array is initialized.

Returns:

bool

void **get() const

Get the memory pointer of the Array.

Returns:

void **

const void **c_get() const

Get the const memory pointer of the Array.

Returns:

const void **

~Array()

destructor

Array(const Array&) = default

copy constructor

Public Static Functions

static inline Array::Pointer New()

Create a new Array::Pointer object.

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

static Array::Pointer create(const Array::Pointer &array)

Create a new Array::Pointer object from another Array::Pointer.

Parameters:

array – Array::Pointer

Returns:

Array::Pointer

static inline void check_ptr(const Array::Pointer &ptr, const char *errorMessage)

Check if the shared_ptr is null and throw an exception if it is.

Parameters:
  • ptr – The shared_ptr to check

  • errorMessage – The error message to throw

Friends

friend std::ostream &operator<<(std::ostream &out, const Array::Pointer &array)

operator << to print the Array::Pointer

template<typename T>
friend void print(const Array::Pointer &array)

Print the Array as a matrix for debugging.