Reputation: 71
I wrote simple CUDA c++ program simulating diffusion on 2D matrix. I got in trouble when I tried to used some of the libraries which are provided in Toolkit. I would like to replace my extremely inefficient matrix transpose kernel with something from cuBlas and also implCU with cuSolvers implementation of solving linear systems. Trouble is that I dont know how to use the functions or compile them. Its working with Makefiles on sample codes provided by Nvidia. If someone would help me, ideally showing me how are these functions supposed to be used when writing .cu files, I would be grateful.
Here is the code: http://pastebin.com/UKhJZQBz
I am on Ubuntu 16.04 and I have exported the PATH variables (so they include /usr/local/cuda-8.0/bin) as is written in official guide.
Here is the output from nvcc -I /usr/local/cuda-8.0/samples/common/inc/ difusion2d.cu
/tmp/tmpxft_00001c09_00000000-16_difusion2d.o: In function `csr_mat_norminf(int, int, int, cusparseMatDescr*, double const*, int const*, int const*)':
undefined reference to `cusparseGetMatIndexBase'
/tmp/tmpxft_00001c09_00000000-16_difusion2d.o: In function `display_matrix(int, int, int, cusparseMatDescr*, double const*, int const*, int const*)':
undefined reference to `cusparseGetMatIndexBase'
/tmp/tmpxft_00001c09_00000000-16_difusion2d.o: In function `main':
undefined reference to `cusolverDnCreate'
undefined reference to `cublasCreate_v2'
undefined reference to `cusolverDnSetStream'
undefined reference to `cublasSetStream_v2'
collect2: error: ld returned 1 exit status
Upvotes: 0
Views: 1468
Reputation: 72348
You must explicitly link the cublas and cusolver libraries. Something like
nvcc -I /usr/local/cuda-8.0/samples/common/inc \
-L/path/to/CUDA/libraries difusion2d.cu -lcublas -lcusolver
should work. Depending on your installation, the -L
option to provide a search path to the libraries may or may not be necessary.
Upvotes: 1