opm-simulators
Loading...
Searching...
No Matches
Opm::gpuistl::PinnedMemoryHolder< T > Class Template Reference

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

#include <PinnedMemoryHolder.hpp>

Public Member Functions

 PinnedMemoryHolder (T *ptr, std::size_t numberOfElements, unsigned int flags=cudaHostRegisterDefault)
 Constructs a PinnedMemoryHolder and registers the host memory.
 ~PinnedMemoryHolder ()
 Destructor.
 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.
std::size_t numberOfElements () const
 Gets the number of elements in the pinned memory region.

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()

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.

◆ ~PinnedMemoryHolder()

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

Destructor.

Unregisters the host memory.

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.

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