/* Copyright 2024 SINTEF AS This file is part of the Open Porous Media project (OPM). OPM is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. OPM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OPM. If not, see . */ #include #include #include #include #include #include namespace Opm::cuistl { template CuView::CuView(std::vector& data) : CuView(data.data(), data.size()) { } template std::vector CuView::asStdVector() const { std::vector temporary(m_numberOfElements); copyToHost(temporary); return temporary; } template void CuView::copyFromHost(const T* dataPointer, size_t numberOfElements) { if (numberOfElements > size()) { OPM_THROW(std::runtime_error, fmt::format("Requesting to copy too many elements. View has {} elements, while {} was requested.", size(), numberOfElements)); } OPM_CUDA_SAFE_CALL(cudaMemcpy(data(), dataPointer, numberOfElements * sizeof(T), cudaMemcpyHostToDevice)); } template void CuView::copyToHost(T* dataPointer, size_t numberOfElements) const { assertSameSize(numberOfElements); OPM_CUDA_SAFE_CALL(cudaMemcpy(dataPointer, data(), numberOfElements * sizeof(T), cudaMemcpyDeviceToHost)); } template void CuView::copyFromHost(const std::vector& data) { copyFromHost(data.data(), data.size()); } template void CuView::copyToHost(std::vector& data) const { copyToHost(data.data(), data.size()); } template class CuView; template class CuView; template class CuView; } // namespace Opm::cuistl