Skip to content

Commit

Permalink
fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
yangulei committed Feb 17, 2022
1 parent 1c7ef99 commit aab406b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
37 changes: 28 additions & 9 deletions src/tir/ir/data_layout.cc
Original file line number Diff line number Diff line change
Expand Up @@ -269,10 +269,16 @@ inline bool GetStoreRule(Array<PrimExpr>* index_rule, Array<PrimExpr>* shape_rul

std::stringstream ss;
ss << "index rule for " << src_layout.name() << "-->" << dst_layout.name() << ": [ ";
for (const auto& r : *index_rule) { ss << r << ", "; }; ss << "]" << std::endl;
for (const auto& r : *index_rule) {
ss << r << ", ";
}
ss << "]" << std::endl;

ss << "shape rule for " << src_layout.name() << "-->" << dst_layout.name() << ": [ ";
for (const auto& r : *shape_rule) { ss << r << ", "; }; ss << "]" << std::endl;
for (const auto& r : *shape_rule) {
ss << r << ", ";
}
ss << "]" << std::endl;
VLOG(1) << std::endl << ss.str();

return true;
Expand Down Expand Up @@ -366,12 +372,22 @@ inline Array<PrimExpr> TransformShape(const Array<PrimExpr>& src_shape,
}

std::stringstream ss;
ss << "shape rule for " << Layout(src_axis).name() << "-->" << Layout(target_axis).name() << ": [ ";
for (const auto& r : transform_rule) { ss << r << ", "; }; ss << "]" << std::endl;
ss << "shape rule for " << Layout(src_axis).name() << "-->" << Layout(target_axis).name()
<< ": [ ";
for (const auto& r : transform_rule) {
ss << r << ", ";
}
ss << "]" << std::endl;

ss << "shape transform: [ ";
for (const auto& s : src_shape) { ss << s << ", "; }; ss << "] --> [ ";
for (const auto& r : result) { ss << r << ", "; }; ss << "]" << std::endl;
for (const auto& s : src_shape) {
ss << s << ", ";
}
ss << "] --> [ ";
for (const auto& r : result) {
ss << r << ", ";
}
ss << "]" << std::endl;
VLOG(1) << std::endl << ss.str();

return result;
Expand All @@ -380,13 +396,15 @@ inline Array<PrimExpr> TransformShape(const Array<PrimExpr>& src_shape,
Array<PrimExpr> BijectiveLayout::ForwardShape(const Array<PrimExpr>& shape) const {
ICHECK(defined()) << "Cannot operate on an undefined bijective layout.";
const BijectiveLayoutNode* self = operator->();
return TransformShape(shape, self->src_layout->axes, self->dst_layout->axes, self->shape_forward_rule);
return TransformShape(shape, self->src_layout->axes, self->dst_layout->axes,
self->shape_forward_rule);
}

Array<PrimExpr> BijectiveLayout::BackwardShape(const Array<PrimExpr>& shape) const {
ICHECK(defined()) << "Cannot operate on an undefined bijective layout.";
const BijectiveLayoutNode* self = operator->();
return TransformShape(shape, self->dst_layout->axes, self->src_layout->axes, self->shape_backward_rule);
return TransformShape(shape, self->dst_layout->axes, self->src_layout->axes,
self->shape_backward_rule);
}

BijectiveLayout::BijectiveLayout(Layout src_layout, Layout dst_layout) {
Expand All @@ -398,7 +416,8 @@ BijectiveLayout::BijectiveLayout(Layout src_layout, Layout dst_layout) {
// To be consistent with previous behavior, a nullptr layout is created
// when argument is invalid.
if (GetStoreRule(&n->index_forward_rule, &n->shape_forward_rule, n->src_layout, n->dst_layout)) {
ICHECK(GetStoreRule(&n->index_backward_rule, &n->shape_backward_rule, n->dst_layout, n->src_layout));
ICHECK(GetStoreRule(&n->index_backward_rule, &n->shape_backward_rule, n->dst_layout,
n->src_layout));
data_ = std::move(n);
}
}
Expand Down
2 changes: 2 additions & 0 deletions tests/python/relay/test_pass_alter_op_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ def expected():

assert tvm.ir.structural_equal(a, b), "Actual = \n" + str(a)


def test_alter_layout_multi():
"""Test alternating the layout of a conv2d.
The layout of broadcast operators and the weight should be changed accordingly.
Expand Down Expand Up @@ -207,6 +208,7 @@ def expected():

assert tvm.ir.structural_equal(a, b), "Actual = \n" + str(a)


def test_alter_layout_lrn():
"""Test alternating the layout of a conv2d.
The layout of broadcast operators and the weight should be changed accordingly.
Expand Down

0 comments on commit aab406b

Please sign in to comment.