Hi all, I am writing a fused kernel that involves using cuSolverDx’s heev to compute eigenvalues and eigenvectors of small Hermitian positive semidefinite matrices of type complex float stored in column major. I am using cuSolverDx 0.5.0 with CUDA 13.0 on an RTX 6000 Ada.
When the matrix has exactly one eigenvalue that is exactly zero, sometimes cuSolverDx heev would give one correct eigenvalue with the rest of the eigenvalues being nan while returning info 0. Here’s what I mean by “sometimes”. For each of the following cases, I apply cuSolverDx heev to 2^20 random matrices.
- The bug does not happen on full rank matrices.
- When there is exactly one eigenvalue that is exactly zero, the bug occurs around 10 times out of the 2^20 random matrices I’ve tried.
- When there are exactly two eigenvalues that are exactly zero, the bug does not happen.
I have attached below a minimal reproducer with one of the failed cases involving a 4-by-4 rank-3 upper triangular matrix of type complex float stored in column major. The equivalent LAPACK 3.9.0’s cheev gives the correct answer. As additional reference, I also tried the failed case on cuSOLVER’s heevjBatched, XsyevBatched, and heevd, they also give the correct answer.
I am aware of a very recent bug report on a different routine (cuSOLVERDnXgeev), and I am not sure whether the two bugs are related.
// Minimal reproducer:
// cuSolverDx's heev returns nan eigenvalues with info = 0
// cuSOLVER's heevjBatched, XsyevBatched, and heevd return correct eigenvalues with info = 0
//
// MathDx 26.06.1, cuSolverDx 0.5.0, cuSOLVER 12.0.4, CUDA 13.0, LAPACK 3.9.0, RTX 6000 Ada
//
// Build:
// X=external/mathdx; C=/usr/pubsw/packages/CUDA/13.0
// $C/bin/nvcc -std=c++17 -arch=sm_89 -rdc=true -dlto -I$X/include -I$X/external/cutlass/include heev_nan_repro.cu \
// -L$X/lib -lcusolverdx -lcusolver -llapack -Xlinker -rpath,$C/lib64 -o heev_nan_repro && ./heev_nan_repro
#include <cstdio>
#include <complex>
#include <cusolverDn.h>
#include <cusolverdx.hpp>
using Heev = decltype(cusolverdx::Size<4>() + cusolverdx::Precision<float>() + cusolverdx::Type<cusolverdx::type::complex>()
+ cusolverdx::Function<cusolverdx::heev>() + cusolverdx::FillMode<cusolverdx::fill_mode::upper>()
+ cusolverdx::Arrangement<cusolverdx::arrangement::col_major>() + cusolverdx::Job<cusolverdx::job::no_vectors>()
+ cusolverdx::SM<890>() + cusolverdx::Thread());
extern "C" void cheev_(const char *jobz, const char *uplo, const int *n, std::complex<float> *a, const int *lda, float *w,
std::complex<float> *work, const int *lwork, float *rwork, int *info, size_t, size_t);
static const std::complex<float> G[16] = {
{3.664379835e+00f, 0.f}, {}, {}, {},
{-5.536674261e-01f, 9.496642947e-01f}, {5.122905374e-01f, 0.f}, {}, {},
{-2.275886059e+00f, 9.832407832e-01f}, {4.101600945e-01f, 2.608992755e-01f}, {2.376560450e+00f, 0.f}, {},
{2.731287479e-01f, 1.057614088e+00f}, {2.444558889e-01f, -3.210833073e-01f}, {-3.514528275e-03f, -8.952040076e-01f}, {7.113531232e-01f, 0.f}};
__global__ void kernel(std::complex<float> *a, float *w, int *info)
{
Heev::a_data_type work[Heev::workspace_size];
Heev().execute(reinterpret_cast<Heev::a_data_type *>(a), w, work, info);
}
int main()
{
std::complex<float> *a;
float *w;
int *info;
cudaMallocManaged(&a, sizeof G);
cudaMallocManaged(&w, 4 * sizeof(float));
cudaMallocManaged(&info, sizeof(int));
// cuSolverDx heev
std::copy(G, G + 16, a);
kernel<<<1, 1>>>(a, w, info);
cudaDeviceSynchronize();
printf("cuSolverDx heev: info %d, eigenvalues %g %g %g %g\n", *info, w[0], w[1], w[2], w[3]);
// cuSOLVER
cusolverDnHandle_t h;
syevjInfo_t jp;
cusolverDnParams_t xp;
cusolverDnCreate(&h);
cusolverDnCreateSyevjInfo(&jp);
cusolverDnCreateParams(&xp);
const auto jobz = CUSOLVER_EIG_MODE_NOVECTOR;
const auto uplo = CUBLAS_FILL_MODE_UPPER;
int lw;
size_t dws, hws;
void *dwork, *hwork;
// cuSOLVER: cusolverDnCheevjBatched
std::copy(G, G + 16, a);
cusolverDnCheevjBatched_bufferSize(h, jobz, uplo, 4, (cuComplex *)a, 4, w, &lw, jp, 1);
cudaMalloc(&dwork, lw * sizeof(cuComplex));
cusolverDnCheevjBatched(h, jobz, uplo, 4, (cuComplex *)a, 4, w, (cuComplex *)dwork, lw, info, jp, 1);
cudaDeviceSynchronize();
printf("cuSOLVER heevjBatched: info %d, eigenvalues %g %g %g %g\n", *info, w[0], w[1], w[2], w[3]);
cudaFree(dwork);
// cuSOLVER: cusolverDnXsyevBatched
std::copy(G, G + 16, a);
cusolverDnXsyevBatched_bufferSize(h, xp, jobz, uplo, 4, CUDA_C_32F, a, 4, CUDA_R_32F, w, CUDA_C_32F, &dws, &hws, 1);
cudaMalloc(&dwork, dws + 1);
hwork = malloc(hws + 1);
cusolverDnXsyevBatched(h, xp, jobz, uplo, 4, CUDA_C_32F, a, 4, CUDA_R_32F, w, CUDA_C_32F, dwork, dws, hwork, hws, info, 1);
cudaDeviceSynchronize();
printf("cuSOLVER XsyevBatched: info %d, eigenvalues %g %g %g %g\n", *info, w[0], w[1], w[2], w[3]);
cudaFree(dwork);
free(hwork);
// cuSOLVER: cusolverDnCheevd
std::copy(G, G + 16, a);
cusolverDnCheevd_bufferSize(h, jobz, uplo, 4, (cuComplex *)a, 4, w, &lw);
cudaMalloc(&dwork, lw * sizeof(cuComplex));
cusolverDnCheevd(h, jobz, uplo, 4, (cuComplex *)a, 4, w, (cuComplex *)dwork, lw, info);
cudaDeviceSynchronize();
printf("cuSOLVER heevd: info %d, eigenvalues %g %g %g %g\n", *info, w[0], w[1], w[2], w[3]);
cudaFree(dwork);
// LAPACK: cheev
std::complex<float> b[16], work[64];
float wl[4], rwork[12];
int n = 4, lwork = 64, linfo;
std::copy(G, G + 16, b);
cheev_("N", "U", &n, b, &n, wl, work, &lwork, rwork, &linfo, 1, 1);
printf("LAPACK cheev (reference): info %d, eigenvalues %g %g %g %g\n", linfo, wl[0], wl[1], wl[2], wl[3]);
}
Output:
cuSolverDx heev: info 0, eigenvalues nan nan nan 0.365793
cuSOLVER heevjBatched: info 0, eigenvalues 1.50494e-08 0.365793 0.673537 6.22526
cuSOLVER XsyevBatched: info 0, eigenvalues 2.19498e-07 0.365792 0.673537 6.22526
cuSOLVER heevd: info 0, eigenvalues -1.17751e-07 0.365793 0.673537 6.22525
LAPACK cheev (reference): info 0, eigenvalues 4.50742e-08 0.365793 0.673537 6.22526