Installing PyCUDA on Mac OS X

You're looking at the generic instructions for installing PyCUDA on Mac, involving the system Python. If you'd like to use a different Python version (or are running into trouble with these insructions), check these subpages:

The process of installing PyCUDA on Mac OS X is very similar to the Linux one. In fact, you can use the shell (Terminal) for all operations. Below are the components used to build/use PyCUDA:

(You can install Xcode and not bother installing the C++ compiler and Mac OS SDK separately. However, Xcode will take 2+ GB of your drive.)

Pre-install Tips

Step 1: Install Boost

You may already have a working copy of the Boost C++ libraries. If so, make sure that it's version 1.35.0 or newer. If not, no problem, please follow the simple BoostInstallationHowto.

export DYLD_LIBRARY_PATH=/usr/local/cuda/lib:$HOME/pool/lib:$DYLD_LIBRARY_PATH

$HOME/pool/lib is where you installed Boost to. Change it if installed elsewhere.

Continue here when you're done installing Boost.

Step 2: Download and unpack PyCUDA

Download PyCUDA and unpack it:

$ tar xfz pycuda-VERSION.tar.gz

Step 3: Install Numpy

PyCUDA is designed to work in conjunction with numpy, Python's array package. Here's an easy way to install it, if you do not have it already:

$ cd pycuda-VERSION
$ sudo "python ez_setup.py" # this will install setuptools
$ sudo "easy_install numpy" # this will install numpy using setuptools

(If you're not sure, repeating these commands will not hurt.)

Step 4: Build PyCUDA

Next, just type:

$ cd pycuda-VERSION # if you're not there already
$ python configure.py --boost-inc-dir=$HOME/pool/include/boost-1_39/ --boost-lib-dir=$HOME/pool/lib/ --boost-python-libname=boost_python-xgcc42-mt --cuda-root=/usr/local/cuda/

siteconf.py shoud look like:

   1 BOOST_INC_DIR = ['/Users/k5patel/pool/include/boost-1_39/']
   2 BOOST_LIB_DIR = ['/Users/k5patel/pool/lib/']
   3 BOOST_COMPILER = 'gcc42'
   4 BOOST_PYTHON_LIBNAME = ['boost_python-xgcc42-mt']
   5 BOOST_THREAD_LIBNAME = ['boost_thread-xgcc42-mt']
   6 CUDA_TRACE = False
   7 CUDA_ROOT = '/usr/local/cuda/'
   8 CUDA_ENABLE_GL = False
   9 CUDADRV_LIB_DIR = []
  10 CUDADRV_LIBNAME = ['cuda']
  11 
  12 # not necessary with PyCUDA past 2010-01-23 or newer than 0.93.
  13 CXXFLAGS = ['-m32']
  14 LDFLAGS = ['-m32']
  15 
  16 # if on Snow Leopard, include these two lines:
  17 CXXFLAGS.extend(['-isysroot', '/Developer/SDKs/MacOSX10.6.sdk'])
  18 LDFLAGS.extend(['-isysroot', '/Developer/SDKs/MacOSX10.6.sdk'])
  19 
  20 # (Dear Lazyweb--can we detect Snow Leopard somehow? Thanks! -AK)
  21 

Note that gcc42 is a compiler tag that depends on the compiler with which you built boost. Check the contents of your boost library directory to find out what the correct tag is. The instructions above assume that the boost libraries were installed in $HOME/pool. Also note that you will (probably) have to change the value of :option:--cuda-root.

If you are getting the following error: ld: library not found for -lboost_python-xgcc40-mt and installed in /usr/lib, try to re-install boost somewhere else or just "cp -vf /usr/lib/libboost* ." and use --boost-lib-dir=./ with configure.py

Now it's time to build PyCUDA

$ sudo "make install"

ensure that there are no warnings around the line of "different architecture"

Once that works, congratulations! You've successfully built PyCUDA.

Step 5: Test PyCUDA

If you'd like to be extra-careful, you can run PyCUDA's unit tests:

$ cd pycuda-VERSION/test
$ python test_driver.py

If it says "OK" at the end, that means your installation of PyCUDA was successful. Reward yourself by checking out the tutorial.

Notes about Snow Leopard

Python on Snow Leopard defaults to a 64-bit executable. You can check this by typing:

   1 import sys
   2 print sys.maxint
   3 

If it's ~2 billion, you're running Python in 32-bit mode. If it's a huge number, you've got a 64-bit Python, which conflicts with your 32-bit CUDA/PyCUDA drivers and can cause your error message.

You can force Python on Snow Leopard to run in 32-bit by setting a special environment variable:

VERSIONER_PYTHON_PREFER_32_BIT=yes

Or you can make this change permanent and global by writing this to the defaults:

defaults write com.apple.versioner.python Prefer-32-Bit 1

(BryanCatanzaro)

Fatal Python error: Interpreter not initialized (version mismatch?)

If for some reason you are unable to get Boost to link against the correct python, you can use install_name_tool to relink it against the correct one. For example, the following command will relink from the System Python (2.6.1) to the MacPython (2.6.4) on Snow Leopard:

% install_name_tool -change /System/Library/Frameworks/Python.framework/Versions/2.6/Python /Library/Frameworks/Python.framework/Versions/2.6/Python libboost_python.dylib 


CategoryPyCuda

PyCuda/Installation/Mac (last edited 2010-05-06 02:31:14 by AndreasKloeckner)