Hi. My name is Alex Wiltschko.

This is my internet log.



16 June, 2011

Installing PyCUDA on Snow Leopard

PREAMBLE:
If you're running Mac OS 10.5, this little walk-through is not for you! Get outta here. Git! If you want a nice tutorial on how to install for 10.5, go to the official tutorial for how to install 10.5.  

—————

If you are running Mac OS 10.6, and want some of that gradient optimization and sparse matrix multiplication goodness that PyCUDA offers that (as far as I can tell) ain't in PyOpenCL, you're in for a fun time. Well, I'm being sarcastic, and not you specifically, more like me, I did most of the hair pulling, and I'd like to save you some hair. 

Let's go through this step by step.

1) You should have Python on your system and NumPy as well. I'd highly recommend downloading the Enthought Python Distribution (EPD), and forgetting about the trials of getting an optimized NumPy installation working. Just don't worry about it, download the EPD, install it, and come back when you're done. 

2) We need to snag all of the drivers and toolkits that NVidia provides that PyCUDA depends upon. You can find them here, at this linky link. Scroll down to the bottom of that page, under "MAC OS X", and download everything that has a "download" link next to it. Go through all the installations of everything you downloaded. Okay. Now...

3) Update your shell. What's that mean? Well, launch Terminal.app, and you'll need to edit your bash profile. You can do this by typing

open ~/.profile

If you're running a different shell, I'll assume you know where your profile file is, and you can open it up on your own. This profile might look like this (or it might not, who knows)

Wh
We're going to have to update this to tell the computer where all the fancy things we installed now live. Add these three lines:

 

export PATH="/usr/local/cuda/bin:${PATH}"
export DYLD_LIBRARY_PATH=/usr/local/cuda/lib:$HOME/pool/lib:${DYLD_LIBRARY_PATH}
export PYTHONPATH=$HOME/lib/python:$PYTHONPATH

So, your bash profile should now look like something like this

Wh

Alright, that should do it. We're ready to start rolling.

 

4) Open up Terminal.app, and issue these commands:

git clone http://git.tiker.net/trees/pycuda.git
python configure.py

What do those lines do? The first one grabs all the code we want to install. The last line writes up some files that'll help us install everything.

3) Okay, that primes the pump, but we're not quite ready to install PyCUDA yet. In terminal, run:

open siteconf.py

That'll open up your favorite text editor. On my system, I use TextMate, and this is what I see:

2
What's there by default is wrong. We need to add a few lines for our system (otherwise, PyCUDA will complain bitterly that it's not compiling on OS 10.5, and then it'll throw up on itself and crap out). So, we add these lines:

# if on Snow Leopard, include these lines:

CXXFLAGS = ["-arch", "x86_64", "-arch", "i386"]
LDFLAGS = ["-arch", "x86_64", "-arch", "i386"]
CXXFLAGS.extend(['-isysroot', '/Developer/SDKs/MacOSX10.6.sdk'])
LDFLAGS.extend(['-isysroot', '/Developer/SDKs/MacOSX10.6.sdk'])

And then when we look at our siteconf.py, it looks like this:
3

IF YOU'VE INSTALLED PYTHON 2.7 USING HOMEBREW, THEN YOUR FLAGS SHOULD INSTEAD BE

CXXFLAGS = ["-arch", "x86_64", "-arch", "i386", "-mmacosx-version-min=10.6", "-I/usr/local/lib/python2.7/site-packages/numpy/core/include"] # last element of list -- path to numpy include dir.
LDFLAGS = ["-arch", "x86_64", "-arch", "i386", "-mmacosx-version-min=10.6"]

(thanks to Uznick for this tip)

4) Alrighty, now go back to the Terminal, and type in these two lines:

git submodule init 
git submodule update

These lines grab some extra little helper packages. You won't often see the "git submodule" command used in the wild, but here's one instance where it's absolutely necessary. 

5) Alrighty, this is the home stretch. In terminal, type

make

If there are no errors, wait for quite some time. I believe it is traditional to say "grab a soda," or something like that. If there are errors, see my little "error disclaimer" below.

6) When all the little text finishes flashing by, issue the final stroke:

sudo make install
7) Kablamo. You've now got PyCUDA installed on your system. Convince yourself by launching your Python interpeter (I like iPython the best), and import PyCUDA

ipython
import pycuda
4

Ta-da!

8 (OPTIONAL) ) Do a jig!

 

ERROR DISCLAIMER: if this doesn't work for you for some reason, feel free to email me at  alex (dot) bw (at) gmail (dot) com. I'd be happy to answer questions. Getting this library installed is kind of a hassle, so anything I can do to make the world a slightly less frustrating place, well, I'd love to do it.

Search it. Browse it. Subscribe it. Get caught up in it.


Get the RSS feed! Go ahead.