Modify util function in OperationFactory (#5290)
author오형석/On-Device Lab(SR)/Staff Engineer/삼성전자 <hseok82.oh@samsung.com>
Tue, 28 May 2019 04:25:17 +0000 (13:25 +0900)
committer박세희/On-Device Lab(SR)/Principal Engineer/삼성전자 <saehie.park@samsung.com>
Tue, 28 May 2019 04:25:17 +0000 (13:25 +0900)
* Modify util function in OperationFactory

- Rename util function for struct param setting: set{Struct_name} to make{Struct_name}
- Use explicit static casting for uint32_t from int32_t in makeStride function

Signed-off-by: Hyeongseok Oh <hseok82.oh@samsung.com>
* Rename makeExplicitPadding

runtimes/neurun/frontend/nnapi/wrapper/OperationFactory.cc

index 4172efc..8c64fb4 100644 (file)
@@ -29,10 +29,9 @@ void replaceDataType(Operands &operands, const OperandIndex &index, const DataTy
   operands.at(index).type(type);
 }
 
-ExplicitPadding setExplicitPaddingParam(Operands &operands, const OperandIndex &left_index,
-                                        const OperandIndex &right_index,
-                                        const OperandIndex &top_index,
-                                        const OperandIndex &bottom_index)
+ExplicitPadding makeExplicitPadding(Operands &operands, const OperandIndex &left_index,
+                                    const OperandIndex &right_index, const OperandIndex &top_index,
+                                    const OperandIndex &bottom_index)
 {
   auto left = operands.at(left_index).asScalar<int32_t>();
   auto right = operands.at(right_index).asScalar<int32_t>();
@@ -53,8 +52,8 @@ ExplicitPadding setExplicitPaddingParam(Operands &operands, const OperandIndex &
   return param;
 }
 
-Stride setStride(Operands &operands, const OperandIndex &horizontal_index,
-                 const OperandIndex &vertical_index)
+Stride makeStride(Operands &operands, const OperandIndex &horizontal_index,
+                  const OperandIndex &vertical_index)
 {
   auto horizontal = operands.at(horizontal_index).asScalar<int32_t>();
   auto vertical = operands.at(vertical_index).asScalar<int32_t>();
@@ -65,8 +64,8 @@ Stride setStride(Operands &operands, const OperandIndex &horizontal_index,
   }
 
   Stride stride;
-  stride.horizontal = horizontal;
-  stride.vertical = vertical;
+  stride.horizontal = static_cast<uint32_t>(horizontal);
+  stride.vertical = static_cast<uint32_t>(vertical);
 
   return stride;
 }
@@ -139,9 +138,8 @@ OperationFactory::OperationFactory()
       const auto activation_index = OperandIndex{init_param.inputs[10]};
 
       param.padding.type = PaddingType::EXPLICIT;
-      param.padding.param =
-          setExplicitPaddingParam(operands, padding_left_index, padding_right_index,
-                                  padding_top_index, padding_bottom_index);
+      param.padding.param = makeExplicitPadding(operands, padding_left_index, padding_right_index,
+                                                padding_top_index, padding_bottom_index);
       param.hstride_index = OperandIndex{init_param.inputs[7]};
       param.vstride_index = OperandIndex{init_param.inputs[8]};
       param.multiplier_index = OperandIndex{init_param.inputs[9]};
@@ -209,9 +207,8 @@ OperationFactory::OperationFactory()
       const auto activation_index = OperandIndex{init_param.inputs[9]};
 
       param.padding.type = PaddingType::EXPLICIT;
-      param.padding.param =
-          setExplicitPaddingParam(operands, padding_left_index, padding_right_index,
-                                  padding_top_index, padding_bottom_index);
+      param.padding.param = makeExplicitPadding(operands, padding_left_index, padding_right_index,
+                                                padding_top_index, padding_bottom_index);
       param.hstride_index = OperandIndex{init_param.inputs[5]};
       param.vstride_index = OperandIndex{init_param.inputs[6]};
 
@@ -280,9 +277,8 @@ OperationFactory::OperationFactory()
       const auto activation_index = OperandIndex{init_param.inputs[9]};
 
       param.padding.type = PaddingType::EXPLICIT;
-      param.padding.param =
-          setExplicitPaddingParam(operands, padding_left_index, padding_right_index,
-                                  padding_top_index, padding_bottom_index);
+      param.padding.param = makeExplicitPadding(operands, padding_left_index, padding_right_index,
+                                                padding_top_index, padding_bottom_index);
       param.hstride_index = OperandIndex{init_param.inputs[5]};
       param.vstride_index = OperandIndex{init_param.inputs[6]};
 
@@ -425,7 +421,7 @@ OperationFactory::OperationFactory()
 
       param.padding.type =
           NNAPIConvert::getPaddingType(operands.at(padding_index).asScalar<PaddingCode>());
-      param.stride = setStride(operands, hstride_index, vstride_index);
+      param.stride = makeStride(operands, hstride_index, vstride_index);
       param.activation =
           NNAPIConvert::getFusedActivation(operands.at(activation_index).asScalar<FuseCode>());
     }
@@ -450,10 +446,9 @@ OperationFactory::OperationFactory()
       const auto activation_index = OperandIndex{init_param.inputs[9]};
 
       param.padding.type = PaddingType::EXPLICIT;
-      param.padding.param =
-          setExplicitPaddingParam(operands, padding_left_index, padding_right_index,
-                                  padding_top_index, padding_bottom_index);
-      param.stride = setStride(operands, hstride_index, vstride_index);
+      param.padding.param = makeExplicitPadding(operands, padding_left_index, padding_right_index,
+                                                padding_top_index, padding_bottom_index);
+      param.stride = makeStride(operands, hstride_index, vstride_index);
       param.activation =
           NNAPIConvert::getFusedActivation(operands.at(activation_index).asScalar<FuseCode>());
     }
@@ -993,9 +988,8 @@ OperationFactory::OperationFactory()
       const auto activation_index = OperandIndex{init_param.inputs[9]};
 
       param.padding.type = PaddingType::EXPLICIT;
-      param.padding.param =
-          setExplicitPaddingParam(operands, padding_left_index, padding_right_index,
-                                  padding_top_index, padding_bottom_index);
+      param.padding.param = makeExplicitPadding(operands, padding_left_index, padding_right_index,
+                                                padding_top_index, padding_bottom_index);
       param.hstride_index = OperandIndex{init_param.inputs[5]};
       param.vstride_index = OperandIndex{init_param.inputs[6]};
       param.kw_index = OperandIndex{init_param.inputs[7]};