Introduce shape converter (#4428)
author오형석/On-Device Lab(SR)/Staff Engineer/삼성전자 <hseok82.oh@samsung.com>
Fri, 15 Feb 2019 00:12:46 +0000 (09:12 +0900)
committer박세희/On-Device Lab(SR)/Principal Engineer/삼성전자 <saehie.park@samsung.com>
Fri, 15 Feb 2019 00:12:46 +0000 (09:12 +0900)
Introduce shape converter from NNAPI operand type to neurun shape

Signed-off-by: Hyeongseok Oh <hseok82.oh@samsung.com>
runtimes/neurun/src/util/TypeConvert.cc
runtimes/neurun/src/util/TypeConvert.h

index a083903..d1b6ddc 100644 (file)
@@ -35,5 +35,17 @@ const model::operand::TypeInfo typeInfoFromOperandType(const ANeuralNetworksOper
                                   type->zeroPoint);
 }
 
+const model::operand::Shape shapeFromOperandType(const ANeuralNetworksOperandType *type)
+{
+  model::operand::Shape shape(type->dimensionCount);
+
+  for (uint32_t axis = 0; axis < type->dimensionCount; ++axis)
+  {
+    shape.dim(axis) = type->dimensions[axis];
+  }
+
+  return shape;
+}
+
 } // namespace util
 } // namespace neurun
index 2f1a056..070fef5 100644 (file)
@@ -25,6 +25,7 @@
 #include <NeuralNetworks.h>
 
 #include "model/operand/TypeInfo.h"
+#include "model/operand/Shape.h"
 
 namespace neurun
 {
@@ -48,6 +49,13 @@ model::operand::DataType typeFromOperandCode(OperandCode type);
  */
 const model::operand::TypeInfo typeInfoFromOperandType(const ANeuralNetworksOperandType *type);
 
+/**
+ * @brief     Convert operand shape info from NNAPI to internal operand shape
+ * @param[in] type  NNAPI's operand type
+ * @return    neurun's internal operand shape
+ */
+const model::operand::Shape shapeFromOperandType(const ANeuralNetworksOperandType *type);
+
 } // namespace neurun
 } // namespace util