[moco-tf] Use calc_node_pad for fix pad of loco nodes (#6300)
author박세희/On-Device Lab(SR)/Principal Engineer/삼성전자 <saehie.park@samsung.com>
Wed, 7 Aug 2019 01:42:35 +0000 (10:42 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Wed, 7 Aug 2019 01:42:35 +0000 (10:42 +0900)
This will change to use calc_node_pad() method to fix pad in FixShapeInference for loco nodes

Signed-off-by: SaeHie Park <saehie.park@samsung.com>
compiler/moco-tf/src/Transforms/FixShapeTransform.cpp

index cdf9335..a13fe84 100644 (file)
@@ -219,17 +219,11 @@ bool fix_shape(loco::AvgPool2D *node)
   shape_data->feature_shape(ofm_feature_shape);
   node->annot(std::move(shape_data));
 
-  // calculate padding height, width
-  int32_t i_height = (output_height - 1) * stride_height + effective_window_height - input_height;
-  int32_t i_width = (output_width - 1) * stride_width + effective_window_width - input_width;
-  uint32_t pad_height = i_height >= 0 ? i_height : 0U;
-  uint32_t pad_width = i_width >= 0 ? i_width : 0U;
+  FixPadContext ctx = {
+      input_height,  input_width,  output_height,           output_width,
+      stride_height, stride_width, effective_window_height, effective_window_width};
 
-  // set padding values
-  node->pad()->top(pad_height / 2);
-  node->pad()->bottom(pad_height - node->pad()->top());
-  node->pad()->left(pad_width / 2);
-  node->pad()->right(pad_width - node->pad()->left());
+  calc_node_pad(node, ctx);
 
   // clear annotation PaddingData
   node->annot<PaddingData>(nullptr);
@@ -349,17 +343,10 @@ bool fix_shape(loco::Conv2D *node)
   shape_data->feature_shape(ofm_feature_shape);
   node->annot(std::move(shape_data));
 
-  // calculate padding height, width
-  int32_t i_height = (output_height - 1) * stride_height + effective_ker_height - input_height;
-  int32_t i_width = (output_width - 1) * stride_width + effective_ker_width - input_width;
-  uint32_t pad_height = i_height >= 0 ? i_height : 0U;
-  uint32_t pad_width = i_width >= 0 ? i_width : 0U;
+  FixPadContext ctx = {input_height,  input_width,  output_height,        output_width,
+                       stride_height, stride_width, effective_ker_height, effective_ker_width};
 
-  // set padding values
-  node->pad()->top(pad_height / 2);
-  node->pad()->bottom(pad_height - node->pad()->top());
-  node->pad()->left(pad_width / 2);
-  node->pad()->right(pad_width - node->pad()->left());
+  calc_node_pad(node, ctx);
 
   // clear annotation PaddingData
   node->annot<PaddingData>(nullptr);
@@ -538,17 +525,11 @@ bool fix_shape(loco::MaxPool2D *node)
   shape_data->feature_shape(ofm_feature_shape);
   node->annot(std::move(shape_data));
 
-  // calculate padding height, width
-  int32_t i_height = (output_height - 1) * stride_height + effective_window_height - input_height;
-  int32_t i_width = (output_width - 1) * stride_width + effective_window_width - input_width;
-  uint32_t pad_height = i_height >= 0 ? i_height : 0U;
-  uint32_t pad_width = i_width >= 0 ? i_width : 0U;
+  FixPadContext ctx = {
+      input_height,  input_width,  output_height,           output_width,
+      stride_height, stride_width, effective_window_height, effective_window_width};
 
-  // set padding values
-  node->pad()->top(pad_height / 2);
-  node->pad()->bottom(pad_height - node->pad()->top());
-  node->pad()->left(pad_width / 2);
-  node->pad()->right(pad_width - node->pad()->left());
+  calc_node_pad(node, ctx);
 
   // clear annotation PaddingData
   node->annot<PaddingData>(nullptr);