Merge pull request #5253 from multitalentloes/script_test

Add HIP support
This commit is contained in:
Arne Morten Kvarving
2024-05-07 08:02:53 +02:00
committed by GitHub
13 changed files with 239 additions and 108 deletions
@@ -38,8 +38,12 @@
#include <dune/istl/paamg/pinfo.hh>
#if HAVE_CUDA
#if USE_HIP
#include <opm/simulators/linalg/hipistl/SolverAdapter.hpp>
#else
#include <opm/simulators/linalg/cuistl/SolverAdapter.hpp>
#endif
#endif
namespace Dune
{
@@ -0,0 +1,39 @@
/*
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 <http://www.gnu.org/licenses/>.
*/
// This file keeps the factory a bit more tidy.
// When adding a new GPU preconditioner make sure to add it
// both with the normal cuistl path, and the hipistl path
#if HAVE_CUDA
#if USE_HIP
#include <opm/simulators/linalg/hipistl/CuBlockPreconditioner.hpp>
#include <opm/simulators/linalg/hipistl/CuDILU.hpp>
#include <opm/simulators/linalg/hipistl/CuJac.hpp>
#include <opm/simulators/linalg/hipistl/CuSeqILU0.hpp>
#include <opm/simulators/linalg/hipistl/PreconditionerAdapter.hpp>
#include <opm/simulators/linalg/hipistl/PreconditionerConvertFieldTypeAdapter.hpp>
#else
#include <opm/simulators/linalg/cuistl/CuBlockPreconditioner.hpp>
#include <opm/simulators/linalg/cuistl/CuDILU.hpp>
#include <opm/simulators/linalg/cuistl/CuJac.hpp>
#include <opm/simulators/linalg/cuistl/CuSeqILU0.hpp>
#include <opm/simulators/linalg/cuistl/PreconditionerAdapter.hpp>
#include <opm/simulators/linalg/cuistl/PreconditionerConvertFieldTypeAdapter.hpp>
#endif
#endif
@@ -45,15 +45,9 @@
#include <dune/istl/preconditioners.hh>
#include <config.h>
#if HAVE_CUDA
#include <opm/simulators/linalg/cuistl/CuBlockPreconditioner.hpp>
#include <opm/simulators/linalg/cuistl/CuDILU.hpp>
#include <opm/simulators/linalg/cuistl/CuJac.hpp>
#include <opm/simulators/linalg/cuistl/CuSeqILU0.hpp>
#include <opm/simulators/linalg/cuistl/PreconditionerAdapter.hpp>
#include <opm/simulators/linalg/cuistl/PreconditionerConvertFieldTypeAdapter.hpp>
#endif
// Include all cuistl/GPU preconditioners inside of this headerfile
#include <opm/simulators/linalg/PreconditionerFactoryGPUIncludeWrapper.hpp>
namespace Opm
@@ -100,8 +100,6 @@ cudaSafeCall(cudaError_t error,
* @param functionName name of the function the error occured in (typically __func__)
* @param lineNumber the line number the error occured in (typically __LINE__)
*
* @return the error sent in (for convenience).
*
* Example usage:
* @code{.cpp}
* #include <opm/simulators/linalg/cuistl/detail/cuda_safe_call.hpp>
@@ -119,7 +117,7 @@ cudaSafeCall(cudaError_t error,
*
* @todo Refactor to use std::source_location once we shift to C++20
*/
inline cudaError_t
inline void
cudaWarnIfError(cudaError_t error,
const std::string_view& expression,
const std::string_view& filename,
@@ -129,8 +127,6 @@ cudaWarnIfError(cudaError_t error,
if (error != cudaSuccess) {
OpmLog::warning(getCudaErrorMessage(error, expression, filename, functionName, lineNumber));
}
return error;
}
} // namespace Opm::cuistl::detail
@@ -20,6 +20,7 @@
#include <opm/simulators/linalg/cuistl/detail/vector_operations.hpp>
#include <opm/simulators/linalg/cuistl/detail/cublas_safe_call.hpp>
#include <opm/simulators/linalg/cuistl/detail/cublas_wrapper.hpp>
#include <opm/simulators/linalg/cuistl/detail/cuda_safe_call.hpp>
#include <opm/simulators/linalg/cuistl/CuVector.hpp>
#include <stdexcept>
namespace Opm::cuistl::detail
@@ -160,7 +161,7 @@ template <class T>
void prepareSendBuf(const T* deviceA, T* buffer, size_t numberOfElements, const int* indices)
{
prepareSendBufKernel<<<getBlocks(numberOfElements), getThreads(numberOfElements)>>>(deviceA, buffer, numberOfElements, indices);
cudaDeviceSynchronize(); // The buffers are prepared for MPI. Wait for them to finish.
OPM_CUDA_SAFE_CALL(cudaDeviceSynchronize()); // The buffers are prepared for MPI. Wait for them to finish.
}
template void prepareSendBuf(const double* deviceA, double* buffer, size_t numberOfElements, const int* indices);
template void prepareSendBuf(const float* deviceA, float* buffer, size_t numberOfElements, const int* indices);
+1 -1
View File
@@ -28,7 +28,7 @@ setDevice(int mpiRank, [[maybe_unused]] int numberOfMpiRanks)
{
int deviceCount = -1;
cudaGetDeviceCount(&deviceCount);
[[maybe_unused]] auto cuError = cudaGetDeviceCount(&deviceCount);
if (deviceCount <= 0) {
// If they have CUDA enabled (ie. using a component that needs CUDA, eg. cubicgstab or CUILU0), this will fail