Allow cuFFT plans to be used as a context manager; Set stream before executing cuFFT plans#2362
Conversation
| out_size = a.shape[-1] | ||
|
|
||
| batch = a.size // a.shape[-1] | ||
| plan = cufft.get_current_plan() |
There was a problem hiding this comment.
Doesn't this cause _exec_fft to ignore any plan the user passed in as a kwarg? i.e. if plan is not None, and we are not in a plan context then the provided plan would not be used and Plan1d would be called?
I thought the logic in this section would be something like:
if plan is None:
plan = cufft.get_current_plan()
if plan is None:
plan = cufft.Plan1d(out_size, fft_type, batch)
else:There was a problem hiding this comment.
or alternatively, like in the _default_fft_func below:
curr_plan = cufft.get_current_plan()
if curr_plan is not None:
plan = curr_planThere was a problem hiding this comment.
Yeah good catch! Thank you, @grlee77. I probably got distracted when testing and forgot to revisit this part...
For the record, I was thinking the precedence is:
- plan from context
- plan from argument
- auto planning (for
cupy.fft).
So, if the user uses both context and argument, by design I should have raised an error. I'll add this check when fixing the overridden plan.
| else: | ||
| raise ValueError('a must be contiguous') | ||
|
|
||
| plan = cufft.get_current_plan() |
There was a problem hiding this comment.
same comment here as made for _exec_fft
|
Allowing a plan context manager like this seems pretty nice. I am in favor of it. |
|
@grlee77 thanks for reviewing and supporting this PR. The bug is fixed. |
|
pfnCI, test this please. |
|
Successfully created a job for commit 2517edb: |
|
Jenkins CI test (for commit 2517edb, target branch master) failed with status FAILURE. |
|
Jenkins error on FFT tests is due to #2361. |
|
We will merge #2363 first. |
|
It's merged. Would you like to kick off Jenkins again? |
|
pfnCI, test this please. |
|
Successfully created a job for commit 2517edb: |
|
Jenkins CI test (for commit 2517edb, target branch master) failed with status FAILURE. |
|
pfnCI, test this please. |
|
Successfully created a job for commit 2517edb: |
|
Jenkins CI test (for commit 2517edb, target branch master) failed with status FAILURE. |
|
These test failures seem unrelated to this PR. |
|
pfnCI, test this please. |
|
Successfully created a job for commit 2517edb: |
|
Jenkins CI test (for commit 2517edb, target branch master) succeeded! |
|
LGTM. Thank you for the PR! |
|
Thanks @asi1024! |
Resolves #2356, resolves #2357. This PR enables the following (perhaps more pythonic) usage:
Note that the context manager pattern will work for functions in both
cupy.fftandcupyx.scipy.fftpack.Furthermore, this PR makes it easy to work with the new module
cupyx.scipy.fft(to be added in #2355 following upstream changes):While the
planargument might be added in upstream, see #2356 (comment) and scipy/scipy#10302, we should not count on that.Finally, no backward compatibility is broken in this PR.
Attn: @grlee77, @peterbell10