Question

So I have this code that's suppose to compute the dot product of a matrix in different ways (one of which is to use blas in a c++), but when I try to use nvcc to compile the code, it doesn't work and it says that I have an undefined reference to ddot. This is weird because I'm pretty sure I'm using the calling notation referenced here for cublas: http://www.sdsc.edu/us/training/assets/docs/NVIDIA-03-Toolkit.pdf

Can anyone help me? Here's a snip of code I'm having trouble with:

#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

This is weird to me. I've also tried removing the "_"'s with no luck.

Here's the compile command I use: nvcc program

Do I need to mention the cublas library during the compile somehow? I have the cuda toolkit installed, but I don't know how to reference the library other than with

#include <cublas.h>

New update

It turns out I get the same output whether I include the cublas.h header or not

I also get the same output whether I type -lcublas or not

Here's the output, which is garbage for all compiles (with/without cublas.h & with/without -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
Was it helpful?

Solution

Even when compiling with nvcc, you still need to specify the -lcublas link switch.

It looks like you're calling out the function names incorrectly:

cublasDDOT_()

should be:

cublasDdot()

and:

cublasDAXPY_()

should be:

cublasDaxpy()

The naming is case-sensitive.

If you're not sure about the correct naming, refer to the cublas documentation and take a look at the usage in the sample codes

And yes, remove the underscores. I don't understand why you're calling the function names that way. If you mangle a name, there's no way the linker knows what you intend to link it to.

I'm also not sure any of the "extern C" stuff is necessary. That depends on what else is going on in your project, but I don't think you should use "extern C" wrapped around functions that you intend to be linked with the cublas library, if you are compiling/linking with nvcc

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top