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
19 changes: 19 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,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(
tests/gpuistl/test_blackoilintensivequantities_gpu.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 @@ -422,6 +424,18 @@ macro(opm-simulators_config_hook)
target_compile_definitions(opmsimulators PUBLIC HAVE_CUDA=1)
endif()

# The BlackOil intensive-quantities GPU dispatcher requires either HIP or
# CUDA >= 13.1; the corresponding .cu source is only added to the build
# under the same condition (see CMakeLists_files.cmake). Expose a public
# macro so that callers (e.g. FIBlackoilModel) can guard their use of the
# dispatcher accordingly.
if(hip_FOUND OR CUDA_VERSION VERSION_GREATER_EQUAL 13.1)
target_compile_definitions(opmsimulators
PUBLIC
OPM_HAVE_GPU_BLACKOIL_INTENSIVE_QUANTITIES_DISPATCHER=1
)
endif()

if(USE_GPU_BRIDGE)
target_compile_definitions(opmsimulators PUBLIC COMPILE_GPU_BRIDGE=1)
endif()
Expand Down Expand Up @@ -479,6 +493,7 @@ macro(opm-simulators_tests_hook)
cuVector_operations
deviceBlockOperations
gpu_ad
gpu_ecl_thermal_law_manager
gpu_linear_two_phase_material
gpu_resources
gpu_safe_call
Expand All @@ -504,6 +519,7 @@ macro(opm-simulators_tests_hook)
primary_variables_gpu
solver_adapter
throw_macros_on_gpu
blackoilintensivequantities_gpu
)
if(TEST ${test})
set_tests_properties(${test}
Expand Down Expand Up @@ -670,6 +686,9 @@ macro(opm-simulators_targets_hook)
target_sources(test_RestartSerialization PRIVATE $<TARGET_OBJECTS:moduleVersion>)
target_sources(test_glift1 PRIVATE $<TARGET_OBJECTS:moduleVersion>)
target_sources(test_tpsa_localresidual PRIVATE $<TARGET_OBJECTS:moduleVersion>)
if (TARGET test_blackoilintensivequantities_gpu)
target_sources(test_blackoilintensivequantities_gpu PRIVATE $<TARGET_OBJECTS:moduleVersion>)
endif()
if(MPI_FOUND)
target_sources(test_chopstep PRIVATE $<TARGET_OBJECTS:moduleVersion>)
endif()
Expand Down
18 changes: 18 additions & 0 deletions CMakeLists_files.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,18 @@ 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)
if(hip_FOUND OR CUDA_VERSION VERSION_GREATER_EQUAL 13.1)
ADD_CUDA_OR_HIP_FILE(MAIN_SOURCE_FILES opm/simulators/linalg GpuBlackoilIntensiveQuantitiesDispatcher.cu)
endif()


# HEADERS
list(APPEND PUBLIC_HEADER_FILES opm/models/discretization/common/fvbaseelementcontextgpu.hh)
list(APPEND PUBLIC_HEADER_FILES opm/simulators/flow/GpuEclMaterialLawManager.hpp)
list(APPEND PUBLIC_HEADER_FILES opm/simulators/flow/GpuEclThermalLawManager.hpp)
list(APPEND PUBLIC_HEADER_FILES opm/simulators/flow/GpuFlowProblem.hpp)
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 @@ -570,6 +579,9 @@ 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)
if(hip_FOUND OR CUDA_VERSION VERSION_GREATER_EQUAL 13.1)
ADD_CUDA_OR_HIP_FILE(TEST_SOURCE_FILES tests test_gpu_ecl_thermal_law_manager.cu)
endif()
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 @@ -587,6 +599,10 @@ 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)
if(hip_FOUND OR CUDA_VERSION VERSION_GREATER_EQUAL 13.1)
ADD_CUDA_OR_HIP_FILE(TEST_SOURCE_FILES tests test_blackoilintensivequantities_gpu.cu)
endif()

# 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 Down Expand Up @@ -707,6 +723,7 @@ list (APPEND TEST_DATA_FILES
tests/data/test_stokes2c.dgf
tests/data/test_stokes2cni.dgf
tests/data/waterair.dgf
tests/very_simple_deck.DATA
)


Expand Down Expand Up @@ -969,6 +986,7 @@ list (APPEND PUBLIC_HEADER_FILES
opm/simulators/flow/FIPContainer.hpp
opm/simulators/flow/FlowBaseProblemProperties.hpp
opm/simulators/flow/FlowBaseVanguard.hpp
opm/simulators/flow/FlowGasWaterEnergyTypeTag.hpp
opm/simulators/flow/FlowGenericProblem.hpp
opm/simulators/flow/FlowGenericProblem_impl.hpp
opm/simulators/flow/FlowGenericVanguard.hpp
Expand Down
86 changes: 44 additions & 42 deletions flowexperimental/BlackOilEnergyIntensiveQuantitiesGlobalIndex.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,20 @@ class BlackOilEnergyIntensiveQuantitiesGlobalIndex<TypeTag, EnergyModules::Fully
static constexpr unsigned numPhases = FluidSystem::numPhases;

public:
void updateTemperature_([[maybe_unused]] const Problem& problem,
const PrimaryVariables& priVars,
[[maybe_unused]] unsigned globalSpaceIndex,
unsigned timeIdx)
OPM_HOST_DEVICE void updateTemperature_([[maybe_unused]] const Problem& problem,
const PrimaryVariables& priVars,
[[maybe_unused]] unsigned globalSpaceIndex,
unsigned timeIdx)
{
auto& fs = Parent::asImp_().fluidState_;
// set temperature
fs.setTemperature(priVars.makeEvaluation(temperatureIdx, timeIdx));
}
void updateEnergyQuantities_(const Problem& problem,
[[maybe_unused]] const PrimaryVariables& priVars,
unsigned globalSpaceIndex,
unsigned timeIdx,
const ParamCache& paramCache)
OPM_HOST_DEVICE void updateEnergyQuantities_(const Problem& problem,
[[maybe_unused]] const PrimaryVariables& priVars,
unsigned globalSpaceIndex,
unsigned timeIdx,
const ParamCache& paramCache)
{
auto& fs = Parent::asImp_().fluidState_;

Expand Down Expand Up @@ -120,25 +120,27 @@ class BlackOilEnergyIntensiveQuantitiesGlobalIndex<TypeTag, EnergyModules::Seque
static constexpr unsigned numPhases = FluidSystem::numPhases;
public:

void updateTemperature_([[maybe_unused]] const Problem& problem,
[[maybe_unused]] const PrimaryVariables& priVars,
[[maybe_unused]] unsigned globalSpaceIndex,
[[maybe_unused]] unsigned timeIdx)
OPM_HOST_DEVICE void updateTemperature_([[maybe_unused]] const Problem& problem,
[[maybe_unused]] const PrimaryVariables& priVars,
[[maybe_unused]] unsigned globalSpaceIndex,
[[maybe_unused]] unsigned timeIdx)
{
throw std::logic_error("updateTemperature not implemented "
"SequentialImplicitThermal can not be used with"
"global intensive quantites yet.");
OPM_THROW(std::logic_error,
"updateTemperature not implemented "
"SequentialImplicitThermal can not be used with"
"global intensive quantites yet.");
}

void updateEnergyQuantities_([[maybe_unused]] const Problem& problem,
[[maybe_unused]] const PrimaryVariables& priVars,
[[maybe_unused]] unsigned globalSpaceIndex,
[[maybe_unused]] unsigned timeIdx,
[[maybe_unused]] const ParamCache& paramCache)
OPM_HOST_DEVICE void updateEnergyQuantities_([[maybe_unused]] const Problem& problem,
[[maybe_unused]] const PrimaryVariables& priVars,
[[maybe_unused]] unsigned globalSpaceIndex,
[[maybe_unused]] unsigned timeIdx,
[[maybe_unused]] const ParamCache& paramCache)
{
throw std::logic_error("updateEnergyQuantities_ not implemented "
"SequentialImplicitThermal can not be used with"
"global intensive quantites yet.");
OPM_THROW(std::logic_error,
"updateEnergyQuantities_ not implemented "
"SequentialImplicitThermal can not be used with"
"global intensive quantites yet.");
}

};
Expand All @@ -155,21 +157,21 @@ class BlackOilEnergyIntensiveQuantitiesGlobalIndex<TypeTag, EnergyModules::Const
using Scalar = GetPropType<TypeTag, Properties::Scalar>;

public:
void updateTemperature_([[maybe_unused]] const Problem& problem,
[[maybe_unused]] const PrimaryVariables& priVars,
[[maybe_unused]] unsigned globalSpaceIdx,
[[maybe_unused]] unsigned timeIdx)
OPM_HOST_DEVICE void updateTemperature_([[maybe_unused]] const Problem& problem,
[[maybe_unused]] const PrimaryVariables& priVars,
[[maybe_unused]] unsigned globalSpaceIdx,
[[maybe_unused]] unsigned timeIdx)
{
auto& fs = this->asImp_().fluidState_;
Scalar T = problem.temperature(globalSpaceIdx, timeIdx);
fs.setTemperature(T);
}

void updateEnergyQuantities_([[maybe_unused]] const Problem& problem,
[[maybe_unused]] const PrimaryVariables& priVars,
[[maybe_unused]] unsigned globalSpaceIdx,
[[maybe_unused]] unsigned timeIdx,
const typename FluidSystem::template ParameterCache<Evaluation>&)
OPM_HOST_DEVICE void updateEnergyQuantities_([[maybe_unused]] const Problem& problem,
[[maybe_unused]] const PrimaryVariables& priVars,
[[maybe_unused]] unsigned globalSpaceIdx,
[[maybe_unused]] unsigned timeIdx,
const typename FluidSystem::template ParameterCache<Evaluation>&)
{ }
};

Expand All @@ -185,17 +187,17 @@ class BlackOilEnergyIntensiveQuantitiesGlobalIndex<TypeTag, EnergyModules::NoTem
using Scalar = GetPropType<TypeTag, Properties::Scalar>;

public:
void updateTemperature_([[maybe_unused]] const Problem& problem,
[[maybe_unused]] const PrimaryVariables& priVars,
[[maybe_unused]] unsigned globalSpaceIdx,
[[maybe_unused]] unsigned timeIdx)
OPM_HOST_DEVICE void updateTemperature_([[maybe_unused]] const Problem& problem,
[[maybe_unused]] const PrimaryVariables& priVars,
[[maybe_unused]] unsigned globalSpaceIdx,
[[maybe_unused]] unsigned timeIdx)
{ }

void updateEnergyQuantities_([[maybe_unused]] const Problem& problem,
[[maybe_unused]] const PrimaryVariables& priVars,
[[maybe_unused]] unsigned globalSpaceIdx,
[[maybe_unused]] unsigned timeIdx,
const typename FluidSystem::template ParameterCache<Evaluation>&)
OPM_HOST_DEVICE void updateEnergyQuantities_([[maybe_unused]] const Problem& problem,
[[maybe_unused]] const PrimaryVariables& priVars,
[[maybe_unused]] unsigned globalSpaceIdx,
[[maybe_unused]] unsigned timeIdx,
const typename FluidSystem::template ParameterCache<Evaluation>&)
{ }
};

Expand Down
60 changes: 30 additions & 30 deletions opm/models/blackoil/blackoilbrinemodules.hh
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public:
static void registerParameters()
{}

static bool primaryVarApplies(unsigned pvIdx)
static OPM_HOST_DEVICE bool primaryVarApplies(unsigned pvIdx)
{
if constexpr (enableBrine) {
return pvIdx == saltConcentrationIdx;
Expand Down Expand Up @@ -135,7 +135,7 @@ public:
return static_cast<Scalar>(1.0);
}

static bool eqApplies(unsigned eqIdx)
static OPM_HOST_DEVICE bool eqApplies(unsigned eqIdx)
{
if constexpr (enableBrine) {
return eqIdx == contiBrineEqIdx;
Expand Down Expand Up @@ -405,18 +405,18 @@ public:
* primary variables
*
*/
void updateSaltConcentration_(const ElementContext& elemCtx,
unsigned dofIdx,
unsigned timeIdx)
OPM_HOST_DEVICE void updateSaltConcentration_(const ElementContext& elemCtx,
unsigned dofIdx,
unsigned timeIdx)
{
const PrimaryVariables& priVars = elemCtx.primaryVars(dofIdx, timeIdx);
const LinearizationType lintype = elemCtx.linearizationType();
updateSaltConcentration_(priVars, timeIdx, lintype);
}

void updateSaltConcentration_(const PrimaryVariables& priVars,
const unsigned timeIdx,
const LinearizationType lintype)
OPM_HOST_DEVICE void updateSaltConcentration_(const PrimaryVariables& priVars,
const unsigned timeIdx,
const LinearizationType lintype)
{
const unsigned pvtnumRegionIdx = priVars.pvtRegionIndex();
auto& fs = asImp_().fluidState_;
Expand All @@ -442,9 +442,9 @@ public:
}
}

void saltPropertiesUpdate_([[maybe_unused]] const ElementContext& elemCtx,
[[maybe_unused]] unsigned dofIdx,
[[maybe_unused]] unsigned timeIdx)
OPM_HOST_DEVICE void saltPropertiesUpdate_([[maybe_unused]] const ElementContext& elemCtx,
[[maybe_unused]] unsigned dofIdx,
[[maybe_unused]] unsigned timeIdx)
{
if constexpr (enableSaltPrecipitation) {
const Evaluation porosityFactor = min(1.0 - asImp_().fluidState_.saltSaturation(), 1.0); //phi/phi_0
Expand All @@ -455,20 +455,20 @@ public:
}
}

const Evaluation& brineRefDensity() const
OPM_HOST_DEVICE const Evaluation& brineRefDensity() const
{ return refDensity_; }

Scalar saltSolubility() const
OPM_HOST_DEVICE Scalar saltSolubility() const
{ return saltSolubility_; }

Scalar saltDensity() const
OPM_HOST_DEVICE Scalar saltDensity() const
{ return saltDensity_; }

const Evaluation& permFactor() const
OPM_HOST_DEVICE const Evaluation& permFactor() const
{ return permFactor_; }

protected:
Implementation& asImp_()
OPM_HOST_DEVICE Implementation& asImp_()
{ return *static_cast<Implementation*>(this); }

Evaluation saltConcentration_;
Expand All @@ -487,27 +487,27 @@ class BlackOilBrineIntensiveQuantities<TypeTag, false>
using Scalar = GetPropType<TypeTag, Properties::Scalar>;

public:
void updateSaltConcentration_(const ElementContext&,
unsigned,
unsigned)
OPM_HOST_DEVICE void updateSaltConcentration_(const ElementContext&,
unsigned,
unsigned)
{}

void saltPropertiesUpdate_(const ElementContext&,
unsigned,
unsigned)
OPM_HOST_DEVICE void saltPropertiesUpdate_(const ElementContext&,
unsigned,
unsigned)
{}

const Evaluation& brineRefDensity() const
{ throw std::runtime_error("brineRefDensity() called but brine are disabled"); }
OPM_HOST_DEVICE const Evaluation& brineRefDensity() const
{ OPM_THROW(std::runtime_error, "brineRefDensity() called but brine are disabled"); }

const Scalar saltSolubility() const
{ throw std::logic_error("saltSolubility() called but salt precipitation is disabled"); }
OPM_HOST_DEVICE const Scalar saltSolubility() const
{ OPM_THROW(std::logic_error, "saltSolubility() called but salt precipitation is disabled"); }

const Scalar saltDensity() const
{ throw std::logic_error("saltDensity() called but salt precipitation is disabled"); }
OPM_HOST_DEVICE const Scalar saltDensity() const
{ OPM_THROW(std::logic_error, "saltDensity() called but salt precipitation is disabled"); }

const Evaluation& permFactor() const
{ throw std::logic_error("permFactor() called but salt precipitation is disabled"); }
OPM_HOST_DEVICE const Evaluation& permFactor() const
{ OPM_THROW(std::logic_error, "permFactor() called but salt precipitation is disabled"); }
};

} // namespace Opm
Expand Down
Loading