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

Electropaint OS X for Snow Leopard

Posted: March 13th, 2010 | Author: Thomas | Filed under: Apple, Development, SGI, Software | Tags: , , , , , , | 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).

ElectropaintOSX

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


CUDA, Objective-C and Xcode — Part 2

Posted: July 22nd, 2009 | Author: Thomas | Filed under: Apple, CUDA, Development | Tags: , , , , | 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:

  1. Launch Xcode and create a cocoa application project
    File > New Project… > Mac OS X > Applications > Cocoa Application
  2. Name the project “CUDA_Demo_1”.
  3. 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.
  4. Create a new file where we put the CUDA code into.
    File > New File… > Mac OS X > Other > Empty File
  5. Name the new file “cudaCompute.cu”.
  6. 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”.
  7. Add a new class that will be the AppController instance
    File > New File… > Mac OS X > Cocoa > Objective-C class
  8. Name the new class files (.m and .h) AppController
  9. Declare a IBAction method that will handle a button press in AppController.h
    - (IBAction)buttonPressed:(id)sender;
  10. Declare the cudaCompute function in AppController.h
    void cudaCompute(void);
  11. Implement buttonPressed: in Appcontroller.m
    - (IBAction)buttonPressed:(id)sender

    {
    cudaCompute();
    NSLog(@"The function cudaCompute was called.");
    }
  12. 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.
  13. Finally set some options before building the project:
    Project > Edit Project Settings > Build
  14. NVIDIA CUDA – CodeGeneration > Device Emulation > Off
  15. NVIDIA CUDA – CodeGeneration > Host Compilation > C
  16. Linking > Runpath Search Paths >  /usr/local/cuda/lib
  17. Linking > Other Linker Flags > -lcuda -lcudart
  18. Search Paths > Library Search Paths > /usr/local/cuda/lib
  19. Search Paths > User Header Search Paths > /usr/local/cuda/include (activate the recursive flag – it will display /usr/local/cuda/include/**)
  20. 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


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.


ColorRef and iPhone OS 3.0

Posted: June 7th, 2009 | Author: Thomas | Filed under: Apple, Development, iPhone | Tags: , , , | No Comments »

The iPhone OS 3.0 will be released soon. From my experience with the beta of iPhone OS, ColorRef version 1.0.1 should still be usable with iPhone OS 3.0. You are going to notice some quirks, but no real show stoppers.

An updated version of ColorRef will be available soon after the release of the iPhone OS 3.0. Currently the internal build is working fine and could already be released … if, well … actually Apple does not allow any application built with the beta SDK into the App Store. So all I can do is test but not release.

I guess, during the WWDC we are going to learn about the time schedule of the final SDK and the iPhone OS 3.0. I am going to release an update as soon as possible. Hopefully the App Store review team will not drown under the torrent of apps rebuilt for iPhone OS 3.0. But with over 35.000 applications available I see some long shifts coming for the review team during the next weeks.


KVC Accessors – The Quick Way

Posted: May 22nd, 2009 | Author: Thomas | Filed under: Apple, Development | Tags: , , , | No Comments »

Before the availibility of Objective-C 2.0 the usage of Key-Value Coding accessors required some boiler plate code. Objective-C 2.0 introduced the @property and @synthesize directives and reduced a lot of boiler plate code into two simple statements. Which is kind of nice.
Nevertheless there might be circumstances that force you to implement KVC accessors manually. But you do not have to type all the accessor methods code by yourself. Xcode can take care of this task. Here is how to do this.

Within you .h file, create the property you need for your application. Let us assume you need an array like this:


NSArray *someArray;

Select the whole line where you just defined your NSArray instance variable and go to the script menu (it is the one with the ancient scroll icon). Select the command

Script Menu > Code > Place Accessor Decls on Clipboard

Next, paste the declarations to your .h file. Select the whole line with your NSArray instance variable again, this time select the command

Script Menu > Code > Place Accessor Defs on Clipboard

and paste the content of the clipboard to your .m file in the @implementation part of your code.
While this is only a minor help for properties of the NSArray class, try the same for the NSMutableArray class. Now we are talking about time saving. Thanks, Xcode team!


0xE800003A

Posted: December 18th, 2008 | Author: Thomas | Filed under: Apple, Development | Tags: , , | No Comments »

Jede Anwendung für das iPhone ist signiert. Egal ob es sich um das fertige Produkt für den AppStore oder  eine adhoc Version aus der laufenden Entwicklung handelt. Manchmal will Xcode nicht so, wie sich der Entwickler das wünscht – das Programm läßt sich verf%&#! nochmal nicht auf dem iPhone installieren. In diesem Falle ist zu prüfen (Stand Xcode 3.1.2, iPhone OS 2.2):

  1. Build > Clean (nach jeder 0xE800003A Meldung ausführen)
  2. In der Info.plist den Bundle Identifier richtig setzen. Dabei beachten, dass Sonderzeichen nicht verwendet werden. Ich trage an dieser Stelle net.CrimsonMagic.${PRODUCT_NAME:identifier} ein.
  3. Targets > theAppName > Info > Code Signing > Code Signing Identity > Any iPhone OS Device > iPhone Developer: Vorname Nachname auswählen.

Vorausgesetzt ist natürlich, dass ein Provisioning Profile im Organizer von Xcode hinterlegt ist und der dazu passende Private Key im Mac OS X Schlüsselbund liegt. Eigentlich ganz einfach … wenn alle drei Punkte beachtet werden.


NSDragOperationDelete ≠ Erwartungskonform?

Posted: October 19th, 2008 | Author: Thomas | Filed under: Apple, Development | Tags: , , , | 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.


Interface Builder Trick zur Fensterwahl

Posted: October 7th, 2008 | Author: Thomas | Filed under: Apple, Development | Tags: | No Comments »

Im Interface Builder von Xcode 3.1.1 ist es zuweilen schwierig, das gewünschte Element auszusuchen. Gerade wenn viele Elemente dich nebeneinander oder sogar übereinander liegen, dann gelingt die Selektion des gewünschten Elements  nicht immer auf anhieb.

Im Podcast Mac Developer Roundtable wurde in Episode 11 ein guter Trick für den IB verraten. Mittels SHIFT+Rechtsklick auf ein Element werden alle dazugehörigen Elemente in einem Pop-Up-Menü angezeigt. Auf diese Weise ist die Auswahl viel bequemer und es ist besser zu erkennen, welche Objekte zu einem Element gehören.