Block-Structured AMR Software Framework
 
Loading...
Searching...
No Matches
amrex::Gpu::Buffer< T, > Class Template Reference

#include <AMReX_GpuBuffer.H>

Public Member Functions

 Buffer (std::initializer_list< T > init)
 
 Buffer (T const *h_p, const std::size_t n)
 
 Buffer (const std::size_t n)
 
 Buffer ()=default
 
T const * data () const noexcept
 
T * data () noexcept
 
T const * hostData () const noexcept
 
T * hostData () noexcept
 
T & operator[] (const std::size_t i) noexcept
 Changes the value of an element of the host (CPU) vector. Does not update the device (GPU) vector, so copyToDeviceAsync() needs to be called before accessing the data on the GPU.
 
const T & operator[] (const std::size_t i) const noexcept
 
std::size_t size () const noexcept
 
bool empty () const noexcept
 
void resize (const std::size_t n) noexcept
 
void clear () noexcept
 
void shrink_to_fit () noexcept
 
void reserve (const std::size_t n) noexcept
 
void push_back (const T &value) noexcept
 Adds an element to the back of the host (CPU) vector. Does not update the device (GPU) vector, so copyToDeviceAsync() needs to be called before accessing the data on the GPU.
 
T * copyToDeviceAsync () noexcept
 
T * copyToHost () noexcept
 

Private Member Functions

bool useDVect () const noexcept
 

Private Attributes

DeviceVector< T > d_vect
 
PinnedVector< T > h_vect
 

Constructor & Destructor Documentation

◆ Buffer() [1/4]

template<typename T , std::enable_if_t< std::is_trivially_copyable_v< T >, int > = 0>
amrex::Gpu::Buffer< T, >::Buffer ( std::initializer_list< T >  init)
inline

◆ Buffer() [2/4]

template<typename T , std::enable_if_t< std::is_trivially_copyable_v< T >, int > = 0>
amrex::Gpu::Buffer< T, >::Buffer ( T const *  h_p,
const std::size_t  n 
)
inline

◆ Buffer() [3/4]

template<typename T , std::enable_if_t< std::is_trivially_copyable_v< T >, int > = 0>
amrex::Gpu::Buffer< T, >::Buffer ( const std::size_t  n)
inline

◆ Buffer() [4/4]

template<typename T , std::enable_if_t< std::is_trivially_copyable_v< T >, int > = 0>
amrex::Gpu::Buffer< T, >::Buffer ( )
default

Member Function Documentation

◆ clear()

template<typename T , std::enable_if_t< std::is_trivially_copyable_v< T >, int > = 0>
void amrex::Gpu::Buffer< T, >::clear ( )
inlinenoexcept

◆ copyToDeviceAsync()

template<typename T , std::enable_if_t< std::is_trivially_copyable_v< T >, int > = 0>
T * amrex::Gpu::Buffer< T, >::copyToDeviceAsync ( )
inlinenoexcept

◆ copyToHost()

template<typename T , std::enable_if_t< std::is_trivially_copyable_v< T >, int > = 0>
T * amrex::Gpu::Buffer< T, >::copyToHost ( )
inlinenoexcept

◆ data() [1/2]

template<typename T , std::enable_if_t< std::is_trivially_copyable_v< T >, int > = 0>
T const * amrex::Gpu::Buffer< T, >::data ( ) const
inlinenoexcept

◆ data() [2/2]

template<typename T , std::enable_if_t< std::is_trivially_copyable_v< T >, int > = 0>
T * amrex::Gpu::Buffer< T, >::data ( )
inlinenoexcept

◆ empty()

template<typename T , std::enable_if_t< std::is_trivially_copyable_v< T >, int > = 0>
bool amrex::Gpu::Buffer< T, >::empty ( ) const
inlinenoexcept

◆ hostData() [1/2]

template<typename T , std::enable_if_t< std::is_trivially_copyable_v< T >, int > = 0>
T const * amrex::Gpu::Buffer< T, >::hostData ( ) const
inlinenoexcept

◆ hostData() [2/2]

template<typename T , std::enable_if_t< std::is_trivially_copyable_v< T >, int > = 0>
T * amrex::Gpu::Buffer< T, >::hostData ( )
inlinenoexcept

◆ operator[]() [1/2]

template<typename T , std::enable_if_t< std::is_trivially_copyable_v< T >, int > = 0>
const T & amrex::Gpu::Buffer< T, >::operator[] ( const std::size_t  i) const
inlinenoexcept

◆ operator[]() [2/2]

template<typename T , std::enable_if_t< std::is_trivially_copyable_v< T >, int > = 0>
T & amrex::Gpu::Buffer< T, >::operator[] ( const std::size_t  i)
inlinenoexcept

Changes the value of an element of the host (CPU) vector. Does not update the device (GPU) vector, so copyToDeviceAsync() needs to be called before accessing the data on the GPU.

buf.resize(n);
for (int i=0; i<n; ++i) {
buf[i] = i*i;
}
int * ptr = buf.data();
// Use ptr inside ParallelFor
// optional:
// Change values of ptr inside ParallelFor
buf.copyToHost();
// Use buf.hostData() or buf[] on the CPU
Definition AMReX_GpuBuffer.H:18
T const * data() const noexcept
Definition AMReX_GpuBuffer.H:45
T * copyToHost() noexcept
Definition AMReX_GpuBuffer.H:145
void resize(const std::size_t n) noexcept
Definition AMReX_GpuBuffer.H:86
T * copyToDeviceAsync() noexcept
Definition AMReX_GpuBuffer.H:133

◆ push_back()

template<typename T , std::enable_if_t< std::is_trivially_copyable_v< T >, int > = 0>
void amrex::Gpu::Buffer< T, >::push_back ( const T &  value)
inlinenoexcept

Adds an element to the back of the host (CPU) vector. Does not update the device (GPU) vector, so copyToDeviceAsync() needs to be called before accessing the data on the GPU.

buf.reserve(n);
for (int i=0; i<n; ++i) {
buf.push_back(i*i);
}
int * ptr = buf.data();
// Use ptr inside ParallelFor
// optional:
// Change values of ptr inside ParallelFor
buf.copyToHost();
// Use buf.hostData() or buf[] on the CPU
void reserve(const std::size_t n) noexcept
Definition AMReX_GpuBuffer.H:103
void push_back(const T &value) noexcept
Adds an element to the back of the host (CPU) vector. Does not update the device (GPU) vector,...
Definition AMReX_GpuBuffer.H:129

◆ reserve()

template<typename T , std::enable_if_t< std::is_trivially_copyable_v< T >, int > = 0>
void amrex::Gpu::Buffer< T, >::reserve ( const std::size_t  n)
inlinenoexcept

◆ resize()

template<typename T , std::enable_if_t< std::is_trivially_copyable_v< T >, int > = 0>
void amrex::Gpu::Buffer< T, >::resize ( const std::size_t  n)
inlinenoexcept

◆ shrink_to_fit()

template<typename T , std::enable_if_t< std::is_trivially_copyable_v< T >, int > = 0>
void amrex::Gpu::Buffer< T, >::shrink_to_fit ( )
inlinenoexcept

◆ size()

template<typename T , std::enable_if_t< std::is_trivially_copyable_v< T >, int > = 0>
std::size_t amrex::Gpu::Buffer< T, >::size ( ) const
inlinenoexcept

◆ useDVect()

template<typename T , std::enable_if_t< std::is_trivially_copyable_v< T >, int > = 0>
bool amrex::Gpu::Buffer< T, >::useDVect ( ) const
inlineprivatenoexcept

Member Data Documentation

◆ d_vect

template<typename T , std::enable_if_t< std::is_trivially_copyable_v< T >, int > = 0>
DeviceVector<T> amrex::Gpu::Buffer< T, >::d_vect
private

◆ h_vect

template<typename T , std::enable_if_t< std::is_trivially_copyable_v< T >, int > = 0>
PinnedVector<T> amrex::Gpu::Buffer< T, >::h_vect
private

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