Having a problem compiling, when I put my kernel and launch function into .cuh and .cu files.
void kernel(int* dev_out, kernelProp kProp);
int launchKernel(int dim);
void kernel(int* dev_out, kernelProp kProp)
if (kProp == _gridDim)
dev_out = gridDim.x;
if (kProp == _blockDim)
dev_out = blockDim.x;
if (kProp == _threadID)
dev_out = threadIdx.x;
if (kProp == _blockID)
dev_out = blockIdx.x;
int launchKernel(int dim)
HANDLE_ERROR( cudaMalloc(&dev_out,sizeof(int)) );
kernel<<<grid,3>>>( dev_out, _blockID );
HANDLE_ERROR( cudaMemcpy(&out,dev_out,sizeof(int),cudaMemcpyDeviceToHost) );
#define DIM 1000
var = launchKernel(DIM);
cout << var;
Don’t know what to do with ‘…/Documents/Visual Studio 2010/OpenGLStuff/Particles GPU/kernel.cuh’
Well is it kernels.cuh or kernel.cuh ? Perhaps you should post the complete compile error output from VS.
its kernels.cuh and kernels.cu.
I changed some stuff in my build. In the SDK examples I noticed, that all the .cuh and .cu are excluded from the build. So I did that as well. Now I’m getting linker errors:
main.obj : error LNK2001: unresolved external symbol _gridDim
1>main.obj : error LNK2001: unresolved external symbol _threadIdx
1>main.obj : error LNK2001: unresolved external symbol _blockDim
1>main.obj : error LNK2001: unresolved external symbol _blockIdx
1>main.obj : error LNK2019: unresolved external symbol "int __cdecl launchKernel(int)" (?launchKernel@@YAHH@Z) referenced in function _main
1>\Documents\Visual Studio 2010\CUDAStuff\Debug\CUDATestExternCuh.exe : fatal error LNK1120: 5 unresolved externals
the unresolved external symbol is referring to my enum kernelProp. What am I doing wrong?
You don’t exclude .cu files from the build, normally. Those are considered to be compilable modules, ordinarily. A .cuh is a header file, it should be excluded from the build, it only gets compiled when it is included in a compilable module somewhere.
I finally got it. Thanks x100 for the help!
The linker errors were a result of including headers from the “Cuda by Example” headers.
Just as txbob said, you have to exclude the .cuh files from the build.