-
Notifications
You must be signed in to change notification settings - Fork 0
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] Buffer flatten #340
[Refactor] Buffer flatten #340
Conversation
Thanks @junrushao1994 One thing that I noticed is the change of unordered map from strong ref object to weak ref(raw ptr). We need to be careful with such a change, especially in cases where an IR object can be mutated. we need to be careful when using raw ptr in a mutator. Since the children can get de-allocated and re-allocated to another node (causing map info to be inaccurate). Prefer the strong ref version. See a related PR here apache/tvm#6004 Because of that reason, I think we could actually prefer to use strong ref version for unordered map (with ObjectPtrHash and Equal) for most of the maps of interest. The overhead of ref counting is not as large comparing to the gains. For a temporary data structure within a Visitor(that does not change the IR), we should be fine. |
@tqchen It certainly makes sense to avoid deallocation that causes hash map key to be invalid in StmtExprMutators. I wonder in which case it could happen? If we turn off the copy-on-write, I assume it would be valid during visiting. Is that correct? |
in some cases when we visit, say we want to replace a subtree A=> B, then after the replacement of the subtree A could no longer be referenced anywhere(thus de-allocated) If the same address of A get re-allocated to another node during the visit, then the information in the mutator becomes stale. I cannot tell exactly which case it happens, but it indeed casued some bugs before, thus the PR from qualcomm |
If copy-on-write is disabled, then I assume the original IR will keep valid during the visit, which means deallocation of A will be deferred until the visit is finished. Is that correct? |
You are right. In our case there is possibility of COW, so we need to watch out for that |
Got it. I am going to change those data structure outlive the mutator to hold strong references |
A second thought leads me to changing every reference in the mutator to strong ones, in case helping cow |
@Hzfengsy This PR is basically done, please take a look when you have time :-) There are two
if (need_relax || (buffer->scope == "shared" && IsThreadBound(loop))) {
// TODO
dom_map[loop_var] = IntSetFromMinExtent(loop->min, loop->extent);
}
Additionally, I handled Thank a lot! |
src/tir/transforms/buffer_flatten.cc
Outdated
} | ||
|
||
static bool IsDoubleBufferScope(const Map<String, ObjectRef>& annotations) { | ||
for (const auto& kv : annotations) { |
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.
use Map::Get
src/tir/transforms/buffer_flatten.cc
Outdated
for (const auto& kv : annotations) { | ||
const String& ann_key = kv.first; | ||
const ObjectRef& ann_value = kv.second; | ||
if (ann_key != attr::double_buffer_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.
should be ==
?
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.
ooops
No description provided.