ElfPSP_AntColony
Protein Structure Prediction using Ant Colony Optimization
Public Member Functions | Private Attributes | List of all members
CUDAPointer< T > Class Template Reference

Encapsulates a pointer to a memory region within the GPU memory space. More...

Public Member Functions

 CUDAPointer (size_t nElems)
 Constructor that allocates memory within the GPU. More...
 
 ~CUDAPointer ()
 Frees memory allocated upon construction. More...
 
T * get ()
 Returns the raw pointer stored internally. More...
 
 operator T* ()
 Enables casting a CUDAPointer to the associated raw pointer type T*. More...
 
 operator void * ()
 Enables casting a CUDAPointer to void*. More...
 
void memcpyAsync (const T *src)
 Asynchronously copy elements from host memory to GPU memory. More...
 
void copyTo (T *dest, int nElems)
 Synchronously copy elements from GPU memory to host memory. More...
 
void copyTo (T *dest)
 Overload of copyTo(T*, int) that copies the whole memory allocated upon construction to the host memory. More...
 

Private Attributes

T * dPointer
 Pointer to the memory region. More...
 
size_t dNElems
 Number of elements, of the templated type T, that fit in the allocated memory. More...
 

Detailed Description

template<typename T>
class CUDAPointer< T >

Encapsulates a pointer to a memory region within the GPU memory space.

This templated class provides utilities for easy allocation and deallocation of memory in the GPU. Memory is deallocated when the CUDAPointer object runs out of scope.

Constructor & Destructor Documentation

◆ CUDAPointer()

template<typename T>
CUDAPointer< T >::CUDAPointer ( size_t  nElems)
inline

Constructor that allocates memory within the GPU.

Parameters
nElemsNumber of elements, of the templated type T, that should fit in the allocated memory.

◆ ~CUDAPointer()

template<typename T>
CUDAPointer< T >::~CUDAPointer ( )
inline

Frees memory allocated upon construction.

Member Function Documentation

◆ copyTo() [1/2]

template<typename T>
void CUDAPointer< T >::copyTo ( T *  dest,
int  nElems 
)
inline

Synchronously copy elements from GPU memory to host memory.

Parameters
destPointer to memory in host memory to which we should copy elements from GPU memory.
nElemsNumber of elements to be copied. No checks regarding illegal memory access is done, so the user is responsible for that.

◆ copyTo() [2/2]

template<typename T>
void CUDAPointer< T >::copyTo ( T *  dest)
inline

Overload of copyTo(T*, int) that copies the whole memory allocated upon construction to the host memory.

◆ get()

template<typename T>
T* CUDAPointer< T >::get ( )
inline

Returns the raw pointer stored internally.

◆ memcpyAsync()

template<typename T>
void CUDAPointer< T >::memcpyAsync ( const T *  src)
inline

Asynchronously copy elements from host memory to GPU memory.

Parameters
srcPointer to memory in host memory that holds the elements that should be copied. The pointer must have the same number of elements as allocated upon construction of the CUDAPointer object in question.

◆ operator T*()

template<typename T>
CUDAPointer< T >::operator T* ( )
inline

Enables casting a CUDAPointer to the associated raw pointer type T*.

◆ operator void *()

template<typename T>
CUDAPointer< T >::operator void * ( )
inline

Enables casting a CUDAPointer to void*.

Member Data Documentation

◆ dNElems

template<typename T>
size_t CUDAPointer< T >::dNElems
private

Number of elements, of the templated type T, that fit in the allocated memory.

◆ dPointer

template<typename T>
T* CUDAPointer< T >::dPointer
private

Pointer to the memory region.


The documentation for this class was generated from the following file: