pycuda icon indicating copy to clipboard operation
pycuda copied to clipboard

0 sized array operations fail

Open mitkotak opened this issue 1 year ago • 1 comments

Here's the MWE

>>> import pycuda.autoinit
>>> import pycuda.gpuarray as gpuarray
>>> import numpy as np
>>> empty = np.array([])
>>> empty_gpu = gpuarray.to_gpu(empty)
>>> empty + empty # Passes 
>>> empty_gpu + empty_gpu # Fails

Here's the error trace

---------------------------------------------------------------------------
error                                     Traceback (most recent call last)
Input In [7], in <cell line: 7>()
      5 empty_gpu = gpuarray.to_gpu(empty)
      6 empty + empty # Passes
----> 7 empty_gpu + empty_gpu

File ~/pycuda/pycuda/gpuarray.py:588, in GPUArray.__add__(self, other)
    585 if isinstance(other, GPUArray):
    586     # add another vector
    587     result = _get_broadcasted_binary_op_result(self, other)
--> 588     return self._axpbyz(1, other, 1, result)
    590 elif np.isscalar(other):
    591     # add a scalar
    592     if other == 0:

File ~/pycuda/pycuda/gpuarray.py:445, in GPUArray._axpbyz(self, selffac, other, otherfac, out, add_timer, stream)
    432     add_timer(
    433         3 * self.size,
    434         func.prepared_timed_call(
   (...)
    442         ),
    443     )
    444 else:
--> 445     func.prepared_async_call(
    446         out._grid,
    447         out._block,
    448         stream,
    449         selffac,
    450         self.gpudata,
    451         otherfac,
    452         other.gpudata,
    453         out.gpudata,
    454         out.mem_size,
    455     )
    457 return out

File ~/pycuda/pycuda/driver.py:625, in _add_functionality.<locals>.function_prepared_async_call(func, grid, block, stream, *args, **kwargs)
    619     raise TypeError(
    620         "unknown keyword arguments: " + ", ".join(kwargs.keys())
    621     )
    623 from pycuda._pvt_struct import pack
--> 625 arg_buf = pack(func.arg_format, *args)
    627 for texref in func.texrefs:
    628     func.param_set_texref(texref)

error: required argument is not an integer

mitkotak avatar Aug 16 '22 20:08 mitkotak

There's a proposed fix for this at https://gitlab.tiker.net/inducer/pycuda/-/merge_requests/75.

kaushikcfd avatar Aug 26 '22 22:08 kaushikcfd