Skip to content

[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

Merged
merged 1 commit into from
Jan 10, 2020

Conversation

marcrasi
Copy link

@marcrasi marcrasi commented Dec 6, 2019

Sets the SILGen'd AD thunk linkage to the same linkage as the custom derivative that they wrap, by doing two things:

  • Use customDerivativeFn->getLinkage() for the linkage of the AD thunk.
  • Use ForDefinition when getting the custom derivative functions. The NotForDefinition flag is for creating function declarations with external linkage, so if we use that then customDerivativeFn->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:

  • Delete getOrCreateAutoDiffDerivativeForwardingThunk because we can just use the other thunking function, which has a superset of its functionality.
  • Rename getOrCreateAutoDiffDerivativeReabstractionThunk -> getOrCreateCustomDerivativeThunk to clarify that it does all thunking necessary for custom derivatives, not just reabstraction.
  • Make getOrCreateCustomDerivativeThunk determine whether self needs reordering, so that the caller does not have to worry about that.

@marcrasi marcrasi requested review from rxwei and dan-zheng December 6, 2019 18:53
Copy link
Contributor

@dan-zheng dan-zheng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sweet simplications!

@marcrasi
Copy link
Author

marcrasi commented Dec 6, 2019

@swift-ci please test tensorflow

@@ -70,47 +70,6 @@ SILFunction *SILGenModule::getDynamicThunk(SILDeclRef constant,
return F;
}

// SWIFT_ENABLE_TENSORFLOW
SILFunction *
SILGenModule::getOrCreateAutoDiffDerivativeForwardingThunk(
Copy link
Contributor

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!

@marcrasi
Copy link
Author

marcrasi commented Dec 6, 2019

@swift-ci please test tensorflow

@marcrasi
Copy link
Author

marcrasi commented Dec 7, 2019

There's a failure in validation-test/ParseableInterface/verify_all_overlays.py. I think it's because my ForDefinition change is not quite right in certain cases involving .swiftinterface files. #28621 should make this problem go away, so I'll just wait until that gets merged and then retest this.

@dan-zheng
Copy link
Contributor

Ping: #28621 has been merged, in case it unblocks this patch!

@marcrasi
Copy link
Author

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.

@marcrasi marcrasi force-pushed the marcrasi-fix-ad-thunk-linkage branch from 8949d2a to 5f9f843 Compare January 9, 2020 21:45
@marcrasi
Copy link
Author

marcrasi commented Jan 9, 2020

This has become unblocked. I've rebased it and will test it now.

@marcrasi
Copy link
Author

marcrasi commented Jan 9, 2020

@swift-ci please test tensorflow

1 similar comment
@marcrasi
Copy link
Author

marcrasi commented Jan 9, 2020

@swift-ci please test tensorflow

@marcrasi
Copy link
Author

marcrasi commented Jan 9, 2020

@swift-ci please test tensorflow macos

@marcrasi marcrasi merged commit 64dd82a into tensorflow Jan 10, 2020
@marcrasi marcrasi deleted the marcrasi-fix-ad-thunk-linkage branch January 10, 2020 00:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants