-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Missing rules for FFTW unsafe_execute
#1717
Comments
As a stopgap solution one can import ChainRules rrules defined in using Enzyme
using FFTW
using AbstractFFTs
using ChainRulesCore
Enzyme.@import_rrule(typeof(*), AbstractFFTs.Plan, AbstractArray)
Enzyme.@import_rrule(typeof(*), AbstractFFTs.ScaledPlan, AbstractArray)
function test(p, x)
y = p * x
return sum(abs2, y)
end
x = rand(ComplexF64, 256)
p = plan_fft(x)
@show test(p, x)
x = rand(ComplexF64, 256)
dx = make_zero(x)
autodiff(Reverse, test, Active, Const(p), Duplicated(x, dx))
display(dx) These rules don't support in-place plans, so I changed your MWE to use an out-of-place plan. |
x-ref stalled AbstractFFTs.jl PR to add Enzyme rules over there: JuliaMath/AbstractFFTs.jl#103. This seems like the right place for any Julia native rules. However, the base FFTW library is such a cornerstone of computational code across languages that it might justify having rules in base Enzyme, similar to BLAS, if and when anyone has time to write them. |
Thanks for pointing this out! Having some rules for FFTW seems like a good idea. Also, the number of rules I'd need to write for FFTW is potentially much smaller than those for AbstractFFTs. |
Just a note that you can skip importing the rule for Enzyme.@import_rrule(typeof(*), AbstractFFTs.Plan, AbstractArray)
EnzymeRules.inactive(::typeof(plan_fft), args...) = nothing
# ... similar `inactive` methods for the other plan functions, like plan_dct Some parts of FFTW are not yet covered by this, notably the |
Here is a MWE
The inactive rule is to prevent another
ijl_lazy_load_and_lookup
error, but that's easy to beat since it shouldn't be differentiated.Unless I misunderstand something, this is another missing rule. If so, I'll take a crack at writing some rules in the next couple of days.
The text was updated successfully, but these errors were encountered: