Skip to content

Commit

Permalink
[RELAY] Fix ops in packed layout (apache#2472)
Browse files Browse the repository at this point in the history
* [RELAY] Fix ops in packed layout

* Fix style
  • Loading branch information
vinx13 authored and merrymercy committed Feb 17, 2019
1 parent 3440f21 commit a82117e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/relay/op/nn/pooling.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@ bool Pool2DRel(const Array<Type>& types,
return false;
}

std::vector<IndexExpr> oshape({dshape[0], dshape[1], dshape[2], dshape[3]});
std::vector<IndexExpr> oshape;
for (const auto& e : dshape) {
oshape.push_back(e);
}

if (param->ceil_mode) {
oshape[hidx] = ((dshape[hidx] + pad_h - param->pool_size[0] +
param->strides[0] - 1) / param->strides[0]) + 1;
Expand Down
3 changes: 2 additions & 1 deletion src/relay/op/tensor/transform.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ RELAY_REGISTER_OP("cast")
.set_support_level(3)
.add_type_rel("Cast", CastRel)
.set_attr<FTVMCompute>("FTVMCompute", CastCompute)
.set_attr<TOpPattern>("TOpPattern", kElemWise);
.set_attr<TOpPattern>("TOpPattern", kElemWise)
.set_attr<FInferCorrectLayout>("FInferCorrectLayout", ElemwiseArbitraryLayout);

// relay.expand_dims
TVM_REGISTER_NODE_TYPE(ExpandDimsAttrs);
Expand Down
4 changes: 4 additions & 0 deletions tests/python/relay/test_pass_alter_op_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ def before():
# a useless tuple, which will be eliminated
y = relay.Tuple([y])[0]
y = relay.nn.relu(y)
y = relay.nn.max_pool2d(y, pool_size=(2, 2))
y = relay.cast(y, 'int32')
y = relay.nn.batch_flatten(y)
y = relay.Function(free_vars(y), y)
return y
Expand Down Expand Up @@ -112,6 +114,8 @@ def expected():
y = relay.add(y, b)

y = relay.nn.relu(y)
y = relay.nn.max_pool2d(y, pool_size=(2, 2), layout="NCHW16c")
y = relay.cast(y, 'int32')
y = relay.layout_transform(y, "NCHW16c", "NCHW")
y = relay.nn.batch_flatten(y)
y = relay.Function(free_vars(y), y)
Expand Down

0 comments on commit a82117e

Please sign in to comment.