From 0eb60e533662f2f837029be11f6e5c8d0c3e4a6c Mon Sep 17 00:00:00 2001 From: Kjetil Olsen Lye Date: Tue, 30 May 2023 10:03:54 +0200 Subject: [PATCH] Added test of size for copyToHost. --- opm/simulators/linalg/cuistl/CuVector.cpp | 12 ++++++++++-- opm/simulators/linalg/cuistl/CuVector.hpp | 2 ++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/opm/simulators/linalg/cuistl/CuVector.cpp b/opm/simulators/linalg/cuistl/CuVector.cpp index 5a79947e9..baf9b6fa8 100644 --- a/opm/simulators/linalg/cuistl/CuVector.cpp +++ b/opm/simulators/linalg/cuistl/CuVector.cpp @@ -132,9 +132,16 @@ template void CuVector::assertSameSize(const CuVector& x) const { - if (x.m_numberOfElements != m_numberOfElements) { + assertSameSize(x.m_numberOfElements); +} + +template +void +CuVector::assertSameSize(int size) const +{ + if (size != m_numberOfElements) { OPM_THROW(std::invalid_argument, - fmt::format("Given vector has {}, while we have {}.", x.m_numberOfElements, m_numberOfElements)); + fmt::format("Given vector has {}, while we have {}.", size, m_numberOfElements)); } } @@ -263,6 +270,7 @@ template void CuVector::copyToHost(T* dataPointer, size_t numberOfElements) const { + assertSameSize(detail::to_int(numberOfElements)); OPM_CUDA_SAFE_CALL(cudaMemcpy(dataPointer, data(), numberOfElements * sizeof(T), cudaMemcpyDeviceToHost)); } diff --git a/opm/simulators/linalg/cuistl/CuVector.hpp b/opm/simulators/linalg/cuistl/CuVector.hpp index 48380c3fb..1b46c6b1d 100644 --- a/opm/simulators/linalg/cuistl/CuVector.hpp +++ b/opm/simulators/linalg/cuistl/CuVector.hpp @@ -370,6 +370,8 @@ private: detail::CuBlasHandle& m_cuBlasHandle; void assertSameSize(const CuVector& other) const; + void assertSameSize(int size) const; + void assertHasElements() const; }; } // namespace Opm::cuistl