It’s not that I’m so smart, it’s just that I stay with problems longer.
— Albert Einstein

CUDA, Objective-C and Xcode — Part 1

Posted: July 20th, 2009 | Author: Thomas | Filed under: Apple, CUDA, Development | Tags: , , , | 5 Comments »

Xcode is the preferred integrated development enviroment (IDE) for most Cocoa developers. It offers good support for a variety of languages, esp. C, C++ and Objective-C. It is possible to extend Xcode to handle matters which Apple does not support out of the box. This post shows how to integrate CUDA with Xcode.

This howto guide was written for Xcode 3.1.3, Mac OS X 10.5.7 and CUDA 2.2. Keep in mind, that later versions may break the following procedure.

To use CUDA the basic files from NVIDIA are required.

  • CUDA Toolkit 2.2 for Mac OS
  • CUDA SDK 2.2.1 code samples for Mac OS
  • (optional) CUDA Visual Profiler v1.2 for Mac OS

When installing these files, take care to choose custom install and mark the CUDA.kext to be installed. See the note on my earlier post about this.

In the next step two files are required: a plug-in to introduce .cu files to Xcode and a template to set up Xcode for CUDA programming. You can download both files from the NVIDA forum in the CUDA on Mac OS X section, specifically posting #29 in this thread. Some very talented guy called Paul T. Thompson created a plug-in and a template. Download the two files labeled “CUDA_Projects.zip” and “NVCuda.pbplugin.zip”.

As described by Paul, these files need to be copied to specific places in your $HOME directory. Here’s the summary:

“CUDA_Projects.zip”

  1. Extract the file CUDA_Projects.zip
  2. Copy the folder CUDA Projects to the folder
    $HOME/Library/Application Support/Developer/Shared/Xcode/Project Templates/
    If some of the folders do not exist in your $HOME folder, simply create them.

“NVCuda.pbplugin.zip”

  1. Extract the file NVCuda.plugin.zip
  2. Copy the file NVCuda.plugin to the folder
    $HOME/Library/Application Support/Developer/Shared/Xcode/Plug-ins/
    Again, if some folders do not exist in your $HOME folder, simply create them.

Basically, that is all, what needs to be done. Launch Xcode and verify the correct installation of CUDA and the plug-in as well as the template. When creating a New Project… , there should be a new choice if the template was copied to the correct location:

User Templates > CUDA Projects > CUDA C:C++ App

CUDA Project Template

Select this and create a new CUDA C:C++ App. To verify the NVCuda.pbplugin, select

Project > Edit Project Settings > Build

Near the bottom of the list should be a section named NVIDIA CUDA – CodeGeneration. If you see this, the plug-in was installed correctly. By default, Device Emulation is active. In the screenshot below it is deactivated.

CUDA Project Settings

So far — so good. In a soon™ to be published follow up I will explain how to combine Cocoa and CUDA.


5 Comments on “CUDA, Objective-C and Xcode — Part 1”

  1. 1 CrimsonMagic » Blog Archive » CUDA, Objective-C and Xcode — Part 2 said at 20:51 on July 22nd, 2009:

    [...] the last blog entry it was discussed what needs to be installed to get a combination of CUDA, Objective-C and [...]

  2. 2 CrimsonMagic » Blog Archive » CUDA, Objective-C and Xcode — Part 1 | IPhoneMate said at 21:17 on August 17th, 2009:

    [...] post: CrimsonMagic » Blog Archive » CUDA, Objective-C and Xcode — Part 1 Share and [...]

  3. 3 Shadejemedali said at 19:28 on March 7th, 2010:

    thank!

  4. 4 Phil said at 00:36 on April 5th, 2010:

    Thank you for this description – I’ll try it out as soon as I can – but I’m quite desperate that it will lead me to a running Cuda project with Xcode :D

    keep up the good work ;)

  5. 5 Mohamme Al-Mahfoudh said at 15:40 on June 25th, 2010:

    Thank you sooo much. I was planning to enroll in a CUDA course in the univ and needed a running IDE to help during the course work and your walkthrough got me running in no time !

    Thanks alot and much appreciation. Keep the good work.


Leave a Reply