From: 오형석/On-Device Lab(SR)/Staff Engineer/삼성전자 Date: Tue, 19 Mar 2019 06:45:18 +0000 (+0900) Subject: Interpreter unittest (#4783) X-Git-Tag: submit/tizen/20190325.013700~30 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=beba7c0464fe7868de7deebbd45900eef60095e6;p=platform%2Fcore%2Fml%2Fnnfw.git Interpreter unittest (#4783) * Interpreter unittest Introduce interpreter unittest: unittest for ExecManager Signed-off-by: Hyeongseok Oh * Add comment and namespace --- diff --git a/runtimes/neurun/test/interp/ExecManager.cc b/runtimes/neurun/test/interp/ExecManager.cc new file mode 100644 index 0000000..f710ef1 --- /dev/null +++ b/runtimes/neurun/test/interp/ExecManager.cc @@ -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 + +#include + +#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( + reinterpret_cast(&_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(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(graph.shareModel()); + } + virtual void TearDown() { _executor = nullptr; } + + std::unique_ptr _executor{nullptr}; + const int32_t _activation_value{0}; +}; + +TEST_F(InterpExecManagerTest, create_empty) +{ + _executor = nnfw::cpp14::make_unique(std::make_shared()); + ASSERT_NE(_executor, nullptr); +} + +TEST_F(InterpExecManagerTest, create_simple) +{ + CreateSimpleModel(); + ASSERT_NE(_executor, nullptr); +} + +} // namespace