opm-simulators
Toggle main menu visibility
Loading...
Searching...
No Matches
CuSparseResource_impl.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
#include <exception>
20
#include <opm/common/ErrorMacros.hpp>
21
#include <opm/simulators/linalg/gpuistl/detail/cusparse_safe_call.hpp>
22
23
namespace
Opm::gpuistl::detail
24
{
25
26
namespace
27
{
28
template
<
class
T>
29
struct
CuSparseDeleteAndCreate {
30
};
31
32
template
<>
33
struct
CuSparseDeleteAndCreate<bsrilu02Info_t> {
34
using
DeleterType =
typename
CuSparseResource<bsrilu02Info_t>::DeleterType;
35
using
CreatorType =
typename
CuSparseResource<bsrilu02Info_t>::CreatorType;
36
37
static
DeleterType getDeleter()
38
{
39
return
cusparseDestroyBsrilu02Info;
40
}
41
42
static
CreatorType getCreator()
43
{
44
return
cusparseCreateBsrilu02Info;
45
}
46
};
47
48
template
<>
49
struct
CuSparseDeleteAndCreate<bsrsv2Info_t> {
50
using
DeleterType =
typename
CuSparseResource<bsrsv2Info_t>::DeleterType;
51
using
CreatorType =
typename
CuSparseResource<bsrsv2Info_t>::CreatorType;
52
53
static
DeleterType getDeleter()
54
{
55
return
cusparseDestroyBsrsv2Info;
56
}
57
58
static
CreatorType getCreator()
59
{
60
return
cusparseCreateBsrsv2Info;
61
}
62
};
63
64
template
<>
65
struct
CuSparseDeleteAndCreate<cusparseMatDescr_t> {
66
using
DeleterType =
typename
CuSparseResource<cusparseMatDescr_t>::DeleterType;
67
using
CreatorType =
typename
CuSparseResource<cusparseMatDescr_t>::CreatorType;
68
69
static
DeleterType getDeleter()
70
{
71
return
cusparseDestroyMatDescr;
72
}
73
74
static
CreatorType getCreator()
75
{
76
return
cusparseCreateMatDescr;
77
}
78
};
79
80
}
// namespace
81
template
<
class
T>
82
CuSparseResource<T>::CuSparseResource
(CreatorType creator, DeleterType deleter)
83
: m_deleter(deleter)
84
{
85
// TODO: This should probably not use this macro since it will disguise the
86
// proper name of the function being called.
87
OPM_CUSPARSE_SAFE_CALL(creator(&m_resource));
88
}
89
90
template
<
class
T>
91
CuSparseResource<T>::CuSparseResource
()
92
:
CuSparseResource
<T>(CuSparseDeleteAndCreate<T>::getCreator(), CuSparseDeleteAndCreate<T>::getDeleter())
93
{
94
}
95
96
template
<
class
T>
97
CuSparseResource<T>::CuSparseResource
(
const
CuSparseResource
& other)
98
: m_deleter(other.m_deleter)
99
{
100
*m_resource = other.m_resource;
101
}
102
103
template
<
class
T>
104
CuSparseResource<T>::~CuSparseResource
()
105
{
106
// TODO: This should probably not use this macro since it will disguise the
107
// proper name of the function being called.
108
OPM_CUSPARSE_WARN_IF_ERROR(m_deleter(m_resource));
109
}
110
}
// namespace Opm::gpuistl::detail
Opm::gpuistl::detail::CuSparseResource
The CuSparseResource class wraps a CuSparse resource in a proper RAII pattern.
Definition
CuSparseResource.hpp:55
Opm::gpuistl::detail::CuSparseResource::CuSparseResource
CuSparseResource(CreatorType creator, DeleterType deleter)
CuSparseResource creates a new instance by calling creator, and will delete using deleter.
Definition
CuSparseResource_impl.hpp:82
Opm::gpuistl::detail::CuSparseResource::CuSparseResource
CuSparseResource()
CuSparseResource will automatically select the proper creator and deleter based on the type (and thro...
Definition
CuSparseResource_impl.hpp:91
Opm::gpuistl::detail::CuSparseResource::~CuSparseResource
~CuSparseResource()
Calls the deleter functor.
Definition
CuSparseResource_impl.hpp:104
Opm::gpuistl::detail
Contains wrappers to make the CuBLAS library behave as a modern C++ library with function overlading.
Definition
autotuner.hpp:30
opm
simulators
linalg
gpuistl
detail
CuSparseResource_impl.hpp
Generated by
1.17.0