This code demonstrates a usage of cuSOLVER gesvd function to perform singular value decomposition
A = U * Σ * VH
A is a 3x2 dense matrices,
A = | 1.0 | 2.0 |
| 4.0 | 5.0 |
| 2.0 | 1.0 |
The following code uses three steps:
Step 1: compute A = USVT
Step 2: check accuracy of singular value
Step 3: measure residual A-USVT
All GPUs supported by CUDA Toolkit (https://developer.nvidia.com/cuda-gpus)
Linux
Windows
x86_64
ppc64le
arm64-sbsa
- A Linux/Windows system with recent NVIDIA drivers.
- CMake version 3.18 minimum
- Minimum CUDA 10.1 toolkit is required.
$ mkdir build
$ cd build
$ cmake ..
$ make
Make sure that CMake finds expected CUDA Toolkit. If that is not the case you can add argument -DCMAKE_CUDA_COMPILER=/path/to/cuda/bin/nvcc
to cmake command.
$ mkdir build
$ cd build
$ cmake -DCMAKE_GENERATOR_PLATFORM=x64 ..
$ Open cusolver_examples.sln project in Visual Studio and build
$ ./cusolver_gesvd_example
Sample example output:
A = (matlab base-1)
1.00 2.00
4.00 5.00
2.00 1.00
=====
after gesvd: info_gpu = 0
gesvd converges
S = singular values (matlab base-1)
7.07
1.04
=====
U = left singular vectors (matlab base-1)
-0.31 0.49 0.82
-0.91 0.11 -0.41
-0.29 -0.87 0.41
=====
VT = right singular vectors (matlab base-1)
-0.64 -0.77
-0.77 0.64
=====
|S - S_exact| = 8.881784E-16
|A - U*S*VT| = 1.790181E-15