-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
[TIR] Remove PrimFuncNode::preflattened_buffer_map #10940
Conversation
|
4e7ec70
to
7062789
Compare
`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.
e6c5d51
to
877cc24
Compare
Rebased to resolve merge conflict, expecting same breakage in the ethos-u unit tests. |
This was incorrectly done in the first pass through, caught by CI.
* Remove additional preflatten usage * Use tuple instead of list for `T.Buffer`, as lists now throw * A couple numeric updates
There were a couple of spots that needed to be aware of flattened buffers being represented as buffer aliases.
Forwarding the instrumentation when evaluating FoldConstants helped in debugging, but shouldn't have made it in.
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 |
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.
`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); |
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.
This is not good, please use __builtin_unreachable()
or something like that...
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.
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.
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.
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.
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.
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.
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.
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.
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'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.
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 inMakePackedAPI
. This commit instead maintains the pre-flattened shapes inPrimFuncNode::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.