Interpreter unittest (#4783)
author오형석/On-Device Lab(SR)/Staff Engineer/삼성전자 <hseok82.oh@samsung.com>
Tue, 19 Mar 2019 06:45:18 +0000 (15:45 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Tue, 19 Mar 2019 06:45:18 +0000 (15:45 +0900)
* Interpreter unittest

Introduce interpreter unittest: unittest for ExecManager

Signed-off-by: Hyeongseok Oh <hseok82.oh@samsung.com>
* Add comment and namespace

runtimes/neurun/test/interp/ExecManager.cc [new file with mode: 0644]

diff --git a/runtimes/neurun/test/interp/ExecManager.cc b/runtimes/neurun/test/interp/ExecManager.cc
new file mode 100644 (file)
index 0000000..f710ef1
--- /dev/null
@@ -0,0 +1,101 @@
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <gtest/gtest.h>
+
+#include <cpp14/memory.h>
+
+#include "graph/Graph.h"
+#include "exec/interp/ExecManager.h"
+#include "model/operation/AddNode.h"
+
+namespace
+{
+
+using namespace neurun::model;
+using DataType = neurun::model::operand::DataType;
+using Usage = neurun::model::operand::Usage;
+using ExecManager = neurun::exec::interp::ExecManager;
+using Model = neurun::model::Model;
+
+class InterpExecManagerTest : public ::testing::Test
+{
+protected:
+  virtual void SetUp() {}
+  void CreateSimpleModel()
+  {
+    // Model: one elementwise add operation
+    // model input: lhs, rhs
+    // model output: add result
+    // lhs, rhs, result shape: {1, 2, 2, 1}
+    // activation: none (constant)
+    ::neurun::graph::Graph graph;
+
+    operand::Shape shape{4};
+    shape.dim(0) = 1;
+    shape.dim(1) = 2;
+    shape.dim(2) = 2;
+    shape.dim(3) = 1;
+    operand::TypeInfo type{DataType::TENSOR_INT32, 0, 0};
+    operand::Shape shape_scalar{0};
+    operand::TypeInfo type_scalar{DataType::SCALAR_INT32, 0, 0};
+
+    auto operand_lhs = graph.addOperand(shape, type);
+    auto operand_rhs = graph.addOperand(shape, type);
+    auto input_set = operand::IndexSet{operand_lhs, operand_rhs};
+
+    auto operand_activation = graph.addOperand(shape_scalar, type_scalar);
+    graph.operands().at(operand_activation).usage(Usage::CONSTANT);
+    operation::AddNode::Param param;
+    param.activation_index = operand_activation;
+    graph.setOperandValue(operand_activation,
+                          nnfw::cpp14::make_unique<operand::CachedData>(
+                              reinterpret_cast<const uint8_t *>(&_activation_value), 4));
+
+    auto operand_result = graph.addOperand(shape, type);
+    auto output_set = operand::IndexSet{operand_result};
+
+    graph.operands().at(operand_result).usage(Usage::OPERATION_OUTPUT);
+    graph.addOperation(nnfw::cpp14::make_unique<operation::AddNode>(input_set, output_set, param));
+
+    graph.operands().at(operand_lhs).usage(Usage::MODEL_INPUT);
+    graph.operands().at(operand_rhs).usage(Usage::MODEL_INPUT);
+    graph.addInput(operand_lhs);
+    graph.addInput(operand_rhs);
+    graph.addOutput(operand_rhs);
+    graph.finishBuilding();
+
+    _executor = nnfw::cpp14::make_unique<ExecManager>(graph.shareModel());
+  }
+  virtual void TearDown() { _executor = nullptr; }
+
+  std::unique_ptr<ExecManager> _executor{nullptr};
+  const int32_t _activation_value{0};
+};
+
+TEST_F(InterpExecManagerTest, create_empty)
+{
+  _executor = nnfw::cpp14::make_unique<ExecManager>(std::make_shared<Model>());
+  ASSERT_NE(_executor, nullptr);
+}
+
+TEST_F(InterpExecManagerTest, create_simple)
+{
+  CreateSimpleModel();
+  ASSERT_NE(_executor, nullptr);
+}
+
+} // namespace