-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[AutoDiff] Serialize derivative function configurations per module. #28608
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6998,6 +6998,49 @@ StringRef AbstractFunctionDecl::getInlinableBodyText( | |
return extractInlinableText(getASTContext().SourceMgr, body, scratch); | ||
} | ||
|
||
// SWIFT_ENABLE_TENSORFLOW | ||
/// A uniqued list of derivative function configurations. | ||
struct AbstractFunctionDecl::DerivativeFunctionConfigurationList | ||
: public llvm::SetVector<AutoDiffConfig> { | ||
// Necessary for `ASTContext` allocation. | ||
void *operator new( | ||
size_t bytes, ASTContext &ctx, | ||
unsigned alignment = alignof(DerivativeFunctionConfigurationList)) { | ||
return ctx.Allocate(bytes, alignment); | ||
} | ||
}; | ||
|
||
void AbstractFunctionDecl::prepareDerivativeFunctionConfigurations() { | ||
if (DerivativeFunctionConfigs) | ||
return; | ||
auto &ctx = getASTContext(); | ||
DerivativeFunctionConfigs = new (ctx) DerivativeFunctionConfigurationList(); | ||
// Register an `ASTContext` cleanup calling the list destructor. | ||
ctx.addCleanup([this]() { | ||
this->DerivativeFunctionConfigs->~DerivativeFunctionConfigurationList(); | ||
}); | ||
} | ||
|
||
ArrayRef<AutoDiffConfig> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: even though I think the direction is to eventually plumb result indices through the differentiation system (TF-1038), so preemptively using result indices ( |
||
AbstractFunctionDecl::getDerivativeFunctionConfigurations() { | ||
prepareDerivativeFunctionConfigurations(); | ||
auto &ctx = getASTContext(); | ||
if (ctx.getCurrentGeneration() > DerivativeFunctionConfigGeneration) { | ||
unsigned previousGeneration = DerivativeFunctionConfigGeneration; | ||
DerivativeFunctionConfigGeneration = ctx.getCurrentGeneration(); | ||
ctx.loadDerivativeFunctionConfigurations(this, previousGeneration, | ||
*DerivativeFunctionConfigs); | ||
} | ||
return DerivativeFunctionConfigs->getArrayRef(); | ||
} | ||
|
||
void AbstractFunctionDecl::addDerivativeFunctionConfiguration( | ||
AutoDiffConfig config) { | ||
prepareDerivativeFunctionConfigurations(); | ||
DerivativeFunctionConfigs->insert(config); | ||
} | ||
// SWIFT_ENABLE_TENSORFLOW END | ||
|
||
FuncDecl *FuncDecl::createImpl(ASTContext &Context, | ||
SourceLoc StaticLoc, | ||
StaticSpellingKind StaticSpelling, | ||
|
Uh oh!
There was an error while loading. Please reload this page.