所以我有这个代码,它假设以不同的方式计算矩阵的点积(其中之一是在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
您是否必须将cublasDDOT作为“extern C”之外的“C”? –
@huseyin tugrul buyukisik你是什么意思?我不明白。尽管我在c代码中使用cublasDDOT。 – Mechy
也许将其中一个只读参数声明为const可能会有所帮助。也许不会。也许__restrict__有帮助。 –