1
votes

I want to compile CUDA code on mac but make it executable on Windows.

Is there a way to set up an nvcc CUDA cross compiler?

The problem is that my desktop windows will be inaccessible for a while due to traveling, however i do not want to wasted time by waiting til i get back and compile the code. If I have to wait then it would be a waste of time to debug the code and make sure it compiles correct and the likes. My mac is not equipped with cuda capable hardware though.

1
I use CMake build system for cross compiling. Did you looked at it? - geek
not yet. is it the same as building a regular cross compiler? - mma1480
Nvcc isn't a compiler. It relies on the host compiler to do most of the compilation (including much of the GPU code compilation). To compile for windows, that requires the visual studio compiler, and the requirement is non-negotiable. You can install the tool chain on OS X without an NVIDIA GPU. You just won't be able to run the result OS X executables. - talonmies
Yes, but I think I's easiest way to work with cross-compilation toolchains. You say CMake there is your toolchain file and it set all flags, compilers paths and so on. And you nvcc can recognize that compiler it mast use actually - geek
cross compiling means compiling for a target architecture which is different from the architecture of the host doing the compilation. You can't cross compile for Windows targets on OS X or Linux because the Microsoft compiler can't run on OS X or Linux. CMake can't change that. - talonmies

1 Answers

7
votes

The short answer, is no, it is not possible.

It is a common misconception, but nvcc isn't actually a compiler. It is a compiler driver, and it relies heavily on the host C++ compiler in order to steer compilation both host and device code. To compile CUDA for Windows, you must using the Microsoft C++ compiler. That compiler can't be run on Linux or OS X, so cross compilation to a Windows target is not possible unless you are doing the compilation on a Windows host (so 32/64 bit cross compilation is possible, for example).

The other two CUDA platforms are equally incompatible, despite requiring gcc for compilation, because the back ends are different (Linux is an elf platform, OS X is a mach platform), so even cross compilation between OS X and Linux isn't possible.

You have two choices if compilation on the OS X platform is the goal

  1. Install the OS X toolkit. Even though your hardware doesn't have a compatible GPU, you can still install the toolkit and compile code.
  2. Install the Windows toolkit and visual studio inside a virtual windows installation (or a physical boot camp installation), and compile code inside Windows on the Mac. Again, you don't need NVIDIA compatible hardware to do this.

If you want to run code without a CUDA GPU, there is a non-commercial (GPU Ocelot) and commercial (PGI CUDA-x86) option you could investigate.