-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
[refactor] Remove the global begin_stmt and end_stmt #1034
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.
LGTM + nits :)
std::unordered_map<Stmt *, Stmt *> stmt_to_offloaded) | ||
const std::unordered_map<Stmt *, Stmt *> &stmt_to_offloaded, |
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.
Any reason why const &
here?
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.
Good point. If you look at the entire call stack, it was like:
offload()
\- FixCrossOffloadReferences::run()
\- FixCrossOffloadReferences::FixCrossOffloadReferences()
Before this PR, only the last call used move
, while the first two didn't (likely because we forgot to), so we still made two unnecessary copies. While move is a modern feature, IMO the easiest way to avoid copy remains using const &
. (move
also means transferring ownership, which is really useful when data cannot be copy constructed, e.g. std::unique_ptr
). Does this make sense?
taichi/transforms/offload.cpp
Outdated
@@ -14,20 +14,18 @@ namespace { | |||
// Offloaded local variables to its offset in the global tmps memory. | |||
using StmtToOffsetMap = std::unordered_map<const Stmt *, std::size_t>; | |||
|
|||
std::unique_ptr<std::unordered_map<OffloadedStmt *, Stmt *>> begin_stmt, | |||
end_stmt; | |||
struct OffloadedToBeginEndStmts { |
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.
Name nit: why to
?
struct OffloadedToBeginEndStmts { | |
struct OffloadedRanges { |
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.
Nice! Since many places need to be changed, I will make the change locally.
taichi/transforms/offload.cpp
Outdated
@@ -77,9 +77,11 @@ class Offloader { | |||
} | |||
} | |||
assemble_serial_statements(); | |||
return offloaded_to_begin_end; |
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.
return offloaded_to_begin_end; | |
return offloaded_ranges; |
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.
Ditto
@archibate If you do approve, could you hit the Approve button? |
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.
LGTMig, hitting Approve
button :)
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 in general but I wonder why OffloadedRanges *const offloaded_ranges_;
is used rather than const OffloadedRanges &offloaded_ranges_;
-- I think it's better to use a const reference if we don't modify it.
It's because we do need the non-const value of the hash maps in taichi/taichi/transforms/offload.cpp Line 223 in 28ae40c
BTW it seems that |
I see. So if BTW is there any advantage of |
Yes, see find. There are two overloads on it, based on the constness of
Yes, since |
"One less global variable is a bit less evil in the world." -- Nobody 233 B.C.
As part of the refactor, I also:
const &
to a fewstmt_to_offloaded
maps.Related issue = N/A
WANT_LGTM = any
[Click here for the format server]