Skip to content
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

[TIR] Remove PrimFuncNode::preflattened_buffer_map #10940

Merged
merged 31 commits into from
Nov 16, 2022

Conversation

Lunderberg
Copy link
Contributor

PrimFuncNode::preflattened_buffer_map was introduced in #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.

@Lunderberg
Copy link
Contributor Author

Lunderberg commented Apr 8, 2022

This change still requires an RFC for discussion, but is here as a proof of concept. Edit: Part of RFC#70

Lunderberg added 10 commits May 16, 2022 08:51
`PrimFuncNode::preflattened_buffer_map` was introduced in
apache#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.
@Lunderberg Lunderberg force-pushed the remove_preflattened_buffer_map branch from e6c5d51 to 877cc24 Compare May 16, 2022 13:55
@Lunderberg
Copy link
Contributor Author

Rebased to resolve merge conflict, expecting same breakage in the ethos-u unit tests.

@areusch areusch added needs-triage PRs or issues that need to be investigated by maintainers to find the right assignees to address it and removed needs-triage PRs or issues that need to be investigated by maintainers to find the right assignees to address it labels Oct 19, 2022
* Remove additional preflatten usage
* Use tuple instead of list for `T.Buffer`, as lists now throw
* A couple numeric updates
@tvm-bot
Copy link
Collaborator

tvm-bot commented Nov 10, 2022

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 by @-ing them in a comment.

Generated by tvm-bot

@Lunderberg Lunderberg marked this pull request as ready for review November 10, 2022 19:57
@Lunderberg
Copy link
Contributor Author

@vinx13 This PR removes the preflattened_buffer_map, using buffer aliases instead, as described in your RFC#70.

@Lunderberg Lunderberg changed the title [Draft][TIR] Remove PrimFuncNode::preflattened_buffer_map [TIR] Remove PrimFuncNode::preflattened_buffer_map Nov 10, 2022
@vinx13 vinx13 self-assigned this Nov 10, 2022
Previous parser contextually interpreted buffer subscripts as Ramp
nodes if they occurred as part of an expression.  For new parser, need
to use an explicit step size to generate a Ramp.
@Lunderberg Lunderberg merged commit 78b5322 into apache:main Nov 16, 2022
@Lunderberg Lunderberg deleted the remove_preflattened_buffer_map branch November 17, 2022 14:11
xinetzone pushed a commit to daobook/tvm that referenced this pull request Nov 25, 2022
`PrimFuncNode::preflattened_buffer_map` was introduced in
apache#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, as described in
[RFC#70](apache/tvm-rfcs#70)
return buf_map_[buffer.get()];
} else {
LOG(FATAL) << "Can't work around the undefined buffer";
return *static_cast<BufferEntry*>(nullptr);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not good, please use __builtin_unreachable() or something like that...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've opened #13542, which removes this line entirely, with the [[noreturn]] attribute applied to both implementations of LOG(FATAL) so that the warning does not occur.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants