Installing CUDA on Mac OS

CUDA is a parallel computing platform and programming model that enables dramatic increases in computing performance by harnessing the power of the graphics processing unit (GPU).

In this post, I will tell you how to get started with CUDA on Mac OS. To use CUDA on your system, you will need the following installed:

  1. CUDA-enabled GPU. A list of such GPUs is available here
  2. Mac OS X v. 10.5.6 or later (10.6.3 or later for 64-bit CUDA applications)
  3. The gcc compiler and toolchain installed using Xcode
  4. CUDA software (available at no cost from http://developer.nvidia.com/cuda/cuda-downloads)

Once you have verified that you have a supported NVIDIA processor and a supported version the Mac OS, you need to download the CUDA software. Download the following packages for the latest version of the Development Tools from the site above:

  1. CUDA Driver
  2. CUDA Toolkit
  3. GPU Computing SDK

Installation:

  1. Install the CUDA Driver
    Install the CUDA driver package by executing the installer and following the on-screen prompts. This will install /Library/Framework/CUDA.framework and the UNIX-compatibility stub /usr/local/cuda/lib/libcuda.dylib that refers to it
  2. Install the CUDA Toolkit
    Install the CUDA Toolkit by executing the Toolkit installer package and following the on-screen prompts. The CUDA Toolkit supplements the CUDA Driver with compilers and additional libraries and header files that are installed into /usr/local/cuda by default
  3. Define the environment variables
    – The PATH variable needs to include /usr/local/cuda/bin
    – 
    DYLD_LIBRARY_PATH needs to contain /usr/local/cuda/lib
    The typical way to place these values in your environment is with the following commands:
    export PATH=/usr/local/cuda/bin:$PATH
    export DYLD_LIBRARY_PATH=/usr/local/cuda/lib:$DYLD_LIBRARY_PAT
    To make these settings permanent, place them in ~/.bash_profile
  4. Install CUDA SDK
    The default installation process places the files in/Developer/GPU Computing

To compile the examples, cd into /Developer/GPU Computing/C and type make. The resulting binaries will be installed under the home directory in /Developer/GPU Computing/C/bin/darwin/release

Verify the installation by running ./deviceQuery, the output of which should be something like this

Sample CUDA deviceQuery Program

Now, you are all set to start with CUDA programming!

 

References:

  1. CUDA getting started guide for Mac OS
Advertisements

Why Apple and Mac OS? – II

What’s a hardware with out software? Many think they need to buy many softwares for Mac OS. Frankly, until now I haven’t spent more than $100 on my software. Mac OS gives a very colorful environment to play with: you have Mach, FreeBSD, a nice driver development environment, and a lot of the system’s source code to go with it.

Windows is the odd-man out here. So, let me not talk about it. 😛 When I started using Linux during my college, I wondered why do people still use Windows?! (Ok…you can’t play games like in Windows). I have made heavy use of Linux in academics and now in my job. You can get a lot of the same, or similar software on Mac OS X. You can compile it yourself like you do in linux. Using Macports, you can install most of the softwares like you do on a linux machine. Like ‘sudo apt get install’ you have ‘sudo port install‘ on Mac OS. Mac OS  is representative of a “best-effort” approach – Apple took technology they had collected over the years, along with technology that had flourished in the open source world, and put together a reasonable system.

Personally, I prefer Mac OS to Linux. I found installing new stuff on Mac way easier than other platforms. I mostly use C/C++ in my coding. Once Xcode is installed, voilà! You have the necessary libraries requied to kick-off programming. Macs come with Ruby and Python installed, and an incredible C/C++/Objective C development environment from Xcode environment. The terminal base in linux is very similar to Linux. So, compiling and executing a program via terminal is the same as Linux. Newer versions of Xcode comes preinstalled with OpenCL. As a GPU progrmmer, that makes my life more easy. No need to install any extra libraries. Installing CUDA is also very easy. And also libraries like OpenGL are very easy to install. If you are familiar with linux, then you will be experiencing the same with a little make-up 😉

And I have also started with iPhone programming, and to deploy apps must have a Mac hardware!  You can’t test iPhone apps on a non-Mac hardware. Here again, Xcode simplifies things a lot. Mac OS runs pretty much all open source software flawlessly and, of course, it comes with all of the Unix command line tools and a well-built Terminal app for running them. So, those who are used to the terminal, you will not miss anything.

Here is a list of some of the softwares available for Mac OS.

The Spotlight feature easily lets you search any files on the disk. There are many productivity apps like Garagegand, iPhoto, iMovie, iWeb. Garageband is useful to start any project involving music. You can actually tune your guitar using the mic on a Mac machine. iPhoto lets you organise your photos accordingly. When you attach a new device, Mac OS will mostly recognise that and install the necessary drivers. Since the Mac hardware is so tightly controlled by Apple, Mac OS includes all of the drivers for everything, from graphics to USB, and things just tend to work. And another feature, Universal Access, using which even the blind users can interact with Mac software. Its called Voice Over and it’s exaplained here.

Then there is a great back up feature in Mac OS. Its called Time Machine. It’s as simple as clicking a ‘yes’ button when you put a hard-drive to use as a back-up. And if you want a Mac hardware but prefer working with Linux/windows environment, there’s way for that too. Firstly, Windows Parallels, which is a commercial software where you can install Linux or Windows in Mac OS and access them from. If you want a multi-boot system, you can use Boot Camp, which comes preloaded with Mac OS. It assists users in installing Windows/Linux through non-destructive partitioning of the hard-drive.

Everything said, I prefer to work with a Mac any day over other machines! But…

“Talk is cheap, I will show you the codes from next post” 😉

Why Apple and Mac OS? – I

My friends constantly keep pestering me about my Macbook (2010 model), which sadly is discontinued now, and cant wait to mock me when I run into any trouble with my machine. Recently, I had an issue with my machine where during boot-up it stood still at a white screen with no activity for hours. Well, this issue has a name – Macbook white screen of death! After googling, I found that this was a common issue. But I had to shed some bucks to get it working again. I wanted to upgrade my machine with a better RAM and easy to carry around. So, I ordered a Macbook Air. When my friends came to know about this they asked me – “Why again?”. So, I am writing this post which prompted me to do so. These are my personal views. 😉

I bought my Macbook 2 years ago and I loved it since then. It took me a few days to get acquainted with the new OS but the smooth interface mesmerized me. The multi-touch trackpad is my favorite. If you have used it, you know exactly what I’m talking about. The worst thing about multi-touch on Mac is having to go back to a Windows laptop — you get so used to two and three finger taps that it’s nearly impossible to stop doing it!

Let me break the post into two parts:

  1. Why apple hardware?
  2. Why software?

To use Mac OS, I need not necessarily buy a macintosh machine. I can install Hackintosh on any machine which simulates a Mac OS supporting all the softwares and updates with no issues. Then why apple hardware? As I said earlier, my favorite part in my machine is the multi-touch trackpad. I have worked with few other machines which claim to have a multi-touch trackpad but I found all of them to be jerky. No interface was as smooth. And then the looks. You can’t stop staring at a Macbook with the apple logo glowing. 😉
The apple hardware is in fact expensive. Many  think that Apple is unnecessarily making us buy their machines in order to use Mac OS X. It might be their business strategy! Apple machines are not just pretty, stylish or good-looking, a lot of engineering goes into building them. Take MacBook Air, for example. Its unibody enclosure is machined from a solid block of aluminum. The result is a notebook that is thin and light, looks polished and refined, and feels strong and durable. The magnetic MagSafe power connector breaks cleanly away from the notebook if you trip over the power cord. And who doesn’t love a backlit keyboard which glows in low-light ambience environment. And the battery life – an amazing 7 hours per recharge! Well, these are only some of the features.

If you’ve never, take a look at the inside of a G5 PowerMac. Do an ioreg -l -w 0 on that machine. There are nine fans and twenty-one temperature sensors on it (might vary depending on the model). It’s amazingly quiet.

So, apple hardware and Mac OS is like a package deal. To get the best performance and ease of usability you need to have both.

 

References:

  1. http://adrianoconnor.net/2011/03/10-reasons-why-mac-os-x-is-better-than-windows/
  2. http://osxbook.com/book/bonus/ancient/whatismacosx/conclusion.html

General Purpose Graphic Processing Unit (GPGPU)

In the previous post I described about a GPU, which was intended for graphics acceleration. But how do we, the common people, use the parallel computing capability of a GPU? For that, first let me talk about General Purpose Graphic Processing Unit.

General-purpose computing on graphics processing units (GPGPU, GPGP or less often GP²U) is the means of using a graphics processing unit (GPU), which typically handles computations only for computer graphics, to perform computations in applications traditionally handled by the central processing unit (CPU). Any GPU providing a functionally complete set of operations performed on arbitrary bits can compute any computable value. Additionally, the use of multiple graphics cards in one computer, or large numbers of graphics chips, further parallelizes the already parallel nature of graphics processing. The general-purpose CPU is better at some stuff though : general programming, accessing memory randomly, executing steps in order, everyday stuff. It’s true, though, that CPUs are sprouting cores, looking more and more like GPUs in some respects.

In brief the thing about parallel processing is using tons of cores to break stuff up and crunch it all at once—is that applications have to be programmed to take advantage of it. It’s not easy, which is why Intel at this point hires more software engineers than hardware ones. So even if the hardware’s there, you still need the software to get there, and it’s a whole different kind of programming. Which brings us to OpenCL (Open Computing Language) and CUDA. They’re frameworks that make it way easier to use graphics cards for general purpose computing. OpenCL is the “open standard for parallel programming of heterogeneous systems” standardized by the Khronos Group—AMD, Apple, IBM, Intel, Nvidia, Samsung and a bunch of others are involved. In semi-English, it’s a cross-platform standard for parallel programming across different kinds of hardware—using both CPU and GPU—that anyone can use for free. CUDA is Nvidia’s own architecture for parallel programming on its graphics cards.

Ok…parallel computing is pretty great for scientists and organizations who deal with computationally intensive simulations that go on for days. But does it make our stuff go faster? The answer is — of course. Any one with a good  graphics card has a potential super computer by his side. Converting, decoding, creating and streaming videos—stuff you’re probably using now more than you did a couple years ago—have improved dramatically. Say bye-bye to  20-minute renders. Ditto for image editing; there’ll be less waiting for effects to propagate with giant images (Photoshop CS5, Illustrator, Fireworks etc. already use GPU acceleration). And also many applications like Mathematica, MATLAB and other modelling softwares are making use of GPUs for acceleration.

Hello world!

Hello World!

The future of supercomputing can be summed up in three letters: GPU. GPU stands for graphics processing unit. In the world of high-performance computing, graphics processing units are the talk of the town.

The GPU is a specialized circuit designed to accelerate the image output in a frame buffer intended for output to a display.
GPUs are very efficient at manipulating computer graphics and are generally more effective than general-purpose CPUs for algorithms where processing of large blocks of data is done in parallel. GPUs are moving from video games into high performance computing in a big way since companies like Nvidia and AMD began focusing on software and revised its hardware designs to make them easier to use. Basically a GPU has a large number of cores each capable of executing an operation of its own.

GPU-based high performance computers are starting to play a significant role in large-scale modelling. Three of the 5 most powerful supercomputers in the world take advantage of GPU acceleration. Not coincidentally, this is exactly what China has done to achieve the world’s fastest speeds with its “Tianhe-1A” supercomputer. That computer combines about 7,000 Nvidia GPUs with 14,000 Intel CPUs: the only hybrid CPU-GPU system in the world of that scale.

An example Nvidia’s Russell gave to think about the difference between a traditional CPU and a GPU is this: If you were looking for a word in a book, and handed the task to a CPU, it would start at page 1 and read it all the way to the end, because it’s a “serial” processor. It would be fast, but would take time because it has to go in order. A GPU, which is a “parallel” processor, “would tear the book into a thousand pieces” and read it all at the same time. Even if each individual word is read more slowly, the book may be read in its entirety quicker, because words are read simultaneously.