All posts

Snow Leopard OpenCL Grand Central

Originally published on macresearch.org, around 2008. Reproduced from the author's archive; some links may no longer resolve.

Snow Leopard will be a Performance Monster

In case you missed it, alongside all the hoo-ha surrounding the new iPhone 3G last week, there was a little information (link no longer available) posted by Apple about the next release of Mac OS X: Snow Leopard. What is most surprising about this is that Snow Leopard will have very little new functionality … at least, functionality visible to the user. No Time Machine or Spotlight, just under-the-cover improvements in performance and stability. Doesn’t sound very interesting, right? Wrong.

Snow Leopard may well end up being more important to scientific developers than major releases like Tiger and Leopard. Of the 5 features listed on Apple’s Snow Leopard page (link no longer available), 3 are directly relevant to performance. (It’s also interesting to note that 1 feature — MS Exchange Support — is an enterprise feature, perhaps indicating that Apple is finally ready to make a push there.)

The first performance feature is 64-bit, which we have seen before, but appears to be improved in Snow Leopard, allowing enormous amounts of RAM to be addressed. This should be beneficial to certain scientific applications.

The second is Multicore, and a new technology called Grand Central. Apple’s site describes it thusly

“Grand Central,” a new set of technologies built into Snow Leopard, brings unrivaled support for multicore systems to Mac OS X. More cores, not faster clock speeds, drive performance increases in today’s processors. Grand Central takes full advantage by making all of Mac OS X multicore aware and optimizing it for allocating tasks across multiple cores and processors. Grand Central also makes it much easier for developers to create programs that squeeze every last drop of power from multicore systems.

This is a reasonably vague PR description, so having not actually attended WWDC this year, it leaves me with a lot of questions. It seems Apple is hard at work on a whole new model for threading, one that will be much simpler to use than pthreads. What this will look like is not clear from the publicly available information. Probably some sort of language support in C, or system level changes to the APIs, and a different approach to scheduling in the kernel.

Grand Central may be partially inspired by the iPhone, where ‘multi-threading’ is a dirty word. It could be that Apple wants a threading model that is more flexible, running in parallel on multicore, interleaved on a single core Mac, and completely serially on iPhone. With such a model built into the kernel, Apple could choose when to allow parallel operations, and how many. In the current system, any app can spawn threads when it chooses, and potentially bring your operating system to a grinding standstill (or run down the battery).

The last new performance feature in Snow Leopard is OpenCL. From Apple’s web site:

Another powerful Snow Leopard technology, OpenCL (Open Computing Language), makes it possible for developers to efficiently tap the vast gigaflops of computing power currently locked up in the graphics processing unit (GPU). With GPUs approaching processing speeds of a trillion operations per second, they’re capable of considerably more than just drawing pictures. OpenCL takes that power and redirects it for general-purpose computing.

This must be related to the discussion of CUDA (link no longer available) that took place last week, but it goes further than anticipated. It is now common knowledge that graphics cards have vast amounts of untapped computing resources; the problem is, every manufacturer has devised its own means of accessing those resources. As things stand today, you need a different version of your software for each variety of GPU.

This is not the first time a situation like this has arisen. In the early days of 3D graphics, it was also a problem. At that time, SGI took the initiative, introducing OpenGL, an open language for programming 3D graphics. The rest is history.

Apple is clearly trying to do the same thing for executing code on the GPU. OpenCL is intended to be an open language; any code written with OpenCL should work on any graphics card, and will presumably fall back to executing on the CPU if no OpenCL-aware GPU is available. If the graphics card manufacturers adopt the new standard, it should make developing high-performance scientific apps that utilize the GPU much simpler.

So, if you thought Snow Leopard was more purr than pounce, think again: under the hood, Apple are introducing some very interesting technologies, and scientific developers are amongst the big winners.