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)
 
void clear () noexcept
 
void shrink_to_fit ()
 
void reserve (const std::size_t n)
 
void push_back (const T &value)
 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 ()
 
T * copyToHost ()
 

Detailed Description

template<typename T, std::enable_if_t< std::is_trivially_copyable_v< T >, int > = 0>
class amrex::Gpu::Buffer< T, >
Warning
Gpu::Buffer assumes the GPU launch-region state stays fixed for its lifetime. Flipping the launch-region flag between construction and destruction may break Gpu::Buffer's member functions.

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

◆ copyToHost()

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

◆ 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:23
T const * data() const noexcept
Definition AMReX_GpuBuffer.H:50
T * copyToDeviceAsync()
Definition AMReX_GpuBuffer.H:138
void resize(const std::size_t n)
Definition AMReX_GpuBuffer.H:91
T * copyToHost()
Definition AMReX_GpuBuffer.H:150

◆ 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)
inline

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)
Definition AMReX_GpuBuffer.H:108
void push_back(const T &value)
Adds an element to the back of the host (CPU) vector. Does not update the device (GPU) vector,...
Definition AMReX_GpuBuffer.H:134

◆ 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)
inline

◆ 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)
inline

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

◆ 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

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