Wednesday, December 23, 2009

PyCUDA on Mac OS X

PyCUDA came to my attention sometime back and i've got a chance to install it and starting to play with it - this package is essentially a python binding to CUDA (Compute Unified Device Architecture) by Nvidia; and this package (download it here) provides an easier way to program your CUDA graphics card via Python.

Btw, i've installed PyCuda 0.93, boost 1.41.0 and CUDA 2.3 on Mac OS X 10.5.8

So in this post of mine, i'd like to share some of the problems i've faced but before i do that its important that you read through the following wiki pages:
And try out the installation of PyCUDA on those pages but if you found a problem, i might have a solution for you. So i'll run a couple of Q&As here and hope it helps

Q: After i installed PyCUDA as instructed, i ran the test_driver.py and an error message was thrown out Fatal Python error: Interpreter not initialized (version mismatch?). Why is this happening?
A: The version of the Python used is incorrect. You need to rebuild boost and PyCUDA using a consistent version of Python and you need to check the following files
  • siteconf.py (; this file is produced after launching configure.py)
  • project-config.jam (; this file is produced after launching bootstrap.sh)
I changed the following lines in project-config.jam to look like this:
# Python configuration
# using python : 2.5 : /Library/Frameworks/Python.framework/Versions/2.5 ;
using python : 2.5 : /System/Library/Frameworks/Python.framework/Versions/2.5/ ;

Noticed that i changed the python interpreter to use another location (This same location must be used to build PyCuda subsequently (i.e. /System/Library/Frameworks/Python.framework/Versions/2.5/bin/python ./setup.py build etc)

Should be alright now...

Q: When i ran the test_driver.py, i found an error message like this
Traceback (most recent call last):
  File "test_driver.py", line 15, in
    gen = pycuda.autoinit.device.get_attributes()
  File "/Library/Python/2.5/site-packages/pycuda-0.93-py2.5-macosx-10.5-i386.egg/pycuda/driver.py", line 50, in device_get_attributes
    print getattr(device_attribute,i), dev.get_attribute(getattr(device_attribute, i))
pycuda._driver.LogicError: cuDeviceGetAttribute failed: not found
Why is this happening?
A: Frankly, i don't know at the moment but the other tests in the package i've run and tested is alright but something odd is happening (I'm sure its got something to do with my lack of understanding of how libraries are loaded/unloaded)

What i know at this point is that when i re-worked the package a little to provide me debug output, i've found an interesting scenario and you can see this below
cuDeviceGetAttribute
CAN_MAP_HOST_MEMORY 1
cuDeviceGetAttribute
CLOCK_RATE
Traceback (most recent call last):
  File "test_driver.py", line 15, in
    gen = pycuda.autoinit.device.get_attributes()
  File "/Library/Python/2.5/site-packages/pycuda-0.93-py2.5-macosx-10.5-i386.egg/pycuda/driver.py", line 50, in device_get_attributes
    print getattr(device_attribute,i), dev.get_attribute(getattr(device_attribute, i))
pycuda._driver.LogicError: cuDeviceGetAttribute failed: not found



You will see a output that resembles this:
cuDeviceGetAttribute <--- this was enabled by setting CUDA_TRACE=True (False is default)
CAN_MAP_HOST_MEMORY, 1 <--- CUDA device attribute mapped to PyCUDA and the number 1 is the end result of calling the actual API in CUDA
and from some simple deduction you can see that for some reason the program reported that it could not locate the API by the stack trace. .... Will investigate further when i have the bandwidth again but meanwhile feel free to email me if you have an idea why its failing

---- update on 25 dec 2009 -----
A small and quick update is that after removing the attribute CLOCK_RATE in driver.py, it ran fine and the verification passed.
---- end of update ------

---- update on 30 dec 2009 ----
Finally, i've got spare time to look at this and turns out to be a problem with GeForce graphics card present on my machine (there are 2 9400m and 9600m GT)
In a nutshell, i've used the low powered version i.e. 9400m and when i changed to 9600m GT (high performance chip) the problem was resolved.
This is odd because this problem was not present in CUDA 2.0 - Apple / Nvidia bug? Hrmm...
---- end of update ----

But other than that, so far so good :) Have fun !



0 comments: