Question

I am attempting to parallelize simulation code I am using for my thesis with CUDA/Thrust. CUDA/Thrust require use of the nvcc compiler. The C++ code the simulation is written in is kept in an XCode project, and my research group uses XCode feature to track changes and interface with other code, so working outside of it would be hugely inconvenient.

Unfortunately, though I have successfully installed CUDA 6.0, including the nvcc compiler, I cannot find how to make XCode choose nvcc rather than the default compiler. It does not seem to be an option (see screenshot).

I evidently lack the reputation to post an image, but here is a link to it in Dropbox. https://dl.dropboxusercontent.com/u/10738291/XCode%20Screen%20Shot.png If you don't want to look, it just shows that the only compiler option under 'Build Options' is LLVM.

The getting started guide (http://docs.nvidia.com/cuda/cuda-getting-started-guide-for-mac-os-x/#compiler-verification) says only what compiler options to invoke when already using nvcc, but not how to force use of nvcc.

Any idea how I can get XCode to use nvcc instead?

Was it helpful?

Solution

While Xcode has a plug-in mechanism, it is not publicly documented and it changes between point releases of Xcode (like from Xcode 5.0 to 5.1). You likely can't use it, and even if you figured it out, you don't want to use it.

Instead, what you should do is add either a "Run Script" build phase, or more likely, a "Build Rule". With a "Run Script" build phase you can run any command-line script you want. But with a "Build Rule" you can add commands to parse particular file types, so all files of that type will be built with your compiler.

So when I was trying to learn Haskell a few months ago, I added a Build Rule for *.hs files that ran ghc, the Haskell compiler. Your script for a build rule will look something like this:

#!/bin/sh
ghc -c -O -odir ${DERIVED_FILE_DIR} ${SCRIPT_INPUT_FILE}

Replace ghc -c -O -odir with whatever your compiler is and whatever arguments you need.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top