/* * 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 &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(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(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(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(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(&Execution::execute, this); } void Execution::waitFinish() { VERBOSE(Execution) << "Wait to finish execution" << std::endl; _exec_thread->join(); } } // namespace exec } // namespace neurun