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)
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
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:
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'])
git submodule update
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.




