Posted: March 13th, 2010 | Author: Thomas | Filed under: Apple, Development, SGI, Software | Tags: Apple, Cocoa, Development, IRIX, Objective-C, Screensaver, Xcode | 4 Comments »
My favorite screensaver of all times is Electropaint. It has its origins in the IRIX OS. The word “mesmerize” was always one of the things I connected with this screensaver. Electropaint™ is a US Trademark of Tristram Visual, www.tristram.com. But since IRIX is gone for good, Electropaint was on the same route …
Fortunatly, there is a good clone of Electropaint for Mac OS X. An older release can be found in Lloyd’s Lounge. Some time later a universal binary of the screensaver for Intel Macs was made available by Alexander von Below.
Since the release of Mac OS X 10.6 “Snow Leopard” all screensavers need to be 64 bit and use Garbage Collection. Apple posted a TN about the requirement and how to adjust the build settings. Otherwise Mac OS X will not allow the use of the older screensaver module.
So I took the source code and adjusted the build settings according to the TN. A few minutes later, a new build of ElectropaintOSX was ready. Another few minutes later the updated DMG file for easy download was assembled. As my contribution to the project was very small, I increased the version to 0.3.1 — indicating that this is the same codebase as in version 0.3 (Minor change: int and float were replaced by NSUInteger and CGFloat).

I do no longer have an 10.4 SDK on my computer, so I built ElectropaintOSX only for Mac OS X 10.5 and 10.6. And I do no longer have any computer with Mac OS X 10.5, so I could not test the build on Leopard. But it should be OK. If not, try the built supplied by Alexander von Below.
So, here is the link to the DMG file that contains the screensaver and the source code. Happy screensaving.
ElectropaintOSX 0.3.1
Requires: Mac OS X 10.5 or better
Posted: July 22nd, 2009 | Author: Thomas | Filed under: Apple, CUDA, Development | Tags: Cocoa, CUDA, Development, Objective-C, Xcode | No Comments »
In the last blog entry it was discussed what needs to be installed to get a combination of CUDA, Objective-C and Xcode up and running. This part of the series shows how to actually build a very simple project that uses CUDA and Objective-C.
It is assumed that CUDA 2.2, the NVCuda plug-in and the template are installed at their default locations. Furthermore a basic understanding of Objective-C, Xcode and the IB is required.
This is a step by step guide, how to build the simple project:
- Launch Xcode and create a cocoa application project
File > New Project… > Mac OS X > Applications > Cocoa Application
- Name the project “CUDA_Demo_1”.
- Drag the file “/usr/local/cuda/lib/libcudart.dylib” into the project (under the blue icon in the Groups & Files window of Xcode). Copying is not required, but does not hurt either.
- Create a new file where we put the CUDA code into.
File > New File… > Mac OS X > Other > Empty File
- Name the new file “cudaCompute.cu”.
- Copy the “Listing One” of Part 1 from Dr. Dobbs excellent CUDA tutorial into the newly created file cudaCompute.cu. Change the line:
int main(void)
into the following line
extern “C” void cudaCompute(void)
And do not forget the closing bracket in the last line. It is missing in the code of Dr. Dobb’s “Listing One”.
- Add a new class that will be the AppController instance
File > New File… > Mac OS X > Cocoa > Objective-C class
- Name the new class files (.m and .h) AppController
- Declare a IBAction method that will handle a button press in AppController.h
- (IBAction)buttonPressed:(id)sender;
- Declare the cudaCompute function in AppController.h
void cudaCompute(void);
- Implement buttonPressed: in Appcontroller.m
- (IBAction)buttonPressed:(id)sender
{
cudaCompute();
NSLog(@"The function cudaCompute was called.");
}
- Open the MainMenu.xib, put an Object (from the Controller Group) into the xib, set the object to be of the class AppController. Add a button to the window and hook the button to the buttonPressed: action of the AppController class.
- Finally set some options before building the project:
Project > Edit Project Settings > Build
- NVIDIA CUDA – CodeGeneration > Device Emulation > Off
- NVIDIA CUDA – CodeGeneration > Host Compilation > C
- Linking > Runpath Search Paths > /usr/local/cuda/lib
- Linking > Other Linker Flags > -lcuda -lcudart
- Search Paths > Library Search Paths > /usr/local/cuda/lib
- Search Paths > User Header Search Paths > /usr/local/cuda/include (activate the recursive flag – it will display /usr/local/cuda/include/**)
- Build the project. Look at the output. Not much to see there. But this is actually a working CUDA with Objective-C example.
Add some printf statements to see the output the input values of the assert command in cudaCompute.cu. This might help to understand and verify that the application worked as it is supposed to. The project file that can be downloaded here – CUDA_Demo_1 – includes a version of cudaCompute.cu with some additional output and comments.
Some notes about this project:
- It is a very simple example and not even using a true CUDA kernel. The example is about mixing CUDA, Objective-C and Xcode — not about state of the art GPU programming.
- The project settings for the section NVIDIA CUDA – CodeGeneration will only be displayed if there is at least one .cu file included in the project.
- libcudart.dylib is the cuda runtime dynamic library
- Xcode seems to remember some settings as new defaults. So I might have missed to mention a change to a required option. Please inform me if you have some problems with the example, I will try to figure it out.
- Hint: Have a look at the CUDA C:C++ App template for the correct build settings.
- NVIDIA released CUDA 2.3 SDK today. Everything above is valid for CUDA 2.2 SDK. No guarantees for 2.3 – though looking at the release notes there seem to be no obvious show stoppers.
- Thanks to “TheBaron” from the #cuda channel of irc.freenode.net for answering my questions with lots of patience.
The next part of this series will most likely deal with the question, how to move data between Cocoa NSArrays and plain C arrays. And I have to learn more about CUDA. So when looking a my schedule, do not expect Part 3 to arrive soon™.
CUDA, Objective-C and Xcode — Part 2
CUDA, Objective-C and Xcode — Part 1
Posted: July 20th, 2009 | Author: Thomas | Filed under: Apple, CUDA, Development | Tags: Cocoa, CUDA, Objective-C, Xcode | 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”
- Extract the file CUDA_Projects.zip
- 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”
- Extract the file NVCuda.plugin.zip
- 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

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.

So far — so good. In a soon™ to be published follow up I will explain how to combine Cocoa and CUDA.
Posted: October 19th, 2008 | Author: Thomas | Filed under: Apple, Development | Tags: Apple, Development, Objective-C, Xcode | No Comments »
Bei der Implementierung von Drag’n'drop kann die Konstante NSDragOperationDelete verwendet werden, um Objekte zu löschen. Dazu wird ein Objekt auf den Papierkorb gezogen.
Erstaunlicherweise verhält sich bei dieser Drag’n'Drop-Aktion der Papierkorb nicht so, wie es der Benutzer von Umgang mit Dateien kennt. Das Objekt, dass in den Papierkorb gelegt wurde, wird sofort gelöscht und kann nicht wieder hergestellt werden. Das entspricht nicht dem Ansatz, dass gleiche Objekte eines GUIs auch gleiche Eigenschaften bzw. Funktionen ausweisen sollten.
Vermutlich ist daher diese Funktion bei nur wenigen Anwendungen implementiert. Somit ist es empfehlenswert, für die Drag’n'drop-Aktion einen passenden NSUndoManager zu haben.