undefined reference to `cublasCreate_v2'

Hi - I’m new to CUDA and just trying to learn the basics
I’m following the example in the CUBLAS Library but when making the call cublasCreate(&handle) I get this error

undefined reference to `cublasCreate_v2’

I have included cublas_v2.h exactly the same way as the example. Aimilar errors come up when trying to use other cublas functions - can anyone tell me why I’m getting this error? Thanks.

Are you linking the cublas library?

nvcc file.cu -lcublas

1 Like

I guess that was it - thanks, and sorry for asking such a simple question :)

@ikzo don’t apologise… your question helped me!

In Nsight, how to incorporate nvcc file.cu -lcublas -lcusparse. I am a beginner. I have included cublas_v2.h and cusparse_v2.h. I am running through my local machine which is connected by ssh to the remote server and open Nsight by typing in the terminal.

Take a look here:

http://stackoverflow.com/questions/16148814/how-to-link-to-cublas-library-in-eclipse-nsight/16149904#16149904

Thank you very much for your reply. I have already found this link during searching in between. But, really I appreciate your help

I have a similar problem with nvlink during a compilation of a code:

nvcc -arch=sm_61 -shared -Xcompiler -fPIC -O3 -dc -m64 -o /home/mgovorcin/Installation_dir/isce/isce-2.2.0/build/components/zerodop/GPUampcor/src/gpu-ampcor.o -c components/zerodop/GPUampcor/cuda/GPUamp.cu
nvcc -arch=sm_61 -shared -Xcompiler -fPIC -O3 -dlink /home/mgovorcin/Installation_dir/isce/isce-2.2.0/build/components/zerodop/GPUampcor/src/gpu-ampcor.o -o /home/mgovorcin/Installation_dir/isce/isce-2.2.0/build/components/zerodop/GPUampcor/src/gpu-ampcor-linked.o -L/usr/local/cuda/lib64 -lcuda -lcublas_static -lcufft_static -lculibos -lcublas_device -lcudart -lcudadevrt
nvlink error : Undefined reference to ‘cublasCreate_v2’ in ‘/home/mgovorcin/Installation_dir/isce/isce-2.2.0/build/components/zerodop/GPUampcor/src/gpu-ampcor.o’
nvlink error : Undefined reference to ‘cublasScasum_v2’ in ‘/home/mgovorcin/Installation_dir/isce/isce-2.2.0/build/components/zerodop/GPUampcor/src/gpu-ampcor.o’
nvlink error : Undefined reference to 'cublasDestroy_v2’ in ‘/home/mgovorcin/Installation_dir/isce/isce-2.2.0/build/components/zerodop/GPUampcor/src/gpu-ampcor.o’
nvlink error : Undefined reference to ‘cublasIcamax_v2’ in ‘/home/mgovorcin/Installation_dir/isce/isce-2.2.0/build/components/zerodop/GPUampcor/src/gpu-ampcor.o’

Based on everything that I read, can see that the problem is in linking the object with CUDA libraries. I already have all environmental variables (PATH, LD_LIBRARY_PATH, LIBRARY_PATH and CPATH) set and it is not working. I you can see the error above, I also try direct linking with -L option and received the same error. Moreover, I played with the compile flags and didnt get anywhere. Also, important is to mention that samples in /usr/local/cuda/sample all work find and I managed to install tensorflow with this cuda-10 installation.
I saw that undefined reference is also sometime resolved by putting extern C in the code, as it is not my code don’t know exactly where to put it and when I tried, I got the same error again.

I dont know what else to do, everything looks to be installed correctly but compilation of this code doesn’t want to go through. Can somebody please help me with this matter?

Other information:
lspci | grep -i nvidia
3b:00.0 VGA compatible controller: NVIDIA Corporation GP104GL (rev a1)
3b:00.1 Audio device: NVIDIA Corporation GP104 High Definition Audio Controller (rev a1)
af:00.0 VGA compatible controller: NVIDIA Corporation GP104GL (rev a1)
af:00.1 Audio device: NVIDIA Corporation GP104 High Definition Audio Controller (rev a1)

gcc (Ubuntu 7.3.0-27ubuntu1~18.04) 7.3.0

x86_64
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=18.04

4.15.0-39-generic

Thanks

If you are calling CUBLAS routines from device code, note that device CUBLAS support has been dropped from CUDA 10:

https://docs.nvidia.com/cuda/cuda-toolkit-release-notes/index.html

(it was deprecated in CUDA 9).

based on my testing, that appears to be the reason you are getting these messages

Thank you Robert for your reply. I installed cuda-9.2 aside the cuda-10.0, and compilation worked just fine with a link to cuda-9.2 version directory.

It looks like the problem is an incompatibility between the code and cuda version.

Thanks again

Hello,

I believe I have a similar problem, as you @mgovorcinzd describe above. I am trying to compile GRASShopPER (a GPU based genome assembler) that was written for CUDA 8.2. I am using Ubuntu 18.02 LTS and CUDA 10.2.

If I am to install CUDA 9.2 alongside the CUDA 10.2 installation, would I simply change the $PATH and $LD_LIBRARY_PATH variables to point to CUDA 9.2 for the compiling of the code and then switch it back?

Is/are compiled CUDA files forwards compatible?

If I am to install CUDA 9.2 alongside the CUDA 10.2 installation, would I simply change the $PATH and $LD_LIBRARY_PATH variables to point to CUDA 9.2 for the compiling of the code and then switch it back?

Yes. It’s not uncommon to have a few versions on your computer. Confirm you’re using the correct version with

nvcc --version

Is/are compiled CUDA files forwards compatible?

Yes. As long as you’re not using any deprecated functions, you should be able to compile with a newer version of CUDA. When you compile with a newer version of CUDA, make sure your driver is compatible. This can be achieved with nvidia-smi.

nvidia-smi
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 440.33.01    Driver Version: 440.33.01    CUDA Version: 10.2     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  TITAN V             Off  | 00000000:01:00.0  On |                  N/A |
| 41%   58C    P0    42W / 250W |   3121MiB / 12063MiB |      0%      Default |
+-------------------------------+----------------------+----------------------+
|   1  GeForce GTX 1080    Off  | 00000000:02:00.0 Off |                  N/A |
|  0%   48C    P8     9W / 215W |     12MiB /  8119MiB |      0%      Default |
+-------------------------------+----------------------+----------------------+

Thanks!

@Robert_Crovella, I also met the same situation “Undefined reference to ‘cublasCreate_v2’” when I called CUBLAS API from device code using CUDA 10.


If you are calling CUBLAS routines from device code, note that device CUBLAS support has been dropped from CUDA 10:
https://docs.nvidia.com/cuda/cuda-toolkit-release-notes/index.html

(it was deprecated in CUDA 9).

based on my testing, that appears to be the reason you are getting these messages


From your words, Is that mean CUBLAS API called on device code will not be supported any more on CUDA 10.0 and higher CUDA Version?