[PyCUDA] bad argument to internal function
Ken Seehart
ken at seehart.com
Tue Nov 24 23:02:21 PST 2009
Something like this came up for someone else in May:
http://www.mail-archive.com/pycuda@tiker.net/msg00361.html
*SystemError: ../Objects/longobject.c:336: bad argument to internal
function*
File
"/home/ken/projects/gpuserver/secure/static/snippets/yarng/yarng.py",
line 453, in <module>
test('e')
File
"/home/ken/projects/gpuserver/secure/static/snippets/yarng/yarng.py",
line 438, in test
f(rng, v)
File
"/home/ken/projects/gpuserver/secure/static/snippets/yarng/yarng.py",
line 293, in test_ent
self.randomize(v)
File
"/home/ken/projects/gpuserver/secure/static/snippets/yarng/yarng.py",
line 224, in randomize
self.cu_randomize(self.cu_v, self.n, block=(self.N_THREADS_PER_BLOCK,
1, 1), grid=(self.N_BLOCKS, 1))
File
"/usr/local/lib/python2.6/dist-packages/pycuda-0.91.1-py2.6-linux-i686.egg/pycuda/driver.py",
line 108, in function_call
handlers = func.param_set(*args)
File
"/usr/local/lib/python2.6/dist-packages/pycuda-0.91.1-py2.6-linux-i686.egg/pycuda/driver.py",
line 85, in function_param_set
buf = struct.pack(format, *arg_data)
I fixed it by hacking *_add_functionality* in *driver.py*.
The problem seems to be that the *struct* module doesn't know how to
pack a *numpy.int32* as *'L'*. Perhaps this is due to a change in
*numpy,* or some kind of change in *python 2.6*.
My solution was to simply convert the argument to *long* when it is
appended to *arg_data*, since the important type information is
extracted in the following line (format += arg.dtype.char).
This fixed my problem. Thought you'd like to know.
I'm not how to submit a patch (didn't find anything on
http://wiki.tiker.net/PyCuda).
*def function_param_set(func, *args):*
try:
import numpy
except ImportError:
numpy = None
handlers = []
arg_data = []
format = ""
for i, arg in enumerate(args):
if numpy is not None and isinstance(arg, numpy.number):
* arg_data.append(long(arg)) # convert to long so that
struct.pack will be able to format the data
* format += arg.dtype.char
elif isinstance(arg, (DeviceAllocation, PooledDeviceAllocation)):
arg_data.append(int(arg))
format += "P"
elif isinstance(arg, ArgumentHandler):
handlers.append(arg)
arg_data.append(int(arg.get_device_alloc()))
format += "P"
elif isinstance(arg, buffer):
arg_data.append(arg)
format += "s"
else:
try:
gpudata = arg.gpudata
except AttributeError:
raise TypeError("invalid type on parameter #%d
(0-based)" % i)
else:
# for gpuarrays
arg_data.append(int(gpudata))
format += "P"
import struct
buf = struct.pack(format, *arg_data)
func.param_setv(0, buf)
func.param_set_size(len(buf))
return handlers
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.tiker.net/pipermail/pycuda/attachments/20091124/1da75e51/attachment-0001.htm>
More information about the PyCUDA
mailing list