Skip to content

Commit

Permalink
[runtime] listing infer* functions alphabetically (Samsung#640)
Browse files Browse the repository at this point in the history
This arrange infer* functions alphabetically and added comments which works as a marker to reduce conflict later.

Signed-off-by: Hyun Sik Yoon <[email protected]>
  • Loading branch information
hyunsik-yoon authored May 12, 2020
1 parent ed0b485 commit 0759b0b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 15 deletions.
22 changes: 18 additions & 4 deletions runtime/onert/core/include/util/ShapeInference.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,14 @@ namespace shape_inference

using Shapes = std::vector<ir::Shape>;

Shapes inferEltwiseShape(const ir::Shape &lhs_shape, const ir::Shape &rhs_shape);
// Define shape calculation for operations. List them in alphabetic order.
// Remove TODO when the function name matching the alphabet is added

Shapes inferAvgPoolShape(const ir::Shape &in_shape, const ir::operation::AvgPool2D::Param &param,
ir::Layout layout = ir::Layout::NHWC);

ir::Shape inferConcatShape(const Shapes &in_shapes, const ir::operation::Concat::Param &param);

Shapes inferMaxPoolShape(const ir::Shape &in_shape, const ir::operation::MaxPool2D::Param &param,
ir::Layout layout = ir::Layout::NHWC);

Shapes inferConv2DShape(const ir::Shape &in_shape, const ir::Shape &ker_shape,
const ir::operation::Conv2D::Param &param,
ir::Layout layout = ir::Layout::NHWC);
Expand All @@ -53,8 +51,24 @@ Shapes inferDepthwiseConv2DShape(const ir::Shape &in_shape, const ir::Shape &ker
const ir::operation::DepthwiseConv2D::Param &param,
ir::Layout layout = ir::Layout::NHWC);

Shapes inferEltwiseShape(const ir::Shape &lhs_shape, const ir::Shape &rhs_shape);

Shapes inferFullyConnectedShape(const ir::Shape &in_shape, const ir::Shape &ker_shape);

// TODO write op starting from G
// TODO write op starting from L

Shapes inferMaxPoolShape(const ir::Shape &in_shape, const ir::operation::MaxPool2D::Param &param,
ir::Layout layout = ir::Layout::NHWC);

// TODO write op starting from N
// TODO write op starting from P
// TODO write op starting from R
// TODO write op starting from S
// TODO write op starting from T
// TODO write op starting from U
// TODO write op starting from Z

/**
* @brief Class to infer shape before running kernels. It does the following:
* - re-calculate and set output shape at compile time (before running kernels)
Expand Down
36 changes: 25 additions & 11 deletions runtime/onert/core/src/util/ShapeInference.cc
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ std::pair<int, int> calcConvLikeHeightAndWidth(const int in_h, const int in_w, c
// Shape inference
//

// Define shape calculation for operations. List them in alphabetic order.
// Remove TODO when the function name matching the alphabet is added

Shapes inferEltwiseShape(const ir::Shape &lhs_shape, const ir::Shape &rhs_shape)
{
return {broadcastShapes(lhs_shape, rhs_shape)};
Expand Down Expand Up @@ -137,17 +140,6 @@ ir::Shape inferConcatShape(const Shapes &in_shapes, const ir::operation::Concat:
return out_shape;
}

Shapes inferMaxPoolShape(const ir::Shape &in_shape, const ir::operation::MaxPool2D::Param &param,
const ir::Layout layout)
{
assert(layout == ir::Layout::NHWC);
auto ifm_shape = in_shape.asFeature(layout);
const auto out_h_w = calcConvLikeHeightAndWidth(ifm_shape.H, ifm_shape.W, param.kh, param.kw,
param.padding, param.stride);
// Pooling don't change number of channels and batch size
return {ir::Shape{ifm_shape.N, out_h_w.first, out_h_w.second, ifm_shape.C}};
}

Shapes inferConv2DShape(const ir::Shape &in_shape, const ir::Shape &ker_shape,
const ir::operation::Conv2D::Param &param, ir::Layout layout)
{
Expand Down Expand Up @@ -196,6 +188,28 @@ Shapes inferFullyConnectedShape(const ir::Shape &in_shape, const ir::Shape &ker_
return {{ir::Shape({static_cast<int32_t>(batch_size), num_units})}};
}

// TODO write op starting from G
// TODO write op starting from L

Shapes inferMaxPoolShape(const ir::Shape &in_shape, const ir::operation::MaxPool2D::Param &param,
const ir::Layout layout)
{
assert(layout == ir::Layout::NHWC);
auto ifm_shape = in_shape.asFeature(layout);
const auto out_h_w = calcConvLikeHeightAndWidth(ifm_shape.H, ifm_shape.W, param.kh, param.kw,
param.padding, param.stride);
// Pooling don't change number of channels and batch size
return {ir::Shape{ifm_shape.N, out_h_w.first, out_h_w.second, ifm_shape.C}};
}

// TODO write op starting from N
// TODO write op starting from P
// TODO write op starting from R
// TODO write op starting from S
// TODO write op starting from T
// TODO write op starting from U
// TODO write op starting from Z

/*
StaticInferer
Expand Down

0 comments on commit 0759b0b

Please sign in to comment.