how to call kernal in .cpp file

Hi guys,

I want to utilize cuda to speed up the current project.

I have written the kernal thread. And I want to call the kernal thread in a .cpp file. But when compiling the project, there are some errors:

[yongzhao@205 threads]$ make error: âblockDimâ was not declared in this scope error: âblockIdxâ was not declared in this scope error: âthreadIdxâ was not declared in this scope

main.cpp:36: error: expected primary-expression before â<â token
main.cpp:36: error: expected primary-expression before â>â token

make: *** [obj/release/main.cpp.o] Error 1

How to solve it?

how are you linking this cpp file to the nvcc compiler? Are you using the template w/ make files provided in the SDK?

yes, I copy the make file from the /NVIDIA_CUDA_SDK/projects/asyncAPI and then write all of files of my project and include the

Well, it would be helpful if you would post your code… it’s not clear just from the error message what is going wrong.

If I’m reading this correctly

  1. you are trying to compile the .cu with a standard c++ compiler (g++ ?) which doesn’t recognize cuda stuff (and specifically the blockDim etc. code), or you didn’t declare your kernel as a kernel (you need to give it the global attribute) which seems more plausible as you didn’t get an error (or at least didn’t mention it) about not recognizing it (which g++ should complain about)

  2. You are trying to make a kernel call from the cpp file which is definitely not compiled with nvcc (never tested whether nvcc would even agree to compile it as cuda code) and thus the kernel paradigm <<< dimGrid, dimBlock >>> is not recognized.

You should:

a. make sure the cu file is compiled with nvcc (remove the @ from the compilation rules in the make file if they are there to print the actual compilation command and submit that)

b. make sure the kernels are marked as such (global)

c. make the kernel call from the .cu file and make a wrapper function to be called from the .cpp file to make that happen