Skip to content

dask.array.triu does not works with cupy array #7452

@aktech

Description

@aktech

What happened:
There is a bug which is preventing da.triu to work on cupy arrays. I feel the bug is in dask.array which is sending wrong array to cupy as in sending np.ndarray instead of cp.ndarray. I haven't looked very closely, but this should be easy to fix, I believe.

cc @pentschev for FYI

What you expected to happen:
Result of triu function on the cupy array

Minimal Complete Verifiable Example:

import cupy
import dask.array as da
import dask

print(cupy.__version__)
print(dask.__version__)

x = da.arange(4).reshape(2, 2)
x = x.map_blocks(cupy.asarray)
t = da.triu(x)
t.compute()

Traceback:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-2-b21820d122aa> in <module>
      8 x = x.map_blocks(cupy.asarray)
      9 t = da.triu(x)
---> 10 t.compute()

~/.conda/envs/sgkit-gpu-new/lib/python3.8/site-packages/dask/base.py in compute(self, **kwargs)
    281         dask.base.compute
    282         """
--> 283         (result,) = compute(self, traverse=False, **kwargs)
    284         return result
    285 

~/.conda/envs/sgkit-gpu-new/lib/python3.8/site-packages/dask/base.py in compute(*args, **kwargs)
    563         postcomputes.append(x.__dask_postcompute__())
    564 
--> 565     results = schedule(dsk, keys, **kwargs)
    566     return repack([f(r, *a) for r, (f, a) in zip(results, postcomputes)])
    567 

~/.conda/envs/sgkit-gpu-new/lib/python3.8/site-packages/dask/threaded.py in get(dsk, result, cache, num_workers, pool, **kwargs)
     74                 pools[thread][num_workers] = pool
     75 
---> 76     results = get_async(
     77         pool.apply_async,
     78         len(pool._pool),

~/.conda/envs/sgkit-gpu-new/lib/python3.8/site-packages/dask/local.py in get_async(apply_async, num_workers, dsk, result, cache, get_id, rerun_exceptions_locally, pack_exception, raise_exception, callbacks, dumps, loads, **kwargs)
    485                         _execute_task(task, data)  # Re-execute locally
    486                     else:
--> 487                         raise_exception(exc, tb)
    488                 res, worker_id = loads(res_info)
    489                 state["cache"][key] = res

~/.conda/envs/sgkit-gpu-new/lib/python3.8/site-packages/dask/local.py in reraise(exc, tb)
    315     if exc.__traceback__ is not tb:
    316         raise exc.with_traceback(tb)
--> 317     raise exc
    318 
    319 

~/.conda/envs/sgkit-gpu-new/lib/python3.8/site-packages/dask/local.py in execute_task(key, task_info, dumps, loads, get_id, pack_exception)
    220     try:
    221         task, data = loads(task_info)
--> 222         result = _execute_task(task, data)
    223         id = get_id()
    224         result = dumps((result, id))

~/.conda/envs/sgkit-gpu-new/lib/python3.8/site-packages/dask/core.py in _execute_task(arg, cache, dsk)
    119         # temporaries by their reference count and can execute certain
    120         # operations in-place.
--> 121         return func(*(_execute_task(a, cache) for a in args))
    122     elif not ishashable(arg):
    123         return arg

~/.conda/envs/sgkit-gpu-new/lib/python3.8/site-packages/dask/optimization.py in __call__(self, *args)
    961         if not len(args) == len(self.inkeys):
    962             raise ValueError("Expected %d args, got %d" % (len(self.inkeys), len(args)))
--> 963         return core.get(self.dsk, self.outkey, dict(zip(self.inkeys, args)))
    964 
    965     def __reduce__(self):

~/.conda/envs/sgkit-gpu-new/lib/python3.8/site-packages/dask/core.py in get(dsk, out, cache)
    149     for key in toposort(dsk):
    150         task = dsk[key]
--> 151         result = _execute_task(task, cache)
    152         cache[key] = result
    153     result = _execute_task(out, cache)

~/.conda/envs/sgkit-gpu-new/lib/python3.8/site-packages/dask/core.py in _execute_task(arg, cache, dsk)
    119         # temporaries by their reference count and can execute certain
    120         # operations in-place.
--> 121         return func(*(_execute_task(a, cache) for a in args))
    122     elif not ishashable(arg):
    123         return arg

<__array_function__ internals> in where(*args, **kwargs)

cupy/core/core.pyx in cupy.core.core.ndarray.__array_function__()

~/.conda/envs/sgkit-gpu-new/lib/python3.8/site-packages/cupy/_sorting/search.py in where(condition, x, y)
    209     if fusion._is_fusing():
    210         return fusion._call_ufunc(_where_ufunc, condition, x, y)
--> 211     return _where_ufunc(condition.astype('?'), x, y)
    212 
    213 

cupy/core/_kernel.pyx in cupy.core._kernel.ufunc.__call__()

cupy/core/_kernel.pyx in cupy.core._kernel._preprocess_args()

TypeError: Unsupported type <class 'numpy.ndarray'>

Anything else we need to know?:

Environment:

  • Dask version: 2021.03.0
  • Python version: 3.8.8
  • Operating System: Ubuntu 18.04
  • Install method (conda, pip, source): conda

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions