You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by GitBox <gi...@apache.org> on 2022/04/08 14:49:58 UTC
[GitHub] [tvm] Lunderberg opened a new pull request, #10940: [Draft][TIR] Remove PrimFuncNode::preflattened_buffer_map
Lunderberg opened a new pull request, #10940:
URL: https://github.com/apache/tvm/pull/10940
`PrimFuncNode::preflattened_buffer_map` was introduced in https://github.com/apache/tvm/pull/9727, in order to maintain a record of the pre-flattened buffer shape until it can be used in `MakePackedAPI`. This commit instead maintains the pre-flattened shapes in `PrimFuncNode::buffer_map`, while the body of the function uses a flattened buffer alias.
Passes LLVM tests in test_target_codegen_llvm.py as initial proof of concept.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] Lunderberg commented on pull request #10940: [Draft][TIR] Remove PrimFuncNode::preflattened_buffer_map
Posted by GitBox <gi...@apache.org>.
Lunderberg commented on PR #10940:
URL: https://github.com/apache/tvm/pull/10940#issuecomment-1127707395
Rebased to resolve merge conflict, expecting same breakage in the ethos-u unit tests.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] Lunderberg commented on pull request #10940: [Draft][TIR] Remove PrimFuncNode::preflattened_buffer_map
Posted by GitBox <gi...@apache.org>.
Lunderberg commented on PR #10940:
URL: https://github.com/apache/tvm/pull/10940#issuecomment-1310828878
@vinx13 This PR removes the `preflattened_buffer_map`, using buffer aliases instead, as described in your [RFC#70](https://github.com/apache/tvm-rfcs/pull/70).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] kparzysz-quic commented on a diff in pull request #10940: [TIR] Remove PrimFuncNode::preflattened_buffer_map
Posted by GitBox <gi...@apache.org>.
kparzysz-quic commented on code in PR #10940:
URL: https://github.com/apache/tvm/pull/10940#discussion_r1038321051
##########
src/tir/transforms/storage_flatten.cc:
##########
@@ -1160,18 +1144,70 @@ class BufferBindUnwrapper : public StmtExprMutator {
};
const BufferEntry& GetBufferEntry(Buffer buffer) {
- auto alloc_key = buffer->data.get();
- if (!buf_map_.count(buffer.get()) && buffer_var_defines_.count(alloc_key)) {
+ if (buf_map_.count(buffer.get())) {
+ const BufferEntry& e = buf_map_[buffer.get()];
+ ICHECK(e.in_scope) << "Cannot access a buffer " << buffer->name << ", out of scope";
+ return e;
+ } else if (buffer_var_defines_.count(buffer->data.get())) {
+ // The buffer var was defined, but the buffer hasn't been seen
+ // before.
BufferEntry entry;
entry.buffer = buffer;
+ var_to_buffer_[buffer->data.get()] = buffer;
buf_map_[buffer.get()] = std::move(entry);
- }
+ return buf_map_[buffer.get()];
+ } else if (var_remap_.count(buffer->data.get())) {
+ // The buffer var is an alias of a bound buffer. Only
+ // supported if the bound buffer has no offsets. In this
+ // case, we just need to make a new aliasing buffer that
+ // shares the remapped data variable.
+ Var old_var = buffer->data;
+ Var new_var = Downcast<Var>(var_remap_[old_var.get()]);
- auto it = buf_map_.find(buffer.get());
- ICHECK(it != buf_map_.end()) << "Cannot find allocated buffer for " << buffer;
- const BufferEntry& e = it->second;
- ICHECK(e.in_scope) << "Cannot access a buffer " << buffer->name << ", out of scope";
- return it->second;
+ {
+ ICHECK(var_to_buffer_.count(old_var.get()))
+ << "Cannot find remap information for aliased buffer var " << old_var->name_hint
+ << ", required to verify this alias is legal.";
+ const Buffer& aliased_buffer = var_to_buffer_[old_var.get()];
+ const BufferEntry& entry = buf_map_[aliased_buffer.get()];
+ if (entry.remap) {
+ for (const auto& begin : entry.remap->begins) {
+ ICHECK(is_zero(begin)) << "Aliasing of buffer with offset is not supported";
+ }
+ }
+ }
+
+ {
+ Buffer new_buf = buffer;
+ new_buf.CopyOnWrite()->data = new_var;
+
+ RemapInfo remap_info;
+ remap_info.target = new_buf;
+ remap_info.begins = Array<PrimExpr>(buffer->shape.size(), 0);
+ remap_info.extents = buffer->shape;
+
+ BufferEntry entry;
+ entry.buffer = buffer;
+ entry.remap = std::make_unique<RemapInfo>(remap_info);
+ entry.in_scope = true;
+ var_to_buffer_[buffer->data.get()] = buffer;
+ buf_map_[buffer.get()] = std::move(entry);
+ }
+ return buf_map_[buffer.get()];
+ } else if (var_to_buffer_.count(buffer->data.get())) {
+ // This buffer is an alias of a known buffer, with no remaps. A
+ // buffer entry should be generated and returned.
+ BufferEntry entry;
+ entry.buffer = buffer;
+ entry.in_scope = true;
+ var_to_buffer_[buffer->data.get()] = buffer;
+ buf_map_[buffer.get()] = std::move(entry);
+
+ return buf_map_[buffer.get()];
+ } else {
+ LOG(FATAL) << "Can't work around the undefined buffer";
+ return *static_cast<BufferEntry*>(nullptr);
Review Comment:
This is not good, please use `__builtin_unreachable()` or something like that...
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] Lunderberg commented on pull request #10940: [Draft][TIR] Remove PrimFuncNode::preflattened_buffer_map
Posted by GitBox <gi...@apache.org>.
Lunderberg commented on PR #10940:
URL: https://github.com/apache/tvm/pull/10940#issuecomment-1092947073
This change still requires an RFC for discussion, but is here as a proof of concept.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] Lunderberg commented on a diff in pull request #10940: [TIR] Remove PrimFuncNode::preflattened_buffer_map
Posted by GitBox <gi...@apache.org>.
Lunderberg commented on code in PR #10940:
URL: https://github.com/apache/tvm/pull/10940#discussion_r1038517978
##########
src/tir/transforms/storage_flatten.cc:
##########
@@ -1160,18 +1144,70 @@ class BufferBindUnwrapper : public StmtExprMutator {
};
const BufferEntry& GetBufferEntry(Buffer buffer) {
- auto alloc_key = buffer->data.get();
- if (!buf_map_.count(buffer.get()) && buffer_var_defines_.count(alloc_key)) {
+ if (buf_map_.count(buffer.get())) {
+ const BufferEntry& e = buf_map_[buffer.get()];
+ ICHECK(e.in_scope) << "Cannot access a buffer " << buffer->name << ", out of scope";
+ return e;
+ } else if (buffer_var_defines_.count(buffer->data.get())) {
+ // The buffer var was defined, but the buffer hasn't been seen
+ // before.
BufferEntry entry;
entry.buffer = buffer;
+ var_to_buffer_[buffer->data.get()] = buffer;
buf_map_[buffer.get()] = std::move(entry);
- }
+ return buf_map_[buffer.get()];
+ } else if (var_remap_.count(buffer->data.get())) {
+ // The buffer var is an alias of a bound buffer. Only
+ // supported if the bound buffer has no offsets. In this
+ // case, we just need to make a new aliasing buffer that
+ // shares the remapped data variable.
+ Var old_var = buffer->data;
+ Var new_var = Downcast<Var>(var_remap_[old_var.get()]);
- auto it = buf_map_.find(buffer.get());
- ICHECK(it != buf_map_.end()) << "Cannot find allocated buffer for " << buffer;
- const BufferEntry& e = it->second;
- ICHECK(e.in_scope) << "Cannot access a buffer " << buffer->name << ", out of scope";
- return it->second;
+ {
+ ICHECK(var_to_buffer_.count(old_var.get()))
+ << "Cannot find remap information for aliased buffer var " << old_var->name_hint
+ << ", required to verify this alias is legal.";
+ const Buffer& aliased_buffer = var_to_buffer_[old_var.get()];
+ const BufferEntry& entry = buf_map_[aliased_buffer.get()];
+ if (entry.remap) {
+ for (const auto& begin : entry.remap->begins) {
+ ICHECK(is_zero(begin)) << "Aliasing of buffer with offset is not supported";
+ }
+ }
+ }
+
+ {
+ Buffer new_buf = buffer;
+ new_buf.CopyOnWrite()->data = new_var;
+
+ RemapInfo remap_info;
+ remap_info.target = new_buf;
+ remap_info.begins = Array<PrimExpr>(buffer->shape.size(), 0);
+ remap_info.extents = buffer->shape;
+
+ BufferEntry entry;
+ entry.buffer = buffer;
+ entry.remap = std::make_unique<RemapInfo>(remap_info);
+ entry.in_scope = true;
+ var_to_buffer_[buffer->data.get()] = buffer;
+ buf_map_[buffer.get()] = std::move(entry);
+ }
+ return buf_map_[buffer.get()];
+ } else if (var_to_buffer_.count(buffer->data.get())) {
+ // This buffer is an alias of a known buffer, with no remaps. A
+ // buffer entry should be generated and returned.
+ BufferEntry entry;
+ entry.buffer = buffer;
+ entry.in_scope = true;
+ var_to_buffer_[buffer->data.get()] = buffer;
+ buf_map_[buffer.get()] = std::move(entry);
+
+ return buf_map_[buffer.get()];
+ } else {
+ LOG(FATAL) << "Can't work around the undefined buffer";
+ return *static_cast<BufferEntry*>(nullptr);
Review Comment:
I've opened https://github.com/apache/tvm/pull/13542, which removes this line entirely, with the `[[noreturn]]` attribute applied to both implementations of `LOG(FATAL)` so that the warning does not occur.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] Lunderberg commented on a diff in pull request #10940: [TIR] Remove PrimFuncNode::preflattened_buffer_map
Posted by GitBox <gi...@apache.org>.
Lunderberg commented on code in PR #10940:
URL: https://github.com/apache/tvm/pull/10940#discussion_r1038507234
##########
src/tir/transforms/storage_flatten.cc:
##########
@@ -1160,18 +1144,70 @@ class BufferBindUnwrapper : public StmtExprMutator {
};
const BufferEntry& GetBufferEntry(Buffer buffer) {
- auto alloc_key = buffer->data.get();
- if (!buf_map_.count(buffer.get()) && buffer_var_defines_.count(alloc_key)) {
+ if (buf_map_.count(buffer.get())) {
+ const BufferEntry& e = buf_map_[buffer.get()];
+ ICHECK(e.in_scope) << "Cannot access a buffer " << buffer->name << ", out of scope";
+ return e;
+ } else if (buffer_var_defines_.count(buffer->data.get())) {
+ // The buffer var was defined, but the buffer hasn't been seen
+ // before.
BufferEntry entry;
entry.buffer = buffer;
+ var_to_buffer_[buffer->data.get()] = buffer;
buf_map_[buffer.get()] = std::move(entry);
- }
+ return buf_map_[buffer.get()];
+ } else if (var_remap_.count(buffer->data.get())) {
+ // The buffer var is an alias of a bound buffer. Only
+ // supported if the bound buffer has no offsets. In this
+ // case, we just need to make a new aliasing buffer that
+ // shares the remapped data variable.
+ Var old_var = buffer->data;
+ Var new_var = Downcast<Var>(var_remap_[old_var.get()]);
- auto it = buf_map_.find(buffer.get());
- ICHECK(it != buf_map_.end()) << "Cannot find allocated buffer for " << buffer;
- const BufferEntry& e = it->second;
- ICHECK(e.in_scope) << "Cannot access a buffer " << buffer->name << ", out of scope";
- return it->second;
+ {
+ ICHECK(var_to_buffer_.count(old_var.get()))
+ << "Cannot find remap information for aliased buffer var " << old_var->name_hint
+ << ", required to verify this alias is legal.";
+ const Buffer& aliased_buffer = var_to_buffer_[old_var.get()];
+ const BufferEntry& entry = buf_map_[aliased_buffer.get()];
+ if (entry.remap) {
+ for (const auto& begin : entry.remap->begins) {
+ ICHECK(is_zero(begin)) << "Aliasing of buffer with offset is not supported";
+ }
+ }
+ }
+
+ {
+ Buffer new_buf = buffer;
+ new_buf.CopyOnWrite()->data = new_var;
+
+ RemapInfo remap_info;
+ remap_info.target = new_buf;
+ remap_info.begins = Array<PrimExpr>(buffer->shape.size(), 0);
+ remap_info.extents = buffer->shape;
+
+ BufferEntry entry;
+ entry.buffer = buffer;
+ entry.remap = std::make_unique<RemapInfo>(remap_info);
+ entry.in_scope = true;
+ var_to_buffer_[buffer->data.get()] = buffer;
+ buf_map_[buffer.get()] = std::move(entry);
+ }
+ return buf_map_[buffer.get()];
+ } else if (var_to_buffer_.count(buffer->data.get())) {
+ // This buffer is an alias of a known buffer, with no remaps. A
+ // buffer entry should be generated and returned.
+ BufferEntry entry;
+ entry.buffer = buffer;
+ entry.in_scope = true;
+ var_to_buffer_[buffer->data.get()] = buffer;
+ buf_map_[buffer.get()] = std::move(entry);
+
+ return buf_map_[buffer.get()];
+ } else {
+ LOG(FATAL) << "Can't work around the undefined buffer";
+ return *static_cast<BufferEntry*>(nullptr);
Review Comment:
Given that the effect of control flow reaching `__builtin_unreachable()` is to make the program behavior undefined, I had assumed that intentionally invoking undefined behavior in an unreachable location would be identical to `__builtin_unreachable()`, without relying on non-standard intrinsics. The C++23 implementation of `std::unreachable()` has the same semantics, that program behavior is undefined if the unreachable location is reached.
That said, this pattern is primarily to suppress the warning that occurs if a return value isn't in a branch, and isn't the most readable. Testing, it looks like a much better way to suppress the warning would be to mark `LOG(FATAL)` as `[[noreturn]]`, so that the warning never needs to be suppressed in the first place.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] kparzysz-quic commented on a diff in pull request #10940: [TIR] Remove PrimFuncNode::preflattened_buffer_map
Posted by GitBox <gi...@apache.org>.
kparzysz-quic commented on code in PR #10940:
URL: https://github.com/apache/tvm/pull/10940#discussion_r1038512241
##########
src/tir/transforms/storage_flatten.cc:
##########
@@ -1160,18 +1144,70 @@ class BufferBindUnwrapper : public StmtExprMutator {
};
const BufferEntry& GetBufferEntry(Buffer buffer) {
- auto alloc_key = buffer->data.get();
- if (!buf_map_.count(buffer.get()) && buffer_var_defines_.count(alloc_key)) {
+ if (buf_map_.count(buffer.get())) {
+ const BufferEntry& e = buf_map_[buffer.get()];
+ ICHECK(e.in_scope) << "Cannot access a buffer " << buffer->name << ", out of scope";
+ return e;
+ } else if (buffer_var_defines_.count(buffer->data.get())) {
+ // The buffer var was defined, but the buffer hasn't been seen
+ // before.
BufferEntry entry;
entry.buffer = buffer;
+ var_to_buffer_[buffer->data.get()] = buffer;
buf_map_[buffer.get()] = std::move(entry);
- }
+ return buf_map_[buffer.get()];
+ } else if (var_remap_.count(buffer->data.get())) {
+ // The buffer var is an alias of a bound buffer. Only
+ // supported if the bound buffer has no offsets. In this
+ // case, we just need to make a new aliasing buffer that
+ // shares the remapped data variable.
+ Var old_var = buffer->data;
+ Var new_var = Downcast<Var>(var_remap_[old_var.get()]);
- auto it = buf_map_.find(buffer.get());
- ICHECK(it != buf_map_.end()) << "Cannot find allocated buffer for " << buffer;
- const BufferEntry& e = it->second;
- ICHECK(e.in_scope) << "Cannot access a buffer " << buffer->name << ", out of scope";
- return it->second;
+ {
+ ICHECK(var_to_buffer_.count(old_var.get()))
+ << "Cannot find remap information for aliased buffer var " << old_var->name_hint
+ << ", required to verify this alias is legal.";
+ const Buffer& aliased_buffer = var_to_buffer_[old_var.get()];
+ const BufferEntry& entry = buf_map_[aliased_buffer.get()];
+ if (entry.remap) {
+ for (const auto& begin : entry.remap->begins) {
+ ICHECK(is_zero(begin)) << "Aliasing of buffer with offset is not supported";
+ }
+ }
+ }
+
+ {
+ Buffer new_buf = buffer;
+ new_buf.CopyOnWrite()->data = new_var;
+
+ RemapInfo remap_info;
+ remap_info.target = new_buf;
+ remap_info.begins = Array<PrimExpr>(buffer->shape.size(), 0);
+ remap_info.extents = buffer->shape;
+
+ BufferEntry entry;
+ entry.buffer = buffer;
+ entry.remap = std::make_unique<RemapInfo>(remap_info);
+ entry.in_scope = true;
+ var_to_buffer_[buffer->data.get()] = buffer;
+ buf_map_[buffer.get()] = std::move(entry);
+ }
+ return buf_map_[buffer.get()];
+ } else if (var_to_buffer_.count(buffer->data.get())) {
+ // This buffer is an alias of a known buffer, with no remaps. A
+ // buffer entry should be generated and returned.
+ BufferEntry entry;
+ entry.buffer = buffer;
+ entry.in_scope = true;
+ var_to_buffer_[buffer->data.get()] = buffer;
+ buf_map_[buffer.get()] = std::move(entry);
+
+ return buf_map_[buffer.get()];
+ } else {
+ LOG(FATAL) << "Can't work around the undefined buffer";
+ return *static_cast<BufferEntry*>(nullptr);
Review Comment:
`LOG(FATAL)` should already be `[[noreturn]]`, (this has come up before). Clang 14 warns about the "reference to null", so this actually generates a warning for me. No matter what, as it is here, this is an explicit UB.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] tvm-bot commented on pull request #10940: [Draft][TIR] Remove PrimFuncNode::preflattened_buffer_map
Posted by GitBox <gi...@apache.org>.
tvm-bot commented on PR #10940:
URL: https://github.com/apache/tvm/pull/10940#issuecomment-1310800069
<!---bot-comment-->
Thanks for contributing to TVM! Please refer to the contributing guidelines https://tvm.apache.org/docs/contribute/ for useful information and tips. Please request code reviews from [Reviewers](https://github.com/apache/incubator-tvm/blob/master/CONTRIBUTORS.md#reviewers) by @-ing them in a comment.
<!--bot-comment-docs-start-->
* Built docs for commit de1d5fefa73145010b39e2d9c271a20849396898 can be found [here](https://pr-docs.tlcpack.ai/PR-10940/20/docs/index.html).<!--bot-comment-docs-end-->
<sub>Generated by [tvm-bot](https://github.com/apache/tvm/blob/main/ci/README.md#github-actions)</sub>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] Lunderberg commented on a diff in pull request #10940: [TIR] Remove PrimFuncNode::preflattened_buffer_map
Posted by GitBox <gi...@apache.org>.
Lunderberg commented on code in PR #10940:
URL: https://github.com/apache/tvm/pull/10940#discussion_r1038515838
##########
src/tir/transforms/storage_flatten.cc:
##########
@@ -1160,18 +1144,70 @@ class BufferBindUnwrapper : public StmtExprMutator {
};
const BufferEntry& GetBufferEntry(Buffer buffer) {
- auto alloc_key = buffer->data.get();
- if (!buf_map_.count(buffer.get()) && buffer_var_defines_.count(alloc_key)) {
+ if (buf_map_.count(buffer.get())) {
+ const BufferEntry& e = buf_map_[buffer.get()];
+ ICHECK(e.in_scope) << "Cannot access a buffer " << buffer->name << ", out of scope";
+ return e;
+ } else if (buffer_var_defines_.count(buffer->data.get())) {
+ // The buffer var was defined, but the buffer hasn't been seen
+ // before.
BufferEntry entry;
entry.buffer = buffer;
+ var_to_buffer_[buffer->data.get()] = buffer;
buf_map_[buffer.get()] = std::move(entry);
- }
+ return buf_map_[buffer.get()];
+ } else if (var_remap_.count(buffer->data.get())) {
+ // The buffer var is an alias of a bound buffer. Only
+ // supported if the bound buffer has no offsets. In this
+ // case, we just need to make a new aliasing buffer that
+ // shares the remapped data variable.
+ Var old_var = buffer->data;
+ Var new_var = Downcast<Var>(var_remap_[old_var.get()]);
- auto it = buf_map_.find(buffer.get());
- ICHECK(it != buf_map_.end()) << "Cannot find allocated buffer for " << buffer;
- const BufferEntry& e = it->second;
- ICHECK(e.in_scope) << "Cannot access a buffer " << buffer->name << ", out of scope";
- return it->second;
+ {
+ ICHECK(var_to_buffer_.count(old_var.get()))
+ << "Cannot find remap information for aliased buffer var " << old_var->name_hint
+ << ", required to verify this alias is legal.";
+ const Buffer& aliased_buffer = var_to_buffer_[old_var.get()];
+ const BufferEntry& entry = buf_map_[aliased_buffer.get()];
+ if (entry.remap) {
+ for (const auto& begin : entry.remap->begins) {
+ ICHECK(is_zero(begin)) << "Aliasing of buffer with offset is not supported";
+ }
+ }
+ }
+
+ {
+ Buffer new_buf = buffer;
+ new_buf.CopyOnWrite()->data = new_var;
+
+ RemapInfo remap_info;
+ remap_info.target = new_buf;
+ remap_info.begins = Array<PrimExpr>(buffer->shape.size(), 0);
+ remap_info.extents = buffer->shape;
+
+ BufferEntry entry;
+ entry.buffer = buffer;
+ entry.remap = std::make_unique<RemapInfo>(remap_info);
+ entry.in_scope = true;
+ var_to_buffer_[buffer->data.get()] = buffer;
+ buf_map_[buffer.get()] = std::move(entry);
+ }
+ return buf_map_[buffer.get()];
+ } else if (var_to_buffer_.count(buffer->data.get())) {
+ // This buffer is an alias of a known buffer, with no remaps. A
+ // buffer entry should be generated and returned.
+ BufferEntry entry;
+ entry.buffer = buffer;
+ entry.in_scope = true;
+ var_to_buffer_[buffer->data.get()] = buffer;
+ buf_map_[buffer.get()] = std::move(entry);
+
+ return buf_map_[buffer.get()];
+ } else {
+ LOG(FATAL) << "Can't work around the undefined buffer";
+ return *static_cast<BufferEntry*>(nullptr);
Review Comment:
Looks like there were two independent `LOG(FATAL)` implementations, and only the one that occurred when `TVM_LOG_CUSTOMIZE` was defined has `[[noreturn]]` applied to it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] Lunderberg commented on a diff in pull request #10940: [TIR] Remove PrimFuncNode::preflattened_buffer_map
Posted by GitBox <gi...@apache.org>.
Lunderberg commented on code in PR #10940:
URL: https://github.com/apache/tvm/pull/10940#discussion_r1038517488
##########
src/tir/transforms/storage_flatten.cc:
##########
@@ -1160,18 +1144,70 @@ class BufferBindUnwrapper : public StmtExprMutator {
};
const BufferEntry& GetBufferEntry(Buffer buffer) {
- auto alloc_key = buffer->data.get();
- if (!buf_map_.count(buffer.get()) && buffer_var_defines_.count(alloc_key)) {
+ if (buf_map_.count(buffer.get())) {
+ const BufferEntry& e = buf_map_[buffer.get()];
+ ICHECK(e.in_scope) << "Cannot access a buffer " << buffer->name << ", out of scope";
+ return e;
+ } else if (buffer_var_defines_.count(buffer->data.get())) {
+ // The buffer var was defined, but the buffer hasn't been seen
+ // before.
BufferEntry entry;
entry.buffer = buffer;
+ var_to_buffer_[buffer->data.get()] = buffer;
buf_map_[buffer.get()] = std::move(entry);
- }
+ return buf_map_[buffer.get()];
+ } else if (var_remap_.count(buffer->data.get())) {
+ // The buffer var is an alias of a bound buffer. Only
+ // supported if the bound buffer has no offsets. In this
+ // case, we just need to make a new aliasing buffer that
+ // shares the remapped data variable.
+ Var old_var = buffer->data;
+ Var new_var = Downcast<Var>(var_remap_[old_var.get()]);
- auto it = buf_map_.find(buffer.get());
- ICHECK(it != buf_map_.end()) << "Cannot find allocated buffer for " << buffer;
- const BufferEntry& e = it->second;
- ICHECK(e.in_scope) << "Cannot access a buffer " << buffer->name << ", out of scope";
- return it->second;
+ {
+ ICHECK(var_to_buffer_.count(old_var.get()))
+ << "Cannot find remap information for aliased buffer var " << old_var->name_hint
+ << ", required to verify this alias is legal.";
+ const Buffer& aliased_buffer = var_to_buffer_[old_var.get()];
+ const BufferEntry& entry = buf_map_[aliased_buffer.get()];
+ if (entry.remap) {
+ for (const auto& begin : entry.remap->begins) {
+ ICHECK(is_zero(begin)) << "Aliasing of buffer with offset is not supported";
+ }
+ }
+ }
+
+ {
+ Buffer new_buf = buffer;
+ new_buf.CopyOnWrite()->data = new_var;
+
+ RemapInfo remap_info;
+ remap_info.target = new_buf;
+ remap_info.begins = Array<PrimExpr>(buffer->shape.size(), 0);
+ remap_info.extents = buffer->shape;
+
+ BufferEntry entry;
+ entry.buffer = buffer;
+ entry.remap = std::make_unique<RemapInfo>(remap_info);
+ entry.in_scope = true;
+ var_to_buffer_[buffer->data.get()] = buffer;
+ buf_map_[buffer.get()] = std::move(entry);
+ }
+ return buf_map_[buffer.get()];
+ } else if (var_to_buffer_.count(buffer->data.get())) {
+ // This buffer is an alias of a known buffer, with no remaps. A
+ // buffer entry should be generated and returned.
+ BufferEntry entry;
+ entry.buffer = buffer;
+ entry.in_scope = true;
+ var_to_buffer_[buffer->data.get()] = buffer;
+ buf_map_[buffer.get()] = std::move(entry);
+
+ return buf_map_[buffer.get()];
+ } else {
+ LOG(FATAL) << "Can't work around the undefined buffer";
+ return *static_cast<BufferEntry*>(nullptr);
Review Comment:
> No matter what, as it is here, this is an explicit UB.
Agreed. That was intentional as a way to indicate an unreachable path without compiler-specific intrinsics, though I'm realizing that my intent for it to be both (1) deducible by the compiler as undefined for the purpose of optimization and (2) not deducible by the compiler as undefined for the purpose of producing warnings wasn't the most consistent of plans.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] Lunderberg merged pull request #10940: [TIR] Remove PrimFuncNode::preflattened_buffer_map
Posted by GitBox <gi...@apache.org>.
Lunderberg merged PR #10940:
URL: https://github.com/apache/tvm/pull/10940
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org