Class for managing memory on the CUDA Device.
More...
#include <DeviceMemoryManager.hpp>
|
template<typename Pointee > |
static Pointee * | allocateMemoryUnregistered (const unsigned int instanceCount) |
| Allocates Device memory for the given number of instances of the supplied type. More...
|
|
template<typename Pointee > |
static void | allocateMemoryUnregistered (Pointee **pointerToPointer, const unsigned int instanceCount) |
| Allocates Device memory for the given number of instances of the supplied type. More...
|
|
static void | freeMemoryUnregistered (void *const pointer) |
| Frees the Device memory pointed to by the given pointer. More...
|
|
static bool | isDeviceMemoryPointer (const void *const ptr) |
| Returns whether the given pointer is a pointer to CUDA Device memory. More...
|
|
static bool | isHostMemoryPointer (const void *const ptr) |
| Returns whether the given pointer is a pointer to Host memory. More...
|
|
template<typename T > |
static void | copyElementsFromHostToDevice (const T *const src, T *const dest, const std::size_t count) |
| Copies count elements of type T from the Host to the Device. More...
|
|
template<typename T > |
static void | copyElementsFromDeviceToHost (const T *const src, T *const dest, const std::size_t count) |
| Copies count elements of type T from the Device to the Host. More...
|
|
template<typename T > |
static void | copyElementsFromDeviceToDevice (const T *const src, T *const dest, const std::size_t count) |
| Copies count elements of type T from the Device to the Device. More...
|
|
template<typename T > |
static void | zeroMemory (T *const start, const std::size_t numberOfElements) |
| Writes zero-bytes to the given Device memory region. More...
|
|
template<typename T > |
static bool | elementMemoryEqualOnHostAndDevice (const T *const host, const T *const device, const std::size_t count) |
| Returns whether the count elements of type T at host in Host memory have the same byte-wise representation as the count elements at device on the CUDA Device. More...
|
|
Class for managing memory on the CUDA Device.
Definition at line 21 of file DeviceMemoryManager.hpp.
◆ DeviceMemoryManager()
DeviceMemoryManager::DeviceMemoryManager |
( |
| ) |
|
◆ ~DeviceMemoryManager()
DeviceMemoryManager::~DeviceMemoryManager |
( |
| ) |
|
The destructor.
If there are Device buffers which have not been freed, and the autofree flag has not been set, prints corresponding warning messages to stderr
.
Definition at line 17 of file DeviceMemoryManager.cpp.
◆ allocateMemory() [1/2]
template<typename Pointee >
Pointee* OpenMPCD::CUDA::DeviceMemoryManager::allocateMemory |
( |
const unsigned int |
instanceCount | ) |
|
|
inline |
Allocates Device memory for the given number of instances of the supplied type.
The returned pointer points to at least instanceCount * sizeof(Pointee) bytes of allocated Device memory.
Memory allocated through this function is registered with this instance. Unless the memory is freed via a call to this instance's freeMemory
, or the autofree flag is set via setAutofree
, this instance will, during destruction, print error messages about every unfreed allocation in the destructor.
- Exceptions
-
- Template Parameters
-
- Parameters
-
[in] | instanceCount | The number of instances the returned buffer should fit at a minimum. If 0 , nullptr is returned. |
Definition at line 62 of file DeviceMemoryManager.hpp.
◆ allocateMemory() [2/2]
template<typename Pointee >
void OpenMPCD::CUDA::DeviceMemoryManager::allocateMemory |
( |
Pointee ** |
pointerToPointer, |
|
|
const unsigned int |
instanceCount |
|
) |
| |
|
inline |
Allocates Device memory for the given number of instances of the supplied type.
After a successful call, the given pointer points to at least instanceCount * sizeof(Pointee) bytes of allocated Device memory.
Memory allocated through this function is registered with this instance. Unless the memory is freed via a call to this instance's freeMemory
, or the autofree flag is set via setAutofree
, this instance will, during destruction, print error messages about every unfreed allocation in the destructor.
- Exceptions
-
- Template Parameters
-
- Parameters
-
[out] | pointerToPointer | A valid pointer to the pointer that is to be set. Will be set to nullptr if instanceCount == 0 . |
[in] | instanceCount | The number of instances the returned buffer should fit at a minimum. |
Definition at line 91 of file DeviceMemoryManager.hpp.
◆ allocateMemoryUnregistered() [1/2]
template<typename Pointee >
static Pointee* OpenMPCD::CUDA::DeviceMemoryManager::allocateMemoryUnregistered |
( |
const unsigned int |
instanceCount | ) |
|
|
inlinestatic |
Allocates Device memory for the given number of instances of the supplied type.
The returned pointer points to at least instanceCount * sizeof(Pointee)
bytes of allocated Device memory.
Memory allocated through this function is not registered with this instance, in contrast to allocateMemory
.
- Exceptions
-
- Template Parameters
-
- Parameters
-
[in] | instanceCount | The number of instances the returned buffer should fit at a minimum. If 0 , nullptr is returned. |
Definition at line 121 of file DeviceMemoryManager.hpp.
◆ allocateMemoryUnregistered() [2/2]
template<typename Pointee >
static void OpenMPCD::CUDA::DeviceMemoryManager::allocateMemoryUnregistered |
( |
Pointee ** |
pointerToPointer, |
|
|
const unsigned int |
instanceCount |
|
) |
| |
|
inlinestatic |
Allocates Device memory for the given number of instances of the supplied type.
After a successful call, the given pointer points to at least instanceCount * sizeof(Pointee)
bytes of allocated Device memory.
Memory allocated through this function is not registered with this instance, in contrast to allocateMemory
.
- Exceptions
-
- Template Parameters
-
- Parameters
-
[out] | pointerToPointer | A valid pointer to the pointer that is to be set. Will be set to nullptr if instanceCount == 0 . |
[in] | instanceCount | The number of instances the returned buffer should fit at a minimum. |
Definition at line 154 of file DeviceMemoryManager.hpp.
◆ copyElementsFromDeviceToDevice()
template<typename T >
void OpenMPCD::CUDA::DeviceMemoryManager::copyElementsFromDeviceToDevice |
( |
const T *const |
src, |
|
|
T *const |
dest, |
|
|
const std::size_t |
count |
|
) |
| |
|
static |
Copies count
elements of type T
from the Device to the Device.
- Exceptions
-
- Template Parameters
-
T | The type of elements to copy. |
- Parameters
-
[in] | src | The source to copy from. |
[out] | dest | The destination to copy to. |
[in] | count | The number of elements of type T to copy. |
Definition at line 66 of file ImplementationDetails/DeviceMemoryManager.hpp.
◆ copyElementsFromDeviceToHost()
template<typename T >
void OpenMPCD::CUDA::DeviceMemoryManager::copyElementsFromDeviceToHost |
( |
const T *const |
src, |
|
|
T *const |
dest, |
|
|
const std::size_t |
count |
|
) |
| |
|
static |
Copies count
elements of type T
from the Device to the Host.
- Exceptions
-
- Template Parameters
-
T | The type of elements to copy. |
- Parameters
-
[in] | src | The source to copy from. |
[out] | dest | The destination to copy to. |
[in] | count | The number of elements of type T to copy. |
Definition at line 44 of file ImplementationDetails/DeviceMemoryManager.hpp.
◆ copyElementsFromHostToDevice()
template<typename T >
void OpenMPCD::CUDA::DeviceMemoryManager::copyElementsFromHostToDevice |
( |
const T *const |
src, |
|
|
T *const |
dest, |
|
|
const std::size_t |
count |
|
) |
| |
|
static |
Copies count
elements of type T
from the Host to the Device.
- Exceptions
-
- Template Parameters
-
T | The type of elements to copy. |
- Parameters
-
[in] | src | The source to copy from. |
[out] | dest | The destination to copy to. |
[in] | count | The number of elements of type T to copy. |
Definition at line 22 of file ImplementationDetails/DeviceMemoryManager.hpp.
◆ elementMemoryEqualOnHostAndDevice()
template<typename T >
bool OpenMPCD::CUDA::DeviceMemoryManager::elementMemoryEqualOnHostAndDevice |
( |
const T *const |
host, |
|
|
const T *const |
device, |
|
|
const std::size_t |
count |
|
) |
| |
|
static |
Returns whether the count
elements of type T
at host
in Host memory have the same byte-wise representation as the count
elements at device
on the CUDA Device.
- Exceptions
-
- Template Parameters
-
T | The type of elements to copy. |
- Parameters
-
[in] | host | Pointer to the data on the Host. |
[out] | device | Pointer to the data on the CUDA Device. |
[in] | count | The number of elements of type T to compare, which must not be 0 . |
Definition at line 104 of file ImplementationDetails/DeviceMemoryManager.hpp.
◆ freeMemory()
void DeviceMemoryManager::freeMemory |
( |
void *const |
pointer | ) |
|
Frees the Device memory pointed to by the given pointer.
- Exceptions
-
OpenMPCD::MemoryManagementException | Throws if the given non-nullptr pointer has not been allocated through and registered with this instance, i.e. if the given pointer has not been created via a call to allocateMemory . |
- Parameters
-
[in] | pointer | The pointer to free. If it is nullptr , nothing happens. |
Definition at line 40 of file DeviceMemoryManager.cpp.
◆ freeMemoryUnregistered()
void DeviceMemoryManager::freeMemoryUnregistered |
( |
void *const |
pointer | ) |
|
|
static |
Frees the Device memory pointed to by the given pointer.
Note that one should not use this function with pointers allocated in a way that the pointer is registered with an instance of this class, e.g. via allocateMemory
, since otherwise, that memory is either going to be freed twice, or a (spurious) warning about unfreed memory may be produced.
- Exceptions
-
- Parameters
-
[in] | pointer | The pointer to free. If it is nullptr , nothing happens. |
Definition at line 53 of file DeviceMemoryManager.cpp.
◆ isDeviceMemoryPointer()
bool DeviceMemoryManager::isDeviceMemoryPointer |
( |
const void *const |
ptr | ) |
|
|
static |
Returns whether the given pointer is a pointer to CUDA Device memory.
Returns false
if ptr == nullptr
.
- Exceptions
-
- Parameters
-
[in] | ptr | The pointer to check. |
Definition at line 81 of file DeviceMemoryManager.cpp.
◆ isHostMemoryPointer()
bool DeviceMemoryManager::isHostMemoryPointer |
( |
const void *const |
ptr | ) |
|
|
static |
Returns whether the given pointer is a pointer to Host memory.
If this function returns true, it does necessarily not mean that it is permissible to dereference the pointer.
Returns false
if ptr == nullptr
.
- Exceptions
-
- Parameters
-
[in] | ptr | The pointer to check. |
Definition at line 105 of file DeviceMemoryManager.cpp.
◆ setAutofree()
void OpenMPCD::CUDA::DeviceMemoryManager::setAutofree |
( |
const bool |
enable | ) |
|
|
inline |
Sets, or unsets, the autofree flag.
If the autofree flag is set, all reserved device memory is freed upon destruction of this instance, without raising warnings or errors.
- Parameters
-
[in] | enable | Whether to enable the autofree feature. |
Definition at line 207 of file DeviceMemoryManager.hpp.
◆ zeroMemory()
template<typename T >
void OpenMPCD::CUDA::DeviceMemoryManager::zeroMemory |
( |
T *const |
start, |
|
|
const std::size_t |
numberOfElements |
|
) |
| |
|
static |
Writes zero-bytes to the given Device memory region.
- Exceptions
-
- Template Parameters
-
T | The type of elements pointed to by start . |
- Parameters
-
[in] | start | The first element to write zero-bytes to. |
[in] | numberOfElements | The number of elements of type T to write zero-bytes to. |
Definition at line 88 of file ImplementationDetails/DeviceMemoryManager.hpp.
The documentation for this class was generated from the following files: