RAII class for a CUDA memory buffer.
#include <DeviceMemory.h>
Name | |
---|---|
DeviceMemory() =default Default constructor, creates an empty object, without allocating any memory on the device. | |
DeviceMemory(size_t numberOfBytes) Constructor allocating the required number of bytes. | |
DeviceMemory(void * deviceMemory) Constructor taking ownership of an already allocated CUDA memory pointer. This class will free the pointer once it goes out of scope. | |
bool | allocateMemory(size_t numberOfBytes) Allocates device memory. The memory allocated will automatically be freed by the destructor. |
bool | reallocateMemory(size_t numberOfBytes) Reallocates device memory. Already existing memory allocation will be freed before the new allocation is made. In case this DeviceMemory has no earlier memory allocation, this method will just allocate new CUDA memory and return a success status. |
bool | allocateAndResetMemory(size_t numberOfBytes) Allocates device memory and resets all bytes to zeroes. The memory allocated will automatically be freed by the destructor. |
bool | freeMemory() Free the device memory held by this class. Calling this when no memory is allocated is a no-op. |
~DeviceMemory() Destructor, frees the internal CUDA memory. | |
template T * | getDevicePointer() const |
size_t | getSize() const |
DeviceMemory(DeviceMemory && other) | |
DeviceMemory & | operator=(DeviceMemory && other) |
void | swap(DeviceMemory & other) |
DeviceMemory(DeviceMemory const & ) =delete DeviceMemory is not copyable. | |
DeviceMemory | operator=(DeviceMemory const & ) =delete |
DeviceMemory() =default
Default constructor, creates an empty object, without allocating any memory on the device.
explicit DeviceMemory(
size_t numberOfBytes
)
Constructor allocating the required number of bytes.
Parameters:
explicit DeviceMemory(
void * deviceMemory
)
Constructor taking ownership of an already allocated CUDA memory pointer. This class will free the pointer once it goes out of scope.
Parameters:
bool allocateMemory(
size_t numberOfBytes
)
Allocates device memory. The memory allocated will automatically be freed by the destructor.
Parameters:
Return: True on success, false if there is already memory allocated by this instance, or if the CUDA malloc failed.
bool reallocateMemory(
size_t numberOfBytes
)
Reallocates device memory. Already existing memory allocation will be freed before the new allocation is made. In case this DeviceMemory has no earlier memory allocation, this method will just allocate new CUDA memory and return a success status.
Parameters:
Return: True on success, false if CUDA free or CUDA malloc failed.
bool allocateAndResetMemory(
size_t numberOfBytes
)
Allocates device memory and resets all bytes to zeroes. The memory allocated will automatically be freed by the destructor.
Parameters:
Return: True on success, false if there is already memory allocated by this instance, or if any of the CUDA operations failed.
bool freeMemory()
Free the device memory held by this class. Calling this when no memory is allocated is a no-op.
Return: True in case the memory was successfully freed (or not allocated to begin with), false otherwise.
~DeviceMemory()
Destructor, frees the internal CUDA memory.
template <typename T =uint8_t>
inline T * getDevicePointer() const
Template Parameters:
Return: the CUDA memory pointer handled by this class. Nullptr in case no memory is allocated.
size_t getSize() const
Return: The size of the CUDA memory allocation held by this class.
DeviceMemory(
DeviceMemory && other
)
DeviceMemory & operator=(
DeviceMemory && other
)
void swap(
DeviceMemory & other
)
DeviceMemory(
DeviceMemory const &
) =delete
DeviceMemory is not copyable.
DeviceMemory operator=(
DeviceMemory const &
) =delete
Updated on 2023-06-13 at 17:00:17 +0200