【发布时间】:2013-05-13 16:47:38
【问题描述】:
所以我有这段代码假设以不同的方式计算矩阵的点积(其中一种是在 c++ 中使用 blas),但是当我尝试使用 nvcc 编译代码时,它不会工作,它说我对 ddot 有一个未定义的引用。这很奇怪,因为我很确定我正在使用此处为 cublas 引用的调用符号:http://www.sdsc.edu/us/training/assets/docs/NVIDIA-03-Toolkit.pdf
谁能帮助我?这是我遇到问题的代码片段:
#include <cublas.h> //just some included files here. No problems with these
#include <fstream>
#include <string>
#include <sstream>
using namespace std;
extern "C" //This is where I mention the cublas functions are external.
//I think this is necessary since I also have cuda pieces of code
{
double cublasDDOT_(int *n, double *A, int *incA, double *B, int *incB);
void cublasDAXPY_(int *n, double *a, double *A, int *incA, double *B, int *incB);
}
//Stuff happens here
C[i][t]=cublasDDOT_(&n, partA, &incA, partB, &incB); //This is a piece of my function and where the compiler chokes up
这对我来说很奇怪。我也尝试过删除“_”,但没有成功。
这是我使用的编译命令:nvcc program
我是否需要在编译过程中以某种方式提及 cublas 库?我已经安装了 cuda 工具包,但除了 with 之外我不知道如何引用该库
#include <cublas.h>
新更新
事实证明,无论我是否包含 cublas.h 标头,我都会得到相同的输出
无论我是否输入 -lcublas,我都会得到相同的输出
这是所有编译的垃圾输出(带/不带 cublas.h 和带/不带 -lcublas)
nvcc project4.cu -lcublas
/tmp/tmpxft_000051cb_00000000-14_project4.o: In function `ddot(int&, int&, int&, double**&, double**&, double**&, double*&, double*&, int&, int&, double&, double&, double*)':
tmpxft_000051cb_00000000-3_project4.cudafe1.cpp:(.text+0xda1): undefined reference to `cublasDDOT'
/tmp/tmpxft_000051cb_00000000-14_project4.o: In function `daxpy(int&, int&, int&, double**&, double**&, double**&, double**&, double*&, double*&, int&, int&, double&, double&, double*)':
tmpxft_000051cb_00000000-3_project4.cudafe1.cpp:(.text+0xff3): undefined reference to `cublasDAXPY'
collect2: ld returned 1 exit status
【问题讨论】:
-
你必须在“extern C”之外将cublasDDOT作为“C”吗?
-
@huseyin tugrul buyukisik 你是什么意思?我不明白。不过,我确实在我的 c 代码中使用了 cublasDDOT。
-
也许将只读参数之一声明为 const 可能会有所帮助。也许不吧。也许 restrict 有帮助。
-
什么是限制?
-
关于内存空间中参数不重叠的问题。顺便问一下,你的 CUDA 设备是什么?