0

我编写了简单的 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
4

1 回答 1

1

您必须显式链接 cublas 和 cusolver 库。就像是

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

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

于 2017-03-19T10:27:27.420 回答