main .cu function question

Hi

Is it possible to run a main function on a .c file and from there, use functions located on a .cu file.

I noticed that all the examples have the main function on the .cu file.

If possible, how do u set up visual 2005 to accomplish this?

thanks…

Sure can, refer to the SDK sample “cppIntegration”.

BTW, I think there is no need to add a prefix "extern “C” "to the function(in *.cu) which will be called in *.c, as distinguished from *.cpp.

I was wondering how you people invoke their kernel from outside the .cu file. I think you just make an method inside the .cu file that acts like a wrapper like this:

.c

...

doSomething(a,b);

...

.cu

...

doSomething(int a, int b) {

   kernel<<<,>>>(a,b);

}

__global__ void kernel(int a, int b) {

   ...

}

...

That is exactly how I do it. Kernel calls, texture binding and constant memory copies are the only things in my code that are in .cu files. Everything else is in C++ files, including cudaMalloc and the such.

For error checking, I have my kernel wrappers perform a threadSynchronize, then check for errors and return the cudaError_t from cudaGetLastError (only in debug mode).

So if i get it right you call cudaMalloc() from the .c file? I also use a wrapper method to allocate my memory for my kernel invocation and to write the data back i use a get method like

void getParameter(int *param){

memcpydev2host();

}

Right, I don’t use wrappers for memory allocations and copies. These are just plain jane C functions that can be called by any object file linked into the executable. Just include “cuda_runtime_api.h” (I think I got the file name correctly).

It’s only those calls that need nvcc special processing, like binding textures, copying to constant memory, and calling kernels that I use wrappers for.

Thanks all for your help.

I have a second problem.

Every time I add #include <cutil.h> to .c file I get a bunch of compiling errors (many) in the cutil.h file.

I saw they safely do this in the examples.

I am guessing it is because I am adding it to .c file instead of a .cpp file.

Any way to fix this??

What kind of errors do you get? Can you post them.

these errors

2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(122) : error C2143: syntax error : missing ‘{’ before ‘__stdcall’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(124) : error C2146: syntax error : missing ‘)’ before identifier ‘verbose’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(124) : error C2081: ‘bool’ : name in formal parameter list illegal
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(124) : error C2061: syntax error : identifier ‘verbose’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(124) : error C2059: syntax error : ‘;’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(124) : error C2513: '/global/ ’ : no variable declared before ‘=’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(124) : error C2059: syntax error : ‘)’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(124) : error C2065: ‘false’ : undeclared identifier
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(138) : error C2143: syntax error : missing ‘{’ before ‘__stdcall’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(140) : error C2146: syntax error : missing ‘)’ before identifier ‘verbose’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(140) : error C2081: ‘bool’ : name in formal parameter list illegal
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(140) : error C2061: syntax error : identifier ‘verbose’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(140) : error C2059: syntax error : ‘;’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(140) : error C2513: '/global/ ’ : no variable declared before ‘=’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(140) : error C2059: syntax error : ‘)’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(154) : error C2143: syntax error : missing ‘{’ before ‘__stdcall’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(155) : error C2146: syntax error : missing ‘)’ before identifier ‘verbose’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(155) : error C2081: ‘bool’ : name in formal parameter list illegal
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(155) : error C2061: syntax error : identifier ‘verbose’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(155) : error C2059: syntax error : ‘;’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(155) : error C2513: '/global/ ’ : no variable declared before ‘=’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(155) : error C2059: syntax error : ‘)’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(169) : error C2143: syntax error : missing ‘{’ before ‘__stdcall’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(171) : error C2146: syntax error : missing ‘)’ before identifier ‘verbose’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(171) : error C2081: ‘bool’ : name in formal parameter list illegal
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(171) : error C2061: syntax error : identifier ‘verbose’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(171) : error C2059: syntax error : ‘;’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(171) : error C2513: '/global/ ’ : no variable declared before ‘=’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(171) : error C2059: syntax error : ‘)’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(185) : error C2143: syntax error : missing ‘{’ before ‘__stdcall’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(187) : error C2146: syntax error : missing ‘)’ before identifier ‘verbose’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(187) : error C2081: ‘bool’ : name in formal parameter list illegal
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(187) : error C2061: syntax error : identifier ‘verbose’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(187) : error C2059: syntax error : ‘;’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(187) : error C2513: '/global/ ’ : no variable declared before ‘=’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(187) : error C2059: syntax error : ‘)’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(201) : error C2143: syntax error : missing ‘{’ before ‘__stdcall’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(203) : error C2146: syntax error : missing ‘)’ before identifier ‘verbose’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(203) : error C2081: ‘bool’ : name in formal parameter list illegal
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(203) : error C2061: syntax error : identifier ‘verbose’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(203) : error C2059: syntax error : ‘;’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(203) : error C2513: '/global/ ’ : no variable declared before ‘=’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(203) : error C2059: syntax error : ‘)’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(215) : error C2143: syntax error : missing ‘{’ before ‘__stdcall’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(217) : error C2146: syntax error : missing ‘)’ before identifier ‘verbose’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(217) : error C2081: ‘bool’ : name in formal parameter list illegal
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(217) : error C2061: syntax error : identifier ‘verbose’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(217) : error C2059: syntax error : ‘;’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(217) : error C2513: '/global/ ’ : no variable declared before ‘=’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(217) : error C2059: syntax error : ‘)’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(229) : error C2143: syntax error : missing ‘{’ before ‘__stdcall’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(231) : error C2146: syntax error : missing ‘)’ before identifier ‘verbose’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(231) : error C2081: ‘bool’ : name in formal parameter list illegal
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(231) : error C2061: syntax error : identifier ‘verbose’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(231) : error C2059: syntax error : ‘;’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(231) : error C2513: '/global/ ’ : no variable declared before ‘=’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(231) : error C2059: syntax error : ‘)’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(241) : error C2143: syntax error : missing ‘{’ before ‘__stdcall’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(243) : error C2146: syntax error : missing ‘)’ before identifier ‘verbose’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(243) : error C2081: ‘bool’ : name in formal parameter list illegal
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(243) : error C2061: syntax error : identifier ‘verbose’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(243) : error C2059: syntax error : ‘;’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(243) : error C2513: '/global/ ’ : no variable declared before ‘=’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(243) : error C2059: syntax error : ‘)’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(253) : error C2143: syntax error : missing ‘{’ before ‘__stdcall’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(255) : error C2146: syntax error : missing ‘)’ before identifier ‘verbose’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(255) : error C2081: ‘bool’ : name in formal parameter list illegal
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(255) : error C2061: syntax error : identifier ‘verbose’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(255) : error C2059: syntax error : ‘;’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(255) : error C2513: '/global/ ’ : no variable declared before ‘=’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(255) : error C2059: syntax error : ‘)’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(265) : error C2143: syntax error : missing ‘{’ before ‘__stdcall’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(267) : error C2146: syntax error : missing ‘)’ before identifier ‘verbose’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(267) : error C2081: ‘bool’ : name in formal parameter list illegal
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(267) : error C2061: syntax error : identifier ‘verbose’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(267) : error C2059: syntax error : ‘;’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(267) : error C2513: '/global/ ’ : no variable declared before ‘=’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(267) : error C2059: syntax error : ‘)’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(277) : error C2143: syntax error : missing ‘{’ before ‘__stdcall’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(279) : error C2146: syntax error : missing ‘)’ before identifier ‘verbose’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(279) : error C2081: ‘bool’ : name in formal parameter list illegal
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(279) : error C2061: syntax error : identifier ‘verbose’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(279) : error C2059: syntax error : ‘;’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(279) : error C2513: '/global/ ’ : no variable declared before ‘=’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(279) : error C2059: syntax error : ‘)’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(293) : error C2143: syntax error : missing ‘{’ before ‘__stdcall’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(306) : error C2143: syntax error : missing ‘{’ before ‘__stdcall’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(320) : error C2143: syntax error : missing ‘{’ before ‘__stdcall’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(336) : error C2143: syntax error : missing ‘{’ before ‘__stdcall’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(352) : error C2143: syntax error : missing ‘{’ before ‘__stdcall’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(367) : error C2143: syntax error : missing ‘{’ before ‘__stdcall’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(379) : error C2143: syntax error : missing ‘{’ before ‘__stdcall’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(391) : error C2143: syntax error : missing ‘{’ before ‘__stdcall’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(404) : error C2143: syntax error : missing ‘{’ before ‘__stdcall’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(416) : error C2143: syntax error : missing ‘{’ before ‘__stdcall’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(428) : error C2143: syntax error : missing ‘{’ before ‘__stdcall’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(440) : error C2143: syntax error : missing ‘{’ before ‘__stdcall’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(461) : error C2143: syntax error : missing ‘{’ before ‘__stdcall’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(475) : error C2143: syntax error : missing ‘{’ before ‘__stdcall’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(489) : error C2143: syntax error : missing ‘{’ before ‘__stdcall’
2>c:\windowsxp\program files\microsoft visual studio 8\vc\include\cutil.h(503) : error C2143: syntax error : missing ‘{’ before ‘__stdcall’

It looks like your include does not work. Try to include cuda.h or some of those. cutil.h is only for the CUDA_SAFE_CALL, CUT_SAFE_CALL and other utilities… cutil is not the CUDA runtime…