summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author이상규/On-Device Lab(SR)/Principal Engineer/삼성전자 <sg5.lee@samsung.com>2019-04-10 08:04:14 (GMT)
committer이춘석/On-Device Lab(SR)/Staff Engineer/삼성전자 <chunseok.lee@samsung.com>2019-04-10 08:04:14 (GMT)
commitea76b6388a44fa8943384d8d6e93042aebd28d95 (patch)
tree7b1fff2e3566497461725c7ea705176901f1bd81
parent9f6b712b39856c2cf8bf27c5426ad98635976900 (diff)
downloadnnfw-ea76b6388a44fa8943384d8d6e93042aebd28d95.zip
nnfw-ea76b6388a44fa8943384d8d6e93042aebd28d95.tar.gz
nnfw-ea76b6388a44fa8943384d8d6e93042aebd28d95.tar.bz2
[neurun] Remove type and shape argument from Executor's setInput and setOutput (#4957)
IExecutor, ExecutorBase, ExecManager will have setInput and setOutput that don't require `type` and `shape` parameters. In this case, `type` and `shape` from model will be used. ExecManager test is also modified to use newly introduced setInput and setOutput. Signed-off-by: Sanggyu Lee <sg5.lee@samsung.com>
-rw-r--r--runtimes/neurun/core/include/exec/IExecutor.h18
-rw-r--r--runtimes/neurun/core/src/exec/ExecutorBase.cc55
-rw-r--r--runtimes/neurun/core/src/exec/ExecutorBase.h4
-rw-r--r--runtimes/neurun/core/src/exec/interp/ExecManager.cc34
-rw-r--r--runtimes/neurun/core/src/exec/interp/ExecManager.h14
-rw-r--r--runtimes/neurun/test/interp/ExecManager.cc38
6 files changed, 132 insertions, 31 deletions
diff --git a/runtimes/neurun/core/include/exec/IExecutor.h b/runtimes/neurun/core/include/exec/IExecutor.h
index 0c03843..8c40e6e 100644
--- a/runtimes/neurun/core/include/exec/IExecutor.h
+++ b/runtimes/neurun/core/include/exec/IExecutor.h
@@ -52,6 +52,15 @@ struct IExecutor
/**
* @brief Set input data's information
* @param[in] index Input index
+ * @param[in] buffer Input data's buffer pointer
+ * @param[in] length Input data's length
+ */
+ virtual void setInput(const model::operand::IO::Index &index, const void *buffer,
+ size_t length) = 0;
+ /**
+ * @brief Set input data's information, especially to specify unknown dimensions on model
+ * build time.
+ * @param[in] index Input index
* @param[in] type Input data's type info
* @param[in] shape Input data's shape
* @param[in] buffer Input data's buffer pointer
@@ -63,6 +72,15 @@ struct IExecutor
/**
* @brief Set output data's information
* @param[in] index Output index
+ * @param[in] buffer Output data's buffer pointer
+ * @param[in] length Output data's length
+ */
+ virtual void setOutput(const model::operand::IO::Index &index, void *buffer, size_t length) = 0;
+
+ /**
+ * @brief Set output data's information, especially to specify unknown dimensions on model
+ * build time.
+ * @param[in] index Output index
* @param[in] type Output data's type info
* @param[in] shape Output data's shape
* @param[in] buffer Output data's buffer pointer
diff --git a/runtimes/neurun/core/src/exec/ExecutorBase.cc b/runtimes/neurun/core/src/exec/ExecutorBase.cc
index 46c505d..8948d0a 100644
--- a/runtimes/neurun/core/src/exec/ExecutorBase.cc
+++ b/runtimes/neurun/core/src/exec/ExecutorBase.cc
@@ -55,7 +55,33 @@ void ExecutorBase::setInput(const model::operand::IO::Index &index,
source<uint8_t>(index, buffer, length);
break;
default:
- throw std::runtime_error("Not supported, yet");
+ throw std::runtime_error("Not supported yet");
+ break;
+ }
+}
+
+void ExecutorBase::setInput(const model::operand::IO::Index &index, const void *buffer,
+ size_t length)
+{
+ using ::neurun::model::operand::DataType;
+ const auto idx = _model->inputs.at(index);
+ switch (_model->operands.at(idx).typeInfo().type())
+ {
+ case DataType::FLOAT32:
+ source<float>(index, buffer, length);
+ break;
+ case DataType::INT32:
+ source<int32_t>(index, buffer, length);
+ break;
+ case DataType::UINT32:
+ source<uint32_t>(index, buffer, length);
+ break;
+ case DataType::BOOL8:
+ case DataType::QUANT8_ASYMM:
+ source<uint8_t>(index, buffer, length);
+ break;
+ default:
+ throw std::runtime_error("Not supported yet");
break;
}
}
@@ -81,7 +107,32 @@ void ExecutorBase::setOutput(const model::operand::IO::Index &index,
sink<uint8_t>(index, buffer, length);
break;
default:
- throw std::runtime_error("Not supported, yet");
+ throw std::runtime_error("Not supported yet");
+ break;
+ }
+}
+
+void ExecutorBase::setOutput(const model::operand::IO::Index &index, void *buffer, size_t length)
+{
+ using ::neurun::model::operand::DataType;
+ const auto idx = _model->inputs.at(index);
+ switch (_model->operands.at(idx).typeInfo().type())
+ {
+ case DataType::FLOAT32:
+ sink<float>(index, buffer, length);
+ break;
+ case DataType::INT32:
+ sink<int32_t>(index, buffer, length);
+ break;
+ case DataType::UINT32:
+ sink<uint32_t>(index, buffer, length);
+ break;
+ case DataType::BOOL8:
+ case DataType::QUANT8_ASYMM:
+ sink<uint8_t>(index, buffer, length);
+ break;
+ default:
+ throw std::runtime_error("Not supported yet");
break;
}
}
diff --git a/runtimes/neurun/core/src/exec/ExecutorBase.h b/runtimes/neurun/core/src/exec/ExecutorBase.h
index 5122d3f..ea8b01d 100644
--- a/runtimes/neurun/core/src/exec/ExecutorBase.h
+++ b/runtimes/neurun/core/src/exec/ExecutorBase.h
@@ -45,9 +45,13 @@ public:
const model::Model &model() override { return *_model; }
+ void setInput(const model::operand::IO::Index &index, const void *buffer, size_t length) override;
+
void setInput(const model::operand::IO::Index &index, const model::operand::TypeInfo &type,
const model::operand::Shape &shape, const void *buffer, size_t length) override;
+ void setOutput(const model::operand::IO::Index &index, void *buffer, size_t length) override;
+
void setOutput(const model::operand::IO::Index &index, const model::operand::TypeInfo &type,
const model::operand::Shape &shape, void *buffer, size_t length) override;
diff --git a/runtimes/neurun/core/src/exec/interp/ExecManager.cc b/runtimes/neurun/core/src/exec/interp/ExecManager.cc
index 40dfab7..4436842 100644
--- a/runtimes/neurun/core/src/exec/interp/ExecManager.cc
+++ b/runtimes/neurun/core/src/exec/interp/ExecManager.cc
@@ -45,6 +45,23 @@ void ExecManager::setInput(const neurun::model::operand::IO::Index &index,
_tensor_map.insert({input_index, input_tensor});
}
+void ExecManager::setInput(const neurun::model::operand::IO::Index &index, const void *buffer,
+ size_t length)
+{
+ const auto input_index = _model->inputs.at(index);
+ const TensorInfo info{_model->operands.at(input_index).shape(),
+ _model->operands.at(input_index).typeInfo()};
+
+ if (length < info.total_size())
+ {
+ throw std::runtime_error{"Too small length"};
+ }
+
+ auto input_tensor = std::make_shared<ROTensor>(info);
+ input_tensor->setBuffer(reinterpret_cast<const uint8_t *>(buffer));
+ _tensor_map.insert({input_index, input_tensor});
+}
+
void ExecManager::setOutput(const neurun::model::operand::IO::Index &index,
const neurun::model::operand::TypeInfo &type,
const neurun::model::operand::Shape &shape, void *buffer, size_t length)
@@ -62,6 +79,23 @@ void ExecManager::setOutput(const neurun::model::operand::IO::Index &index,
_tensor_map.insert({output_index, output_tensor});
}
+void ExecManager::setOutput(const neurun::model::operand::IO::Index &index, void *buffer,
+ size_t length)
+{
+ const auto output_index = _model->outputs.at(index);
+ const TensorInfo info{_model->operands.at(output_index).shape(),
+ _model->operands.at(output_index).typeInfo()};
+
+ if (length < info.total_size())
+ {
+ throw std::runtime_error{"Too small length"};
+ }
+
+ auto output_tensor = std::make_shared<Tensor>(info);
+ output_tensor->setBuffer(reinterpret_cast<uint8_t *>(buffer));
+ _tensor_map.insert({output_index, output_tensor});
+}
+
void ExecManager::execute(void)
{
/************************************************************************
diff --git a/runtimes/neurun/core/src/exec/interp/ExecManager.h b/runtimes/neurun/core/src/exec/interp/ExecManager.h
index 51a2c0f..dea6905 100644
--- a/runtimes/neurun/core/src/exec/interp/ExecManager.h
+++ b/runtimes/neurun/core/src/exec/interp/ExecManager.h
@@ -61,6 +61,13 @@ public:
void setInput(const model::operand::IO::Index &index, const model::operand::TypeInfo &type,
const model::operand::Shape &shape, const void *buffer, size_t length);
/**
+ * @brief Set input data's information
+ * @param[in] index Input index
+ * @param[in] buffer Input data's buffer pointer
+ * @param[in] length Input data's length
+ */
+ void setInput(const model::operand::IO::Index &index, const void *buffer, size_t length);
+ /**
* @brief Set output data's information
* @param[in] index Output index
* @param[in] type Output data's type info
@@ -71,6 +78,13 @@ public:
void setOutput(const model::operand::IO::Index &index, const model::operand::TypeInfo &type,
const model::operand::Shape &shape, void *buffer, size_t length);
/**
+ * @brief Set output data's information
+ * @param[in] index Output index
+ * @param[in] buffer Output data's buffer pointer
+ * @param[in] length Output data's length
+ */
+ void setOutput(const model::operand::IO::Index &index, void *buffer, size_t length);
+ /**
* @brief Start execution
* @note It should be called after setting input and output buffer
*/
diff --git a/runtimes/neurun/test/interp/ExecManager.cc b/runtimes/neurun/test/interp/ExecManager.cc
index 0538881..bce87a9 100644
--- a/runtimes/neurun/test/interp/ExecManager.cc
+++ b/runtimes/neurun/test/interp/ExecManager.cc
@@ -110,21 +110,13 @@ TEST_F(InterpExecManagerTest, setInput)
CreateSimpleModel();
auto input1 = operand::IO::Index{0};
- auto input1_idx = _graph->getInputs().at(input1);
-
- auto input1_type = _graph->operands().at(input1_idx).typeInfo();
- auto input1_shape = _graph->operands().at(input1_idx).shape();
-
const int32_t input1_buffer[4] = {1, 0, -1, -2};
- EXPECT_THROW(_executor->setInput(input1, input1_type, input1_shape,
- reinterpret_cast<const void *>(input1_buffer), 4),
+ EXPECT_THROW(_executor->setInput(input1, reinterpret_cast<const void *>(input1_buffer), 4),
std::runtime_error);
- EXPECT_THROW(_executor->setInput(input1, input1_type, input1_shape,
- reinterpret_cast<const void *>(input1_buffer), 12),
+ EXPECT_THROW(_executor->setInput(input1, reinterpret_cast<const void *>(input1_buffer), 12),
std::runtime_error);
- EXPECT_NO_THROW(_executor->setInput(input1, input1_type, input1_shape,
- reinterpret_cast<const void *>(input1_buffer), 16));
+ EXPECT_NO_THROW(_executor->setInput(input1, reinterpret_cast<const void *>(input1_buffer), 16));
}
TEST_F(InterpExecManagerTest, setOutput)
@@ -134,19 +126,13 @@ TEST_F(InterpExecManagerTest, setOutput)
auto output = operand::IO::Index{0};
auto output_idx = _graph->getOutputs().at(output);
- auto output_type = _graph->operands().at(output_idx).typeInfo();
- auto output_shape = _graph->operands().at(output_idx).shape();
-
int32_t output_buffer[4] = {};
- EXPECT_THROW(_executor->setOutput(output, output_type, output_shape,
- reinterpret_cast<void *>(output_buffer), 4),
+ EXPECT_THROW(_executor->setOutput(output, reinterpret_cast<void *>(output_buffer), 4),
std::runtime_error);
- EXPECT_THROW(_executor->setOutput(output, output_type, output_shape,
- reinterpret_cast<void *>(output_buffer), 12),
+ EXPECT_THROW(_executor->setOutput(output, reinterpret_cast<void *>(output_buffer), 12),
std::runtime_error);
- EXPECT_NO_THROW(_executor->setOutput(output, output_type, output_shape,
- reinterpret_cast<void *>(output_buffer), 16));
+ EXPECT_NO_THROW(_executor->setOutput(output, reinterpret_cast<void *>(output_buffer), 16));
}
TEST_F(InterpExecManagerTest, execute)
@@ -158,9 +144,6 @@ TEST_F(InterpExecManagerTest, execute)
auto input1_idx = _graph->getInputs().at(input1);
auto input2_idx = _graph->getInputs().at(input2);
- auto operand_type = _graph->operands().at(input1_idx).typeInfo();
- auto operand_shape = _graph->operands().at(input1_idx).shape();
-
const int32_t input1_buffer[4] = {1, 0, -1, -2};
const int32_t input2_buffer[4] = {1, 3, 2, 4};
@@ -169,12 +152,9 @@ TEST_F(InterpExecManagerTest, execute)
int32_t output_buffer[4] = {};
- EXPECT_NO_THROW(_executor->setInput(input1, operand_type, operand_shape,
- reinterpret_cast<const void *>(input1_buffer), 16));
- EXPECT_NO_THROW(_executor->setInput(input2, operand_type, operand_shape,
- reinterpret_cast<const void *>(input2_buffer), 16));
- EXPECT_NO_THROW(_executor->setOutput(output, operand_type, operand_shape,
- reinterpret_cast<void *>(output_buffer), 16));
+ EXPECT_NO_THROW(_executor->setInput(input1, reinterpret_cast<const void *>(input1_buffer), 16));
+ EXPECT_NO_THROW(_executor->setInput(input2, reinterpret_cast<const void *>(input2_buffer), 16));
+ EXPECT_NO_THROW(_executor->setOutput(output, reinterpret_cast<void *>(output_buffer), 16));
EXPECT_THROW(_executor->execute(), std::runtime_error);
}