19#ifndef OPM_GPUBUFFER_HEADER_HPP
20#define OPM_GPUBUFFER_HEADER_HPP
21#include <dune/common/fvector.hh>
22#include <dune/istl/bvector.hh>
25#include <opm/common/ErrorMacros.hpp>
26#include <opm/simulators/linalg/gpuistl/detail/safe_conversion.hpp>
27#include <opm/simulators/linalg/gpuistl/GpuView.hpp>
30#include <cuda_runtime.h>
60 using size_type = size_t;
71 GpuBuffer(
const GpuBuffer<T>& other);
82 explicit GpuBuffer(
const std::vector<T>& data);
87 GpuBuffer() =
default;
94 explicit GpuBuffer(
const size_t numberOfElements);
106 GpuBuffer(
const T* dataOnHost,
const size_t numberOfElements);
111 virtual ~GpuBuffer();
121 const T* data()
const;
130 template <
int BlockDimension>
131 void copyFromHost(
const Dune::BlockVector<Dune::FieldVector<T, BlockDimension>>& bvector)
134 if (m_numberOfElements != bvector.size()) {
135 OPM_THROW(std::runtime_error,
136 fmt::format(
"Given incompatible vector size. GpuBuffer has size {}, \n"
137 "however, BlockVector has N() = {}, and size = {}.",
142 const auto dataPointer =
static_cast<const T*
>(&(bvector[0][0]));
143 copyFromHost(dataPointer, m_numberOfElements);
153 template <
int BlockDimension>
154 void copyToHost(Dune::BlockVector<Dune::FieldVector<T, BlockDimension>>& bvector)
const
157 if (m_numberOfElements != bvector.size()) {
158 OPM_THROW(std::runtime_error,
159 fmt::format(
"Given incompatible vector size. GpuBuffer has size {},\n however, the BlockVector "
160 "has has N() = {}, and size() = {}.",
165 const auto dataPointer =
static_cast<T*
>(&(bvector[0][0]));
166 copyToHost(dataPointer, m_numberOfElements);
176 void copyFromHost(
const T* dataPointer,
size_t numberOfElements);
185 void copyToHost(T* dataPointer,
size_t numberOfElements)
const;
194 void copyFromHost(
const std::vector<T>& data);
203 void copyToHost(std::vector<T>& data)
const;
209 size_type size()
const;
221 std::vector<T> asStdVector()
const;
224 T* m_dataOnDevice =
nullptr;
225 size_t m_numberOfElements = 0;
227 void assertSameSize(
const GpuBuffer<T>& other)
const;
228 void assertSameSize(
size_t size)
const;
230 void assertHasElements()
const;
constexpr auto getPropValue()
get the value data member of a property
Definition propertysystem.hh:242