Added test of size for copyToHost.

This commit is contained in:
Kjetil Olsen Lye 2023-05-30 10:03:54 +02:00
parent b4b1a7b77f
commit 0eb60e5336
2 changed files with 12 additions and 2 deletions

View File

@ -132,9 +132,16 @@ template <typename T>
void
CuVector<T>::assertSameSize(const CuVector<T>& x) const
{
if (x.m_numberOfElements != m_numberOfElements) {
assertSameSize(x.m_numberOfElements);
}
template <typename T>
void
CuVector<T>::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 <class T>
void
CuVector<T>::copyToHost(T* dataPointer, size_t numberOfElements) const
{
assertSameSize(detail::to_int(numberOfElements));
OPM_CUDA_SAFE_CALL(cudaMemcpy(dataPointer, data(), numberOfElements * sizeof(T), cudaMemcpyDeviceToHost));
}

View File

@ -370,6 +370,8 @@ private:
detail::CuBlasHandle& m_cuBlasHandle;
void assertSameSize(const CuVector<T>& other) const;
void assertSameSize(int size) const;
void assertHasElements() const;
};
} // namespace Opm::cuistl