NetSci
|
Manages CUDA-supported arrays, offering initialization, memory management, and data manipulation. Implemented as a template class in C++, with Python and Tcl wrapper interfaces. In Python and Tcl, use as <ElementType>CuArray (e.g., FloatCuArray, IntCuArray), as they don't support templates. Supports float and int types in Python and Tcl, and all numeric types in C++. More...
#include <cuarray.h>
Public Member Functions | |
CuArray () | |
Constructs an empty CuArray object. | |
CuArrayError | init (int m, int n) |
Initializes CuArray with specified dimensions and allocates memory on host and device. | |
CuArrayError | init (T *host, int m, int n) |
Initializes CuArray with specified host data and dimensions, performing a shallow copy. Allocates memory on both the host and the device. The data is shallow copied, so the ownership remains unchanged. | |
CuArrayError | fromCuArrayShallowCopy (CuArray< T > *cuArray, int start, int end, int m, int n) |
Performs a shallow copy of data from another CuArray within a specified row range. Copies the host data from the given CuArray, within the inclusive range specified by 'start' and 'end'. This CuArray does not own the copied data, and deallocation is handled by the source CuArray. | |
CuArrayError | fromCuArrayDeepCopy (CuArray< T > *cuArray, int start, int end, int m, int n) |
Performs a deep copy of data from another CuArray within a specified row range. Copies the host data from the given CuArray, including all data within the inclusive range defined by 'start' and 'end'. Memory for the copied data is allocated in this CuArray's host memory. | |
~CuArray () | |
Destructor for CuArray. Deallocates memory on both the host and the device. | |
int | n () const |
Returns the number of columns in the CuArray. | |
int | m () const |
Returns the number of rows in the CuArray. | |
int | size () const |
Returns the total number of elements in the CuArray. | |
size_t | bytes () const |
Returns the total size in bytes of the CuArray data. | |
T *& | host () |
Returns a reference to the host data. | |
T *& | device () |
Returns a reference to the device data. | |
CuArrayError | allocateHost () |
Allocates memory for the host data. | |
CuArrayError | allocateDevice () |
Allocates memory for the device data. | |
CuArrayError | allocatedHost () const |
Checks if memory is allocated for the host data. | |
CuArrayError | allocatedDevice () const |
Checks if memory is allocated for the device data. | |
CuArrayError | toDevice () |
Copies data from the host to the device. | |
CuArrayError | toHost () |
Copies data from the device to the host. | |
CuArrayError | deallocateHost () |
Deallocates memory for the host data. | |
CuArrayError | deallocateDevice () |
Deallocates memory for the device data. | |
CuArrayError | fromNumpy (T *NUMPY_ARRAY, int NUMPY_ARRAY_DIM1, int NUMPY_ARRAY_DIM2) |
Copies data from a NumPy array to the CuArray. | |
CuArrayError | fromNumpy (T *NUMPY_ARRAY, int NUMPY_ARRAY_DIM1) |
Copies data from a NumPy array to the CuArray. | |
void | toNumpy (T **NUMPY_ARRAY, int **NUMPY_ARRAY_DIM1, int **NUMPY_ARRAY_DIM2) |
Copies data from the CuArray to a NumPy array. | |
void | toNumpy (T **NUMPY_ARRAY, int **NUMPY_ARRAY_DIM1) |
Copies data from the CuArray to a NumPy array. | |
T | get (int i, int j) const |
Returns the value at a specified position in the CuArray. | |
CuArrayError | set (T value, int i, int j) |
Sets a value at a specified position in the CuArray. | |
CuArrayError | load (const std::string &fname) |
Loads CuArray data from a specified file. | |
void | save (const std::string &fname) |
Saves CuArray data to a specified file. | |
CuArray< T > * | sort (int i) |
Sorts CuArray based on the values in a specified row. | |
T & | operator[] (int i) const |
Returns a reference to the element at a specified index in the CuArray. | |
int | owner () const |
Returns the owner status of the CuArray. Indicates whether the CuArray is responsible for memory deallocation. | |
CuArray< int > * | argsort (int i) |
Performs an argsort on a specified row of the CuArray. Returns a new CuArray containing sorted indices. | |
Private Attributes | |
T * | host_ |
T * | device_ |
int | n_ {} |
int | m_ {} |
int | size_ {} |
size_t | bytes_ {} |
int | allocatedDevice_ {} |
int | allocatedHost_ {} |
int | owner_ {} |
Manages CUDA-supported arrays, offering initialization, memory management, and data manipulation. Implemented as a template class in C++, with Python and Tcl wrapper interfaces. In Python and Tcl, use as <ElementType>CuArray (e.g., FloatCuArray, IntCuArray), as they don't support templates. Supports float and int types in Python and Tcl, and all numeric types in C++.
T | Data type of the array elements. |
Constructs an empty CuArray object.
C++ Example
Python Example
Checks if memory is allocated for the device data.
C++ Example
Allocates memory for the device data.
C++ Example
Checks if memory is allocated for the host data.
C++ Example
Allocates memory for the host data.
C++ Example
Performs an argsort on a specified row of the CuArray. Returns a new CuArray containing sorted indices.
i | Column index to argsort. |
C++ Example
Python Example
Returns the total size in bytes of the CuArray data.
Includes both the host and device memory.
C++ Example
Python Example
Deallocates memory for the device data.
C++ Example
Deallocates memory for the host data.
C++ Example
Returns a reference to the device data.
C++ Example
CuArrayError CuArray< T >::fromCuArrayDeepCopy | ( | CuArray< T > * | cuArray, |
int | start, | ||
int | end, | ||
int | m, | ||
int | n | ||
) |
Performs a deep copy of data from another CuArray within a specified row range. Copies the host data from the given CuArray, including all data within the inclusive range defined by 'start' and 'end'. Memory for the copied data is allocated in this CuArray's host memory.
cuArray | Pointer to the source CuArray. |
start | Index of the first row to copy. |
end | Index of the last row to copy. |
m | Number of rows in this CuArray. |
n | Number of columns in this CuArray. |
C++ Example
Python Example
CuArrayError CuArray< T >::fromCuArrayShallowCopy | ( | CuArray< T > * | cuArray, |
int | start, | ||
int | end, | ||
int | m, | ||
int | n | ||
) |
Performs a shallow copy of data from another CuArray within a specified row range. Copies the host data from the given CuArray, within the inclusive range specified by 'start' and 'end'. This CuArray does not own the copied data, and deallocation is handled by the source CuArray.
cuArray | Pointer to the source CuArray. |
start | Index of the first row to copy. |
end | Index of the last row to copy. |
m | Number of rows in this CuArray. |
n | Number of columns in this CuArray. |
C++ Example
Copies data from a NumPy array to the CuArray.
NUMPY_ARRAY | Pointer to input NumPy array. |
NUMPY_ARRAY_DIM1 | Dimension 1 of the NumPy array. |
C++ Example
Python Example
CuArrayError CuArray< T >::fromNumpy | ( | T * | NUMPY_ARRAY, |
int | NUMPY_ARRAY_DIM1, | ||
int | NUMPY_ARRAY_DIM2 | ||
) |
Copies data from a NumPy array to the CuArray.
NUMPY_ARRAY | Pointer to the input NumPy array. |
NUMPY_ARRAY_DIM1 | Dimension 1 of the NumPy array. |
NUMPY_ARRAY_DIM2 | Dimension 2 of the NumPy array. |
C++ Example
Python Example
Returns the value at a specified position in the CuArray.
i | Row index. |
j | Column index. |
C++ Example
Python Example
Returns a reference to the host data.
C++ Example
Initializes CuArray with specified dimensions and allocates memory on host and device.
m | Number of rows. |
n | Number of columns. |
C++ Example
Python Example
Initializes CuArray with specified host data and dimensions, performing a shallow copy. Allocates memory on both the host and the device. The data is shallow copied, so the ownership remains unchanged.
host | Pointer to input host data. |
m | Number of rows. |
n | Number of columns. |
C++ Example
Loads CuArray data from a specified file.
fname | File name to load from. |
C++ Example
Python Example
Returns the number of rows in the CuArray.
C++ Example
Python Example
Returns the number of columns in the CuArray.
C++ Example
Python Example
Returns a reference to the element at a specified index in the CuArray.
i | Index of the element. |
C++ Example
Python Example
Returns the owner status of the CuArray. Indicates whether the CuArray is responsible for memory deallocation.
C++ Example
Saves CuArray data to a specified file.
fname | File name to save to. |
C++ Example
Python Example
CuArrayError CuArray< T >::set | ( | T | value, |
int | i, | ||
int | j | ||
) |
Sets a value at a specified position in the CuArray.
value | Value to set. |
i | Row index. |
j | Column index. |
C++ Example
Python Example
Returns the total number of elements in the CuArray.
C++ Example
Python Example
Sorts CuArray based on the values in a specified row.
i | Index of the row to sort by. |
C++ Example
Python Example
Copies data from the host to the device.
C++ Example
Copies data from the device to the host.
C++ Example
Copies data from the CuArray to a NumPy array.
NUMPY_ARRAY | Pointer to output NumPy array. |
NUMPY_ARRAY_DIM1 | Dimension 1 of the NumPy array. |
C++ Example
Python Example
Copies data from the CuArray to a NumPy array.
NUMPY_ARRAY | Pointer to output NumPy array. |
NUMPY_ARRAY_DIM1 | Dimension 1 of the NumPy array. |
NUMPY_ARRAY_DIM2 | Dimension 2 of the NumPy array. |
C++ Example
Python Example