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

The GpuView class is provides a view of some data allocated on the GPU Essenstially is only stores a pointer and a size. More...

#include <GpuView.hpp>

Classes

class  iterator
 Iterator class to make GpuViews more similar to std containers. More...
 

Public Types

using value_type = T
 

Public Member Functions

 GpuView ()=default
 Default constructor that will initialize cublas and allocate 0 bytes of memory. More...
 
 GpuView (std::vector< T > &data)
 constructor based on std::vectors, this will make a view on the CPU More...
 
__host__ __device__ T & operator[] (size_t idx)
 operator[] to retrieve a reference to an item in the buffer More...
 
__host__ __device__ T operator[] (size_t idx) const
 operator[] to retrieve a copy of an item in the buffer More...
 
__host__ __device__ GpuView (T *dataOnHost, size_t numberOfElements)
 GpuView allocates new GPU memory of size numberOfElements * sizeof(T) and copies numberOfElements from data. More...
 
 ~GpuView ()=default
 ~GpuView calls cudaFree More...
 
__host__ __device__ T * data ()
 
__host__ __device__ const T * data () const
 
__host__ __device__ T & front ()
 
__host__ __device__ T & back ()
 
__host__ __device__ T front () const
 
__host__ __device__ T back () const
 
void copyFromHost (const T *dataPointer, size_t numberOfElements)
 copyFromHost copies numberOfElements from the CPU memory dataPointer More...
 
void copyToHost (T *dataPointer, size_t numberOfElements) const
 copyFromHost copies numberOfElements to the CPU memory dataPointer More...
 
void copyFromHost (const std::vector< T > &data)
 copyToHost copies data from an std::vector More...
 
void copyToHost (std::vector< T > &data) const
 copyToHost copies data to an std::vector More...
 
__host__ __device__ size_t size () const
 size returns the size (number of T elements) in the vector More...
 
std::vector< T > asStdVector () const
 creates an std::vector of the same size and copies the GPU data to this std::vector More...
 
__host__ __device__ iterator begin ()
 Get an iterator pointing to the first element of the buffer. More...
 
__host__ __device__ iterator begin () const
 Get a const iterator pointing to the first element of the buffer. More...
 
__host__ __device__ iterator end ()
 Get an iterator pointing to the address after the last element of the buffer. More...
 
__host__ __device__ iterator end () const
 Get a const iterator pointing to the address after the last element of the buffer. More...
 

Detailed Description

template<typename T>
class Opm::gpuistl::GpuView< T >

The GpuView class is provides a view of some data allocated on the GPU Essenstially is only stores a pointer and a size.

This class supports being used from inside a CUDA/HIP Kernel. Implementations are placed in this headerfile for functions that may be called inside a kernel to avoid expensive RDC (relocatable device code)

The view will typically provide a view into a GpuBuffer and be able to manipulate the data within it

Parameters
TType of the data we store, typically int/float/double w/o const specifier

Member Typedef Documentation

◆ value_type

template<typename T >
using Opm::gpuistl::GpuView< T >::value_type = T

Constructor & Destructor Documentation

◆ GpuView() [1/3]

template<typename T >
Opm::gpuistl::GpuView< T >::GpuView ( )
explicitdefault

Default constructor that will initialize cublas and allocate 0 bytes of memory.

◆ GpuView() [2/3]

template<typename T >
Opm::gpuistl::GpuView< T >::GpuView ( std::vector< T > &  data)

constructor based on std::vectors, this will make a view on the CPU

Parameters
datastd vector to pr

◆ GpuView() [3/3]

template<typename T >
__host__ __device__ Opm::gpuistl::GpuView< T >::GpuView ( T *  dataOnHost,
size_t  numberOfElements 
)
inline

GpuView allocates new GPU memory of size numberOfElements * sizeof(T) and copies numberOfElements from data.

Note
This assumes the data is on the CPU.
Parameters
numberOfElementsnumber of T elements to allocate
dataOnHostdata on host/CPU

◆ ~GpuView()

template<typename T >
Opm::gpuistl::GpuView< T >::~GpuView ( )
default

~GpuView calls cudaFree

Member Function Documentation

◆ asStdVector()

template<typename T >
std::vector< T > Opm::gpuistl::GpuView< T >::asStdVector ( ) const

creates an std::vector of the same size and copies the GPU data to this std::vector

Returns
an std::vector containing the elements copied from the GPU.

◆ back() [1/2]

template<typename T >
__host__ __device__ T & Opm::gpuistl::GpuView< T >::back ( )
inline
Returns
fetch the last element in a GpuView

◆ back() [2/2]

template<typename T >
__host__ __device__ T Opm::gpuistl::GpuView< T >::back ( ) const
inline
Returns
fetch the last element in a GpuView

◆ begin() [1/2]

template<typename T >
__host__ __device__ iterator Opm::gpuistl::GpuView< T >::begin ( )
inline

Get an iterator pointing to the first element of the buffer.

Parameters
iteratorto traverse the buffer

◆ begin() [2/2]

template<typename T >
__host__ __device__ iterator Opm::gpuistl::GpuView< T >::begin ( ) const
inline

Get a const iterator pointing to the first element of the buffer.

Parameters
iteratorto traverse the buffer

◆ copyFromHost() [1/2]

template<typename T >
void Opm::gpuistl::GpuView< T >::copyFromHost ( const std::vector< T > &  data)

copyToHost copies data from an std::vector

Parameters
datathe vector to copy from
Note
This does synchronous transfer.
This assumes that the size of this view is equal to the size of the input vector.

◆ copyFromHost() [2/2]

template<typename T >
void Opm::gpuistl::GpuView< T >::copyFromHost ( const T *  dataPointer,
size_t  numberOfElements 
)

copyFromHost copies numberOfElements from the CPU memory dataPointer

Parameters
dataPointerraw pointer to CPU memory
numberOfElementsnumber of elements to copy
Note
This does synchronous transfer.
assumes that this view has numberOfElements elements

◆ copyToHost() [1/2]

template<typename T >
void Opm::gpuistl::GpuView< T >::copyToHost ( std::vector< T > &  data) const

copyToHost copies data to an std::vector

Parameters
datathe vector to copy to
Note
This does synchronous transfer.
This assumes that the size of this view is equal to the size of the input vector.

◆ copyToHost() [2/2]

template<typename T >
void Opm::gpuistl::GpuView< T >::copyToHost ( T *  dataPointer,
size_t  numberOfElements 
) const

copyFromHost copies numberOfElements to the CPU memory dataPointer

Parameters
dataPointerraw pointer to CPU memory
numberOfElementsnumber of elements to copy
Note
This does synchronous transfer.
assumes that this view has numberOfElements elements

◆ data() [1/2]

template<typename T >
__host__ __device__ T * Opm::gpuistl::GpuView< T >::data ( )
inline
Returns
the raw pointer to the GPU data

◆ data() [2/2]

template<typename T >
__host__ __device__ const T * Opm::gpuistl::GpuView< T >::data ( ) const
inline
Returns
the raw pointer to the GPU data

◆ end() [1/2]

template<typename T >
__host__ __device__ iterator Opm::gpuistl::GpuView< T >::end ( )
inline

Get an iterator pointing to the address after the last element of the buffer.

Parameters
iteratorpointing to the first value after the end of the buffer

◆ end() [2/2]

template<typename T >
__host__ __device__ iterator Opm::gpuistl::GpuView< T >::end ( ) const
inline

Get a const iterator pointing to the address after the last element of the buffer.

Parameters
iteratorpointing to the first value after the end of the buffer

◆ front() [1/2]

template<typename T >
__host__ __device__ T & Opm::gpuistl::GpuView< T >::front ( )
inline
Returns
fetch the first element in a GpuView

◆ front() [2/2]

template<typename T >
__host__ __device__ T Opm::gpuistl::GpuView< T >::front ( ) const
inline
Returns
fetch the first element in a GpuView

◆ operator[]() [1/2]

template<typename T >
__host__ __device__ T & Opm::gpuistl::GpuView< T >::operator[] ( size_t  idx)
inline

operator[] to retrieve a reference to an item in the buffer

Parameters
idxThe index of the element

◆ operator[]() [2/2]

template<typename T >
__host__ __device__ T Opm::gpuistl::GpuView< T >::operator[] ( size_t  idx) const
inline

operator[] to retrieve a copy of an item in the buffer

Parameters
idxThe index of the element

◆ size()

template<typename T >
__host__ __device__ size_t Opm::gpuistl::GpuView< T >::size ( ) const
inline

size returns the size (number of T elements) in the vector

Returns
number of elements

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