enums.hh
Go to the documentation of this file.
1#pragma once
2#include <batchlas/export.hh>
3
4#include <complex>
5#include <concepts>
6#include <cstdint>
7#include <iosfwd>
8#include <string_view>
9#include <type_traits>
10
11/// @file
12/// @brief Enumerations, scalar traits and scalar concepts shared by every public header.
13///
14/// Every enum here has a `constexpr std::string_view to_string(E)` next to its
15/// definition that returns the enumerator's own spelling, and one templated
16/// `operator<<` at the end of the namespace prints all of them.
17
18// Backend and MatrixFormat carry BATCHLAS_API because they are non-type template
19// arguments: an instantiation gets the minimum visibility of its arguments, so an
20// unannotated enum hides every instantiation on it and consumers fail to link.
21// Annotate any further enum that becomes a template argument.
22// evidence: docs/design/symbol-visibility.md#symbol-visibility-enums-used-as-template-arguments
23namespace batchlas {
24 /// @addtogroup api_enums
25 /// @{
26
27 /// @brief Real type underlying a scalar: `T` itself for a real `T`, `R` for `std::complex<R>`.
28 template<typename T>
29 struct base_type {
30 using type = T; ///< The real type.
31 };
32
33 /// @brief Specialisation that strips `std::complex`.
34 template<typename T>
35 struct base_type<std::complex<T>> {
36 using type = T; ///< The component type `R` of `std::complex<R>`.
37 };
38
39 /// @brief Shorthand for `base_type<T>::type`: the precision of `T` (tolerances, norms, eigenvalues).
40 template<typename T>
41 using float_t = typename base_type<T>::type;
42
43 /// @brief True for `std::complex<R>`, false otherwise.
44 template <typename T>
45 struct is_std_complex : std::false_type {};
46
47 /// @brief Specialisation for `std::complex<R>`.
48 template <typename T>
49 struct is_std_complex<std::complex<T>> : std::true_type {};
50
51 /// @brief Value of is_std_complex<T>.
52 template <typename T>
54
55 /// @brief A real floating-point scalar (`float`, `double`).
56 template <typename T>
57 concept RealScalar = std::floating_point<T>;
58
59 /// @brief A `std::complex` scalar (`std::complex<float>`, `std::complex<double>`).
60 template <typename T>
62
63 /// @brief Any scalar the numerical entry points accept: real or complex floating point.
64 template <typename T>
66
67 /// @brief Storage format of a Matrix / MatrixView, used as a template argument.
68 ///
69 /// Only `Dense` and `CSR` have storage implementations; the other enumerators
70 /// name formats and are not instantiated by the library.
71 /// @see @ref design_matrix_model
72 enum class BATCHLAS_API MatrixFormat {
73 Dense, ///< Column-major dense storage with leading dimension and batch stride.
74 CSR, ///< Compressed Sparse Row.
75 CSC, ///< Compressed Sparse Column.
76 COO, ///< Coordinate.
77 SELL, ///< Sliced ELLPACK.
78 BSR, ///< Blocked Sparse Row.
79 BLOCKED_ELL ///< Blocked ELLPACK.
80 };
81
82 /// @brief Spelling of @p v as in source.
83 /// @ingroup api_enums_lowlevel
84 inline constexpr std::string_view to_string(MatrixFormat v) {
85 switch (v) {
86 case MatrixFormat::Dense: return "Dense";
87 case MatrixFormat::CSR: return "CSR";
88 case MatrixFormat::CSC: return "CSC";
89 case MatrixFormat::COO: return "COO";
90 case MatrixFormat::SELL: return "SELL";
91 case MatrixFormat::BSR: return "BSR";
92 case MatrixFormat::BLOCKED_ELL: return "BLOCKED_ELL";
93 }
94 return "MatrixFormat(?)";
95 }
96
97 /// @brief Constrains a member or overload to dense storage.
98 template <MatrixFormat F>
100
101 /// @brief Constrains a member or overload to CSR storage.
102 template <MatrixFormat F>
104
105 /// @brief Library family an entry point dispatches to, used as a template argument.
106 ///
107 /// Callers normally do not spell it: the queue-taking entry points take the
108 /// backend from the batchlas::Queue (Queue::backend(), Queue::set_backend()).
109 /// Only the backends compiled into the build (`BATCHLAS_HAS_*_BACKEND`) are
110 /// available; Queue::backend_available() reports which.
111 enum class BATCHLAS_API Backend {
112 AUTO, ///< A request, not a backend: the Queue resolves it from its device on first query.
113 CUDA, ///< NVIDIA GPU: cuBLAS / cuSOLVER / cuSPARSE and the native SYCL kernels.
114 ROCM, ///< AMD GPU: rocBLAS / rocSOLVER / rocSPARSE and the native SYCL kernels.
115 MKL, ///< Reserved; no dispatch target, never available.
116 MAGMA, ///< Reserved; no dispatch target, never available.
117 SYCL, ///< Native SYCL kernels on a GPU with no vendor library (AdaptiveCpp Metal); float and
118 ///< complex<float> only unless the build has device fp64 (`BATCHLAS_HAS_DEVICE_FP64`).
119 NETLIB ///< Host CBLAS / LAPACKE; the fallback for any device.
120 // Add more as needed
121 };
122
123 /// @brief Spelling of @p v as in source.
124 /// @ingroup api_enums_lowlevel
125 inline constexpr std::string_view to_string(Backend v) {
126 switch (v) {
127 case Backend::AUTO: return "AUTO";
128 case Backend::CUDA: return "CUDA";
129 case Backend::ROCM: return "ROCM";
130 case Backend::MKL: return "MKL";
131 case Backend::MAGMA: return "MAGMA";
132 case Backend::SYCL: return "SYCL";
133 case Backend::NETLIB: return "NETLIB";
134 }
135 return "Backend(?)";
136 }
137
138 /// @brief A vendor library inside a Backend; selects library-specific type and handle mappings.
139 enum class BackendLibrary {
140 CUBLAS, ///< Backend::CUDA.
141 CUSPARSE, ///< Backend::CUDA.
142 CUSOLVER, ///< Backend::CUDA.
143 ROCBLAS, ///< Backend::ROCM.
144 ROCSPARSE, ///< Backend::ROCM.
145 ROCSOLVER, ///< Backend::ROCM.
146 MAGMA, ///< Backend::MAGMA.
147 MKL, ///< Backend::MKL.
148 CBLAS, ///< Backend::NETLIB.
149 LAPACKE ///< Backend::NETLIB.
150 };
151
152 /// @brief Spelling of @p v as in source.
153 /// @ingroup api_enums_lowlevel
154 inline constexpr std::string_view to_string(BackendLibrary v) {
155 switch (v) {
156 case BackendLibrary::CUBLAS: return "CUBLAS";
157 case BackendLibrary::CUSPARSE: return "CUSPARSE";
158 case BackendLibrary::CUSOLVER: return "CUSOLVER";
159 case BackendLibrary::ROCBLAS: return "ROCBLAS";
160 case BackendLibrary::ROCSPARSE: return "ROCSPARSE";
161 case BackendLibrary::ROCSOLVER: return "ROCSOLVER";
162 case BackendLibrary::MAGMA: return "MAGMA";
163 case BackendLibrary::MKL: return "MKL";
164 case BackendLibrary::CBLAS: return "CBLAS";
165 case BackendLibrary::LAPACKE: return "LAPACKE";
166 }
167 return "BackendLibrary(?)";
168 }
169
170 /// @brief The operator op() applied to an operand: op(A) = A, A^T or A^H.
171 enum class Transpose {
172 NoTrans, ///< op(A) = A.
173 Trans, ///< op(A) = A^T.
174 ConjTrans ///< op(A) = A^H (the same as Trans for real scalars).
175 };
176
177 /// @brief Spelling of @p v as in source.
178 /// @ingroup api_enums_lowlevel
179 inline constexpr std::string_view to_string(Transpose v) {
180 switch (v) {
181 case Transpose::NoTrans: return "NoTrans";
182 case Transpose::Trans: return "Trans";
183 case Transpose::ConjTrans: return "ConjTrans";
184 }
185 return "Transpose(?)";
186 }
187
188 /// @brief Whether an eigensolver computes eigenvectors (LAPACK `jobz`).
189 enum class JobType {
190 EigenVectors, ///< Eigenvalues and eigenvectors (`jobz = 'V'`).
191 NoEigenVectors ///< Eigenvalues only (`jobz = 'N'`).
192 };
193
194 /// @brief Spelling of @p v as in source.
195 /// @ingroup api_enums_lowlevel
196 inline constexpr std::string_view to_string(JobType v) {
197 switch (v) {
198 case JobType::EigenVectors: return "EigenVectors";
199 case JobType::NoEigenVectors: return "NoEigenVectors";
200 }
201 return "JobType(?)";
202 }
203
204 /// @brief Which singular vectors gesvd computes for one factor (LAPACK `jobu` / `jobvt`).
205 ///
206 /// For an m x n input with k = min(m, n):
207 /// | Value | LAPACK | U | V^H |
208 /// | ------ | ------ | ------- | ------- |
209 /// | `None` | 'N' | not computed; its MatrixView is not touched | same |
210 /// | `All` | 'A' | m x m | n x n |
211 /// | `Thin` | 'S' | m x k, the first k left vectors | k x n, the first k right vectors, conjugated |
212 ///
213 /// Thin and All differ on at most one side: for m <= n a thin U is the full U,
214 /// for m >= n a thin V^H is the full V^H, and for square input they coincide on
215 /// both. Entry points canonicalise with canonical_jobu() / canonical_jobvh().
216 /// LAPACK's 'O' (overwrite A) is not offered.
217 /// @see @ref design_gesvd
218 // Append new enumerators only: benchmarks pass jobs as ints, so the ordinals are stable API.
219 // evidence: docs/design/gesvd.md#gesvd-design-why-svdvectorsthin-exists
220 enum class SvdVectors {
221 None, ///< Do not compute this factor.
222 All, ///< Full square factor (LAPACK 'A').
223 Thin ///< Economy factor with k = min(m, n) vectors (LAPACK 'S').
224 };
225
226 /// @brief Spelling of @p v as in source.
227 /// @ingroup api_enums_lowlevel
228 inline constexpr std::string_view to_string(SvdVectors v) {
229 switch (v) {
230 case SvdVectors::None: return "None";
231 case SvdVectors::All: return "All";
232 case SvdVectors::Thin: return "Thin";
233 }
234 return "SvdVectors(?)";
235 }
236
237 /// @brief Number of columns of U that @p job writes.
238 /// @param job the U job
239 /// @param m rows of the input
240 /// @param k min(m, n)
241 /// @return m for All, k for Thin, 0 for None (nothing is written)
242 /// @ingroup api_enums_lowlevel
243 inline constexpr int64_t svd_u_cols(SvdVectors job, int64_t m, int64_t k) {
244 return job == SvdVectors::All ? m : (job == SvdVectors::Thin ? k : 0);
245 }
246
247 /// @brief Number of rows of V^H that @p job writes.
248 /// @param job the V^H job
249 /// @param n columns of the input
250 /// @param k min(m, n)
251 /// @return n for All, k for Thin, 0 for None (nothing is written)
252 /// @ingroup api_enums_lowlevel
253 inline constexpr int64_t svd_vh_rows(SvdVectors job, int64_t n, int64_t k) {
254 return job == SvdVectors::All ? n : (job == SvdVectors::Thin ? k : 0);
255 }
256
257 /// @brief Rewrites a U job of Thin to All when both request the same shape (k == m).
258 ///
259 /// A kernel that cannot produce a genuinely thin factor then still serves every
260 /// Thin request that asks for nothing smaller.
261 /// @param job the requested U job
262 /// @param m rows of the input
263 /// @param k min(m, n)
264 /// @return All if @p job is Thin and k == m, otherwise @p job
265 /// @trap Call once per entry point and pass the result on: a `*_buffer_size` and
266 /// its run path must canonicalise identically, or the workspace is sized
267 /// for a different computation than the one performed.
268 /// @ingroup api_enums_lowlevel
269 inline constexpr SvdVectors canonical_jobu(SvdVectors job, int64_t m, int64_t k) {
270 return (job == SvdVectors::Thin && k == m) ? SvdVectors::All : job;
271 }
272
273 /// @brief Rewrites a V^H job of Thin to All when both request the same shape (k == n).
274 /// @param job the requested V^H job
275 /// @param n columns of the input
276 /// @param k min(m, n)
277 /// @return All if @p job is Thin and k == n, otherwise @p job
278 /// @see canonical_jobu() for the calling rule.
279 /// @ingroup api_enums_lowlevel
280 inline constexpr SvdVectors canonical_jobvh(SvdVectors job, int64_t n, int64_t k) {
281 return (job == SvdVectors::Thin && k == n) ? SvdVectors::All : job;
282 }
283
284 /// @brief Which triangle of a symmetric, Hermitian or triangular operand is referenced.
285 /// @trap In an option struct write `PotrfOptions{}`, never a bare `{}`: `{}` can
286 /// select the positional overload, whose `Uplo{}` is `Upper`.
287 enum class Uplo {
288 Upper, ///< The upper triangle (i <= j).
289 Lower ///< The lower triangle (i >= j).
290 };
291
292 /// @brief Spelling of @p v as in source.
293 /// @ingroup api_enums_lowlevel
294 inline constexpr std::string_view to_string(Uplo v) {
295 switch (v) {
296 case Uplo::Upper: return "Upper";
297 case Uplo::Lower: return "Lower";
298 }
299 return "Uplo(?)";
300 }
301
302 /// @brief Whether a triangular operand's diagonal is read or assumed to be one.
303 enum class Diag {
304 NonUnit, ///< The stored diagonal is used.
305 Unit ///< The diagonal is taken as 1 and not read.
306 };
307
308 /// @brief Spelling of @p v as in source.
309 /// @ingroup api_enums_lowlevel
310 inline constexpr std::string_view to_string(Diag v) {
311 switch (v) {
312 case Diag::NonUnit: return "NonUnit";
313 case Diag::Unit: return "Unit";
314 }
315 return "Diag(?)";
316 }
317
318 /// @brief Side on which a special operand multiplies: op(A) * B or B * op(A).
319 enum class Side {
320 Left, ///< The special operand is on the left.
321 Right ///< The special operand is on the right.
322 };
323
324 /// @brief Spelling of @p v as in source.
325 /// @ingroup api_enums_lowlevel
326 inline constexpr std::string_view to_string(Side v) {
327 switch (v) {
328 case Side::Left: return "Left";
329 case Side::Right: return "Right";
330 }
331 return "Side(?)";
332 }
333
334 /// @brief Order in which eigenvalues (and their vectors) are returned.
335 enum class SortOrder {
336 Ascending, ///< Smallest first.
337 Descending ///< Largest first.
338 };
339
340 /// @brief Spelling of @p v as in source.
341 /// @ingroup api_enums_lowlevel
342 inline constexpr std::string_view to_string(SortOrder v) {
343 switch (v) {
344 case SortOrder::Ascending: return "Ascending";
345 case SortOrder::Descending: return "Descending";
346 }
347 return "SortOrder(?)";
348 }
349
350 /// @brief Order in which a sequence of plane rotations is applied (steqr sweeps).
351 enum class ApplyOrder {
352 Forward, ///< First rotation first (a QR sweep).
353 Backward ///< Last rotation first (a QL sweep).
354 };
355
356 /// @brief Spelling of @p v as in source.
357 /// @ingroup api_enums_lowlevel
358 inline constexpr std::string_view to_string(ApplyOrder v) {
359 switch (v) {
360 case ApplyOrder::Forward: return "Forward";
361 case ApplyOrder::Backward: return "Backward";
362 }
363 return "ApplyOrder(?)";
364 }
365
366 /// @brief Algorithm family of the partial symmetric/Hermitian eigensolver `syevx`.
367 ///
368 /// `Auto` picks on matrix format, n, batch size and jobz; the number of requested
369 /// eigenpairs enters no threshold (`syevx_select_algorithm`). Set per call through SyevxParams::method, or
370 /// process-wide through `BATCHLAS_SYEVX_ALGORITHM`
371 /// (`auto|direct|direct_subset|filtered|lobpcg`). **The environment variable wins**
372 /// over SyevxParams::method, as a `BATCHLAS_<OP>_ROUTE` kernel pin does for the
373 /// other ops, so a whole application can be forced onto one algorithm for diagnosis.
374 ///
375 /// A choice the input cannot use degrades instead of failing: DirectSubset on
376 /// complex or sparse input runs Direct (dense) or LOBPCG (CSR), and Direct or
377 /// DirectSubset on CSR runs LOBPCG. A non-extremal SyevxSelect range is never
378 /// degraded to a different part of the spectrum: on CSR input, or with an
379 /// explicit LOBPCG or Filtered, it throws batchlas::invalid_argument (under the
380 /// environment override the dense case runs Direct instead). `syevx` and
381 /// `syevx_buffer_size` resolve the choice identically.
382 /// @see @ref perf_syevx for the routing thresholds, @ref design_syevx for the tiers.
383 enum class SyevxAlgorithm {
384 Auto, ///< Heuristic selection on format, n, batch size and jobz (the default).
385 Direct, ///< Full syev on a copy of A, then select the requested eigenpairs.
386 DirectSubset, ///< Two-stage reduction, bisection + inverse iteration on the subset (real, dense).
387 Filtered, ///< Chebyshev-filtered subspace iteration (dense and CSR); only when asked for.
388 LOBPCG ///< Locally Optimal Block Preconditioned Conjugate Gradient; the CSR default.
389 };
390
391 /// @brief Spelling of @p v as in source.
392 /// @ingroup api_enums_lowlevel
393 inline constexpr std::string_view to_string(SyevxAlgorithm v) {
394 switch (v) {
395 case SyevxAlgorithm::Auto: return "Auto";
396 case SyevxAlgorithm::Direct: return "Direct";
397 case SyevxAlgorithm::DirectSubset: return "DirectSubset";
398 case SyevxAlgorithm::Filtered: return "Filtered";
399 case SyevxAlgorithm::LOBPCG: return "LOBPCG";
400 }
401 return "SyevxAlgorithm(?)";
402 }
403
404 /// @brief Which part of the spectrum `syevx` returns.
405 ///
406 /// `Extremal` (the default) returns `neigs` eigenpairs from one end, chosen by
407 /// SyevxParams::find_largest: descending for the largest, ascending for the
408 /// smallest. It is the Index range [n-neigs, n-1] or [0, neigs-1] and is
409 /// normalised to one internally.
410 /// @note Deliberately not `EigenRangeType`, whose natural default `All` means
411 /// "every eigenvalue"; that type stays the tridiagonal-layer vocabulary.
412 /// @see @ref design_syevx_range
413 // evidence: docs/design/syevx-range-selection.md#syevx-range-syevxselect-rather-than-eigenrangetype
414 enum class SyevxSelect {
415 Extremal, ///< `neigs` eigenpairs from one end; SyevxParams::find_largest picks the end.
416 Index, ///< SyevxParams::il .. iu inclusive, 0-based in the ascending spectrum.
417 Value ///< Every eigenvalue in the half-open interval (vl, vu].
418 };
419
420 /// @brief Spelling of @p v as in source.
421 /// @ingroup api_enums_lowlevel
422 inline constexpr std::string_view to_string(SyevxSelect v) {
423 switch (v) {
424 case SyevxSelect::Extremal: return "Extremal";
425 case SyevxSelect::Index: return "Index";
426 case SyevxSelect::Value: return "Value";
427 }
428 return "SyevxSelect(?)";
429 }
430
431 /// @brief Preconditioner of the LOBPCG path of `syevx`; the other algorithms ignore it.
432 ///
433 /// Set per call through SyevxParams::preconditioner_type. `Auto` picks ILU(k)
434 /// when a factor was supplied (or requested through
435 /// SyevxParams::build_preconditioner), otherwise the default from
436 /// `BATCHLAS_SYEVX_PRECONDITIONER` (`auto|none|jacobi|jacobi_shifted|iluk`),
437 /// otherwise `None`. Unlike SyevxAlgorithm, **the environment variable only
438 /// supplies the default** and never overrides an explicit request.
439 ///
440 /// @ingroup api_enums_lowlevel
441 /// The two Jacobi forms are different operators. `Jacobi` approximates A^{-1},
442 /// so, like ILU(k), it is valid only for the smallest eigenpairs and
443 /// `find_largest` is rejected with it; on a batch item whose diagonal is not
444 /// uniformly positive it falls back to the identity. `JacobiShifted` shifts by
445 /// the current Ritz value and is valid at either end. `Auto` never picks either.
446 /// @see @ref perf_syevx for the measured iteration counts.
447 // evidence: docs/perf/syevx.md#lobpcg-jacobi-preconditioners
448 // evidence: docs/design/syevx.md#syevx-why-the-preconditioner-environment-variable-is-only-a-default
450 Auto, ///< ILU(k) if configured, else the environment default, else None.
451 None, ///< Unpreconditioned.
452 Jacobi, ///< diag(A)^{-1}; dense and CSR, smallest eigenpairs only.
453 JacobiShifted, ///< (diag(A) - lambda I)^{-1}; dense and CSR, either end.
454 ILUK ///< Supplied or syevx-built ILU(k) factor; CSR, smallest eigenpairs only.
455 };
456
457 /// @brief Spelling of @p v as in source.
458 /// @ingroup api_enums_lowlevel
459 inline constexpr std::string_view to_string(SyevxPreconditioner v) {
460 switch (v) {
461 case SyevxPreconditioner::Auto: return "Auto";
462 case SyevxPreconditioner::None: return "None";
463 case SyevxPreconditioner::Jacobi: return "Jacobi";
464 case SyevxPreconditioner::JacobiShifted: return "JacobiShifted";
465 case SyevxPreconditioner::ILUK: return "ILUK";
466 }
467 return "SyevxPreconditioner(?)";
468 }
469
470 /// @brief Algorithm used by `ortho` to orthonormalise the columns of a batch of blocks.
471 enum class OrthoAlgorithm {
472 Chol2, ///< CholeskyQR applied twice; the default.
473 Cholesky, ///< One CholeskyQR pass; rarely accurate enough on its own.
474 ShiftChol3, ///< Shifted CholeskyQR3; more robust than Chol2 on ill-conditioned blocks.
475 Householder, ///< Householder QR.
476 CGS2, ///< Classical Gram-Schmidt with one reorthogonalisation pass.
477 SVQB, ///< SVQB (orthonormalisation through the Gram matrix's eigendecomposition).
478 SVQB2, ///< SVQB applied twice.
479 NUM_ALGORITHMS ///< Count of the enumerators above, not an algorithm.
480 };
481
482 /// @brief Spelling of @p v as in source.
483 /// @ingroup api_enums_lowlevel
484 inline constexpr std::string_view to_string(OrthoAlgorithm v) {
485 switch (v) {
486 case OrthoAlgorithm::Chol2: return "Chol2";
487 case OrthoAlgorithm::Cholesky: return "Cholesky";
488 case OrthoAlgorithm::ShiftChol3: return "ShiftChol3";
489 case OrthoAlgorithm::Householder: return "Householder";
490 case OrthoAlgorithm::CGS2: return "CGS2";
491 case OrthoAlgorithm::SVQB: return "SVQB";
492 case OrthoAlgorithm::SVQB2: return "SVQB2";
493 case OrthoAlgorithm::NUM_ALGORITHMS: return "NUM_ALGORITHMS";
494 }
495 return "OrthoAlgorithm(?)";
496 }
497
498
499 /// @brief Internal compute precision of a GEMM (the cuBLAS `cublasComputeType_t`).
500 ///
501 /// Anything but `Default` is served only by the vendor library: the native GEMM
502 /// kernels do not support it. On cuBLAS, a single-precision scalar accepts
503 /// F32, F16, BF16 and TF32, a double-precision scalar only F64; any other
504 /// combination throws batchlas::unsupported.
505 enum class ComputePrecision {
506 Default, ///< The precision of the scalar type.
507 F32, ///< 32-bit float accumulation.
508 F64, ///< 64-bit float accumulation.
509 F16, ///< Half-precision inputs, 32-bit accumulation (`CUBLAS_COMPUTE_32F_FAST_16F`).
510 BF16, ///< bfloat16 inputs, 32-bit accumulation (`CUBLAS_COMPUTE_32F_FAST_16BF`).
511 TF32 ///< TensorFloat-32 inputs, 32-bit accumulation (`CUBLAS_COMPUTE_32F_FAST_TF32`).
512 };
513
514 /// @brief Spelling of @p v as in source.
515 /// @ingroup api_enums_lowlevel
516 inline constexpr std::string_view to_string(ComputePrecision v) {
517 switch (v) {
518 case ComputePrecision::Default: return "Default";
519 case ComputePrecision::F32: return "F32";
520 case ComputePrecision::F64: return "F64";
521 case ComputePrecision::F16: return "F16";
522 case ComputePrecision::BF16: return "BF16";
523 case ComputePrecision::TF32: return "TF32";
524 }
525 return "ComputePrecision(?)";
526 }
527
528 /// @brief How a VectorView is reinterpreted as a MatrixView: 1 x n or n x 1.
529 enum class VectorOrientation {
530 Row, ///< A 1 x n matrix; `ld` is the vector's `inc`.
531 Column ///< An n x 1 matrix; requires `inc == 1`.
532 };
533
534 /// @brief Spelling of @p v as in source.
535 /// @ingroup api_enums_lowlevel
536 inline constexpr std::string_view to_string(VectorOrientation v) {
537 switch (v) {
538 case VectorOrientation::Row: return "Row";
539 case VectorOrientation::Column: return "Column";
540 }
541 return "VectorOrientation(?)";
542 }
543
544 /// @brief Matrix norm computed by `norm` and used by the condition estimators.
545 enum class NormType {
546 Frobenius, ///< sqrt(sum |a_ij|^2).
547 One, ///< Maximum absolute column sum.
548 Inf, ///< Maximum absolute row sum.
549 Max, ///< Maximum absolute entry (not a consistent norm).
550 Spectral ///< Largest singular value; symmetric/Hermitian input only.
551 };
552
553 /// @brief Spelling of @p v as in source.
554 /// @ingroup api_enums_lowlevel
555 inline constexpr std::string_view to_string(NormType v) {
556 switch (v) {
557 case NormType::Frobenius: return "Frobenius";
558 case NormType::One: return "One";
559 case NormType::Inf: return "Inf";
560 case NormType::Max: return "Max";
561 case NormType::Spectral: return "Spectral";
562 }
563 return "NormType(?)";
564 }
565
566 /// @brief Storage order argument of the host CBLAS / LAPACKE calls.
567 ///
568 /// BatchLAS matrices are always column-major; this only labels host-library calls.
569 /// @see @ref design_matrix_model
570 enum class Layout {
571 RowMajor, ///< Row-major (CblasRowMajor).
572 ColMajor ///< Column-major (CblasColMajor).
573 };
574
575 /// @brief Spelling of @p v as in source.
576 /// @ingroup api_enums_lowlevel
577 inline constexpr std::string_view to_string(Layout v) {
578 switch (v) {
579 case Layout::RowMajor: return "RowMajor";
580 case Layout::ColMajor: return "ColMajor";
581 }
582 return "Layout(?)";
583 }
584
585 /// @brief Prints any BatchLAS enum as its enumerator spelling, via its to_string().
586 ///
587 /// Found by ADL. The printed text can be pasted back into source.
588 /// @param os output stream
589 /// @param value enumerator to print
590 /// @return @p os
591 /// @ingroup api_enums_lowlevel
592 // Templated on the stream so this header needs only <iosfwd>; it is pulled into device code.
593 // Constrained on to_string so an enum without a printer gets no operator<< rather than a broken one.
594 template <typename CharT, typename Traits, typename E>
595 requires std::is_enum_v<E> && requires(E e) { to_string(e); }
596 std::basic_ostream<CharT, Traits>& operator<<(std::basic_ostream<CharT, Traits>& os, E value) {
597 return os << to_string(value);
598 }
599
600 /// @}
601}
A std::complex scalar (std::complex<float>, std::complex<double>).
Definition enums.hh:61
Constrains a member or overload to CSR storage.
Definition enums.hh:103
Constrains a member or overload to dense storage.
Definition enums.hh:99
Any scalar the numerical entry points accept: real or complex floating point.
Definition enums.hh:65
A real floating-point scalar (float, double).
Definition enums.hh:57
std::basic_ostream< CharT, Traits > & operator<<(std::basic_ostream< CharT, Traits > &os, E value)
Prints any BatchLAS enum as its enumerator spelling, via its to_string().
Definition enums.hh:596
constexpr SvdVectors canonical_jobu(SvdVectors job, int64_t m, int64_t k)
Rewrites a U job of Thin to All when both request the same shape (k == m).
Definition enums.hh:269
constexpr SvdVectors canonical_jobvh(SvdVectors job, int64_t n, int64_t k)
Rewrites a V^H job of Thin to All when both request the same shape (k == n).
Definition enums.hh:280
SyevxPreconditioner
Preconditioner of the LOBPCG path of syevx; the other algorithms ignore it.
Definition enums.hh:449
constexpr int64_t svd_u_cols(SvdVectors job, int64_t m, int64_t k)
Number of columns of U that job writes.
Definition enums.hh:243
constexpr std::string_view to_string(MatrixFormat v)
Spelling of v as in source.
Definition enums.hh:84
constexpr int64_t svd_vh_rows(SvdVectors job, int64_t n, int64_t k)
Number of rows of V^H that job writes.
Definition enums.hh:253
@ Auto
ILU(k) if configured, else the environment default, else None.
Definition enums.hh:450
@ ILUK
Supplied or syevx-built ILU(k) factor; CSR, smallest eigenpairs only.
Definition enums.hh:454
@ Jacobi
diag(A)^{-1}; dense and CSR, smallest eigenpairs only.
Definition enums.hh:452
@ None
Unpreconditioned.
Definition enums.hh:451
@ JacobiShifted
(diag(A) - lambda I)^{-1}; dense and CSR, either end.
Definition enums.hh:453
JobType
Whether an eigensolver computes eigenvectors (LAPACK jobz).
Definition enums.hh:189
Transpose
The operator op() applied to an operand: op(A) = A, A^T or A^H.
Definition enums.hh:171
Diag
Whether a triangular operand's diagonal is read or assumed to be one.
Definition enums.hh:303
NormType
Matrix norm computed by norm and used by the condition estimators.
Definition enums.hh:545
SyevxSelect
Which part of the spectrum syevx returns.
Definition enums.hh:414
SortOrder
Order in which eigenvalues (and their vectors) are returned.
Definition enums.hh:335
Backend
Library family an entry point dispatches to, used as a template argument.
Definition enums.hh:111
ComputePrecision
Internal compute precision of a GEMM (the cuBLAS cublasComputeType_t).
Definition enums.hh:505
Uplo
Which triangle of a symmetric, Hermitian or triangular operand is referenced.
Definition enums.hh:287
SvdVectors
Which singular vectors gesvd computes for one factor (LAPACK jobu / jobvt).
Definition enums.hh:220
BackendLibrary
A vendor library inside a Backend; selects library-specific type and handle mappings.
Definition enums.hh:139
VectorOrientation
How a VectorView is reinterpreted as a MatrixView: 1 x n or n x 1.
Definition enums.hh:529
constexpr bool is_std_complex_v
Value of is_std_complex<T>.
Definition enums.hh:53
typename base_type< T >::type float_t
Shorthand for base_type<T>::type: the precision of T (tolerances, norms, eigenvalues).
Definition enums.hh:41
OrthoAlgorithm
Algorithm used by ortho to orthonormalise the columns of a batch of blocks.
Definition enums.hh:471
MatrixFormat
Storage format of a Matrix / MatrixView, used as a template argument.
Definition enums.hh:72
Layout
Storage order argument of the host CBLAS / LAPACKE calls.
Definition enums.hh:570
ApplyOrder
Order in which a sequence of plane rotations is applied (steqr sweeps).
Definition enums.hh:351
SyevxAlgorithm
Algorithm family of the partial symmetric/Hermitian eigensolver syevx.
Definition enums.hh:383
Side
Side on which a special operand multiplies: op(A) * B or B * op(A).
Definition enums.hh:319
@ NoEigenVectors
Eigenvalues only (jobz = 'N').
Definition enums.hh:191
@ EigenVectors
Eigenvalues and eigenvectors (jobz = 'V').
Definition enums.hh:190
@ Trans
op(A) = A^T.
Definition enums.hh:173
@ NoTrans
op(A) = A.
Definition enums.hh:172
@ ConjTrans
op(A) = A^H (the same as Trans for real scalars).
Definition enums.hh:174
@ Unit
The diagonal is taken as 1 and not read.
Definition enums.hh:305
@ NonUnit
The stored diagonal is used.
Definition enums.hh:304
@ Inf
Maximum absolute row sum.
Definition enums.hh:548
@ One
Maximum absolute column sum.
Definition enums.hh:547
@ Max
Maximum absolute entry (not a consistent norm).
Definition enums.hh:549
@ Frobenius
sqrt(sum |a_ij|^2).
Definition enums.hh:546
@ Spectral
Largest singular value; symmetric/Hermitian input only.
Definition enums.hh:550
@ Value
Every eigenvalue in the half-open interval (vl, vu].
Definition enums.hh:417
@ Index
SyevxParams::il .. iu inclusive, 0-based in the ascending spectrum.
Definition enums.hh:416
@ Extremal
neigs eigenpairs from one end; SyevxParams::find_largest picks the end.
Definition enums.hh:415
@ Ascending
Smallest first.
Definition enums.hh:336
@ Descending
Largest first.
Definition enums.hh:337
@ MAGMA
Reserved; no dispatch target, never available.
Definition enums.hh:116
@ NETLIB
Host CBLAS / LAPACKE; the fallback for any device.
Definition enums.hh:119
@ SYCL
Native SYCL kernels on a GPU with no vendor library (AdaptiveCpp Metal); float and complex<float> onl...
Definition enums.hh:117
@ ROCM
AMD GPU: rocBLAS / rocSOLVER / rocSPARSE and the native SYCL kernels.
Definition enums.hh:114
@ MKL
Reserved; no dispatch target, never available.
Definition enums.hh:115
@ CUDA
NVIDIA GPU: cuBLAS / cuSOLVER / cuSPARSE and the native SYCL kernels.
Definition enums.hh:113
@ AUTO
A request, not a backend: the Queue resolves it from its device on first query.
Definition enums.hh:112
@ F64
64-bit float accumulation.
Definition enums.hh:508
@ F32
32-bit float accumulation.
Definition enums.hh:507
@ F16
Half-precision inputs, 32-bit accumulation (CUBLAS_COMPUTE_32F_FAST_16F).
Definition enums.hh:509
@ Default
The precision of the scalar type.
Definition enums.hh:506
@ TF32
TensorFloat-32 inputs, 32-bit accumulation (CUBLAS_COMPUTE_32F_FAST_TF32).
Definition enums.hh:511
@ BF16
bfloat16 inputs, 32-bit accumulation (CUBLAS_COMPUTE_32F_FAST_16BF).
Definition enums.hh:510
@ Upper
The upper triangle (i <= j).
Definition enums.hh:288
@ Lower
The lower triangle (i >= j).
Definition enums.hh:289
@ None
Do not compute this factor.
Definition enums.hh:221
@ Thin
Economy factor with k = min(m, n) vectors (LAPACK 'S').
Definition enums.hh:223
@ All
Full square factor (LAPACK 'A').
Definition enums.hh:222
@ MAGMA
Backend::MAGMA.
Definition enums.hh:146
@ ROCSOLVER
Backend::ROCM.
Definition enums.hh:145
@ CBLAS
Backend::NETLIB.
Definition enums.hh:148
@ CUBLAS
Backend::CUDA.
Definition enums.hh:140
@ ROCSPARSE
Backend::ROCM.
Definition enums.hh:144
@ MKL
Backend::MKL.
Definition enums.hh:147
@ LAPACKE
Backend::NETLIB.
Definition enums.hh:149
@ CUSOLVER
Backend::CUDA.
Definition enums.hh:142
@ CUSPARSE
Backend::CUDA.
Definition enums.hh:141
@ ROCBLAS
Backend::ROCM.
Definition enums.hh:143
@ Column
An n x 1 matrix; requires inc == 1.
Definition enums.hh:531
@ Row
A 1 x n matrix; ld is the vector's inc.
Definition enums.hh:530
@ CGS2
Classical Gram-Schmidt with one reorthogonalisation pass.
Definition enums.hh:476
@ SVQB2
SVQB applied twice.
Definition enums.hh:478
@ ShiftChol3
Shifted CholeskyQR3; more robust than Chol2 on ill-conditioned blocks.
Definition enums.hh:474
@ Householder
Householder QR.
Definition enums.hh:475
@ SVQB
SVQB (orthonormalisation through the Gram matrix's eigendecomposition).
Definition enums.hh:477
@ NUM_ALGORITHMS
Count of the enumerators above, not an algorithm.
Definition enums.hh:479
@ Cholesky
One CholeskyQR pass; rarely accurate enough on its own.
Definition enums.hh:473
@ Chol2
CholeskyQR applied twice; the default.
Definition enums.hh:472
@ BLOCKED_ELL
Blocked ELLPACK.
Definition enums.hh:79
@ CSC
Compressed Sparse Column.
Definition enums.hh:75
@ BSR
Blocked Sparse Row.
Definition enums.hh:78
@ SELL
Sliced ELLPACK.
Definition enums.hh:77
@ Dense
Column-major dense storage with leading dimension and batch stride.
Definition enums.hh:73
@ CSR
Compressed Sparse Row.
Definition enums.hh:74
@ COO
Coordinate.
Definition enums.hh:76
@ ColMajor
Column-major (CblasColMajor).
Definition enums.hh:572
@ RowMajor
Row-major (CblasRowMajor).
Definition enums.hh:571
@ Forward
First rotation first (a QR sweep).
Definition enums.hh:352
@ Backward
Last rotation first (a QL sweep).
Definition enums.hh:353
@ Auto
Heuristic selection on format, n, batch size and jobz (the default).
Definition enums.hh:384
@ DirectSubset
Two-stage reduction, bisection + inverse iteration on the subset (real, dense).
Definition enums.hh:386
@ LOBPCG
Locally Optimal Block Preconditioned Conjugate Gradient; the CSR default.
Definition enums.hh:388
@ Direct
Full syev on a copy of A, then select the requested eigenpairs.
Definition enums.hh:385
@ Filtered
Chebyshev-filtered subspace iteration (dense and CSR); only when asked for.
Definition enums.hh:387
@ Right
The special operand is on the right.
Definition enums.hh:321
@ Left
The special operand is on the left.
Definition enums.hh:320
T type
The component type R of std::complex<R>.
Definition enums.hh:36
Real type underlying a scalar: T itself for a real T, R for std::complex<R>.
Definition enums.hh:29
T type
The real type.
Definition enums.hh:30
True for std::complex<R>, false otherwise.
Definition enums.hh:45