# GPU/CPU Agnostic FFT code

**URL:** <https://discourse.julialang.org/t/gpu-cpu-agnostic-fft-code/126283>\
**Category:** New to Julia\
**Tags:** gpu, hpc\
**Created:** [February 25, 2025, 10:48am UTC](https://discourse.julialang.org/t/gpu-cpu-agnostic-fft-code/126283 "2025-02-25T10:48:55Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![yolhan\_mannes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yolhan_mannes/32/220485_2.png) [@yolhan\_mannes](https://discourse.julialang.org/u/yolhan_mannes)\
**Post date:** [February 25, 2025, 10:55am UTC](https://discourse.julialang.org/t/gpu-cpu-agnostic-fft-code/126283/2 "2025-02-25T10:55:34Z")

</div>

Julia has a FFTW.jl library that dispatch on cpu and gpu and no problem mixing CuArray programing and kernel programing, both will be agnostic, if you need something more than AcceleratedKernels.jl, KernelAbstraction.jl creates agnostic kernels for cpu and gpu. Also, CxxWrap.jl can help you port things that you don’t know how to translate but that won’t be agnostic. For instance in this code

```julia
using FFTW, CUDA, BenchmarkTools
julia> function try_FFT_on_cpu()
           values = rand(256, 256, 256)
           value_complex = ComplexF32.(values)
           cvalues = similar((value_complex), ComplexF32)
           copyto!(cvalues, values)
           cy = similar(cvalues)
           cF = plan_fft!(cvalues, flags=FFTW.MEASURE)
           @btime a = ($cF*$cy)
           return nothing
       end
try_FFT_on_cpu (generic function with 1 method)

julia> function try_FFT_on_cuda()
           values = rand(256, 256, 256)
           value_complex = ComplexF32.(values)
           cvalues = similar(cu(value_complex), ComplexF32)
           copyto!(cvalues, values)
           cy = similar(cvalues)
           cF = plan_fft!(cvalues)
           @btime CUDA.@sync a = ($cF*$cy)
           return nothing
       end
try_FFT_on_cuda (generic function with 1 method)

```

from [Unreasonably fast FFT on CUDA - #8 by roflmaostc](https://discourse.julialang.org/t/unreasonably-fast-fft-on-cuda/109398/8)

---

_[View the full topic](https://discourse.julialang.org/t/gpu-cpu-agnostic-fft-code/126283)._
