Hanxue
Hanxue

Reputation: 12766

Application not linking to CUDA

I am trying to compile and run an application that depends on CUDA SDK. The CUDA shared objects are installed in the standard location on Ubuntu:

$ ls -l /usr/lib/x86_64-linux-gnu/libcuda*
lrwxrwxrwx 1 root root       12 Feb 26 18:26 /usr/lib/x86_64-linux-gnu/libcuda.so -> libcuda.so.1
lrwxrwxrwx 1 root root       17 Feb 26 18:26 /usr/lib/x86_64-linux-gnu/libcuda.so.1 -> libcuda.so.331.49
-rw-r--r-- 1 root root 13871048 Feb 13 04:29 /usr/lib/x86_64-linux-gnu/libcuda.so.331.49
-rw-r--r-- 1 root root   307722 Jul 19  2013 /usr/lib/x86_64-linux-gnu/libcudadevrt.a
lrwxrwxrwx 1 root root       16 Jan 23 01:36 /usr/lib/x86_64-linux-gnu/libcudart.so -> libcudart.so.5.5
lrwxrwxrwx 1 root root       19 Jan 23 01:36 /usr/lib/x86_64-linux-gnu/libcudart.so.5.5 -> libcudart.so.5.5.22
-rw-r--r-- 1 root root   313400 Jul 19  2013 /usr/lib/x86_64-linux-gnu/libcudart.so.5.5.22
-rw-r--r-- 1 root root   642322 Jul 19  2013 /usr/lib/x86_64-linux-gnu/libcudart_static.a

The application is properly linked to CUDA during compilation

LDFLAGS="-lcuda" CFLAGS="-O2 -march=native" ./configure --with-cuda=/usr/lib/x86_64-linux-gnu

No errors during make (gcc). When I run the binary, I get this error

$ ./cudaminer 
           *** CudaMiner for nVidia GPUs by Christian Buchner ***
                     This is version 2014-02-28 (beta)
        based on pooler-cpuminer 2.3.2 (c) 2010 Jeff Garzik, 2012 pooler
            Cuda additions Copyright 2013,2014 Christian Buchner
          LTC donation address: LKS1WDKGED647msBQfLBHV3Ls8sveGncnm
          BTC donation address: 16hJF5mceSojnTD3ZTUDqdRhDyPJzoRakM
          YAC donation address: Y87sptDEcpLkLeAuex6qZioDbvy1qXZEj4
[2014-04-02 20:48:56] Unable to query CUDA driver version! Is an nVidia driver installed?

ldd on the binary seems to be correct as well

$ ldd cudaminer|grep cuda
        libcudart.so.5.5 => /usr/lib/x86_64-linux-gnu/libcudart.so.5.5 (0x00007fe268048000)

Source Code

The error can actually be traced back to the source code at Github, calling the function cudaDriverGetVersion. This function exist in the shared library

$ nm -D /usr/lib/x86_64-linux-gnu/libcuda.so|grep Version
0000000000144fc0 T cuCtxGetApiVersion
00000000002d2980 T cudbgGetAPIVersion
00000000001476f0 T cuDriverGetVersion

$ nm -D /usr/lib/x86_64-linux-gnu/libcudart.so|grep Version
0000000000027810 T cudaDriverGetVersion
0000000000027670 T cudaRuntimeGetVersion

What is causing the error here?


Update 1

Output of nvidia-smi -a is

==============NVSMI LOG==============

Timestamp                       : Thu Apr  3 06:26:36 2014
Driver Version                  : 304.121

Attached GPUs                   : 1
GPU 0000:00:03.0
    Product Name                : GRID K520
    Display Mode                : N/A
    Persistence Mode            : Disabled
    Driver Model
        Current                 : N/A
        Pending                 : N/A
    Serial Number               : N/A
    GPU UUID                    : GPU-1e3aafd5-e821-41a0-62de-3b8fe1b74dd2
    VBIOS Version               : 80.04.D4.00.03
    Inforom Version
        Image Version           : N/A
        OEM Object              : N/A
        ECC Object              : N/A
        Power Management Object : N/A
    GPU Operation Mode
        Current                 : N/A
        Pending                 : N/A
    PCI
        Bus                     : 0x00
        Device                  : 0x03
        Domain                  : 0x0000
        Device Id               : 0x118A10DE
        Bus Id                  : 0000:00:03.0
        Sub System Id           : 0x101410DE
        GPU Link Info
            PCIe Generation
                Max             : N/A
                Current         : N/A
            Link Width
                Max             : N/A
                Current         : N/A
    Fan Speed                   : N/A
    Performance State           : N/A
    Clocks Throttle Reasons     : N/A
    Memory Usage
        Total                   : 4095 MB
       Used                    : 10 MB
        Free                    : 4085 MB
    Compute Mode                : Default
    Utilization
        Gpu                     : N/A
        Memory                  : N/A
    Ecc Mode
        Current                 : N/A
        Pending                 : N/A
    ECC Errors
        Volatile
            Single Bit            
                Device Memory   : N/A
                Register File   : N/A
                L1 Cache        : N/A
                L2 Cache        : N/A
                Texture Memory  : N/A
                Total           : N/A
            Double Bit            
                Device Memory   : N/A
                Register File   : N/A
                L1 Cache        : N/A
                L2 Cache        : N/A
                Texture Memory  : N/A
                Total           : N/A
        Aggregate
            Single Bit            
                Device Memory   : N/A
                Register File   : N/A
                L1 Cache        : N/A
                L2 Cache        : N/A
                Texture Memory  : N/A
                Total           : N/A
            Double Bit            
                Device Memory   : N/A
                Register File   : N/A
                L1 Cache        : N/A
                L2 Cache        : N/A
                Texture Memory  : N/A
                Total           : N/A
    Temperature
        Gpu                     : 48 C
    Power Readings
        Power Management        : N/A
        Power Draw              : N/A
        Power Limit             : N/A
        Default Power Limit     : N/A
        Min Power Limit         : N/A
        Max Power Limit         : N/A
    Clocks
        Graphics                : N/A
        SM                      : N/A
        Memory                  : N/A
    Applications Clocks
        Graphics                : N/A
        Memory                  : N/A
    Max Clocks
        Graphics                : N/A
        SM                      : N/A
        Memory                  : N/A
    Compute Processes           : N/A

Upvotes: 0

Views: 1354

Answers (1)

Thomas McGuire
Thomas McGuire

Reputation: 5466

This is not a linking problem.

As you checked yourself, linking to libcudart.so works correctly, and the application even gets loaded, which means the library is found at load time. ldd confirms that as well. Otherwise the application wouldn't even start up and wouldn't be able to produce any output.

Instead of a linking problem, this is simply the call to cudaDriverGetVersion() returning an error.

You need to figure out why cudaDriverGetVersion() returns an error - check the source code if it is available (I couldn't find it with a quick Google search, maybe the Cuda library is not open source). If you have no source, try using strace to figure out what it is doing.

I asssume cudaDriverGetVersion() tries to dynamically open a shared library (the driver) with dlopen and simply can't find that driver. Probably you just need to adjust some search paths. Check the documentation of the Cuda library as well.

Upvotes: 1

Related Questions