Good morning, I’m trying to solve a least square problem on GPU but I’m fighting against some problem with external libraries.
I’m using CUDA 12 on a NVIDIA GeForce RTX 3060 Laptop GPU.
#include <cuda.h>
#include <cuda_runtime.h>
#include <cusolverSp.h>
int main(int argc, char** argv) {
// Set up the input data
int m = 1000;
int n = 100;
float* A = new float[m * n];
float* b = new float[m];
// Initialize A and b with some values
// Allocate device memory for the input data
float* d_A;
cudaMalloc((void**)&d_A, m * n * sizeof(float));
float* d_b;
cudaMalloc((void**)&d_b, m * sizeof(float));
// Copy the input data to the device
cudaMemcpy(d_A, A, m * n * sizeof(float), cudaMemcpyHostToDevice);
cudaMemcpy(d_b, b, m * sizeof(float), cudaMemcpyHostToDevice);
// Create the CUSOLVER context
cusolverSpHandle_t solver;
cusolverSpCreate(&solver);
// Allocate device memory for the solution
float* d_x;
cudaMalloc((void**)&d_x, n * sizeof(float));
// Set up the CUSOLVER LSQR parameters
cusolverSpLsqrParams params;
params.tol = 1e-6;
params.max_iter = 1000;
params.normA = 0; // Automatically compute the norm of A
params.normB = 0; // Automatically compute the norm of b
// Solve the least squares problem
int status = cusolverSpLsqr(solver, m, n, ¶ms, d_A, d_b, d_x);
if (status != CUSOLVER_STATUS_SUCCESS) {
// Handle error
}
// Copy the solution from the device to the host
float* x = new float[n];
cudaMemcpy(x, d_x, n * sizeof(float), cudaMemcpyDeviceToHost);
// Clean up
delete[] A;
delete[] b;
delete[] x;
cudaFree(d_A);
cudaFree(d_b);
cudaFree(d_x);
cusolverSpDestroy(solver);
}
During the compilation I get these errors:
../src/QR.cu(32): error: identifier "cusolverSpLsqrParams" is undefined
../src/QR.cu(39): error: identifier "cusolverSpLsqr" is undefined
The compile command generated by ECLIPSE is the following:
Invoking: NVCC Compiler
/usr/local/cuda/bin/nvcc -I../cublas --device-debug --debug -gencode arch=compute_52,code=sm_52 -gencode arch=compute_52,code=compute_52 -ccbin g++ -c -o "src/QR.o" "../src/QR.cu"
I’m pretty sure that there is some error in the libraries linking, but I have found no solution on the web.
Can someone indicate my how to fix this problem?
EDIT:
I understood that the support for cublas has been removed after cuda 10.
But this version with cusolver should work aslo for cuda 12.
Any Hint?
Thank you very much.