From 3581865492cc241ef9dd2de989249fccc67e1e95 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EC=98=A4=ED=98=95=EC=84=9D/On-Device=20Lab=28SR=29/Staff?= =?utf8?q?=20Engineer/=EC=82=BC=EC=84=B1=EC=A0=84=EC=9E=90?= Date: Wed, 18 Sep 2019 19:09:46 +0900 Subject: [PATCH] Implement NNAPI synchronous execution function (#7574) Inplement NNAPI ANeuralNetworksExecution_compute function and wrapper Wrapper uses neurun's synchronous execution method Signed-off-by: Hyeongseok Oh --- runtimes/neurun/frontend/nnapi/execution.cc | 17 +++++++++++++++++ .../frontend/nnapi/wrapper/ANeuralNetworksExecution.cc | 16 ++++++++++++++++ .../frontend/nnapi/wrapper/ANeuralNetworksExecution.h | 1 + 3 files changed, 34 insertions(+) diff --git a/runtimes/neurun/frontend/nnapi/execution.cc b/runtimes/neurun/frontend/nnapi/execution.cc index 837cab0..3a1b0ef 100644 --- a/runtimes/neurun/frontend/nnapi/execution.cc +++ b/runtimes/neurun/frontend/nnapi/execution.cc @@ -257,6 +257,23 @@ int ANeuralNetworksExecution_startCompute(ANeuralNetworksExecution *execution, return ANEURALNETWORKS_NO_ERROR; } +int ANeuralNetworksExecution_compute(ANeuralNetworksExecution *execution) +{ + if (execution == nullptr) + { + VERBOSE(NNAPI::Execution) << "Compute: Incorrect null pointer parameter" << std::endl; + return ANEURALNETWORKS_UNEXPECTED_NULL; + } + + if (!execution->execute()) + { + VERBOSE(NNAPI::Execution) << "Compute: Fail to execution" << std::endl; + return ANEURALNETWORKS_BAD_STATE; + } + + return ANEURALNETWORKS_NO_ERROR; +} + void ANeuralNetworksExecution_free(ANeuralNetworksExecution *execution) { delete execution; } int ANeuralNetworksExecution_setInputFromMemory(ANeuralNetworksExecution *execution, int32_t index, diff --git a/runtimes/neurun/frontend/nnapi/wrapper/ANeuralNetworksExecution.cc b/runtimes/neurun/frontend/nnapi/wrapper/ANeuralNetworksExecution.cc index ee621e3..df51886 100644 --- a/runtimes/neurun/frontend/nnapi/wrapper/ANeuralNetworksExecution.cc +++ b/runtimes/neurun/frontend/nnapi/wrapper/ANeuralNetworksExecution.cc @@ -184,6 +184,22 @@ bool ANeuralNetworksExecution::startExecute(void) noexcept return true; } +bool ANeuralNetworksExecution::execute(void) noexcept +{ + try + { + _execution->execute(); + } + catch (const std::exception &e) + { + VERBOSE(EXCEPTION) << e.what() << std::endl; + + return false; + } + + return true; +} + const std::shared_ptr ANeuralNetworksExecution::instance(void) noexcept { return _execution; diff --git a/runtimes/neurun/frontend/nnapi/wrapper/ANeuralNetworksExecution.h b/runtimes/neurun/frontend/nnapi/wrapper/ANeuralNetworksExecution.h index 946a12d..6e71887 100644 --- a/runtimes/neurun/frontend/nnapi/wrapper/ANeuralNetworksExecution.h +++ b/runtimes/neurun/frontend/nnapi/wrapper/ANeuralNetworksExecution.h @@ -38,6 +38,7 @@ public: bool setOutput(uint32_t index, const ANeuralNetworksOperandType *type, void *buffer, size_t length) noexcept; bool startExecute(void) noexcept; + bool execute(void) noexcept; const neurun::model::OperandIndex getInputOperandIndex(int32_t index) noexcept; const neurun::model::OperandIndex getOutputOperandIndex(int32_t index) noexcept; -- 2.7.4