Hi
I was trying to get my head around reduction kernels and wanted to run
the example from the doctumentation. I ran in some trouble doing so.
Here is the complete code I tried to run:
import pyopencl as cl
import pyopencl.array
import pyopencl.reduction
import numpy
if __name__ == '__main__':
context = cl.Context(None,
[(cl.context_properties.PLATFORM,cl.get_platforms()[0])],
cl.device_type.GPU)
queue = cl.CommandQueue(context)
a = cl.array.arange(400, dtype=numpy.float32)
b = cl.array.arange(400, dtype=numpy.float32)
krnl = cl.reduction.ReductionKernel(context, numpy.float32,
neutral="0",
reduce_expr="a+b", map_expr="x[i]*y[i]",
arguments="__global float *x, __global float *y")
my_dot_prod = krnl(a, b).get()
print (my_dot_prod)
Upon running this, I got the following exception:
Traceback (most recent call last):
File
"Z:\Projects\eclipse_workspace\PCPcl\src\cl_testing\reduce_test.py",
line 15, in <module>
a = cl.array.arange(400, dtype=numpy.float32)
File "C:\Python32\lib\site-packages\pyopencl\array.py", line 806, in
arange
return _arange(*args, **kwargs)
File "C:\Python32\lib\site-packages\pyopencl\array.py", line 731, in
_arange
if isinstance(args[-1], np.dtype):
IndexError: tuple index out of range
In the array._arange method this line only works when the data type is a
non-keyword argument, because if it is an keyword argument, *args is
empty. So this needs to be caught and checked against the content of
**kwargs
When I do the same with the numpy dtype as non keyword argument, I get this:
Traceback (most recent call last):
File
"Z:\Projects\eclipse_workspace\PCPcl\src\cl_testing\reduce_test.py",
line 15, in <module>
a = cl.array.arange(400, numpy.float32)
File "C:\Python32\lib\site-packages\pyopencl\array.py", line 806, in
arange
return _arange(*args, **kwargs)
File "C:\Python32\lib\site-packages\pyopencl\array.py", line 774, in
_arange
stop = dtype.type(inf.stop)
ValueError: invalid __array_struct__
This I don't understand. dtype.type should at this point be a
numpy.dtype object of type numpy.float32. I guess the problem must be in
this info() class thats derived from pytools.Record
_______________________________________________
PyOpenCL mailing list
[email protected]
http://lists.tiker.net/listinfo/pyopencl