I am happy to announce the availability of PyCuda, which is a Python wrapper around Cuda. What differentiates it from previousefforts?
[*] Object cleanup is tied to lifetime of objects. This idiom, often called RAII in C++, makes it much easier to write correct, leak- and crash-free code. PyCuda knows about dependencies, too, so (for example) it won’t detach from a context before all memory allocated in it is also freed.
well that’s funny. We are just started working on a project called jacuda (pre alpha) TODO the same stuff in java :) We wanted to include python support, but now that you have done it, why to reinvent the wheel new :)
The truth of the matter is that I haven’t tried it on any other CUDA. It may well work out of the box on 1.1, I simply don’t know. (and chose to be careful in the announcement)
If it doesn’t, I’d be happy to help you get it to work. Just let me know what breaks–all it should take is a few ifdefs.
Wow! This looks great. A nice addition would be integration of the GPUWorker code by MisterAnderson42. This streamlines running tasks on multiple GPUs in the same computer.
I’ve looked at the GPUWorker code. I agree that having something like it would be interesting. However, integrating PyCuda and GPUWorker in a straightforward manner would mean significant code duplication. I’m not sure I want to do that at this point. It got me thinking, though, and with the (new) PyCuda v0.90.2, you can pursue a similar strategy from the Python API alone. PyCuda will now release the Python Global Interpreter Lock while waiting on CUDA, which enables other CUDA-using Python threads to run. While this may not be the final answer, it’s at least a step in the multi-GPU direction.
ok after a week or so I found finally time and try to compile and install it under osx leopard and cuda 1.1
well sadly it failed.
any ideas?
here is the error message:
src/wrapper/wrap_cudadrv.cpp:796: error: 'dstArray' was not declared in this scope
src/wrapper/wrap_cudadrv.cpp: In member function 'void<unnamed>::memcpy_3d::set_dst_device(CUdeviceptr)':
src/wrapper/wrap_cudadrv.cpp:796: error: 'dstMemoryType' was not declared in this scope
src/wrapper/wrap_cudadrv.cpp:796: error: 'dstDevice' was not declared in this scope
src/wrapper/wrap_cudadrv.cpp: In member function 'void<unnamed>::memcpy_3d::execute() const':
src/wrapper/wrap_cudadrv.cpp:800: error: 'cuMemcpy3D' was not declared in this scope
src/wrapper/wrap_cudadrv.cpp: In member function 'void<unnamed>::memcpy_3d::execute_async(const<unnamed>::stream&) const':
src/wrapper/wrap_cudadrv.cpp:804: error: 'cuMemcpy3DAsync' was not declared in this scope
src/wrapper/wrap_cudadrv.cpp: At global scope:
src/wrapper/wrap_cudadrv.cpp:781: error: expected class-name before '{' token
src/wrapper/wrap_cudadrv.cpp: In constructor '<unnamed>::memcpy_3d::memcpy_3d()':
src/wrapper/wrap_cudadrv.cpp:784: error: 'reserved0' was not declared in this scope
src/wrapper/wrap_cudadrv.cpp:785: error: 'reserved1' was not declared in this scope
src/wrapper/wrap_cudadrv.cpp:787: error: 'srcXInBytes' was not declared in this scope
src/wrapper/wrap_cudadrv.cpp:788: error: 'srcY' was not declared in this scope
src/wrapper/wrap_cudadrv.cpp:789: error: 'srcZ' was not declared in this scope
src/wrapper/wrap_cudadrv.cpp:791: error: 'dstXInBytes' was not declared in this scope
src/wrapper/wrap_cudadrv.cpp:792: error: 'dstY' was not declared in this scope
src/wrapper/wrap_cudadrv.cpp:793: error: 'dstZ' was not declared in this scope
src/wrapper/wrap_cudadrv.cpp: In member function 'void<unnamed>::memcpy_3d::set_src_host(boost::python::api::object)':
src/wrapper/wrap_cudadrv.cpp:796: error: 'srcMemoryType' was not declared in this scope
src/wrapper/wrap_cudadrv.cpp:796: error: 'srcHost' was not declared in this scope
src/wrapper/wrap_cudadrv.cpp: In member function 'void<unnamed>::memcpy_3d::set_src_array(const<unnamed>::array&)':
src/wrapper/wrap_cudadrv.cpp:796: error: 'srcMemoryType' was not declared in this scope
src/wrapper/wrap_cudadrv.cpp:796: error: 'srcArray' was not declared in this scope
src/wrapper/wrap_cudadrv.cpp: In member function 'void<unnamed>::memcpy_3d::set_src_device(CUdeviceptr)':
src/wrapper/wrap_cudadrv.cpp:796: error: 'srcMemoryType' was not declared in this scope
src/wrapper/wrap_cudadrv.cpp:796: error: 'srcDevice' was not declared in this scope
src/wrapper/wrap_cudadrv.cpp: In member function 'void<unnamed>::memcpy_3d::set_dst_host(boost::python::api::object)':
src/wrapper/wrap_cudadrv.cpp:796: error: 'dstMemoryType' was not declared in this scope
src/wrapper/wrap_cudadrv.cpp:796: error: 'dstHost' was not declared in this scope
src/wrapper/wrap_cudadrv.cpp: In member function 'void<unnamed>::memcpy_3d::set_dst_array(const<unnamed>::array&)':
src/wrapper/wrap_cudadrv.cpp:796: error: 'dstMemoryType' was not declared in this scope
src/wrapper/wrap_cudadrv.cpp:796: error: 'dstArray' was not declared in this scope
src/wrapper/wrap_cudadrv.cpp: In member function 'void<unnamed>::memcpy_3d::set_dst_device(CUdeviceptr)':
src/wrapper/wrap_cudadrv.cpp:796: error: 'dstMemoryType' was not declared in this scope
src/wrapper/wrap_cudadrv.cpp:796: error: 'dstDevice' was not declared in this scope
src/wrapper/wrap_cudadrv.cpp: In member function 'void<unnamed>::memcpy_3d::execute() const':
src/wrapper/wrap_cudadrv.cpp:800: error: 'cuMemcpy3D' was not declared in this scope
src/wrapper/wrap_cudadrv.cpp: In member function 'void<unnamed>::memcpy_3d::execute_async(const<unnamed>::stream&) const':
src/wrapper/wrap_cudadrv.cpp:804: error: 'cuMemcpy3DAsync' was not declared in this scope
src/wrapper/wrap_cudadrv.cpp: In function 'void init_module__driver()':
src/wrapper/wrap_cudadrv.cpp:947: error: 'CUctx_flags' was not declared in this scope
src/wrapper/wrap_cudadrv.cpp:947: error: template argument 1 is invalid
src/wrapper/wrap_cudadrv.cpp:948: error: 'CU_CTX_SCHED_AUTO' was not declared in this scope
src/wrapper/wrap_cudadrv.cpp:949: error: 'CU_CTX_SCHED_SPIN' was not declared in this scope
src/wrapper/wrap_cudadrv.cpp:950: error: 'CU_CTX_SCHED_YIELD' was not declared in this scope
src/wrapper/wrap_cudadrv.cpp:951: error: 'CU_CTX_SCHED_MASK' was not declared in this scope
src/wrapper/wrap_cudadrv.cpp:952: error: 'CU_CTX_FLAGS_MASK' was not declared in this scope
src/wrapper/wrap_cudadrv.cpp:983: error: 'CU_DEVICE_ATTRIBUTE_MAX_SHARED_MEMORY_PER_BLOCK' was not declared in this scope
src/wrapper/wrap_cudadrv.cpp:988: error: 'CU_DEVICE_ATTRIBUTE_MAX_REGISTERS_PER_BLOCK' was not declared in this scope
src/wrapper/wrap_cudadrv.cpp:994: error: 'CU_DEVICE_ATTRIBUTE_MULTIPROCESSOR_COUNT' was not declared in this scope
src/wrapper/wrap_cudadrv.cpp: In function 'void init_module__driver()':
src/wrapper/wrap_cudadrv.cpp:947: error: 'CUctx_flags' was not declared in this scope
src/wrapper/wrap_cudadrv.cpp:947: error: template argument 1 is invalid
src/wrapper/wrap_cudadrv.cpp:948: error: 'CU_CTX_SCHED_AUTO' was not declared in this scope
src/wrapper/wrap_cudadrv.cpp:949: error: 'CU_CTX_SCHED_SPIN' was not declared in this scope
src/wrapper/wrap_cudadrv.cpp:950: error: 'CU_CTX_SCHED_YIELD' was not declared in this scope
src/wrapper/wrap_cudadrv.cpp:951: error: 'CU_CTX_SCHED_MASK' was not declared in this scope
src/wrapper/wrap_cudadrv.cpp:952: error: 'CU_CTX_FLAGS_MASK' was not declared in this scope
src/wrapper/wrap_cudadrv.cpp:983: error: 'CU_DEVICE_ATTRIBUTE_MAX_SHARED_MEMORY_PER_BLOCK' was not declared in this scope
src/wrapper/wrap_cudadrv.cpp:988: error: 'CU_DEVICE_ATTRIBUTE_MAX_REGISTERS_PER_BLOCK' was not declared in this scope
src/wrapper/wrap_cudadrv.cpp:994: error: 'CU_DEVICE_ATTRIBUTE_MULTIPROCESSOR_COUNT' was not declared in this scope
src/wrapper/wrap_cudadrv.cpp:1159: error: 'srcXInBytes' is not a member of 'init_module__driver()::cl'
src/wrapper/wrap_cudadrv.cpp:1160: error: 'srcY' is not a member of 'init_module__driver()::cl'
src/wrapper/wrap_cudadrv.cpp:1161: error: 'srcZ' is not a member of 'init_module__driver()::cl'
src/wrapper/wrap_cudadrv.cpp:1162: error: 'srcLOD' is not a member of 'init_module__driver()::cl'
src/wrapper/wrap_cudadrv.cpp:1163: error: 'srcMemoryType' is not a member of 'init_module__driver()::cl'
src/wrapper/wrap_cudadrv.cpp:1164: error: 'srcDevice' is not a member of 'init_module__driver()::cl'
src/wrapper/wrap_cudadrv.cpp:1165: error: 'srcPitch' is not a member of 'init_module__driver()::cl'
src/wrapper/wrap_cudadrv.cpp:1159: error: 'srcXInBytes' is not a member of 'init_module__driver()::cl'
src/wrapper/wrap_cudadrv.cpp:1160: error: 'srcY' is not a member of 'init_module__driver()::cl'
src/wrapper/wrap_cudadrv.cpp:1161: error: 'srcZ' is not a member of 'init_module__driver()::cl'
src/wrapper/wrap_cudadrv.cpp:1162: error: 'srcLOD' is not a member of 'init_module__driver()::cl'
src/wrapper/wrap_cudadrv.cpp:1166: error: 'srcHeight' is not a member of 'init_module__driver()::cl'src/wrapper/wrap_cudadrv.cpp:1163: error: 'srcMemoryType' is not a member of 'init_module__driver()::cl'
src/wrapper/wrap_cudadrv.cpp:1164: error: 'srcDevice' is not a member of 'init_module__driver()::cl'
src/wrapper/wrap_cudadrv.cpp:1165: error: 'srcPitch' is not a member of 'init_module__driver()::cl'
src/wrapper/wrap_cudadrv.cpp:1166: error: 'srcHeight' is not a member of 'init_module__driver()::cl'
src/wrapper/wrap_cudadrv.cpp:1172: error: 'dstXInBytes' is not a member of 'init_module__driver()::cl'
src/wrapper/wrap_cudadrv.cpp:1173: error: 'dstY' is not a member of 'init_module__driver()::cl'
src/wrapper/wrap_cudadrv.cpp:1174: error: 'dstZ' is not a member of 'init_module__driver()::cl'
src/wrapper/wrap_cudadrv.cpp:1175: error: 'dstLOD' is not a member of 'init_module__driver()::cl'
src/wrapper/wrap_cudadrv.cpp:1172: error: 'dstXInBytes' is not a member of 'init_module__driver()::cl'
src/wrapper/wrap_cudadrv.cpp:1176: error: 'dstMemoryType' is not a member of 'init_module__driver()::cl'
src/wrapper/wrap_cudadrv.cpp:1173: error: 'dstY' is not a member of 'init_module__driver()::cl'
src/wrapper/wrap_cudadrv.cpp:1177: error: 'dstDevice' is not a member of 'init_module__driver()::cl'
src/wrapper/wrap_cudadrv.cpp:1178: error: 'dstPitch' is not a member of 'init_module__driver()::cl'src/wrapper/wrap_cudadrv.cpp:1174: error: 'dstZ' is not a member of 'init_module__driver()::cl'
src/wrapper/wrap_cudadrv.cpp:1179: error: 'dstHeight' is not a member of 'init_module__driver()::cl'
src/wrapper/wrap_cudadrv.cpp:1175: error: 'dstLOD' is not a member of 'init_module__driver()::cl'
src/wrapper/wrap_cudadrv.cpp:1176: error: 'dstMemoryType' is not a member of 'init_module__driver()::cl'
src/wrapper/wrap_cudadrv.cpp:1177: error: 'dstDevice' is not a member of 'init_module__driver()::cl'
src/wrapper/wrap_cudadrv.cpp:1185: error: 'WidthInBytes' is not a member of 'init_module__driver()::cl'
src/wrapper/wrap_cudadrv.cpp:1178: error: 'dstPitch' is not a member of 'init_module__driver()::cl'
src/wrapper/wrap_cudadrv.cpp:1186: error: 'Height' is not a member of 'init_module__driver()::cl'
src/wrapper/wrap_cudadrv.cpp:1179: error: 'dstHeight' is not a member of 'init_module__driver()::cl'
src/wrapper/wrap_cudadrv.cpp:1187: error: 'Depth' is not a member of 'init_module__driver()::cl'
src/wrapper/wrap_cudadrv.cpp:1185: error: 'WidthInBytes' is not a member of 'init_module__driver()::cl'
src/wrapper/wrap_cudadrv.cpp:1186: error: 'Height' is not a member of 'init_module__driver()::cl'
src/wrapper/wrap_cudadrv.cpp:1187: error: 'Depth' is not a member of 'init_module__driver()::cl'
src/wrapper/wrap_cudadrv.cpp:1221: error: 'CUDA_ARRAY3D_DESCRIPTOR' does not name a type
src/wrapper/wrap_cudadrv.cpp:1222: error: 'cl' was not declared in this scope
src/wrapper/wrap_cudadrv.cpp:1222: error: template argument 1 is invalid
src/wrapper/wrap_cudadrv.cpp:1223: error: 'cl' is not a class or namespace
src/wrapper/wrap_cudadrv.cpp:1223: error: 'Width' was not declared in this scope
src/wrapper/wrap_cudadrv.cpp:1224: error: 'cl' is not a class or namespace
src/wrapper/wrap_cudadrv.cpp:1224: error: 'Height' was not declared in this scope
src/wrapper/wrap_cudadrv.cpp:1225: error: 'cl' is not a class or namespace
src/wrapper/wrap_cudadrv.cpp:1225: error: 'Depth' was not declared in this scope
src/wrapper/wrap_cudadrv.cpp:1226: error: 'cl' is not a class or namespace
src/wrapper/wrap_cudadrv.cpp:1226: error: 'Format' was not declared in this scope
src/wrapper/wrap_cudadrv.cpp:1227: error: 'cl' is not a class or namespace
src/wrapper/wrap_cudadrv.cpp:1227: error: 'NumChannels' was not declared in this scope
src/wrapper/wrap_cudadrv.cpp:1221: error: 'CUDA_ARRAY3D_DESCRIPTOR' does not name a type
src/wrapper/wrap_cudadrv.cpp:1222: error: 'cl' was not declared in this scope
src/wrapper/wrap_cudadrv.cpp:1222: error: template argument 1 is invalid
src/wrapper/wrap_cudadrv.cpp:1223: error: 'cl' is not a class or namespace
src/wrapper/wrap_cudadrv.cpp:1223: error: 'Width' was not declared in this scope
src/wrapper/wrap_cudadrv.cpp:1224: error: 'cl' is not a class or namespace
src/wrapper/wrap_cudadrv.cpp:1224: error: 'Height' was not declared in this scope
src/wrapper/wrap_cudadrv.cpp:1225: error: 'cl' is not a class or namespace
src/wrapper/wrap_cudadrv.cpp:1225: error: 'Depth' was not declared in this scope
src/wrapper/wrap_cudadrv.cpp:1226: error: 'cl' is not a class or namespace
src/wrapper/wrap_cudadrv.cpp:1226: error: 'Format' was not declared in this scope
src/wrapper/wrap_cudadrv.cpp:1227: error: 'cl' is not a class or namespace
src/wrapper/wrap_cudadrv.cpp:1227: error: 'NumChannels' was not declared in this scope
src/wrapper/wrap_cudadrv.cpp:1235: error: ISO C++ forbids declaration of 'type name' with no type
src/wrapper/wrap_cudadrv.cpp:1235: error: missing '>' to terminate the template argument list
src/wrapper/wrap_cudadrv.cpp:1235: error: template argument 1 is invalid
src/wrapper/wrap_cudadrv.cpp:1237: error: 'get_descriptor_3d' is not a member of 'init_module__driver()::cl'
src/wrapper/wrap_cudadrv.cpp:1235: error: ISO C++ forbids declaration of 'type name' with no type
src/wrapper/wrap_cudadrv.cpp:1235: error: missing '>' to terminate the template argument list
src/wrapper/wrap_cudadrv.cpp:1235: error: template argument 1 is invalid
src/wrapper/wrap_cudadrv.cpp:1237: error: 'get_descriptor_3d' is not a member of 'init_module__driver()::cl'
lipo: can't open input file: /var/tmp//cczt266y.out (No such file or directory)
error: command 'gcc' failed with exit status 1
make: *** [install] Error 1
Define BOOST_BIND_ENABLE_STDCALL in the compiler settings. It enables boost::bind support for stdcall. Only define this for 32-bit builds, though. stdcall is automatically turned into cdecl on 64-bit windows causing multiply defined symbols in a boost header file when BOOST_BIND_ENABLE_STDCALL is defined.
# Specify the path to the Boost project. If you move this project,
# adjust the path to refer to the Boost root directory.
use-project boost
: c:/dev/sdk/boost_1_35_0;
# : ../../../..;
# Set up the project-wide requirements that everything uses the
# boost_python library defined in the project whose global ID is
# /boost/python.
project boost-python-quickstart
: requirements
<library>/boost/python//boost_python
<include>c:/cuda/include
<include>C:/Python25/Lib/site-packages/numpy/core/include/
<library>c:/cuda/lib/cuda.lib
;
# Make the definition of the python-extension rule available
import python;
# Declare a Python extension called hello.
python-extension _driver : wrap_cudadrv.cpp
:
<define>BOOST_BIND_ENABLE_STDCALL
;
it seems to have problems with the boost library, since it reports missing files.
gcc -fno-strict-aliasing -Wno-long-double -no-cpp-precomp -mno-fused-madd -fno-common -dynamic -Wall -O3 -DNDEBUG -arch i386 -arch ppc -pipe -I/usr/local/boost/include/ -I/usr/local/cuda/include -I/Library/Python/2.5/site-packages/numpy-1.1.0-py2.5-macosx-10.5-i386.egg/numpy/core/include -I/System/Library/Frameworks/Python.framework/Versions/2.5/include/python2.5 -c src/wrapper/wrap_cudadrv.cpp -o build/temp.macosx-10.5-i386-2.5/src/wrapper/wrap_cudadrv.o
In file included from src/wrapper/wrap_cudadrv.cpp:8:
src/wrapper/wrap_helpers.hpp:7:28: error: boost/python.hpp: No such file or directory
src/wrapper/wrap_cudadrv.cpp:9:41: error: boost/python/stl_iterator.hpp: No such file or directory
src/wrapper/wrap_cudadrv.cpp:10:32: error: boost/shared_ptr.hpp: No such file or directory
src/wrapper/wrap_cudadrv.cpp:11:30: error: boost/weak_ptr.hpp: No such file or directory
I attached the complete errorlog. errorLog.rtf (138 KB)
Now I was able to compile pycuda, but sadly the quest is not done yet and it complain with a couple of warnings.
creating build/temp.macosx-10.5-i386-2.5/src/wrapper
gcc -fno-strict-aliasing -Wno-long-double -no-cpp-precomp -mno-fused-madd -fno-common -dynamic -Wall -O3 -DNDEBUG -arch i386 -arch ppc -pipe -I/usr/local/boost/include/boost-1_35 -I/usr/local/cuda/include -I/Library/Python/2.5/site-packages/numpy-1.1.0-py2.5-macosx-10.5-i386.egg/numpy/core/include -I/System/Library/Frameworks/Python.framework/Versions/2.5/include/python2.5 -c src/wrapper/wrap_cudadrv.cpp -o build/temp.macosx-10.5-i386-2.5/src/wrapper/wrap_cudadrv.o
g++ -Wl,-F. -bundle -undefined dynamic_lookup -arch i386 -arch ppc build/temp.macosx-10.5-i386-2.5/src/wrapper/wrap_cudadrv.o -L/usr/local/boost/lib -L/usr/local/cuda/lib -lboost_python-mt-1_35 -lcuda -o build/lib.macosx-10.5-i386-2.5/pycuda/_driver.so
ld: warning in /usr/local/boost/lib/libboost_python-mt-1_35.dylib, file is not of required architecture
ld: warning in /usr/local/cuda/lib/libcuda.dylib, file is not of required architecture
I guess it’s related to the flag “-arch i386” or “-arch ppc”. I try to track it down.
if we ignore this warning we will not be able to run the tests
[b]fry:test wohlgemuth$ python test_driver.py
[/b]
Traceback (most recent call last):
File "test_driver.py", line 2, in <module>
import pycuda.driver as drv
File "/Library/Python/2.5/site-packages/pycuda-0.90.2-py2.5-macosx-10.5-i386.egg/pycuda/driver.py", line 1, in <module>
from _driver import *
ImportError: dlopen(/Library/Python/2.5/site-packages/pycuda-0.90.2-py2.5-macosx-10.5-i386.egg/pycuda/_driver.so, 2): Symbol not found: _cuCtxGetDevice
Referenced from: /Library/Python/2.5/site-packages/pycuda-0.90.2-py2.5-macosx-10.5-i386.egg/pycuda/_driver.so
Expected in: dynamic lookup