c - 应用程序未链接到 CUDA

标签 c linux cuda linker ld

我正在尝试编译和运行依赖于 CUDA SDK 的应用程序。 CUDA 共享对象安装在 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

应用程序在编译期间正确链接到 CUDA

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

make (gcc) 期间没有错误。当我运行二进制文件时,出现此错误

$ ./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 似乎也是正确的

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

源代码

错误实际上可以追溯到源代码Github ,调用函数 cudaDriverGetVersion。该函数存在于共享库中

$ 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

是什么导致了这里的错误?


更新1

nvidia-smi -a 的输出是

==============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

最佳答案

这不是链接问题。

当您检查自己时,链接到 libcudart.so 工作正常,应用程序甚至被加载,这意味着库在加载时找到。 ldd 也证实了这一点。否则,应用程序甚至无法启动,也无法产生任何输出。

这不是链接问题,只是调用 cudaDriverGetVersion() 返回错误。

您需要弄清楚为什么 cudaDriverGetVersion() 返回错误 - 检查源代码是否可用(我无法通过快速 Google 搜索找到它,也许 Cuda 库不可用开源)。如果您没有源代码,请尝试使用 strace 来弄清楚它在做什么。

我假设 cudaDriverGetVersion() 尝试使用 dlopen 动态打开共享库(驱动程序),但根本找不到该驱动程序。可能您只需要调整一些搜索路径。还要检查 Cuda 库的文档。

关于c - 应用程序未链接到 CUDA,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22822804/

相关文章:

cuda - 动态检测启用 CUDA 的 NVIDIA 卡,然后才初始化 CUDA 运行时 : How to do?

windows - SSL 内部的 SSH 隧道

c - 如何将套接字文件描述符放入缓冲区并继续接受传入连接?

c - 避免 CUDA 字符串搜索中的分支发散

c++ - 双递归如何在 C/C++ 中工作——例如二叉树的深度?

php - 如何从 PHP 执行 SSH?

cuda - 对 cuda 同步函数的调用会阻止 GPU 上的所有先前任务吗?

c - 当前时间

c - 是否可以在具有 32 位处理器的机器上运行 64 位代码?

c - 打开 MP 性能不佳/令人困惑