-
Notifications
You must be signed in to change notification settings - Fork 82
Closed
Description
We need an easier way to register custom adjoints that are compatible with Enzyme. The tricky bit here is coming up with a good ABI.
The goal would be to somewhat mimic Diffractor,jl (cc: @simeonschaub), meaning that the rule selection would run before activity analysis and during Julia inference. Alternatively we could attempt to have a callback function that can create additional code after activity analysis, but I rather would like that kind of unlimited compiler recursion.
So taking Base.sin as an example. During type-inference we have Tuple{typeof(Base.sin), Float64} (and maybe the return type) and we somehow need to map that onto:
function tfunc_rrrule(::typeof(Base.sin), ::Type{Active}, ::Type{Active{T}}) where T
function ∇sin(ret_grad, x::Active{T}, tape) where T
return cos(x) * ret_grad
end
end
function tfunc_rrrule(::typeof(Base.sin), ::Type{Const}, ::Type{Active{T}}) where T
function ∇sin(ret_grad, x::Active{T}, tape) where T
return zero(T)
end
end
or:
function rrrule(::typeof(Base.sin), ret_grad::Active{T}, x::Active{T}, tape) where T
return cos(x) * ret_grad
end
function rrrule(::typeof(Base.sin), ret_grad::Const{T}, x::Active{T}, tape) where T
return zero(T)
end
Metadata
Metadata
Assignees
Labels
No labels