Closed pierrepaleo closed 1 year ago
cc @alexfikl (since this came from a change you made)
To reproduce the bug:
In [1]: import pyopencl, pyopencl.array, numpy
In [2]: ctx = pyopencl.create_some_context()
In [3]: queue = pyopencl.CommandQueue(ctx)
In [4]: ary = pyopencl.array.empty(queue, numpy.uint64(10), dtype="float32")
In [5]: ary = pyopencl.array.empty(queue, (numpy.uint64(10),), dtype="float32")
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-5-1e5620a87523> in <module>
----> 1 ary = pyopencl.array.empty(queue, (numpy.uint64(10),), dtype="float32")
/usr/lib/python3/dist-packages/pyopencl/array.py in __init__(***failed resolving arguments***)
532 context = queue.context
533
--> 534 self.base_data = cl.Buffer(
535 context, cl.mem_flags.READ_WRITE, alloc_nbytes)
536 else:
TypeError: __init__(): incompatible constructor arguments. The following argument types are supported:
1. pyopencl._cl.Buffer(context: pyopencl._cl.Context, flags: int, size: int = 0, hostbuf: object = None)
Invoked with: <pyopencl.Context at 0x1040dd0 on <pyopencl.Device 'gfx900:xnack-' on 'AMD Accelerated Parallel Processing' at 0x1d34a20>>, 1, 40.0
I have a code which does a series of allocations using
pyopencl.array
.One of the allocation fails with the following error
~Unfortunately it's difficult to create a MWE to reproduce the crash, not sure why (caching ?).~ See https://github.com/inducer/pyopencl/issues/659#issuecomment-1318177386 for a MWE reproducing the crash
After investigation, it seems that the cause is in
pyopencl.array
which tries to allocate a buffer wheresize
is passed as float.Consider the following part in
pyopencl/array.py
:Importantly, if
size
is auint64
anddim
is an integer, the*=
operation is promotingsize
to a float (!).I'd suggest to use the following:
The above code snippet fixes the problem in my case.
Tested on python 3.8, pocl driver, power9 architecture, Nvidia V100 GPU: