Skip to content
Open
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
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ macro(opm-simulators_sources_hook)
set_source_files_properties(
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 @@ -490,6 +491,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 Down
9 changes: 9 additions & 0 deletions CMakeLists_files.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,10 @@ if(CUDA_FOUND OR hip_FOUND)


# 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 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 +574,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 Down Expand Up @@ -707,6 +714,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 +977,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
309 changes: 309 additions & 0 deletions opm/models/discretization/common/fvbaseelementcontextgpu.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,309 @@
// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
// vi: set et ts=4 sw=4 sts=4:
/*
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 2 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/>.

Consult the COPYING file in the top-level source directory of this
module for the precise wording of the license and the list of
copyright holders.
*/
/*!
* \file
*
* \brief GPU-compatible stub of FvBaseElementContext.
*
* All methods are annotated with OPM_HOST_DEVICE and return dummy/default
* values. This class is intended as a placeholder so that GPU kernels that
* receive an element context can compile; it does not implement any real
* behaviour.
*
* The heavy Dune/grid infrastructure present in FvBaseElementContext is
* intentionally absent here because those types are not usable inside a
* CUDA/HIP kernel.
*/
#ifndef OPM_FV_BASE_ELEMENT_CONTEXT_GPU_HH
#define OPM_FV_BASE_ELEMENT_CONTEXT_GPU_HH

#include <opm/common/utility/gpuDecorators.hpp>
#include <opm/models/discretization/common/fvbaseproperties.hh>
#include <opm/models/discretization/common/linearizationtype.hh>

#include <cstddef>

namespace Opm
{

/*!
* \ingroup FiniteVolumeDiscretizations
*
* \brief GPU-compatible stub mirroring the public interface of FvBaseElementContext.
*
* Uses the same TypeTag-based template parameter as FvBaseElementContext; all
* concrete types are extracted via GetPropType at compile time.
*
* \tparam TypeTag The type tag from which Scalar, PrimaryVariables, etc. are derived.
*/
template <class TypeTag>
class FvBaseElementContextGpu
{
public:
using Scalar = GetPropType<TypeTag, Properties::Scalar>;
using PrimaryVariables = GetPropType<TypeTag, Properties::PrimaryVariables>;
using IntensiveQuantities = GetPropType<TypeTag, Properties::IntensiveQuantities>;
using ExtensiveQuantities = GetPropType<TypeTag, Properties::ExtensiveQuantities>;
using Problem = GetPropType<TypeTag, Properties::Problem>;
using Model = GetPropType<TypeTag, Properties::Model>;
using GradientCalculator = GetPropType<TypeTag, Properties::GradientCalculator>;

// -----------------------------------------------------------------------
// Construction / assignment
// -----------------------------------------------------------------------

OPM_HOST_DEVICE FvBaseElementContextGpu() = default;
OPM_HOST_DEVICE ~FvBaseElementContextGpu() = default;
OPM_HOST_DEVICE FvBaseElementContextGpu(const FvBaseElementContextGpu&) = default;
OPM_HOST_DEVICE FvBaseElementContextGpu(FvBaseElementContextGpu&&) noexcept = default;
OPM_HOST_DEVICE FvBaseElementContextGpu& operator=(const FvBaseElementContextGpu&) = default;
OPM_HOST_DEVICE FvBaseElementContextGpu& operator=(FvBaseElementContextGpu&&) noexcept
= default;

// -----------------------------------------------------------------------
// Stencil / element update stubs
// -----------------------------------------------------------------------

OPM_HOST_DEVICE void updateAll()
{
}
OPM_HOST_DEVICE void updateStencil()
{
}
OPM_HOST_DEVICE void updatePrimaryStencil()
{
}
OPM_HOST_DEVICE void updateStencilTopology()
{
}
OPM_HOST_DEVICE void updateAllIntensiveQuantities()
{
}
OPM_HOST_DEVICE void updateIntensiveQuantities(unsigned /*timeIdx*/)
{
}
OPM_HOST_DEVICE void updatePrimaryIntensiveQuantities(unsigned /*timeIdx*/)
{
}
OPM_HOST_DEVICE void updateIntensiveQuantities(const PrimaryVariables& /*priVars*/,
unsigned /*dofIdx*/,
unsigned /*timeIdx*/)
{
}
OPM_HOST_DEVICE void updateAllExtensiveQuantities()
{
}
OPM_HOST_DEVICE void updateExtensiveQuantities(unsigned /*timeIdx*/)
{
}

// -----------------------------------------------------------------------
// Focus DOF
// -----------------------------------------------------------------------

OPM_HOST_DEVICE void setFocusDofIndex(unsigned dofIdx)
{
focusDofIdx_ = static_cast<int>(dofIdx);
}
OPM_HOST_DEVICE unsigned focusDofIndex() const
{
return focusDofIdx_;
}

// -----------------------------------------------------------------------
// Linearization type
// -----------------------------------------------------------------------

OPM_HOST_DEVICE LinearizationType linearizationType() const
{
return LinearizationType {};
}

// -----------------------------------------------------------------------
// Problem / model accessors — return references to dummy stored objects
// -----------------------------------------------------------------------

OPM_HOST_DEVICE const Problem& problem() const
{
return problem_;
}
OPM_HOST_DEVICE const Model& model() const
{
return model_;
}

// -----------------------------------------------------------------------
// DOF / face counts
// -----------------------------------------------------------------------

OPM_HOST_DEVICE std::size_t numDof(unsigned /*timeIdx*/) const
{
return 0;
}
OPM_HOST_DEVICE std::size_t numPrimaryDof(unsigned /*timeIdx*/) const
{
return 0;
}
OPM_HOST_DEVICE std::size_t numInteriorFaces(unsigned /*timeIdx*/) const
{
return 0;
}
OPM_HOST_DEVICE std::size_t numBoundaryFaces(unsigned /*timeIdx*/) const
{
return 0;
}

// -----------------------------------------------------------------------
// Global space index / volume
// -----------------------------------------------------------------------

OPM_HOST_DEVICE unsigned globalSpaceIndex(unsigned /*dofIdx*/, unsigned /*timeIdx*/) const
{
return 0;
}

OPM_HOST_DEVICE Scalar dofVolume(unsigned /*dofIdx*/, unsigned /*timeIdx*/) const
{
return Scalar {0};
}

OPM_HOST_DEVICE Scalar dofTotalVolume(unsigned /*dofIdx*/, unsigned /*timeIdx*/) const
{
return Scalar {0};
}

// -----------------------------------------------------------------------
// Boundary
// -----------------------------------------------------------------------

OPM_HOST_DEVICE bool onBoundary() const
{
return false;
}

// -----------------------------------------------------------------------
// Intensive quantities
// -----------------------------------------------------------------------

OPM_HOST_DEVICE const IntensiveQuantities& intensiveQuantities(unsigned /*dofIdx*/,
unsigned /*timeIdx*/) const
{
return intensiveQuantitiesStashed_;
}

OPM_HOST_DEVICE IntensiveQuantities& intensiveQuantities(unsigned /*dofIdx*/,
unsigned /*timeIdx*/)
{
return intensiveQuantitiesStashed_;
}

OPM_HOST_DEVICE const IntensiveQuantities* thermodynamicHint(unsigned /*dofIdx*/,
unsigned /*timeIdx*/) const
{
return nullptr;
}

// -----------------------------------------------------------------------
// Primary variables
// -----------------------------------------------------------------------

OPM_HOST_DEVICE const PrimaryVariables& primaryVars(unsigned /*dofIdx*/,
unsigned /*timeIdx*/) const
{
return priVarsStashed_;
}

// -----------------------------------------------------------------------
// Stash / restore
// -----------------------------------------------------------------------

OPM_HOST_DEVICE bool haveStashedIntensiveQuantities() const
{
return stashedDofIdx_ != -1;
}

OPM_HOST_DEVICE int stashedDofIdx() const
{
return stashedDofIdx_;
}

OPM_HOST_DEVICE void stashIntensiveQuantities(unsigned dofIdx)
{
stashedDofIdx_ = static_cast<int>(dofIdx);
}

OPM_HOST_DEVICE void restoreIntensiveQuantities(unsigned /*dofIdx*/)
{
stashedDofIdx_ = -1;
}

// -----------------------------------------------------------------------
// Gradient calculator
// -----------------------------------------------------------------------

OPM_HOST_DEVICE const GradientCalculator& gradientCalculator() const
{
return gradientCalculator_;
}

// -----------------------------------------------------------------------
// Extensive quantities
// -----------------------------------------------------------------------

OPM_HOST_DEVICE const ExtensiveQuantities& extensiveQuantities(unsigned /*fluxIdx*/,
unsigned /*timeIdx*/) const
{
return extensiveQuantitiesStashed_;
}

// -----------------------------------------------------------------------
// Storage cache flag
// -----------------------------------------------------------------------

OPM_HOST_DEVICE bool enableStorageCache() const
{
return enableStorageCache_;
}
OPM_HOST_DEVICE void setEnableStorageCache(bool yesno)
{
enableStorageCache_ = yesno;
}

private:
// Dummy stored objects returned by reference accessors.
// On device these are default-constructed and carry no meaningful data.
Problem problem_ {};
Model model_ {};
GradientCalculator gradientCalculator_ {};
IntensiveQuantities intensiveQuantitiesStashed_ {};
ExtensiveQuantities extensiveQuantitiesStashed_ {};
PrimaryVariables priVarsStashed_ {};

int stashedDofIdx_ {-1};
int focusDofIdx_ {-1};
bool enableStorageCache_ {false};
};

} // namespace Opm

#endif // OPM_FV_BASE_ELEMENT_CONTEXT_GPU_HH
Loading