# Directly applying CuFFT on StructArrays

**URL:** <https://discourse.julialang.org/t/directly-applying-cufft-on-structarrays/55977>\
**Category:** GPU\
**Created:** [February 25, 2021, 2:28am UTC](https://discourse.julialang.org/t/directly-applying-cufft-on-structarrays/55977 "2021-02-25T02:28:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![weylspinor](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/weylspinor/32/23897_2.png) [@weylspinor](https://discourse.julialang.org/u/weylspinor)\
**Post date:** [February 25, 2021, 2:28am UTC](https://discourse.julialang.org/t/directly-applying-cufft-on-structarrays/55977/1 "2021-02-25T02:28:20Z")

</div>

I wonder if there is a way to use `CuFFT` directly on `StructArrays{<:Complex}`. Currently, if I write e.g.

```julia
using CUDA, StructArrays
x_re = rand(Float32, 10);
x_im = rand(Float32, 10);
x = StructArray{ComplexF32}((x_re,x_im));
x_gpu = replace_storage(CuArray, x);
F = CUFFT.plan_fft!(x_gpu); # throws an error

```

The main problem is that `StructArrays` are subtypes of `AbstractArrays`, which is too obscure to be passed to the functions in `CUFFT` (and the same happens with `FFTW.jl`, i.e. `FFTW.plan_fft!(x)` will throw an error).

I think that making a wrapper for `x_gpu` would be a possible solution, but I have no idea on that wrapper. Another solution would be to directly pass `x_gpu` to `ccall`-ed `CUDA` libraries but I have no idea on this too. Could you give me a suggestion?

---

<div class="post-metadata">

**Author:** ![maleadt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maleadt/32/10097_2.png) [@maleadt](https://discourse.julialang.org/u/maleadt)\
**Post date:** [February 25, 2021, 7:43am UTC](https://discourse.julialang.org/t/directly-applying-cufft-on-structarrays/55977/2 "2021-02-25T07:43:43Z")

</div>

A StructArray is made up of two individual arrays, so the memory layout is different to what CUFFT expects (complex elements). So that can’t work, unless CUFFT has APIs that accept two arrays too, in which case you’d need to add the necessary wrappers using `::StructArray` inputs. Another alternative is a native Julia FFT kernel, but that’s a lot of work too.
