8
votes

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?

3
Have you considered using the driver API?Matt
@Matt no - how much work would it take to convert from the runtime api to the driver api?jmilloy
If you have a lot of CUDA code it will take you a while to convert - the driver API is quite a lot more verbose than the runtime API. The driver API code would be easier to compile through mingw, since you call the driver through standard C functions. I can't tell you whether it is worth the pain of switching or not though!Matt

3 Answers

2
votes

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!

1
votes

As far as I know, it is impossible to use CUDA without MSVC. So, you need MSVC to make nvcc work, and you can compile CPU code with mingw and link everything together.

According to http://forums.nvidia.com/index.php?showtopic=30743

"There are no current plans to support mingw."

1
votes

You might want to take a look at how the cycles renderer handles this, look at https://developer.blender.org/diffusion/B/browse/master/extern/cuew/ and https://developer.blender.org/diffusion/B/browse/master/intern/cycles/device/device_cuda.cpp

I know it's not an automagic trick but it might help you get started.