【问题标题】:Compiling my CUDA program with libraries provided in toolkit使用工具包中提供的库编译我的 CUDA 程序
【发布时间】:2017-08-10 15:26:51
【问题描述】:

我编写了简单的 CUDA c++ 程序来模拟二维矩阵上的扩散。当我尝试使用 Toolkit 中提供的一些库时遇到了麻烦。我想用 cuBlas 的东西替换我效率极低的矩阵转置内核,也想用求解线性系统的 cuSolvers 实现替换 implCU。麻烦的是我不知道如何使用这些函数或编译它们。它与 Nvidia 提供的示例代码上的 Makefiles 一起工作。如果有人能帮助我,最好向我展示在编写 .cu 文件时应该如何使用这些函数,我将不胜感激。

这里是代码:http://pastebin.com/UKhJZQBz

我在 Ubuntu 16.04 上,并且按照官方指南中的说明导出了 PATH 变量(因此它们包括 /usr/local/cuda-8.0/bin)。

这是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

【问题讨论】:

  • 它对我有用的方式是 nvcc -I /usr/local/cuda-8.0/samples/common/inc/ -lcusolver -lcublas -lcusparse difusion2d.cu

标签: cuda cublas cusolver


【解决方案1】:

您必须显式链接 cublas 和 cusolver 库。类似的东西

nvcc -I /usr/local/cuda-8.0/samples/common/inc \
     -L/path/to/CUDA/libraries  difusion2d.cu -lcublas -lcusolver

应该可以。根据您的安装,提供库搜索路径的 -L 选项可能不是必需的。

【讨论】:

  • TY。我仍然对 doeas -lcu* 的实际工作方式有些困惑,请您向我解释一下吗?此外,当我包含库的路径时,我会遇到很多错误(路径已经在 $LD_LIBRARY_PATH 中)这与 cuda 代码的整个编译过程有何关系?
  • 如果您愿意阅读,这里有所有这些的文档docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/…
猜你喜欢
  • 2018-04-23
  • 2010-12-03
  • 1970-01-01
  • 1970-01-01
  • 2011-09-18
  • 1970-01-01
  • 1970-01-01
  • 2012-09-29
  • 2014-03-16
相关资源
最近更新 更多