question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`cupy.fft.irfft` is slow

See original GitHub issue

cupy.fft.irfft is extremely slow and causes unexpected device synchronization.

fft     :    CPU:  511.504 us   +/-182.837 (min:  466.546 / max: 6098.848) us     GPU-0:  914.825 us   +/-181.750 (min:  868.352 / max: 6491.872) us
ifft    :    CPU:  516.756 us   +/-89.689 (min:  499.988 / max: 3025.299) us     GPU-0:  993.364 us   +/-83.566 (min:  970.336 / max: 3351.712) us
rfft    :    CPU:  473.139 us   +/-12.516 (min:  462.383 / max:  624.113) us     GPU-0:  711.520 us   +/-12.456 (min:  699.104 / max:  857.184) us
irfft   :    CPU:483281.932 us   +/-5010.430 (min:479695.227 / max:490367.569) us     GPU-0:483321.136 us   +/-5021.194 (min:479726.959 / max:490421.997) us

Reproducer:

import cupy
import cupyx


a = cupy.random.rand(5000000).astype('f')

funcs = [
    cupy.fft.fft,
    cupy.fft.ifft,
    cupy.fft.rfft,
    cupy.fft.irfft,
]

for f in funcs:
    perf = cupyx.time.repeat(f, (a,), n_warmup=5, max_duration=1)
    print(perf)

cc: @leofang

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

4reactions
grlee77commented, Jul 6, 2020

I think this is just caused by the chosen size of 5,000,000 being particularly unfavorable for irfft. Size 5,000,000 would result from a forward rfft of a signal of size 9,999,999 which is similarly fairly slow (~100 ms when I timed it).

If I take the irfft of a signal of size 5,000,001 or 2,500,001 for example, I get times around 1 ms which is more in line with the results of the other cases above.

2reactions
grlee77commented, Jul 6, 2020

Follow-up: The prime factors of 9,999,999 are [3, 3, 239, 4649], so this involves some large factors that aren’t favorable to good FFT-based acceleration.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Fast Fourier Transform with CuPy — CuPy 11.4.0 documentation
CuPy covers the full Fast Fourier Transform (FFT) functionalities provided in NumPy ... Therefore, the first invocation will be very slow, and this...
Read more >
IRFFT much slower than RFFT on GPU #50230 - GitHub
IRFFT takes much longer than RFFT (orders of magnitude) when running on the GPU. On the CPU, they take about the same amount...
Read more >
numpy.fft.irfft: Why is len(a) necessary? - Stack Overflow
This function computes the inverse of the one-dimensional n-point discrete Fourier Transform of real input computed by rfft . In other words, ...
Read more >
cupy.pdf - Read the Docs
It may make things slower at the first kernel call, though this slow down will be ... cupy.fft.irfft(a, n=None, axis=- 1, norm=None).
Read more >
numpy.fft.irfft() Numpy 1.10官方教程 _w3cschool - 编程狮
numpy.fft.irfft numpy.fft.irfft(a, n=None, axis=-1, norm=None) [source] Compute the inverse of the n-point DFT for real input. This function compu Numpy ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found