Eigen-Contrib  5.0.1-dev+master
 
Loading...
Searching...
No Matches
CuDssSupport.h
1// This file is part of Eigen, a lightweight C++ template library
2// for linear algebra.
3//
4// Copyright (C) 2026 Rasmus Munk Larsen <rmlarsen@gmail.com>
5//
6// This Source Code Form is subject to the terms of the Mozilla
7// Public License v. 2.0. If a copy of the MPL was not distributed
8// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9// SPDX-License-Identifier: MPL-2.0
10
11// cuDSS-specific support types. cuDSS is NVIDIA's sparse direct solver library
12// (Cholesky, LDL^T, LU); it requires CUDA 12.0+ and ships separately from the
13// CUDA Toolkit.
14
15#ifndef EIGEN_GPU_CUDSS_SUPPORT_H
16#define EIGEN_GPU_CUDSS_SUPPORT_H
17
18// IWYU pragma: private
19#include "./InternalHeaderCheck.h"
20
21#include "./GpuSupport.h"
22#include <cudss.h>
23
29#if defined(CUDSS_VERSION) && CUDSS_VERSION >= 800
30#define EIGEN_HAS_CUDSS_SOLVER_CONFIG 1
31#else
32#define EIGEN_HAS_CUDSS_SOLVER_CONFIG 0
33#endif
34
35namespace Eigen {
36namespace gpu {
37namespace internal {
38#define EIGEN_CUDSS_CHECK(x) \
39 do { \
40 const cudssStatus_t _s = (x); \
41 if (_s != CUDSS_STATUS_SUCCESS) \
42 ::Eigen::gpu::internal::gpu_check_failed_code("cuDSS", static_cast<int>(_s), #x, __FILE__, __LINE__); \
43 } while (0)
44
45// cuDSS 0.8 changed cudssMatrixCreateDn/Csr from cudaDataType_t to the
46// value-compatible cudssDataType_t (CUDSS_R_32F == CUDA_R_32F, ...); cuDSS 1.0
47// changed them back and kept cudssDataType_t only as a deprecated typedef of
48// cudaDataType_t. Map the module's cudaDataType_t traits through this alias so
49// all three API generations compile without deprecation warnings. CUDSS_VERSION
50// is major * 10000 + minor * 100 + patch: 0.8.0 is 800, 1.0.0 is 10000.
51#if defined(CUDSS_VERSION) && CUDSS_VERSION >= 800 && CUDSS_VERSION < 10000
52using cudss_value_type_t = cudssDataType_t;
53#else
54using cudss_value_type_t = cudaDataType_t;
55#endif
56
57constexpr cudss_value_type_t to_cudss_data_type(cudaDataType_t t) { return static_cast<cudss_value_type_t>(t); }
58
59template <typename Scalar>
60struct cudss_spd_type;
61
62template <>
63struct cudss_spd_type<float> {
64 static constexpr cudssMatrixType_t value = CUDSS_MTYPE_SPD;
65};
66template <>
67struct cudss_spd_type<double> {
68 static constexpr cudssMatrixType_t value = CUDSS_MTYPE_SPD;
69};
70template <>
71struct cudss_spd_type<std::complex<float>> {
72 static constexpr cudssMatrixType_t value = CUDSS_MTYPE_HPD;
73};
74template <>
75struct cudss_spd_type<std::complex<double>> {
76 static constexpr cudssMatrixType_t value = CUDSS_MTYPE_HPD;
77};
78
79// Real → SYMMETRIC (A = A^T), complex → HERMITIAN (A = A^H). cuDSS also accepts
80// CUDSS_MTYPE_SYMMETRIC for complex (A = A^T, no conjugation), but SparseLDLT
81// implements Eigen's SimplicialLDLT semantics, which are Hermitian for complex.
82// Complex symmetric would need a separate trait and solver mode.
83template <typename Scalar>
84struct cudss_hermitian_type;
85
86template <>
87struct cudss_hermitian_type<float> {
88 static constexpr cudssMatrixType_t value = CUDSS_MTYPE_SYMMETRIC;
89};
90template <>
91struct cudss_hermitian_type<double> {
92 static constexpr cudssMatrixType_t value = CUDSS_MTYPE_SYMMETRIC;
93};
94template <>
95struct cudss_hermitian_type<std::complex<float>> {
96 static constexpr cudssMatrixType_t value = CUDSS_MTYPE_HERMITIAN;
97};
98template <>
99struct cudss_hermitian_type<std::complex<double>> {
100 static constexpr cudssMatrixType_t value = CUDSS_MTYPE_HERMITIAN;
101};
102
103template <typename StorageIndex>
104struct cudss_index_type;
105
106template <>
107struct cudss_index_type<int> {
108 static constexpr cudaDataType_t value = CUDA_R_32I;
109};
110template <>
111struct cudss_index_type<int64_t> {
112 static constexpr cudaDataType_t value = CUDA_R_64I;
113};
114
115// A symmetric matrix stored as CSC (ColMajor) reaches cuDSS as CSR of A^T. The
116// data is identical since A = A^T, but the triangle view must be swapped.
117template <int UpLo, int StorageOrder>
118struct cudss_view_type;
119
120template <>
121struct cudss_view_type<Lower, ColMajor> {
122 static constexpr cudssMatrixViewType_t value = CUDSS_MVIEW_UPPER;
123};
124template <>
125struct cudss_view_type<Upper, ColMajor> {
126 static constexpr cudssMatrixViewType_t value = CUDSS_MVIEW_LOWER;
127};
128
129template <>
130struct cudss_view_type<Lower, RowMajor> {
131 static constexpr cudssMatrixViewType_t value = CUDSS_MVIEW_LOWER;
132};
133template <>
134struct cudss_view_type<Upper, RowMajor> {
135 static constexpr cudssMatrixViewType_t value = CUDSS_MVIEW_UPPER;
136};
137} // namespace internal
138} // namespace gpu
139} // namespace Eigen
140
141#endif // EIGEN_GPU_CUDSS_SUPPORT_H
Namespace containing all symbols from the Eigen library.