Skip to main content

singe_cusparse/
types.rs

1use std::fmt::{self, Display, Formatter};
2
3use num_enum::{IntoPrimitive, TryFromPrimitive};
4use singe_core::impl_enum_conversion;
5use singe_cusparse_sys as sys;
6
7/// Indicates whether scalar values are read from host memory or device memory.
8/// If an operation uses several scalar values, all of them use the same pointer mode.
9/// The pointer mode can be set and retrieved with [`Context::set_scalar_pointer_mode`](crate::context::Context::set_scalar_pointer_mode) and [`Context::scalar_pointer_mode`](crate::context::Context::scalar_pointer_mode), respectively.
10#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, TryFromPrimitive, IntoPrimitive)]
11#[repr(u32)]
12pub enum PointerMode {
13    /// Scalars are read from host memory.
14    Host = sys::cusparsePointerMode_t::CUSPARSE_POINTER_MODE_HOST as _,
15    /// Scalars are read from device memory.
16    Device = sys::cusparsePointerMode_t::CUSPARSE_POINTER_MODE_DEVICE as _,
17}
18
19impl_enum_conversion!(sys::cusparsePointerMode_t, PointerMode);
20
21/// Selects whether an operation processes only indices or both data and indices.
22#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, TryFromPrimitive, IntoPrimitive)]
23#[repr(u32)]
24pub enum Action {
25    /// Process only indices.
26    Symbolic = sys::cusparseAction_t::CUSPARSE_ACTION_SYMBOLIC as _,
27    /// Process data and indices.
28    Numeric = sys::cusparseAction_t::CUSPARSE_ACTION_NUMERIC as _,
29}
30
31impl_enum_conversion!(sys::cusparseAction_t, Action);
32
33/// Describes the matrix kind stored in sparse storage.
34/// For symmetric, Hermitian, and triangular matrices, only their lower or upper part is assumed to be stored.
35///
36/// Matrix type and fill mode minimize storage for symmetric or Hermitian matrices and let SpMV operations use symmetry when useful.
37/// To compute `y=A*x` when `A` is symmetric and only lower triangular part is stored, two steps are needed.
38/// First step is to compute `y=(L+D)*x` and second step is to compute `y=L^T*x + y`.
39/// Because the transpose operation `y=L^T*x` is much slower than the non-transpose version `y=L*x`, the symmetric property does not always improve performance.
40/// It is usually more efficient to expand the symmetric matrix to a general matrix and
41/// apply `y=A*x` with matrix type [`MatrixType::General`].
42///
43/// In general, SpMV, preconditioners (incomplete Cholesky or incomplete LU) and triangular solver are combined together in iterative solvers, for example PCG and GMRES.
44/// If applications use general matrices instead of symmetric matrices, preconditioners
45/// only need to support general matrices.
46/// Therefore the newer `\[bsr|csr\]sv2` (triangular solver), `\[bsr|csr\]ilu02` (incomplete LU), and `\[bsr|csr\]ic02` (incomplete Cholesky) operations only support matrix type [`MatrixType::General`].
47#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, TryFromPrimitive, IntoPrimitive)]
48#[repr(u32)]
49pub enum MatrixType {
50    /// The matrix is general.
51    General = sys::cusparseMatrixType_t::CUSPARSE_MATRIX_TYPE_GENERAL as _,
52    /// The matrix is symmetric.
53    Symmetric = sys::cusparseMatrixType_t::CUSPARSE_MATRIX_TYPE_SYMMETRIC as _,
54    /// The matrix is Hermitian.
55    Hermitian = sys::cusparseMatrixType_t::CUSPARSE_MATRIX_TYPE_HERMITIAN as _,
56    /// The matrix is triangular.
57    Triangular = sys::cusparseMatrixType_t::CUSPARSE_MATRIX_TYPE_TRIANGULAR as _,
58}
59
60impl_enum_conversion!(sys::cusparseMatrixType_t, MatrixType);
61
62/// Selects whether the lower or upper part of a matrix is stored in sparse storage.
63#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, TryFromPrimitive, IntoPrimitive)]
64#[repr(u32)]
65pub enum FillMode {
66    /// The lower triangular part is stored.
67    Lower = sys::cusparseFillMode_t::CUSPARSE_FILL_MODE_LOWER as _,
68    /// The upper triangular part is stored.
69    Upper = sys::cusparseFillMode_t::CUSPARSE_FILL_MODE_UPPER as _,
70}
71
72impl_enum_conversion!(sys::cusparseFillMode_t, FillMode);
73
74/// Selects whether matrix diagonal entries are treated as unity.
75/// The diagonal elements are always assumed to be present, but if
76/// [`DiagonalType::Unit`] is passed to an operation, the operation assumes that
77/// all diagonal entries are one and does not read or modify them.
78/// This behavior is independent of the actual values stored in memory.
79#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, TryFromPrimitive, IntoPrimitive)]
80#[repr(u32)]
81pub enum DiagonalType {
82    /// The matrix diagonal has non-unit elements.
83    NonUnit = sys::cusparseDiagType_t::CUSPARSE_DIAG_TYPE_NON_UNIT as _,
84    /// The matrix diagonal has unit elements.
85    Unit = sys::cusparseDiagType_t::CUSPARSE_DIAG_TYPE_UNIT as _,
86}
87
88impl_enum_conversion!(sys::cusparseDiagType_t, DiagonalType);
89
90/// Selects whether matrix indices are zero-based or one-based.
91#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, TryFromPrimitive, IntoPrimitive)]
92#[repr(u32)]
93pub enum IndexBase {
94    /// The base index is zero (C compatibility).
95    Zero = sys::cusparseIndexBase_t::CUSPARSE_INDEX_BASE_ZERO as _,
96    /// The base index is one (one-based indexing compatibility).
97    One = sys::cusparseIndexBase_t::CUSPARSE_INDEX_BASE_ONE as _,
98}
99
100impl_enum_conversion!(sys::cusparseIndexBase_t, IndexBase);
101
102/// Selects the operation applied to an input, such as a sparse matrix or vector.
103#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, TryFromPrimitive, IntoPrimitive)]
104#[repr(u32)]
105pub enum Operation {
106    /// Non-transpose operation.
107    NonTranspose = sys::cusparseOperation_t::CUSPARSE_OPERATION_NON_TRANSPOSE as _,
108    /// Transpose operation.
109    Transpose = sys::cusparseOperation_t::CUSPARSE_OPERATION_TRANSPOSE as _,
110    /// Conjugate transpose operation.
111    ConjugateTranspose = sys::cusparseOperation_t::CUSPARSE_OPERATION_CONJUGATE_TRANSPOSE as _,
112}
113
114impl Operation {
115    pub const HERMITIAN: Self = Self::ConjugateTranspose;
116}
117
118impl_enum_conversion!(sys::cusparseOperation_t, Operation);
119
120/// Selects whether dense matrix elements are scanned by rows or columns in `cusparse[S|D|C|Z]nnz`.
121/// This also controls block storage format in BSR matrices.
122#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, TryFromPrimitive, IntoPrimitive)]
123#[repr(u32)]
124pub enum Direction {
125    /// Matrix elements are scanned by rows.
126    Row = sys::cusparseDirection_t::CUSPARSE_DIRECTION_ROW as _,
127    /// Matrix elements are scanned by columns.
128    Column = sys::cusparseDirection_t::CUSPARSE_DIRECTION_COLUMN as _,
129}
130
131impl_enum_conversion!(sys::cusparseDirection_t, Direction);
132
133#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, TryFromPrimitive, IntoPrimitive)]
134#[repr(u32)]
135pub enum ColorAlgorithm {
136    Algorithm0 = sys::cusparseColorAlg_t::CUSPARSE_COLOR_ALG0 as _,
137    Algorithm1 = sys::cusparseColorAlg_t::CUSPARSE_COLOR_ALG1 as _,
138}
139
140impl_enum_conversion!(sys::cusparseColorAlg_t, ColorAlgorithm);
141
142#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, TryFromPrimitive, IntoPrimitive)]
143#[repr(u32)]
144pub enum CsrToCscAlgorithm {
145    Default = sys::cusparseCsr2CscAlg_t::CUSPARSE_CSR2CSC_ALG_DEFAULT as _,
146}
147
148impl_enum_conversion!(sys::cusparseCsr2CscAlg_t, CsrToCscAlgorithm);
149
150/// Describes the sparse matrix storage format.
151#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, TryFromPrimitive, IntoPrimitive)]
152#[repr(u32)]
153pub enum Format {
154    /// The matrix is stored in Compressed Sparse Row (CSR) format.
155    Csr = sys::cusparseFormat_t::CUSPARSE_FORMAT_CSR as _,
156    /// The matrix is stored in Compressed Sparse Column (CSC) format.
157    Csc = sys::cusparseFormat_t::CUSPARSE_FORMAT_CSC as _,
158    /// The matrix is stored in Coordinate (COO) format organized in *Structure of Arrays (SoA)* layout.
159    Coo = sys::cusparseFormat_t::CUSPARSE_FORMAT_COO as _,
160    /// The matrix is stored in Blocked-Ellpack (Blocked-ELL) format.
161    BlockedEll = sys::cusparseFormat_t::CUSPARSE_FORMAT_BLOCKED_ELL as _,
162    /// The matrix is stored in Block Sparse Row (BSR) format.
163    Bsr = sys::cusparseFormat_t::CUSPARSE_FORMAT_BSR as _,
164    SlicedEllpack = sys::cusparseFormat_t::CUSPARSE_FORMAT_SLICED_ELLPACK as _,
165}
166
167impl_enum_conversion!(sys::cusparseFormat_t, Format);
168
169/// Describes the memory layout of a dense matrix.
170#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, TryFromPrimitive, IntoPrimitive)]
171#[repr(u32)]
172pub enum Order {
173    /// The matrix is stored in column-major.
174    Column = sys::cusparseOrder_t::CUSPARSE_ORDER_COL as _,
175    /// The matrix is stored in row-major.
176    Row = sys::cusparseOrder_t::CUSPARSE_ORDER_ROW as _,
177}
178
179impl_enum_conversion!(sys::cusparseOrder_t, Order);
180
181/// Describes the integer type used for sparse matrix indices.
182#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, TryFromPrimitive, IntoPrimitive)]
183#[repr(u32)]
184pub enum IndexType {
185    I16 = sys::cusparseIndexType_t::CUSPARSE_INDEX_16U as _,
186    /// 32-bit signed integer \[0, 2^31 - 1\].
187    I32 = sys::cusparseIndexType_t::CUSPARSE_INDEX_32I as _,
188    /// 64-bit signed integer \[0, 2^63 - 1\].
189    I64 = sys::cusparseIndexType_t::CUSPARSE_INDEX_64I as _,
190}
191
192impl_enum_conversion!(sys::cusparseIndexType_t, IndexType);
193
194#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, TryFromPrimitive, IntoPrimitive)]
195#[repr(u32)]
196pub enum SparseMatrixAttribute {
197    FillMode = sys::cusparseSpMatAttribute_t::CUSPARSE_SPMAT_FILL_MODE as _,
198    DiagonalType = sys::cusparseSpMatAttribute_t::CUSPARSE_SPMAT_DIAG_TYPE as _,
199}
200
201impl_enum_conversion!(sys::cusparseSpMatAttribute_t, SparseMatrixAttribute);
202
203pub trait IndexTypeLike: Copy + 'static {
204    fn index_type() -> IndexType;
205}
206
207impl IndexTypeLike for u16 {
208    fn index_type() -> IndexType {
209        IndexType::I16
210    }
211}
212
213impl IndexTypeLike for i32 {
214    fn index_type() -> IndexType {
215        IndexType::I32
216    }
217}
218
219impl IndexTypeLike for i64 {
220    fn index_type() -> IndexType {
221        IndexType::I64
222    }
223}
224
225#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, TryFromPrimitive, IntoPrimitive)]
226#[repr(u32)]
227pub enum SpMvAlgorithm {
228    Default = sys::cusparseSpMVAlg_t::CUSPARSE_SPMV_ALG_DEFAULT as _,
229    Csr1 = sys::cusparseSpMVAlg_t::CUSPARSE_SPMV_CSR_ALG1 as _,
230    Csr2 = sys::cusparseSpMVAlg_t::CUSPARSE_SPMV_CSR_ALG2 as _,
231    Coo1 = sys::cusparseSpMVAlg_t::CUSPARSE_SPMV_COO_ALG1 as _,
232    Coo2 = sys::cusparseSpMVAlg_t::CUSPARSE_SPMV_COO_ALG2 as _,
233    Sell1 = sys::cusparseSpMVAlg_t::CUSPARSE_SPMV_SELL_ALG1 as _,
234    Bsr1 = sys::cusparseSpMVAlg_t::CUSPARSE_SPMV_BSR_ALG1 as _,
235}
236
237impl_enum_conversion!(sys::cusparseSpMVAlg_t, SpMvAlgorithm);
238
239#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, TryFromPrimitive, IntoPrimitive)]
240#[repr(u32)]
241pub enum SpSvAlgorithm {
242    Default = sys::cusparseSpSVAlg_t::CUSPARSE_SPSV_ALG_DEFAULT as _,
243}
244
245impl_enum_conversion!(sys::cusparseSpSVAlg_t, SpSvAlgorithm);
246
247#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, TryFromPrimitive, IntoPrimitive)]
248#[repr(u32)]
249pub enum SpSvUpdate {
250    General = sys::cusparseSpSVUpdate_t::CUSPARSE_SPSV_UPDATE_GENERAL as _,
251    Diagonal = sys::cusparseSpSVUpdate_t::CUSPARSE_SPSV_UPDATE_DIAGONAL as _,
252}
253
254impl_enum_conversion!(sys::cusparseSpSVUpdate_t, SpSvUpdate);
255
256#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, TryFromPrimitive, IntoPrimitive)]
257#[repr(u32)]
258pub enum SpSMAlgorithm {
259    Default = sys::cusparseSpSMAlg_t::CUSPARSE_SPSM_ALG_DEFAULT as _,
260}
261
262impl_enum_conversion!(sys::cusparseSpSMAlg_t, SpSMAlgorithm);
263
264#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, TryFromPrimitive, IntoPrimitive)]
265#[repr(u32)]
266pub enum SpSmUpdate {
267    General = sys::cusparseSpSMUpdate_t::CUSPARSE_SPSM_UPDATE_GENERAL as _,
268    Diagonal = sys::cusparseSpSMUpdate_t::CUSPARSE_SPSM_UPDATE_DIAGONAL as _,
269}
270
271impl_enum_conversion!(sys::cusparseSpSMUpdate_t, SpSmUpdate);
272
273#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, TryFromPrimitive, IntoPrimitive)]
274#[repr(u32)]
275pub enum SparseToDenseAlgorithm {
276    Default = sys::cusparseSparseToDenseAlg_t::CUSPARSE_SPARSETODENSE_ALG_DEFAULT as _,
277}
278
279impl_enum_conversion!(sys::cusparseSparseToDenseAlg_t, SparseToDenseAlgorithm);
280
281#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, TryFromPrimitive, IntoPrimitive)]
282#[repr(u32)]
283pub enum DenseToSparseAlgorithm {
284    Default = sys::cusparseDenseToSparseAlg_t::CUSPARSE_DENSETOSPARSE_ALG_DEFAULT as _,
285}
286
287impl_enum_conversion!(sys::cusparseDenseToSparseAlg_t, DenseToSparseAlgorithm);
288
289#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, TryFromPrimitive, IntoPrimitive)]
290#[repr(u32)]
291pub enum SpMmAlgorithm {
292    Default = sys::cusparseSpMMAlg_t::CUSPARSE_SPMM_ALG_DEFAULT as _,
293    Coo1 = sys::cusparseSpMMAlg_t::CUSPARSE_SPMM_COO_ALG1 as _,
294    Coo2 = sys::cusparseSpMMAlg_t::CUSPARSE_SPMM_COO_ALG2 as _,
295    Coo3 = sys::cusparseSpMMAlg_t::CUSPARSE_SPMM_COO_ALG3 as _,
296    Coo4 = sys::cusparseSpMMAlg_t::CUSPARSE_SPMM_COO_ALG4 as _,
297    Csr1 = sys::cusparseSpMMAlg_t::CUSPARSE_SPMM_CSR_ALG1 as _,
298    Csr2 = sys::cusparseSpMMAlg_t::CUSPARSE_SPMM_CSR_ALG2 as _,
299    Csr3 = sys::cusparseSpMMAlg_t::CUSPARSE_SPMM_CSR_ALG3 as _,
300    BlockedEll1 = sys::cusparseSpMMAlg_t::CUSPARSE_SPMM_BLOCKED_ELL_ALG1 as _,
301    Bsr1 = sys::cusparseSpMMAlg_t::CUSPARSE_SPMM_BSR_ALG1 as _,
302}
303
304impl_enum_conversion!(sys::cusparseSpMMAlg_t, SpMmAlgorithm);
305
306#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, TryFromPrimitive, IntoPrimitive)]
307#[repr(u32)]
308pub enum SpMmOpAlgorithm {
309    Default = sys::cusparseSpMMOpAlg_t::CUSPARSE_SPMM_OP_ALG_DEFAULT as _,
310}
311
312impl_enum_conversion!(sys::cusparseSpMMOpAlg_t, SpMmOpAlgorithm);
313
314#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, TryFromPrimitive, IntoPrimitive)]
315#[repr(u32)]
316pub enum SpGemmAlgorithm {
317    Default = sys::cusparseSpGEMMAlg_t::CUSPARSE_SPGEMM_DEFAULT as _,
318    CsrDeterministic = sys::cusparseSpGEMMAlg_t::CUSPARSE_SPGEMM_CSR_ALG_DETERMINITIC as _,
319    CsrNondeterministic = sys::cusparseSpGEMMAlg_t::CUSPARSE_SPGEMM_CSR_ALG_NONDETERMINITIC as _,
320    Algorithm1 = sys::cusparseSpGEMMAlg_t::CUSPARSE_SPGEMM_ALG1 as _,
321    Algorithm2 = sys::cusparseSpGEMMAlg_t::CUSPARSE_SPGEMM_ALG2 as _,
322    Algorithm3 = sys::cusparseSpGEMMAlg_t::CUSPARSE_SPGEMM_ALG3 as _,
323}
324
325impl_enum_conversion!(sys::cusparseSpGEMMAlg_t, SpGemmAlgorithm);
326
327#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, TryFromPrimitive, IntoPrimitive)]
328#[repr(u32)]
329pub enum SddmmAlgorithm {
330    Default = sys::cusparseSDDMMAlg_t::CUSPARSE_SDDMM_ALG_DEFAULT as _,
331}
332
333impl_enum_conversion!(sys::cusparseSDDMMAlg_t, SddmmAlgorithm);
334
335impl Display for PointerMode {
336    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
337        match self {
338            Self::Host => write!(f, "CUSPARSE_POINTER_MODE_HOST"),
339            Self::Device => write!(f, "CUSPARSE_POINTER_MODE_DEVICE"),
340        }
341    }
342}
343
344impl Display for Action {
345    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
346        match self {
347            Self::Symbolic => write!(f, "CUSPARSE_ACTION_SYMBOLIC"),
348            Self::Numeric => write!(f, "CUSPARSE_ACTION_NUMERIC"),
349        }
350    }
351}
352
353impl Display for MatrixType {
354    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
355        match self {
356            Self::General => write!(f, "CUSPARSE_MATRIX_TYPE_GENERAL"),
357            Self::Symmetric => write!(f, "CUSPARSE_MATRIX_TYPE_SYMMETRIC"),
358            Self::Hermitian => write!(f, "CUSPARSE_MATRIX_TYPE_HERMITIAN"),
359            Self::Triangular => write!(f, "CUSPARSE_MATRIX_TYPE_TRIANGULAR"),
360        }
361    }
362}
363
364impl Display for FillMode {
365    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
366        match self {
367            Self::Lower => write!(f, "CUSPARSE_FILL_MODE_LOWER"),
368            Self::Upper => write!(f, "CUSPARSE_FILL_MODE_UPPER"),
369        }
370    }
371}
372
373impl Display for DiagonalType {
374    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
375        match self {
376            Self::NonUnit => write!(f, "CUSPARSE_DIAG_TYPE_NON_UNIT"),
377            Self::Unit => write!(f, "CUSPARSE_DIAG_TYPE_UNIT"),
378        }
379    }
380}
381
382impl Display for IndexBase {
383    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
384        match self {
385            Self::Zero => write!(f, "CUSPARSE_INDEX_BASE_ZERO"),
386            Self::One => write!(f, "CUSPARSE_INDEX_BASE_ONE"),
387        }
388    }
389}
390
391impl Display for Operation {
392    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
393        match self {
394            Self::NonTranspose => write!(f, "CUSPARSE_OPERATION_NON_TRANSPOSE"),
395            Self::Transpose => write!(f, "CUSPARSE_OPERATION_TRANSPOSE"),
396            Self::ConjugateTranspose => write!(f, "CUSPARSE_OPERATION_CONJUGATE_TRANSPOSE"),
397        }
398    }
399}
400
401impl Display for Direction {
402    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
403        match self {
404            Self::Row => write!(f, "CUSPARSE_DIRECTION_ROW"),
405            Self::Column => write!(f, "CUSPARSE_DIRECTION_COLUMN"),
406        }
407    }
408}
409
410impl Display for ColorAlgorithm {
411    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
412        match self {
413            Self::Algorithm0 => write!(f, "CUSPARSE_COLOR_ALG0"),
414            Self::Algorithm1 => write!(f, "CUSPARSE_COLOR_ALG1"),
415        }
416    }
417}
418
419impl Display for CsrToCscAlgorithm {
420    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
421        match self {
422            Self::Default => write!(f, "CUSPARSE_CSR2CSC_ALG_DEFAULT"),
423        }
424    }
425}
426
427impl Display for Format {
428    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
429        match self {
430            Self::Csr => write!(f, "CUSPARSE_FORMAT_CSR"),
431            Self::Csc => write!(f, "CUSPARSE_FORMAT_CSC"),
432            Self::Coo => write!(f, "CUSPARSE_FORMAT_COO"),
433            Self::BlockedEll => write!(f, "CUSPARSE_FORMAT_BLOCKED_ELL"),
434            Self::Bsr => write!(f, "CUSPARSE_FORMAT_BSR"),
435            Self::SlicedEllpack => write!(f, "CUSPARSE_FORMAT_SLICED_ELLPACK"),
436        }
437    }
438}
439
440impl Display for Order {
441    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
442        match self {
443            Self::Column => write!(f, "CUSPARSE_ORDER_COL"),
444            Self::Row => write!(f, "CUSPARSE_ORDER_ROW"),
445        }
446    }
447}
448
449impl Display for IndexType {
450    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
451        match self {
452            Self::I16 => write!(f, "CUSPARSE_INDEX_16U"),
453            Self::I32 => write!(f, "CUSPARSE_INDEX_32I"),
454            Self::I64 => write!(f, "CUSPARSE_INDEX_64I"),
455        }
456    }
457}
458
459impl Display for SparseMatrixAttribute {
460    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
461        match self {
462            Self::FillMode => write!(f, "CUSPARSE_SPMAT_FILL_MODE"),
463            Self::DiagonalType => write!(f, "CUSPARSE_SPMAT_DIAG_TYPE"),
464        }
465    }
466}
467
468impl Display for SpMvAlgorithm {
469    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
470        match self {
471            Self::Default => write!(f, "CUSPARSE_SPMV_ALG_DEFAULT"),
472            Self::Csr1 => write!(f, "CUSPARSE_SPMV_CSR_ALG1"),
473            Self::Csr2 => write!(f, "CUSPARSE_SPMV_CSR_ALG2"),
474            Self::Coo1 => write!(f, "CUSPARSE_SPMV_COO_ALG1"),
475            Self::Coo2 => write!(f, "CUSPARSE_SPMV_COO_ALG2"),
476            Self::Sell1 => write!(f, "CUSPARSE_SPMV_SELL_ALG1"),
477            Self::Bsr1 => write!(f, "CUSPARSE_SPMV_BSR_ALG1"),
478        }
479    }
480}
481
482impl Display for SpSvAlgorithm {
483    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
484        match self {
485            Self::Default => write!(f, "CUSPARSE_SPSV_ALG_DEFAULT"),
486        }
487    }
488}
489
490impl Display for SpSvUpdate {
491    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
492        match self {
493            Self::General => write!(f, "CUSPARSE_SPSV_UPDATE_GENERAL"),
494            Self::Diagonal => write!(f, "CUSPARSE_SPSV_UPDATE_DIAGONAL"),
495        }
496    }
497}
498
499impl Display for SpSMAlgorithm {
500    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
501        match self {
502            Self::Default => write!(f, "CUSPARSE_SPSM_ALG_DEFAULT"),
503        }
504    }
505}
506
507impl Display for SpSmUpdate {
508    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
509        match self {
510            Self::General => write!(f, "CUSPARSE_SPSM_UPDATE_GENERAL"),
511            Self::Diagonal => write!(f, "CUSPARSE_SPSM_UPDATE_DIAGONAL"),
512        }
513    }
514}
515
516impl Display for SparseToDenseAlgorithm {
517    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
518        match self {
519            Self::Default => write!(f, "CUSPARSE_SPARSETODENSE_ALG_DEFAULT"),
520        }
521    }
522}
523
524impl Display for DenseToSparseAlgorithm {
525    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
526        match self {
527            Self::Default => write!(f, "CUSPARSE_DENSETOSPARSE_ALG_DEFAULT"),
528        }
529    }
530}
531
532impl Display for SpMmAlgorithm {
533    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
534        match self {
535            Self::Default => write!(f, "CUSPARSE_SPMM_ALG_DEFAULT"),
536            Self::Coo1 => write!(f, "CUSPARSE_SPMM_COO_ALG1"),
537            Self::Coo2 => write!(f, "CUSPARSE_SPMM_COO_ALG2"),
538            Self::Coo3 => write!(f, "CUSPARSE_SPMM_COO_ALG3"),
539            Self::Coo4 => write!(f, "CUSPARSE_SPMM_COO_ALG4"),
540            Self::Csr1 => write!(f, "CUSPARSE_SPMM_CSR_ALG1"),
541            Self::Csr2 => write!(f, "CUSPARSE_SPMM_CSR_ALG2"),
542            Self::Csr3 => write!(f, "CUSPARSE_SPMM_CSR_ALG3"),
543            Self::BlockedEll1 => write!(f, "CUSPARSE_SPMM_BLOCKED_ELL_ALG1"),
544            Self::Bsr1 => write!(f, "CUSPARSE_SPMM_BSR_ALG1"),
545        }
546    }
547}
548
549impl Display for SpMmOpAlgorithm {
550    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
551        match self {
552            Self::Default => write!(f, "CUSPARSE_SPMM_OP_ALG_DEFAULT"),
553        }
554    }
555}
556
557impl Display for SpGemmAlgorithm {
558    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
559        match self {
560            Self::Default => write!(f, "CUSPARSE_SPGEMM_DEFAULT"),
561            Self::CsrDeterministic => {
562                write!(f, "CUSPARSE_SPGEMM_CSR_ALG_DETERMINITIC")
563            }
564            Self::CsrNondeterministic => {
565                write!(f, "CUSPARSE_SPGEMM_CSR_ALG_NONDETERMINITIC")
566            }
567            Self::Algorithm1 => write!(f, "CUSPARSE_SPGEMM_ALG1"),
568            Self::Algorithm2 => write!(f, "CUSPARSE_SPGEMM_ALG2"),
569            Self::Algorithm3 => write!(f, "CUSPARSE_SPGEMM_ALG3"),
570        }
571    }
572}
573
574impl Display for SddmmAlgorithm {
575    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
576        match self {
577            Self::Default => write!(f, "CUSPARSE_SDDMM_ALG_DEFAULT"),
578        }
579    }
580}