Skip to content
Draft
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
55 changes: 55 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,10 @@ macro(opm-simulators_sources_hook)
# cuda warns when constxpr functions are used in kernels.
# since the entire stl is constexpr ..., we enable relaxed flag
set_source_files_properties(
opm/simulators/linalg/gpuistl/GpuBlackoilIntensiveQuantitiesDispatcher.cu
tests/gpuistl/test_blackoilfluidstategpu.cu
tests/gpuistl/test_gpu_ad.cu
tests/gpuistl/test_gpu_ecl_thermal_law_manager.cu
tests/gpuistl/test_gpu_linear_two_phase_material.cu
tests/gpuistl/test_gpuPvt.cu
tests/gpuistl/test_gpuBlackOilFluidSystem.cu
Expand Down Expand Up @@ -735,6 +737,7 @@ macro(opm-simulators_targets_hook)
SOURCES
flow/flow_${OBJ}.cpp
)

simulators_add_target_options(TARGET flow_lib${OBJ})
list(APPEND FLOW_TGTS $<TARGET_OBJECTS:flow_lib${OBJ}>)
list(APPEND FLOWMODELS_PREFIXED flow_${OBJ})
Expand Down Expand Up @@ -775,6 +778,58 @@ macro(opm-simulators_targets_hook)
opmsimulators
)

# Flow GPU executables handled separately to avoid making flow dependent on CUDA/HIP
set(FLOW_GPU_MODELS
gpu_gaswater_thermal
)

if(CONVERT_CUDA_TO_HIP OR CUDA_FOUND)

if(CONVERT_CUDA_TO_HIP)
set(EXTENSION "hip")
else()
set(EXTENSION "cu")
endif()

foreach(OBJ ${FLOW_GPU_MODELS})

opm_add_library(
TARGET
flow_lib${OBJ}
TYPE
OBJECT
SOURCES
flow/flow_${OBJ}.${EXTENSION}
)

simulators_add_target_options(TARGET flow_lib${OBJ})
list(APPEND FLOW_GPU_TGTS $<TARGET_OBJECTS:flow_lib${OBJ}>)
list(APPEND FLOWMODELS_PREFIXED flow_${OBJ})

opm_add_executable(
TARGET
flow_${OBJ}
SOURCES
flow/flow_${OBJ}_main.cpp
$<TARGET_OBJECTS:moduleVersion>
$<TARGET_OBJECTS:flow_lib${OBJ}>
LIBRARIES
opmsimulators
)
endforeach()

opm_add_executable(
TARGET
flow_gpu
SOURCES
flow/flow_gpu_main.cpp
${FLOW_GPU_TGTS}
$<TARGET_OBJECTS:moduleVersion>
LIBRARIES
opmsimulators
)
endif()

if(OPM_ENABLE_PYTHON)
set_target_properties(
flow_libblackoil
Expand Down
46 changes: 46 additions & 0 deletions CMakeLists_files.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -338,9 +338,12 @@ if(CUDA_FOUND OR hip_FOUND)
ADD_CUDA_OR_HIP_FILE(MAIN_SOURCE_FILES opm/simulators/linalg detail/FlexibleSolverWrapper.cpp)
ADD_CUDA_OR_HIP_FILE(MAIN_SOURCE_FILES opm/simulators/linalg FlexibleSolver_gpu_instantiate.cpp)
ADD_CUDA_OR_HIP_FILE(MAIN_SOURCE_FILES opm/simulators/linalg PreconditionerFactory_gpu_instantiate.cpp)
ADD_CUDA_OR_HIP_FILE(MAIN_SOURCE_FILES opm/simulators/linalg GpuBlackoilIntensiveQuantitiesDispatcher.cu)


# HEADERS
ADD_CUDA_OR_HIP_FILE(PUBLIC_HEADER_FILES opm/simulators/linalg GpuBlackoilIntensiveQuantitiesDispatcher.hpp)
ADD_CUDA_OR_HIP_FILE(PUBLIC_HEADER_FILES opm/simulators/linalg GpuFlowGasWaterEnergyTypeTags.hpp)
ADD_CUDA_OR_HIP_FILE(PUBLIC_HEADER_FILES opm/simulators/linalg detail/autotuner.hpp)
ADD_CUDA_OR_HIP_FILE(PUBLIC_HEADER_FILES opm/simulators/linalg detail/coloringAndReorderingUtils.hpp)
ADD_CUDA_OR_HIP_FILE(PUBLIC_HEADER_FILES opm/simulators/linalg detail/gpu_safe_call.hpp)
Expand Down Expand Up @@ -567,6 +570,7 @@ if(CUDA_FOUND OR hip_FOUND)
ADD_CUDA_OR_HIP_FILE(TEST_SOURCE_FILES tests test_safe_conversion.cpp)
ADD_CUDA_OR_HIP_FILE(TEST_SOURCE_FILES tests test_solver_adapter.cpp)
ADD_CUDA_OR_HIP_FILE(TEST_SOURCE_FILES tests test_gpu_ad.cu)
ADD_CUDA_OR_HIP_FILE(TEST_SOURCE_FILES tests test_gpu_ecl_thermal_law_manager.cu)
ADD_CUDA_OR_HIP_FILE(TEST_SOURCE_FILES tests test_gpu_linear_two_phase_material.cu)
ADD_CUDA_OR_HIP_FILE(TEST_SOURCE_FILES tests test_gpuPvt.cu)
ADD_CUDA_OR_HIP_FILE(TEST_SOURCE_FILES tests test_gpu_smart_pointers.cu)
Expand All @@ -584,6 +588,7 @@ if(CUDA_FOUND OR hip_FOUND)
ADD_CUDA_OR_HIP_FILE(TEST_SOURCE_FILES tests test_primary_variables_gpu.cu)
endif()
ADD_CUDA_OR_HIP_FILE(TEST_SOURCE_FILES tests test_MiniMatrix.cu)
ADD_CUDA_OR_HIP_FILE(TEST_SOURCE_FILES tests test_blackoilintensivequantities_gpu.cu)
# Boost < 1.75 + nvcc = trouble in this test
if(Boost_VERSION VERSION_GREATER 1.74)
ADD_CUDA_OR_HIP_FILE(TEST_SOURCE_FILES tests test_MiniVector.cu)
Expand All @@ -592,6 +597,42 @@ if(CUDA_FOUND OR hip_FOUND)
if(MPI_FOUND)
ADD_CUDA_OR_HIP_FILE(TEST_SOURCE_FILES tests test_GpuOwnerOverlapCopy.cpp)
endif()

# for loop providing the flag --expt-relaxed-constexpr to fix some cuda issues with constexpr
if(NOT CONVERT_CUDA_TO_HIP)
set(CU_FILES_NEEDING_RELAXED_CONSTEXPR
tests/gpuistl/test_gpu_ad.cu
tests/gpuistl/test_gpu_linear_two_phase_material.cu
tests/gpuistl/test_gpuPvt.cu
tests/gpuistl/test_gpuBlackOilFluidSystem.cu
tests/gpuistl/test_GpuSparseMatrix.cu
tests/gpuistl/test_GpuSparseTable.cu
tests/gpuistl/test_blackoilfluidstategpu.cu
flow/flow_gpu_gaswater_thermal.cu
)

foreach(file ${CU_FILES_NEEDING_RELAXED_CONSTEXPR})
set_source_files_properties(${file}
PROPERTIES
COMPILE_FLAGS
"--expt-relaxed-constexpr"
)
endforeach()

set(CU_FILES_NEEDING_FPERMISSIVE
tests/gpuistl/test_primary_variables_gpu.cu
)

foreach(file ${CU_FILES_NEEDING_FPERMISSIVE})
# Certain structures in OPM requires the -fpermissive flag to compile with nvcc,
# this enables this for the specific files
set_source_files_properties(${file}
PROPERTIES
COMPILE_FLAGS
"-fpermissive --expt-relaxed-constexpr -Xcompiler=-fpermissive"
)
endforeach()
endif()
endif()

if(USE_GPU_BRIDGE)
Expand Down Expand Up @@ -788,6 +829,9 @@ list (APPEND PUBLIC_HEADER_FILES
opm/models/discretization/common/linearizationtype.hh
opm/models/discretization/common/restrictprolong.hh
opm/models/discretization/common/tpfalinearizer.hh
opm/models/discretization/common/tpfalinearizergpukernels.hh
opm/models/discretization/common/tpfalinearizergpuparams.hh
opm/models/discretization/common/tpfalinearizerstructs.hh
opm/models/discretization/common/tpsalinearizer.hpp
opm/models/discretization/ecfv/ecfvbaseoutputmodule.hh
opm/models/discretization/ecfv/ecfvdiscretization.hh
Expand Down Expand Up @@ -963,6 +1007,7 @@ list (APPEND PUBLIC_HEADER_FILES
opm/simulators/flow/FacePropertiesTPSA_impl.hpp
opm/simulators/flow/FemCpGridCompat.hpp
opm/simulators/flow/FIBlackoilModel.hpp
opm/simulators/flow/SimpleFIBlackOilModel.hpp
opm/simulators/flow/FIPContainer.hpp
opm/simulators/flow/FlowBaseProblemProperties.hpp
opm/simulators/flow/FlowBaseVanguard.hpp
Expand Down Expand Up @@ -1019,6 +1064,7 @@ list (APPEND PUBLIC_HEADER_FILES
opm/simulators/flow/SimulatorSerializer.hpp
opm/simulators/flow/SolutionContainers.hpp
opm/simulators/flow/SubDomain.hpp
opm/simulators/flow/ThermalGasWaterFlowProblem.hpp
opm/simulators/flow/TTagFlowProblemTPFA.hpp
opm/simulators/flow/TTagFlowProblemTPSA.hpp
opm/simulators/flow/TTagFlowProblemGasWater.hpp
Expand Down
79 changes: 79 additions & 0 deletions flow/flow_gpu.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
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/>.
*/
#ifndef FLOW_GPU_HPP
#define FLOW_GPU_HPP

#include <opm/simulators/flow/FlowGasWaterEnergyTypeTag.hpp>
#include <opm/simulators/flow/SimpleFIBlackOilModel.hpp>
/*
This file extracts typetag declarations that must be present in both the .CU and .HIP
executables for Flow to avoid double maintenance.
*/

namespace Opm
{

namespace Properties
{
namespace TTag
{
// FlowGasWaterEnergyProblemGPU is declared in FlowGasWaterEnergyTypeTag.hpp
// (InheritsFrom = FlowGasWaterEnergyProblem). The template below maps it
// to FlowGasWaterEnergyProblemGPUTrue<Storage> for GPU-storage variants.

template <template <class> class Storage>
struct FlowGasWaterEnergyProblemGPUTrue {
using InheritsFrom = std::tuple<FlowGasWaterEnergyProblemGPU>;
};

template <template <class> class Storage>
struct to_gpu_type<FlowGasWaterEnergyProblemGPU, Storage> {
using type = FlowGasWaterEnergyProblemGPUTrue<Storage>;
};
} // namespace TTag

template <class TypeTag>
struct RunAssemblyOnGpu<TypeTag, TTag::FlowGasWaterEnergyProblemGPU> {
static constexpr bool value = true;
};

template <class TypeTag>
struct Scalar<TypeTag, TTag::FlowGasWaterEnergyProblemGPU> {
using type = double;
};

template <class TypeTag>
struct GpuFIBlackOilModel<TypeTag, TTag::FlowGasWaterEnergyProblemGPU> {
using type = SimpleFIBlackOilModel<TypeTag>;
};

template <class TypeTag, template <class> class Storage>
struct FluidSystem<TypeTag, TTag::FlowGasWaterEnergyProblemGPUTrue<Storage>> {
using type = Opm::
BlackOilFluidSystemNonStatic<double, Opm::BlackOilDefaultFluidSystemIndices, Storage>;
};
} // namespace Properties

//! \brief Main function used in flow binary.
int flowGasWaterEnergyMainGPU(int argc, char** argv, bool outputCout, bool outputFiles);

//! \brief Main function used in flow_gaswater binary.
int flowGasWaterEnergyMainGPUStandalone(int argc, char** argv);

} // namespace Opm

#endif // FLOW_GPU_HPP
70 changes: 70 additions & 0 deletions flow/flow_gpu_gaswater_thermal.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
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/>.
*/
#include "config.h"

#undef HAVE_DUNE_ALUGRID // Disable ALUGRID if it is available as nvcc struggles with it
#undef HAVE_DUNE_FEM // Disable DUNE-FEM if it is available as nvcc struggles with it

// For now flow_gpu is developed to support SPE11 simulations, that is 2-phase gas-water flow with
// thermal effects The goal is to support both property-evaluation and matrix assembly on the GPU,
// in addition to the linear solver which already works on the GPU. The CPU would still have to
// manage well contributions, although there are no wells in SPE11, only source-terms.

#include <flow/flow_gpu.hpp>

#include <opm/common/utility/gpuDecorators.hpp>

#include <opm/material/common/ResetLocale.hpp>
#include <opm/material/thermal/EnergyModuleType.hpp>
#include <opm/models/blackoil/blackoiltwophaseindices.hh>

#include <opm/grid/CpGrid.hpp>
#include <opm/simulators/flow/FlowGasWaterEnergyTypeTag.hpp>
#include <opm/simulators/flow/Main.hpp>
#include <opm/simulators/flow/SimpleFIBlackOilModel.hpp>
#include <opm/simulators/flow/SimulatorFullyImplicitBlackoil.hpp>

#include <opm/models/blackoil/blackoillocalresidualtpfa.hh>
#include <opm/models/discretization/common/tpfalinearizer.hh>

namespace Opm
{

int
flowGasWaterEnergyMainGPU(int argc, char** argv, bool outputCout, bool outputFiles)
{
// we always want to use the default locale, and thus spare us the trouble
// with incorrect locale settings.
resetLocale();

FlowMain<Properties::TTag::FlowGasWaterEnergyProblemGPU> mainfunc {
argc, argv, outputCout, outputFiles};
return mainfunc.execute();
}

int
flowGasWaterEnergyMainGPUStandalone(int argc, char** argv)
{
using TypeTag = Properties::TTag::FlowGasWaterEnergyProblemGPU;
auto mainObject = std::make_unique<::Opm::Main>(argc, argv);
auto ret = mainObject->runStatic<TypeTag>();
// Destruct mainObject as the destructor calls MPI_Finalize!
mainObject.reset();
return ret;
}

} // namespace Opm
67 changes: 67 additions & 0 deletions flow/flow_gpu_gaswater_thermal.hip
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
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/>.
*/
#include "config.h"

// For now flow_gpu is developed to support SPE11 simulations, that is 2-phase gas-water flow with
// thermal effects The goal is to support both property-evaluation and matrix assembly on the GPU,
// in addition to the linear solver which already works on the GPU. The CPU would still have to
// manage well contributions, although there are no wells in SPE11, only source-terms.

#include <flow/flow_gpu.hpp>

#include <opm/common/utility/gpuDecorators.hpp>

#include <opm/material/common/ResetLocale.hpp>
#include <opm/material/thermal/EnergyModuleType.hpp>

#include <opm/grid/CpGrid.hpp>
#include <opm/simulators/flow/FlowGasWaterEnergyTypeTag.hpp>
#include <opm/simulators/flow/Main.hpp>
#include <opm/simulators/flow/SimpleFIBlackOilModel.hpp>
#include <opm/simulators/flow/SimulatorFullyImplicitBlackoil.hpp>

#include <opm/models/blackoil/blackoillocalresidualtpfa.hh>
#include <opm/models/blackoil/blackoiltwophaseindices.hh>
#include <opm/models/discretization/common/tpfalinearizer.hh>

namespace Opm
{

int
flowGasWaterEnergyMainGPU(int argc, char** argv, bool outputCout, bool outputFiles)
{
// we always want to use the default locale, and thus spare us the trouble
// with incorrect locale settings.
resetLocale();

FlowMain<Properties::TTag::FlowGasWaterEnergyProblemGPU> mainfunc {
argc, argv, outputCout, outputFiles};
return mainfunc.execute();
}

int
flowGasWaterEnergyMainGPUStandalone(int argc, char** argv)
{
using TypeTag = Properties::TTag::FlowGasWaterEnergyProblemGPU;
auto mainObject = std::make_unique<::Opm::Main>(argc, argv);
auto ret = mainObject->runStatic<TypeTag>();
// Destruct mainObject as the destructor calls MPI_Finalize!
mainObject.reset();
return ret;
}

} // namespace Opm
Loading