OpenMPCD
ImplementationDetails/DeviceBuffer.hpp
Go to the documentation of this file.
1 /**
2  * @file
3  * Implements functionality of the `OpenMPCD::CUDA::DeviceBuffer` class.
4  */
5 
6 #ifndef OPENMPCD_CUDA_IMPLEMENTATIONDETAILS_DEVICEBUFFER_HPP
7 #define OPENMPCD_CUDA_IMPLEMENTATIONDETAILS_DEVICEBUFFER_HPP
8 
10 #include <OpenMPCD/Exceptions.hpp>
12 
13 namespace OpenMPCD
14 {
15 namespace CUDA
16 {
17 
18 template<typename T>
19 DeviceBuffer<T>::DeviceBuffer(const std::size_t elementCount_)
20  : elementCount(elementCount_)
21 {
23  elementCount != 0,
25 
26  DeviceMemoryManager::allocateMemoryUnregistered(
27  &pointer, sizeof(T) * elementCount);
28 }
29 
30 template<typename T>
32 {
33  DeviceMemoryManager::freeMemoryUnregistered(pointer);
34 }
35 
36 template<typename T>
38 {
39  return pointer;
40 }
41 
42 template<typename T>
43 const T* DeviceBuffer<T>::getPointer() const
44 {
45  return pointer;
46 }
47 
48 template<typename T>
50 {
51  return elementCount;
52 }
53 
54 template<typename T>
55 void DeviceBuffer<T>::copyFromDevice(const T* const src)
56 {
58 
59  DeviceMemoryManager::copyElementsFromDeviceToDevice(
60  src, pointer, getElementCount());
61 }
62 
63 template<typename T>
65 {
66  DeviceMemoryManager::zeroMemory(getPointer(), getElementCount());
67 }
68 
69 } //namespace CUDA
70 } //namespace OpenMPCD
71 
72 
73 #endif //OPENMPCD_CUDA_IMPLEMENTATIONDETAILS_DEVICEBUFFER_HPP
Exceptions.hpp
DeviceMemoryManager.hpp
OPENMPCD_DEBUG_ASSERT.hpp
OPENMPCD_DEBUG_ASSERT_EXCEPTIONTYPE
#define OPENMPCD_DEBUG_ASSERT_EXCEPTIONTYPE(assertion, ExceptionType)
Definition: OPENMPCD_DEBUG_ASSERT.hpp:76
OpenMPCD::CUDA::DeviceBuffer
Represents a memory buffer on the Device.
Definition: DeviceBuffer.hpp:24
OpenMPCD::CUDA::DeviceBuffer::DeviceBuffer
DeviceBuffer(const std::size_t elementCount_)
The constructor.
Definition: ImplementationDetails/DeviceBuffer.hpp:19
OpenMPCD::NULLPointerException
NULL-pointer exception.
Definition: Exceptions.hpp:96
OpenMPCD::InvalidArgumentException
Invalid argument exception.
Definition: Exceptions.hpp:128