You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The compiler is not optimizing the code as well as it could when simple derivatives are called from code that contains control-flow.
Reproduction
import _Differentiation
@differentiable(reverse)func oneOperation(a:Float)->Float{return a *2}func f(){varobj:Float=0
for i in 1...1000{
obj +=gradient(at:Float(i), of: oneOperation)}}// As compared to `f()` derivative of `oneOperation`// is fully inlined into `g()`.func g(){// Simple function composition.varobj:Float=0
obj +=gradient(at:Float(i), of: oneOperation)}f()
Expected behavior
More optimized code should be generated. Specifically, the derivative of the simple function, called from a conditional control-flow context, should ideally have the same performance (minus the overhead of control-flow itself) as when called from a non-conditional control-flow context.
Environment
Present in 5.9 and likely all higher and lower versioned toolchains.
Additional information
No response
The text was updated successfully, but these errors were encountered:
jkshtj
added
bug
A deviation from expected or documented behavior. Also: expected but undesirable behavior.
triage needed
This issue needs more specific labels
labels
Feb 9, 2024
…ns in closure-lifetime-fixup pass
This commit modifies the closure-lifetime-fixup pass to skip fixing up
closure-lifetimes for differentiable functions derived from `thin_to_thick_function`
instructions. Such closures should be trivial and should not necessitate
lifetime fixups as they do not capture any values.
Fixesapple#71510
Description
The compiler is not optimizing the code as well as it could when simple derivatives are called from code that contains control-flow.
Reproduction
Expected behavior
More optimized code should be generated. Specifically, the derivative of the simple function, called from a conditional control-flow context, should ideally have the same performance (minus the overhead of control-flow itself) as when called from a non-conditional control-flow context.
Environment
Present in 5.9 and likely all higher and lower versioned toolchains.
Additional information
No response
The text was updated successfully, but these errors were encountered: