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>
requires (std::is_trivially_copyable_v<T>)
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>
amrex::Gpu::Buffer< T >::Buffer ( std::initializer_list< T > init)
inline

◆ Buffer() [2/4]

template<typename T>
amrex::Gpu::Buffer< T >::Buffer ( T const * h_p,
const std::size_t n )
inline

◆ Buffer() [3/4]

template<typename T>
amrex::Gpu::Buffer< T >::Buffer ( const std::size_t n)
inline

◆ Buffer() [4/4]

template<typename T>
amrex::Gpu::Buffer< T >::Buffer ( )
default

Member Function Documentation

◆ clear()

template<typename T>
void amrex::Gpu::Buffer< T >::clear ( )
inlinenoexcept

◆ copyToDeviceAsync()

template<typename T>
T * amrex::Gpu::Buffer< T >::copyToDeviceAsync ( )
inline

◆ copyToHost()

template<typename T>
T * amrex::Gpu::Buffer< T >::copyToHost ( )
inline

◆ data() [1/2]

template<typename T>
T const * amrex::Gpu::Buffer< T >::data ( ) const
inlinenodiscardnoexcept

◆ data() [2/2]

template<typename T>
T * amrex::Gpu::Buffer< T >::data ( )
inlinenodiscardnoexcept

◆ empty()

template<typename T>
bool amrex::Gpu::Buffer< T >::empty ( ) const
inlinenodiscardnoexcept

◆ hostData() [1/2]

template<typename T>
T const * amrex::Gpu::Buffer< T >::hostData ( ) const
inlinenodiscardnoexcept

◆ hostData() [2/2]

template<typename T>
T * amrex::Gpu::Buffer< T >::hostData ( )
inlinenodiscardnoexcept

◆ operator[]() [1/2]

template<typename T>
const T & amrex::Gpu::Buffer< T >::operator[] ( const std::size_t i) const
inlinenodiscardnoexcept

◆ operator[]() [2/2]

template<typename T>
T & amrex::Gpu::Buffer< T >::operator[] ( const std::size_t i)
inlinenodiscardnoexcept

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:24
T * copyToDeviceAsync()
Definition AMReX_GpuBuffer.H:139
void resize(const std::size_t n)
Definition AMReX_GpuBuffer.H:92
T const * data() const noexcept
Definition AMReX_GpuBuffer.H:51
T * copyToHost()
Definition AMReX_GpuBuffer.H:151

◆ push_back()

template<typename T>
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:109
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:135

◆ reserve()

template<typename T>
void amrex::Gpu::Buffer< T >::reserve ( const std::size_t n)
inline

◆ resize()

template<typename T>
void amrex::Gpu::Buffer< T >::resize ( const std::size_t n)
inline

◆ shrink_to_fit()

template<typename T>
void amrex::Gpu::Buffer< T >::shrink_to_fit ( )
inline

◆ size()

template<typename T>
std::size_t amrex::Gpu::Buffer< T >::size ( ) const
inlinenodiscardnoexcept

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