swift
dd1d6890 - [AutoDiff] Support `inout` argument differentiation. (#30013)

Commit
5 years ago
[AutoDiff] Support `inout` argument differentiation. (#30013) Cherry-pick https://github.com/apple/swift/pull/29959: AST and SIL typing rules for `inout` parameter differentiation. --- Add reverse-mode differentiation support for `apply` with `inout` arguments. Notable pullback generation changes: - If the pullback seed argument is `inout`, assign it (rather than a copy) directly as the adjoint buffer of the original result. This is important so the value is updated in-place. - In `visitApplyInst`: skip adjoint accumulation for `inout` arguments. Adjoint accumulation for `inout` arguments occurs when callee pullbacks are applied, so no extra accumulation is necessary. Add derivatives for functions with `inout` parameters in the stdlib for testing: - `FloatingPoint` operations: `+=`, `-=`, `*=`, `/=` - `Array.append` Resolves TF-1165. Todos: - Add more tests, e.g. SILGen tests for `inout` derivative typing rules. - Evaluate performance of `inout` derivatives vs functional derivatives + mutation. - TF-1166: enable `@differentiable` attribute on `set` accessors. - TF-1173: add forward-mode differentiation support for `apply` with `inout` parameters. Exposes TF-1175: incorrect activity for class arguments. Exposes TF-1176: incorrect activity for class `modify` accessors. Add negative tests.
Author
Parents
Loading