summaryrefslogtreecommitdiff
path: root/runtimes/neurun/core/src/exec/Execution.cc
diff options
context:
space:
mode:
Diffstat (limited to 'runtimes/neurun/core/src/exec/Execution.cc')
-rw-r--r--runtimes/neurun/core/src/exec/Execution.cc108
1 files changed, 108 insertions, 0 deletions
diff --git a/runtimes/neurun/core/src/exec/Execution.cc b/runtimes/neurun/core/src/exec/Execution.cc
new file mode 100644
index 000000000..01114d8c8
--- /dev/null
+++ b/runtimes/neurun/core/src/exec/Execution.cc
@@ -0,0 +1,108 @@
+/*
+ * 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 "exec/Execution.h"
+
+#include "util/logging.h"
+
+namespace neurun
+{
+namespace exec
+{
+
+Execution::Execution(const std::shared_ptr<IExecutor> &executor) : _executor{executor}
+{
+ _io_desc.inputs.resize(_executor->model().inputs.size());
+ _io_desc.outputs.resize(_executor->model().outputs.size());
+}
+
+void Execution::setInput(const model::IOIndex &index, const void *buffer, size_t length)
+{
+ const auto input_index = model().inputs.at(index);
+ const auto info = model().operands.at(input_index).info();
+
+ if (length < info.total_size())
+ {
+ throw std::runtime_error{"Too small length"};
+ }
+
+ _io_desc.inputs.at(index.value()) = nnfw::cpp14::make_unique<InputDesc>(info, buffer, length);
+}
+
+void Execution::setInput(const model::IOIndex &index, const model::TypeInfo &type,
+ const model::Shape &shape, const void *buffer, size_t length)
+{
+ const model::OperandInfo info{shape, type};
+
+ if (length < info.total_size())
+ {
+ throw std::runtime_error{"Too small length"};
+ }
+
+ _io_desc.inputs.at(index.value()) = nnfw::cpp14::make_unique<InputDesc>(info, buffer, length);
+}
+
+void Execution::setOutput(const model::IOIndex &index, void *buffer, size_t length)
+{
+ const auto output_index = model().outputs.at(index);
+ const auto info = model().operands.at(output_index).info();
+
+ if (length < info.total_size())
+ {
+ throw std::runtime_error{"Too small length"};
+ }
+
+ _io_desc.outputs.at(index.value()) = nnfw::cpp14::make_unique<OutputDesc>(info, buffer, length);
+}
+
+void Execution::setOutput(const model::IOIndex &index, const model::TypeInfo &type,
+ const model::Shape &shape, void *buffer, size_t length)
+{
+ const model::OperandInfo info{shape, type};
+
+ if (length < info.total_size())
+ {
+ throw std::runtime_error{"Too small length"};
+ }
+
+ _io_desc.outputs.at(index.value()) = nnfw::cpp14::make_unique<OutputDesc>(info, buffer, length);
+}
+
+void Execution::execute()
+{
+ VERBOSE(Execution) << "Start execution" << std::endl;
+
+ _executor->execute(_io_desc);
+
+ VERBOSE(Execution) << "Execution finished" << std::endl;
+}
+
+void Execution::startExecute()
+{
+ VERBOSE(Execution) << "Create asynchronous execution thread" << std::endl;
+
+ _exec_thread = nnfw::cpp14::make_unique<std::thread>(&Execution::execute, this);
+}
+
+void Execution::waitFinish()
+{
+ VERBOSE(Execution) << "Wait to finish execution" << std::endl;
+
+ _exec_thread->join();
+}
+
+} // namespace exec
+} // namespace neurun