diff options
Diffstat (limited to 'runtimes/neurun/core/src/exec/ExecutionObservers.cc')
-rw-r--r-- | runtimes/neurun/core/src/exec/ExecutionObservers.cc | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/runtimes/neurun/core/src/exec/ExecutionObservers.cc b/runtimes/neurun/core/src/exec/ExecutionObservers.cc new file mode 100644 index 000000000..e6561fe5c --- /dev/null +++ b/runtimes/neurun/core/src/exec/ExecutionObservers.cc @@ -0,0 +1,77 @@ +/* + * 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/ExecutionObservers.h" +#include "util/logging.h" +#include "model/operation/PermuteNode.h" +#include "exec/IExecutor.h" +#include "misc/polymorphic_downcast.h" + +namespace neurun +{ + +namespace exec +{ + +void ProfileObserver::handleBegin(neurun::exec::IExecutor *, const neurun::model::Operation *, + const neurun::backend::Backend *backend) +{ + _timer = backend->config()->timer(); + if (_timer == nullptr) + throw std::runtime_error("To profile backend timer() method must be implemented"); + _timer->handleBegin(); +} + +void ProfileObserver::handleEnd(IExecutor *exec, const model::Operation *node, + const backend::Backend *backend) +{ + _timer->handleEnd(); + const auto timer_res = _timer->getTime(); + + auto node_name = node->getName(); + VERBOSE(ProfileInfo) << "Time for " << node_name << " : " << timer_res << std::endl; + + // fill ExecTime: + bool is_quantized = exec->model().operands.at(node->getInputs().at(0)).typeInfo().type() == + model::DataType::QUANT8_ASYMM; + + uint32_t size = 0; + for (const auto &input : node->getInputs()) + { + size += exec->model().operands.at(input).info().total_size(); + } + for (const auto &output : node->getOutputs()) + { + size += exec->model().operands.at(output).info().total_size(); + } + if (node_name == "Permute") + { + auto *permute_node = + nnfw::misc::polymorphic_downcast<const model::operation::PermuteNode *>(node); + assert(permute_node != nullptr); + _et->updatePermuteTime(permute_node->param().input_backend_ctx->backend, + permute_node->param().output_backend_ctx->backend, is_quantized, size, + timer_res); + } + else + { + _et->updateOperationExecTime(backend, node_name, is_quantized, size, timer_res); + } +}; + +} // namespace exec + +} // namespace neurun |