-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[AutoDiff] simplify SILGen thunking and set correct thunk linkage #28616
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
Conversation
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.
Sweet simplications!
@swift-ci please test tensorflow |
@@ -70,47 +70,6 @@ SILFunction *SILGenModule::getDynamicThunk(SILDeclRef constant, | |||
return F; | |||
} | |||
|
|||
// SWIFT_ENABLE_TENSORFLOW | |||
SILFunction * | |||
SILGenModule::getOrCreateAutoDiffDerivativeForwardingThunk( |
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.
I believe as is, getOrCreateAutoDiffDerivativeForwardingThunk
created a more efficient thunk, as it never reabstracts the returned linear map while getOrCreateCustomDerivativeThunk
always does. Not a big deal!
@swift-ci please test tensorflow |
There's a failure in |
Ping: #28621 has been merged, in case it unblocks this patch! |
Oh, it seems that I also need https://bugs.swift.org/browse/TF-1001 for the problem to go away. So I'll wait until after I do that to retest this PR. |
8949d2a
to
5f9f843
Compare
This has become unblocked. I've rebased it and will test it now. |
@swift-ci please test tensorflow |
1 similar comment
@swift-ci please test tensorflow |
@swift-ci please test tensorflow macos |
Sets the SILGen'd AD thunk linkage to the same linkage as the custom derivative that they wrap, by doing two things:
customDerivativeFn->getLinkage()
for the linkage of the AD thunk.ForDefinition
when getting the custom derivative functions. TheNotForDefinition
flag is for creating function declarations with external linkage, so if we use that thencustomDerivativeFn->getLinkage()
is an external linkage, which is not right. (This code is probably going to be deleted very soon anyways, when we forbid custom derivatives in@differentiable
attributes.)Also it was initially hard for me to figure out what was going on, so I made some simplifications:
getOrCreateAutoDiffDerivativeForwardingThunk
because we can just use the other thunking function, which has a superset of its functionality.getOrCreateAutoDiffDerivativeReabstractionThunk
->getOrCreateCustomDerivativeThunk
to clarify that it does all thunking necessary for custom derivatives, not just reabstraction.getOrCreateCustomDerivativeThunk
determine whether self needs reordering, so that the caller does not have to worry about that.