Ok, so I managed to get CUDA working in Xcode with OpenMP. It took me a while, so I figure I might as well post all the details to save others the trouble.
The first problem is that the current version of Xcode uses GCC 4.0.1 by default, which does not support OpenMP. Inside an Xcode project, we can specify which version of gcc to use, but NVCC doesn’t care about our choice, and goes ahead and uses the system default anyway. So you have two options: You can either install the latest version of gcc, as I did, or you can change the system default. Changing the system default to GCC 4.2 (which is included in the latest release of xcode) has the advantage that it is an Apple build, and therefore has all the extra Mac OS X stuff built in. Installing a new release has the advantage that you won’t have to change the system default.
To change the system default, navigate to ‘/usr/bin/’ and type:
‘sudo rm gcc’
then:
‘sudo ln -s /opt/local/bin/gcc-4.2 gcc’
This will delete the existing symbolic link, which points to gcc-4.0, and replace it with one that points to gcc-4.2. Your system default is now changed.
Going the other route, you can download and install macports, and the very nice gui front end, ‘Porticus’, and have it download and install the latest version of GCC (in my case, it was 4.4)'. The catch is that it will download the SOURCE for gcc, and then proceed (very VERY slowly) to compile it. It took about 3-4 hours on my second generation MacBook Pro, so be forewarned. Once the new version of GCC is installed (let’s assume that it put it in ‘/opt/local/bin’, as it did for me), navigate to the install directory and type:
‘sudo ln -s /opt/local/bin/gcc-mp-4.4 gcc’
to make the symbolic link you need (this assumes that you want the gcc-mp-4.4 binary to be the default for this installation, as I did).
Now, the next step is to enable Xcode to recognize .cu files, and let it know what the heck to do with them. For that, you need a slightly modified version of Llamatron’s awesome plugin, which I’m attaching below. The change is that I’ve added a project build option to allow you to pass options to the NVCC compiler directly. So download the NVCuda.pbplugin.zip file, decompress it (should happen automatically), and place it in your ‘/Users//Library/Application Support/Developer/Shared/Xcode/Plug-ins/’ directory. If the plug-ins folders doesn’t exist, just create it.
Next, download the CUDA project template file, ‘CUDA Projects.zip’, and decompress it. This folder goes (for Xcode 3.1) in ‘/User//Library/Application Support/Developer/Shared/Xcode/Project Templates/’. Again, if Project Templates doesn’t exist, just create it. Be sure that when you move the folder, that you move the ‘CUDA Projects’ folder, which contains ‘CUDA C/C++ App’, and not just the sub folder itself. If you forget the ‘CUDA Projects’ folder, Xcode probably won’t recognize the project.
Now it’s time to start Xcode. Once Xcode is up, choose ‘New Project…’ from the File menu, and you should see a ‘CUDA Projects’ category under User Templates. Choose the only option (CUDA C:C++ App), and hit ok.
Now, to test it out, lets add ‘#include <omp.h>’ to the .cu file. If you simply changed the system default compiler to GCC 4.2, then at this point you should be able to compile with no errors. If we forgot something, then you’ll probably get an error saying that omp.h doesn’t exist. In that case, you’re on your own to figure it out. :P sorry. Now, if you installed a new version of GCC, such as 4.4, as I did, then there’s one last step we have to take before we can compile. In the project window, under Groups & Files, on the left, click on your project file, and then the info icon. Go to the Build tab, and scroll all the way to the bottom. You should see a setting labeled, “Custom Options for NVCC”. If you don’t see it, then I screwed up somehow, and again, you’re on your own. Assuming you see it though, this is where we tell NVCC where to look for the new gcc compiler (which knows how to handle OpenMP). The command to insert is ‘-ccbin=/opt/local/bin’ (assuming that you installed the new gcc to /opt/local/bin, of course.) The -ccbin option is the same thing as ‘–compiler-bin-dir’, and just tells it where to look. So NOW, finally, you should be able to Build & Go with no errors. If it doesn’t work, then, yes, you’re on your own. But if I did screw this stuff up somehow, and someone figures it out, by all means let me know and I’ll try to fix it.
Enjoy, and good luck!
Paul
CUDA_Projects.zip (87.4 KB)
[attachment=9876:NVCuda.pbplugin.zip]