19#ifndef OPM_GPUVECTOR_HEADER_HPP
20#define OPM_GPUVECTOR_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/CuBlasHandle.hpp>
27#include <opm/simulators/linalg/gpuistl/detail/safe_conversion.hpp>
28#include <opm/simulators/linalg/gpuistl/detail/gpu_constants.hpp>
94 explicit GpuVector(
const std::vector<T>& data);
117 template<
int BlockDimension>
118 explicit GpuVector(
const Dune::BlockVector<Dune::FieldVector<T, BlockDimension>>&
bvector)
131 GpuVector& operator=(T
scalar);
136 GpuVector() : m_dataOnDevice(
nullptr), m_numberOfElements(0), m_cuBlasHandle(detail::CuBlasHandle::getInstance()) {}
145 explicit GpuVector(
const size_t numberOfElements);
159 GpuVector(
const T*
dataOnHost,
const size_t numberOfElements);
174 const T* data()
const;
183 template <
int BlockDimension>
184 void copyFromHost(
const Dune::BlockVector<Dune::FieldVector<T, BlockDimension>>&
bvector)
189 fmt::format(
"Given incompatible vector size. GpuVector has size {}, \n"
190 "however, BlockVector has N() = {}, and dim = {}.",
207 template <
int BlockDimension>
213 fmt::format(
"Given incompatible vector size. GpuVector has size {}, \n"
214 "however, BlockVector has N() = {}, and dim = {}.",
230 template <
int BlockDimension>
231 void copyToHost(Dune::BlockVector<Dune::FieldVector<T, BlockDimension>>&
bvector)
const
236 fmt::format(
"Given incompatible vector size. GpuVector has size {},\n however, the BlockVector "
237 "has has N() = {}, and dim() = {}.",
254 template <
int BlockDimension>
260 fmt::format(
"Given incompatible vector size. GpuVector has size {},\n however, the BlockVector "
261 "has has N() = {}, and dim() = {}.",
277 void copyFromHost(
const T*
dataPointer,
size_t numberOfElements);
300 void copyToHost(T*
dataPointer,
size_t numberOfElements)
const;
323 void copyFromHost(
const std::vector<T>& data);
342 void copyToHost(std::vector<T>& data)
const;
455 size_type dim()
const;
471 std::vector<T> asStdVector()
const;
477 template <
int blockSize>
481 fmt::format(
"blockSize is not a multiple of dim(). Given blockSize = {}, and dim() = {}",
485 Dune::BlockVector<Dune::FieldVector<T, blockSize>>
returnValue(dim() / blockSize);
507 std::string toDebugString()
509 std::vector<T>
v = asStdVector();
510 std::string
res =
"";
512 res += std::to_string(element) +
" ";
514 res += std::to_string(
v[
v.size()-1]);
519 T* m_dataOnDevice =
nullptr;
523 int m_numberOfElements;
524 detail::CuBlasHandle& m_cuBlasHandle;
527 void assertSameSize(
int size)
const;
529 void assertHasElements()
const;
535namespace Opm::gpuistl
void setZeroAtIndexSet(T *deviceData, size_t numberOfElements, const int *indices)
setZeroAtIndexSet sets deviceData to zero in the indices of contained in indices
constexpr cudaStream_t DEFAULT_STREAM
The default GPU stream (stream 0)
Definition gpu_constants.hpp:31
__host__ __device__ std::size_t to_size_t(int i)
to_size_t converts a (on most relevant platforms) a 32 bit signed int to a 64 bits unsigned int
Definition safe_conversion.hpp:86
constexpr auto getPropValue()
get the value data member of a property
Definition propertysystem.hh:240