Opm::gpuistl::PinnedMemoryHolder< T > Class Template Reference

RAII class for pinning host memory using cudaHostRegister. More...

#include <PinnedMemoryHolder.hpp>

Inheritance diagram for Opm::gpuistl::PinnedMemoryHolder< T >:
Inheritance graph

Public Member Functions

 PinnedMemoryHolder (T *ptr, std::size_t numberOfElements, unsigned int flags=cudaHostRegisterDefault)
 Constructs a PinnedMemoryHolder and registers the host memory. More...
 
 ~PinnedMemoryHolder ()
 Destructor. Unregisters the host memory. More...
 
 PinnedMemoryHolder (const PinnedMemoryHolder &)=delete
 
PinnedMemoryHolderoperator= (const PinnedMemoryHolder &)=delete
 
 PinnedMemoryHolder (PinnedMemoryHolder &&other) noexcept
 
PinnedMemoryHolderoperator= (PinnedMemoryHolder &&other) noexcept
 
T * get () const
 Gets the pointer to the pinned memory. More...
 
std::size_t numberOfElements () const
 Gets the number of elements in the pinned memory region. More...
 

Detailed Description

template<class T>
class Opm::gpuistl::PinnedMemoryHolder< T >

RAII class for pinning host memory using cudaHostRegister.

This class registers a given host memory region in its constructor and unregisters it in its destructor. This is useful for speeding up asynchronous memory transfers between host and GPU.

Template Parameters
TThe type of data pointed to by the host pointer.

Constructor & Destructor Documentation

◆ PinnedMemoryHolder() [1/3]

template<class T >
Opm::gpuistl::PinnedMemoryHolder< T >::PinnedMemoryHolder ( T *  ptr,
std::size_t  numberOfElements,
unsigned int  flags = cudaHostRegisterDefault 
)
inline

Constructs a PinnedMemoryHolder and registers the host memory.

Parameters
ptrPointer to the host memory to be pinned.
numberOfElementsThe number of elements of type T in the memory region.
flagsFlags for cudaHostRegister. Defaults to cudaHostRegisterDefault.
Exceptions
std::runtime_errorif cudaHostRegister fails.

References Opm::gpuistl::PinnedMemoryHolder< T >::numberOfElements(), and OPM_GPU_SAFE_CALL.

◆ ~PinnedMemoryHolder()

template<class T >
Opm::gpuistl::PinnedMemoryHolder< T >::~PinnedMemoryHolder ( )
inline

Destructor. Unregisters the host memory.

References OPM_GPU_SAFE_CALL.

◆ PinnedMemoryHolder() [2/3]

template<class T >
Opm::gpuistl::PinnedMemoryHolder< T >::PinnedMemoryHolder ( const PinnedMemoryHolder< T > &  )
delete

◆ PinnedMemoryHolder() [3/3]

template<class T >
Opm::gpuistl::PinnedMemoryHolder< T >::PinnedMemoryHolder ( PinnedMemoryHolder< T > &&  other)
inlinenoexcept

Member Function Documentation

◆ get()

template<class T >
T * Opm::gpuistl::PinnedMemoryHolder< T >::get ( ) const
inline

Gets the pointer to the pinned memory.

Returns
Pointer to the pinned memory, or nullptr if not valid.

◆ numberOfElements()

template<class T >
std::size_t Opm::gpuistl::PinnedMemoryHolder< T >::numberOfElements ( ) const
inline

Gets the number of elements in the pinned memory region.

Returns
Number of elements.

Referenced by Opm::gpuistl::PinnedMemoryHolder< T >::PinnedMemoryHolder().

◆ operator=() [1/2]

template<class T >
PinnedMemoryHolder & Opm::gpuistl::PinnedMemoryHolder< T >::operator= ( const PinnedMemoryHolder< T > &  )
delete

◆ operator=() [2/2]

template<class T >
PinnedMemoryHolder & Opm::gpuistl::PinnedMemoryHolder< T >::operator= ( PinnedMemoryHolder< T > &&  other)
inlinenoexcept

References OPM_GPU_SAFE_CALL.


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