Say my compnay has got a huge systems consist of many C files. Now i’m trying to call cuda functions from one of the file (to speedup those functions). And changing all the C files into CU files is not an option, as i have no control over them. So is there any efficient way to call cuda functions from within a C file (not CU file) and access their outputs? how is it done?
so far I have seen that similar idea was already developed for Matlab, cuda functions can be called directly from matlab environment and the outputs are accessible. But is this possible for ordinary C files?
__global__ void kernel(int a, int b, int c) {
some calculations
}
void kernel_wrapper(int a, int b, int c) {
dimGrid, dimBlock;
kernel<<<dimGrid, dimBlock>>>(a,b,c);
}
That is all and the simplest way to do so. You can also make more wrappers to copy back your memory but this can also be done from the .c file because the cudaMemcpy’ are c compatible or how you call them… :P
Note: you need to include the cuda.h or cudart.h in you .c files to make use of them and it is also needed to make an .h file for you .cu file
I’m following this topic because I also have some problems with calling .cu functions from a .c file. I’m working in vs2005.
I followed the steps decribed in this topic.
I made a header file for the .cu function.
The header file is included in both .c and .cu.
The additional libraries/headers are also included in the .c file.
cuda.h, not the “cutil.h”
The functions of c and cu are very simply.
But this error always occures:
error LNK2019: unresolved external symbol _Cudafunction ni function _main
file:
line:
error fatal erro LNK1120: 1 unresolved external
file: template.exe
line: 1
I started from the template project of the nvidia cuda site. But I think there are still some libraries that need to be included. But wihich one I don’t know.
“Shortcut” does NOT necessarily imply windows. You could do the same in Linux with “Hard” or “Soft” Links. In Linux, it just takes a shell script to set the links right and you can keep going…
I dont understand why you find this method stupid. I dont see anything stupid in this method.
Are you an ex-microsoft employee? :-)
btw,
Can some1 tell if VS2005 can compile files that are actually shortcuts?
hi, i haven’t been able to make this work yet. I’m not good in compiling shared library, I’ll need more specific instructions to do it lol
as for compiling them into .o files, i’ve tried including b.h in my a.c file, the compilation failed as gcc cannot recognize the line "extern “C” void … " , when i compile with “nvcc -o test a.o b.o” the compiler also fail as it cannot find the function kernel_wrapper(). I’m pretty stuck and confused here.
would you mind state more explicitly how did you do it? i hope you don’t mind to put in a simple example please. Thank you.
You need two .cu files, one .cc or .cpp file and one .c file that contains the “main” function. I started from the cppIntegration project on the cuda sdk example projects.
The following is based on three year ago work using W2K and XP.
Windows shortcuts are implemented at the WIN32 GUI or maybe kernel layer, far above the file system. They are little files interpretted above the file system layer. So most software will work OK with them, certainly GUI software should because GUI s/w uses Windows standard dialog boxes which do the right thing.
Once you get down to the command line in cmd.exe you can run into problems where your program thinks you want the file implementing the shortcut, not the thing the shortcut points to. Also the ANSI C and C++ libraries will definitely choke on shortcuts.
UNIX / Linux links are functions of the file system, an app gets what the file system tells it, and must specifically ask “Is this really a link?”
As I found that your c++ file contains only c programs, I changed it so that you don’t have to go through a c++ wrapper. My full codes (with Makefile) listed below.
in fact, the main problem i faced before was the compilation problem. So when i included the correct libraries path and compile, the cuda program can then be correctly called from C file. :)
and what if instead to be .c files are .cpp files? Should it work ?
Let’s say we have main.cpp, a.cpp, b.cpp, c.cpp, a.h and b.h. We would like to introduce a kernel like we have seen in b.cu.
and what if instead to be .c files are .cpp files? Should it work ?
Let’s say we have main.cpp, a.cpp, b.cpp, c.cpp, a.h and b.h. We would like to introduce a kernel like we have seen in b.cu.
are the files in the same directory? alternately, you can include the absolute path to the .h file you’re trying to include, but I wouldn’t recommend that as a long-term solution. It should be very simple - you’re really just trying to invoke an extern method