‘/tmp/tmpxft_0000120b_0000000-10_my_program”中对‘cublasCreate_v2’的未定义引用

问题描述 投票:0回答:1

我尝试在 NVIDIA Tesla P100 显卡(Ubuntu 版本 16.04)上使用 CUDA 9.0 工具包编译代码,代码中使用了 CUBLAS 库。为了编译,我使用以下命令来编译“my_program.cu”

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

但是,我遇到了以下错误:

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

我已经在编译命令中链接了库路径,为什么还是报错。请帮我解决这个错误。

cuda cublas
1个回答
2
投票

很明显您正在尝试在设备代码中使用 CUBLAS 库。这与普通主机的使用不同,需要特殊的编译/链接步骤。你需要:

    针对正确的设备架构进行编译(必须是 cc3.5 或更高版本)
  1. 使用可重定位设备代码链接
  2. cublas
  3. device 库中的链接(除了 cublas 主机库)
  4. CUDA 设备运行时库中的链接
  5. 使用 CUDA 10.0 之前的 CUDA 工具包
在编译命令行中添加以下内容应该可以帮助您实现目标:

nvcc -std=c++11 my_program.cu -o my_program.o -lcublas -arch=sm_60 -rdc=true -lcublas_device -lcudadevrt
以上假设您实际上正在使用正确安装的 CUDA 9.0。 CUBLAS 设备库已弃用,现已从较新的 CUDA 工具包中删除(请参阅

此处)。

已弃用和删除意味着您无法再从设备代码中调用

cublas

 函数,即用 
__global__
__device__
 关键字修饰的任何函数。

© www.soinside.com 2019 - 2024. All rights reserved.