From: 오형석/On-Device Lab(SR)/Staff Engineer/삼성전자 Date: Thu, 14 Feb 2019 02:12:03 +0000 (+0900) Subject: Revise frontend model object creation and finish (#4412) X-Git-Tag: submit/tizen/20190325.013700~260 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ce610313b470f8322de36176fc1c877a7f71d34d;p=platform%2Fcore%2Fml%2Fnnfw.git Revise frontend model object creation and finish (#4412) * Revise frontend model object creation and finish - Add log message for fail - Add noexcept keyword to wrapper method - Move duplicate finish call check from wrapper to NNAPI implementation Signed-off-by: Hyeongseok Oh * Return false if exception catched --- diff --git a/runtimes/neurun/src/frontend/model.cc b/runtimes/neurun/src/frontend/model.cc index 4f69305..4c30979 100644 --- a/runtimes/neurun/src/frontend/model.cc +++ b/runtimes/neurun/src/frontend/model.cc @@ -28,17 +28,20 @@ #include "frontend/wrapper/memory.h" #include "model/operation/Node.Include.h" #include "util/TypeConvert.h" +#include "util/logging.h" int ANeuralNetworksModel_create(ANeuralNetworksModel **model) { if (model == nullptr) { + VERBOSE(NNAPI::Model) << "create: Incorrect null pointer parameter" << std::endl; return ANEURALNETWORKS_UNEXPECTED_NULL; } *model = new (std::nothrow) ANeuralNetworksModel{}; if (*model == nullptr) { + VERBOSE(NNAPI::Model) << "create: Fail to create model object" << std::endl; return ANEURALNETWORKS_OUT_OF_MEMORY; } @@ -482,8 +485,21 @@ int ANeuralNetworksModel_finish(ANeuralNetworksModel *model) { if (model == nullptr) { + VERBOSE(NNAPI::Model) << "finish: Incorrect null pointer parameter" << std::endl; return ANEURALNETWORKS_UNEXPECTED_NULL; } - return model->finish(); + if (model->isFinished()) + { + VERBOSE(NNAPI::Model) << "finish: Already finished" << std::endl; + return ANEURALNETWORKS_BAD_STATE; + } + + if (!model->finish()) + { + VERBOSE(NNAPI::Model) << "finish: Fail to generate internal graph" << std::endl; + return ANEURALNETWORKS_BAD_STATE; + } + + return ANEURALNETWORKS_NO_ERROR; } diff --git a/runtimes/neurun/src/frontend/wrapper/model.cc b/runtimes/neurun/src/frontend/wrapper/model.cc index a7a9275..424f436 100644 --- a/runtimes/neurun/src/frontend/wrapper/model.cc +++ b/runtimes/neurun/src/frontend/wrapper/model.cc @@ -17,29 +17,33 @@ #include "model.h" #include "graph/Graph.h" +#include "util/logging.h" // // ANeuralNetworksModel // -ANeuralNetworksModel::ANeuralNetworksModel() +ANeuralNetworksModel::ANeuralNetworksModel() noexcept : _model{new neurun::graph::Graph}, _optional_operands{} { // DO NOTHING } -ResultCode ANeuralNetworksModel::finish() +bool ANeuralNetworksModel::finish() noexcept { - // This function must only be called once for a given model - if (isFinished()) + try { - return ANEURALNETWORKS_BAD_STATE; - } + fillOptionalOperand(); - fillOptionalOperand(); + _model->finishBuilding(); + } + catch (const std::exception &e) + { + VERBOSE(EXCEPTION) << e.what() << '\n'; - _model->finishBuilding(); + return false; + } - return ANEURALNETWORKS_NO_ERROR; + return true; } void ANeuralNetworksModel::fillOptionalOperand(void) diff --git a/runtimes/neurun/src/frontend/wrapper/model.h b/runtimes/neurun/src/frontend/wrapper/model.h index 6491b63..fa25777 100644 --- a/runtimes/neurun/src/frontend/wrapper/model.h +++ b/runtimes/neurun/src/frontend/wrapper/model.h @@ -25,11 +25,11 @@ struct ANeuralNetworksModel { public: - ANeuralNetworksModel(); + ANeuralNetworksModel() noexcept; public: neurun::graph::Graph &deref(void) { return *_model; } - ResultCode finish(); + bool finish() noexcept; bool isFinished() { return !_model->isBuildingPhase(); } void release(std::shared_ptr &model) { model = _model; } void setOptionalOperand(const neurun::model::operand::Index idx)