Doxygen
1.9.1
|
Template class that wraps around a single GPU array, providing functionality that mimics std::vector. More...
#include <tsgAcceleratedDataStructures.hpp>
Public Types | |
using | value_type = T |
The data-type of the vector entries. | |
Public Member Functions | |
GpuVector (GpuVector< T > const &)=delete | |
Delete the copy-constructor. | |
GpuVector< T > & | operator= (GpuVector< T > const &)=delete |
Delete the copy-assignment. | |
GpuVector (GpuVector< T > &&other) | |
Allow for move-construction. | |
GpuVector< T > & | operator= (GpuVector< T > &&other) |
Allow for move-assignment. | |
GpuVector () | |
Default constructor, creates an empty (null) array. | |
GpuVector (AccelerationContext const *acc, size_t count) | |
Construct a vector with count number of entries. | |
GpuVector (AccelerationContext const *acc, int dim1, int dim2) | |
Same as GpuVector(dim1 * dim2), but guards against overflow. More... | |
GpuVector (AccelerationContext const *acc, const std::vector< T > &cpu_data) | |
Create a vector with size that matches cpu_data and copy the data to the GPU device. | |
GpuVector (AccelerationContext const *acc, int dim1, int dim2, T const *cpu_data) | |
Construct a vector and load with date provided on to the cpu. | |
template<typename IteratorLike > | |
GpuVector (AccelerationContext const *acc, IteratorLike ibegin, IteratorLike iend) | |
Construct a vector by loading from a given range. | |
~GpuVector () | |
Destructor, release all allocated memory. | |
size_t | size () const |
Return the current size of the GPU array. | |
T * | data () |
Get a reference to the GPU array, which an be used as input to GPU libraries and kernels. | |
const T * | data () const |
Get a const-reference to the GPU array, which an be used as input to GPU libraries and kernels. | |
void | resize (AccelerationContext const *acc, size_t count) |
Clear all data currently stored in the vector and allocate a new array (unlike std::vector this does not relocate the old data). | |
void | clear () |
Delete all allocated memory and reset the array to empty. | |
bool | empty () const |
Return true if the size() is zero. | |
void | load (AccelerationContext const *acc, const std::vector< T > &cpu_data) |
Copy the content of cpu_data to the GPU device, all pre-existing data is deleted and the vector is resized to match cpu_data. | |
template<typename IteratorLike > | |
void | load (AccelerationContext const *acc, IteratorLike ibegin, IteratorLike iend) |
Load from a range defined by the begin and end, converts if necessary. | |
template<typename U > | |
Utils::use_if<!std::is_same< U, T >::value > | load (AccelerationContext const *acc, const std::vector< U > &cpu_data) |
Takes a vector with entries of different precision, converts and loads. More... | |
void | load (AccelerationContext const *acc, size_t count, const T *cpu_data) |
Copy the first count entries of cpu_data to the GPU device. More... | |
template<typename U > | |
Utils::use_if<!std::is_same< U, T >::value > | load (AccelerationContext const *acc, size_t count, const U *cpu_data) |
Takes a vector with entries of different precision, converts and loads. More... | |
void | unload (AccelerationContext const *acc, std::vector< T > &cpu_data) const |
Copy the data from the GPU array to cpu_data, the cpu_data will be resized and overwritten. | |
std::vector< T > | unload (AccelerationContext const *acc) const |
Return a CPU vector holding the data of the GPU. | |
void | unload (AccelerationContext const *acc, size_t num, T *cpu_data) const |
Copy the first num entries to the cpu_data buffer, assumes that the buffer is sufficiently large. | |
void | unload (AccelerationContext const *acc, T *cpu_data) const |
Copy the data from the GPU array to the cpu_data buffer, assumes that the buffer is sufficiently large. | |
T * | eject () |
Move the data to the external array, the vector is set to empty (unlike move command on std::vector). | |
Template class that wraps around a single GPU array, providing functionality that mimics std::vector.
Note that the class does not provide a single entry access and it is not copyable, only movable in assignment and constructor.
|
inline |
Same as GpuVector(dim1 * dim2), but guards against overflow.
Many of the Tasmanian data-structures are inherently two-dimensional, for example, passing number of points and number of dimensions separately makes the code more readable, and both integers are converted to size_t before multiplication which prevents overflow. Note: the dimensions will not be stored, the underlying data is still one dimensional.
|
inline |
Takes a vector with entries of different precision, converts and loads.
Used when the CPU vectors are stored in double-precision format while the GPU entries are prepared to work with single-precision.
void TasGrid::GpuVector< T >::load | ( | AccelerationContext const * | acc, |
size_t | count, | ||
const T * | cpu_data | ||
) |
Copy the first count entries of cpu_data to the GPU device.
If count does not match the current size, the current array will be deleted and new array will be allocated (even if size() exceeds count). The final vector size will match count. However, if count matches size(), the data is overwritten but no arrays will be allocated, deleted, or de-aliased.
|
inline |
Takes a vector with entries of different precision, converts and loads.
Used when the CPU data is stored in double-precision format while the GPU entries are prepared to work with single-precision.