A templatized class to encapsulate a device global memory pointer in a std::vector like interface complete with most of the usual methods. This class is intended to be used only in host code and does not work device side; Passing the pointer to a kernel can be done with the data() method. This class works for any device side pointer, scalar or array valued.
More...
#include <DeviceVector.h>
|
| | DeviceVector () noexcept |
| |
| | DeviceVector (size_t const size, bool const initialize=false) |
| | Construct a new Device Vector object by calling the _allocate private method.
|
| |
| | DeviceVector (DeviceVector< T > &&other) noexcept |
| |
| DeviceVector & | operator= (DeviceVector< T > &&other) noexcept |
| |
|
| ~DeviceVector () |
| | Destroy the Device Vector object by calling the _deAllocate private method.
|
| |
|
| DeviceVector (const DeviceVector< T > &)=delete |
| |
|
DeviceVector< T > & | operator= (const DeviceVector< T > &other)=delete |
| |
| T * | data () |
| | Get the raw device pointer.
|
| |
| size_t | size () |
| | Get the number of elements in the array.
|
| |
| T | operator[] (size_t const &index) |
| | Overload the [] operator to return a value from device memory. This method performs a cudaMemcpy to copy the desired element to the host then returns it. Unlike the at() method this method does not perform bounds checking.
|
| |
| T | at (size_t const index) |
| | Return a value from device memory. This method performs a cudaMemcpy to copy the desired element to the host then returns it. Unlike the [] overload this method perform bounds checking.
|
| |
| void | assign (T const &hostValue, size_t const &index=0) |
| | Assign a single value in the array. Should generally only be used when the pointer points to a scalar value. By default this writes hostValue to the 0th element of the array.
|
| |
| void | resize (size_t const newSize) |
| | Resize the device container to contain newSize elements. If newSize is greater than the current size then all the values are kept and the rest of the array is default initialized. If newSize is smaller than the current size then the array is truncated and values at locations greater than newSize are lost. Keeping the values in the array requires that the new array be allocated, the values be copied, then the old array be freed; as such this method is quite slow and can use a large amount of memory. If you don't care about the values in the array then use the reset method.
|
| |
| void | reset (size_t const newSize) |
| | Reset the size of the array. This frees the old array and allocates a new one; all values in the array may be lost. The values in memory are not initialized and therefore the behaviour of the default values is undefined.
|
| |
| void | cpyHostToDevice (const T *arrIn, size_t const &arrSize) |
| | Copy the first arrSize elements of arrIn to the device.
|
| |
| void | cpyHostToDevice (std::vector< T > const &vecIn) |
| | Copy the contents of a std::vector to the device.
|
| |
| void | cpyDeviceToHost (T *arrOut, size_t const &arrSize) |
| | Copy the array from the device to a host array. Checks if the host array is large enough based on the arrSize parameter.
|
| |
| void | cpyDeviceToHost (std::vector< T > &vecOut) |
| | Copy the array from the device to a host std::vector. Checks if the host array is large enough.
|
| |
template<typename T>
class cuda_utilities::DeviceVector< T >
A templatized class to encapsulate a device global memory pointer in a std::vector like interface complete with most of the usual methods. This class is intended to be used only in host code and does not work device side; Passing the pointer to a kernel can be done with the data() method. This class works for any device side pointer, scalar or array valued.
- Template Parameters
-
| T | Any trivially copyable type where sizeof(T) returns correct results should work, but non-primitive types have not been tested. |
◆ DeviceVector() [1/3]
◆ DeviceVector() [2/3]
Construct a new Device Vector object by calling the _allocate private method.
- Parameters
-
| [in] | size | The number of elements desired in the array. Can be any positive integer. |
| [in] | initialize | (optional) If true then initialize the GPU memory to int(0) |
◆ DeviceVector() [3/3]
Define a move constructor
◆ assign()
Assign a single value in the array. Should generally only be used when the pointer points to a scalar value. By default this writes hostValue to the 0th element of the array.
- Parameters
-
| [in] | hostValue | The value to write to the device array |
| [in] | index | The location to write the value to, defaults to zero. |
◆ at()
Return a value from device memory. This method performs a cudaMemcpy to copy the desired element to the host then returns it. Unlike the [] overload this method perform bounds checking.
- Parameters
-
| [in] | index | The index of the desired value |
- Returns
- T The value at dev_ptr[index]
◆ cpyDeviceToHost() [1/2]
Copy the array from the device to a host std::vector. Checks if the host array is large enough.
- Parameters
-
| [out] | vecOut | The std::vector to copy the device array into |
◆ cpyDeviceToHost() [2/2]
Copy the array from the device to a host array. Checks if the host array is large enough based on the arrSize parameter.
- Parameters
-
| [out] | arrOut | The pointer to the host array |
| [in] | arrSize | The number of elements allocated in the host array |
◆ cpyHostToDevice() [1/2]
Copy the first arrSize elements of arrIn to the device.
- Parameters
-
| [in] | arrIn | The pointer to the array to be copied to the device |
| [in] | arrSize | The number of elements/size of the array to copy to the device |
◆ cpyHostToDevice() [2/2]
Copy the contents of a std::vector to the device.
- Parameters
-
| [in] | vecIn | The array whose contents are to be copied |
◆ data()
Get the raw device pointer.
- Returns
- T* The pointer for the array in global memory
◆ operator=()
◆ operator[]()
Overload the [] operator to return a value from device memory. This method performs a cudaMemcpy to copy the desired element to the host then returns it. Unlike the at() method this method does not perform bounds checking.
- Parameters
-
| [in] | index | The index of the desired value |
- Returns
- T The value at dev_ptr[index]
◆ reset()
Reset the size of the array. This frees the old array and allocates a new one; all values in the array may be lost. The values in memory are not initialized and therefore the behaviour of the default values is undefined.
- Parameters
-
◆ resize()
Resize the device container to contain newSize elements. If newSize is greater than the current size then all the values are kept and the rest of the array is default initialized. If newSize is smaller than the current size then the array is truncated and values at locations greater than newSize are lost. Keeping the values in the array requires that the new array be allocated, the values be copied, then the old array be freed; as such this method is quite slow and can use a large amount of memory. If you don't care about the values in the array then use the reset method.
- Parameters
-
| [in] | newSize | The desired size of the array |
◆ size()
Get the number of elements in the array.
- Returns
- size_t The number of elements in the array
The documentation for this class was generated from the following file: