CuSparseResource.hpp
Go to the documentation of this file.
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
26namespace Opm::cuistl::detail
27{
28
53template <class T>
55{
56public:
57 using CreatorType = typename std::function<cusparseStatus_t(T*)>;
58 using DeleterType = typename std::function<cusparseStatus_t(T)>;
59
68
73
78
79 // This should not be copyable.
82
86 T get()
87 {
88 return m_resource;
89 }
90
91private:
92 T m_resource;
93
94 DeleterType m_deleter;
95};
96
97} // namespace Opm::cuistl::impl
99#endif // CUSPARSERESOURCE_HPP
The CuSparseResource class wraps a CuSparse resource in a proper RAII pattern.
Definition: CuSparseResource.hpp:55
CuSparseResource()
CuSparseResource will automatically select the proper creator and deleter based on the type (and thro...
Definition: CuSparseResource_impl.hpp:91
CuSparseResource(const CuSparseResource &)=delete
typename std::function< cusparseStatus_t(T *)> CreatorType
Definition: CuSparseResource.hpp:57
T get()
get returns the raw pointer to the resource.
Definition: CuSparseResource.hpp:86
CuSparseResource & operator=(const CuSparseResource &)=delete
typename std::function< cusparseStatus_t(T)> DeleterType
Definition: CuSparseResource.hpp:58
~CuSparseResource()
Definition: CuSparseResource_impl.hpp:97
Definition: cublas_safe_call.hpp:32