visual studio 2010 - How do I set up my code/VS10 to recognize CUDA function calls within .c files? -


basically, have compiler compiling .cu files , have (i think) full operation within .cu files, when try call them (kernel<<<1,1>>>(void)), compiler registers syntax errors due cuda syntax. also, calls cudamalloc fail within c files.

here 3 short files, can tell erroring.

//kernel.cu     #include "kernel.h" #include <cuda.h> #include <cuda_runtime_api.h>  __global__ int kernel(void){          return 5; } 

and

//kernel.h #ifndef _kernel_h_ #define _kernel_h_  extern "c" int kernel(void);  #endif 

and

//main.c #include "kernel.h" #include <cuda.h> #include <cuda_runtime_api.h>  int main() {    int* device_a;     cudamalloc( (void**)&device_a, sizeof(int) );     kernel<<<1,1>>>(); } 

i got header file of sdk examples. also, have build configuration set cuda 4.2, hence why .cu file compiles. if made incidental syntax errors, because simplified posting, not in source, although please mention in case.

kernel.cu compiles fine.

kernel.h has error: "error c2059: syntax error : 'string'" on "extern..." line. (could because took c++ example?)

main.c has error: "error c2065: 'kernel' : undeclared identifier"

and: "error c2059: syntax error : '<'"

but when comment out kernel call, cudamalloc, get: "error lnk2019: unresolved external symbol _cudamalloc@8 referenced in function _main"

and: "fatal error lnk1120: 1 unresolved externals"

is visual studio 2010, or not including? sdk examples, can't tell i'm doing wrong, other found way, think, not use triple bracket (ctrl+f doesn't find any). appreciated. thank in advance!

edit: after looking @ more examples, use triple bracket syntax fine.

edit: for using reference, __global__ functions can return void. if try return else, did, receive compiler errors.

  1. put functions invoke cuda kernel in .cu files.

  2. set vs2010 compile cu files cuda compiler, not built in 1 (use cuda rules files (cuda.props, cuda.xml, cuda.targets) located within cuda sdk).

  3. i recommend placing kernels in files different extension (e.g. .curnel files), not compiled directly (only if called).

  4. i recommend putting declaration of functions invoke cuda kernels in .cuh files.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -