-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[AutoDiff] Start supporting loadable types with address-only tangents. #32540
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
[AutoDiff] Start supporting loadable types with address-only tangents. #32540
Conversation
Previously, PullbackEmitter assumed that original values' value category matches their `TangentVector` types' value category. This was problematic for loadable types with address-only `TangentVector` types. Now, PullbackEmitter starts to support differentiation of loadable types with address-only `TangentVector` types. This patch focuses on supporting and testing class types, more support can be added incrementally. Resolves TF-1149.
@swift-ci Please smoke test |
@@ -178,6 +178,21 @@ Optional<TangentSpace> PullbackEmitter::getTangentSpace(CanType type) { | |||
LookUpConformanceInModule(getModule().getSwiftModule())); | |||
} | |||
|
|||
SILValueCategory PullbackEmitter::getTangentValueCategory(SILValue v) { | |||
// Quick check: if the value has an address type, the tangent value category |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not always true. Address only original types can totally have an non-address-only tangent, simplest example:
struct Foo<T>: Differentiable {
var a: Float
@noDerivative var b: T
}
Could you add a FIXME here with an appropriate bug number?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Address only original types can totally have an non-address-only tangent
This case is actually currently supported today. The differentiation transform always creates adjoint buffers for address-typed original values, regardless of whether the tangent type is loadable or address-only.
Offline, you pointed out that we should make "tangent value category" depend solely on whether the tangent type is loadable or address-only. For loadable tangent types, using symbolic adjoint values instead of concrete adjoint buffers would be more efficient.
I filed SR-13077 to track this improvement and left a comment in the code.
Clarify `PullbackEmitter::getTangentValueCategory`.
@swift-ci Please smoke test |
Previously,
PullbackEmitter
assumed that original values' value categorymatches their
TangentVector
types' value category. This was problematicfor loadable types with address-only
TangentVector
types.Now,
PullbackEmitter
starts to support differentiation of loadable types withaddress-only
TangentVector
types. This patch focuses on supporting and testingclass types, more support can be added incrementally.
Resolves TF-1149.
Unblocks future
_Differentiation
module changes like TF-1267.Example:
Before: cryptic error due to artificial limitations (lack of compiler support).
After: no error.