cuda - A mix of c++ and cublas code isn't compiling -
so have code that's suppose compute dot product of matrix in different ways (one of use blas in c++), when try use nvcc compile code, doesn't work , says have undefined reference ddot. weird because i'm pretty sure i'm using calling notation referenced here cublas: http://www.sdsc.edu/us/training/assets/docs/nvidia-03-toolkit.pdf
can me? here's snip of code i'm having trouble with:
#include <cublas.h> //just included files here. no problems these #include <fstream> #include <string> #include <sstream> using namespace std; extern "c" //this mention cublas functions external. //i think necessary since 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 piece of function , compiler chokes
this weird me. i've tried removing "_"'s no luck.
here's compile command use: nvcc program
do need mention cublas library during compile somehow? have cuda toolkit installed, don't know how reference library other with
#include <cublas.h>
new update
it turns out same output whether include cublas.h header or not
i same output whether type -lcublas or not
here's output, garbage 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 `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 `cublasdaxpy' collect2: ld returned 1 exit status
even when compiling nvcc, still need specify -lcublas
link switch.
it looks you're calling out function names incorrectly:
cublasddot_()
should be:
cublasddot()
and:
cublasdaxpy_()
should be:
cublasdaxpy()
the naming case-sensitive.
if you're not sure correct naming, refer cublas documentation , take @ usage in sample codes
and yes, remove underscores. don't understand why you're calling function names way. if mangle name, there's no way linker knows intend link to.
i'm not sure of "extern c" stuff necessary. depends on else going on in project, don't think should use "extern c" wrapped around functions intend linked cublas library, if compiling/linking nvcc
Comments
Post a Comment