Skip to content

dask.fft does not work with cupy arrays #6118

Closed

Description

@izaid
import numpy as np

import cupy as cp

import dask.array as da

x = cp.random.randn(128, 128)
x = da.from_array(x)

da.fft.fft2(x)

Similar to my last issue. It may be that I've mistakenly assumed dask has support for cupy, in which case my apologies. I've seen examples with dask and cupy, but do not know how extensive that is.

Activity

  1. mrocklin commented on Apr 21, 2020

    @mrocklin
    Member

    @izaid thanks for raising. cc @pentschev and @quasiben from NVIDIA in case they have time to test this out.

  2. pentschev commented on Apr 21, 2020

    @pentschev
    Member

    For completeness, this is the error:

    Exception ignored in: <bound method PlanNd.__del__ of <cupy.cuda.cufft.PlanNd object at 0x7f22d8142c80>>
    Traceback (most recent call last):
      File "cupy/cuda/cufft.pyx", line 277, in cupy.cuda.cufft.PlanNd.__del__
    AttributeError: 'PlanNd' object has no attribute 'plan'

    I'm not totally sure what's missing here, perhaps we need to do some handling of plans for CuPy, that would need to be investigated. For sure at least

    sample = np.ones(a.ndim * (8,), dtype=a.dtype)
    would have to be replaced with
    def ones_like_safe(a, shape, **kwargs):
    , but I'm not sure if that's all that's necessary, I guess not.

    Unfortunately, I won't have time for any further investigation until at least mid/late May.

  3. pentschev commented on Apr 21, 2020

    @pentschev
    Member

    Also linked this to our __array_function__ issue tracker in #4731 .

  4. mrocklin commented on Apr 21, 2020

    @mrocklin
    Member

    Unfortunately, I won't have time for any further investigation until at least mid/late May.

    Sure, I'm certain that all of the UCX issues will be ironed out before then ;)

  5. pentschev commented on Apr 21, 2020

    @pentschev
    Member

    Sure, I'm certain that all of the UCX issues will be ironed out before then ;)

    I hope so, but no idea at this point as I thought so many times in the past several months.

  6. mrocklin commented on Apr 21, 2020

    @mrocklin
    Member
  7. leofang commented on Jul 27, 2020

    @leofang

    For some reason my browser opened up this issue to me 🧐 @izaid @pentschev Could you please check if the execution runs correctly, i.e. the result of da.fft.fft2(x) is correct? Note that the error happens at __del__, which in my experience is related to object lifetime not being properly handled in a given context (CUDA's or other libraries').

  8. quasiben commented on Jul 28, 2020

    @quasiben
    Member

    Things do work but an odd exception is raised?

    In [21]: import numpy as np
        ...:
        ...: import cupy as cp
        ...:
        ...: import dask.array as da
        ...:
        ...: y = cp.random.randn(128, 128)
        ...: x = da.from_array(y)
        ...:
        ...: arr = da.fft.fft2(x)
    Exception ignored in: <bound method PlanNd.__del__ of <cupy.cuda.cufft.PlanNd object at 0x7f3de3178d60>>
    Traceback (most recent call last):
      File "cupy/cuda/cufft.pyx", line 277, in cupy.cuda.cufft.PlanNd.__del__
    AttributeError: 'PlanNd' object has no attribute 'plan'
    
    In [22]: da.utils.assert_eq(arr.compute(), cp.fft.fft2(y))
    Out[22]: True

    I am guessing the exception happens during meta construction...

    This is with cupy version 7.6.0

  9. pentschev commented on Aug 5, 2020

    @pentschev
    Member

    I tested this with CuPy 8.0.0b5 and it works, but still fails with 7.7.0. Given there has been a lot of changes for CuPy 8 on the cuFFT front, I think it's unlikely that those changes will be backported to CuPy 7.

    @izaid FYI, CuPy 8 is scheduled for release in late September, so by then this should be no problem anymore, if you can't wait you may considering building it from source to get past this issue.

  10. izaid commented on Aug 27, 2020

    @izaid
    Author

    @pentschev Cheers, thanks for that! Looking forward to giving this a shot with CuPy 8.

  11. leofang commented on Nov 2, 2020

    @leofang

    I verified this works with CuPy v8 and Dask v2.30.

  12. mrocklin commented on Nov 3, 2020

    @mrocklin
    Member

    I'm glad to hear it. Thanks for reporting @leofang .

    Closing.

  13. makslevental commented on Dec 15, 2020

    @makslevental

    I'm confused about how this should work? Running the initial code does indeed produce an FFT but from what I can tell (by watching nvidia-smi) dask does not use my GPUs when I run in this way. Is that correct? Is there a way to get dask to perform these FFTs on gpu workers?

  14. quasiben commented on Dec 15, 2020

    @quasiben
    Member

    @makslevental -- I would recommend opening up a new issue with a minimal reproducer if you have a problem here. Generally, the way this works is through is with NEP-18 , a protocol to dispatch to other libraries from NumPy

    In [1]: import cupy
    
    In [2]: import numpy as np
    
    In [3]: arr = cupy.random.randn(128, 128)
    
    In [4]: res = np.fft.fft(arr)
    
    In [5]: type(res)
    Out[5]: cupy.core.core.ndarray
  15. makslevental commented on Dec 15, 2020

    @makslevental

    @quasiben thanks for the tip. will do if I can't track it down.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions