3

Using the pyfftw library, it is easy to do a 1D FFT over a single axis of a multi-dimensional array of shape (M, 2**N) without cycling over the zeroth index explicitly as follows:

afft = pyfftw.interfaces.numpy_fft.fft(a, axis=1).

Switching to arrayfire so that my code can be run on a GPU, I am using the following to do the same thing (with import arrayfire as af):

for idx in af.ParallelRange(M):
    afft = af.fft(a[idx,:])

Although this is executed in parallel it doesn't seem like the best way of doing things and will also make my code horrible to look at.

Is there a way to eliminate the loop using af.fft in a similar way to the pyfftw function, or with an arrayfire version of numpy slicing?

  • 1
    Inspecting the [Arrayfire docs](http://arrayfire.org/docs/group__signal__func__fft.htm) it doesn’t look like the 1D FFT supports applying the 1D transform along one dimension of a multi-dimensional array. What a disappointment, NVIDIA CUDA has had this for years now. – Ahmed Fasih Jan 24 '17 at 11:59
  • 1
    Make sure you do careful timing to see if looping over the second dimension in parallel CPU-threads is faster! It might thrash the GPU if each loopant executes a single FFT on the GPU. It really depends on your array sizes (the length of FFT and the number of FFTs), but if your sizes are big enough, it might be fastest to do a serial loop and let the GPU parallelize one transform at a time. – Ahmed Fasih Jan 24 '17 at 12:07
  • @AhmedFasih -- Other than this one 'missing' feature I have so far found arrayfire to be fantastic in terms of simplicity. There is an option to use a cuda backend, so it might be possible to implement the slicing through that perhaps. Speedup using `af.ParallelRange` with the `af.fft` has so far been faster than just using the standard python `for` loop, but I haven't had the time to benchmark this properly yet. Thanks for the tip re. looping over the second index; I'll give this a go and update once I'm confident that arrayfire will be suitable for what I'm trying to do. –  Jan 24 '17 at 13:25
  • I’ve also used CUFFT through PyCUDA successfully—PyCUDA consumes Numpy arrays, so it’s really ergonomic to use, and of course CUFFT is solid gold. – Ahmed Fasih Jan 24 '17 at 13:58
  • 1
    @FeeJF This is a feature request in upstream arrayfire: https://github.com/arrayfire/arrayfire/issues/1095 – Pavan Yalamanchili Jan 24 '17 at 15:35
  • @PavanYalamanchili Excellent, thank you for the link. –  Jan 24 '17 at 15:36

0 Answers0