[neurun] Use internal data type in CPU backend (#2432)
author오형석/동작제어Lab(SR)/Staff Engineer/삼성전자 <hseok82.oh@samsung.com>
Thu, 23 Aug 2018 06:09:57 +0000 (15:09 +0900)
committer박세희/동작제어Lab(SR)/Principal Engineer/삼성전자 <saehie.park@samsung.com>
Thu, 23 Aug 2018 06:09:57 +0000 (15:09 +0900)
Define convert function to make CPU backend shape from graph operand
Use internal data type to make backend shape
Change CPU backend interface to use backend shape instead of graph shape
Change CPU backend operation to save input data type

Signed-off-by: Hyeongseok Oh <hseok82.oh@samsung.com>
21 files changed:
runtimes/neurun/src/backend/cpu/StageGenerator.cc
runtimes/neurun/src/kernel/cpu/AvgPoolLayer.cc
runtimes/neurun/src/kernel/cpu/AvgPoolLayer.h
runtimes/neurun/src/kernel/cpu/ConcatLayer.cc
runtimes/neurun/src/kernel/cpu/ConcatLayer.h
runtimes/neurun/src/kernel/cpu/ConvolutionLayer.cc
runtimes/neurun/src/kernel/cpu/ConvolutionLayer.h
runtimes/neurun/src/kernel/cpu/FullyConnectedLayer.cc
runtimes/neurun/src/kernel/cpu/FullyConnectedLayer.h
runtimes/neurun/src/kernel/cpu/MaxPoolLayer.cc
runtimes/neurun/src/kernel/cpu/MaxPoolLayer.h
runtimes/neurun/src/kernel/cpu/OperationUtils.cc
runtimes/neurun/src/kernel/cpu/OperationUtils.h
runtimes/neurun/src/kernel/cpu/ReshapeLayer.cc
runtimes/neurun/src/kernel/cpu/ReshapeLayer.h
runtimes/neurun/src/kernel/cpu/SoftMaxLayer.cc
runtimes/neurun/src/kernel/cpu/SoftMaxLayer.h
runtimes/neurun/src/kernel/cpu/TensorConvertFromCommonLayer.cc
runtimes/neurun/src/kernel/cpu/TensorConvertFromCommonLayer.h
runtimes/neurun/src/kernel/cpu/TensorConvertToCommonLayer.cc
runtimes/neurun/src/kernel/cpu/TensorConvertToCommonLayer.h

index f9cab11..fa607db 100644 (file)
@@ -3,6 +3,7 @@
 #include <stdexcept>
 
 #include "internal/Padding.h"
+#include "kernel/cpu/OperationUtils.h"
 #include "kernel/cpu/ConvolutionLayer.h"
 #include "kernel/cpu/AvgPoolLayer.h"
 #include "kernel/cpu/MaxPoolLayer.h"
@@ -65,10 +66,10 @@ Stage StageGenerator::generate(const ::internal::tflite::op::Conv2D::implicit::N
     int ker_index;
     int bias_index;
 
-    ::neurun::internal::operand::Shape ofm_shape{1};
-    ::neurun::internal::operand::Shape ifm_shape{1};
-    ::neurun::internal::operand::Shape ker_shape{1};
-    ::neurun::internal::operand::Shape bias_shape{1};
+    ::neurun::kernel::cpu::Shape ofm_shape;
+    ::neurun::kernel::cpu::Shape ifm_shape;
+    ::neurun::kernel::cpu::Shape ker_shape;
+    ::neurun::kernel::cpu::Shape bias_shape;
 
     ::internal::Padding padding;
     ::internal::Stride stride;
@@ -83,16 +84,17 @@ Stage StageGenerator::generate(const ::internal::tflite::op::Conv2D::implicit::N
   param.ker_index = ker_index.asInt();
   param.bias_index = bias_index.asInt();
 
-  param.ofm_shape = _ctx.at(ofm_index).shape();
-  param.ifm_shape = _ctx.at(ifm_index).shape();
-  param.ker_shape = _ctx.at(ker_index).shape();
-  param.bias_shape = _ctx.at(bias_index).shape();
+  param.ofm_shape = ::neurun::kernel::cpu::getShape(_ctx.at(ofm_index));
+  param.ifm_shape = ::neurun::kernel::cpu::getShape(_ctx.at(ifm_index));
+  param.ker_shape = ::neurun::kernel::cpu::getShape(_ctx.at(ker_index));
+  param.bias_shape = ::neurun::kernel::cpu::getShape(_ctx.at(bias_index));
 
   param.stride = stride;
   param.padding = (padding_type == ANEURALNETWORKS_PADDING_SAME)
-                      ? ::internal::same_padding(
-                            param.ifm_shape.asFeature(), param.ofm_shape.asFeature(), stride,
-                            param.ker_shape.asKernel().W, param.ker_shape.asKernel().H)
+                      ? ::internal::same_padding(_ctx.at(ifm_index).shape().asFeature(),
+                                                 _ctx.at(ofm_index).shape().asFeature(), stride,
+                                                 _ctx.at(ker_index).shape().asKernel().W,
+                                                 _ctx.at(ker_index).shape().asKernel().H)
                       : ::internal::valid_padding();
 
   param.activation = static_cast<FuseCode>(_ctx.at(activation_index).asScalar<int32_t>());
@@ -151,8 +153,8 @@ Stage StageGenerator::generate(const ::internal::tflite::op::MaxPool2D::implicit
     uint32_t kw;
     uint32_t kh;
 
-    ::neurun::internal::operand::Shape ofm_shape{1};
-    ::neurun::internal::operand::Shape ifm_shape{1};
+    ::neurun::kernel::cpu::Shape ofm_shape;
+    ::neurun::kernel::cpu::Shape ifm_shape;
 
     ::internal::Padding padding;
     ::internal::Stride stride;
@@ -168,23 +170,24 @@ Stage StageGenerator::generate(const ::internal::tflite::op::MaxPool2D::implicit
   param.kh = kh;
   param.kw = kw;
 
-  param.ofm_shape = _ctx.at(ofm_index).shape();
-  param.ifm_shape = _ctx.at(ifm_index).shape();
+  param.ofm_shape = ::neurun::kernel::cpu::getShape(_ctx.at(ofm_index));
+  param.ifm_shape = ::neurun::kernel::cpu::getShape(_ctx.at(ifm_index));
 
   param.stride.vertical = vstride;
   param.stride.horizontal = hstride;
 
-  param.padding = (padding_type == ANEURALNETWORKS_PADDING_SAME)
-                      ? ::internal::same_padding(param.ifm_shape.asFeature(),
-                                                 param.ofm_shape.asFeature(), param.stride, kw, kh)
-                      : ::internal::valid_padding();
+  param.padding =
+      (padding_type == ANEURALNETWORKS_PADDING_SAME)
+          ? ::internal::same_padding(_ctx.at(ifm_index).shape().asFeature(),
+                                     _ctx.at(ofm_index).shape().asFeature(), param.stride, kw, kh)
+          : ::internal::valid_padding();
 
   param.activation = static_cast<FuseCode>(_ctx.at(activation_index).asScalar<int32_t>());
 
-  VERBOSE(MaxPool2D) << "IFM_H: " << param.ifm_shape.asFeature().H << std::endl;
-  VERBOSE(MaxPool2D) << "IFM_W: " << param.ifm_shape.asFeature().W << std::endl;
-  VERBOSE(MaxPool2D) << "OFM_H: " << param.ofm_shape.asFeature().H << std::endl;
-  VERBOSE(MaxPool2D) << "OFM_W: " << param.ofm_shape.asFeature().W << std::endl;
+  VERBOSE(MaxPool2D) << "IFM_H: " << _ctx.at(ifm_index).shape().asFeature().H << std::endl;
+  VERBOSE(MaxPool2D) << "IFM_W: " << _ctx.at(ifm_index).shape().asFeature().W << std::endl;
+  VERBOSE(MaxPool2D) << "OFM_H: " << _ctx.at(ofm_index).shape().asFeature().H << std::endl;
+  VERBOSE(MaxPool2D) << "OFM_W: " << _ctx.at(ofm_index).shape().asFeature().W << std::endl;
   VERBOSE(MaxPool2D) << "KER_H: " << kh << std::endl;
   VERBOSE(MaxPool2D) << "KER_W: " << kw << std::endl;
   VERBOSE(MaxPool2D) << "STRIDE_H: " << vstride << std::endl;
@@ -249,8 +252,8 @@ Stage StageGenerator::generate(const ::internal::tflite::op::AvgPool2D::implicit
     uint32_t kw;
     uint32_t kh;
 
-    ::neurun::internal::operand::Shape ofm_shape{1};
-    ::neurun::internal::operand::Shape ifm_shape{1};
+    ::neurun::kernel::cpu::Shape ofm_shape;
+    ::neurun::kernel::cpu::Shape ifm_shape;
 
     ::internal::Padding padding;
     ::internal::Stride stride;
@@ -266,23 +269,24 @@ Stage StageGenerator::generate(const ::internal::tflite::op::AvgPool2D::implicit
   param.kh = kh;
   param.kw = kw;
 
-  param.ofm_shape = _ctx.at(ofm_index).shape();
-  param.ifm_shape = _ctx.at(ifm_index).shape();
+  param.ofm_shape = ::neurun::kernel::cpu::getShape(_ctx.at(ofm_index));
+  param.ifm_shape = ::neurun::kernel::cpu::getShape(_ctx.at(ifm_index));
 
   param.stride.vertical = vstride;
   param.stride.horizontal = hstride;
 
-  param.padding = (padding_type == ANEURALNETWORKS_PADDING_SAME)
-                      ? ::internal::same_padding(param.ifm_shape.asFeature(),
-                                                 param.ofm_shape.asFeature(), param.stride, kw, kh)
-                      : ::internal::valid_padding();
+  param.padding =
+      (padding_type == ANEURALNETWORKS_PADDING_SAME)
+          ? ::internal::same_padding(_ctx.at(ifm_index).shape().asFeature(),
+                                     _ctx.at(ofm_index).shape().asFeature(), param.stride, kw, kh)
+          : ::internal::valid_padding();
 
   param.activation = static_cast<FuseCode>(_ctx.at(activation_index).asScalar<int32_t>());
 
-  VERBOSE(AvgPool2D) << "IFM_H: " << param.ifm_shape.asFeature().H << std::endl;
-  VERBOSE(AvgPool2D) << "IFM_W: " << param.ifm_shape.asFeature().W << std::endl;
-  VERBOSE(AvgPool2D) << "OFM_H: " << param.ofm_shape.asFeature().H << std::endl;
-  VERBOSE(AvgPool2D) << "OFM_W: " << param.ofm_shape.asFeature().W << std::endl;
+  VERBOSE(AvgPool2D) << "IFM_H: " << _ctx.at(ifm_index).shape().asFeature().H << std::endl;
+  VERBOSE(AvgPool2D) << "IFM_W: " << _ctx.at(ifm_index).shape().asFeature().W << std::endl;
+  VERBOSE(AvgPool2D) << "OFM_H: " << _ctx.at(ofm_index).shape().asFeature().H << std::endl;
+  VERBOSE(AvgPool2D) << "OFM_W: " << _ctx.at(ofm_index).shape().asFeature().W << std::endl;
   VERBOSE(AvgPool2D) << "KER_H: " << kh << std::endl;
   VERBOSE(AvgPool2D) << "KER_W: " << kw << std::endl;
   VERBOSE(AvgPool2D) << "STRIDE_H: " << vstride << std::endl;
@@ -325,8 +329,8 @@ Stage StageGenerator::generate(const ::internal::tflite::op::Concat::Node &node)
 
     int32_t axis;
 
-    ::neurun::internal::operand::Shape ofm_shape{1};
-    std::vector<::neurun::internal::operand::Shape> ifm_shapes;
+    ::neurun::kernel::cpu::Shape ofm_shape;
+    std::vector<::neurun::kernel::cpu::Shape> ifm_shapes;
   };
 
   Param param;
@@ -335,12 +339,12 @@ Stage StageGenerator::generate(const ::internal::tflite::op::Concat::Node &node)
   param.input_indexes = node.param().ifm_indexes;
   param.axis = _ctx.at(axis_index).asScalar<int32_t>();
 
-  param.ofm_shape = _ctx.at(ofm_index).shape();
+  param.ofm_shape = ::neurun::kernel::cpu::getShape(_ctx.at(ofm_index));
 
   for (auto ifm_ind : node.param().ifm_indexes)
   {
     const ::neurun::graph::operand::Index ifm_index{ifm_ind};
-    param.ifm_shapes.emplace_back(_ctx.at(ifm_index).shape());
+    param.ifm_shapes.emplace_back(::neurun::kernel::cpu::getShape(_ctx.at(ifm_index)));
   }
 
   auto tensors = _tensor_builder;
@@ -382,10 +386,10 @@ Stage StageGenerator::generate(const ::internal::tflite::op::FullyConnected::Nod
     int weight_index;
     int bias_index;
 
-    ::neurun::internal::operand::Shape ofm_shape{1};
-    ::neurun::internal::operand::Shape ifm_shape{1};
-    ::neurun::internal::operand::Shape weight_shape{1};
-    ::neurun::internal::operand::Shape bias_shape{1};
+    ::neurun::kernel::cpu::Shape ofm_shape;
+    ::neurun::kernel::cpu::Shape ifm_shape;
+    ::neurun::kernel::cpu::Shape weight_shape;
+    ::neurun::kernel::cpu::Shape bias_shape;
 
     FuseCode activation;
   };
@@ -397,10 +401,10 @@ Stage StageGenerator::generate(const ::internal::tflite::op::FullyConnected::Nod
   param.weight_index = weight_index.asInt();
   param.bias_index = bias_index.asInt();
 
-  param.ofm_shape = _ctx.at(output_index).shape();
-  param.ifm_shape = _ctx.at(input_index).shape();
-  param.weight_shape = _ctx.at(weight_index).shape();
-  param.bias_shape = _ctx.at(bias_index).shape();
+  param.ofm_shape = ::neurun::kernel::cpu::getShape(_ctx.at(output_index));
+  param.ifm_shape = ::neurun::kernel::cpu::getShape(_ctx.at(input_index));
+  param.weight_shape = ::neurun::kernel::cpu::getShape(_ctx.at(weight_index));
+  param.bias_shape = ::neurun::kernel::cpu::getShape(_ctx.at(bias_index));
 
   param.activation = static_cast<FuseCode>(_ctx.at(activation_index).asScalar<int32_t>());
 
@@ -433,8 +437,8 @@ Stage StageGenerator::generate(const ::internal::tflite::op::Reshape::Node &node
     int output_index;
     int input_index;
 
-    ::neurun::internal::operand::Shape ofm_shape{1};
-    ::neurun::internal::operand::Shape ifm_shape{1};
+    ::neurun::kernel::cpu::Shape ofm_shape;
+    ::neurun::kernel::cpu::Shape ifm_shape;
   };
 
   Param param;
@@ -442,8 +446,8 @@ Stage StageGenerator::generate(const ::internal::tflite::op::Reshape::Node &node
   param.output_index = output_index.asInt();
   param.input_index = input_index.asInt();
 
-  param.ofm_shape = _ctx.at(output_index).shape();
-  param.ifm_shape = _ctx.at(input_index).shape();
+  param.ofm_shape = ::neurun::kernel::cpu::getShape(_ctx.at(output_index));
+  param.ifm_shape = ::neurun::kernel::cpu::getShape(_ctx.at(input_index));
 
   auto tensors = _tensor_builder;
 
@@ -473,8 +477,8 @@ Stage StageGenerator::generate(const ::internal::tflite::op::Softmax::Node &node
     int output_index;
     int input_index;
 
-    ::neurun::internal::operand::Shape ofm_shape{1};
-    ::neurun::internal::operand::Shape ifm_shape{1};
+    ::neurun::kernel::cpu::Shape ofm_shape;
+    ::neurun::kernel::cpu::Shape ifm_shape;
 
     float scale;
   };
@@ -484,8 +488,8 @@ Stage StageGenerator::generate(const ::internal::tflite::op::Softmax::Node &node
   param.output_index = output_index.asInt();
   param.input_index = input_index.asInt();
 
-  param.ofm_shape = _ctx.at(output_index).shape();
-  param.ifm_shape = _ctx.at(input_index).shape();
+  param.ofm_shape = ::neurun::kernel::cpu::getShape(_ctx.at(output_index));
+  param.ifm_shape = ::neurun::kernel::cpu::getShape(_ctx.at(input_index));
 
   param.scale = _ctx.at(scale_index).asScalar<float>();
 
index daa2ff7..2cdd5b8 100644 (file)
@@ -66,18 +66,16 @@ bool AvgPoolLayer::averagePoolQuant8()
   return true;
 }
 
-void AvgPoolLayer::configure(uint8_t *inputData,
-                             const ::neurun::internal::operand::Shape inputShape,
-                             const uint32_t paddingLeft, const uint32_t paddingRight,
-                             const uint32_t paddingTop, const uint32_t paddingBottom,
-                             const uint32_t strideWidth, const uint32_t strideHeight,
-                             const uint32_t kernelWidth, const uint32_t kernelHeight,
-                             const FuseCode activation, uint8_t *outputData,
-                             const ::neurun::internal::operand::Shape outputShape)
+void AvgPoolLayer::configure(uint8_t *inputData, const Shape inputShape, const uint32_t paddingLeft,
+                             const uint32_t paddingRight, const uint32_t paddingTop,
+                             const uint32_t paddingBottom, const uint32_t strideWidth,
+                             const uint32_t strideHeight, const uint32_t kernelWidth,
+                             const uint32_t kernelHeight, const FuseCode activation,
+                             uint8_t *outputData, const Shape outputShape)
 {
   _inputData = inputData;
-  _inputShape = convertShape(inputShape);
-  _inputType = inputShape.type();
+  _inputShape = inputShape;
+  _inputType = inputShape.type;
   _paddingLeft = paddingLeft;
   _paddingRight = paddingRight;
   _paddingTop = paddingTop;
@@ -88,16 +86,16 @@ void AvgPoolLayer::configure(uint8_t *inputData,
   _kernelHeight = kernelHeight;
   _activation = activation;
   _outputData = outputData;
-  _outputShape = convertShape(outputShape);
+  _outputShape = outputShape;
 }
 
 void AvgPoolLayer::run()
 {
-  if (_inputType == static_cast<uint32_t>(OperandType::TENSOR_FLOAT32))
+  if (_inputType == OperandType::TENSOR_FLOAT32)
   {
     averagePoolFloat32();
   }
-  else if (_inputType == static_cast<uint32_t>(OperandType::TENSOR_QUANT8_ASYMM))
+  else if (_inputType == OperandType::TENSOR_QUANT8_ASYMM)
   {
     averagePoolQuant8();
   }
index 67423b3..ab5c3bf 100644 (file)
@@ -27,12 +27,12 @@ public:
 
   bool averagePoolQuant8();
 
-  void configure(uint8_t *inputData, const ::neurun::internal::operand::Shape inputShape,
-                 const uint32_t paddingLeft, const uint32_t paddingRight, const uint32_t paddingTop,
+  void configure(uint8_t *inputData, const Shape inputShape, const uint32_t paddingLeft,
+                 const uint32_t paddingRight, const uint32_t paddingTop,
                  const uint32_t paddingBottom, const uint32_t strideWidth,
                  const uint32_t strideHeight, const uint32_t kernelWidth,
                  const uint32_t kernelHeight, const FuseCode activation, uint8_t *outputData,
-                 const ::neurun::internal::operand::Shape outputShape);
+                 const Shape outputShape);
 
   void run();
 
@@ -55,7 +55,7 @@ private:
 
   FuseCode _activation;
 
-  int32_t _inputType;
+  OperandType _inputType;
 };
 
 } // namespace cpu
index 29b1cb8..45c2c04 100644 (file)
@@ -67,31 +67,30 @@ bool ConcatLayer::concatenationQuant8()
 }
 
 void ConcatLayer::configure(const std::vector<const uint8_t *> &inputDataPtrs,
-                            const std::vector<::neurun::internal::operand::Shape> &inputShapes,
-                            int32_t axis, uint8_t *outputData,
-                            const ::neurun::internal::operand::Shape outputShape)
+                            const std::vector<Shape> &inputShapes, int32_t axis,
+                            uint8_t *outputData, const Shape outputShape)
 {
   _inputDataPtrs = inputDataPtrs;
 
   for (auto shape : inputShapes)
   {
-    _inputShapes.emplace_back(convertShape(shape));
-    _inputType = shape.type();
+    _inputShapes.emplace_back(shape);
+    _inputType = shape.type;
   }
 
   _axis = axis;
 
   _outputData = outputData;
-  _outputShape = convertShape(outputShape);
+  _outputShape = outputShape;
 }
 
 void ConcatLayer::run()
 {
-  if (_inputType == static_cast<uint32_t>(OperandType::TENSOR_FLOAT32))
+  if (_inputType == OperandType::TENSOR_FLOAT32)
   {
     concatenationFloat32();
   }
-  else if (_inputType == static_cast<uint32_t>(OperandType::TENSOR_QUANT8_ASYMM))
+  else if (_inputType == OperandType::TENSOR_QUANT8_ASYMM)
   {
     concatenationQuant8();
   }
index 8b97218..1f36c9d 100644 (file)
@@ -45,8 +45,8 @@ public:
   bool concatenationQuant8();
 
   void configure(const std::vector<const uint8_t *> &inputDataPtrs,
-                 const std::vector<::neurun::internal::operand::Shape> &inputShapes, int32_t axis,
-                 uint8_t *outputData, const ::neurun::internal::operand::Shape outputShape);
+                 const std::vector<Shape> &inputShapes, int32_t axis, uint8_t *outputData,
+                 const Shape outputShape);
 
   void run();
 
@@ -59,7 +59,7 @@ private:
   std::vector<Shape> _inputShapes;
   Shape _outputShape;
 
-  int32_t _inputType;
+  OperandType _inputType;
 };
 
 } // namespace cpu
index 60d2cd1..71d33b3 100644 (file)
@@ -145,20 +145,20 @@ bool ConvolutionLayer::convQuant8()
   return true;
 }
 
-void ConvolutionLayer::configure(
-    uint8_t *inputData, const ::neurun::internal::operand::Shape inputShape, uint8_t *kernelData,
-    const ::neurun::internal::operand::Shape kernelShape, uint8_t *biasData,
-    const ::neurun::internal::operand::Shape biasShape, const uint32_t paddingLeft,
-    const uint32_t paddingRight, const uint32_t paddingTop, const uint32_t paddingBottom,
-    const uint32_t strideWidth, const uint32_t strideHeight, const FuseCode activation,
-    uint8_t *outputData, const ::neurun::internal::operand::Shape outputShape)
+void ConvolutionLayer::configure(uint8_t *inputData, const Shape inputShape, uint8_t *kernelData,
+                                 const Shape kernelShape, uint8_t *biasData, const Shape biasShape,
+                                 const uint32_t paddingLeft, const uint32_t paddingRight,
+                                 const uint32_t paddingTop, const uint32_t paddingBottom,
+                                 const uint32_t strideWidth, const uint32_t strideHeight,
+                                 const FuseCode activation, uint8_t *outputData,
+                                 const Shape outputShape)
 {
   _inputData = inputData;
-  _inputShape = convertShape(inputShape);
+  _inputShape = inputShape;
   _kernelData = kernelData;
-  _kernelShape = convertShape(kernelShape);
+  _kernelShape = kernelShape;
   _biasData = biasData;
-  _biasShape = convertShape(biasShape);
+  _biasShape = biasShape;
   _paddingLeft = paddingLeft;
   _paddingRight = paddingRight;
   _paddingTop = paddingTop;
@@ -167,7 +167,7 @@ void ConvolutionLayer::configure(
   _strideHeight = strideHeight;
   _activation = activation;
   _outputData = outputData;
-  _outputShape = convertShape(outputShape);
+  _outputShape = outputShape;
 }
 
 void ConvolutionLayer::run()
index 525f3eb..d1f8c87 100644 (file)
@@ -27,13 +27,11 @@ public:
 
   bool convQuant8();
 
-  void configure(uint8_t *inputData, const ::neurun::internal::operand::Shape inputShape,
-                 uint8_t *kernelData, const ::neurun::internal::operand::Shape kernelShape,
-                 uint8_t *biasData, const ::neurun::internal::operand::Shape biasShape,
+  void configure(uint8_t *inputData, const Shape inputShape, uint8_t *kernelData,
+                 const Shape kernelShape, uint8_t *biasData, const Shape biasShape,
                  const uint32_t paddingLeft, const uint32_t paddingRight, const uint32_t paddingTop,
                  const uint32_t paddingBottom, const uint32_t strideW, const uint32_t strideH,
-                 const FuseCode activation, uint8_t *outputData,
-                 const ::neurun::internal::operand::Shape outputShape);
+                 const FuseCode activation, uint8_t *outputData, const Shape outputShape);
 
   void run();
 
index 6a4987e..4fc124e 100644 (file)
@@ -96,31 +96,30 @@ bool FullyConnectedLayer::fullyConnectedQuant8()
   return true;
 }
 
-void FullyConnectedLayer::configure(
-    uint8_t *inputData, const ::neurun::internal::operand::Shape inputShape, uint8_t *weightsData,
-    const ::neurun::internal::operand::Shape weightsShape, uint8_t *biasData,
-    const ::neurun::internal::operand::Shape biasShape, FuseCode activation, uint8_t *outputData,
-    const ::neurun::internal::operand::Shape outputShape)
+void FullyConnectedLayer::configure(uint8_t *inputData, const Shape inputShape,
+                                    uint8_t *weightsData, const Shape weightsShape,
+                                    uint8_t *biasData, const Shape biasShape, FuseCode activation,
+                                    uint8_t *outputData, const Shape outputShape)
 {
   _inputData = inputData;
-  _inputShape = convertShape(inputShape);
-  _inputType = inputShape.type();
+  _inputShape = inputShape;
+  _inputType = inputShape.type;
   _weightsData = weightsData;
-  _weightsShape = convertShape(weightsShape);
+  _weightsShape = weightsShape;
   _biasData = biasData;
-  _biasShape = convertShape(biasShape);
+  _biasShape = biasShape;
   _activation = activation;
   _outputData = outputData;
-  _outputShape = convertShape(outputShape);
+  _outputShape = outputShape;
 }
 
 void FullyConnectedLayer::run()
 {
-  if (_inputType == static_cast<uint32_t>(OperandType::TENSOR_FLOAT32))
+  if (_inputType == OperandType::TENSOR_FLOAT32)
   {
     fullyConnectedFloat32();
   }
-  else if (_inputType == static_cast<uint32_t>(OperandType::TENSOR_QUANT8_ASYMM))
+  else if (_inputType == OperandType::TENSOR_QUANT8_ASYMM)
   {
     fullyConnectedQuant8();
   }
index 7a21680..ba1666d 100644 (file)
@@ -27,11 +27,9 @@ public:
 
   bool fullyConnectedQuant8();
 
-  void configure(uint8_t *inputData, const ::neurun::internal::operand::Shape inputShape,
-                 uint8_t *weightsData, const ::neurun::internal::operand::Shape weightsShape,
-                 uint8_t *biasData, const ::neurun::internal::operand::Shape biasShape,
-                 FuseCode activation, uint8_t *outputData,
-                 const ::neurun::internal::operand::Shape outputShape);
+  void configure(uint8_t *inputData, const Shape inputShape, uint8_t *weightsData,
+                 const Shape weightsShape, uint8_t *biasData, const Shape biasShape,
+                 FuseCode activation, uint8_t *outputData, const Shape outputShape);
 
   void run();
 
@@ -48,7 +46,7 @@ private:
 
   FuseCode _activation;
 
-  int32_t _inputType;
+  OperandType _inputType;
 };
 
 } // namespace cpu
index f45c068..d40275e 100644 (file)
@@ -49,18 +49,17 @@ bool MaxPoolLayer::maxPoolQuant8()
   return true;
 }
 
-void MaxPoolLayer::configure(uint8_t *inputData,
-                             const ::neurun::internal::operand::Shape inputShape,
-                             const uint32_t paddingLeft, const uint32_t paddingRight,
-                             const uint32_t paddingTop, const uint32_t paddingBottom,
-                             const uint32_t strideWidth, const uint32_t strideHeight,
-                             const uint32_t kernelWidth, const uint32_t kernelHeight,
-                             const FuseCode activation, uint8_t *outputData,
-                             const ::neurun::internal::operand::Shape outputShape)
+void MaxPoolLayer::configure(uint8_t *inputData, const Shape inputShape, const uint32_t paddingLeft,
+                             const uint32_t paddingRight, const uint32_t paddingTop,
+                             const uint32_t paddingBottom, const uint32_t strideWidth,
+                             const uint32_t strideHeight, const uint32_t kernelWidth,
+                             const uint32_t kernelHeight, const FuseCode activation,
+                             uint8_t *outputData, const Shape outputShape)
 {
   _inputData = inputData;
-  _inputShape = convertShape(inputShape);
-  _inputType = inputShape.type();
+
+  _inputShape = inputShape;
+  _inputType = inputShape.type;
   _paddingLeft = paddingLeft;
   _paddingRight = paddingRight;
   _paddingTop = paddingTop;
@@ -71,16 +70,16 @@ void MaxPoolLayer::configure(uint8_t *inputData,
   _kernelHeight = kernelHeight;
   _activation = activation;
   _outputData = outputData;
-  _outputShape = convertShape(outputShape);
+  _outputShape = outputShape;
 }
 
 void MaxPoolLayer::run()
 {
-  if (_inputType == static_cast<uint32_t>(OperandType::TENSOR_FLOAT32))
+  if (_inputType == OperandType::TENSOR_FLOAT32)
   {
     maxPoolFloat32();
   }
-  else if (_inputType == static_cast<uint32_t>(OperandType::TENSOR_QUANT8_ASYMM))
+  else if (_inputType == OperandType::TENSOR_QUANT8_ASYMM)
   {
     maxPoolQuant8();
   }
index 405073c..219bbc6 100644 (file)
@@ -27,12 +27,12 @@ public:
 
   bool maxPoolQuant8();
 
-  void configure(uint8_t *inputData, const ::neurun::internal::operand::Shape inputShape,
-                 const uint32_t paddingLeft, const uint32_t paddingRight, const uint32_t paddingTop,
+  void configure(uint8_t *inputData, const Shape inputShape, const uint32_t paddingLeft,
+                 const uint32_t paddingRight, const uint32_t paddingTop,
                  const uint32_t paddingBottom, const uint32_t strideWidth,
                  const uint32_t strideHeight, const uint32_t kernelWidth,
                  const uint32_t kernelHeight, const FuseCode activation, uint8_t *outputData,
-                 const ::neurun::internal::operand::Shape outputShape);
+                 const Shape outputShape);
 
   void run();
 
@@ -55,7 +55,7 @@ private:
 
   FuseCode _activation;
 
-  uint32_t _inputType;
+  OperandType _inputType;
 };
 
 } // namespace cpu
index bd56311..5580027 100644 (file)
@@ -168,13 +168,13 @@ int32_t CalculateInputRadius(int input_integer_bits, int input_left_shift)
   return static_cast<int32_t>(std::floor(max_input_rescaled));
 }
 
-Shape convertShape(const ::neurun::internal::operand::Shape &o)
+Shape getShape(const ::neurun::internal::operand::Object &o)
 {
   Shape shape;
 
-  shape.type = static_cast<OperandType>(o.type());
-  shape.dimensions = std::vector<uint32_t>(o.dims().begin(), o.dims().end());
-  shape.scale = o.scale();
+  shape.type = static_cast<OperandType>(static_cast<int32_t>(o.typeInfo().type()));
+  shape.dimensions = std::vector<uint32_t>(o.shape().dims().begin(), o.shape().dims().end());
+  shape.scale = o.shape().scale();
   // shape.offset = _offset;
 
   return shape;
index d13a065..c3ace90 100644 (file)
@@ -85,7 +85,7 @@ void CalculateActivationRangeUint8(int32_t activation, const Shape &outputShape,
 
 int32_t CalculateInputRadius(int input_integer_bits, int input_left_shift);
 
-Shape convertShape(const ::neurun::internal::operand::Shape &o);
+Shape getShape(const ::neurun::internal::operand::Object &o);
 
 uint32_t sizeOfData(OperandType type, const std::vector<uint32_t> &dimensions);
 
index 895d3f3..3e5b442 100644 (file)
@@ -35,15 +35,13 @@ bool ReshapeLayer::reshapeGeneric()
   return true;
 }
 
-void ReshapeLayer::configure(uint8_t *inputData,
-                             const ::neurun::internal::operand::Shape &inputShape,
-                             uint8_t *outputData,
-                             const ::neurun::internal::operand::Shape &outputShape)
+void ReshapeLayer::configure(uint8_t *inputData, const Shape &inputShape, uint8_t *outputData,
+                             const Shape &outputShape)
 {
   _inputData = inputData;
-  _inputShape = convertShape(inputShape);
+  _inputShape = inputShape;
   _outputData = outputData;
-  _outputShape = convertShape(outputShape);
+  _outputShape = outputShape;
 }
 
 void ReshapeLayer::run() { reshapeGeneric(); }
index 3610386..5c3e059 100644 (file)
@@ -25,8 +25,8 @@ public:
 public:
   bool reshapeGeneric();
 
-  void configure(uint8_t *inputData, const ::neurun::internal::operand::Shape &inputShape,
-                 uint8_t *outputData, const ::neurun::internal::operand::Shape &outputShape);
+  void configure(uint8_t *inputData, const Shape &inputShape, uint8_t *outputData,
+                 const Shape &outputShape);
 
   void run();
 
index eeb86b3..8d594f2 100644 (file)
@@ -76,26 +76,24 @@ bool SoftMaxLayer::softmaxQuant8()
   return true;
 }
 
-void SoftMaxLayer::configure(uint8_t *inputData,
-                             const ::neurun::internal::operand::Shape &inputShape, const float beta,
-                             uint8_t *outputData,
-                             const ::neurun::internal::operand::Shape &outputShape)
+void SoftMaxLayer::configure(uint8_t *inputData, const Shape &inputShape, const float beta,
+                             uint8_t *outputData, const Shape &outputShape)
 {
   _inputData = inputData;
-  _inputShape = convertShape(inputShape);
-  _inputType = inputShape.type();
+  _inputShape = inputShape;
+  _inputType = inputShape.type;
   _outputData = outputData;
-  _outputShape = convertShape(outputShape);
+  _outputShape = outputShape;
   _beta = beta;
 }
 
 void SoftMaxLayer::run()
 {
-  if (_inputType == static_cast<uint32_t>(OperandType::TENSOR_FLOAT32))
+  if (_inputType == OperandType::TENSOR_FLOAT32)
   {
     softmaxFloat32();
   }
-  else if (_inputType == static_cast<uint32_t>(OperandType::TENSOR_QUANT8_ASYMM))
+  else if (_inputType == OperandType::TENSOR_QUANT8_ASYMM)
   {
     softmaxQuant8();
   }
index 9c395ca..b627ad7 100644 (file)
@@ -27,9 +27,8 @@ public:
 
   bool softmaxQuant8();
 
-  void configure(uint8_t *inputData, const ::neurun::internal::operand::Shape &inputShape,
-                 const float beta, uint8_t *outputData,
-                 const ::neurun::internal::operand::Shape &outputShape);
+  void configure(uint8_t *inputData, const Shape &inputShape, const float beta, uint8_t *outputData,
+                 const Shape &outputShape);
 
   void run();
 
@@ -42,7 +41,7 @@ private:
   Shape _inputShape;
   Shape _outputShape;
 
-  int32_t _inputType;
+  OperandType _inputType;
 };
 
 } // namespace cpu
index 44327ac..00e9147 100644 (file)
@@ -74,7 +74,7 @@ bool TensorConvertFromCommonLayer::convert()
 
 void TensorConvertFromCommonLayer::configure(::internal::common::Tensor *inputTensor,
                                              ::internal::cpu::Tensor *outputTensor,
-                                             const ::neurun::internal::operand::Shape &tensorShape)
+                                             const Shape &tensorShape)
 {
   _inputTensor = inputTensor;
   _outputTensor = outputTensor;
index f10f3fc..56f7bcf 100644 (file)
@@ -47,7 +47,7 @@ public:
   bool convert();
 
   void configure(::internal::common::Tensor *inputTensor, ::internal::cpu::Tensor *outputTensor,
-                 const ::neurun::internal::operand::Shape &tensorShape);
+                 const Shape &tensorShape);
 
   void run();
 
@@ -55,7 +55,7 @@ private:
   ::internal::common::Tensor *_inputTensor;
   ::internal::cpu::Tensor *_outputTensor;
 
-  ::neurun::internal::operand::Shape _tensorShape{1};
+  Shape _tensorShape{1};
 };
 
 } // namespace cpu
index 9cd79c1..7d721f4 100644 (file)
@@ -74,7 +74,7 @@ bool TensorConvertToCommonLayer::convert()
 
 void TensorConvertToCommonLayer::configure(::internal::cpu::Tensor *inputTensor,
                                            ::internal::common::Tensor *outputTensor,
-                                           const ::neurun::internal::operand::Shape &tensorShape)
+                                           const Shape &tensorShape)
 {
   _inputTensor = inputTensor;
   _outputTensor = outputTensor;
index 92d7adb..7e96d1a 100644 (file)
@@ -47,7 +47,7 @@ public:
   bool convert();
 
   void configure(::internal::cpu::Tensor *inputTensor, ::internal::common::Tensor *outputTensor,
-                 const ::neurun::internal::operand::Shape &tensorShape);
+                 const Shape &tensorShape);
 
   void run();
 
@@ -55,7 +55,7 @@ private:
   ::internal::cpu::Tensor *_inputTensor;
   ::internal::common::Tensor *_outputTensor;
 
-  ::neurun::internal::operand::Shape _tensorShape{1};
+  Shape _tensorShape{1};
 };
 
 } // namespace cpu