Error in simple cuda compilation

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 the function 'int main (int, char **): FSPB_main.cpp: 167: 45: error:' cudaMalloc was not declared in this Volume

What does this error mean? Is it just cudaMalloc, and suppose it is supported for the compiler?

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

+7
source share
1 answer

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

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

and then on the cmd line you also need to add PATH ( -I option) where these components 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 

Remember to add -I. to this command if your code depends on custom headers you wrote that are in the same source code directory.

+15
source

All Articles