summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author이상규/On-Device Lab(SR)/Principal Engineer/삼성전자 <sg5.lee@samsung.com>2019-04-11 04:12:05 (GMT)
committer이춘석/On-Device Lab(SR)/Staff Engineer/삼성전자 <chunseok.lee@samsung.com>2019-04-11 04:12:05 (GMT)
commit6c9b0771af355f0f106a3d441beb8b3f453b3f90 (patch)
tree3af990394435acf4817fc27b6eedb407d9b0d912
parente4ad757c394e9e558ff9f6d2c7b5145cfe2c95de (diff)
downloadnnfw-6c9b0771af355f0f106a3d441beb8b3f453b3f90.zip
nnfw-6c9b0771af355f0f106a3d441beb8b3f453b3f90.tar.gz
nnfw-6c9b0771af355f0f106a3d441beb8b3f453b3f90.tar.bz2
[neurun] add ExecManager::{setInput,setOutput} unit tests (#4972)
Add unittest for specifying unspecified dimension with setInput and setOutput. Signed-off-by: Sanggyu Lee <sg5.lee@samsung.com>
-rw-r--r--runtimes/neurun/test/interp/ExecManager.cc94
1 files changed, 94 insertions, 0 deletions
diff --git a/runtimes/neurun/test/interp/ExecManager.cc b/runtimes/neurun/test/interp/ExecManager.cc
index bce87a9..2a4027a 100644
--- a/runtimes/neurun/test/interp/ExecManager.cc
+++ b/runtimes/neurun/test/interp/ExecManager.cc
@@ -86,6 +86,58 @@ protected:
_executor = nnfw::cpp14::make_unique<ExecManager>(_graph->shareModel());
}
+
+ void CreateUnspecifiedDimensionsModel()
+ {
+ // Model: one elementwise add operation
+ // model input: lhs, rhs
+ // model output: add result
+ // lhs, rhs, result shape: {1, unknown, 2, 1}
+ // activation: none (constant)
+ std::unique_ptr<neurun::model::Model> model = nnfw::cpp14::make_unique<neurun::model::Model>();
+
+ // Add operands
+
+ operand::Shape shape{1, 0, 2, 1};
+ operand::TypeInfo type{DataType::INT32};
+ operand::Shape shape_scalar(0);
+ operand::TypeInfo type_scalar{DataType::INT32};
+
+ auto operand_lhs = model->operands.append(shape, type);
+ auto operand_rhs = model->operands.append(shape, type);
+
+ auto operand_activation = model->operands.append(shape_scalar, type_scalar);
+ model->operands.at(operand_activation).usage(Usage::CONSTANT);
+ model->operands.at(operand_activation)
+ .data(nnfw::cpp14::make_unique<operand::CachedData>(
+ reinterpret_cast<const uint8_t *>(&_activation_value), 4));
+
+ auto operand_result = model->operands.append(shape, type);
+
+ // Add operations
+
+ operation::AddNode::Param param;
+ param.activation_index = operand_activation;
+ auto input_set = operand::IndexSet{operand_lhs, operand_rhs};
+ auto output_set = operand::IndexSet{operand_result};
+ model->operations.append(
+ nnfw::cpp14::make_unique<operation::AddNode>(input_set, output_set, param));
+
+ // Identify model inputs and outputs
+
+ model->operands.at(operand_lhs).usage(Usage::MODEL_INPUT);
+ model->inputs.append(operand_lhs);
+ model->operands.at(operand_rhs).usage(Usage::MODEL_INPUT);
+ model->inputs.append(operand_rhs);
+ model->operands.at(operand_result).usage(Usage::OPERATION_OUTPUT);
+ model->outputs.append(operand_result);
+
+ _graph = nnfw::cpp14::make_unique<::neurun::graph::Graph>(std::move(model));
+ _graph->finishBuilding();
+
+ _executor = nnfw::cpp14::make_unique<ExecManager>(_graph->shareModel());
+ }
+
virtual void TearDown() { _executor = nullptr; }
std::unique_ptr<::neurun::graph::Graph> _graph{nullptr};
@@ -135,6 +187,48 @@ TEST_F(InterpExecManagerTest, setOutput)
EXPECT_NO_THROW(_executor->setOutput(output, reinterpret_cast<void *>(output_buffer), 16));
}
+TEST_F(InterpExecManagerTest, setInputForUnspecifiedDimensions)
+{
+ CreateUnspecifiedDimensionsModel();
+
+ auto input1 = operand::IO::Index{0};
+ const int32_t input1_buffer[4] = {1, 0, -1, -2};
+
+ operand::TypeInfo operand_type{DataType::INT32};
+ operand::Shape operand_shape{1, 2, 2, 1};
+
+ EXPECT_THROW(_executor->setInput(input1, operand_type, operand_shape,
+ reinterpret_cast<const void *>(input1_buffer), 4),
+ std::runtime_error);
+ EXPECT_THROW(_executor->setInput(input1, operand_type, operand_shape,
+ reinterpret_cast<const void *>(input1_buffer), 12),
+ std::runtime_error);
+ EXPECT_NO_THROW(_executor->setInput(input1, operand_type, operand_shape,
+ reinterpret_cast<const void *>(input1_buffer), 16));
+}
+
+TEST_F(InterpExecManagerTest, setOutputForUnspecifiedDimensions)
+{
+ CreateUnspecifiedDimensionsModel();
+
+ auto output = operand::IO::Index{0};
+ auto output_idx = _graph->getOutputs().at(output);
+
+ operand::TypeInfo operand_type{DataType::INT32};
+ operand::Shape operand_shape{1, 2, 2, 1};
+
+ int32_t output_buffer[4] = {};
+
+ EXPECT_THROW(_executor->setOutput(output, operand_type, operand_shape,
+ reinterpret_cast<void *>(output_buffer), 4),
+ std::runtime_error);
+ EXPECT_THROW(_executor->setOutput(output, operand_type, operand_shape,
+ reinterpret_cast<void *>(output_buffer), 12),
+ std::runtime_error);
+ EXPECT_NO_THROW(_executor->setOutput(output, operand_type, operand_shape,
+ reinterpret_cast<void *>(output_buffer), 16));
+}
+
TEST_F(InterpExecManagerTest, execute)
{
CreateSimpleModel();