-
Notifications
You must be signed in to change notification settings - Fork 129
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
Use move semantics to push objects on tapes #1249
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.
clang-tidy made some suggestions
assert(E && "must be provided"); | ||
E = E->IgnoreImplicit(); | ||
if (type.isNull()) | ||
type = E->getType(); | ||
QualType TapeType = |
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.
warning: misleading indentation: statement is indented too deeply [readability-misleading-indentation]
QualType TapeType =
^
Additional context
lib/Differentiator/ReverseModeVisitor.cpp:97: did you mean this line to be inside this 'if'
if (type.isNull())
^
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.
@vgvassilev Is it broken or am I not seeing something?
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 think the problem is the indentation of the entire function.
This commit introduces move semantics to ``clad::pop`` and, where possible, ``clad::push``. The latter is done when local variables inside loops get promoted to the function scope, e.g. ``` while (cond) { some_type x = init; ... } ``` In the reverse mode, it becomes ``` some_type x; while (cond) { clad::push(_tape, x), x = init; // the value will be usefull in the reverse pass, we need to store it ... } ``` In such cases, the commit introduces ``std::move``: ``` some_type x; while (cond) { clad::push(_tape, std::move(x)), x = init; // the value is stored right before it's overwritten so we can move it ... } ``` This is useful for 2 reasons: 1) Moving objects is move efficient than copying. 2) This way, we can expect the underlying data (e.g. of stl containers) to stay at the same memory location in the reverse pass.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #1249 +/- ##
=======================================
Coverage 94.66% 94.66%
=======================================
Files 51 51
Lines 8903 8910 +7
=======================================
+ Hits 8428 8435 +7
Misses 475 475
|
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!
assert(E && "must be provided"); | ||
E = E->IgnoreImplicit(); | ||
if (type.isNull()) | ||
type = E->getType(); | ||
QualType TapeType = |
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 think the problem is the indentation of the entire function.
This PR introduces move semantics to
clad::pop
and, where possible,clad::push
. The latter is done when local variables inside loops get promoted to the function scope, e.g.In the reverse mode, it becomes
In such cases, the PR introduces
std::move
:This is useful for 2 reasons:
This PR is opened to make #1247 smaller.