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
3 changes: 2 additions & 1 deletion Common/include/linear_algebra/CMatrixVectorProduct.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class CSysMatrixVectorProduct final : public CMatrixVectorProduct<ScalarType> {
const CSysMatrix<ScalarType>& matrix; /*!< \brief pointer to matrix that defines the product. */
CGeometry* geometry; /*!< \brief geometry associated with the matrix. */
const CConfig* config; /*!< \brief config of the problem. */
VecExpr::CDeviceExpressionContext device_context;
mutable bool matrix_uploaded = false; /*!< \brief Upload the matrix lazily on the first actual GPU matvec. */

public:
Expand All @@ -83,7 +84,7 @@ class CSysMatrixVectorProduct final : public CMatrixVectorProduct<ScalarType> {
*/
inline CSysMatrixVectorProduct(const CSysMatrix<ScalarType>& matrix_ref, CGeometry* geometry_ref,
const CConfig* config_ref)
: matrix(matrix_ref), geometry(geometry_ref), config(config_ref) {}
: matrix(matrix_ref), geometry(geometry_ref), config(config_ref), device_context(config_ref->GetCUDA()) {}

/*!
* \note This class cannot be default constructed as that would leave us with invalid pointers.
Expand Down
15 changes: 15 additions & 0 deletions Common/include/linear_algebra/CPreconditioner.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,18 @@ class CPreconditioner {
template <class ScalarType>
CPreconditioner<ScalarType>::~CPreconditioner() {}

/*!
* \class CIdentityPreconditioner
* \brief No-op preconditioner used when Krylov solvers run without preconditioning.
*/
template <class ScalarType>
class CIdentityPreconditioner final : public CPreconditioner<ScalarType> {
public:
inline void operator()(const CSysVector<ScalarType>& u, CSysVector<ScalarType>& v) const override { v = u; }

inline bool IsIdentity() const override { return true; }
};

/*!
* \class CJacobiPreconditioner
* \brief Specialization of preconditioner that uses CSysMatrix class.
Expand Down Expand Up @@ -332,6 +344,9 @@ CPreconditioner<ScalarType>* CPreconditioner<ScalarType>::Create(ENUM_LINEAR_SOL
CPreconditioner<ScalarType>* prec = nullptr;

switch (kind) {
case NO_PRECONDITIONER:
prec = new CIdentityPreconditioner<ScalarType>();
break;
case JACOBI:
prec = new CJacobiPreconditioner<ScalarType>(jacobian, geometry, config);
break;
Expand Down
27 changes: 27 additions & 0 deletions Common/include/linear_algebra/CSysMatrix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,16 @@ struct CSysMatrixComms {
MPI_QUANTITIES commType = MPI_QUANTITIES::SOLUTION_MATRIX);
};

/*!
* \brief Opaque storage for CUDA/cuSPARSE resources used by the GPU SpMV path.
*/
struct CudaSpMVResources;

/*!
* \brief Release cached CUDA/cuSPARSE resources used by the GPU SpMV path.
*/
void ReleaseCudaSpMVResources(CudaSpMVResources*& resources);

/*!
* \class CSysMatrix
* \ingroup SpLinSys
Expand Down Expand Up @@ -148,8 +158,10 @@ class CSysMatrix {
ScalarType* d_matrix; /*!< \brief Device Pointer to store the matrix values on the GPU. */
const unsigned long* d_row_ptr; /*!< \brief Device Pointers to the first element in each row. */
const unsigned long* d_col_ind; /*!< \brief Device Column index for each of the elements in val(). */
ScalarType* d_invM = nullptr; /*!< \brief Device inverse diagonal blocks for the Jacobi preconditioner. */
bool useCuda = false; /*!< \brief Boolean that indicates whether user has enabled CUDA or not.
Mainly used to conditionally free GPU memory in the class destructor. */
mutable CudaSpMVResources* spmv_resources = nullptr; /*!< \brief Cached cuSPARSE resources for GPU SpMV. */

ScalarType* ILU_matrix; /*!< \brief Entries of the ILU sparse matrix. */
unsigned long nnz_ilu; /*!< \brief Number of possible nonzero entries in the matrix (ILU). */
Expand Down Expand Up @@ -924,6 +936,13 @@ class CSysMatrix {
*/
void BuildJacobiPreconditioner();

/*!
* \brief Build the Jacobi preconditioner on the GPU/device side.
* \note This helper is intended as the implementation hook for GPU-resident Krylov solvers.
* The actual implementation belongs in CSysMatrixGPU.cu.
*/
void BuildJacobiPreconditionerGPU();

/*!
* \brief Multiply CSysVector by the preconditioner
* \param[in] vec - CSysVector to be multiplied by the preconditioner.
Expand All @@ -934,6 +953,14 @@ class CSysMatrix {
void ComputeJacobiPreconditioner(const CSysVector<ScalarType>& vec, CSysVector<ScalarType>& prod, CGeometry* geometry,
const CConfig* config) const;

/*!
* \brief Apply the Jacobi preconditioner on the GPU/device side.
* \note This helper is intended as the implementation hook for GPU-resident Krylov solvers.
* The actual implementation belongs in CSysMatrixGPU.cu.
*/
void ComputeJacobiPreconditionerGPU(const CSysVector<ScalarType>& vec, CSysVector<ScalarType>& prod,
CGeometry* geometry, const CConfig* config) const;

/*!
* \brief Build the ILU preconditioner.
*/
Expand Down
Loading
Loading