-
Notifications
You must be signed in to change notification settings - Fork 15
SVD in CUDA
The calculation of the Singular Value Decomposition (SVD) of a matrix is at the basis of many computations and approaches in applied science. One example is the regularized solution of linear systems of equations. Another is Principal Component Analysis.
Many times, the applications requiring the SVD calculation deal with large matrices and/or request the SVD computation in an iterative process. Fortunately, the SVD can be quickly computed in CUDA using the routines provided in the cuSOLVER library. Below, we provide few representative examples relevant in common situations.
Before proceeding further, two points to remember:
-
gesvdroutines assumeNrows >= Ncols. Of course, the caseNrows < Ncolscan be dealt with by matrix transposition, for example bycublas<t>geam(); - column major ordering is assumed.
The full example is contained in the SVD.cu file.
The first step towards SVD calculation in CUDA is to initialize the cuSOLVER, as is required for any other routine of the cuSOLVER library:
cusolverDnHandle_t solver_handle;
cusolverDnCreate(&solver_handle);
The second step is to allocate the buffer space required by the SVD calculation routine:
cusolveSafeCall(cusolverDnDgesvd_bufferSize(solver_handle, Nrows, Ncols, &work_size));
double *work; gpuErrchk(cudaMalloc(&work, work_size * sizeof(double)));