19#ifndef OPM_GPUVIEW_HEADER_HPP
20#define OPM_GPUVIEW_HEADER_HPP
22#include <dune/common/fvector.hh>
24#include <opm/common/ErrorMacros.hpp>
26#include <opm/common/utility/gpuDecorators.hpp>
27#include <opm/simulators/linalg/gpuistl/detail/safe_conversion.hpp>
75 return m_dataPtr[
idx];
87 return m_dataPtr[
idx];
143 return m_dataPtr[m_numberOfElements-1];
165 return m_dataPtr[m_numberOfElements-1];
209 return m_numberOfElements;
221 using iterator_category = std::forward_iterator_tag;
222 using difference_type = std::ptrdiff_t;
223 using value_type = T;
225 using reference = T&;
273 return !(m_ptr == other.m_ptr);
279 return m_ptr == other.m_ptr;
286 return std::distance(other.m_ptr, m_ptr);
307 return m_ptr < other.m_ptr;
314 return m_ptr > other.m_ptr;
343 return iterator(m_dataPtr + m_numberOfElements);
351 return iterator(m_dataPtr + m_numberOfElements);
356 size_t m_numberOfElements;
362 assertSameSize(other.m_numberOfElements);
368#if OPM_IS_INSIDE_DEVICE_FUNCTION
370 assert(
size == m_numberOfElements &&
"Views did not have the same size");
372 if (
size != m_numberOfElements) {
374 fmt::format(
"Given view has {}, while this View has {}.",
size, m_numberOfElements));
382#if OPM_IS_INSIDE_DEVICE_FUNCTION
384 assert(m_numberOfElements > 0 &&
"View has 0 elements");
386 if (m_numberOfElements <= 0) {
387 OPM_THROW(std::invalid_argument,
"View has 0 elements");
395#if OPM_IS_INSIDE_DEVICE_FUNCTION
397 assert(
idx < m_numberOfElements &&
"The index provided was not in the range [0, buffersize-1]");
399 if (
idx >= m_numberOfElements) {
401 fmt::format(
"The index provided was not in the range [0, buffersize-1]"));
Iterator class to make GpuViews more similar to std containers.
Definition GpuView.hpp:218
__host__ __device__ bool operator>(const iterator &other) const
Greater than comparison.
Definition GpuView.hpp:313
__host__ __device__ iterator operator--(int)
Post-decrement operator.
Definition GpuView.hpp:264
__host__ __device__ bool operator==(const iterator &other) const
Inequality comparison operator.
Definition GpuView.hpp:278
__host__ __device__ reference operator*() const
Dereference operator.
Definition GpuView.hpp:234
__host__ __device__ difference_type operator-(const iterator &other) const
subtraction operator
Definition GpuView.hpp:285
__host__ __device__ iterator & operator++()
Pre-increment operator.
Definition GpuView.hpp:240
__host__ __device__ iterator operator+(difference_type n) const
Addition operator with diffptr.
Definition GpuView.hpp:299
__host__ __device__ iterator operator-(difference_type n) const
Subtraction of given number of elements from iterator.
Definition GpuView.hpp:292
__host__ __device__ iterator operator++(int)
Post-increment operator.
Definition GpuView.hpp:248
__host__ __device__ iterator & operator--()
Pre-decrement operator.
Definition GpuView.hpp:256
__host__ __device__ bool operator!=(const iterator &other) const
Inequality comparison operator.
Definition GpuView.hpp:272
__host__ __device__ iterator(T *ptr)
Create iterator from a pointer.
Definition GpuView.hpp:230
__host__ __device__ bool operator<(const iterator &other) const
Less than comparison.
Definition GpuView.hpp:306
The GpuView class is provides a view of some data allocated on the GPU Essenstially is only stores a ...
Definition GpuView.hpp:53
__host__ __device__ GpuView(T *dataOnHost, size_t numberOfElements)
GpuView allocates new GPU memory of size numberOfElements * sizeof(T) and copies numberOfElements fro...
Definition GpuView.hpp:100
__host__ __device__ iterator begin()
Get an iterator pointing to the first element of the buffer.
Definition GpuView.hpp:326
GpuView()=default
Default constructor that will initialize cublas and allocate 0 bytes of memory.
__host__ __device__ size_t size() const
size returns the size (number of T elements) in the vector
Definition GpuView.hpp:208
__host__ __device__ T * data()
Definition GpuView.hpp:113
void copyFromHost(const T *dataPointer, size_t numberOfElements)
copyFromHost copies numberOfElements from the CPU memory dataPointer
Definition GpuView.cpp:46
__host__ __device__ iterator end() const
Get a const iterator pointing to the address after the last element of the buffer.
Definition GpuView.hpp:350
__host__ __device__ T & front()
Definition GpuView.hpp:127
__host__ __device__ T operator[](size_t idx) const
operator[] to retrieve a copy of an item in the buffer
Definition GpuView.hpp:83
void copyToHost(T *dataPointer, size_t numberOfElements) const
copyFromHost copies numberOfElements to the CPU memory dataPointer
Definition GpuView.cpp:59
__host__ __device__ T & back()
Definition GpuView.hpp:138
__host__ __device__ T back() const
Definition GpuView.hpp:160
__host__ __device__ T front() const
Definition GpuView.hpp:149
__host__ __device__ iterator end()
Get an iterator pointing to the address after the last element of the buffer.
Definition GpuView.hpp:342
__host__ __device__ const T * data() const
Definition GpuView.hpp:120
~GpuView()=default
~GpuView calls cudaFree
__host__ __device__ T & operator[](size_t idx)
operator[] to retrieve a reference to an item in the buffer
Definition GpuView.hpp:71
std::vector< T > asStdVector() const
creates an std::vector of the same size and copies the GPU data to this std::vector
Definition GpuView.cpp:37
__host__ __device__ iterator begin() const
Get a const iterator pointing to the first element of the buffer.
Definition GpuView.hpp:334
constexpr auto getPropValue()
get the value data member of a property
Definition propertysystem.hh:242