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

auto allocate() -> void

Allocate memory space of the array on the device.

auto writeFrom(const void *host_data) -> void

Write host data into the Array.

Parameters:

host_data – pointer to the host data

auto writeFrom(const void *host_data, const std::array<size_t, 3> &region, const std::array<size_t, 3> &buffer_origin) -> void

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

auto writeFrom(const void *host_data, size_t x_coord, size_t y_coord, size_t z_coord) -> void

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

auto readTo(void *host_data) const -> void

Read the Array data into host memory.

Parameters:

host_data – pointer to the host data

auto readTo(void *host_data, const std::array<size_t, 3> &region, const std::array<size_t, 3> &buffer_origin) const -> void

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

auto readTo(void *host_data, size_t x_coord, size_t y_coord, size_t z_coord) const -> void

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

auto copyTo(const Array::Pointer &dst) const -> void

Copy the Array data into another Array.

Parameters:

dst – destination Array::Pointer

auto 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 -> void

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

auto fill(float value) -> void

Fill the Array with a specific value.

Parameters:

value – value to fill the array with

auto size() const -> size_t

Get the size of the Array (number of elements)

Returns:

size_t

auto width() const -> size_t

Get the width of the Array.

Returns:

size_t

auto height() const -> size_t

Get the height of the Array.

Returns:

size_t

auto depth() const -> size_t

Get the depth of the Array.

Returns:

size_t

auto itemSize() const -> size_t

Get the item size of the Array (bytes)

Returns:

size_t

auto dtype() const -> dType

Get the data type of the Array.

Returns:

dType

auto mtype() const -> mType

Get the memory type of the Array.

Returns:

mType

auto device() const -> Device::Pointer

Get the device pointer where the Array is stored.

Returns:

Device::Pointer

auto dim() const -> unsigned int

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

Returns:

unsigned int

auto dimension() const -> unsigned int

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

Returns:

unsigned int

auto initialized() const -> bool

Check if the Array is initialized.

Returns:

bool

auto get() const -> void**

Get the memory pointer of the Array.

Returns:

void **

auto c_get() const -> const void**

Get the const memory pointer of the Array.

Returns:

const void **

~Array()

destructor

Array(const Array&) = default

copy constructor

Public Static Functions

static inline auto New() -> Array::Pointer

Create a new Array::Pointer object.

static auto 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) -> Array::Pointer

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 auto 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) -> Array::Pointer

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 auto create(const Array::Pointer &array) -> Array::Pointer

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 auto operator<<(std::ostream &out, const Array::Pointer &array) -> std::ostream&

operator << to print the Array::Pointer

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

Print the Array as a matrix for debugging.