csullivan commented on a change in pull request #7807:
URL: https://github.com/apache/tvm/pull/7807#discussion_r617118760
##########
File path: src/relay/transforms/simplify_expr.cc
##########
@@ -163,6 +141,69 @@ class SimplifyTranspose : public DFPatternRewrite {
return x;
}
+ String PermuteLayout(const String& layout, std::vector<int> axes) const {
+ std::string new_layout{};
+ std::string old_layout{layout};
+ for (auto axis : axes) {
+ new_layout += old_layout[axis];
+ }
+ return String(new_layout);
+ }
+
+ Optional<Expr> FoldRankChangingLayoutTrans(const Expr& data, const Call&
call) const {
+ Optional<Expr> layout_trans;
+ if (auto attr = call->attrs.as<LayoutTransformAttrs>()) {
+ Layout src_layout(attr->src_layout);
+ Layout dst_layout(attr->dst_layout);
+ if (src_layout->axes.size() != dst_layout->axes.size()) {
+ auto axes = GetTransposeAxisOrder(Downcast<Call>(call->args[0]),
src_layout->axes.size());
+ std::vector<int> inverse(axes.size());
+ for (size_t i = 0; i < axes.size(); i++) {
+ inverse[axes[i]] = i;
+ }
+ String new_layout = PermuteLayout(attr->src_layout, inverse);
+ layout_trans = MakeLayoutTransform(data, new_layout, dst_layout->name);
+ }
+ } else if (auto attr =
Downcast<Call>(call->args[0])->attrs.as<LayoutTransformAttrs>()) {
Review comment:
Attrs is guaranteed to be available for a Call, no? Are you worried
about arg[0] not being of type Call? I believe the latter is guaranteed by the
pattern matcher in this case. Let me know if I missed your meaning
--
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.
For queries about this service, please contact Infrastructure at:
[email protected]