My Project
Loading...
Searching...
No Matches
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.
 
 GpuView (std::vector< T > &data)
 constructor based on std::vectors, this will make a view on the CPU
 
__host__ __device__ T & operator[] (size_t idx)
 operator[] to retrieve a reference to an item in the buffer
 
__host__ __device__ T operator[] (size_t idx) const
 operator[] to retrieve a copy of an item in the buffer
 
__host__ __device__ GpuView (T *dataOnHost, size_t numberOfElements)
 GpuView allocates new GPU memory of size numberOfElements * sizeof(T) and copies numberOfElements from data.
 
 ~GpuView ()=default
 ~GpuView calls cudaFree
 
__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
 
void copyToHost (T *dataPointer, size_t numberOfElements) const
 copyFromHost copies numberOfElements to the CPU memory dataPointer
 
void copyFromHost (const std::vector< T > &data)
 copyToHost copies data from an std::vector
 
void copyToHost (std::vector< T > &data) const
 copyToHost copies data to an std::vector
 
__host__ __device__ size_t size () const
 size returns the size (number of T elements) in the vector
 
std::vector< T > asStdVector () const
 creates an std::vector of the same size and copies the GPU data to this std::vector
 
__host__ __device__ iterator begin ()
 Get an iterator pointing to the first element of the buffer.
 
__host__ __device__ iterator begin () const
 Get a const iterator pointing to the first element of the buffer.
 
__host__ __device__ iterator end ()
 Get an iterator pointing to the address after the last element of the buffer.
 
__host__ __device__ iterator end () const
 Get a const iterator pointing to the address after the last element of the buffer.
 

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

Constructor & Destructor Documentation

◆ GpuView() [1/2]

template<class 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() [2/2]

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

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<class 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<class 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<class 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<class 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 files: