So, I was able to fix the problem ("ValueError: unable to map dtype
'uint32'"), but I don't really like the solution.
Here is the code we are looking at:
DTYPE_TO_NAME = {}
NAME_TO_DTYPE = {}
def register_dtype(dtype, c_names, alias_ok=False):
if isinstance(c_names, str):
c_names = [c_names]
dtype = np.dtype(dtype)
# check if pre-existing
if not alias_ok and dtype in DTYPE_TO_NAME:
raise RuntimeError("dtype '%s' already registered (as '%s', new
names '%s')"
% (dtype, DTYPE_TO_NAME[dtype], ", ".join(c_names)))
for nm in c_names:
if nm in NAME_TO_DTYPE and NAME_TO_DTYPE[nm] != dtype:
raise RuntimeError("name '%s' already registered" % nm)
for nm in c_names:
NAME_TO_DTYPE[nm] = dtype
if not dtype in DTYPE_TO_NAME:
DTYPE_TO_NAME[dtype] = c_names[0]
if not str(dtype) in DTYPE_TO_NAME:
DTYPE_TO_NAME[str(dtype)] = c_names[0]
def _fill_dtype_registry(respect_windows):
from sys import platform
register_dtype(np.bool, "bool")
register_dtype(np.int8, "char")
register_dtype(np.uint8, "unsigned char")
register_dtype(np.int16, ["short", "signed short", "signed short int",
"short signed int"])
register_dtype(np.uint16, ["unsigned short", "unsigned short int",
"short unsigned int"])
register_dtype(np.int32, ["int", "signed int"])
register_dtype(np.uint32, ["unsigned", "unsigned int"])
if tuple.__itemsize__ * 8 == 64:
if 'win32' in platform:
i64_name = "long long"
else:
i64_name = "long"
register_dtype(np.int64, [i64_name, "%s int" % i64_name, "signed %s
int" % i64_name,
"%s signed int" % i64_name])
register_dtype(np.uint64, ["unsigned %s" % i64_name, "unsigned %s
int" % i64_name,
"%s unsigned int" % i64_name])
register_dtype(np.float32, "float")
register_dtype(np.float64, "double")
# }}}
# {{{ dtype -> ctype
def dtype_to_ctype(dtype, with_fp_tex_hack=False):
if dtype is None:
raise ValueError("dtype may not be None")
dtype = np.dtype(dtype)
if with_fp_tex_hack:
if dtype == np.float32:
return "fp_tex_float"
elif dtype == np.float64:
return "fp_tex_double"
try:
return DTYPE_TO_NAME[str(dtype)] # CHANGE IS HERE: added "str()"
around dtype
except KeyError:
raise ValueError, "unable to map dtype '%s'" % dtype
this is in pyopencl/compyte/dtypes.py. Basically, it registers several
dataypes (including complex datatypes) at startup, and stores them in
dictionaries. Then, to convert between types, it just looks up the types in
the dictionaries. When it registers each datatype, it registers it as both
an np.dtype and as a string.
In my case, it was failing to find uint32. I confirmed that uint32 was
present (both as np.dtype and as string), but for some reason the python
dict was failing to find it, and throwing KeyError instead. So, i convert
dtype to a string before lookup, and it finds it, and everything works.
So, now it is working, but this seems more like a workaround than a
solution. Any ideas why this is happening? I tested on numpy 1.5.1 and
2.0.0.
Lewis
On Sat, Dec 31, 2011 at 1:21 PM, Lewis Anderson <[email protected]>wrote:
> Got it. I thought it would automatically forward. But I'll reply to all. I
> switched to an ATI graphics card, because it was much faster. I built
> pyopencl and everything was fine.
>
> When I run it, it gives an error when making an elementwise kernel:
> "ValueError: unable to map dtype 'uint32'". I saw your previous post on the
> PyCUDA list about doing "git submodule update", and I did that, and still
> have the same problem. So this is on the most recent version of the code
> from git.
>
> Relevant code:
>
> def init_gpu():
> ''' init_gpu(): initialize PyOpenCL, build all kernels
> '''
> global ctx,queue,cl_moving_average
> if USE_GPU:
> os.environ['CL_LOG_ERRORS'] = 'stdout'
> #ctx = cl.create_some_context()
> ctx = cl.Context(dev_type=cl.device_type.GPU)
> print ctx
> queue = cl.CommandQueue(ctx)
> print queue
> cl_moving_average = ElementwiseKernel(ctx,
> "float *act, float *act_l",
> """
> float delta = act[i]-act_l[i];
> float change = 0.0;
> if (delta >= 0.0)
> change = %f*delta; // alpha_plus
> else
> change = %f*delta; // alpha_minus
> act_l[i] = change + act_l[i];
> """%(alpha_plus,alpha_minus),
> "moving_average") # FAILURE IS HERE
>
> Stacktrace:
>
> landerson@lewis-anderson-desktop:~/Dropbox/Cortex/code$ python
> visual_cortex.py
> --- Cortex.py ---
> eta:0.1000, alpha+:0.6000, alpha-:0.0500
> <pyopencl.Context at 0x973b148 on <pyopencl.Device 'ATI RV770' on 'AMD
> Accelerated Parallel Processing' at 0x972ccd8>>
> <pyopencl._cl.CommandQueue object at 0x95b725c>
>
> Traceback (most recent call last):
> File "visual_cortex.py", line 2, in <module>
> import cortex as c, numpy as np, math, retina as r,os,time
> File "/home/landerson/Dropbox/Cortex/code/cortex.py", line 1427, in
> <module>
> init_gpu()
> File "/home/landerson/Dropbox/Cortex/code/cortex.py", line 1280, in
> init_gpu
> "moving_average")
> File
> "/usr/local/lib/python2.7/dist-packages/pyopencl-2011.2-py2.7-linux-i686.egg/pyopencl/elementwise.py",
> line 126, in __init__
> **kwargs)
> File
> "/usr/local/lib/python2.7/dist-packages/pyopencl-2011.2-py2.7-linux-i686.egg/pyopencl/elementwise.py",
> line 91, in get_elwise_kernel_and_types
> name=name, options=options, preamble=preamble, **kwargs)
> File
> "/usr/local/lib/python2.7/dist-packages/pyopencl-2011.2-py2.7-linux-i686.egg/pyopencl/elementwise.py",
> line 61, in get_elwise_program
> "arguments": ", ".join(arg.declarator() for arg in arguments),
> File
> "/usr/local/lib/python2.7/dist-packages/pyopencl-2011.2-py2.7-linux-i686.egg/pyopencl/elementwise.py",
> line 61, in <genexpr>
> "arguments": ", ".join(arg.declarator() for arg in arguments),
> File
> "/usr/local/lib/python2.7/dist-packages/pyopencl-2011.2-py2.7-linux-i686.egg/pyopencl/tools.py",
> line 240, in declarator
> return "%s %s" % (dtype_to_ctype(self.dtype), self.name)
> File
> "/usr/local/lib/python2.7/dist-packages/pyopencl-2011.2-py2.7-linux-i686.egg/pyopencl/compyte/dtypes.py",
> line 107, in dtype_to_ctype
> raise ValueError, "unable to map dtype '%s'" % dtype
> ValueError: unable to map dtype 'uint32'
>
> System specs:
> Ubuntu 11.10 32-bit
> ATI Radeon 4870
> PyOpenCL
>
> Any ideas? Thanks,
> Lewis
>
>
> On Fri, Dec 30, 2011 at 5:25 PM, Andreas Kloeckner <
> [email protected]> wrote:
>
>> On Fri, 30 Dec 2011 15:29:14 -0800, Lewis Anderson <
>> [email protected]> wrote:
>> > Okay. So I took a closer look at the build process. I am linking against
>> > /usr/lib/nvidia-current/libOpenCL.so.1.0.0, which I have confirmed
>> exists.
>> > The problem is that it doesnt seem to get linked, because I get this
>> > warning when I do "make":
>> >
>> > warning: no library file corresponding to
>> > '/usr/lib/nvidia-current/libOpenCL.so.1.0.0' found (skipping)
>> >
>> > And then the final g++ command (in the make process) doesnt contain
>> > libOpenCL.so, meaning it doesnt get linked which leads to the undefined
>> > symbol failure.
>> >
>> >
>> > So, the question now, is why does make fail to find libOpenCL.so? Any
>> > ideas?
>>
>> You are not allowed to specify the "lib" and ".so.1.0.0" parts in
>> configuring pyopencl. I.e. when you link using "-lOpenCL", the linker
>> will look for "libOpenCL.so" (no version tag numbers), which it expects
>> to be a symlink to the desired version. Also, the path goes in the
>> separate "lib dir" entry. Also make sure to use Nvidia headers when
>> linking against an Nvidia libOpenCL.
>>
>> HTH,
>> Andreas
>>
>> PS: Please make sure to keep the list cc'd for archival. Thanks.
>>
>
>
_______________________________________________
PyOpenCL mailing list
[email protected]
http://lists.tiker.net/listinfo/pyopencl