Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error in a simple cuda compilation

Tags:

c++

c

cuda

gpu

FSPB_main.cpp

int main(int args, char* argv[]){    
    .......   

   float *d_a;   
   cudaMalloc( (void**)&d_a, 5*sizeof(float) );

}

$ nvcc -L/usr/local/cuda/lib -lcutil -lcudpp -lcuda -lcudart -c -o FSPB_main.o FSPB_main.cpp

FSPB_main.cpp: In function ‘int main(int, char**)’: FSPB_main.cpp:167:45: error: ‘cudaMalloc’ was not declared in this scope

What does this error mean? It's just a cudaMalloc and it suppose to be supported for the compiler right?

Can functions like cudaMalloc be used in a .cpp file? Do I need to create a .cu file just for anything what comes from CUDA?

like image 590
Manolete Avatar asked Jun 16 '11 15:06

Manolete


1 Answers

You need to include the header files where the CUDA functions are declared:

#include <cuda_runtime_api.h>
#include <cuda.h>

and then on the cmd line you also need to add the PATH (option -I) where those includes are located.

On my system, version 2.1 of CUDA installed the header files on /usr/local/cuda. To compile, I would do something like:

nvcc -I/usr/local/cuda/include -L/usr/local/cuda/lib -lcutil -lcudpp -lcuda -lcudart -c -o FSPB_main.o FSPB_main.cpp

Don't forget to add -I. to that command if your code depend on custom headers you wrote that are located in the same directory of the source code.

like image 81
karlphillip Avatar answered Nov 18 '22 16:11

karlphillip