2013-05-18 39 views
0

所以我有这个代码,它假设以不同的方式计算矩阵的点积(其中之一是在C++中使用bla),但是当我尝试使用nvcc编译代码,它不起作用,它说我有一个未定义的引用ddot。这很奇怪,因为我很确定我在这里引用了cublas的调用符号:http://www.sdsc.edu/us/training/assets/docs/NVIDIA-03-Toolkit.pdfC++和cublas代码的混合不编译

任何人都可以帮我吗?下面是我遇到的一段代码:

#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工具包,但我不知道该怎么比

#include <cublas.h>

新的更新

原来我得到相同的输出I是否包括参考图书馆等cublas.h页眉或不

我也得到了相同的输出是否我键入-lcublas与否

下面是输出的,这是所有编译垃圾(WIT H /无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 
+0

您是否必须将cublasDDOT作为“extern C”之外的“C”? –

+0

@huseyin tugrul buyukisik你是什么意思?我不明白。尽管我在c代码中使用cublasDDOT。 – Mechy

+0

也许将其中一个只读参数声明为const可能会有所帮助。也许不会。也许__restrict__有帮助。 –

回答

1

即使NVCC编译时,你还需要指定-lcublas链路切换。

看起来你没有正确地调用了函数名:

cublasDDOT_() 

应该是:

cublasDdot() 

和:

cublasDAXPY_() 

应该是:

cublasDaxpy() 

命名是区分大小写的。

如果你不知道正确的命名,指CUBLAS documentation,并采取在sample codes

看看使用是的,删除下划线。我不明白你为什么要这样调用函数名称。如果你打乱了一个名字,链接器就无法知道你打算把它链接到什么地方。

我也不确定任何“extern C”的东西是必要的。这取决于你的项目还在发生什么,但是如果你正在编译/链接nvcc,我认为你不应该使用包含函数的“extern C”来包装函数,如果你正在编译/链接到nvcc文件夹。

+0

由于它位于具有未知路径的奇怪服务器上,因此我无法执行链接。我认为它是正确的,因为-lcublas被接受了,对吗? – Mechy

+0

哦,这很有趣,我得到相同的输出,无论我是否使用-lcublas – Mechy

+0

是的,我也错过了你似乎使用不正确的函数名称,我编辑了我的答案上面。 –