singe-cusolver 0.1.0-alpha.5

Safe Rust wrappers for the NVIDIA cuSOLVER dense and sparse solver library.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
#[allow(unused_imports)]
use crate::irs::xgesv;

use std::fmt::{self, Display, Formatter};

use num_enum::{IntoPrimitive, TryFromPrimitive};
use singe_core::impl_enum_conversion;
use singe_cuda::data_type::DataType;
use singe_cusolver_sys as sys;

/// Selects the generalized eigenvalue problem type.
///
/// This corresponds to LAPACK integer `1` (`A*x = lambda*B*x`), `2`
/// (`A*B*x = lambda*x`), and `3` (`B*A*x = lambda*x`) arguments.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, TryFromPrimitive, IntoPrimitive)]
#[repr(u32)]
pub enum EigenType {
    /// A\*x = lambda\*B\*x.
    Type1 = sys::cusolverEigType_t::CUSOLVER_EIG_TYPE_1 as _,
    /// A\*B\*x = lambda\*x.
    Type2 = sys::cusolverEigType_t::CUSOLVER_EIG_TYPE_2 as _,
    /// B\*A\*x = lambda\*x.
    Type3 = sys::cusolverEigType_t::CUSOLVER_EIG_TYPE_3 as _,
}

impl_enum_conversion!(sys::cusolverEigType_t, EigenType);

/// Selects whether to compute eigenvectors.
///
/// This corresponds to LAPACK `N` (eigenvalues only) and `V` (eigenvalues and
/// eigenvectors) arguments.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, TryFromPrimitive, IntoPrimitive)]
#[repr(u32)]
pub enum EigenMode {
    /// Compute only eigenvalues.
    NoVector = sys::cusolverEigMode_t::CUSOLVER_EIG_MODE_NOVECTOR as _,
    /// Compute both eigenvalues and eigenvectors.
    Vector = sys::cusolverEigMode_t::CUSOLVER_EIG_MODE_VECTOR as _,
}

impl_enum_conversion!(sys::cusolverEigMode_t, EigenMode);

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, TryFromPrimitive, IntoPrimitive)]
#[repr(u32)]
pub enum EigenRange {
    All = sys::cusolverEigRange_t::CUSOLVER_EIG_RANGE_ALL as _,
    Index = sys::cusolverEigRange_t::CUSOLVER_EIG_RANGE_I as _,
    Value = sys::cusolverEigRange_t::CUSOLVER_EIG_RANGE_V as _,
}

impl_enum_conversion!(sys::cusolverEigRange_t, EigenRange);

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, TryFromPrimitive, IntoPrimitive)]
#[repr(u32)]
pub enum Norm {
    Infinity = sys::cusolverNorm_t::CUSOLVER_INF_NORM as _,
    Maximum = sys::cusolverNorm_t::CUSOLVER_MAX_NORM as _,
    One = sys::cusolverNorm_t::CUSOLVER_ONE_NORM as _,
    Frobenius = sys::cusolverNorm_t::CUSOLVER_FRO_NORM as _,
}

impl_enum_conversion!(sys::cusolverNorm_t, Norm);

/// Indicates which IRS refinement solver to use for a cuSOLVER operation.
/// Empirically, [`IrsRefinement::Gmres`] is often the best option.
///
/// More details about the refinement process are available in Azzam Haidar,
/// Stanimire Tomov, Jack Dongarra, and Nicholas J. Higham, "Harnessing GPU
/// tensor cores for fast FP16 arithmetic to speed up mixed-precision iterative
/// refinement solvers," SC '18.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, TryFromPrimitive, IntoPrimitive)]
#[repr(u32)]
pub enum IrsRefinement {
    /// Solver is not set; this value is what is set when creating the `params` structure.
    /// The IRS solver returns an error if this value is used.
    NotSet = sys::cusolverIRSRefinement_t::CUSOLVER_IRS_REFINE_NOT_SET as _,
    /// No refinement solver; the IRS solver performs a factorization followed by a solve without any refinement.
    /// For example, when used with [`xgesv`], this matches the non-refined solver path with the factorization carried out in the lowest precision.
    /// If both the main and lowest precision are [`PrecisionType::R64F`], this is equivalent to solving entirely in `f64`.
    None = sys::cusolverIRSRefinement_t::CUSOLVER_IRS_REFINE_NONE as _,
    /// Classical iterative refinement solver.
    /// Similar to the value used in LAPACK operations.
    Classical = sys::cusolverIRSRefinement_t::CUSOLVER_IRS_REFINE_CLASSICAL as _,
    /// Classical iterative refinement solver that uses the GMRES (Generalized Minimal Residual) internally to solve the correction equation at each iteration.
    /// The classical refinement iteration is the outer iteration, and GMRES is the inner iteration.
    /// If the tolerance of the inner GMRES is very low, for example near machine precision, the outer *classical refinement iteration* performs only one iteration and this option behaves like [`IrsRefinement::Gmres`].
    ClassicalGmres = sys::cusolverIRSRefinement_t::CUSOLVER_IRS_REFINE_CLASSICAL_GMRES as _,
    /// GMRES (Generalized Minimal Residual) based iterative refinement solver.
    /// Recent studies use GMRES as a refinement solver that can outperform classical iterative refinement.
    /// Recommended setting based on cuSOLVER experimentation.
    Gmres = sys::cusolverIRSRefinement_t::CUSOLVER_IRS_REFINE_GMRES as _,
    /// GMRES-based iterative refinement solver that uses another GMRES solve internally for the preconditioned system.
    GmresGmres = sys::cusolverIRSRefinement_t::CUSOLVER_IRS_REFINE_GMRES_GMRES as _,
    GmresNoPcond = sys::cusolverIRSRefinement_t::CUSOLVER_IRS_REFINE_GMRES_NOPCOND as _,
    PrecDd = sys::cusolverIRSRefinement_t::CUSOLVER_PREC_DD as _,
    PrecSs = sys::cusolverIRSRefinement_t::CUSOLVER_PREC_SS as _,
    PrecSht = sys::cusolverIRSRefinement_t::CUSOLVER_PREC_SHT as _,
}

impl_enum_conversion!(sys::cusolverIRSRefinement_t, IrsRefinement);

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, TryFromPrimitive, IntoPrimitive)]
#[repr(u32)]
pub enum PrecisionType {
    R8I = sys::cusolverPrecType_t::CUSOLVER_R_8I as _,
    R8U = sys::cusolverPrecType_t::CUSOLVER_R_8U as _,
    R64F = sys::cusolverPrecType_t::CUSOLVER_R_64F as _,
    R32F = sys::cusolverPrecType_t::CUSOLVER_R_32F as _,
    R16F = sys::cusolverPrecType_t::CUSOLVER_R_16F as _,
    R16Bf = sys::cusolverPrecType_t::CUSOLVER_R_16BF as _,
    RTf32 = sys::cusolverPrecType_t::CUSOLVER_R_TF32 as _,
    RAp = sys::cusolverPrecType_t::CUSOLVER_R_AP as _,
    C8I = sys::cusolverPrecType_t::CUSOLVER_C_8I as _,
    C8U = sys::cusolverPrecType_t::CUSOLVER_C_8U as _,
    C64F = sys::cusolverPrecType_t::CUSOLVER_C_64F as _,
    C32F = sys::cusolverPrecType_t::CUSOLVER_C_32F as _,
    C16F = sys::cusolverPrecType_t::CUSOLVER_C_16F as _,
    C16Bf = sys::cusolverPrecType_t::CUSOLVER_C_16BF as _,
    CTf32 = sys::cusolverPrecType_t::CUSOLVER_C_TF32 as _,
    CAp = sys::cusolverPrecType_t::CUSOLVER_C_AP as _,
}

impl_enum_conversion!(sys::cusolverPrecType_t, PrecisionType);

impl PrecisionType {
    pub const fn from_data_type(data_type: DataType) -> Option<Self> {
        match data_type {
            DataType::F64 => Some(Self::R64F),
            DataType::F32 => Some(Self::R32F),
            DataType::F16 => Some(Self::R16F),
            DataType::Bf16 => Some(Self::R16Bf),
            DataType::ComplexF64 => Some(Self::C64F),
            DataType::ComplexF32 => Some(Self::C32F),
            DataType::ComplexF16 => Some(Self::C16F),
            DataType::ComplexBf16 => Some(Self::C16Bf),
            _ => None,
        }
    }
}

/// Algorithm selected by [`Params::set_adv_options`](crate::params::Params::set_adv_options).
/// The set of algorithms supported for each operation is described with that
/// operation's documentation.
///
/// The default algorithm is [`AlgorithmMode::Default`].
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, TryFromPrimitive, IntoPrimitive)]
#[repr(u32)]
pub enum AlgorithmMode {
    Default = sys::cusolverAlgMode_t::CUSOLVER_ALG_0 as _,
    Algorithm1 = sys::cusolverAlgMode_t::CUSOLVER_ALG_1 as _,
    Algorithm2 = sys::cusolverAlgMode_t::CUSOLVER_ALG_2 as _,
}

impl_enum_conversion!(sys::cusolverAlgMode_t, AlgorithmMode);

/// Specifies how the vectors which define the elementary reflectors are stored.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, TryFromPrimitive, IntoPrimitive)]
#[repr(u32)]
pub enum StorevMode {
    /// Columnwise.
    Columnwise = sys::cusolverStorevMode_t::CUBLAS_STOREV_COLUMNWISE as _,
    /// Rowwise.
    Rowwise = sys::cusolverStorevMode_t::CUBLAS_STOREV_ROWWISE as _,
}

impl_enum_conversion!(sys::cusolverStorevMode_t, StorevMode);

/// Specifies the order in which the elementary reflectors are multiplied to form the block reflector.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, TryFromPrimitive, IntoPrimitive)]
#[repr(u32)]
pub enum DirectMode {
    /// Forward.
    Forward = sys::cusolverDirectMode_t::CUBLAS_DIRECT_FORWARD as _,
    /// Backward.
    Backward = sys::cusolverDirectMode_t::CUBLAS_DIRECT_BACKWARD as _,
}

impl_enum_conversion!(sys::cusolverDirectMode_t, DirectMode);

/// Indicates whether repeated cuSOLVER executions with the same input are
/// required to produce bitwise-identical results.
///
/// Compared with cuBLAS atomics mode, [`DeterministicMode`] covers
/// non-determinism beyond atomic operations.
///
/// Use [`Context::set_deterministic_mode`](crate::context::Context::set_deterministic_mode)
/// and [`Context::deterministic_mode`](crate::context::Context::deterministic_mode)
/// to configure and query this setting.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, TryFromPrimitive, IntoPrimitive)]
#[repr(u32)]
pub enum DeterministicMode {
    /// Compute deterministic results.
    Deterministic = sys::cusolverDeterministicMode_t::CUSOLVER_DETERMINISTIC_RESULTS as _,
    /// Allow non-deterministic results.
    AllowNonDeterministic =
        sys::cusolverDeterministicMode_t::CUSOLVER_ALLOW_NON_DETERMINISTIC_RESULTS as _,
}

impl_enum_conversion!(sys::cusolverDeterministicMode_t, DeterministicMode);

/// Compute precision mode selected by [`set_math_mode`](crate::context::Context::set_math_mode).
///
/// The following combinations of [`MathMode`] using the bitwise OR operator are allowed.
/// Math mode selection for cuSOLVER operations.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, TryFromPrimitive, IntoPrimitive)]
#[repr(u32)]
pub enum MathMode {
    /// Default math mode.
    /// Tensor Cores are used whenever possible.
    Default = sys::cusolverMathMode_t::CUSOLVER_DEFAULT_MATH as _,
    /// Use FP32 emulation according to the configured emulation strategy (see [`set_emulation_strategy`](crate::context::Context::set_emulation_strategy)).
    Fp32EmulatedBf16x9 = sys::cusolverMathMode_t::CUSOLVER_FP32_EMULATED_BF16X9_MATH as _,
}

impl_enum_conversion!(sys::cusolverMathMode_t, MathMode);

/// Selects which filled part of a dense matrix is used by the operation.
///
/// This corresponds to BLAS `L`/`l` (lower) and `U`/`u` (upper) arguments.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, TryFromPrimitive, IntoPrimitive)]
#[repr(u32)]
pub enum FillMode {
    /// The lower part of the matrix is filled.
    Lower = sys::cublasFillMode_t::CUBLAS_FILL_MODE_LOWER as _,
    /// The upper part of the matrix is filled.
    Upper = sys::cublasFillMode_t::CUBLAS_FILL_MODE_UPPER as _,
    /// The full matrix is filled.
    Full = sys::cublasFillMode_t::CUBLAS_FILL_MODE_FULL as _,
}

impl_enum_conversion!(sys::cublasFillMode_t, FillMode);

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, TryFromPrimitive, IntoPrimitive)]
#[repr(u32)]
pub enum DiagonalType {
    NonUnit = sys::cublasDiagType_t::CUBLAS_DIAG_NON_UNIT as _,
    Unit = sys::cublasDiagType_t::CUBLAS_DIAG_UNIT as _,
}

impl_enum_conversion!(sys::cublasDiagType_t, DiagonalType);

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, TryFromPrimitive, IntoPrimitive)]
#[repr(u32)]
pub enum SideMode {
    Left = sys::cublasSideMode_t::CUBLAS_SIDE_LEFT as _,
    Right = sys::cublasSideMode_t::CUBLAS_SIDE_RIGHT as _,
}

impl_enum_conversion!(sys::cublasSideMode_t, SideMode);

/// Selects the operation to perform with a dense matrix.
///
/// This corresponds to BLAS `N`/`n` (non-transpose), `T`/`t` (transpose), and
/// `C`/`c` (conjugate transpose) arguments.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, TryFromPrimitive, IntoPrimitive)]
#[repr(u32)]
pub enum Operation {
    /// Non-transpose operation.
    NonTranspose = sys::cublasOperation_t::CUBLAS_OP_N as _,
    /// Transpose operation.
    Transpose = sys::cublasOperation_t::CUBLAS_OP_T as _,
    /// Conjugate transpose operation.
    ConjugateTranspose = sys::cublasOperation_t::CUBLAS_OP_C as _,
    Conjugate = sys::cublasOperation_t::CUBLAS_OP_CONJG as _,
}

impl Operation {
    pub const HERMITIAN: Self = Self::ConjugateTranspose;
}

impl_enum_conversion!(sys::cublasOperation_t, Operation);

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum SvdMode {
    All,
    Some,
    Overwrite,
    None,
}

impl SvdMode {
    pub const fn as_raw(self) -> i8 {
        match self {
            Self::All => b'A' as i8,
            Self::Some => b'S' as i8,
            Self::Overwrite => b'O' as i8,
            Self::None => b'N' as i8,
        }
    }
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum TruncatedSvdMode {
    Some,
    None,
}

impl TruncatedSvdMode {
    pub const fn as_raw(self) -> i8 {
        match self {
            Self::Some => b'S' as i8,
            Self::None => b'N' as i8,
        }
    }
}

/// Indicates which operation is configured by
/// [`Params::set_adv_options`](crate::params::Params::set_adv_options).
/// [`Function::Getrf`] corresponds to the `getrf` operation.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, TryFromPrimitive, IntoPrimitive)]
#[repr(u32)]
pub enum Function {
    /// Corresponds to `Getrf`.
    Getrf = sys::cusolverDnFunction_t::CUSOLVERDN_GETRF as _,
    Potrf = sys::cusolverDnFunction_t::CUSOLVERDN_POTRF as _,
    SyevBatched = sys::cusolverDnFunction_t::CUSOLVERDN_SYEVBATCHED as _,
}

impl_enum_conversion!(sys::cusolverDnFunction_t, Function);

impl Display for EigenType {
    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
        match self {
            Self::Type1 => write!(f, "CUSOLVER_EIG_TYPE_1"),
            Self::Type2 => write!(f, "CUSOLVER_EIG_TYPE_2"),
            Self::Type3 => write!(f, "CUSOLVER_EIG_TYPE_3"),
        }
    }
}

impl Display for EigenMode {
    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
        match self {
            Self::NoVector => write!(f, "CUSOLVER_EIG_MODE_NOVECTOR"),
            Self::Vector => write!(f, "CUSOLVER_EIG_MODE_VECTOR"),
        }
    }
}

impl Display for EigenRange {
    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
        match self {
            Self::All => write!(f, "CUSOLVER_EIG_RANGE_ALL"),
            Self::Index => write!(f, "CUSOLVER_EIG_RANGE_I"),
            Self::Value => write!(f, "CUSOLVER_EIG_RANGE_V"),
        }
    }
}

impl Display for Norm {
    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
        match self {
            Self::Infinity => write!(f, "CUSOLVER_INF_NORM"),
            Self::Maximum => write!(f, "CUSOLVER_MAX_NORM"),
            Self::One => write!(f, "CUSOLVER_ONE_NORM"),
            Self::Frobenius => write!(f, "CUSOLVER_FRO_NORM"),
        }
    }
}

impl Display for IrsRefinement {
    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
        match self {
            Self::NotSet => write!(f, "CUSOLVER_IRS_REFINE_NOT_SET"),
            Self::None => write!(f, "CUSOLVER_IRS_REFINE_NONE"),
            Self::Classical => write!(f, "CUSOLVER_IRS_REFINE_CLASSICAL"),
            Self::ClassicalGmres => write!(f, "CUSOLVER_IRS_REFINE_CLASSICAL_GMRES"),
            Self::Gmres => write!(f, "CUSOLVER_IRS_REFINE_GMRES"),
            Self::GmresGmres => write!(f, "CUSOLVER_IRS_REFINE_GMRES_GMRES"),
            Self::GmresNoPcond => write!(f, "CUSOLVER_IRS_REFINE_GMRES_NOPCOND"),
            Self::PrecDd => write!(f, "CUSOLVER_PREC_DD"),
            Self::PrecSs => write!(f, "CUSOLVER_PREC_SS"),
            Self::PrecSht => write!(f, "CUSOLVER_PREC_SHT"),
        }
    }
}

impl Display for PrecisionType {
    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
        match self {
            Self::R8I => write!(f, "CUSOLVER_R_8I"),
            Self::R8U => write!(f, "CUSOLVER_R_8U"),
            Self::R64F => write!(f, "CUSOLVER_R_64F"),
            Self::R32F => write!(f, "CUSOLVER_R_32F"),
            Self::R16F => write!(f, "CUSOLVER_R_16F"),
            Self::R16Bf => write!(f, "CUSOLVER_R_16BF"),
            Self::RTf32 => write!(f, "CUSOLVER_R_TF32"),
            Self::RAp => write!(f, "CUSOLVER_R_AP"),
            Self::C8I => write!(f, "CUSOLVER_C_8I"),
            Self::C8U => write!(f, "CUSOLVER_C_8U"),
            Self::C64F => write!(f, "CUSOLVER_C_64F"),
            Self::C32F => write!(f, "CUSOLVER_C_32F"),
            Self::C16F => write!(f, "CUSOLVER_C_16F"),
            Self::C16Bf => write!(f, "CUSOLVER_C_16BF"),
            Self::CTf32 => write!(f, "CUSOLVER_C_TF32"),
            Self::CAp => write!(f, "CUSOLVER_C_AP"),
        }
    }
}

impl Display for AlgorithmMode {
    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
        match self {
            Self::Default => write!(f, "CUSOLVER_ALG_0"),
            Self::Algorithm1 => write!(f, "CUSOLVER_ALG_1"),
            Self::Algorithm2 => write!(f, "CUSOLVER_ALG_2"),
        }
    }
}

impl Display for StorevMode {
    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
        match self {
            Self::Columnwise => write!(f, "CUBLAS_STOREV_COLUMNWISE"),
            Self::Rowwise => write!(f, "CUBLAS_STOREV_ROWWISE"),
        }
    }
}

impl Display for DirectMode {
    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
        match self {
            Self::Forward => write!(f, "CUBLAS_DIRECT_FORWARD"),
            Self::Backward => write!(f, "CUBLAS_DIRECT_BACKWARD"),
        }
    }
}

impl Display for DeterministicMode {
    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
        match self {
            Self::Deterministic => write!(f, "CUSOLVER_DETERMINISTIC_RESULTS"),
            Self::AllowNonDeterministic => {
                write!(f, "CUSOLVER_ALLOW_NON_DETERMINISTIC_RESULTS")
            }
        }
    }
}

impl Display for MathMode {
    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
        match self {
            Self::Default => write!(f, "CUSOLVER_DEFAULT_MATH"),
            Self::Fp32EmulatedBf16x9 => write!(f, "CUSOLVER_FP32_EMULATED_BF16X9_MATH"),
        }
    }
}

impl Display for FillMode {
    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
        match self {
            Self::Lower => write!(f, "CUBLAS_FILL_MODE_LOWER"),
            Self::Upper => write!(f, "CUBLAS_FILL_MODE_UPPER"),
            Self::Full => write!(f, "CUBLAS_FILL_MODE_FULL"),
        }
    }
}

impl Display for DiagonalType {
    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
        match self {
            Self::NonUnit => write!(f, "CUBLAS_DIAG_NON_UNIT"),
            Self::Unit => write!(f, "CUBLAS_DIAG_UNIT"),
        }
    }
}

impl Display for SideMode {
    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
        match self {
            Self::Left => write!(f, "CUBLAS_SIDE_LEFT"),
            Self::Right => write!(f, "CUBLAS_SIDE_RIGHT"),
        }
    }
}

impl Display for Operation {
    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
        match self {
            Self::NonTranspose => write!(f, "CUBLAS_OP_N"),
            Self::Transpose => write!(f, "CUBLAS_OP_T"),
            Self::ConjugateTranspose => write!(f, "CUBLAS_OP_C"),
            Self::Conjugate => write!(f, "CUBLAS_OP_CONJG"),
        }
    }
}

impl Display for SvdMode {
    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
        match self {
            Self::All => write!(f, "A"),
            Self::Some => write!(f, "S"),
            Self::Overwrite => write!(f, "O"),
            Self::None => write!(f, "N"),
        }
    }
}

impl Display for TruncatedSvdMode {
    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
        match self {
            Self::Some => write!(f, "S"),
            Self::None => write!(f, "N"),
        }
    }
}

impl Display for Function {
    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
        match self {
            Self::Getrf => write!(f, "CUSOLVERDN_GETRF"),
            Self::Potrf => write!(f, "CUSOLVERDN_POTRF"),
            Self::SyevBatched => write!(f, "CUSOLVERDN_SYEVBATCHED"),
        }
    }
}