[neurun] Set type info in internal operand (#2416)
author오형석/동작제어Lab(SR)/Staff Engineer/삼성전자 <hseok82.oh@samsung.com>
Thu, 23 Aug 2018 01:25:30 +0000 (10:25 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Thu, 23 Aug 2018 01:25:30 +0000 (10:25 +0900)
* [neurun] Set type info in internal operand

Assign TypeInfo into internal operand.
It is duplicated data with shape yet.

Signed-off-by: Hyeongseok Oh <hseok82.oh@samsung.com>
* Fix format and remove global namespace prefix

runtimes/neurun/src/frontend/model.cc
runtimes/neurun/src/graph/Graph.cc
runtimes/neurun/src/graph/Graph.h
runtimes/neurun/src/graph/operand/Set.cc
runtimes/neurun/src/graph/operand/Set.h
runtimes/neurun/src/internal/operand/Object.h
runtimes/neurun/test/graph/operand/Set.cc
runtimes/neurun/test/graph/operation/SetIO.cc
runtimes/neurun/test/graph/verifier/Verifier.cc

index 5828024..d7f7f6c 100644 (file)
@@ -79,6 +79,8 @@ int ANeuralNetworksModel_addOperand(ANeuralNetworksModel *model,
   }
 
   ::neurun::internal::operand::Shape shape(type->dimensionCount);
+  ::neurun::internal::operand::TypeInfo typeInfo((OperandCode)(type->type), type->scale,
+                                                 type->zeroPoint);
 
   for (uint32_t axis = 0; axis < type->dimensionCount; ++axis)
   {
@@ -87,7 +89,7 @@ int ANeuralNetworksModel_addOperand(ANeuralNetworksModel *model,
 
   shape.set(type->type, type->scale, type->zeroPoint);
 
-  model->deref().addOperand(shape);
+  model->deref().addOperand(shape, typeInfo);
 
   // NOTE We do NOT allocate CLTensor here as we do not how to interpret this one.
   //      TensorFlow Lite may interpret a rank-4 tensor either as a feature map (with batch) or
index d14fe6c..c3987a4 100644 (file)
@@ -14,10 +14,11 @@ namespace neurun
 namespace graph
 {
 
-operand::Index Graph::addOperand(const ::neurun::internal::operand::Shape &shape)
+operand::Index Graph::addOperand(const ::neurun::internal::operand::Shape &shape,
+                                 const ::neurun::internal::operand::TypeInfo &type)
 {
   assert(_phase == Phase::BUILDING);
-  return _operands.append(shape);
+  return _operands.append(shape, type);
 }
 
 operation::Index Graph::addOperation(std::unique_ptr<operation::Node> &&node)
index 6592d64..cec6ff7 100644 (file)
@@ -63,7 +63,8 @@ public:
 
   // Graph Building
 public:
-  operand::Index addOperand(const ::neurun::internal::operand::Shape &shape);
+  operand::Index addOperand(const ::neurun::internal::operand::Shape &shape,
+                            const ::neurun::internal::operand::TypeInfo &type);
   operation::Index addOperation(std::unique_ptr<operation::Node> &&node);
   void setOperandValue(const operand::Index &ind,
                        std::unique_ptr<::neurun::internal::operand::Data> &&data);
index 7c68120..59d900b 100644 (file)
@@ -7,11 +7,11 @@ namespace graph
 namespace operand
 {
 
-Index Set::append(const internal::Shape &shape)
+Index Set::append(const internal::Shape &shape, const internal::TypeInfo &type)
 {
   uint32_t index = _objects.size();
 
-  _objects.emplace_back(new internal::Object{shape});
+  _objects.emplace_back(new internal::Object{shape, type});
 
   return Index{index};
 }
index d900839..f3dd994 100644 (file)
@@ -4,7 +4,7 @@
 #include <memory>
 #include <vector>
 
-#include "internal/Model.h"
+#include "internal/operand/Object.h"
 #include "Index.h"
 
 namespace neurun
@@ -25,7 +25,7 @@ public:
   Set() = default;
 
 public:
-  Index append(const internal::Shape &);
+  Index append(const internal::Shape &, const internal::TypeInfo &);
 
 public:
   const internal::Object &at(const Index &) const;
index 93e76a5..4e22665 100644 (file)
@@ -8,6 +8,7 @@
 
 #include "Shape.h"
 #include "Data.h"
+#include "TypeInfo.h"
 
 namespace neurun
 {
@@ -28,7 +29,8 @@ enum class OperandUsage
 class Object
 {
 public:
-  explicit Object(const Shape &shape) : _shape{shape}, _usage{OperandUsage::NOT_DEFINED}
+  explicit Object(const Shape &shape, const TypeInfo &type)
+      : _shape{shape}, _type{type}, _usage{OperandUsage::NOT_DEFINED}
   {
     // DO NOTHING
   }
@@ -67,6 +69,7 @@ public:
 
 private:
   const Shape _shape;
+  const TypeInfo _type;
   std::unique_ptr<Data> _data;
   OperandUsage _usage;
 };
index cd679c7..e263277 100644 (file)
@@ -17,8 +17,10 @@ TEST(graph_operand_Set, set_test)
   shape1.dim(2) = 30;
   shape1.dim(3) = 40;
 
-  set.append(shape0);
-  set.append(shape1);
+  ::neurun::internal::operand::TypeInfo type{ANEURALNETWORKS_TENSOR_INT32, 0, 0};
+
+  set.append(shape0, type);
+  set.append(shape1, type);
 
   ASSERT_EQ(set.exist(neurun::graph::operand::Index{0u}), true);
   ASSERT_EQ(set.exist(neurun::graph::operand::Index{1u}), true);
index bc1e15f..46bf1c9 100644 (file)
@@ -17,15 +17,16 @@ TEST(graph_operation_setIO, operation_setIO_conv)
   neurun::graph::Graph graph;
 
   neurun::internal::operand::Shape shape{1u};
+  neurun::internal::operand::TypeInfo type{ANEURALNETWORKS_TENSOR_INT32, 0, 0};
   shape.dim(0) = 3;
 
   // Add Conv
   std::vector<uint32_t> params;
   for (int i = 0; i < 7; ++i)
   {
-    params.emplace_back(graph.addOperand(shape).asInt());
+    params.emplace_back(graph.addOperand(shape, type).asInt());
   }
-  uint32_t outoperand = graph.addOperand(shape).asInt();
+  uint32_t outoperand = graph.addOperand(shape, type).asInt();
 
   using Param = internal::tflite::op::Conv2D::implicit::Param;
   using Node = internal::tflite::op::Conv2D::implicit::Node;
@@ -45,15 +46,16 @@ TEST(graph_operation_setIO, operation_setIO_concat)
   neurun::graph::Graph graph;
 
   neurun::internal::operand::Shape shape{1u};
+  neurun::internal::operand::TypeInfo type{ANEURALNETWORKS_TENSOR_INT32, 0, 0};
   shape.dim(0) = 3;
 
   // Add Concat
   std::vector<uint32_t> params;
   for (int i = 0; i < 7; ++i)
   {
-    params.emplace_back(graph.addOperand(shape).asInt());
+    params.emplace_back(graph.addOperand(shape, type).asInt());
   }
-  uint32_t outoperand = graph.addOperand(shape).asInt();
+  uint32_t outoperand = graph.addOperand(shape, type).asInt();
 
   using Param = internal::tflite::op::Concat::Param;
   using Node = internal::tflite::op::Concat::Node;
index db2fd94..a609063 100644 (file)
@@ -35,10 +35,11 @@ TEST(Verifier, dag_checker)
   neurun::graph::verifier::DAGChecker verifier;
 
   ::neurun::internal::operand::Shape shape{1u};
+  ::neurun::internal::operand::TypeInfo type{ANEURALNETWORKS_TENSOR_INT32, 0, 0};
   shape.dim(0) = 3;
 
-  auto operand1 = graph.addOperand(shape);
-  auto operand2 = graph.addOperand(shape);
+  auto operand1 = graph.addOperand(shape, type);
+  auto operand2 = graph.addOperand(shape, type);
 
   graph.addInput(operand1);
   graph.addOutput(operand2);