cudacublas

Undefined reference to `cublasCreate_v2’ in ‘/tmp/tmpxft_0000120b_0000000-10_my_program”


I have tried to compile a code using CUDA 9.0 toolkit on NVIDIA Tesla P100 graphic card (Ubuntu version 16.04) and CUBLAS library is used in the code. For compilation, I have used the following command to compile “my_program.cu”

nvcc -std=c++11 -L/usr/local/cuda-9.0/lib64 my_program.cu -o mu_program.o -lcublas

But, I have got the following error:

nvlink error: Undefined reference to 'cublasCreate_v2’in '/tmp/tmpxft_0000120b_0000000-10_my_program’

As I have already linked the library path in the compilation command, why do I still get the error. Please help me to solve this error.


Solution

  • It seems fairly evident that you are trying to use the CUBLAS library in device code. This is different than ordinary host usage and requires special compilation/linking steps. You need to:

    1. compile for the correct device architecture (must be cc3.5 or higher)
    2. use relocatable device code linking
    3. link in the cublas device library (in addition to the cublas host library)
    4. link in the CUDA device runtime library
    5. Use a CUDA toolkit prior to CUDA 10.0

    The following additions to your compile command line should get you there:

    nvcc -std=c++11 my_program.cu -o my_program.o -lcublas -arch=sm_60 -rdc=true -lcublas_device -lcudadevrt
    

    The above assumes you are actually using a proper install of CUDA 9.0. The CUBLAS device library was deprecated and is now removed from newer CUDA toolkits (see here).

    Deprecated and removed means that you can no longer call cublas functions from device code, that is any function decorated with either the __global__ or __device__ keyword.