opm-simulators
CuMatrixDescription.hpp
1 /*
2  Copyright 2022-2023 SINTEF AS
3 
4  This file is part of the Open Porous Media project (OPM).
5 
6  OPM is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  OPM is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with OPM. If not, see <http://www.gnu.org/licenses/>.
18 */
19 #ifndef CU_MATRIX_DESCRIPTION_HPP
20 #define CU_MATRIX_DESCRIPTION_HPP
21 #include <opm/simulators/linalg/gpuistl/detail/CuSparseResource.hpp>
22 #include <opm/simulators/linalg/gpuistl/detail/cusparse_safe_call.hpp>
23 
24 namespace Opm::gpuistl::detail
25 {
26 
31 
35 using GpuSparseMatrixDescriptionPtr = std::shared_ptr<CuSparseResource<cusparseMatDescr_t>>;
36 
43 {
44  auto description = std::make_shared<GpuSparseMatrixDescription>();
45 
46  // Note: We always want to use zero base indexing.
47  OPM_CUSPARSE_SAFE_CALL(cusparseSetMatType(description->get(), CUSPARSE_MATRIX_TYPE_GENERAL));
48  OPM_CUSPARSE_SAFE_CALL(cusparseSetMatIndexBase(description->get(), CUSPARSE_INDEX_BASE_ZERO));
49 
50  return description;
51 }
52 
61 {
62  auto description = createMatrixDescription();
63  OPM_CUSPARSE_SAFE_CALL(cusparseSetMatFillMode(description->get(), CUSPARSE_FILL_MODE_LOWER));
64  OPM_CUSPARSE_SAFE_CALL(cusparseSetMatDiagType(description->get(), CUSPARSE_DIAG_TYPE_UNIT));
65  return description;
66 }
67 
76 {
77  auto description = createMatrixDescription();
78  OPM_CUSPARSE_SAFE_CALL(cusparseSetMatFillMode(description->get(), CUSPARSE_FILL_MODE_UPPER));
79  OPM_CUSPARSE_SAFE_CALL(cusparseSetMatDiagType(description->get(), CUSPARSE_DIAG_TYPE_NON_UNIT));
80 
81  return description;
82 }
83 
84 } // namespace Opm::gpuistl::detail
85 
86 #endif // CU_MATRIX_DESCRIPTION_HPP
GpuSparseMatrixDescriptionPtr createMatrixDescription()
createMatrixDescription creates a default matrix description
Definition: CuMatrixDescription.hpp:42
GpuSparseMatrixDescriptionPtr createUpperDiagonalDescription()
createUpperDiagonalDescription creates an upper diagonal matrix description
Definition: CuMatrixDescription.hpp:75
GpuSparseMatrixDescriptionPtr createLowerDiagonalDescription()
createLowerDiagonalDescription creates a lower diagonal matrix description
Definition: CuMatrixDescription.hpp:60
std::shared_ptr< CuSparseResource< cusparseMatDescr_t > > GpuSparseMatrixDescriptionPtr
Pointer to GpuSparseMatrixDescription holder.
Definition: CuMatrixDescription.hpp:35
The CuSparseResource class wraps a CuSparse resource in a proper RAII pattern.
Definition: CuSparseResource.hpp:54
Contains wrappers to make the CuBLAS library behave as a modern C++ library with function overlading...
Definition: autotuner.hpp:29