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