mxlib
c++ tools for analyzing astronomical data and other tasks by Jared R. Males. [git repo]
Loading...
Searching...
No Matches
cusolverDnParams.hpp
Go to the documentation of this file.
1/** \file cusolverDnParams.hpp
2 * \author Jared R. Males
3 * \brief Management of a cusolverDnParams structure
4 * \ingroup cuda_files
5 *
6 */
7
8//***********************************************************************//
9// Copyright 2025 Jared R. Males (jaredmales@gmail.com)
10//
11// This file is part of mxlib.
12//
13// mxlib is free software: you can redistribute it and/or modify
14// it under the terms of the GNU General Public License as published by
15// the Free Software Foundation, either version 3 of the License, or
16// (at your option) any later version.
17//
18// mxlib is distributed in the hope that it will be useful,
19// but WITHOUT ANY WARRANTY; without even the implied warranty of
20// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21// GNU General Public License for more details.
22//
23// You should have received a copy of the GNU General Public License
24// along with mxlib. If not, see <http://www.gnu.org/licenses/>.
25//***********************************************************************//
26
27#ifndef math_cusolverDnParams_hpp
28#define math_cusolverDnParams_hpp
29
30#ifdef MXLIB_CUDA
31
32#include <cuda_runtime.h>
33#include <cusolverDn.h>
34
35namespace mx
36{
37namespace cuda
38{
39
40/// Management of a cusolverDnParams structure
41/** RAII management of a cusolverDnParams structure.
42 *
43 * The handle is not created automatically on default construction, e.g. in case
44 * it is desired to do so in a critical block scope.
45 *
46 * The handle is destroyed on the call to this class's destructor.
47 *
48 * \todo throw exceptions in cuda::cusolverDnParams
49 */
50struct cusolverDnParams
51{
52
53 private:
54 cusolverDnParams_t m_handle{ NULL };
55
56 public:
57 /// Default c'tor
58 /** Creates the structure
59 */
60 cusolverDnParams()
61 {
62 create();
63 }
64
65 /// Constructor with option to create /not-create the structure
66 explicit cusolverDnParams( bool create /**< [in] if true the structure is created. if false it is not created. */ )
67 {
68 if( create )
69 {
70 this->create();
71 }
72 }
73
74 /// Destructor
75 ~cusolverDnParams()
76 {
77 if( m_handle )
78 {
79 cusolverDnDestroyParams( m_handle );
80 }
81 }
82
83 /// Create (allocate) the structure.
84 void create()
85 {
86 cusolverStatus_t csec = cusolverDnCreateParams( &m_handle );
87 if( csec != CUSOLVER_STATUS_SUCCESS )
88 {
89 std::cerr << __FILE__ << " " << __LINE__ << " " << csec << "\n";
90 exit( -1 );
91 }
92 }
93
94 /// Get the structure for use in calls to cusolverDN routines
95 /**
96 * \returns the cusolverDnParams structure
97 */
98 cusolverDnParams_t operator()()
99 {
100 return m_handle;
101 }
102
103 /// Conversion operator, allows objects of this class to be used as if they are the structure
104 /**
105 * \returns the cusolverDnParams structure
106 */
107 operator cusolverDnParams_t()
108 {
109 return m_handle;
110 }
111};
112
113} // namespace cuda
114} // namespace mx
115
116#endif //MXLIB_CUDA
117
118#endif // math_cusolverDnParams_hpp
The mxlib c++ namespace.
Definition mxlib.hpp:37