Skip to content

Fix type of AbstractFFTs.Plan for real-complex FFTs - #2504

Merged
maleadt merged 2 commits into
JuliaGPU:masterfrom
jipolanco:jip/fftplan-type
Sep 25, 2024
Merged

maleadt merged 2 commits into
JuliaGPU:masterfrom
jipolanco:jip/fftplan-type

Conversation

@jipolanco

Copy link
Copy Markdown
Contributor

In AbstractFFTs.jl, the Plan{T} abstract type is defined such that T is the input type of the FFT. For example, a real-to-complex plan returned by plan_rfft should be a subtype of Plan{T} for T real, while the inverse plan (complex-to-real) should be a Plan{Complex{T}}. This is satisfied in particular by plans created by FFTW.jl.

Currently, the opposite is true for CuFFTPlans:

using CUDA
using FFTW
using AbstractFFTs

T = Float64

# CPU

u = rand(T, 256)
p_cpu = plan_rfft(u)
v = p_cpu * u
w = p_cpu \ v

p_cpu isa AbstractFFTs.Plan{T}  # true
p_cpu.pinv isa AbstractFFTs.Plan{Complex{T}}  # true

eltype(p_cpu)       # Float64
eltype(p_cpu.pinv)  # ComplexF64

# GPU

u_gpu = CuArray(u)
p_gpu = plan_rfft(u_gpu)
v_gpu = p_gpu * u_gpu
w_gpu = p_gpu \ v_gpu

p_gpu isa AbstractFFTs.Plan{T}  # false
p_gpu.pinv isa AbstractFFTs.Plan{Complex{T}}  # false

eltype(p_gpu)       # ComplexF64
eltype(p_gpu.pinv)  # Float64

This PR attempts to fix this issue.

@maleadt

maleadt commented Sep 25, 2024

Copy link
Copy Markdown
Member

Thanks!

@maleadt
maleadt merged commit 71ae06b into JuliaGPU:master Sep 25, 2024
@jipolanco
jipolanco deleted the jip/fftplan-type branch September 25, 2024 19:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants