-
Notifications
You must be signed in to change notification settings - Fork 125
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
Make built-in type variable declarations global #738
Conversation
clang-tidy review says "All clean, LGTM! 👍" |
6da2b92
to
f4f8b5d
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #738 +/- ##
==========================================
+ Coverage 94.60% 94.63% +0.03%
==========================================
Files 49 49
Lines 7190 7201 +11
==========================================
+ Hits 6802 6815 +13
+ Misses 388 386 -2
|
clang-tidy review says "All clean, LGTM! 👍" |
Why do we need both this pull request and #688? |
f4f8b5d
to
b1b24a2
Compare
clang-tidy review says "All clean, LGTM! 👍" |
b1b24a2
to
7ebcff1
Compare
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.
clang-tidy made some suggestions
7ebcff1
to
2776e59
Compare
03efa6b
to
9fa1bf8
Compare
9642d20
to
ce70387
Compare
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.
Glad to see moving! Here is a round of comments.
@@ -2530,19 +2516,26 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context, | |||
VarDeclDiff ReverseModeVisitor::DifferentiateVarDecl(const VarDecl* VD) { | |||
StmtDiff initDiff; | |||
Expr* VDDerivedInit = nullptr; | |||
// We take the parent of the current scope because the main compound | |||
// statement of the function has its own scope as well. | |||
bool isInFunctionGlobalScope = getCurrentScope()->getParent()==m_DerivativeFnScope; |
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.
bool isInFunctionGlobalScope = getCurrentScope()->getParent()==m_DerivativeFnScope; | |
bool isFunctionScope = getCurrentScope()->isFunctionScope(); |
Any clue why that does not work?
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.
Because the outermost compound statement is not considered function scope.
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 made the outermost compound statement FnScope so now this option works. I did this in my last commit.
@@ -2530,19 +2516,26 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context, | |||
VarDeclDiff ReverseModeVisitor::DifferentiateVarDecl(const VarDecl* VD) { | |||
StmtDiff initDiff; | |||
Expr* VDDerivedInit = nullptr; | |||
// We take the parent of the current scope because the main compound |
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.
If getCurrentScope()->isFunctionScope()
is false for int f() {
this probably means that when we create the scope for the first compound statement of the function we should also add the Scope::FnScope
flag to the current scope.
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 a good idea. I did this in my last commit. Thank you for pointing this out.
@@ -2752,6 +2725,9 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context, | |||
llvm::SmallVector<Decl*, 4> declsDiff; | |||
// Need to put array decls inlined. | |||
llvm::SmallVector<Decl*, 4> localDeclsDiff; | |||
// We take the parent of the current scope because the main compound | |||
// statement of the function has its own scope as well. | |||
bool isInFunctionGlobalScope = getCurrentScope()->getParent()==m_DerivativeFnScope; |
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.
See past comments.
clang-tidy review says "All clean, LGTM! 👍" |
3 similar comments
clang-tidy review says "All clean, LGTM! 👍" |
clang-tidy review says "All clean, LGTM! 👍" |
clang-tidy review says "All clean, LGTM! 👍" |
clang-tidy review says "All clean, LGTM! 👍" |
1 similar comment
clang-tidy review says "All clean, LGTM! 👍" |
When we produce a gradient function we generally have a forward and reverse sweep. In the forward sweep we accumulate the state and in the reverse sweep we use that state to invert the program execution. The forward sweep generally follows the sematics of the primal function and when neccessary stores the state which would be needed but lost for the reverse sweep. However, to minimize the stores onto the tape we need to reuse some of the variables between the forward and the reverse sweeps which requires some variables to be promoted to the enclosing lexical scope of both sweeps. Fixes vgvassilev#659, fixes vgvassilev#681.
e46cbef
to
d225ab6
Compare
clang-tidy review says "All clean, LGTM! 👍" |
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.
LGTM! Good job!
When we produce a gradient function we generally have a forward and reverse
sweep. In the forward sweep we accumulate the state and in the reverse sweep
we use that state to invert the program execution. The forward sweep generally
follows the sematics of the primal function and when neccessary stores the state
which would be needed but lost for the reverse sweep.
However, to minimize the stores onto the tape we need to reuse some of the
variables between the forward and the reverse sweeps which requires some
variables to be promoted to the enclosing lexical scope of both sweeps.
Fixes #659, fixes #681.