Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions opm/simulators/linalg/gpuistl/GpuSeqILU0.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,17 +187,14 @@ template <typename T, typename std::enable_if_t<is_gpu_matrix_v<T>, int>>
GpuSeqILU0<M, X, Y, l>::GpuSeqILU0(const M& A, field_type w)
: m_underlyingMatrix(A)
, m_w(w)
, m_LU(A.getNonZeroValues().data(),
A.getRowIndices().data(),
A.getColumnIndices().data(),
A.nonzeroes(),
A.blockSize(),
A.N())
, m_LU(A.getRowIndices(), A.getColumnIndices(), A.blockSize())
, m_temporaryStorage(m_LU.N() * m_LU.blockSize())
, m_descriptionL(detail::createLowerDiagonalDescription())
, m_descriptionU(detail::createUpperDiagonalDescription())
, m_cuSparseHandle(detail::CuSparseHandle::getInstance())
{
m_LU.updateNonzeroValues(A);

// Some sanity check
OPM_ERROR_IF(A.N() != m_LU.N(),
fmt::format("CuSparse matrix not same size as DUNE matrix. {} vs {}.", m_LU.N(), A.N()));
Expand Down
4 changes: 4 additions & 0 deletions opm/simulators/linalg/gpuistl/GpuVector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <opm/simulators/linalg/gpuistl/detail/cublas_wrapper.hpp>
#include <opm/simulators/linalg/gpuistl/detail/gpu_constants.hpp>
#include <opm/simulators/linalg/gpuistl/detail/gpu_safe_call.hpp>
#include <opm/simulators/linalg/gpuistl/detail/is_gpu_pointer.hpp>
#include <opm/simulators/linalg/gpuistl/detail/vector_operations.hpp>

namespace Opm::gpuistl
Expand All @@ -49,6 +50,9 @@ template <class T>
GpuVector<T>::GpuVector(const T* dataOnHost, const size_t numberOfElements)
: GpuVector(numberOfElements)
{
if (detail::isGPUPointer(dataOnHost)) {
OPM_THROW(std::invalid_argument, "dataOnHost is a GPU pointer, use copy constructor instead");
}

OPM_GPU_SAFE_CALL(cudaMemcpy(
m_dataOnDevice, dataOnHost, detail::to_size_t(m_numberOfElements) * sizeof(T), cudaMemcpyHostToDevice));
Expand Down
7 changes: 7 additions & 0 deletions tests/gpuistl/test_GpuVector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ BOOST_AUTO_TEST_CASE(TestCopyFromHostConstructor)
BOOST_CHECK_EQUAL_COLLECTIONS(buffer.begin(), buffer.end(), data.begin(), data.end());
}

BOOST_AUTO_TEST_CASE(TestCopyFromHostConstructorWithGPUPointer)
{
std::vector<double> data {{1, 2, 3, 4, 5, 6, 7}};
auto vectorOnGPU = Opm::gpuistl::GpuVector<double>(data.data(), data.size());
BOOST_CHECK_THROW(Opm::gpuistl::GpuVector<double>(vectorOnGPU.data(), data.size()), std::invalid_argument);
}


BOOST_AUTO_TEST_CASE(TestCopyFromHostFunction)
{
Expand Down