baracuda-cusolver-sys 0.0.1-alpha.78

Raw FFI bindings and dynamic loader for NVIDIA cuSOLVER (Dn subset).
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
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
//! Raw FFI + dynamic loader for NVIDIA cuSOLVER (Dense + Sparse + Refactor).
//!
//! `baracuda-cusolver` wraps this with a safe, typed API. Use this
//! crate directly only if you need a function that the safe layer
//! hasn't wrapped yet (in which case please file a bug).

#![allow(non_camel_case_types, non_snake_case, non_upper_case_globals)]
#![warn(missing_debug_implementations)]

use core::ffi::{c_int, c_void};
use std::sync::OnceLock;

use baracuda_core::{Library, LoaderError, platform};
use baracuda_cuda_sys::runtime::cudaStream_t;
use baracuda_types::CudaStatus;

// ---- handles --------------------------------------------------------------

/// Opaque dense cuSOLVER handle.
pub type cusolverDnHandle_t = *mut c_void;
/// Opaque sparse cuSOLVER handle.
pub type cusolverSpHandle_t = *mut c_void;
/// Opaque sparse-refactor cuSOLVER handle.
pub type cusolverRfHandle_t = *mut c_void;
/// Opaque generic-API parameter object for `cusolverDnX*` routines.
pub type cusolverDnParams_t = *mut c_void;
/// Opaque parameter object for iterative-refinement solvers.
pub type cusolverDnIRSParams_t = *mut c_void;
/// Opaque info object for iterative-refinement solvers.
pub type cusolverDnIRSInfos_t = *mut c_void;
/// Opaque control object for Jacobi-based symmetric eigendecomposition.
pub type syevjInfo_t = *mut c_void;
/// Opaque control object for Jacobi-based SVD.
pub type gesvdjInfo_t = *mut c_void;

// ---- enums ----------------------------------------------------------------

/// Transpose selector — same values as `cublasOperation_t` (N=0, T=1, C=2).
#[repr(i32)]
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum cublasOperation_t {
    /// No transpose.
    N = 0,
    /// Transpose.
    T = 1,
    /// Conjugate transpose.
    C = 2,
}

/// Triangular fill mode (matches the cuBLAS enum).
#[repr(i32)]
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum cublasFillMode_t {
    /// Lower-triangular.
    Lower = 0,
    /// Upper-triangular.
    Upper = 1,
    /// Full / dense matrix.
    Full = 2,
}

/// Side selector for one-sided operators (apply from left or right).
#[repr(i32)]
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum cublasSideMode_t {
    /// Apply from the left.
    Left = 0,
    /// Apply from the right.
    Right = 1,
}

/// Diagonal-unit selector (matches the cuBLAS enum).
#[repr(i32)]
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum cublasDiagType_t {
    /// Non-unit diagonal.
    NonUnit = 0,
    /// Unit diagonal.
    Unit = 1,
}

/// Generalized eigenproblem variant for `sygv*` / `hegv*` routines.
#[repr(i32)]
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum cusolverEigType_t {
    /// Type-1 generalized eigenproblem: `A*x = lambda*B*x`.
    Type1 = 1,
    /// Type-2 generalized eigenproblem: `A*B*x = lambda*x`.
    Type2 = 2,
    /// Type-3 generalized eigenproblem: `B*A*x = lambda*x`.
    Type3 = 3,
}

/// Eigenvalue-only vs eigenvalue-and-vector selector for eigensolvers.
#[repr(i32)]
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum cusolverEigMode_t {
    /// Compute eigenvalues only.
    NoVector = 0,
    /// Compute eigenvalues and eigenvectors.
    Vector = 1,
}

/// Subset-of-spectrum selector for partial eigensolvers.
#[repr(i32)]
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum cusolverEigRange_t {
    /// Compute all eigenvalues.
    All = 1001,
    /// Compute eigenvalues with indices in `[il, iu]`.
    I = 1002,
    /// Compute eigenvalues in the half-open interval `(vl, vu]`.
    V = 1003,
}

/// Element-dtype selector used by the generic-API (`cusolverDnX*`) routines.
#[repr(i32)]
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum cudaDataType {
    /// 32-bit real (`f32`).
    R_32F = 0,
    /// 64-bit real (`f64`).
    R_64F = 1,
    /// 16-bit real (IEEE half / `f16`).
    R_16F = 2,
    /// 32-bit complex (`Complex<f32>`).
    C_32F = 4,
    /// 64-bit complex (`Complex<f64>`).
    C_64F = 5,
    /// 16-bit real bfloat16.
    R_16BF = 14,
}

// ---- status ---------------------------------------------------------------

/// Status / error code returned by cuSOLVER FFI calls.
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[repr(transparent)]
pub struct cusolverStatus_t(pub i32);

impl cusolverStatus_t {
    /// Status: success.
    pub const SUCCESS: Self = Self(0);
    /// Status: not initialized.
    pub const NOT_INITIALIZED: Self = Self(1);
    /// Status: alloc failed.
    pub const ALLOC_FAILED: Self = Self(2);
    /// Status: invalid value.
    pub const INVALID_VALUE: Self = Self(3);
    /// Status: arch mismatch.
    pub const ARCH_MISMATCH: Self = Self(4);
    /// Status: execution failed.
    pub const EXECUTION_FAILED: Self = Self(6);
    /// Status: internal error.
    pub const INTERNAL_ERROR: Self = Self(7);
    /// Status: not supported.
    pub const NOT_SUPPORTED: Self = Self(9);
    /// Status: zero pivot.
    pub const ZERO_PIVOT: Self = Self(10);

    /// Returns `true` when this is the success status code.
    pub const fn is_success(self) -> bool {
        self.0 == 0
    }
}

impl CudaStatus for cusolverStatus_t {
    fn code(self) -> i32 {
        self.0
    }
    fn name(self) -> &'static str {
        match self.0 {
            0 => "CUSOLVER_STATUS_SUCCESS",
            1 => "CUSOLVER_STATUS_NOT_INITIALIZED",
            2 => "CUSOLVER_STATUS_ALLOC_FAILED",
            3 => "CUSOLVER_STATUS_INVALID_VALUE",
            6 => "CUSOLVER_STATUS_EXECUTION_FAILED",
            7 => "CUSOLVER_STATUS_INTERNAL_ERROR",
            9 => "CUSOLVER_STATUS_NOT_SUPPORTED",
            10 => "CUSOLVER_STATUS_ZERO_PIVOT",
            _ => "CUSOLVER_STATUS_UNRECOGNIZED",
        }
    }
    fn description(self) -> &'static str {
        match self.0 {
            0 => "success",
            1 => "cuSOLVER not initialized",
            6 => "execution failed on device",
            10 => "factorization produced a zero pivot",
            _ => "unrecognized cuSOLVER status code",
        }
    }
    fn is_success(self) -> bool {
        cusolverStatus_t::is_success(self)
    }
    fn library(self) -> &'static str {
        "cusolver"
    }
}

// ---- complex types (alias to plain 2-element arrays) ---------------------

/// Single-precision complex number, ABI-compatible with cuBLAS / cuSOLVER `cuComplex`.
#[repr(C)]
#[derive(Copy, Clone, Debug)]
pub struct cuComplex {
    /// Real component (`f32`).
    pub x: f32,
    /// Imaginary component (`f32`).
    pub y: f32,
}

/// Double-precision complex number, ABI-compatible with cuBLAS / cuSOLVER `cuDoubleComplex`.
#[repr(C)]
#[derive(Copy, Clone, Debug)]
pub struct cuDoubleComplex {
    /// Real component (`f64`).
    pub x: f64,
    /// Imaginary component (`f64`).
    pub y: f64,
}

// ---- PFN type declaration macros -----------------------------------------

/// `getrf_bufferSize(handle, m, n, a, lda, lwork) -> status`
macro_rules! dn_getrf_bufsize {
    ($(#[$attr:meta])* $name:ident, $t:ty) => {
        $(#[$attr])*
        pub type $name = unsafe extern "C" fn(
            handle: cusolverDnHandle_t,
            m: c_int,
            n: c_int,
            a: *mut $t,
            lda: c_int,
            lwork: *mut c_int,
        ) -> cusolverStatus_t;
    };
}

macro_rules! dn_getrf {
    ($(#[$attr:meta])* $name:ident, $t:ty) => {
        $(#[$attr])*
        pub type $name = unsafe extern "C" fn(
            handle: cusolverDnHandle_t,
            m: c_int,
            n: c_int,
            a: *mut $t,
            lda: c_int,
            workspace: *mut $t,
            ipiv: *mut c_int,
            info: *mut c_int,
        ) -> cusolverStatus_t;
    };
}

macro_rules! dn_getrs {
    ($(#[$attr:meta])* $name:ident, $t:ty) => {
        $(#[$attr])*
        pub type $name = unsafe extern "C" fn(
            handle: cusolverDnHandle_t,
            trans: cublasOperation_t,
            n: c_int,
            nrhs: c_int,
            a: *const $t,
            lda: c_int,
            ipiv: *const c_int,
            b: *mut $t,
            ldb: c_int,
            info: *mut c_int,
        ) -> cusolverStatus_t;
    };
}

macro_rules! dn_geqrf_bufsize {
    ($(#[$attr:meta])* $name:ident, $t:ty) => {
        $(#[$attr])*
        pub type $name = unsafe extern "C" fn(
            handle: cusolverDnHandle_t,
            m: c_int,
            n: c_int,
            a: *mut $t,
            lda: c_int,
            lwork: *mut c_int,
        ) -> cusolverStatus_t;
    };
}

macro_rules! dn_geqrf {
    ($(#[$attr:meta])* $name:ident, $t:ty) => {
        $(#[$attr])*
        pub type $name = unsafe extern "C" fn(
            handle: cusolverDnHandle_t,
            m: c_int,
            n: c_int,
            a: *mut $t,
            lda: c_int,
            tau: *mut $t,
            workspace: *mut $t,
            lwork: c_int,
            info: *mut c_int,
        ) -> cusolverStatus_t;
    };
}

macro_rules! dn_potrf_bufsize {
    ($(#[$attr:meta])* $name:ident, $t:ty) => {
        $(#[$attr])*
        pub type $name = unsafe extern "C" fn(
            handle: cusolverDnHandle_t,
            uplo: cublasFillMode_t,
            n: c_int,
            a: *mut $t,
            lda: c_int,
            lwork: *mut c_int,
        ) -> cusolverStatus_t;
    };
}

macro_rules! dn_potrf {
    ($(#[$attr:meta])* $name:ident, $t:ty) => {
        $(#[$attr])*
        pub type $name = unsafe extern "C" fn(
            handle: cusolverDnHandle_t,
            uplo: cublasFillMode_t,
            n: c_int,
            a: *mut $t,
            lda: c_int,
            workspace: *mut $t,
            lwork: c_int,
            info: *mut c_int,
        ) -> cusolverStatus_t;
    };
}

macro_rules! dn_potrs {
    ($(#[$attr:meta])* $name:ident, $t:ty) => {
        $(#[$attr])*
        pub type $name = unsafe extern "C" fn(
            handle: cusolverDnHandle_t,
            uplo: cublasFillMode_t,
            n: c_int,
            nrhs: c_int,
            a: *const $t,
            lda: c_int,
            b: *mut $t,
            ldb: c_int,
            info: *mut c_int,
        ) -> cusolverStatus_t;
    };
}

macro_rules! dn_gesvd_bufsize {
    ($(#[$attr:meta])* $name:ident) => {
        $(#[$attr])*
        pub type $name = unsafe extern "C" fn(
            handle: cusolverDnHandle_t,
            m: c_int,
            n: c_int,
            lwork: *mut c_int,
        ) -> cusolverStatus_t;
    };
}

macro_rules! dn_gesvd_real {
    ($(#[$attr:meta])* $name:ident, $t:ty) => {
        $(#[$attr])*
        pub type $name = unsafe extern "C" fn(
            handle: cusolverDnHandle_t,
            jobu: u8,
            jobvt: u8,
            m: c_int,
            n: c_int,
            a: *mut $t,
            lda: c_int,
            s: *mut $t,
            u: *mut $t,
            ldu: c_int,
            vt: *mut $t,
            ldvt: c_int,
            work: *mut $t,
            lwork: c_int,
            rwork: *mut $t,
            info: *mut c_int,
        ) -> cusolverStatus_t;
    };
}

macro_rules! dn_gesvd_complex {
    ($(#[$attr:meta])* $name:ident, $t:ty, $real:ty) => {
        $(#[$attr])*
        pub type $name = unsafe extern "C" fn(
            handle: cusolverDnHandle_t,
            jobu: u8,
            jobvt: u8,
            m: c_int,
            n: c_int,
            a: *mut $t,
            lda: c_int,
            s: *mut $real,
            u: *mut $t,
            ldu: c_int,
            vt: *mut $t,
            ldvt: c_int,
            work: *mut $t,
            lwork: c_int,
            rwork: *mut $real,
            info: *mut c_int,
        ) -> cusolverStatus_t;
    };
}

macro_rules! dn_syevd_bufsize {
    ($(#[$attr:meta])* $name:ident, $t:ty, $real:ty) => {
        $(#[$attr])*
        pub type $name = unsafe extern "C" fn(
            handle: cusolverDnHandle_t,
            jobz: cusolverEigMode_t,
            uplo: cublasFillMode_t,
            n: c_int,
            a: *const $t,
            lda: c_int,
            w: *const $real,
            lwork: *mut c_int,
        ) -> cusolverStatus_t;
    };
}

macro_rules! dn_syevd {
    ($(#[$attr:meta])* $name:ident, $t:ty, $real:ty) => {
        $(#[$attr])*
        pub type $name = unsafe extern "C" fn(
            handle: cusolverDnHandle_t,
            jobz: cusolverEigMode_t,
            uplo: cublasFillMode_t,
            n: c_int,
            a: *mut $t,
            lda: c_int,
            w: *mut $real,
            work: *mut $t,
            lwork: c_int,
            info: *mut c_int,
        ) -> cusolverStatus_t;
    };
}

// ---- core Dn handle ------------------------------------------------------

/// cuSOLVER: create a dense cuSOLVER handle. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
pub type PFN_cusolverDnCreate =
    unsafe extern "C" fn(handle: *mut cusolverDnHandle_t) -> cusolverStatus_t;
/// cuSOLVER: destroy a dense cuSOLVER handle. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
pub type PFN_cusolverDnDestroy =
    unsafe extern "C" fn(handle: cusolverDnHandle_t) -> cusolverStatus_t;
/// cuSOLVER: bind a CUDA stream to a dense cuSOLVER handle. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
pub type PFN_cusolverDnSetStream =
    unsafe extern "C" fn(handle: cusolverDnHandle_t, stream: cudaStream_t) -> cusolverStatus_t;
/// cuSOLVER: query the CUDA stream bound to a dense cuSOLVER handle. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
pub type PFN_cusolverDnGetStream =
    unsafe extern "C" fn(handle: cusolverDnHandle_t, stream: *mut cudaStream_t) -> cusolverStatus_t;

/// cuSOLVER: return the cuSOLVER library version. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
pub type PFN_cusolverGetVersion = unsafe extern "C" fn(version: *mut c_int) -> cusolverStatus_t;

// ---- LU factorization (getrf / getrs) — S/D/C/Z --------------------------

dn_getrf_bufsize!(
    #[doc = "cuSOLVER: single-precision workspace-size query for LU factorization with partial pivoting. See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnSgetrf_bufferSize,
    f32
);
dn_getrf_bufsize!(
    #[doc = "cuSOLVER: double-precision workspace-size query for LU factorization with partial pivoting. See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnDgetrf_bufferSize,
    f64
);
dn_getrf_bufsize!(
    #[doc = "cuSOLVER: single-precision complex workspace-size query for LU factorization with partial pivoting. See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnCgetrf_bufferSize,
    cuComplex
);
dn_getrf_bufsize!(
    #[doc = "cuSOLVER: double-precision complex workspace-size query for LU factorization with partial pivoting. See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnZgetrf_bufferSize,
    cuDoubleComplex
);

dn_getrf!(
    #[doc = "cuSOLVER: single-precision LU factorization with partial pivoting. See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnSgetrf,
    f32
);
dn_getrf!(
    #[doc = "cuSOLVER: double-precision LU factorization with partial pivoting. See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnDgetrf,
    f64
);
dn_getrf!(
    #[doc = "cuSOLVER: single-precision complex LU factorization with partial pivoting. See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnCgetrf,
    cuComplex
);
dn_getrf!(
    #[doc = "cuSOLVER: double-precision complex LU factorization with partial pivoting. See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnZgetrf,
    cuDoubleComplex
);

dn_getrs!(
    #[doc = "cuSOLVER: single-precision solve linear system using LU factors. See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnSgetrs,
    f32
);
dn_getrs!(
    #[doc = "cuSOLVER: double-precision solve linear system using LU factors. See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnDgetrs,
    f64
);
dn_getrs!(
    #[doc = "cuSOLVER: single-precision complex solve linear system using LU factors. See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnCgetrs,
    cuComplex
);
dn_getrs!(
    #[doc = "cuSOLVER: double-precision complex solve linear system using LU factors. See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnZgetrs,
    cuDoubleComplex
);

// ---- QR factorization (geqrf) — S/D/C/Z ----------------------------------

dn_geqrf_bufsize!(
    #[doc = "cuSOLVER: single-precision workspace-size query for QR factorization (Householder). See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnSgeqrf_bufferSize,
    f32
);
dn_geqrf_bufsize!(
    #[doc = "cuSOLVER: double-precision workspace-size query for QR factorization (Householder). See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnDgeqrf_bufferSize,
    f64
);
dn_geqrf_bufsize!(
    #[doc = "cuSOLVER: single-precision complex workspace-size query for QR factorization (Householder). See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnCgeqrf_bufferSize,
    cuComplex
);
dn_geqrf_bufsize!(
    #[doc = "cuSOLVER: double-precision complex workspace-size query for QR factorization (Householder). See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnZgeqrf_bufferSize,
    cuDoubleComplex
);

dn_geqrf!(
    #[doc = "cuSOLVER: single-precision QR factorization (Householder). See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnSgeqrf,
    f32
);
dn_geqrf!(
    #[doc = "cuSOLVER: double-precision QR factorization (Householder). See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnDgeqrf,
    f64
);
dn_geqrf!(
    #[doc = "cuSOLVER: single-precision complex QR factorization (Householder). See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnCgeqrf,
    cuComplex
);
dn_geqrf!(
    #[doc = "cuSOLVER: double-precision complex QR factorization (Householder). See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnZgeqrf,
    cuDoubleComplex
);

// ---- Cholesky (potrf / potrs) — S/D/C/Z ----------------------------------

dn_potrf_bufsize!(
    #[doc = "cuSOLVER: single-precision workspace-size query for Cholesky factorization. See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnSpotrf_bufferSize,
    f32
);
dn_potrf_bufsize!(
    #[doc = "cuSOLVER: double-precision workspace-size query for Cholesky factorization. See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnDpotrf_bufferSize,
    f64
);
dn_potrf_bufsize!(
    #[doc = "cuSOLVER: single-precision complex workspace-size query for Cholesky factorization. See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnCpotrf_bufferSize,
    cuComplex
);
dn_potrf_bufsize!(
    #[doc = "cuSOLVER: double-precision complex workspace-size query for Cholesky factorization. See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnZpotrf_bufferSize,
    cuDoubleComplex
);

dn_potrf!(
    #[doc = "cuSOLVER: single-precision Cholesky factorization. See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnSpotrf,
    f32
);
dn_potrf!(
    #[doc = "cuSOLVER: double-precision Cholesky factorization. See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnDpotrf,
    f64
);
dn_potrf!(
    #[doc = "cuSOLVER: single-precision complex Cholesky factorization. See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnCpotrf,
    cuComplex
);
dn_potrf!(
    #[doc = "cuSOLVER: double-precision complex Cholesky factorization. See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnZpotrf,
    cuDoubleComplex
);

dn_potrs!(
    #[doc = "cuSOLVER: single-precision solve linear system using Cholesky factors. See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnSpotrs,
    f32
);
dn_potrs!(
    #[doc = "cuSOLVER: double-precision solve linear system using Cholesky factors. See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnDpotrs,
    f64
);
dn_potrs!(
    #[doc = "cuSOLVER: single-precision complex solve linear system using Cholesky factors. See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnCpotrs,
    cuComplex
);
dn_potrs!(
    #[doc = "cuSOLVER: double-precision complex solve linear system using Cholesky factors. See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnZpotrs,
    cuDoubleComplex
);

// ---- SVD — S/D/C/Z -------------------------------------------------------

dn_gesvd_bufsize!(
    #[doc = "cuSOLVER: single-precision workspace-size query for singular value decomposition. See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnSgesvd_bufferSize
);
dn_gesvd_bufsize!(
    #[doc = "cuSOLVER: double-precision workspace-size query for singular value decomposition. See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnDgesvd_bufferSize
);
dn_gesvd_bufsize!(
    #[doc = "cuSOLVER: single-precision complex workspace-size query for singular value decomposition. See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnCgesvd_bufferSize
);
dn_gesvd_bufsize!(
    #[doc = "cuSOLVER: double-precision complex workspace-size query for singular value decomposition. See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnZgesvd_bufferSize
);

dn_gesvd_real!(
    #[doc = "cuSOLVER: single-precision singular value decomposition. See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnSgesvd,
    f32
);
dn_gesvd_real!(
    #[doc = "cuSOLVER: double-precision singular value decomposition. See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnDgesvd,
    f64
);
dn_gesvd_complex!(
    #[doc = "cuSOLVER: single-precision complex singular value decomposition. See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnCgesvd,
    cuComplex,
    f32
);
dn_gesvd_complex!(
    #[doc = "cuSOLVER: double-precision complex singular value decomposition. See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnZgesvd,
    cuDoubleComplex,
    f64
);

// ---- Symmetric/Hermitian eigendecomposition (syevd/heevd) --------------

dn_syevd_bufsize!(
    #[doc = "cuSOLVER: single-precision workspace-size query for symmetric eigendecomposition (divide-and-conquer). See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnSsyevd_bufferSize,
    f32,
    f32
);
dn_syevd_bufsize!(
    #[doc = "cuSOLVER: double-precision workspace-size query for symmetric eigendecomposition (divide-and-conquer). See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnDsyevd_bufferSize,
    f64,
    f64
);
dn_syevd_bufsize!(
    #[doc = "cuSOLVER: single-precision complex workspace-size query for Hermitian eigendecomposition (divide-and-conquer). See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnCheevd_bufferSize,
    cuComplex,
    f32
);
dn_syevd_bufsize!(
    #[doc = "cuSOLVER: double-precision complex workspace-size query for Hermitian eigendecomposition (divide-and-conquer). See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnZheevd_bufferSize,
    cuDoubleComplex,
    f64
);

dn_syevd!(
    #[doc = "cuSOLVER: single-precision symmetric eigendecomposition (divide-and-conquer). See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnSsyevd,
    f32,
    f32
);
dn_syevd!(
    #[doc = "cuSOLVER: double-precision symmetric eigendecomposition (divide-and-conquer). See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnDsyevd,
    f64,
    f64
);
dn_syevd!(
    #[doc = "cuSOLVER: single-precision complex Hermitian eigendecomposition (divide-and-conquer). See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnCheevd,
    cuComplex,
    f32
);
dn_syevd!(
    #[doc = "cuSOLVER: double-precision complex Hermitian eigendecomposition (divide-and-conquer). See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnZheevd,
    cuDoubleComplex,
    f64
);

// ---- Generic 64-bit / mixed-precision API (cusolverDnX…) ----------------

/// cuSOLVER: create a generic-API parameter object. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
pub type PFN_cusolverDnCreateParams =
    unsafe extern "C" fn(params: *mut cusolverDnParams_t) -> cusolverStatus_t;
/// cuSOLVER: destroy a generic-API parameter object. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
pub type PFN_cusolverDnDestroyParams =
    unsafe extern "C" fn(params: cusolverDnParams_t) -> cusolverStatus_t;

/// cuSOLVER: generic-API workspace-size query for LU factorization with partial pivoting (dtype configurable via `cudaDataType`). See <https://docs.nvidia.com/cuda/cusolver/index.html>.
pub type PFN_cusolverDnXgetrf_bufferSize = unsafe extern "C" fn(
    handle: cusolverDnHandle_t,
    params: cusolverDnParams_t,
    m: i64,
    n: i64,
    data_type_a: cudaDataType,
    a: *const c_void,
    lda: i64,
    compute_type: cudaDataType,
    workspace_in_bytes_on_device: *mut usize,
    workspace_in_bytes_on_host: *mut usize,
) -> cusolverStatus_t;

/// cuSOLVER: generic-API LU factorization with partial pivoting (dtype configurable via `cudaDataType`). See <https://docs.nvidia.com/cuda/cusolver/index.html>.
pub type PFN_cusolverDnXgetrf = unsafe extern "C" fn(
    handle: cusolverDnHandle_t,
    params: cusolverDnParams_t,
    m: i64,
    n: i64,
    data_type_a: cudaDataType,
    a: *mut c_void,
    lda: i64,
    ipiv: *mut i64,
    compute_type: cudaDataType,
    bufferondevice: *mut c_void,
    workspace_in_bytes_on_device: usize,
    bufferonhost: *mut c_void,
    workspace_in_bytes_on_host: usize,
    info: *mut c_int,
) -> cusolverStatus_t;

/// cuSOLVER: generic-API solve linear system using LU factors (dtype configurable via `cudaDataType`). See <https://docs.nvidia.com/cuda/cusolver/index.html>.
pub type PFN_cusolverDnXgetrs = unsafe extern "C" fn(
    handle: cusolverDnHandle_t,
    params: cusolverDnParams_t,
    trans: cublasOperation_t,
    n: i64,
    nrhs: i64,
    data_type_a: cudaDataType,
    a: *const c_void,
    lda: i64,
    ipiv: *const i64,
    data_type_b: cudaDataType,
    b: *mut c_void,
    ldb: i64,
    info: *mut c_int,
) -> cusolverStatus_t;

/// cuSOLVER: generic-API workspace-size query for QR factorization (Householder) (dtype configurable via `cudaDataType`). See <https://docs.nvidia.com/cuda/cusolver/index.html>.
pub type PFN_cusolverDnXgeqrf_bufferSize = unsafe extern "C" fn(
    handle: cusolverDnHandle_t,
    params: cusolverDnParams_t,
    m: i64,
    n: i64,
    data_type_a: cudaDataType,
    a: *const c_void,
    lda: i64,
    data_type_tau: cudaDataType,
    tau: *const c_void,
    compute_type: cudaDataType,
    workspace_in_bytes_on_device: *mut usize,
    workspace_in_bytes_on_host: *mut usize,
) -> cusolverStatus_t;

/// cuSOLVER: generic-API QR factorization (Householder) (dtype configurable via `cudaDataType`). See <https://docs.nvidia.com/cuda/cusolver/index.html>.
pub type PFN_cusolverDnXgeqrf = unsafe extern "C" fn(
    handle: cusolverDnHandle_t,
    params: cusolverDnParams_t,
    m: i64,
    n: i64,
    data_type_a: cudaDataType,
    a: *mut c_void,
    lda: i64,
    data_type_tau: cudaDataType,
    tau: *mut c_void,
    compute_type: cudaDataType,
    bufferondevice: *mut c_void,
    workspace_in_bytes_on_device: usize,
    bufferonhost: *mut c_void,
    workspace_in_bytes_on_host: usize,
    info: *mut c_int,
) -> cusolverStatus_t;

/// cuSOLVER: generic-API workspace-size query for Cholesky factorization (dtype configurable via `cudaDataType`). See <https://docs.nvidia.com/cuda/cusolver/index.html>.
pub type PFN_cusolverDnXpotrf_bufferSize = unsafe extern "C" fn(
    handle: cusolverDnHandle_t,
    params: cusolverDnParams_t,
    uplo: cublasFillMode_t,
    n: i64,
    data_type_a: cudaDataType,
    a: *const c_void,
    lda: i64,
    compute_type: cudaDataType,
    workspace_in_bytes_on_device: *mut usize,
    workspace_in_bytes_on_host: *mut usize,
) -> cusolverStatus_t;

/// cuSOLVER: generic-API Cholesky factorization (dtype configurable via `cudaDataType`). See <https://docs.nvidia.com/cuda/cusolver/index.html>.
pub type PFN_cusolverDnXpotrf = unsafe extern "C" fn(
    handle: cusolverDnHandle_t,
    params: cusolverDnParams_t,
    uplo: cublasFillMode_t,
    n: i64,
    data_type_a: cudaDataType,
    a: *mut c_void,
    lda: i64,
    compute_type: cudaDataType,
    bufferondevice: *mut c_void,
    workspace_in_bytes_on_device: usize,
    bufferonhost: *mut c_void,
    workspace_in_bytes_on_host: usize,
    info: *mut c_int,
) -> cusolverStatus_t;

/// cuSOLVER: generic-API solve linear system using Cholesky factors (dtype configurable via `cudaDataType`). See <https://docs.nvidia.com/cuda/cusolver/index.html>.
pub type PFN_cusolverDnXpotrs = unsafe extern "C" fn(
    handle: cusolverDnHandle_t,
    params: cusolverDnParams_t,
    uplo: cublasFillMode_t,
    n: i64,
    nrhs: i64,
    data_type_a: cudaDataType,
    a: *const c_void,
    lda: i64,
    data_type_b: cudaDataType,
    b: *mut c_void,
    ldb: i64,
    info: *mut c_int,
) -> cusolverStatus_t;

/// cuSOLVER: generic-API workspace-size query for symmetric eigendecomposition (divide-and-conquer) (dtype configurable via `cudaDataType`). See <https://docs.nvidia.com/cuda/cusolver/index.html>.
pub type PFN_cusolverDnXsyevd_bufferSize = unsafe extern "C" fn(
    handle: cusolverDnHandle_t,
    params: cusolverDnParams_t,
    jobz: cusolverEigMode_t,
    uplo: cublasFillMode_t,
    n: i64,
    data_type_a: cudaDataType,
    a: *const c_void,
    lda: i64,
    data_type_w: cudaDataType,
    w: *const c_void,
    compute_type: cudaDataType,
    device_bytes: *mut usize,
    host_bytes: *mut usize,
) -> cusolverStatus_t;

/// cuSOLVER: generic-API symmetric eigendecomposition (divide-and-conquer) (dtype configurable via `cudaDataType`). See <https://docs.nvidia.com/cuda/cusolver/index.html>.
pub type PFN_cusolverDnXsyevd = unsafe extern "C" fn(
    handle: cusolverDnHandle_t,
    params: cusolverDnParams_t,
    jobz: cusolverEigMode_t,
    uplo: cublasFillMode_t,
    n: i64,
    data_type_a: cudaDataType,
    a: *mut c_void,
    lda: i64,
    data_type_w: cudaDataType,
    w: *mut c_void,
    compute_type: cudaDataType,
    bufferondevice: *mut c_void,
    device_bytes: usize,
    bufferonhost: *mut c_void,
    host_bytes: usize,
    info: *mut c_int,
) -> cusolverStatus_t;

// ==========================================================================
// Jacobi-based eigendecompositions + SVD
// ==========================================================================

/// cuSOLVER: create a Jacobi-eigendecomposition control object. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
pub type PFN_cusolverDnCreateSyevjInfo =
    unsafe extern "C" fn(info: *mut syevjInfo_t) -> cusolverStatus_t;
/// cuSOLVER: destroy a Jacobi-eigendecomposition control object. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
pub type PFN_cusolverDnDestroySyevjInfo =
    unsafe extern "C" fn(info: syevjInfo_t) -> cusolverStatus_t;
/// cuSOLVER: set convergence tolerance on a Jacobi-eigendecomposition control object. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
pub type PFN_cusolverDnXsyevjSetTolerance =
    unsafe extern "C" fn(info: syevjInfo_t, tolerance: f64) -> cusolverStatus_t;
/// cuSOLVER: set the maximum number of sweeps on a Jacobi-eigendecomposition control object. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
pub type PFN_cusolverDnXsyevjSetMaxSweeps =
    unsafe extern "C" fn(info: syevjInfo_t, max_sweeps: c_int) -> cusolverStatus_t;

macro_rules! dn_syevj_bufsize {
    ($(#[$attr:meta])* $name:ident, $t:ty, $real:ty) => {
        $(#[$attr])*
        pub type $name = unsafe extern "C" fn(
            handle: cusolverDnHandle_t,
            jobz: cusolverEigMode_t,
            uplo: cublasFillMode_t,
            n: c_int,
            a: *const $t,
            lda: c_int,
            w: *const $real,
            lwork: *mut c_int,
            params: syevjInfo_t,
        ) -> cusolverStatus_t;
    };
}
dn_syevj_bufsize!(
    #[doc = "cuSOLVER: single-precision workspace-size query for symmetric eigendecomposition (Jacobi). See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnSsyevj_bufferSize,
    f32,
    f32
);
dn_syevj_bufsize!(
    #[doc = "cuSOLVER: double-precision workspace-size query for symmetric eigendecomposition (Jacobi). See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnDsyevj_bufferSize,
    f64,
    f64
);
dn_syevj_bufsize!(
    #[doc = "cuSOLVER: single-precision complex workspace-size query for Hermitian eigendecomposition (Jacobi). See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnCheevj_bufferSize,
    cuComplex,
    f32
);
dn_syevj_bufsize!(
    #[doc = "cuSOLVER: double-precision complex workspace-size query for Hermitian eigendecomposition (Jacobi). See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnZheevj_bufferSize,
    cuDoubleComplex,
    f64
);

macro_rules! dn_syevj {
    ($(#[$attr:meta])* $name:ident, $t:ty, $real:ty) => {
        $(#[$attr])*
        pub type $name = unsafe extern "C" fn(
            handle: cusolverDnHandle_t,
            jobz: cusolverEigMode_t,
            uplo: cublasFillMode_t,
            n: c_int,
            a: *mut $t,
            lda: c_int,
            w: *mut $real,
            work: *mut $t,
            lwork: c_int,
            info: *mut c_int,
            params: syevjInfo_t,
        ) -> cusolverStatus_t;
    };
}
dn_syevj!(
    #[doc = "cuSOLVER: single-precision symmetric eigendecomposition (Jacobi). See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnSsyevj,
    f32,
    f32
);
dn_syevj!(
    #[doc = "cuSOLVER: double-precision symmetric eigendecomposition (Jacobi). See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnDsyevj,
    f64,
    f64
);
dn_syevj!(
    #[doc = "cuSOLVER: single-precision complex Hermitian eigendecomposition (Jacobi). See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnCheevj,
    cuComplex,
    f32
);
dn_syevj!(
    #[doc = "cuSOLVER: double-precision complex Hermitian eigendecomposition (Jacobi). See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnZheevj,
    cuDoubleComplex,
    f64
);

/// cuSOLVER: create a Jacobi-SVD control object. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
pub type PFN_cusolverDnCreateGesvdjInfo =
    unsafe extern "C" fn(info: *mut gesvdjInfo_t) -> cusolverStatus_t;
/// cuSOLVER: destroy a Jacobi-SVD control object. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
pub type PFN_cusolverDnDestroyGesvdjInfo =
    unsafe extern "C" fn(info: gesvdjInfo_t) -> cusolverStatus_t;

macro_rules! dn_gesvdj_bufsize {
    ($(#[$attr:meta])* $name:ident, $t:ty, $real:ty) => {
        $(#[$attr])*
        pub type $name = unsafe extern "C" fn(
            handle: cusolverDnHandle_t,
            jobz: cusolverEigMode_t,
            econ: c_int,
            m: c_int,
            n: c_int,
            a: *const $t,
            lda: c_int,
            s: *const $real,
            u: *const $t,
            ldu: c_int,
            v: *const $t,
            ldv: c_int,
            lwork: *mut c_int,
            params: gesvdjInfo_t,
        ) -> cusolverStatus_t;
    };
}
dn_gesvdj_bufsize!(
    #[doc = "cuSOLVER: single-precision workspace-size query for Jacobi-method singular value decomposition. See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnSgesvdj_bufferSize,
    f32,
    f32
);
dn_gesvdj_bufsize!(
    #[doc = "cuSOLVER: double-precision workspace-size query for Jacobi-method singular value decomposition. See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnDgesvdj_bufferSize,
    f64,
    f64
);
dn_gesvdj_bufsize!(
    #[doc = "cuSOLVER: single-precision complex workspace-size query for Jacobi-method singular value decomposition. See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnCgesvdj_bufferSize,
    cuComplex,
    f32
);
dn_gesvdj_bufsize!(
    #[doc = "cuSOLVER: double-precision complex workspace-size query for Jacobi-method singular value decomposition. See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnZgesvdj_bufferSize,
    cuDoubleComplex,
    f64
);

macro_rules! dn_gesvdj {
    ($(#[$attr:meta])* $name:ident, $t:ty, $real:ty) => {
        $(#[$attr])*
        pub type $name = unsafe extern "C" fn(
            handle: cusolverDnHandle_t,
            jobz: cusolverEigMode_t,
            econ: c_int,
            m: c_int,
            n: c_int,
            a: *mut $t,
            lda: c_int,
            s: *mut $real,
            u: *mut $t,
            ldu: c_int,
            v: *mut $t,
            ldv: c_int,
            work: *mut $t,
            lwork: c_int,
            info: *mut c_int,
            params: gesvdjInfo_t,
        ) -> cusolverStatus_t;
    };
}
dn_gesvdj!(
    #[doc = "cuSOLVER: single-precision Jacobi-method singular value decomposition. See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnSgesvdj,
    f32,
    f32
);
dn_gesvdj!(
    #[doc = "cuSOLVER: double-precision Jacobi-method singular value decomposition. See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnDgesvdj,
    f64,
    f64
);
dn_gesvdj!(
    #[doc = "cuSOLVER: single-precision complex Jacobi-method singular value decomposition. See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnCgesvdj,
    cuComplex,
    f32
);
dn_gesvdj!(
    #[doc = "cuSOLVER: double-precision complex Jacobi-method singular value decomposition. See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnZgesvdj,
    cuDoubleComplex,
    f64
);

// ==========================================================================
// Apply Q from QR (orgqr / ormqr)
// ==========================================================================

macro_rules! dn_orgqr_bufsize {
    ($(#[$attr:meta])* $name:ident, $t:ty) => {
        $(#[$attr])*
        pub type $name = unsafe extern "C" fn(
            handle: cusolverDnHandle_t,
            m: c_int,
            n: c_int,
            k: c_int,
            a: *const $t,
            lda: c_int,
            tau: *const $t,
            lwork: *mut c_int,
        ) -> cusolverStatus_t;
    };
}
dn_orgqr_bufsize!(
    #[doc = "cuSOLVER: single-precision workspace-size query for generate the explicit Q from a QR factorization. See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnSorgqr_bufferSize,
    f32
);
dn_orgqr_bufsize!(
    #[doc = "cuSOLVER: double-precision workspace-size query for generate the explicit Q from a QR factorization. See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnDorgqr_bufferSize,
    f64
);
dn_orgqr_bufsize!(
    #[doc = "cuSOLVER: single-precision complex workspace-size query for generate the explicit unitary Q from a QR factorization. See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnCungqr_bufferSize,
    cuComplex
);
dn_orgqr_bufsize!(
    #[doc = "cuSOLVER: double-precision complex workspace-size query for generate the explicit unitary Q from a QR factorization. See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnZungqr_bufferSize,
    cuDoubleComplex
);

macro_rules! dn_orgqr {
    ($(#[$attr:meta])* $name:ident, $t:ty) => {
        $(#[$attr])*
        pub type $name = unsafe extern "C" fn(
            handle: cusolverDnHandle_t,
            m: c_int,
            n: c_int,
            k: c_int,
            a: *mut $t,
            lda: c_int,
            tau: *const $t,
            work: *mut $t,
            lwork: c_int,
            info: *mut c_int,
        ) -> cusolverStatus_t;
    };
}
dn_orgqr!(
    #[doc = "cuSOLVER: single-precision generate the explicit Q from a QR factorization. See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnSorgqr,
    f32
);
dn_orgqr!(
    #[doc = "cuSOLVER: double-precision generate the explicit Q from a QR factorization. See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnDorgqr,
    f64
);
dn_orgqr!(
    #[doc = "cuSOLVER: single-precision complex generate the explicit unitary Q from a QR factorization. See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnCungqr,
    cuComplex
);
dn_orgqr!(
    #[doc = "cuSOLVER: double-precision complex generate the explicit unitary Q from a QR factorization. See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnZungqr,
    cuDoubleComplex
);

macro_rules! dn_ormqr_bufsize {
    ($(#[$attr:meta])* $name:ident, $t:ty) => {
        $(#[$attr])*
        pub type $name = unsafe extern "C" fn(
            handle: cusolverDnHandle_t,
            side: c_int,
            trans: cublasOperation_t,
            m: c_int,
            n: c_int,
            k: c_int,
            a: *const $t,
            lda: c_int,
            tau: *const $t,
            c: *const $t,
            ldc: c_int,
            lwork: *mut c_int,
        ) -> cusolverStatus_t;
    };
}
dn_ormqr_bufsize!(
    #[doc = "cuSOLVER: single-precision workspace-size query for apply Q (or Q^T) from a QR factorization to a matrix. See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnSormqr_bufferSize,
    f32
);
dn_ormqr_bufsize!(
    #[doc = "cuSOLVER: double-precision workspace-size query for apply Q (or Q^T) from a QR factorization to a matrix. See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnDormqr_bufferSize,
    f64
);
dn_ormqr_bufsize!(
    #[doc = "cuSOLVER: single-precision complex workspace-size query for apply Q (or Q^H) from a QR factorization to a matrix. See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnCunmqr_bufferSize,
    cuComplex
);
dn_ormqr_bufsize!(
    #[doc = "cuSOLVER: double-precision complex workspace-size query for apply Q (or Q^H) from a QR factorization to a matrix. See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnZunmqr_bufferSize,
    cuDoubleComplex
);

macro_rules! dn_ormqr {
    ($(#[$attr:meta])* $name:ident, $t:ty) => {
        $(#[$attr])*
        pub type $name = unsafe extern "C" fn(
            handle: cusolverDnHandle_t,
            side: c_int,
            trans: cublasOperation_t,
            m: c_int,
            n: c_int,
            k: c_int,
            a: *const $t,
            lda: c_int,
            tau: *const $t,
            c: *mut $t,
            ldc: c_int,
            work: *mut $t,
            lwork: c_int,
            info: *mut c_int,
        ) -> cusolverStatus_t;
    };
}
dn_ormqr!(
    #[doc = "cuSOLVER: single-precision apply Q (or Q^T) from a QR factorization to a matrix. See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnSormqr,
    f32
);
dn_ormqr!(
    #[doc = "cuSOLVER: double-precision apply Q (or Q^T) from a QR factorization to a matrix. See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnDormqr,
    f64
);
dn_ormqr!(
    #[doc = "cuSOLVER: single-precision complex apply Q (or Q^H) from a QR factorization to a matrix. See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnCunmqr,
    cuComplex
);
dn_ormqr!(
    #[doc = "cuSOLVER: double-precision complex apply Q (or Q^H) from a QR factorization to a matrix. See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnZunmqr,
    cuDoubleComplex
);

// ---- Sparse cuSOLVER -----------------------------------------------------

/// cuSOLVER: create a sparse cuSOLVER handle. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
pub type PFN_cusolverSpCreate =
    unsafe extern "C" fn(handle: *mut cusolverSpHandle_t) -> cusolverStatus_t;
/// cuSOLVER: destroy a sparse cuSOLVER handle. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
pub type PFN_cusolverSpDestroy =
    unsafe extern "C" fn(handle: cusolverSpHandle_t) -> cusolverStatus_t;
/// cuSOLVER: bind a CUDA stream to a sparse cuSOLVER handle. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
pub type PFN_cusolverSpSetStream =
    unsafe extern "C" fn(handle: cusolverSpHandle_t, stream: cudaStream_t) -> cusolverStatus_t;

/// cuSOLVER: single-precision sparse linear solve via Cholesky on a CSR matrix. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
pub type PFN_cusolverSpScsrlsvchol = unsafe extern "C" fn(
    handle: cusolverSpHandle_t,
    m: c_int,
    nnz: c_int,
    descr_a: *mut c_void,
    csr_val: *const f32,
    csr_row_ptr: *const c_int,
    csr_col_ind: *const c_int,
    b: *const f32,
    tol: f32,
    reorder: c_int,
    x: *mut f32,
    singularity: *mut c_int,
) -> cusolverStatus_t;

/// cuSOLVER: double-precision sparse linear solve via Cholesky on a CSR matrix. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
pub type PFN_cusolverSpDcsrlsvchol = unsafe extern "C" fn(
    handle: cusolverSpHandle_t,
    m: c_int,
    nnz: c_int,
    descr_a: *mut c_void,
    csr_val: *const f64,
    csr_row_ptr: *const c_int,
    csr_col_ind: *const c_int,
    b: *const f64,
    tol: f64,
    reorder: c_int,
    x: *mut f64,
    singularity: *mut c_int,
) -> cusolverStatus_t;

/// cuSOLVER: single-precision sparse linear solve via QR on a CSR matrix. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
pub type PFN_cusolverSpScsrlsvqr = unsafe extern "C" fn(
    handle: cusolverSpHandle_t,
    m: c_int,
    nnz: c_int,
    descr_a: *mut c_void,
    csr_val: *const f32,
    csr_row_ptr: *const c_int,
    csr_col_ind: *const c_int,
    b: *const f32,
    tol: f32,
    reorder: c_int,
    x: *mut f32,
    singularity: *mut c_int,
) -> cusolverStatus_t;

/// cuSOLVER: double-precision sparse linear solve via QR on a CSR matrix. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
pub type PFN_cusolverSpDcsrlsvqr = unsafe extern "C" fn(
    handle: cusolverSpHandle_t,
    m: c_int,
    nnz: c_int,
    descr_a: *mut c_void,
    csr_val: *const f64,
    csr_row_ptr: *const c_int,
    csr_col_ind: *const c_int,
    b: *const f64,
    tol: f64,
    reorder: c_int,
    x: *mut f64,
    singularity: *mut c_int,
) -> cusolverStatus_t;

// ---- Refactor (Rf) sparse LU refactorization -----------------------------

/// cuSOLVER: create a sparse-refactor cuSOLVER handle. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
pub type PFN_cusolverRfCreate =
    unsafe extern "C" fn(handle: *mut cusolverRfHandle_t) -> cusolverStatus_t;
/// cuSOLVER: destroy a sparse-refactor cuSOLVER handle. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
pub type PFN_cusolverRfDestroy =
    unsafe extern "C" fn(handle: cusolverRfHandle_t) -> cusolverStatus_t;
/// cuSOLVER: supply sparse triangular factors and pivot vectors to the refactor handle. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
pub type PFN_cusolverRfSetupDevice = unsafe extern "C" fn(
    n: c_int,
    nnz_a: c_int,
    h_csr_row_ptr_a: *mut c_int,
    h_csr_col_ind_a: *mut c_int,
    h_csr_val_a: *mut f64,
    nnz_l: c_int,
    h_csr_row_ptr_l: *mut c_int,
    h_csr_col_ind_l: *mut c_int,
    h_csr_val_l: *mut f64,
    nnz_u: c_int,
    h_csr_row_ptr_u: *mut c_int,
    h_csr_col_ind_u: *mut c_int,
    h_csr_val_u: *mut f64,
    p: *mut c_int,
    q: *mut c_int,
    handle: cusolverRfHandle_t,
) -> cusolverStatus_t;
/// cuSOLVER: analyze the sparsity pattern of the refactor handle. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
pub type PFN_cusolverRfAnalyze =
    unsafe extern "C" fn(handle: cusolverRfHandle_t) -> cusolverStatus_t;
/// cuSOLVER: refactor with new numerical values reusing the analyzed pattern. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
pub type PFN_cusolverRfRefactor =
    unsafe extern "C" fn(handle: cusolverRfHandle_t) -> cusolverStatus_t;
/// cuSOLVER: solve linear systems using the refactor handle. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
pub type PFN_cusolverRfSolve = unsafe extern "C" fn(
    handle: cusolverRfHandle_t,
    p: *mut c_int,
    q: *mut c_int,
    nrhs: c_int,
    temp: *mut f64,
    ld_temp: c_int,
    xf: *mut f64,
    ld_xf: c_int,
) -> cusolverStatus_t;

// ==========================================================================
// Least-squares (gels): A*X = B → X
// ==========================================================================

macro_rules! dn_gels_bufsize {
    ($(#[$attr:meta])* $name:ident, $t:ty) => {
        $(#[$attr])*
        pub type $name = unsafe extern "C" fn(
            handle: cusolverDnHandle_t,
            m: c_int,
            n: c_int,
            nrhs: c_int,
            d_a: *mut $t,
            lda: c_int,
            d_b: *mut $t,
            ldb: c_int,
            d_x: *mut $t,
            ldx: c_int,
            d_work: *mut c_void,
            lwork_bytes: *mut usize,
        ) -> cusolverStatus_t;
    };
}
dn_gels_bufsize!(
    #[doc = "cuSOLVER: single-precision workspace-size query for least-squares solver (A*X = B). See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnSSgels_bufferSize,
    f32
);
dn_gels_bufsize!(
    #[doc = "cuSOLVER: double-precision workspace-size query for least-squares solver (A*X = B). See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnDDgels_bufferSize,
    f64
);
dn_gels_bufsize!(
    #[doc = "cuSOLVER: single-precision complex workspace-size query for least-squares solver (A*X = B). See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnCCgels_bufferSize,
    cuComplex
);
dn_gels_bufsize!(
    #[doc = "cuSOLVER: double-precision complex workspace-size query for least-squares solver (A*X = B). See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnZZgels_bufferSize,
    cuDoubleComplex
);

macro_rules! dn_gels {
    ($(#[$attr:meta])* $name:ident, $t:ty) => {
        $(#[$attr])*
        pub type $name = unsafe extern "C" fn(
            handle: cusolverDnHandle_t,
            m: c_int,
            n: c_int,
            nrhs: c_int,
            d_a: *mut $t,
            lda: c_int,
            d_b: *mut $t,
            ldb: c_int,
            d_x: *mut $t,
            ldx: c_int,
            d_work: *mut c_void,
            lwork_bytes: usize,
            iter: *mut c_int,
            d_info: *mut c_int,
        ) -> cusolverStatus_t;
    };
}
dn_gels!(
    #[doc = "cuSOLVER: single-precision least-squares solver (A*X = B). See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnSSgels,
    f32
);
dn_gels!(
    #[doc = "cuSOLVER: double-precision least-squares solver (A*X = B). See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnDDgels,
    f64
);
dn_gels!(
    #[doc = "cuSOLVER: single-precision complex least-squares solver (A*X = B). See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnCCgels,
    cuComplex
);
dn_gels!(
    #[doc = "cuSOLVER: double-precision complex least-squares solver (A*X = B). See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnZZgels,
    cuDoubleComplex
);

// ==========================================================================
// Inverse from Cholesky (potri)
// ==========================================================================

macro_rules! dn_potri_bufsize {
    ($(#[$attr:meta])* $name:ident, $t:ty) => {
        $(#[$attr])*
        pub type $name = unsafe extern "C" fn(
            handle: cusolverDnHandle_t,
            uplo: cublasFillMode_t,
            n: c_int,
            a: *mut $t,
            lda: c_int,
            lwork: *mut c_int,
        ) -> cusolverStatus_t;
    };
}
dn_potri_bufsize!(
    #[doc = "cuSOLVER: single-precision workspace-size query for matrix inverse from Cholesky factors. See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnSpotri_bufferSize,
    f32
);
dn_potri_bufsize!(
    #[doc = "cuSOLVER: double-precision workspace-size query for matrix inverse from Cholesky factors. See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnDpotri_bufferSize,
    f64
);
dn_potri_bufsize!(
    #[doc = "cuSOLVER: single-precision complex workspace-size query for matrix inverse from Cholesky factors. See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnCpotri_bufferSize,
    cuComplex
);
dn_potri_bufsize!(
    #[doc = "cuSOLVER: double-precision complex workspace-size query for matrix inverse from Cholesky factors. See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnZpotri_bufferSize,
    cuDoubleComplex
);

macro_rules! dn_potri {
    ($(#[$attr:meta])* $name:ident, $t:ty) => {
        $(#[$attr])*
        pub type $name = unsafe extern "C" fn(
            handle: cusolverDnHandle_t,
            uplo: cublasFillMode_t,
            n: c_int,
            a: *mut $t,
            lda: c_int,
            work: *mut $t,
            lwork: c_int,
            info: *mut c_int,
        ) -> cusolverStatus_t;
    };
}
dn_potri!(
    #[doc = "cuSOLVER: single-precision matrix inverse from Cholesky factors. See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnSpotri,
    f32
);
dn_potri!(
    #[doc = "cuSOLVER: double-precision matrix inverse from Cholesky factors. See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnDpotri,
    f64
);
dn_potri!(
    #[doc = "cuSOLVER: single-precision complex matrix inverse from Cholesky factors. See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnCpotri,
    cuComplex
);
dn_potri!(
    #[doc = "cuSOLVER: double-precision complex matrix inverse from Cholesky factors. See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnZpotri,
    cuDoubleComplex
);

// ==========================================================================
// Batched Jacobi eigen / SVD
// ==========================================================================

macro_rules! dn_syevj_batched_bufsize {
    ($(#[$attr:meta])* $name:ident, $t:ty, $real:ty) => {
        $(#[$attr])*
        pub type $name = unsafe extern "C" fn(
            handle: cusolverDnHandle_t,
            jobz: cusolverEigMode_t,
            uplo: cublasFillMode_t,
            n: c_int,
            a: *const $t,
            lda: c_int,
            w: *const $real,
            lwork: *mut c_int,
            params: syevjInfo_t,
            batch_size: c_int,
        ) -> cusolverStatus_t;
    };
}
dn_syevj_batched_bufsize!(
    #[doc = "cuSOLVER: single-precision workspace-size query for batched symmetric eigendecomposition (Jacobi). See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnSsyevjBatched_bufferSize,
    f32,
    f32
);
dn_syevj_batched_bufsize!(
    #[doc = "cuSOLVER: double-precision workspace-size query for batched symmetric eigendecomposition (Jacobi). See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnDsyevjBatched_bufferSize,
    f64,
    f64
);
dn_syevj_batched_bufsize!(
    #[doc = "cuSOLVER: single-precision complex workspace-size query for batched Hermitian eigendecomposition (Jacobi). See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnCheevjBatched_bufferSize,
    cuComplex,
    f32
);
dn_syevj_batched_bufsize!(
    #[doc = "cuSOLVER: double-precision complex workspace-size query for batched Hermitian eigendecomposition (Jacobi). See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnZheevjBatched_bufferSize,
    cuDoubleComplex,
    f64
);

macro_rules! dn_syevj_batched {
    ($(#[$attr:meta])* $name:ident, $t:ty, $real:ty) => {
        $(#[$attr])*
        pub type $name = unsafe extern "C" fn(
            handle: cusolverDnHandle_t,
            jobz: cusolverEigMode_t,
            uplo: cublasFillMode_t,
            n: c_int,
            a: *mut $t,
            lda: c_int,
            w: *mut $real,
            work: *mut $t,
            lwork: c_int,
            info: *mut c_int,
            params: syevjInfo_t,
            batch_size: c_int,
        ) -> cusolverStatus_t;
    };
}
dn_syevj_batched!(
    #[doc = "cuSOLVER: single-precision batched symmetric eigendecomposition (Jacobi). See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnSsyevjBatched,
    f32,
    f32
);
dn_syevj_batched!(
    #[doc = "cuSOLVER: double-precision batched symmetric eigendecomposition (Jacobi). See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnDsyevjBatched,
    f64,
    f64
);
dn_syevj_batched!(
    #[doc = "cuSOLVER: single-precision complex batched Hermitian eigendecomposition (Jacobi). See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnCheevjBatched,
    cuComplex,
    f32
);
dn_syevj_batched!(
    #[doc = "cuSOLVER: double-precision complex batched Hermitian eigendecomposition (Jacobi). See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnZheevjBatched,
    cuDoubleComplex,
    f64
);

macro_rules! dn_gesvdj_batched_bufsize {
    ($(#[$attr:meta])* $name:ident, $t:ty, $real:ty) => {
        $(#[$attr])*
        pub type $name = unsafe extern "C" fn(
            handle: cusolverDnHandle_t,
            jobz: cusolverEigMode_t,
            m: c_int,
            n: c_int,
            a: *const $t,
            lda: c_int,
            s: *const $real,
            u: *const $t,
            ldu: c_int,
            v: *const $t,
            ldv: c_int,
            lwork: *mut c_int,
            params: gesvdjInfo_t,
            batch_size: c_int,
        ) -> cusolverStatus_t;
    };
}
dn_gesvdj_batched_bufsize!(
    #[doc = "cuSOLVER: single-precision workspace-size query for batched Jacobi-method singular value decomposition. See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnSgesvdjBatched_bufferSize,
    f32,
    f32
);
dn_gesvdj_batched_bufsize!(
    #[doc = "cuSOLVER: double-precision workspace-size query for batched Jacobi-method singular value decomposition. See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnDgesvdjBatched_bufferSize,
    f64,
    f64
);
dn_gesvdj_batched_bufsize!(
    #[doc = "cuSOLVER: single-precision complex workspace-size query for batched Jacobi-method singular value decomposition. See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnCgesvdjBatched_bufferSize,
    cuComplex,
    f32
);
dn_gesvdj_batched_bufsize!(
    #[doc = "cuSOLVER: double-precision complex workspace-size query for batched Jacobi-method singular value decomposition. See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnZgesvdjBatched_bufferSize,
    cuDoubleComplex,
    f64
);

macro_rules! dn_gesvdj_batched {
    ($(#[$attr:meta])* $name:ident, $t:ty, $real:ty) => {
        $(#[$attr])*
        pub type $name = unsafe extern "C" fn(
            handle: cusolverDnHandle_t,
            jobz: cusolverEigMode_t,
            m: c_int,
            n: c_int,
            a: *mut $t,
            lda: c_int,
            s: *mut $real,
            u: *mut $t,
            ldu: c_int,
            v: *mut $t,
            ldv: c_int,
            work: *mut $t,
            lwork: c_int,
            info: *mut c_int,
            params: gesvdjInfo_t,
            batch_size: c_int,
        ) -> cusolverStatus_t;
    };
}
dn_gesvdj_batched!(
    #[doc = "cuSOLVER: single-precision batched Jacobi-method singular value decomposition. See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnSgesvdjBatched,
    f32,
    f32
);
dn_gesvdj_batched!(
    #[doc = "cuSOLVER: double-precision batched Jacobi-method singular value decomposition. See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnDgesvdjBatched,
    f64,
    f64
);
dn_gesvdj_batched!(
    #[doc = "cuSOLVER: single-precision complex batched Jacobi-method singular value decomposition. See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnCgesvdjBatched,
    cuComplex,
    f32
);
dn_gesvdj_batched!(
    #[doc = "cuSOLVER: double-precision complex batched Jacobi-method singular value decomposition. See <https://docs.nvidia.com/cuda/cusolver/index.html>."]
    PFN_cusolverDnZgesvdjBatched,
    cuDoubleComplex,
    f64
);

// ==========================================================================
// cuSOLVERMg — multi-GPU dense solvers (separate library libcusolverMg)
// ==========================================================================

/// Opaque multi-GPU dense cuSOLVERMg handle.
pub type cusolverMgHandle_t = *mut c_void;
/// Opaque multi-GPU matrix descriptor.
pub type cudaLibMgMatrixDesc_t = *mut c_void;
/// Opaque multi-GPU device grid.
pub type cudaLibMgGrid_t = *mut c_void;

/// cuSOLVER: create a multi-GPU dense cuSOLVERMg handle. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
pub type PFN_cusolverMgCreate =
    unsafe extern "C" fn(handle: *mut cusolverMgHandle_t) -> cusolverStatus_t;
/// cuSOLVER: destroy a multi-GPU dense cuSOLVERMg handle. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
pub type PFN_cusolverMgDestroy =
    unsafe extern "C" fn(handle: cusolverMgHandle_t) -> cusolverStatus_t;
/// cuSOLVER: select GPU devices for a cuSOLVERMg handle. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
pub type PFN_cusolverMgDeviceSelect = unsafe extern "C" fn(
    handle: cusolverMgHandle_t,
    n_devices: c_int,
    device_id: *const c_int,
) -> cusolverStatus_t;

/// cuSOLVER: create a multi-GPU device grid. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
pub type PFN_cusolverMgCreateDeviceGrid = unsafe extern "C" fn(
    grid: *mut cudaLibMgGrid_t,
    num_row_devices: i32,
    num_col_devices: i32,
    device_id: *const i32,
    mapping: i32,
) -> cusolverStatus_t;

/// cuSOLVER: destroy a multi-GPU device grid. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
pub type PFN_cusolverMgDestroyGrid =
    unsafe extern "C" fn(grid: cudaLibMgGrid_t) -> cusolverStatus_t;

/// cuSOLVER: create a multi-GPU matrix descriptor. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
pub type PFN_cusolverMgCreateMatrixDesc = unsafe extern "C" fn(
    desc: *mut cudaLibMgMatrixDesc_t,
    num_rows: i64,
    num_cols: i64,
    row_block_size: i64,
    col_block_size: i64,
    data_type: cudaDataType,
    grid: cudaLibMgGrid_t,
) -> cusolverStatus_t;

/// cuSOLVER: destroy a multi-GPU matrix descriptor. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
pub type PFN_cusolverMgDestroyMatrixDesc =
    unsafe extern "C" fn(desc: cudaLibMgMatrixDesc_t) -> cusolverStatus_t;

/// cuSOLVER: multi-GPU workspace-size query for LU factorization with partial pivoting. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
pub type PFN_cusolverMgGetrf_bufferSize = unsafe extern "C" fn(
    handle: cusolverMgHandle_t,
    m: c_int,
    n: c_int,
    array_d_a: *mut *mut c_void,
    ia: c_int,
    ja: c_int,
    desc_a: cudaLibMgMatrixDesc_t,
    array_d_ipiv: *mut *mut c_int,
    compute_type: cudaDataType,
    lwork: *mut i64,
) -> cusolverStatus_t;

/// cuSOLVER: multi-GPU LU factorization with partial pivoting. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
pub type PFN_cusolverMgGetrf = unsafe extern "C" fn(
    handle: cusolverMgHandle_t,
    m: c_int,
    n: c_int,
    array_d_a: *mut *mut c_void,
    ia: c_int,
    ja: c_int,
    desc_a: cudaLibMgMatrixDesc_t,
    array_d_ipiv: *mut *mut c_int,
    compute_type: cudaDataType,
    array_d_work: *mut *mut c_void,
    lwork: i64,
    info: *mut c_int,
) -> cusolverStatus_t;

/// cuSOLVER: multi-GPU workspace-size query for Cholesky factorization. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
pub type PFN_cusolverMgPotrf_bufferSize = unsafe extern "C" fn(
    handle: cusolverMgHandle_t,
    uplo: cublasFillMode_t,
    n: c_int,
    array_d_a: *mut *mut c_void,
    ia: c_int,
    ja: c_int,
    desc_a: cudaLibMgMatrixDesc_t,
    compute_type: cudaDataType,
    lwork: *mut i64,
) -> cusolverStatus_t;

/// cuSOLVER: multi-GPU Cholesky factorization. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
pub type PFN_cusolverMgPotrf = unsafe extern "C" fn(
    handle: cusolverMgHandle_t,
    uplo: cublasFillMode_t,
    n: c_int,
    array_d_a: *mut *mut c_void,
    ia: c_int,
    ja: c_int,
    desc_a: cudaLibMgMatrixDesc_t,
    compute_type: cudaDataType,
    array_d_work: *mut *mut c_void,
    lwork: i64,
    info: *mut c_int,
) -> cusolverStatus_t;

/// cuSOLVER: multi-GPU workspace-size query for symmetric eigendecomposition (divide-and-conquer). See <https://docs.nvidia.com/cuda/cusolver/index.html>.
pub type PFN_cusolverMgSyevd_bufferSize = unsafe extern "C" fn(
    handle: cusolverMgHandle_t,
    jobz: cusolverEigMode_t,
    uplo: cublasFillMode_t,
    n: c_int,
    array_d_a: *mut *mut c_void,
    ia: c_int,
    ja: c_int,
    desc_a: cudaLibMgMatrixDesc_t,
    w: *mut c_void,
    data_type_w: cudaDataType,
    compute_type: cudaDataType,
    lwork: *mut i64,
) -> cusolverStatus_t;

/// cuSOLVER: multi-GPU symmetric eigendecomposition (divide-and-conquer). See <https://docs.nvidia.com/cuda/cusolver/index.html>.
pub type PFN_cusolverMgSyevd = unsafe extern "C" fn(
    handle: cusolverMgHandle_t,
    jobz: cusolverEigMode_t,
    uplo: cublasFillMode_t,
    n: c_int,
    array_d_a: *mut *mut c_void,
    ia: c_int,
    ja: c_int,
    desc_a: cudaLibMgMatrixDesc_t,
    w: *mut c_void,
    data_type_w: cudaDataType,
    compute_type: cudaDataType,
    array_d_work: *mut *mut c_void,
    lwork: i64,
    info: *mut c_int,
) -> cusolverStatus_t;

// ---- loader --------------------------------------------------------------

fn cusolver_candidates() -> Vec<String> {
    platform::versioned_library_candidates("cusolver", &["13", "12", "11"])
}

macro_rules! cusolver_fns {
    ($($(#[$m:meta])* $name:ident as $sym:literal : $pfn:ty);* $(;)?) => {
        /// Loaded cuSOLVER shared library plus a per-symbol `OnceLock` of function pointers.
        pub struct Cusolver {
            lib: Library,
            $($name: OnceLock<$pfn>,)*
        }
        impl core::fmt::Debug for Cusolver {
            fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
                f.debug_struct("Cusolver").field("lib", &self.lib).finish_non_exhaustive()
            }
        }
        impl Cusolver {
            $(
                $(#[$m])*
                pub fn $name(&self) -> Result<$pfn, LoaderError> {
                    if let Some(&p) = self.$name.get() { return Ok(p); }
                    let raw: *mut () = unsafe { self.lib.raw_symbol($sym)? };
                    let p: $pfn = unsafe { core::mem::transmute_copy::<*mut (), $pfn>(&raw) };
                    let _ = self.$name.set(p);
                    Ok(p)
                }
            )*
            fn empty(lib: Library) -> Self {
                Self { lib, $($name: OnceLock::new(),)* }
            }
        }
    };
}

cusolver_fns! {
    // Dn handle
    /// cuSOLVER: create a dense cuSOLVER handle. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_create as "cusolverDnCreate": PFN_cusolverDnCreate;
    /// cuSOLVER: destroy a dense cuSOLVER handle. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_destroy as "cusolverDnDestroy": PFN_cusolverDnDestroy;
    /// cuSOLVER: bind a CUDA stream to a dense cuSOLVER handle. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_set_stream as "cusolverDnSetStream": PFN_cusolverDnSetStream;
    /// cuSOLVER: query the CUDA stream bound to a dense cuSOLVER handle. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_get_stream as "cusolverDnGetStream": PFN_cusolverDnGetStream;
    /// cuSOLVER: return the cuSOLVER library version. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_get_version as "cusolverGetVersion": PFN_cusolverGetVersion;
    // LU (getrf/getrs) S/D/C/Z
    /// cuSOLVER: single-precision workspace-size query for LU factorization with partial pivoting. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_sgetrf_buffer_size as "cusolverDnSgetrf_bufferSize": PFN_cusolverDnSgetrf_bufferSize;
    /// cuSOLVER: double-precision workspace-size query for LU factorization with partial pivoting. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_dgetrf_buffer_size as "cusolverDnDgetrf_bufferSize": PFN_cusolverDnDgetrf_bufferSize;
    /// cuSOLVER: single-precision complex workspace-size query for LU factorization with partial pivoting. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_cgetrf_buffer_size as "cusolverDnCgetrf_bufferSize": PFN_cusolverDnCgetrf_bufferSize;
    /// cuSOLVER: double-precision complex workspace-size query for LU factorization with partial pivoting. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_zgetrf_buffer_size as "cusolverDnZgetrf_bufferSize": PFN_cusolverDnZgetrf_bufferSize;
    /// cuSOLVER: single-precision LU factorization with partial pivoting. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_sgetrf as "cusolverDnSgetrf": PFN_cusolverDnSgetrf;
    /// cuSOLVER: double-precision LU factorization with partial pivoting. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_dgetrf as "cusolverDnDgetrf": PFN_cusolverDnDgetrf;
    /// cuSOLVER: single-precision complex LU factorization with partial pivoting. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_cgetrf as "cusolverDnCgetrf": PFN_cusolverDnCgetrf;
    /// cuSOLVER: double-precision complex LU factorization with partial pivoting. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_zgetrf as "cusolverDnZgetrf": PFN_cusolverDnZgetrf;
    /// cuSOLVER: single-precision solve linear system using LU factors. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_sgetrs as "cusolverDnSgetrs": PFN_cusolverDnSgetrs;
    /// cuSOLVER: double-precision solve linear system using LU factors. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_dgetrs as "cusolverDnDgetrs": PFN_cusolverDnDgetrs;
    /// cuSOLVER: single-precision complex solve linear system using LU factors. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_cgetrs as "cusolverDnCgetrs": PFN_cusolverDnCgetrs;
    /// cuSOLVER: double-precision complex solve linear system using LU factors. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_zgetrs as "cusolverDnZgetrs": PFN_cusolverDnZgetrs;
    // QR (geqrf) S/D/C/Z
    /// cuSOLVER: single-precision workspace-size query for QR factorization (Householder). See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_sgeqrf_buffer_size as "cusolverDnSgeqrf_bufferSize": PFN_cusolverDnSgeqrf_bufferSize;
    /// cuSOLVER: double-precision workspace-size query for QR factorization (Householder). See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_dgeqrf_buffer_size as "cusolverDnDgeqrf_bufferSize": PFN_cusolverDnDgeqrf_bufferSize;
    /// cuSOLVER: single-precision complex workspace-size query for QR factorization (Householder). See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_cgeqrf_buffer_size as "cusolverDnCgeqrf_bufferSize": PFN_cusolverDnCgeqrf_bufferSize;
    /// cuSOLVER: double-precision complex workspace-size query for QR factorization (Householder). See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_zgeqrf_buffer_size as "cusolverDnZgeqrf_bufferSize": PFN_cusolverDnZgeqrf_bufferSize;
    /// cuSOLVER: single-precision QR factorization (Householder). See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_sgeqrf as "cusolverDnSgeqrf": PFN_cusolverDnSgeqrf;
    /// cuSOLVER: double-precision QR factorization (Householder). See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_dgeqrf as "cusolverDnDgeqrf": PFN_cusolverDnDgeqrf;
    /// cuSOLVER: single-precision complex QR factorization (Householder). See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_cgeqrf as "cusolverDnCgeqrf": PFN_cusolverDnCgeqrf;
    /// cuSOLVER: double-precision complex QR factorization (Householder). See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_zgeqrf as "cusolverDnZgeqrf": PFN_cusolverDnZgeqrf;
    // Cholesky (potrf/potrs) S/D/C/Z
    /// cuSOLVER: single-precision workspace-size query for Cholesky factorization. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_spotrf_buffer_size as "cusolverDnSpotrf_bufferSize": PFN_cusolverDnSpotrf_bufferSize;
    /// cuSOLVER: double-precision workspace-size query for Cholesky factorization. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_dpotrf_buffer_size as "cusolverDnDpotrf_bufferSize": PFN_cusolverDnDpotrf_bufferSize;
    /// cuSOLVER: single-precision complex workspace-size query for Cholesky factorization. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_cpotrf_buffer_size as "cusolverDnCpotrf_bufferSize": PFN_cusolverDnCpotrf_bufferSize;
    /// cuSOLVER: double-precision complex workspace-size query for Cholesky factorization. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_zpotrf_buffer_size as "cusolverDnZpotrf_bufferSize": PFN_cusolverDnZpotrf_bufferSize;
    /// cuSOLVER: single-precision Cholesky factorization. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_spotrf as "cusolverDnSpotrf": PFN_cusolverDnSpotrf;
    /// cuSOLVER: double-precision Cholesky factorization. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_dpotrf as "cusolverDnDpotrf": PFN_cusolverDnDpotrf;
    /// cuSOLVER: single-precision complex Cholesky factorization. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_cpotrf as "cusolverDnCpotrf": PFN_cusolverDnCpotrf;
    /// cuSOLVER: double-precision complex Cholesky factorization. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_zpotrf as "cusolverDnZpotrf": PFN_cusolverDnZpotrf;
    /// cuSOLVER: single-precision solve linear system using Cholesky factors. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_spotrs as "cusolverDnSpotrs": PFN_cusolverDnSpotrs;
    /// cuSOLVER: double-precision solve linear system using Cholesky factors. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_dpotrs as "cusolverDnDpotrs": PFN_cusolverDnDpotrs;
    /// cuSOLVER: single-precision complex solve linear system using Cholesky factors. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_cpotrs as "cusolverDnCpotrs": PFN_cusolverDnCpotrs;
    /// cuSOLVER: double-precision complex solve linear system using Cholesky factors. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_zpotrs as "cusolverDnZpotrs": PFN_cusolverDnZpotrs;
    // SVD S/D/C/Z
    /// cuSOLVER: single-precision workspace-size query for singular value decomposition. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_sgesvd_buffer_size as "cusolverDnSgesvd_bufferSize": PFN_cusolverDnSgesvd_bufferSize;
    /// cuSOLVER: double-precision workspace-size query for singular value decomposition. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_dgesvd_buffer_size as "cusolverDnDgesvd_bufferSize": PFN_cusolverDnDgesvd_bufferSize;
    /// cuSOLVER: single-precision complex workspace-size query for singular value decomposition. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_cgesvd_buffer_size as "cusolverDnCgesvd_bufferSize": PFN_cusolverDnCgesvd_bufferSize;
    /// cuSOLVER: double-precision complex workspace-size query for singular value decomposition. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_zgesvd_buffer_size as "cusolverDnZgesvd_bufferSize": PFN_cusolverDnZgesvd_bufferSize;
    /// cuSOLVER: single-precision singular value decomposition. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_sgesvd as "cusolverDnSgesvd": PFN_cusolverDnSgesvd;
    /// cuSOLVER: double-precision singular value decomposition. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_dgesvd as "cusolverDnDgesvd": PFN_cusolverDnDgesvd;
    /// cuSOLVER: single-precision complex singular value decomposition. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_cgesvd as "cusolverDnCgesvd": PFN_cusolverDnCgesvd;
    /// cuSOLVER: double-precision complex singular value decomposition. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_zgesvd as "cusolverDnZgesvd": PFN_cusolverDnZgesvd;
    // syevd / heevd
    /// cuSOLVER: single-precision workspace-size query for symmetric eigendecomposition (divide-and-conquer). See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_ssyevd_buffer_size as "cusolverDnSsyevd_bufferSize": PFN_cusolverDnSsyevd_bufferSize;
    /// cuSOLVER: double-precision workspace-size query for symmetric eigendecomposition (divide-and-conquer). See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_dsyevd_buffer_size as "cusolverDnDsyevd_bufferSize": PFN_cusolverDnDsyevd_bufferSize;
    /// cuSOLVER: single-precision complex workspace-size query for Hermitian eigendecomposition (divide-and-conquer). See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_cheevd_buffer_size as "cusolverDnCheevd_bufferSize": PFN_cusolverDnCheevd_bufferSize;
    /// cuSOLVER: double-precision complex workspace-size query for Hermitian eigendecomposition (divide-and-conquer). See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_zheevd_buffer_size as "cusolverDnZheevd_bufferSize": PFN_cusolverDnZheevd_bufferSize;
    /// cuSOLVER: single-precision symmetric eigendecomposition (divide-and-conquer). See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_ssyevd as "cusolverDnSsyevd": PFN_cusolverDnSsyevd;
    /// cuSOLVER: double-precision symmetric eigendecomposition (divide-and-conquer). See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_dsyevd as "cusolverDnDsyevd": PFN_cusolverDnDsyevd;
    /// cuSOLVER: single-precision complex Hermitian eigendecomposition (divide-and-conquer). See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_cheevd as "cusolverDnCheevd": PFN_cusolverDnCheevd;
    /// cuSOLVER: double-precision complex Hermitian eigendecomposition (divide-and-conquer). See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_zheevd as "cusolverDnZheevd": PFN_cusolverDnZheevd;
    // Generic 64-bit X… API
    /// cuSOLVER: create a generic-API parameter object. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_create_params as "cusolverDnCreateParams": PFN_cusolverDnCreateParams;
    /// cuSOLVER: destroy a generic-API parameter object. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_destroy_params as "cusolverDnDestroyParams": PFN_cusolverDnDestroyParams;
    /// cuSOLVER: generic-API workspace-size query for LU factorization with partial pivoting (dtype configurable via `cudaDataType`). See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_xgetrf_buffer_size as "cusolverDnXgetrf_bufferSize": PFN_cusolverDnXgetrf_bufferSize;
    /// cuSOLVER: generic-API LU factorization with partial pivoting (dtype configurable via `cudaDataType`). See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_xgetrf as "cusolverDnXgetrf": PFN_cusolverDnXgetrf;
    /// cuSOLVER: generic-API solve linear system using LU factors (dtype configurable via `cudaDataType`). See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_xgetrs as "cusolverDnXgetrs": PFN_cusolverDnXgetrs;
    /// cuSOLVER: generic-API workspace-size query for QR factorization (Householder) (dtype configurable via `cudaDataType`). See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_xgeqrf_buffer_size as "cusolverDnXgeqrf_bufferSize": PFN_cusolverDnXgeqrf_bufferSize;
    /// cuSOLVER: generic-API QR factorization (Householder) (dtype configurable via `cudaDataType`). See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_xgeqrf as "cusolverDnXgeqrf": PFN_cusolverDnXgeqrf;
    /// cuSOLVER: generic-API workspace-size query for Cholesky factorization (dtype configurable via `cudaDataType`). See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_xpotrf_buffer_size as "cusolverDnXpotrf_bufferSize": PFN_cusolverDnXpotrf_bufferSize;
    /// cuSOLVER: generic-API Cholesky factorization (dtype configurable via `cudaDataType`). See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_xpotrf as "cusolverDnXpotrf": PFN_cusolverDnXpotrf;
    /// cuSOLVER: generic-API solve linear system using Cholesky factors (dtype configurable via `cudaDataType`). See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_xpotrs as "cusolverDnXpotrs": PFN_cusolverDnXpotrs;
    /// cuSOLVER: generic-API workspace-size query for symmetric eigendecomposition (divide-and-conquer) (dtype configurable via `cudaDataType`). See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_xsyevd_buffer_size as "cusolverDnXsyevd_bufferSize": PFN_cusolverDnXsyevd_bufferSize;
    /// cuSOLVER: generic-API symmetric eigendecomposition (divide-and-conquer) (dtype configurable via `cudaDataType`). See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_xsyevd as "cusolverDnXsyevd": PFN_cusolverDnXsyevd;
    // Jacobi eigen
    /// cuSOLVER: create a Jacobi-eigendecomposition control object. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_create_syevj_info as "cusolverDnCreateSyevjInfo": PFN_cusolverDnCreateSyevjInfo;
    /// cuSOLVER: destroy a Jacobi-eigendecomposition control object. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_destroy_syevj_info as "cusolverDnDestroySyevjInfo": PFN_cusolverDnDestroySyevjInfo;
    /// cuSOLVER: set convergence tolerance on a Jacobi-eigendecomposition control object. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_xsyevj_set_tolerance as "cusolverDnXsyevjSetTolerance": PFN_cusolverDnXsyevjSetTolerance;
    /// cuSOLVER: set the maximum number of sweeps on a Jacobi-eigendecomposition control object. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_xsyevj_set_max_sweeps as "cusolverDnXsyevjSetMaxSweeps": PFN_cusolverDnXsyevjSetMaxSweeps;
    /// cuSOLVER: single-precision workspace-size query for symmetric eigendecomposition (Jacobi). See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_ssyevj_buffer_size as "cusolverDnSsyevj_bufferSize": PFN_cusolverDnSsyevj_bufferSize;
    /// cuSOLVER: double-precision workspace-size query for symmetric eigendecomposition (Jacobi). See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_dsyevj_buffer_size as "cusolverDnDsyevj_bufferSize": PFN_cusolverDnDsyevj_bufferSize;
    /// cuSOLVER: single-precision complex workspace-size query for Hermitian eigendecomposition (Jacobi). See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_cheevj_buffer_size as "cusolverDnCheevj_bufferSize": PFN_cusolverDnCheevj_bufferSize;
    /// cuSOLVER: double-precision complex workspace-size query for Hermitian eigendecomposition (Jacobi). See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_zheevj_buffer_size as "cusolverDnZheevj_bufferSize": PFN_cusolverDnZheevj_bufferSize;
    /// cuSOLVER: single-precision symmetric eigendecomposition (Jacobi). See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_ssyevj as "cusolverDnSsyevj": PFN_cusolverDnSsyevj;
    /// cuSOLVER: double-precision symmetric eigendecomposition (Jacobi). See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_dsyevj as "cusolverDnDsyevj": PFN_cusolverDnDsyevj;
    /// cuSOLVER: single-precision complex Hermitian eigendecomposition (Jacobi). See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_cheevj as "cusolverDnCheevj": PFN_cusolverDnCheevj;
    /// cuSOLVER: double-precision complex Hermitian eigendecomposition (Jacobi). See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_zheevj as "cusolverDnZheevj": PFN_cusolverDnZheevj;
    // Jacobi SVD
    /// cuSOLVER: create a Jacobi-SVD control object. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_create_gesvdj_info as "cusolverDnCreateGesvdjInfo": PFN_cusolverDnCreateGesvdjInfo;
    /// cuSOLVER: destroy a Jacobi-SVD control object. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_destroy_gesvdj_info as "cusolverDnDestroyGesvdjInfo": PFN_cusolverDnDestroyGesvdjInfo;
    /// cuSOLVER: single-precision workspace-size query for Jacobi-method singular value decomposition. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_sgesvdj_buffer_size as "cusolverDnSgesvdj_bufferSize": PFN_cusolverDnSgesvdj_bufferSize;
    /// cuSOLVER: double-precision workspace-size query for Jacobi-method singular value decomposition. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_dgesvdj_buffer_size as "cusolverDnDgesvdj_bufferSize": PFN_cusolverDnDgesvdj_bufferSize;
    /// cuSOLVER: single-precision complex workspace-size query for Jacobi-method singular value decomposition. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_cgesvdj_buffer_size as "cusolverDnCgesvdj_bufferSize": PFN_cusolverDnCgesvdj_bufferSize;
    /// cuSOLVER: double-precision complex workspace-size query for Jacobi-method singular value decomposition. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_zgesvdj_buffer_size as "cusolverDnZgesvdj_bufferSize": PFN_cusolverDnZgesvdj_bufferSize;
    /// cuSOLVER: single-precision Jacobi-method singular value decomposition. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_sgesvdj as "cusolverDnSgesvdj": PFN_cusolverDnSgesvdj;
    /// cuSOLVER: double-precision Jacobi-method singular value decomposition. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_dgesvdj as "cusolverDnDgesvdj": PFN_cusolverDnDgesvdj;
    /// cuSOLVER: single-precision complex Jacobi-method singular value decomposition. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_cgesvdj as "cusolverDnCgesvdj": PFN_cusolverDnCgesvdj;
    /// cuSOLVER: double-precision complex Jacobi-method singular value decomposition. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_zgesvdj as "cusolverDnZgesvdj": PFN_cusolverDnZgesvdj;
    // orgqr / ormqr (apply/generate Q from QR)
    /// cuSOLVER: single-precision workspace-size query for generate the explicit Q from a QR factorization. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_sorgqr_buffer_size as "cusolverDnSorgqr_bufferSize": PFN_cusolverDnSorgqr_bufferSize;
    /// cuSOLVER: double-precision workspace-size query for generate the explicit Q from a QR factorization. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_dorgqr_buffer_size as "cusolverDnDorgqr_bufferSize": PFN_cusolverDnDorgqr_bufferSize;
    /// cuSOLVER: single-precision complex workspace-size query for generate the explicit unitary Q from a QR factorization. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_cungqr_buffer_size as "cusolverDnCungqr_bufferSize": PFN_cusolverDnCungqr_bufferSize;
    /// cuSOLVER: double-precision complex workspace-size query for generate the explicit unitary Q from a QR factorization. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_zungqr_buffer_size as "cusolverDnZungqr_bufferSize": PFN_cusolverDnZungqr_bufferSize;
    /// cuSOLVER: single-precision generate the explicit Q from a QR factorization. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_sorgqr as "cusolverDnSorgqr": PFN_cusolverDnSorgqr;
    /// cuSOLVER: double-precision generate the explicit Q from a QR factorization. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_dorgqr as "cusolverDnDorgqr": PFN_cusolverDnDorgqr;
    /// cuSOLVER: single-precision complex generate the explicit unitary Q from a QR factorization. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_cungqr as "cusolverDnCungqr": PFN_cusolverDnCungqr;
    /// cuSOLVER: double-precision complex generate the explicit unitary Q from a QR factorization. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_zungqr as "cusolverDnZungqr": PFN_cusolverDnZungqr;
    /// cuSOLVER: single-precision workspace-size query for apply Q (or Q^T) from a QR factorization to a matrix. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_sormqr_buffer_size as "cusolverDnSormqr_bufferSize": PFN_cusolverDnSormqr_bufferSize;
    /// cuSOLVER: double-precision workspace-size query for apply Q (or Q^T) from a QR factorization to a matrix. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_dormqr_buffer_size as "cusolverDnDormqr_bufferSize": PFN_cusolverDnDormqr_bufferSize;
    /// cuSOLVER: single-precision complex workspace-size query for apply Q (or Q^H) from a QR factorization to a matrix. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_cunmqr_buffer_size as "cusolverDnCunmqr_bufferSize": PFN_cusolverDnCunmqr_bufferSize;
    /// cuSOLVER: double-precision complex workspace-size query for apply Q (or Q^H) from a QR factorization to a matrix. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_zunmqr_buffer_size as "cusolverDnZunmqr_bufferSize": PFN_cusolverDnZunmqr_bufferSize;
    /// cuSOLVER: single-precision apply Q (or Q^T) from a QR factorization to a matrix. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_sormqr as "cusolverDnSormqr": PFN_cusolverDnSormqr;
    /// cuSOLVER: double-precision apply Q (or Q^T) from a QR factorization to a matrix. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_dormqr as "cusolverDnDormqr": PFN_cusolverDnDormqr;
    /// cuSOLVER: single-precision complex apply Q (or Q^H) from a QR factorization to a matrix. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_cunmqr as "cusolverDnCunmqr": PFN_cusolverDnCunmqr;
    /// cuSOLVER: double-precision complex apply Q (or Q^H) from a QR factorization to a matrix. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_zunmqr as "cusolverDnZunmqr": PFN_cusolverDnZunmqr;
    // Sparse
    /// cuSOLVER: create a sparse cuSOLVER handle. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_sp_create as "cusolverSpCreate": PFN_cusolverSpCreate;
    /// cuSOLVER: destroy a sparse cuSOLVER handle. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_sp_destroy as "cusolverSpDestroy": PFN_cusolverSpDestroy;
    /// cuSOLVER: bind a CUDA stream to a sparse cuSOLVER handle. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_sp_set_stream as "cusolverSpSetStream": PFN_cusolverSpSetStream;
    /// cuSOLVER: single-precision sparse linear solve via Cholesky on a CSR matrix. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_sp_scsrlsvchol as "cusolverSpScsrlsvchol": PFN_cusolverSpScsrlsvchol;
    /// cuSOLVER: double-precision sparse linear solve via Cholesky on a CSR matrix. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_sp_dcsrlsvchol as "cusolverSpDcsrlsvchol": PFN_cusolverSpDcsrlsvchol;
    /// cuSOLVER: single-precision sparse linear solve via QR on a CSR matrix. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_sp_scsrlsvqr as "cusolverSpScsrlsvqr": PFN_cusolverSpScsrlsvqr;
    /// cuSOLVER: double-precision sparse linear solve via QR on a CSR matrix. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_sp_dcsrlsvqr as "cusolverSpDcsrlsvqr": PFN_cusolverSpDcsrlsvqr;
    // Refactor
    /// cuSOLVER: create a sparse-refactor cuSOLVER handle. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_rf_create as "cusolverRfCreate": PFN_cusolverRfCreate;
    /// cuSOLVER: destroy a sparse-refactor cuSOLVER handle. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_rf_destroy as "cusolverRfDestroy": PFN_cusolverRfDestroy;
    /// cuSOLVER: supply sparse triangular factors and pivot vectors to the refactor handle. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_rf_setup_device as "cusolverRfSetupDevice": PFN_cusolverRfSetupDevice;
    /// cuSOLVER: analyze the sparsity pattern of the refactor handle. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_rf_analyze as "cusolverRfAnalyze": PFN_cusolverRfAnalyze;
    /// cuSOLVER: refactor with new numerical values reusing the analyzed pattern. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_rf_refactor as "cusolverRfRefactor": PFN_cusolverRfRefactor;
    /// cuSOLVER: solve linear systems using the refactor handle. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_rf_solve as "cusolverRfSolve": PFN_cusolverRfSolve;
    // Least squares (gels) S/D/C/Z
    /// cuSOLVER: single-precision workspace-size query for least-squares solver (A*X = B). See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_ssgels_buffer_size as "cusolverDnSSgels_bufferSize": PFN_cusolverDnSSgels_bufferSize;
    /// cuSOLVER: double-precision workspace-size query for least-squares solver (A*X = B). See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_ddgels_buffer_size as "cusolverDnDDgels_bufferSize": PFN_cusolverDnDDgels_bufferSize;
    /// cuSOLVER: single-precision complex workspace-size query for least-squares solver (A*X = B). See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_ccgels_buffer_size as "cusolverDnCCgels_bufferSize": PFN_cusolverDnCCgels_bufferSize;
    /// cuSOLVER: double-precision complex workspace-size query for least-squares solver (A*X = B). See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_zzgels_buffer_size as "cusolverDnZZgels_bufferSize": PFN_cusolverDnZZgels_bufferSize;
    /// cuSOLVER: single-precision least-squares solver (A*X = B). See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_ssgels as "cusolverDnSSgels": PFN_cusolverDnSSgels;
    /// cuSOLVER: double-precision least-squares solver (A*X = B). See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_ddgels as "cusolverDnDDgels": PFN_cusolverDnDDgels;
    /// cuSOLVER: single-precision complex least-squares solver (A*X = B). See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_ccgels as "cusolverDnCCgels": PFN_cusolverDnCCgels;
    /// cuSOLVER: double-precision complex least-squares solver (A*X = B). See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_zzgels as "cusolverDnZZgels": PFN_cusolverDnZZgels;
    // potri (inverse from Cholesky) S/D/C/Z
    /// cuSOLVER: single-precision workspace-size query for matrix inverse from Cholesky factors. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_spotri_buffer_size as "cusolverDnSpotri_bufferSize": PFN_cusolverDnSpotri_bufferSize;
    /// cuSOLVER: double-precision workspace-size query for matrix inverse from Cholesky factors. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_dpotri_buffer_size as "cusolverDnDpotri_bufferSize": PFN_cusolverDnDpotri_bufferSize;
    /// cuSOLVER: single-precision complex workspace-size query for matrix inverse from Cholesky factors. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_cpotri_buffer_size as "cusolverDnCpotri_bufferSize": PFN_cusolverDnCpotri_bufferSize;
    /// cuSOLVER: double-precision complex workspace-size query for matrix inverse from Cholesky factors. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_zpotri_buffer_size as "cusolverDnZpotri_bufferSize": PFN_cusolverDnZpotri_bufferSize;
    /// cuSOLVER: single-precision matrix inverse from Cholesky factors. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_spotri as "cusolverDnSpotri": PFN_cusolverDnSpotri;
    /// cuSOLVER: double-precision matrix inverse from Cholesky factors. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_dpotri as "cusolverDnDpotri": PFN_cusolverDnDpotri;
    /// cuSOLVER: single-precision complex matrix inverse from Cholesky factors. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_cpotri as "cusolverDnCpotri": PFN_cusolverDnCpotri;
    /// cuSOLVER: double-precision complex matrix inverse from Cholesky factors. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_zpotri as "cusolverDnZpotri": PFN_cusolverDnZpotri;
    // Batched Jacobi eigen
    /// cuSOLVER: single-precision workspace-size query for batched symmetric eigendecomposition (Jacobi). See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_ssyevj_batched_buffer_size as "cusolverDnSsyevjBatched_bufferSize": PFN_cusolverDnSsyevjBatched_bufferSize;
    /// cuSOLVER: double-precision workspace-size query for batched symmetric eigendecomposition (Jacobi). See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_dsyevj_batched_buffer_size as "cusolverDnDsyevjBatched_bufferSize": PFN_cusolverDnDsyevjBatched_bufferSize;
    /// cuSOLVER: single-precision complex workspace-size query for batched Hermitian eigendecomposition (Jacobi). See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_cheevj_batched_buffer_size as "cusolverDnCheevjBatched_bufferSize": PFN_cusolverDnCheevjBatched_bufferSize;
    /// cuSOLVER: double-precision complex workspace-size query for batched Hermitian eigendecomposition (Jacobi). See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_zheevj_batched_buffer_size as "cusolverDnZheevjBatched_bufferSize": PFN_cusolverDnZheevjBatched_bufferSize;
    /// cuSOLVER: single-precision batched symmetric eigendecomposition (Jacobi). See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_ssyevj_batched as "cusolverDnSsyevjBatched": PFN_cusolverDnSsyevjBatched;
    /// cuSOLVER: double-precision batched symmetric eigendecomposition (Jacobi). See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_dsyevj_batched as "cusolverDnDsyevjBatched": PFN_cusolverDnDsyevjBatched;
    /// cuSOLVER: single-precision complex batched Hermitian eigendecomposition (Jacobi). See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_cheevj_batched as "cusolverDnCheevjBatched": PFN_cusolverDnCheevjBatched;
    /// cuSOLVER: double-precision complex batched Hermitian eigendecomposition (Jacobi). See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_zheevj_batched as "cusolverDnZheevjBatched": PFN_cusolverDnZheevjBatched;
    // Batched Jacobi SVD
    /// cuSOLVER: single-precision workspace-size query for batched Jacobi-method singular value decomposition. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_sgesvdj_batched_buffer_size as "cusolverDnSgesvdjBatched_bufferSize": PFN_cusolverDnSgesvdjBatched_bufferSize;
    /// cuSOLVER: double-precision workspace-size query for batched Jacobi-method singular value decomposition. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_dgesvdj_batched_buffer_size as "cusolverDnDgesvdjBatched_bufferSize": PFN_cusolverDnDgesvdjBatched_bufferSize;
    /// cuSOLVER: single-precision complex workspace-size query for batched Jacobi-method singular value decomposition. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_cgesvdj_batched_buffer_size as "cusolverDnCgesvdjBatched_bufferSize": PFN_cusolverDnCgesvdjBatched_bufferSize;
    /// cuSOLVER: double-precision complex workspace-size query for batched Jacobi-method singular value decomposition. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_zgesvdj_batched_buffer_size as "cusolverDnZgesvdjBatched_bufferSize": PFN_cusolverDnZgesvdjBatched_bufferSize;
    /// cuSOLVER: single-precision batched Jacobi-method singular value decomposition. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_sgesvdj_batched as "cusolverDnSgesvdjBatched": PFN_cusolverDnSgesvdjBatched;
    /// cuSOLVER: double-precision batched Jacobi-method singular value decomposition. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_dgesvdj_batched as "cusolverDnDgesvdjBatched": PFN_cusolverDnDgesvdjBatched;
    /// cuSOLVER: single-precision complex batched Jacobi-method singular value decomposition. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_cgesvdj_batched as "cusolverDnCgesvdjBatched": PFN_cusolverDnCgesvdjBatched;
    /// cuSOLVER: double-precision complex batched Jacobi-method singular value decomposition. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_dn_zgesvdj_batched as "cusolverDnZgesvdjBatched": PFN_cusolverDnZgesvdjBatched;
}

/// Lazy-load the cuSOLVER dense / sparse / refactor shared library and return its function-pointer table.
pub fn cusolver() -> Result<&'static Cusolver, LoaderError> {
    static CUSOLVER: OnceLock<Cusolver> = OnceLock::new();
    if let Some(c) = CUSOLVER.get() {
        return Ok(c);
    }
    let candidates: Vec<&'static str> = cusolver_candidates()
        .into_iter()
        .map(|s| Box::leak(s.into_boxed_str()) as &'static str)
        .collect();
    let candidates_leaked: &'static [&'static str] = Box::leak(candidates.into_boxed_slice());
    let lib = Library::open("cusolver", candidates_leaked)?;
    let c = Cusolver::empty(lib);
    let _ = CUSOLVER.set(c);
    Ok(CUSOLVER.get().expect("OnceLock set or lost race"))
}

// ==========================================================================
// cuSOLVERMg — multi-GPU solver, ships in libcusolverMg (separate library)
// ==========================================================================

fn cusolver_mg_candidates() -> Vec<String> {
    platform::versioned_library_candidates("cusolverMg", &["13", "12", "11"])
}

macro_rules! cusolver_mg_fns {
    ($($(#[$m:meta])* $name:ident as $sym:literal : $pfn:ty);* $(;)?) => {
        /// Loaded cuSOLVERMg shared library plus a per-symbol `OnceLock` of function pointers.
        pub struct CusolverMg {
            lib: Library,
            $($name: OnceLock<$pfn>,)*
        }
        impl core::fmt::Debug for CusolverMg {
            fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
                f.debug_struct("CusolverMg").field("lib", &self.lib).finish_non_exhaustive()
            }
        }
        impl CusolverMg {
            $(
                $(#[$m])*
                pub fn $name(&self) -> Result<$pfn, LoaderError> {
                    if let Some(&p) = self.$name.get() { return Ok(p); }
                    let raw: *mut () = unsafe { self.lib.raw_symbol($sym)? };
                    let p: $pfn = unsafe { core::mem::transmute_copy::<*mut (), $pfn>(&raw) };
                    let _ = self.$name.set(p);
                    Ok(p)
                }
            )*
            fn empty(lib: Library) -> Self {
                Self { lib, $($name: OnceLock::new(),)* }
            }
        }
    };
}

cusolver_mg_fns! {
    /// cuSOLVER: create a multi-GPU dense cuSOLVERMg handle. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_mg_create as "cusolverMgCreate": PFN_cusolverMgCreate;
    /// cuSOLVER: destroy a multi-GPU dense cuSOLVERMg handle. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_mg_destroy as "cusolverMgDestroy": PFN_cusolverMgDestroy;
    /// cuSOLVER: select GPU devices for a cuSOLVERMg handle. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_mg_device_select as "cusolverMgDeviceSelect": PFN_cusolverMgDeviceSelect;
    /// cuSOLVER: create a multi-GPU device grid. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_mg_create_device_grid as "cusolverMgCreateDeviceGrid": PFN_cusolverMgCreateDeviceGrid;
    /// cuSOLVER: destroy a multi-GPU device grid. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_mg_destroy_grid as "cusolverMgDestroyGrid": PFN_cusolverMgDestroyGrid;
    /// cuSOLVER: create a multi-GPU matrix descriptor. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_mg_create_matrix_desc as "cusolverMgCreateMatrixDesc": PFN_cusolverMgCreateMatrixDesc;
    /// cuSOLVER: destroy a multi-GPU matrix descriptor. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_mg_destroy_matrix_desc as "cusolverMgDestroyMatrixDesc": PFN_cusolverMgDestroyMatrixDesc;
    /// cuSOLVER: multi-GPU workspace-size query for LU factorization with partial pivoting. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_mg_getrf_buffer_size as "cusolverMgGetrf_bufferSize": PFN_cusolverMgGetrf_bufferSize;
    /// cuSOLVER: multi-GPU LU factorization with partial pivoting. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_mg_getrf as "cusolverMgGetrf": PFN_cusolverMgGetrf;
    /// cuSOLVER: multi-GPU workspace-size query for Cholesky factorization. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_mg_potrf_buffer_size as "cusolverMgPotrf_bufferSize": PFN_cusolverMgPotrf_bufferSize;
    /// cuSOLVER: multi-GPU Cholesky factorization. See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_mg_potrf as "cusolverMgPotrf": PFN_cusolverMgPotrf;
    /// cuSOLVER: multi-GPU workspace-size query for symmetric eigendecomposition (divide-and-conquer). See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_mg_syevd_buffer_size as "cusolverMgSyevd_bufferSize": PFN_cusolverMgSyevd_bufferSize;
    /// cuSOLVER: multi-GPU symmetric eigendecomposition (divide-and-conquer). See <https://docs.nvidia.com/cuda/cusolver/index.html>.
    cusolver_mg_syevd as "cusolverMgSyevd": PFN_cusolverMgSyevd;
}

/// Lazy-load the cuSOLVERMg multi-GPU shared library and return its function-pointer table.
pub fn cusolver_mg() -> Result<&'static CusolverMg, LoaderError> {
    static MG: OnceLock<CusolverMg> = OnceLock::new();
    if let Some(c) = MG.get() {
        return Ok(c);
    }
    let candidates: Vec<&'static str> = cusolver_mg_candidates()
        .into_iter()
        .map(|s| Box::leak(s.into_boxed_str()) as &'static str)
        .collect();
    let leaked: &'static [&'static str] = Box::leak(candidates.into_boxed_slice());
    let lib = Library::open("cusolverMg", leaked)?;
    let _ = MG.set(CusolverMg::empty(lib));
    Ok(MG.get().expect("OnceLock set or lost race"))
}