0

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
Max K
  • 71
  • 1
  • 11
  • The way it worked for me is nvcc -I /usr/local/cuda-8.0/samples/common/inc/ -lcusolver -lcublas -lcusparse difusion2d.cu – Max K Mar 19 '17 at 22:34

1 Answers1

1

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.

talonmies
  • 70,661
  • 34
  • 192
  • 269
  • TY. I am still a bit confused about how doeas -lcu* actually work could you please explain that to me? Also when I include path to library I get quite a lot of errors (the path is already in $LD_LIBRARY_PATH) how does this tie in to whole compilation process of cuda code? – Max K Mar 19 '17 at 22:39
  • there is documentation for all of this if you care to read it http://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/#file-and-path-specifications – talonmies Mar 20 '17 at 06:06