Add C stubs for ML Trainer API 69/266469/1
authorRafal Walczyna <r.walczyna@samsung.com>
Mon, 7 Jun 2021 09:29:07 +0000 (11:29 +0200)
committerPiotr Kosko/Tizen API (PLT) /SRPOL/Engineer/Samsung Electronics <p.kosko@samsung.com>
Fri, 12 Nov 2021 10:06:46 +0000 (11:06 +0100)
original change: https://review.tizen.org/gerrit/259416

Change-Id: I836832a9a71fb8a07c4063a25939f159a0d321d6
Signed-off-by: Rafal Walczyna <r.walczyna@samsung.com>
packaging/webapi-plugins.spec
src/ml/ml.gyp
src/ml/ml_api.js
src/ml/ml_instance.cc
src/ml/ml_instance.h
src/ml/ml_trainer_manager.cc [new file with mode: 0644]
src/ml/ml_trainer_manager.h [new file with mode: 0644]

index 85c327a..b1c5afb 100644 (file)
@@ -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"
index b5a7a9e..78880e0 100644 (file)
         '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',
             ]
           },
         }],
index 316fb4e..0dde0e0 100755 (executable)
@@ -17,4 +17,5 @@
 //= require('ml_common.js');
 //= require('ml_single.js');
 //= require('ml_pipeline.js');
+//= require('ml_trainer.js');
 //= require('ml_manager.js');
index ba97649..bf728cf 100644 (file)
@@ -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
index 5ea36d5..b99890d 100644 (file)
@@ -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 (file)
index 0000000..7cc5d07
--- /dev/null
@@ -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 (file)
index 0000000..17bb576
--- /dev/null
@@ -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 <mutex>
+
+#include "common/platform_result.h"
+#include "ml_trainer.h"
+
+#include <nntrainer/model.h>
+
+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<int, std::unique_ptr<train::Model>> models_;
+  std::mutex trainers_mutex_;
+};
+
+}  // namespace ml
+}  // namespace extension
+
+#endif  // ML_ML_TRAINER_MANAGER_H_