cuda with mingw - updated

jmilloy picture jmilloy · May 4, 2011 · Viewed 9.2k times · Source

We have been developing our code in linux, but would like to compile a windows executable. The old non-gpu version compiles just fine with mingw in windows, so I was hoping I'd be able to do the same with the CUDA version.

The strategy is to compile kernel code with nvcc in visual studio, and the rest with gcc in mingw.

So far, we easily compiled the .cu file (with the kernel and kernel launches) in visual studio. However, we still can't compile the c code in mingw. The c code contains cuda api calls such as cudaMalloc and cuda types such as cudaEvent_t, so we must include cuda.h and cuda_runtime.h. However, gcc gives warnings and errors for these headers, for example:

../include/host_defines.h:57:0: warning: "__cdecl" redefined

and

../include/vector_functions.h:127:14: error: 'short_4' has no member named 'x'

Any ideas on how we can include these headers and compile the c portion of the code?

Answer

Jonas Bötel picture Jonas Bötel · May 4, 2011

If you are really desperate there might be a way. The nvcc is really just a frontend for a bunch of compilers. It invokes g++ a lot to strip comments, separate device and host code, handle name mangling, link stuff back together, etc. (use --verbose) to get the details.

My idea is as follows: You should be able to compile the host code with mingw while compiling the device code to a fatbin on a linux machine (as I guess the device binary is host-machine independent). Afterwards link both parts of the code back together with mingw or use the driver API to load the fatbin dynamically. Disclaimer: Did not test!