opm-simulators
CuSparseResource.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 CUSPARSERESOURCE_HPP
20 #define CUSPARSERESOURCE_HPP
21 #include <cusparse.h>
22 #include <functional>
23 #include <memory>
24 #include <type_traits>
25 
26 namespace Opm::gpuistl::detail
27 {
28 
53 template <class T>
55 {
56 public:
57  using CreatorType = typename std::function<cusparseStatus_t(T*)>;
58  using DeleterType = typename std::function<cusparseStatus_t(T)>;
59 
67  CuSparseResource(CreatorType creator, DeleterType deleter);
68 
73 
78 
80 
81  CuSparseResource& operator=(const CuSparseResource&) = delete;
82 
86  T get()
87  {
88  return m_resource;
89  }
90 
91 private:
92  T m_resource;
93 
94  DeleterType m_deleter;
95 };
96 
97 } // namespace Opm::gpuistl::impl
98 #include <opm/simulators/linalg/gpuistl/detail/CuSparseResource_impl.hpp>
99 #endif // CUSPARSERESOURCE_HPP
~CuSparseResource()
Calls the deleter functor.
Definition: CuSparseResource_impl.hpp:104
CuSparseResource()
CuSparseResource will automatically select the proper creator and deleter based on the type (and thro...
Definition: CuSparseResource_impl.hpp:91
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