Lunderberg commented on code in PR #16966:
URL: https://github.com/apache/tvm/pull/16966#discussion_r1598715370
##########
src/tir/transforms/vectorize_loop.cc:
##########
@@ -72,6 +72,126 @@ inline PrimExpr BroadcastTo(PrimExpr e, int lanes, bool
is_scalable) {
return Broadcast(e, CreateNewLanes(is_scalable, lanes));
}
+bool EnableBufferLevelPredication() {
Review Comment:
To my knowledge, there isn't a general utility that would provide it, though
I definitely agree on its usefulness.
There's currently a couple similar utilities, such as
[`IRMutatorWithAnalyzer`](https://github.com/apache/tvm/blob/main/src/arith/ir_mutator_with_analyzer.h#L45)
and
[`IRVisitorWithAnalyzer`](https://github.com/apache/tvm/blob/main/src/arith/ir_visitor_with_analyzer.h#L35),
which allow context-dependent algebraic simplifications. The easiest way to
implement such a utility for target-aware simplifications would be to extract
out the context-dependent target tracking from an existing visitor/mutator
(e.g.
[here](https://github.com/apache/tvm/blob/main/src/tir/transforms/lower_device_kernel_launch.cc#L65),
used in the `LowerDeviceKernelLaunch` transform) into a `IRVisitorWithTarget`
and `IRMutatorWithTarget`, which is then subclassed again by each transform
that requires it.
For long-term maintainability, I like your suggestion of mixins much more
than the subclasses, because they could be composed together much more easily.
Implemented with subclasses, a hypothetical transform that requires both the
context-dependent target and context-dependent algebraic simplifications would
have incorrect behavior from multiple inheritance, and would need to
re-implement one or the other functionalities.
Unfortunately, I don't think the current `tir::StmtVisitor` API could be
used to support mixins, either through multiple inheritance or through
composition. The main issue is that the implementable virtual functions (e.g.
`tir::StmtVisitor::VisitStmt_(const tir::ForNode*)`) aren't granular enough.
In order to compose separate transforms that provide context-dependent
information, it would require separate virtual functions for pre-visit and
post-visit. I've toyed around with different variations of the TIR stmt/expr
visitor/mutator implementations, but haven't had the time to make anything
PR-able.
TL;DR: It doesn't currently exist, would be very useful to have, and a
subclass would be sufficient for this PR, though long-term maintainability
concerns may appear at some point in the future.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]