From 5ba38f9370f0ede0e50c9b212456e1eef8ec4fa3 Mon Sep 17 00:00:00 2001 From: Rafal Walczyna Date: Mon, 7 Jun 2021 11:29:07 +0200 Subject: [PATCH] Add C stubs for ML Trainer API original change: https://review.tizen.org/gerrit/259416 Change-Id: I836832a9a71fb8a07c4063a25939f159a0d321d6 Signed-off-by: Rafal Walczyna --- packaging/webapi-plugins.spec | 2 ++ src/ml/ml.gyp | 6 ++++ src/ml/ml_api.js | 1 + src/ml/ml_instance.cc | 30 +++++++++++++++++++ src/ml/ml_instance.h | 19 ++++++++++++ src/ml/ml_trainer_manager.cc | 40 ++++++++++++++++++++++++++ src/ml/ml_trainer_manager.h | 54 +++++++++++++++++++++++++++++++++++ 7 files changed, 152 insertions(+) create mode 100644 src/ml/ml_trainer_manager.cc create mode 100644 src/ml/ml_trainer_manager.h diff --git a/packaging/webapi-plugins.spec b/packaging/webapi-plugins.spec index 85c327ae..b1c5afbd 100644 --- a/packaging/webapi-plugins.spec +++ b/packaging/webapi-plugins.spec @@ -526,6 +526,8 @@ BuildRequires: pkgconfig(db-util) %if "%{?tizen_feature_ml_support}" == "1" || "%{?unified_build}" == "1" BuildRequires: pkgconfig(nnstreamer) BuildRequires: pkgconfig(capi-ml-inference) +BuildRequires: pkgconfig(nntrainer) +BuildRequires: pkgconfig(ccapi-ml-training) %endif %if "%{?tizen_feature_badge_support}" == "1" || "%{?unified_build}" == "1" diff --git a/src/ml/ml.gyp b/src/ml/ml.gyp index b5a7a9e4..78880e04 100644 --- a/src/ml/ml.gyp +++ b/src/ml/ml.gyp @@ -37,8 +37,12 @@ 'ml_tensors_info_manager.h', 'ml_single_manager.cc', 'ml_single_manager.h', + 'ml_trainer_manager.cc', + 'ml_trainer_manager.h', 'ml_singleshot.cc', 'ml_singleshot.h', + 'ml_trainer.cc', + 'ml_trainer.h', 'ml_utils.cc', 'ml_utils.h', ], @@ -48,6 +52,8 @@ 'packages': [ 'nnstreamer', 'capi-ml-inference', + 'nntrainer', + 'ccapi-ml-training', ] }, }], diff --git a/src/ml/ml_api.js b/src/ml/ml_api.js index 316fb4ed..0dde0e03 100755 --- a/src/ml/ml_api.js +++ b/src/ml/ml_api.js @@ -17,4 +17,5 @@ //= require('ml_common.js'); //= require('ml_single.js'); //= require('ml_pipeline.js'); +//= require('ml_trainer.js'); //= require('ml_manager.js'); diff --git a/src/ml/ml_instance.cc b/src/ml/ml_instance.cc index ba97649d..bf728cf3 100644 --- a/src/ml/ml_instance.cc +++ b/src/ml/ml_instance.cc @@ -1684,6 +1684,36 @@ void MlInstance::MLPipelineValveIsOpen(const picojson::value& args, picojson::ob ReportSuccess(picojson::value{open}, out); } +void MlInstance::MLTrainerLayerSetProperty(const picojson::value& args, picojson::object& out) { +} +void MlInstance::MLTrainerLayerCreate(const picojson::value& args, picojson::object& out) { +} + +void MlInstance::MLTrainerOptimizerSetProperty(const picojson::value& args, picojson::object& out) { +} +void MlInstance::MLTrainerOptimizerCreate(const picojson::value& args, picojson::object& out) { +} + +void MlInstance::MLTrainerModelConstruct(const picojson::value& args, picojson::object& out) { +} +void MlInstance::MLTrainerModelCompile(const picojson::value& args, picojson::object& out) { +} +void MlInstance::MLTrainerModelAddLayer(const picojson::value& args, picojson::object& out) { +} +void MlInstance::MLTrainerModelRun(const picojson::value& args, picojson::object& out) { +} +void MlInstance::MLTrainerModelSummarize(const picojson::value& args, picojson::object& out) { +} +void MlInstance::MLTrainerModelSetDataset(const picojson::value& args, picojson::object& out) { +} +void MlInstance::MLTrainerModelSetOptimizer(const picojson::value& args, picojson::object& out) { +} +void MlInstance::MLTrainerCreateGeneratorDataset(const picojson::value& args, + picojson::object& out) { +} +void MlInstance::MLTrainerCreateFileDataset(const picojson::value& args, picojson::object& out) { +} + #undef CHECK_EXIST #undef CHECK_TYPE #undef CHECK_TYPE_X diff --git a/src/ml/ml_instance.h b/src/ml/ml_instance.h index 5ea36d5d..b99890d1 100644 --- a/src/ml/ml_instance.h +++ b/src/ml/ml_instance.h @@ -22,6 +22,7 @@ #include "ml/ml_pipeline_manager.h" #include "ml/ml_single_manager.h" +#include "ml/ml_trainer_manager.h" #include "nnstreamer/nnstreamer-single.h" #include "nnstreamer/nnstreamer.h" @@ -147,6 +148,24 @@ class MlInstance : public common::ParsedInstance { void MLPipelineValveSetOpen(const picojson::value& args, picojson::object& out); void MLPipelineValveIsOpen(const picojson::value& args, picojson::object& out); + + Trainer trainer_manager_; + + void MLTrainerLayerSetProperty(const picojson::value& args, picojson::object& out); + void MLTrainerLayerCreate(const picojson::value& args, picojson::object& out); + + void MLTrainerOptimizerSetProperty(const picojson::value& args, picojson::object& out); + void MLTrainerOptimizerCreate(const picojson::value& args, picojson::object& out); + + void MLTrainerModelConstruct(const picojson::value& args, picojson::object& out); + void MLTrainerModelCompile(const picojson::value& args, picojson::object& out); + void MLTrainerModelAddLayer(const picojson::value& args, picojson::object& out); + void MLTrainerModelRun(const picojson::value& args, picojson::object& out); + void MLTrainerModelSummarize(const picojson::value& args, picojson::object& out); + void MLTrainerModelSetDataset(const picojson::value& args, picojson::object& out); + void MLTrainerModelSetOptimizer(const picojson::value& args, picojson::object& out); + void MLTrainerCreateGeneratorDataset(const picojson::value& args, picojson::object& out); + void MLTrainerCreateFileDataset(const picojson::value& args, picojson::object& out); }; } // namespace ml diff --git a/src/ml/ml_trainer_manager.cc b/src/ml/ml_trainer_manager.cc new file mode 100644 index 00000000..7cc5d078 --- /dev/null +++ b/src/ml/ml_trainer_manager.cc @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2021 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 "ml_trainer_manager.h" + +#include "common/tools.h" +#include "nntrainer/model.h" + +using common::ErrorCode; +using common::PlatformResult; + +namespace train = ml::train; + +namespace extension { +namespace ml { + +TrainerManager::TrainerManager() { + ScopeLogger(); +} + +TrainerManager::~TrainerManager() { + ScopeLogger(); +} + + +} // namespace ml +} // namespace extension diff --git a/src/ml/ml_trainer_manager.h b/src/ml/ml_trainer_manager.h new file mode 100644 index 00000000..17bb5765 --- /dev/null +++ b/src/ml/ml_trainer_manager.h @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2021 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. + */ + +#ifndef ML_ML_TRAINER_MANAGER_H_ +#define ML_ML_TRAINER_MANAGER_H_ + +#include + +#include "common/platform_result.h" +#include "ml_trainer.h" + +#include + +using common::PlatformResult; + +namespace train = ml::train; + +namespace extension { +namespace ml { + +class TrainerManager { + public: + TrainerManager(); + ~TrainerManager(); + + TrainerManager(const TrainerManager&) = delete; + TrainerManager& operator=(const TrainerManager&) = delete; + + private: + int next_model_id_ = 0; + int next_layer_id_ = 0; + int next_optimizer_id_ = 0; + int next_dataset_id_ = 0; + std::map> models_; + std::mutex trainers_mutex_; +}; + +} // namespace ml +} // namespace extension + +#endif // ML_ML_TRAINER_MANAGER_H_ -- 2.34.1