fjarri / reikna

Pure Python GPGPU library
http://reikna.publicfields.net/
MIT License
164 stars 16 forks source link

changes to ocl.Array constructor needed after pyopencl ~v2021.2.7 #61

Closed tlambert03 closed 1 year ago

tlambert03 commented 2 years ago

https://github.com/inducer/pyopencl/pull/509 broke reikna's reikna.cluda.ocl.Array subclass:

In [1]: from reikna import cluda

In [2]: api = cluda.ocl_api()

In [3]: thread = api.Thread.create()

In [4]: ary = thread.to_device(np.random.rand(4,4))

In [5]: ary
Out[5]:
cl.Array([[0.10100544, 0.79489181, 0.85656202, 0.78349815],
       [0.51834081, 0.54073664, 0.86848449, 0.04900416],
       [0.43992071, 0.60738575, 0.76459965, 0.01207203],
       [0.04005657, 0.44808462, 0.39126602, 0.89386399]])

so far so good... but using __getitem__ or anything that calls Array. _new_with_changes will cause an error in the constructor.

In [6]: ary[:]
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Input In [6], in <cell line: 1>()
----> 1 ary[:]

File ~/miniconda3/envs/microsim/lib/python3.9/site-packages/reikna/cluda/ocl.py:49, in Array.__getitem__(self, index)
     48 def __getitem__(self, index):
---> 49     res = clarray.Array.__getitem__(self, index)
     51     # Let cl.Array calculate the new strides and offset
     52     return self.thread.array(
     53         shape=res.shape, dtype=res.dtype, strides=res.strides,
     54         base_data=res.base_data,
     55         offset=res.offset)

File ~/miniconda3/envs/microsim/lib/python3.9/site-packages/pyopencl/array.py:2078, in Array.__getitem__(self, index)
   2074     new_strides.append(self.strides[array_axis])
   2076     array_axis += 1
-> 2078 return self._new_with_changes(
   2079         self.base_data, offset=new_offset,
   2080         shape=tuple(new_shape),
   2081         strides=tuple(new_strides))

File ~/miniconda3/envs/microsim/lib/python3.9/site-packages/pyopencl/array.py:640, in Array._new_with_changes(self, data, offset, shape, dtype, strides, queue, allocator)
    637 else:
    638     events = self.events
--> 640 return self.__class__(None, shape, dtype, allocator=allocator,
    641         strides=strides, data=data, offset=offset,
    642         events=events,
    643         _fast=fast, _context=self.context, _queue=queue, _size=size)

TypeError: __init__() got an unexpected keyword argument 'data'

Would it work to add **kwargs to reikna.cluda.ocl.Array.__init__?

fjarri commented 2 years ago

Uhh, yes, this is a known issue, I never got to fixing it. The thing is, that old code is pretty awkward, and my plan was to switch reikna to the the new library (https://github.com/fjarri/grunnur) that would replace cluda and fix this and other issues. But I got pretty busy in the last year, and that just got pushed further to the future. I'll see if it can be fixed in the existing code.

tlambert03 commented 2 years ago

nice! hadn't seen grunner yet... thanks for pointing me to it. No worries here, I'll dig into grunnur a bit.

fjarri commented 1 year ago

Should be fixed by 0d4225f4dafd03b18bf50071ac29eb5eb705c31d