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 <cstdlib>
33#include <iostream>
34
35#include <cuda_runtime.h>
36#include <cusolverDn.h>
37
38namespace mx
39{
40namespace cuda
41{
42
43/// Management of a cusolverDnParams structure
44/** RAII management of a cusolverDnParams structure.
45 *
46 * The handle is not created automatically on default construction, e.g. in case
47 * it is desired to do so in a critical block scope.
48 *
49 * The handle is destroyed on the call to this class's destructor.
50 *
51 * \todo throw exceptions in cuda::cusolverDnParams
52 */
53struct cusolverDnParams
54{
55
56 private:
57 cusolverDnParams_t m_handle{ NULL };
58
59 public:
60 /// Default c'tor
61 /** Creates the structure
62 */
63 cusolverDnParams()
64 {
65 create();
66 }
67
68 /// Constructor with option to create /not-create the structure
69 explicit cusolverDnParams( bool create /**< [in] if true the structure is created. if false it is not created. */ )
70 {
71 if( create )
72 {
73 this->create();
74 }
75 }
76
77 /// Destructor
78 ~cusolverDnParams()
79 {
80 if( m_handle )
81 {
82 cusolverDnDestroyParams( m_handle );
83 }
84 }
85
86 /// Create (allocate) the structure.
87 void create()
88 {
89 cusolverStatus_t csec = cusolverDnCreateParams( &m_handle );
90 if( csec != CUSOLVER_STATUS_SUCCESS )
91 {
92 std::cerr << __FILE__ << " " << __LINE__ << " " << csec << "\n";
93 exit( -1 );
94 }
95 }
96
97 /// Get the structure for use in calls to cusolverDN routines
98 /**
99 * \returns the cusolverDnParams structure
100 */
101 cusolverDnParams_t operator()()
102 {
103 return m_handle;
104 }
105
106 /// Conversion operator, allows objects of this class to be used as if they are the structure
107 /**
108 * \returns the cusolverDnParams structure
109 */
110 operator cusolverDnParams_t()
111 {
112 return m_handle;
113 }
114};
115
116} // namespace cuda
117} // namespace mx
118
119#endif //MXLIB_CUDA
120
121#endif // math_cusolverDnParams_hpp
The mxlib c++ namespace.
Definition mxlib.hpp:37