Repository navigation
Add scipy.fft to cupyx - #2355
Conversation
|
Thanks, Peter. I will take a look soon. Some additional context for the CuPy team: This work is associated with a SciPy Google Summer of Code project. Any feedback on the implementation is greatly appreciated. Relevant SciPy PRs for additional details are: Starting with SciPy 1.4.0, the recommendation to users is to call FFTs via the new |
|
Hi @grlee77 I suppose it'd work like |
|
Yes, this is using the same underlying implementations from |
|
Just to add to that. The |
|
I see, thanks for the clarification, guys. Do you know what's the official long term plan for |
|
also including @larsoner here (not sure if he already follows this repo) |
There are no plans to deprecate it currently. It will be documented as "long term legacy".
You won't be able to pass a |
OK, perhaps it's better to move the further discussion on |
By sorting the axes before applying _cook_shape it would resize the wrong axes.
* API: add missing norm kwarg to irfft * BUG: _fftn handle axes=None case when shape is specified
|
I still have some test failures locally for Question: Should I add tests for the |
FWIW many other repositories I know of and/or work on use a line like the following in some Travis build: It helps ensure that there are no unhappy surprises leading up to new NumPy and SciPy releases. It helps to add this functionality in a PR separate from whatever functionality actually needs it, though, since using the weekly (?) builds themselves already sometimes exposes issues. |
I would skip that for now unless one of the core devs here expresses support for adding it. I did not test the backend part locally yet, but can do that soon. As is, the automated CI on Travis/Appveyor does not actually run any tests on the GPU. Once you think this is ready, you can ping the maintainers here to trigger a build on their internal Jenkins CI which tests on actual GPU hardware. |
|
I am wondering whether it makes sense or not to expose |
|
It looks good to make |
|
Jenkins, test this please. |
|
Successfully created a job for commit 3095913: |
|
Jenkins CI test (for commit 3095913, target branch master) failed with status FAILURE. |
Hopefully this is a workaround pytest issue 774, "import file mismatch".
|
Just confirmed that this new feature can work seamlessly with the multi-GPU support in #2644 🎉 import cupy
import cupyx.scipy.fft as cu_fft
import scipy.fft
x = cupy.arange(64)
cupy.fft.config.use_multi_gpus = True # from #2644
cupy.fft.config.set_cufft_gpus(2) # from #2644
with scipy.fft.set_backend(cu_fft):
scipy.fft.fft(x) # This runs on 2 GPUs! |
|
We were proposing a change to |
| --------------------------- | ||
| 1. The boolean switch ``cupy.fft.config.enable_nd_planning`` also affects the FFT functions in this module, see :doc:`./fft`. Moreover, as with other FFT modules in CuPy, FFT functions in this module can take advantage of an existing cuFFT plan (returned by :func:`cupyx.scipy.fftpack.get_fft_plan`) when used as a context manager. | ||
|
|
||
| 2. Like in ``scipy.fft``, all FFT functions in this module have an optional argument ``overwrite_x`` (default is ``False``), which has the same semantics as in ``scipy.fft``: when it is set to ``True``, the input array ``x`` *can* (not *will*) be overwritten arbitrary. This is not an in-place FFT, the user should always use the return value from the functions, e.g. ``x = cupyx.scipy.fft.fft(x, ..., overwrite_x=True, ...)``. |
You mean remove that protocol from |
|
To make things a bit more concrete regarding @peterbell10 & @hameerabbasi, please correct if I have gotten anything wrong here As this currently is in the PR, with the following setup: import numpy as np
import cupy
import cupyx.scipy.fft as cu_fft
import scipy.fft
x_np = np.arange(10)
x_cp = cupy.asarray(x_np)case 1: (numpy input, no coercion or fallback allowed) with scipy.fft.set_backend(cu_fft, coerce=False, only=True):
z = scipy.fft.fft(x_np)raises case 2: (no coercian, but fallback is allowed) with scipy.fft.set_backend(cu_fft, coerce=False, only=False):
z = scipy.fft.fft(x_np)This will succeed, but will have actually used pocketfft rather than cupy and case 3: (coercion allowed) with scipy.fft.set_backend(cu_fft, coerce=True, only=True):
z = scipy.fft.fft(x_np)Now with coerce=True, case 4: (no coercion or fallback is necessary or allowed) with scipy.fft.set_backend(cu_fft, coerce=False, only=True):
z = scipy.fft.fft(x_cp)In this case the input is already a cupy.ndarray so computation will be with cuFFT and the output is a cupy.ndarray. |
|
In CuPy functions typically do not support numpy array inputs and will raise an error in that case. So I think the behavior for case 4 in my pervious comment (no coercion allowed) would not be surprising to CuPy users. Is that what you have in mind @hameerabbasi? |
|
The changes for the end-user would be that the |
|
Inside SciPy, the typical function would look like this: @ua.create_multimethod("numpy.scipy.fft") # Or similar
def func(signature):
pass |
|
Jenkins, test this please. |
|
Successfully created a job for commit df54d36: |
|
Jenkins CI test (for commit df54d36, target branch master) succeeded! |
toslunar
left a comment
There was a problem hiding this comment.
LGTM
- While it is unusual for CuPy functions to send arrays to GPU automatically, it seems OK for
scipy.fftfunctions to do so with explicitscipy.fft.set_backend(..., coerce=True). - Could you fix typo (https://github.com/cupy/cupy/pull/2355/files#r350904851) in a new PR?
SciPy version 1.4 will have a new submodule
scipy.fftwith an interface very similar tonumpy.fft. This adds a subset of that interface tocupyx.scipyand also addsuarray-based backend support allowing cupy FFTs to be called through thescipy.fftinterface e.g.Tests are currently failing but at least some of the failures seem to be bugs in
cupy.fft. I need to investigate further.