From 57242977c5e8f929bd125e236a781b9bbc52753d Mon Sep 17 00:00:00 2001 From: Marcin Kaminski Date: Fri, 28 Jan 2022 21:18:41 +0100 Subject: [PATCH 01/16] [ML][Training] Thread-safe locks Changes: - mutex added to model object to lock single model when compiling or in training - mutex added for synchronizing models map operations between dispose() and run() Change-Id: I56f80d5beb9f0d93f346d64849bea5aa583e506d --- src/ml/ml_trainer_manager.cc | 88 +++++++++++++++++++++++++++++++++++++++++--- src/ml/ml_trainer_manager.h | 7 ++++ src/ml/ml_trainer_objects.h | 4 ++ 3 files changed, 93 insertions(+), 6 deletions(-) diff --git a/src/ml/ml_trainer_manager.cc b/src/ml/ml_trainer_manager.cc index 00795d5..2f3fcaf 100644 --- a/src/ml/ml_trainer_manager.cc +++ b/src/ml/ml_trainer_manager.cc @@ -79,6 +79,7 @@ PlatformResult TrainerManager::ModelCompile(int id, } auto& model = models_[id]; + std::lock_guard modelLock(model->instanceLock); std::stringstream ss; for (const auto& opt : options) { @@ -124,12 +125,19 @@ PlatformResult TrainerManager::ModelRun(int id, const picojson::object& options) { ScopeLogger(); + // lock the models_ map operations to avoid conflicting with disposal function + models_map_lock_.lock(); if (models_.find(id) == models_.end()) { LoggerE("Could not find model with id: %d", id); + models_map_lock_.unlock(); return PlatformResult(ErrorCode::ABORT_ERR, "Could not find model"); } auto& model = models_[id]; + std::lock_guard modelLock(model->instanceLock); + // model instance is securely locked for other operations + // so it's safe to unlock map now + models_map_lock_.unlock(); if (!model->isCompiled()) { LoggerE("Trying to train model that is not compiled"); @@ -182,16 +190,25 @@ PlatformResult TrainerManager::ModelAddLayer(int id, int layerId) { return PlatformResult(ErrorCode::ABORT_ERR, "Could not find model"); } + auto& model = models_[id]; + bool available = model->instanceLock.try_lock(); + if (!available) { + LoggerE("Model locked - probaly training in progress"); + return PlatformResult(ErrorCode::NO_MODIFICATION_ALLOWED_ERR, + "Model training in progress - cannot modify"); + } + if (layers_.find(layerId) == layers_.end()) { LoggerE("Could not find layer with id: %d", id); + model->instanceLock.unlock(); return PlatformResult(ErrorCode::ABORT_ERR, "Could not find layer"); } - auto& model = models_[id]; auto& layer = layers_[layerId]; if (model->isCompiled()) { LoggerE("Modification of compiled model"); + model->instanceLock.unlock(); return PlatformResult(ErrorCode::INVALID_STATE_ERR, "Modification of compiled model not allowed"); } @@ -201,12 +218,14 @@ PlatformResult TrainerManager::ModelAddLayer(int id, int layerId) { if (ret_val != ML_ERROR_NONE) { LoggerE("Could not add layer to model: %d (%s)", ret_val, ml_strerror(ret_val)); + model->instanceLock.unlock(); return PlatformResult(ErrorCode::ABORT_ERR, ml_strerror(ret_val)); } model->layerIndices.push_back(layerId); layer->setAttached(true); + model->instanceLock.unlock(); return PlatformResult(); } @@ -218,15 +237,25 @@ PlatformResult TrainerManager::ModelSetOptimizer(int id, int optimizerId) { return PlatformResult(ErrorCode::ABORT_ERR, "Could not find model"); } + auto& model = models_[id]; + bool available = model->instanceLock.try_lock(); + if (!available) { + LoggerE("Model locked - probaly training in progress"); + return PlatformResult(ErrorCode::NO_MODIFICATION_ALLOWED_ERR, + "Model training in progress - cannot modify"); + } + if (optimizers_.find(optimizerId) == optimizers_.end()) { LoggerE("Could not find optimizer with id: %d", id); + model->instanceLock.unlock(); return PlatformResult(ErrorCode::ABORT_ERR, "Could not find optimizer"); } - auto& model = models_[id]; auto& optimizer = optimizers_[optimizerId]; + if (model->isCompiled()) { LoggerE("Modification of compiled model"); + model->instanceLock.unlock(); return PlatformResult(ErrorCode::INVALID_STATE_ERR, "Modification of compiled model not allowed"); } @@ -236,6 +265,7 @@ PlatformResult TrainerManager::ModelSetOptimizer(int id, int optimizerId) { if (ret_val != ML_ERROR_NONE) { LoggerE("Could not set optimizer for model: %d (%s)", ret_val, ml_strerror(ret_val)); + model->instanceLock.unlock(); return PlatformResult(ErrorCode::ABORT_ERR, ml_strerror(ret_val)); } @@ -255,6 +285,7 @@ PlatformResult TrainerManager::ModelSetOptimizer(int id, int optimizerId) { model->optimizerIndex = optimizerId; optimizer->setAttached(true); + model->instanceLock.unlock(); return PlatformResult(); } @@ -266,16 +297,25 @@ PlatformResult TrainerManager::ModelSetDataset(int id, int datasetId) { return PlatformResult(ErrorCode::ABORT_ERR, "Could not find model"); } + auto& model = models_[id]; + bool available = model->instanceLock.try_lock(); + if (!available) { + LoggerE("Model locked - probaly training in progress"); + return PlatformResult(ErrorCode::NO_MODIFICATION_ALLOWED_ERR, + "Model training in progress - cannot modify"); + } + if (datasets_.find(datasetId) == datasets_.end()) { LoggerE("Could not find dataset with id: %d", id); + model->instanceLock.unlock(); return PlatformResult(ErrorCode::ABORT_ERR, "Could not find dataset"); } - auto& model = models_[id]; auto& dataset = datasets_[datasetId]; if (model->isCompiled()) { LoggerE("Modification of compiled model"); + model->instanceLock.unlock(); return PlatformResult(ErrorCode::INVALID_STATE_ERR, "Modification of compiled model not allowed"); } @@ -285,6 +325,7 @@ PlatformResult TrainerManager::ModelSetDataset(int id, int datasetId) { if (ret_val != ML_ERROR_NONE) { LoggerE("Could not set dataset for model: %d (%s)", ret_val, ml_strerror(ret_val)); + model->instanceLock.unlock(); return PlatformResult(ErrorCode::ABORT_ERR, ml_strerror(ret_val)); } @@ -303,6 +344,7 @@ PlatformResult TrainerManager::ModelSetDataset(int id, int datasetId) { model->datasetIndex = datasetId; dataset->setAttached(true); + model->instanceLock.unlock(); return PlatformResult(); } @@ -317,6 +359,8 @@ PlatformResult TrainerManager::ModelSummarize(int id, } auto& model = models_[id]; + std::lock_guard modelLock(model->instanceLock); + char* tmpSummary = NULL; int ret_val = @@ -345,6 +389,12 @@ PlatformResult TrainerManager::ModelSave(int id, } auto& model = models_[id]; + bool available = model->instanceLock.try_lock(); + if (!available) { + LoggerE("Model locked - probaly training in progress"); + return PlatformResult(ErrorCode::NO_MODIFICATION_ALLOWED_ERR, + "Model training in progress - cannot save"); + } auto tmpString = path; if (tmpString.substr(0, FILE_PATH_PREFIX.length()) == FILE_PATH_PREFIX) { @@ -356,6 +406,8 @@ PlatformResult TrainerManager::ModelSave(int id, int ret_val = ml_train_model_save(model->getNative(), tmpString.c_str(), format); + model->instanceLock.unlock(); + if (ret_val != ML_ERROR_NONE) { LoggerE("Could not model to file: %d (%s)", ret_val, ml_strerror(ret_val)); return PlatformResult(ErrorCode::ABORT_ERR, ml_strerror(ret_val)); @@ -367,6 +419,9 @@ PlatformResult TrainerManager::ModelSave(int id, PlatformResult TrainerManager::ModelDispose(int id) { ScopeLogger(); + // lock the models_ map operations to avoid conflicting with model training + std::lock_guard model_lock(models_map_lock_); + if (models_.find(id) == models_.end()) { LoggerE("Could not find model with id: %d", id); return PlatformResult(ErrorCode::NOT_FOUND_ERR, "Could not find model"); @@ -374,12 +429,23 @@ PlatformResult TrainerManager::ModelDispose(int id) { auto model = models_[id]; + bool available = model->instanceLock.try_lock(); + if (!available) { + LoggerE("Could not lock model for disposal - probaly training in progress"); + return PlatformResult(ErrorCode::NO_MODIFICATION_ALLOWED_ERR, + "Model training in progress - disposal not allowed"); + } + int ret_val = ml_train_model_destroy(model->getNative()); if (ret_val != ML_ERROR_NONE) { LoggerE("Could not destroy model: %d (%s)", ret_val, ml_strerror(ret_val)); + model->instanceLock.unlock(); return PlatformResult(ErrorCode::ABORT_ERR, ml_strerror(ret_val)); } + // erase model from map and use a shared pointer for related objects removal + models_.erase(id); + // When model is destroyed by ml_train_model_destroy() then all attached // handles (layers, optimizer, dataset) are also destroyed. This means that // after Model disposal all related objects in JS/C++ layer become invalid. @@ -389,16 +455,18 @@ PlatformResult TrainerManager::ModelDispose(int id) { LoggerD("Deleting attached optimizer: %d", model->optimizerIndex); optimizers_.erase(model->optimizerIndex); } + if (model->datasetIndex) { LoggerD("Deleting attached dataset: %d", model->datasetIndex); datasets_.erase(model->datasetIndex); } + for (auto const& ls : model->layerIndices) { LoggerD("Deleting attached layer: %d", ls); layers_.erase(ls); } - models_.erase(id); + model->instanceLock.unlock(); return PlatformResult(); } @@ -417,10 +485,12 @@ PlatformResult TrainerManager::CreateLayer(int& id, layers_[next_layer_id_] = std::make_shared>(n_layer); id = next_layer_id_++; + return PlatformResult(); } -PlatformResult TrainerManager::LayerSetProperty(int id, const std::string& name, +PlatformResult TrainerManager::LayerSetProperty(int id, + const std::string& name, const std::string& value) { ScopeLogger("id: %d, name: %s, value: %s", id, name.c_str(), value.c_str()); @@ -430,6 +500,7 @@ PlatformResult TrainerManager::LayerSetProperty(int id, const std::string& name, } auto layer = layers_[id]; + std::string opt = name + "=" + value; int ret_val = @@ -487,6 +558,7 @@ PlatformResult TrainerManager::CreateOptimizer(int& id, optimizers_[next_optimizer_id_] = std::make_shared>(n_optimizer); id = next_optimizer_id_++; + return PlatformResult(); } @@ -501,6 +573,7 @@ PlatformResult TrainerManager::OptimizerSetProperty(int id, } auto optimizer = optimizers_[id]; + std::string opt = name + "=" + value; int ret_val = ml_train_optimizer_set_property(optimizer->getNative(), opt.c_str(), NULL); @@ -542,7 +615,8 @@ PlatformResult TrainerManager::OptimizerDispose(int id) { return PlatformResult(); } -PlatformResult TrainerManager::CreateFileDataset(int& id, const std::string train_file, +PlatformResult TrainerManager::CreateFileDataset(int& id, + const std::string train_file, const std::string valid_file, const std::string test_file) { ScopeLogger(); @@ -607,6 +681,7 @@ PlatformResult TrainerManager::CreateFileDataset(int& id, const std::string trai datasets_[next_dataset_id_] = std::make_shared>(n_dataset); id = next_dataset_id_++; + return PlatformResult(); } @@ -625,6 +700,7 @@ PlatformResult TrainerManager::DatasetSetProperty( } auto dataset = datasets_[id]; + std::string opt = name + "=" + value; int ret_val = ml_train_dataset_set_property_for_mode(dataset->getNative(), diff --git a/src/ml/ml_trainer_manager.h b/src/ml/ml_trainer_manager.h index 4e38c5a..4ed91b8 100644 --- a/src/ml/ml_trainer_manager.h +++ b/src/ml/ml_trainer_manager.h @@ -17,6 +17,8 @@ #ifndef ML_ML_TRAINER_MANAGER_H_ #define ML_ML_TRAINER_MANAGER_H_ +#include + #include #include "common/platform_result.h" @@ -78,6 +80,11 @@ class TrainerManager { std::map>> optimizers_; std::map>> layers_; std::map>> datasets_; + + // mutex for thread synchronization is needed only for model as only + // the model operations can be run in separate threads (model training to be + // precise) + std::mutex models_map_lock_; }; } // namespace ml diff --git a/src/ml/ml_trainer_objects.h b/src/ml/ml_trainer_objects.h index e826369..a506c9b 100644 --- a/src/ml/ml_trainer_objects.h +++ b/src/ml/ml_trainer_objects.h @@ -23,6 +23,7 @@ then the C library explodes. **/ +#include #include #include @@ -59,6 +60,9 @@ class Model { int datasetIndex; int optimizerIndex; std::vector layerIndices; + // additional mutex for locking single model in different operations + // (like run(), compile() or dispose()) without locking the full models' map + std::mutex instanceLock; }; template -- 2.7.4 From c6dc0f0fb43bd1211e84a1e2d32cabfaf3bc336c Mon Sep 17 00:00:00 2001 From: "Piotr Kosko/Tizen API (PLT) /SRPOL/Engineer/Samsung Electronics" Date: Thu, 10 Feb 2022 15:36:51 +0100 Subject: [PATCH 02/16] [ML] Train - added a test method for trained model [ACR] https://code.sec.samsung.net/jira/browse/TWDAPI-285 [Verification] Code compiles without errors. Verification method is available in JS console. var trainsetFile = "documents/trainingSet.dat"; var validsetFile = "documents/valSet.dat"; // TODO should support virtual roots var outputFile = "/home/owner/media/Documents/webapi_tizen_model.bin" var m = tizen.ml.trainer.createModel() var l1 = tizen.ml.trainer.createLayer("LAYER_IN") l1.setProperty("input_shape", "1:1:62720") l1.setProperty("normalization", "true") l1.setProperty("name", "inputlayer") m.addLayer(l1) var l2 = tizen.ml.trainer.createLayer("LAYER_FC") l2.setProperty("unit", "10") l2.setProperty("activation", "softmax") l2.setProperty("bias_initializer", "zeros") l2.setProperty("weight_regularizer", "l2norm") l2.setProperty("weight_regularizer_constant", "0.005") l2.setProperty("weight_initializer", "xavier_uniform") l2.setProperty("name", "fc1") l2.setProperty("input_layers", "inputlayer") m.addLayer(l2) var opt = tizen.ml.trainer.createOptimizer("OPTIMIZER_ADAM") opt.setProperty("learning_rate", "0.0001") opt.setProperty("decay_rate", "0.96") opt.setProperty("decay_steps", "1000") opt.setProperty("beta1", "0.002") opt.setProperty("beta2", "0.001") opt.setProperty("epsilon", "1e-7") m.setOptimizer(opt); var dataset = tizen.ml.trainer.createFileDataset(trainsetFile, validsetFile, /*no test file*/); dataset.setProperty("buffer_size", "100", "MODE_TRAIN"); dataset.setProperty("buffer_size", "100", "MODE_VALID"); m.setDataset(dataset); var compileOpts = { loss: "cross", batch_size: "16" } m.compile(compileOpts); var runOpts = { epochs: "2", save_path: outputFile } m.run(runOpts, (s) => { console.log("success"); console.log("Test result: " + m._checkMetrics(2.163000, 2.267410, 16.666700)); }, (e) => console.log("error " + JSON.stringify(e))); Change-Id: I4760fe341f58f84c985c6e4e4b609bafe36fb4be --- src/ml/js/ml_trainer.js | 24 +++++++++++++++ src/ml/ml_instance.cc | 28 ++++++++++++++++++ src/ml/ml_instance.h | 2 ++ src/ml/ml_trainer_manager.cc | 70 ++++++++++++++++++++++++++++++++++++++++++-- src/ml/ml_trainer_manager.h | 2 ++ 5 files changed, 124 insertions(+), 2 deletions(-) diff --git a/src/ml/js/ml_trainer.js b/src/ml/js/ml_trainer.js index 4c3a841..f1e0712 100755 --- a/src/ml/js/ml_trainer.js +++ b/src/ml/js/ml_trainer.js @@ -430,6 +430,30 @@ Model.prototype.summarize = function() { return result.summary }; +/* +Private method used for verification of training results. +It returns true if the results match given values (with tolerance 1.0e-5), false otherwise. +*/ +Model.prototype._checkMetrics = function (trainLoss, validLoss, validAccuracy) { + var callArgs = { + trainLoss: trainLoss, validLoss: validLoss, validAccuracy: validAccuracy, + id: this._id + } + + var result = native_.callSync('MLTrainerModelCheckMetrics', callArgs); + + if (native_.isFailure(result)) { + throw native_.getErrorObjectAndValidate( + result, + ValidBasicExceptions, + AbortError + ); + } + + return result.result +}; + + var ValidModelSaveExceptions = [ 'InvalidValuesError', 'TypeMismatchError', diff --git a/src/ml/ml_instance.cc b/src/ml/ml_instance.cc index 250eced..bfff53d 100644 --- a/src/ml/ml_instance.cc +++ b/src/ml/ml_instance.cc @@ -193,6 +193,7 @@ MlInstance::MlInstance() REGISTER_METHOD(MLTrainerModelAddLayer); REGISTER_METHOD(MLTrainerModelRun); REGISTER_METHOD(MLTrainerModelSummarize); + REGISTER_METHOD(MLTrainerModelCheckMetrics); REGISTER_METHOD(MLTrainerModelSave); REGISTER_METHOD(MLTrainerModelSetDataset); REGISTER_METHOD(MLTrainerModelSetOptimizer); @@ -1952,6 +1953,33 @@ void MlInstance::MLTrainerModelSummarize(const picojson::value& args, picojson:: ReportSuccess(out); } +void MlInstance::MLTrainerModelCheckMetrics(const picojson::value& args, + picojson::object& out) { + const std::string kTrainLoss = "trainLoss"; + const std::string kValidLoss = "validLoss"; + const std::string kValidAccuracy = "validAccuracy"; + ScopeLogger("args: %s", args.serialize().c_str()); + CHECK_ARGS(args, kId, double, out); + CHECK_ARGS(args, kTrainLoss, double, out); + CHECK_ARGS(args, kValidLoss, double, out); + CHECK_ARGS(args, kValidAccuracy, double, out); + + auto id = static_cast(args.get(kId).get()); + auto train_loss = args.get(kTrainLoss).get(); + auto valid_loss = args.get(kValidLoss).get(); + auto valid_accuracy = args.get(kValidAccuracy).get(); + + bool as_expected = false; + PlatformResult result = trainer_manager_.CheckMetrics( + id, train_loss, valid_loss, valid_accuracy, &as_expected); + if (!result) { + ReportError(result, &out); + return; + } + + ReportSuccess(picojson::value(as_expected), out); +} + void MlInstance::MLTrainerModelSave(const picojson::value& args, picojson::object& out) { ScopeLogger("args: %s", args.serialize().c_str()); diff --git a/src/ml/ml_instance.h b/src/ml/ml_instance.h index cfec0a7..5e3095d 100644 --- a/src/ml/ml_instance.h +++ b/src/ml/ml_instance.h @@ -166,6 +166,8 @@ class MlInstance : public common::ParsedInstance { 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 MLTrainerModelCheckMetrics(const picojson::value& args, + picojson::object& out); void MLTrainerModelSave(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); diff --git a/src/ml/ml_trainer_manager.cc b/src/ml/ml_trainer_manager.cc index 00795d5..d819d56 100644 --- a/src/ml/ml_trainer_manager.cc +++ b/src/ml/ml_trainer_manager.cc @@ -334,8 +334,74 @@ PlatformResult TrainerManager::ModelSummarize(int id, return PlatformResult(); } -PlatformResult TrainerManager::ModelSave(int id, - const std::string& path, +// These values are defined in nntrainer tests +// nntrainer/include/nntrainer_test_util.h file. These defines are just copied +// because mentioned header is not public. +#define ML_TRAIN_SUMMARY_MODEL_TRAIN_LOSS 101 +#define ML_TRAIN_SUMMARY_MODEL_VALID_LOSS 102 +#define ML_TRAIN_SUMMARY_MODEL_VALID_ACCURACY 103 + +PlatformResult TrainerManager::CheckMetrics(int id, double train_loss, + double valid_loss, + double valid_accuracy, bool* res) { + ScopeLogger("Expected train_loss %f, valid_loss: %f, valid_accuracy: %f", + train_loss, valid_loss, valid_accuracy); + const double tolerance = 1.0e-5; + + if (models_.find(id) == models_.end()) { + LoggerE("Could not find model with id: %d", id); + return PlatformResult(ErrorCode::ABORT_ERR, "Could not find model"); + } + + auto& model = models_[id]; + + int status = ML_ERROR_NONE; + char *summary1 = nullptr, *summary2 = nullptr, *summary3 = nullptr; + status = ml_train_model_get_summary( + model->getNative(), + (ml_train_summary_type_e)ML_TRAIN_SUMMARY_MODEL_TRAIN_LOSS, &summary1); + if (status != ML_ERROR_NONE) { + LoggerE("Could not get summary for model: %d (%s)", status, + ml_strerror(status)); + return PlatformResult(ErrorCode::ABORT_ERR, ml_strerror(status)); + } + double train_loss_real = std::strtof(summary1, nullptr); + LoggerE("Train loss value: %f", train_loss_real); + bool result = (train_loss_real - train_loss) < tolerance; + free(summary1); + + status = ml_train_model_get_summary( + model->getNative(), + (ml_train_summary_type_e)ML_TRAIN_SUMMARY_MODEL_VALID_LOSS, &summary2); + if (status != ML_ERROR_NONE) { + LoggerE("Could not get summary for model: %d (%s)", status, + ml_strerror(status)); + return PlatformResult(ErrorCode::ABORT_ERR, ml_strerror(status)); + } + double valid_loss_real = std::strtof(summary2, nullptr); + LoggerE("Valid loss value: %f", valid_loss_real); + result = result && ((valid_loss_real - valid_loss) < tolerance); + free(summary2); + + status = ml_train_model_get_summary( + model->getNative(), + (ml_train_summary_type_e)ML_TRAIN_SUMMARY_MODEL_VALID_ACCURACY, + &summary3); + if (status != ML_ERROR_NONE) { + LoggerE("Could not get summary for model: %d (%s)", status, + ml_strerror(status)); + return PlatformResult(ErrorCode::ABORT_ERR, ml_strerror(status)); + } + double valid_accuracy_real = std::strtof(summary3, nullptr); + LoggerE("Valid accuracy value: %f", valid_accuracy_real); + result = result && ((valid_accuracy_real - valid_accuracy) < tolerance); + free(summary3); + + *res = result; + return PlatformResult(); +}; + +PlatformResult TrainerManager::ModelSave(int id, const std::string& path, ml_train_model_format_e format) { ScopeLogger(); diff --git a/src/ml/ml_trainer_manager.h b/src/ml/ml_trainer_manager.h index 4e38c5a..efd2fca 100644 --- a/src/ml/ml_trainer_manager.h +++ b/src/ml/ml_trainer_manager.h @@ -45,6 +45,8 @@ class TrainerManager { PlatformResult ModelSetDataset(int id, int datasetId); PlatformResult ModelSummarize(int id, ml_train_summary_type_e level, std::string& summary); + PlatformResult CheckMetrics(int id, double train_loss, double valid_loss, + double valid_accuracy, bool* result); PlatformResult ModelSave(int id, const std::string& path, ml_train_model_format_e format); -- 2.7.4 From ea8e050ca2f69a7ba26c9c43044709009e86f578 Mon Sep 17 00:00:00 2001 From: "Piotr Kosko/Tizen API (PLT) /SRPOL/Engineer/Samsung Electronics" Date: Thu, 17 Feb 2022 13:55:11 +0100 Subject: [PATCH 03/16] [ML][Train] Fix of createModelWithConfiguration [ACR] https://code.sec.samsung.net/jira/browse/TWDAPI-285 Change-Id: I1483b69310f2bd942c2c5b4de35a903c1ee04549 --- src/ml/ml_instance.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ml/ml_instance.cc b/src/ml/ml_instance.cc index 250eced..cfd0fef 100644 --- a/src/ml/ml_instance.cc +++ b/src/ml/ml_instance.cc @@ -50,7 +50,7 @@ const std::string kInTensorsInfo = "inTensorsInfo"; const std::string kIsDynamicMode = "isDynamicMode"; const std::string kListenerName = "listenerName"; const std::string kLocation = "location"; -const std::string kModelPath = "modelPath"; +const std::string kModelPath = "configPath"; const std::string kName = "name"; const std::string kNnfw = "nnfw"; const std::string kCustomRequirement = "customRequirement"; -- 2.7.4 From b42688c500d5566d35e763b6242157e49d00ff9c Mon Sep 17 00:00:00 2001 From: "Piotr Kosko/Tizen API (PLT) /SRPOL/Engineer/Samsung Electronics" Date: Fri, 18 Feb 2022 09:20:19 +0100 Subject: [PATCH 04/16] [ML] Train - fix for virtual root [ACR] https://code.sec.samsung.net/jira/browse/TWDAPI-285 [Verification] Code compiles. Checked in chrome console - save_path in run options now supports virtual roots. Change-Id: I77d67875a73441d1638ffbeb99366ad6a7301957 --- src/ml/js/ml_trainer.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ml/js/ml_trainer.js b/src/ml/js/ml_trainer.js index 4c3a841..27d5d2b 100755 --- a/src/ml/js/ml_trainer.js +++ b/src/ml/js/ml_trainer.js @@ -332,7 +332,8 @@ function ValidateRunOptions(options) { args.epochs = options.epochs; } if (options.hasOwnProperty('save_path')) { - args.save_path = options.save_path; + // produce a global path without "file://" prefix + args.save_path = tizen.filesystem.toURI(options.save_path).substring("file://".length); } return args; } -- 2.7.4 From 6b043b4599a28e0df8310242d7a0cc521d82c39c Mon Sep 17 00:00:00 2001 From: "Piotr Kosko/Tizen API (PLT) /SRPOL/Engineer/Samsung Electronics" Date: Mon, 21 Feb 2022 12:51:50 +0100 Subject: [PATCH 05/16] [version] 2.91 Change-Id: I94eaeb841518c62bedcd9ef2bc701502fb714c27 --- packaging/webapi-plugins.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/webapi-plugins.spec b/packaging/webapi-plugins.spec index a5a6dd2..98c2979 100644 --- a/packaging/webapi-plugins.spec +++ b/packaging/webapi-plugins.spec @@ -18,7 +18,7 @@ Name: webapi-plugins -Version: 2.90 +Version: 2.91 Release: 0 License: Apache-2.0 and BSD-3-Clause and MIT Group: Development/Libraries -- 2.7.4 From f3cb7ccc6fc3d97a5507856d42269c798479d3d4 Mon Sep 17 00:00:00 2001 From: Marcin Kaminski Date: Fri, 18 Feb 2022 20:20:32 +0100 Subject: [PATCH 06/16] [ML][Train] Remove denial of Model modification Changes: - removed check and error reporting for setting new dataset after Model has been compiled and trained as it should be possible to train with new data. Change-Id: I144b45979b83ccaa101cf356a393271fdc352a90 --- src/ml/ml_trainer_manager.cc | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/ml/ml_trainer_manager.cc b/src/ml/ml_trainer_manager.cc index 8f87bcc..3070358 100644 --- a/src/ml/ml_trainer_manager.cc +++ b/src/ml/ml_trainer_manager.cc @@ -313,13 +313,6 @@ PlatformResult TrainerManager::ModelSetDataset(int id, int datasetId) { auto& dataset = datasets_[datasetId]; - if (model->isCompiled()) { - LoggerE("Modification of compiled model"); - model->instanceLock.unlock(); - return PlatformResult(ErrorCode::INVALID_STATE_ERR, - "Modification of compiled model not allowed"); - } - int ret_val = ml_train_model_set_dataset(model->getNative(), dataset->getNative()); if (ret_val != ML_ERROR_NONE) { -- 2.7.4 From dd8fb1748f919d884a74967d23bf182dda27b1ed Mon Sep 17 00:00:00 2001 From: "Piotr Kosko/Tizen API (PLT) /SRPOL/Engineer/Samsung Electronics" Date: Wed, 23 Feb 2022 07:43:21 +0100 Subject: [PATCH 07/16] [ML] Fix Coverity issues for fields initialization [Verification] Code compiles without errors. Change-Id: I37afb023e1844943b0a844594181c6bab8223678 --- src/ml/ml_trainer_objects.cc | 7 ++----- src/ml/ml_trainer_objects.h | 2 +- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/ml/ml_trainer_objects.cc b/src/ml/ml_trainer_objects.cc index 9a9aa32..7e4f5e3 100644 --- a/src/ml/ml_trainer_objects.cc +++ b/src/ml/ml_trainer_objects.cc @@ -2,11 +2,8 @@ namespace extension { namespace ml { -Model::Model() { - optimizerIndex = -1; - datasetIndex = -1; - compiled = false; -} +Model::Model() + : native(nullptr), compiled(false), datasetIndex(-1), optimizerIndex(-1) {} Model::Model(ml_train_model_h native_handle) : Model() { native = native_handle; diff --git a/src/ml/ml_trainer_objects.h b/src/ml/ml_trainer_objects.h index a506c9b..98be440 100644 --- a/src/ml/ml_trainer_objects.h +++ b/src/ml/ml_trainer_objects.h @@ -69,7 +69,7 @@ template class NativeWrapper { T native; bool attached; - NativeWrapper() { attached = false; } + NativeWrapper() : native(nullptr), attached(false) {} public: NativeWrapper(T nativeHandle) : NativeWrapper() { native = nativeHandle; } -- 2.7.4 From 5c50eda242d3823839e6d5b587ef62bb0ae030b7 Mon Sep 17 00:00:00 2001 From: "Piotr Kosko/Tizen API (PLT) /SRPOL/Engineer/Samsung Electronics" Date: Wed, 23 Feb 2022 09:40:06 +0100 Subject: [PATCH 08/16] [notification] Fixed log format [Verification] Code compiles for aarch64 Change-Id: Id93e303e118af2e3153d84c253684330d463185a --- src/notification/user_notification.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/notification/user_notification.cc b/src/notification/user_notification.cc index 6282a3b..3b2c7f0 100644 --- a/src/notification/user_notification.cc +++ b/src/notification/user_notification.cc @@ -290,7 +290,7 @@ PlatformResult UserNotification::AddButtonsToJson(notification_h noti_handle, picojson::array buttons_array; for (size_t i = 0; i < buttons_texts_map_.size(); i++) { - LoggerD("processing button %u", i); + LoggerD("processing button %zu", i); picojson::object item; PlatformResult status = AddTextToJson(noti_handle, buttons_texts_map_.at(i), "text", &item); -- 2.7.4 From 35dffc31872cc5caec0f87620cae4f382ed6127e Mon Sep 17 00:00:00 2001 From: Marcin Kaminski Date: Mon, 21 Feb 2022 20:54:43 +0100 Subject: [PATCH 09/16] [ML][Training] Layer name handling Changes: - proper handling of Layer.name attribute at JS level with name storing at C++ level Change-Id: I68782fd386bba3b709c481b9a5ac69f04c7287e0 --- src/ml/js/ml_trainer.js | 23 +++++++++++++++++++++-- src/ml/ml_instance.cc | 19 +++++++++++++++++++ src/ml/ml_instance.h | 2 ++ src/ml/ml_trainer_manager.cc | 22 ++++++++++++++++++++-- src/ml/ml_trainer_manager.h | 3 ++- src/ml/ml_trainer_objects.h | 15 +++++++++++++++ 6 files changed, 79 insertions(+), 5 deletions(-) diff --git a/src/ml/js/ml_trainer.js b/src/ml/js/ml_trainer.js index 1a69a12..81e8d83 100755 --- a/src/ml/js/ml_trainer.js +++ b/src/ml/js/ml_trainer.js @@ -66,12 +66,27 @@ var DatasetMode = { MODE_TEST: 'MODE_TEST' }; +var ValidGetNameExceptions = [ + 'InvalidValuesError', + 'AbortError' +]; + var Layer = function(id, type) { Object.defineProperties(this, { name: { enumerable: true, get: function() { - // TODO + var result = native_.callSync('MLTrainerLayerGetName', { id: this._id }); + + if (native_.isFailure(result)) { + throw native_.getErrorObjectAndValidate( + result, + ValidGetNameExceptions, + AbortError + ); + } + + return result.name } }, type: { @@ -632,7 +647,11 @@ MachineLearningTrainer.prototype.createLayer = function() { ); } - return new Layer(result.id, args.type); + var nLay = new Layer(result.id, args.type); + + nLay.setProperty("name", args.type.toString() + result.id.toString()); + + return nLay; }; function ValidateAndReturnDatasetPaths(train, valid, test) { diff --git a/src/ml/ml_instance.cc b/src/ml/ml_instance.cc index a59ffc8..74fcc6f 100644 --- a/src/ml/ml_instance.cc +++ b/src/ml/ml_instance.cc @@ -184,6 +184,7 @@ MlInstance::MlInstance() REGISTER_METHOD(MLTrainerLayerSetProperty); REGISTER_METHOD(MLTrainerLayerCreate); + REGISTER_METHOD(MLTrainerLayerGetName); REGISTER_METHOD(MLTrainerLayerDispose); REGISTER_METHOD(MLTrainerOptimizerSetProperty); REGISTER_METHOD(MLTrainerOptimizerCreate); @@ -1759,6 +1760,24 @@ void MlInstance::MLTrainerLayerCreate(const picojson::value& args, picojson::obj ReportSuccess(out); } +void MlInstance::MLTrainerLayerGetName(const picojson::value& args, + picojson::object& out) { + ScopeLogger("args: %s", args.serialize().c_str()); + CHECK_ARGS(args, kId, double, out); + + auto id = static_cast(args.get(kId).get()); + + std::string name; + PlatformResult result = trainer_manager_.LayerGetName(id, name); + if (!result) { + ReportError(result, &out); + return; + } + + out[kName] = picojson::value(static_cast(name)); + ReportSuccess(out); +} + void MlInstance::MLTrainerLayerDispose(const picojson::value& args, picojson::object& out) { ScopeLogger("args: %s", args.serialize().c_str()); diff --git a/src/ml/ml_instance.h b/src/ml/ml_instance.h index 5e3095d..fbf5078 100644 --- a/src/ml/ml_instance.h +++ b/src/ml/ml_instance.h @@ -153,6 +153,8 @@ class MlInstance : public common::ParsedInstance { void MLTrainerLayerSetProperty(const picojson::value& args, picojson::object& out); void MLTrainerLayerCreate(const picojson::value& args, picojson::object& out); + void MLTrainerLayerGetName(const picojson::value& args, + picojson::object& out); void MLTrainerLayerDispose(const picojson::value& args, picojson::object& out); diff --git a/src/ml/ml_trainer_manager.cc b/src/ml/ml_trainer_manager.cc index 3070358..86d852b 100644 --- a/src/ml/ml_trainer_manager.cc +++ b/src/ml/ml_trainer_manager.cc @@ -541,8 +541,7 @@ PlatformResult TrainerManager::CreateLayer(int& id, return PlatformResult(ErrorCode::ABORT_ERR, ml_strerror(ret_val)); } - layers_[next_layer_id_] = - std::make_shared>(n_layer); + layers_[next_layer_id_] = std::make_shared(n_layer); id = next_layer_id_++; return PlatformResult(); @@ -569,6 +568,25 @@ PlatformResult TrainerManager::LayerSetProperty(int id, ml_strerror(ret_val)); return PlatformResult(ErrorCode::ABORT_ERR, ml_strerror(ret_val)); } + + if (name == "name") { + LoggerI("Layer name set detected - changing to: %s", value.c_str()); + layer->setName(value); + } + return PlatformResult(); +} + +PlatformResult TrainerManager::LayerGetName(int id, std::string& name) { + ScopeLogger(); + + if (layers_.find(id) == layers_.end()) { + LoggerE("Could not find layer with id: %d", id); + return PlatformResult(ErrorCode::NOT_FOUND_ERR, "Could not find layer"); + } + + auto layer = layers_[id]; + + name = layer->getName(); return PlatformResult(); } diff --git a/src/ml/ml_trainer_manager.h b/src/ml/ml_trainer_manager.h index fd5feb3..009715b 100644 --- a/src/ml/ml_trainer_manager.h +++ b/src/ml/ml_trainer_manager.h @@ -57,6 +57,7 @@ class TrainerManager { PlatformResult CreateLayer(int& id, ml_train_layer_type_e type); PlatformResult LayerSetProperty(int id, const std::string& name, const std::string& value); + PlatformResult LayerGetName(int id, std::string& name); PlatformResult LayerDispose(int id); PlatformResult CreateOptimizer(int& id, ml_train_optimizer_type_e type); @@ -80,7 +81,7 @@ class TrainerManager { std::map> models_; std::map>> optimizers_; - std::map>> layers_; + std::map> layers_; std::map>> datasets_; // mutex for thread synchronization is needed only for model as only diff --git a/src/ml/ml_trainer_objects.h b/src/ml/ml_trainer_objects.h index 98be440..b8c32d0 100644 --- a/src/ml/ml_trainer_objects.h +++ b/src/ml/ml_trainer_objects.h @@ -24,6 +24,7 @@ then the C library explodes. **/ #include +#include #include #include @@ -73,6 +74,8 @@ class NativeWrapper { public: NativeWrapper(T nativeHandle) : NativeWrapper() { native = nativeHandle; } + virtual ~NativeWrapper() = default; + T& operator=(const T&) = delete; T getNative() { return native; } @@ -82,6 +85,18 @@ class NativeWrapper { bool isAttached() { return attached; } }; +class LayerWrapper : public NativeWrapper { + std::string name; + + public: + LayerWrapper(ml_train_layer_h nativeHandle) : NativeWrapper(nativeHandle) {} + virtual ~LayerWrapper() = default; + + void setName(const std::string& newName) { name = newName; } + + std::string getName() { return name; } +}; + } // namespace ml } // namespace extension -- 2.7.4 From be1e0310d152945a3b99ce619b5e087426a852ac Mon Sep 17 00:00:00 2001 From: "Piotr Kosko/Tizen API (PLT) /SRPOL/Engineer/Samsung Electronics" Date: Thu, 24 Feb 2022 08:28:42 +0100 Subject: [PATCH 10/16] [ML] Fix test break for MLSingleshot [Verification] Code compiles. TCT passrate: * ml-tizen 100% * mlpipeline-tizen 100% * mlsingleshot-tizen 100% Change-Id: Ia2ebef7a46600537946f308be5375e274f40df46 --- src/ml/ml_instance.cc | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/ml/ml_instance.cc b/src/ml/ml_instance.cc index a59ffc8..0ba4cc9 100644 --- a/src/ml/ml_instance.cc +++ b/src/ml/ml_instance.cc @@ -50,7 +50,8 @@ const std::string kInTensorsInfo = "inTensorsInfo"; const std::string kIsDynamicMode = "isDynamicMode"; const std::string kListenerName = "listenerName"; const std::string kLocation = "location"; -const std::string kModelPath = "configPath"; +const std::string kModelPath = "modelPath"; +const std::string kConfigPath = "configPath"; const std::string kName = "name"; const std::string kNnfw = "nnfw"; const std::string kCustomRequirement = "customRequirement"; @@ -1833,11 +1834,11 @@ void MlInstance::MLTrainerModelCreate(const picojson::value& args, picojson::obj ScopeLogger("args: %s", args.serialize().c_str()); int id = -1; PlatformResult result; - if (args.contains(kModelPath)) { + if (args.contains(kConfigPath)) { // create model with config file - CHECK_ARGS(args, kModelPath, std::string, out); - const auto& config_path = - common::tools::ConvertUriToPath(args.get(kModelPath).get()); + CHECK_ARGS(args, kConfigPath, std::string, out); + const auto& config_path = common::tools::ConvertUriToPath( + args.get(kConfigPath).get()); CHECK_STORAGE_ACCESS(config_path, &out); result = trainer_manager_.CreateModel(id, config_path); -- 2.7.4 From d69e0aaeb80f4f2f48d609468f4be29e204c7b34 Mon Sep 17 00:00:00 2001 From: "Piotr Kosko/Tizen API (PLT) /SRPOL/Engineer/Samsung Electronics" Date: Mon, 21 Feb 2022 12:56:59 +0100 Subject: [PATCH 11/16] [ML] Train - added load() method implementation [ACR] https://code.sec.samsung.net/jira/browse/TWDAPI-285 [Verification] Code compiles without errors. Verified in chrome console - load() works. var m2 = tizen.ml.trainer.createModel() m2.load("documents/ttt_INI_WITH_BIN.ini", "FORMAT_INI_WITH_BIN") Change-Id: Ic9d248790814dee47f5d0b712fe15e59ee8b93b9 --- src/ml/js/ml_trainer.js | 40 ++++++++++++++++++++++++++++++++++++++++ src/ml/ml_instance.cc | 27 +++++++++++++++++++++++++++ src/ml/ml_instance.h | 1 + src/ml/ml_trainer_manager.cc | 41 ++++++++++++++++++++++++++++++++++++++++- src/ml/ml_trainer_manager.h | 5 +++-- 5 files changed, 111 insertions(+), 3 deletions(-) diff --git a/src/ml/js/ml_trainer.js b/src/ml/js/ml_trainer.js index 81e8d83..8354bec 100755 --- a/src/ml/js/ml_trainer.js +++ b/src/ml/js/ml_trainer.js @@ -516,6 +516,46 @@ Model.prototype.saveToFile = function () { } }; +Model.prototype.load = function () { + var args = validator_.validateArgs(arguments, [ + { + name: 'path', + type: types_.STRING + }, + { + name: 'format', + type: types_.ENUM, + values: Object.values(SaveFormat) + } + ]); + + var callArgs = { + id: this._id, + savePath: args.path, + saveFormat: args.format + } + + try { + callArgs.savePath = tizen.filesystem.toURI(args.path); + } catch (e) { + throw new WebAPIException(WebAPIException.InvalidValuesError, 'Invalid file path given'); + } + + if (!tizen.filesystem.pathExists(callArgs.savePath)) { + throw new WebAPIException(WebAPIException.NotFoundError, 'Path not found'); + } + + var result = native_.callSync('MLTrainerModelLoad', callArgs); + + if (native_.isFailure(result)) { + throw native_.getErrorObjectAndValidate( + result, + ValidModelSaveExceptions, + AbortError + ); + } +}; + Model.prototype.addLayer = function() { var args = validator_.validateArgs(arguments, [ { diff --git a/src/ml/ml_instance.cc b/src/ml/ml_instance.cc index 9a4d447..6e256d7 100644 --- a/src/ml/ml_instance.cc +++ b/src/ml/ml_instance.cc @@ -197,6 +197,7 @@ MlInstance::MlInstance() REGISTER_METHOD(MLTrainerModelSummarize); REGISTER_METHOD(MLTrainerModelCheckMetrics); REGISTER_METHOD(MLTrainerModelSave); + REGISTER_METHOD(MLTrainerModelLoad); REGISTER_METHOD(MLTrainerModelSetDataset); REGISTER_METHOD(MLTrainerModelSetOptimizer); REGISTER_METHOD(MLTrainerModelDispose); @@ -2026,6 +2027,32 @@ void MlInstance::MLTrainerModelSave(const picojson::value& args, ReportSuccess(out); } +void MlInstance::MLTrainerModelLoad(const picojson::value& args, + picojson::object& out) { + ScopeLogger("args: %s", args.serialize().c_str()); + CHECK_ARGS(args, kId, double, out); + CHECK_ARGS(args, kSavePath, std::string, out); + CHECK_ARGS(args, kSaveFormat, std::string, out); + + auto id = static_cast(args.get(kId).get()); + auto path = args.get(kSavePath).get(); + + ml_train_model_format_e model_format = ML_TRAIN_MODEL_FORMAT_INI_WITH_BIN; + PlatformResult result = types::ModelSaveFormatEnum.getValue( + args.get(kSaveFormat).get(), &model_format); + if (!result) { + LogAndReportError(result, &out); + return; + } + + result = trainer_manager_.ModelLoad(id, path, model_format); + if (!result) { + ReportError(result, &out); + return; + } + ReportSuccess(out); +} + void MlInstance::MLTrainerModelSetDataset(const picojson::value& args, picojson::object& out) { ScopeLogger("args: %s", args.serialize().c_str()); CHECK_ARGS(args, kId, double, out); diff --git a/src/ml/ml_instance.h b/src/ml/ml_instance.h index fbf5078..5fed8fa 100644 --- a/src/ml/ml_instance.h +++ b/src/ml/ml_instance.h @@ -171,6 +171,7 @@ class MlInstance : public common::ParsedInstance { void MLTrainerModelCheckMetrics(const picojson::value& args, picojson::object& out); void MLTrainerModelSave(const picojson::value& args, picojson::object& out); + void MLTrainerModelLoad(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 MLTrainerModelDispose(const picojson::value& args, diff --git a/src/ml/ml_trainer_manager.cc b/src/ml/ml_trainer_manager.cc index 86d852b..5afe64d 100644 --- a/src/ml/ml_trainer_manager.cc +++ b/src/ml/ml_trainer_manager.cc @@ -468,7 +468,46 @@ PlatformResult TrainerManager::ModelSave(int id, const std::string& path, model->instanceLock.unlock(); if (ret_val != ML_ERROR_NONE) { - LoggerE("Could not model to file: %d (%s)", ret_val, ml_strerror(ret_val)); + LoggerE("Could not save model to file: %d (%s)", ret_val, + ml_strerror(ret_val)); + return PlatformResult(ErrorCode::ABORT_ERR, ml_strerror(ret_val)); + } + + return PlatformResult(); +} + +PlatformResult TrainerManager::ModelLoad(int id, const std::string& path, + ml_train_model_format_e format) { + ScopeLogger(); + + if (models_.find(id) == models_.end()) { + LoggerE("Could not find model with id: %d", id); + return PlatformResult(ErrorCode::ABORT_ERR, "Could not find model"); + } + + auto& model = models_[id]; + bool available = model->instanceLock.try_lock(); + if (!available) { + LoggerE("Model locked - probaly training in progress"); + return PlatformResult(ErrorCode::NO_MODIFICATION_ALLOWED_ERR, + "Model training in progress - cannot save"); + } + + auto tmpString = path; + if (tmpString.substr(0, FILE_PATH_PREFIX.length()) == FILE_PATH_PREFIX) { + // remove 'file://' prefix from path before passing to native api + tmpString.erase(0, FILE_PATH_PREFIX.length()); + } + + LoggerI("Loading model from file: %s", tmpString.c_str()); + int ret_val = + ml_train_model_load(model->getNative(), tmpString.c_str(), format); + + model->instanceLock.unlock(); + + if (ret_val != ML_ERROR_NONE) { + LoggerE("Could not load model from file: %d (%s)", ret_val, + ml_strerror(ret_val)); return PlatformResult(ErrorCode::ABORT_ERR, ml_strerror(ret_val)); } diff --git a/src/ml/ml_trainer_manager.h b/src/ml/ml_trainer_manager.h index 009715b..4e2b100 100644 --- a/src/ml/ml_trainer_manager.h +++ b/src/ml/ml_trainer_manager.h @@ -49,8 +49,9 @@ class TrainerManager { std::string& summary); PlatformResult CheckMetrics(int id, double train_loss, double valid_loss, double valid_accuracy, bool* result); - PlatformResult ModelSave(int id, - const std::string& path, + PlatformResult ModelSave(int id, const std::string& path, + ml_train_model_format_e format); + PlatformResult ModelLoad(int id, const std::string& path, ml_train_model_format_e format); PlatformResult ModelDispose(int id); -- 2.7.4 From 88ba7a5b0d45c27f762f3a46aabc4f79f8ee58e6 Mon Sep 17 00:00:00 2001 From: Marcin Kaminski Date: Wed, 23 Feb 2022 20:32:50 +0100 Subject: [PATCH 12/16] [ML][Training] Fixing error handling Changes: - proper error returning at JS level - additional check and proper error returned on recompilation trial Change-Id: If209e316553c94acd0a83decfb843b26a07be592 --- src/ml/js/ml_trainer.js | 25 +++++++++++++---- src/ml/ml_trainer_manager.cc | 67 +++++++++++++++++++++++++++++--------------- 2 files changed, 64 insertions(+), 28 deletions(-) diff --git a/src/ml/js/ml_trainer.js b/src/ml/js/ml_trainer.js index 8354bec..e874baf 100755 --- a/src/ml/js/ml_trainer.js +++ b/src/ml/js/ml_trainer.js @@ -100,6 +100,7 @@ var Layer = function(id, type) { var ValidSetPropertyExceptions = [ 'InvalidValuesError', + 'NotSupportedError', 'TypeMismatchError', 'AbortError' ]; @@ -142,6 +143,7 @@ Layer.prototype.setProperty = function() { var ValidDisposeExceptions = [ 'NotFoundError', + 'NoModificationAllowedError', 'AbortError' ]; @@ -305,6 +307,7 @@ function ValidateCompileOptions(options) { var ValidModelCompileExceptions = [ 'InvalidValuesError', 'TypeMismatchError', + 'NoModificationAllowedError', 'AbortError' ]; @@ -355,7 +358,9 @@ function ValidateRunOptions(options) { var ValidModelRunExceptions = [ 'InvalidValuesError', - 'TypeMismatchError' + 'InvalidStateError', + 'TypeMismatchError', + 'AbortError' ]; Model.prototype.run = function() { @@ -473,6 +478,7 @@ Model.prototype._checkMetrics = function (trainLoss, validLoss, validAccuracy) { var ValidModelSaveExceptions = [ 'InvalidValuesError', 'TypeMismatchError', + "NoModificationAllowedError", 'AbortError' ]; @@ -498,7 +504,7 @@ Model.prototype.saveToFile = function () { try { callArgs.savePath = tizen.filesystem.toURI(args.path); } catch (e) { - throw new WebAPIException(WebAPIException.InvalidValuesError, 'Invalid file path given'); + throw new WebAPIException(WebAPIException.INVALID_VALUES_ERR, 'Invalid file path given'); } if (tizen.filesystem.pathExists(callArgs.savePath)) { @@ -581,12 +587,21 @@ Model.prototype.addLayer = function() { if (native_.isFailure(result)) { throw native_.getErrorObjectAndValidate( result, - ValidBasicExceptions, + ValidSetObjectExceptions, AbortError ); } }; +var ValidSetObjectExceptions = [ + 'InvalidValuesError', + 'TypeMismatchError', + 'NoModificationAllowedError', + 'NotSupportedError', + 'NotFound', + 'AbortError' +]; + Model.prototype.setDataset = function() { var args = validator_.validateArgs(arguments, [ { @@ -612,7 +627,7 @@ Model.prototype.setDataset = function() { if (native_.isFailure(result)) { throw native_.getErrorObjectAndValidate( result, - ValidBasicExceptions, + ValidSetObjectExceptions, AbortError ); } @@ -643,7 +658,7 @@ Model.prototype.setOptimizer = function() { if (native_.isFailure(result)) { throw native_.getErrorObjectAndValidate( result, - ValidBasicExceptions, + ValidSetObjectExceptions, AbortError ); } diff --git a/src/ml/ml_trainer_manager.cc b/src/ml/ml_trainer_manager.cc index 5afe64d..22805e8 100644 --- a/src/ml/ml_trainer_manager.cc +++ b/src/ml/ml_trainer_manager.cc @@ -18,6 +18,8 @@ #include "common/tools.h" +#include "ml_utils.h" + using common::ErrorCode; using common::PlatformResult; @@ -81,6 +83,12 @@ PlatformResult TrainerManager::ModelCompile(int id, auto& model = models_[id]; std::lock_guard modelLock(model->instanceLock); + if (model->isCompiled()) { + LoggerE("Recompilation of compiled model is not allowed"); + return PlatformResult(ErrorCode::NO_MODIFICATION_ALLOWED_ERR, + "Recompilation of compiled model is not allowed"); + } + std::stringstream ss; for (const auto& opt : options) { const auto& key = opt.first; @@ -209,7 +217,7 @@ PlatformResult TrainerManager::ModelAddLayer(int id, int layerId) { if (model->isCompiled()) { LoggerE("Modification of compiled model"); model->instanceLock.unlock(); - return PlatformResult(ErrorCode::INVALID_STATE_ERR, + return PlatformResult(ErrorCode::NO_MODIFICATION_ALLOWED_ERR, "Modification of compiled model not allowed"); } @@ -219,7 +227,8 @@ PlatformResult TrainerManager::ModelAddLayer(int id, int layerId) { LoggerE("Could not add layer to model: %d (%s)", ret_val, ml_strerror(ret_val)); model->instanceLock.unlock(); - return PlatformResult(ErrorCode::ABORT_ERR, ml_strerror(ret_val)); + + return util::ToPlatformResult(ret_val, ml_strerror(ret_val)); } model->layerIndices.push_back(layerId); @@ -256,7 +265,7 @@ PlatformResult TrainerManager::ModelSetOptimizer(int id, int optimizerId) { if (model->isCompiled()) { LoggerE("Modification of compiled model"); model->instanceLock.unlock(); - return PlatformResult(ErrorCode::INVALID_STATE_ERR, + return PlatformResult(ErrorCode::NO_MODIFICATION_ALLOWED_ERR, "Modification of compiled model not allowed"); } @@ -266,7 +275,8 @@ PlatformResult TrainerManager::ModelSetOptimizer(int id, int optimizerId) { LoggerE("Could not set optimizer for model: %d (%s)", ret_val, ml_strerror(ret_val)); model->instanceLock.unlock(); - return PlatformResult(ErrorCode::ABORT_ERR, ml_strerror(ret_val)); + + return util::ToPlatformResult(ret_val, ml_strerror(ret_val)); } if (model->optimizerIndex != INVALID_INDEX) { @@ -294,7 +304,7 @@ PlatformResult TrainerManager::ModelSetDataset(int id, int datasetId) { if (models_.find(id) == models_.end()) { LoggerE("Could not find model with id: %d", id); - return PlatformResult(ErrorCode::ABORT_ERR, "Could not find model"); + return PlatformResult(ErrorCode::NOT_FOUND_ERR, "Could not find model"); } auto& model = models_[id]; @@ -319,7 +329,8 @@ PlatformResult TrainerManager::ModelSetDataset(int id, int datasetId) { LoggerE("Could not set dataset for model: %d (%s)", ret_val, ml_strerror(ret_val)); model->instanceLock.unlock(); - return PlatformResult(ErrorCode::ABORT_ERR, ml_strerror(ret_val)); + + return util::ToPlatformResult(ret_val, ml_strerror(ret_val)); } if (model->datasetIndex != INVALID_INDEX) { @@ -470,7 +481,7 @@ PlatformResult TrainerManager::ModelSave(int id, const std::string& path, if (ret_val != ML_ERROR_NONE) { LoggerE("Could not save model to file: %d (%s)", ret_val, ml_strerror(ret_val)); - return PlatformResult(ErrorCode::ABORT_ERR, ml_strerror(ret_val)); + return util::ToPlatformResult(ret_val, ml_strerror(ret_val)); } return PlatformResult(); @@ -508,7 +519,7 @@ PlatformResult TrainerManager::ModelLoad(int id, const std::string& path, if (ret_val != ML_ERROR_NONE) { LoggerE("Could not load model from file: %d (%s)", ret_val, ml_strerror(ret_val)); - return PlatformResult(ErrorCode::ABORT_ERR, ml_strerror(ret_val)); + return util::ToPlatformResult(ret_val, ml_strerror(ret_val)); } return PlatformResult(); @@ -538,7 +549,8 @@ PlatformResult TrainerManager::ModelDispose(int id) { if (ret_val != ML_ERROR_NONE) { LoggerE("Could not destroy model: %d (%s)", ret_val, ml_strerror(ret_val)); model->instanceLock.unlock(); - return PlatformResult(ErrorCode::ABORT_ERR, ml_strerror(ret_val)); + + return util::ToPlatformResult(ret_val, ml_strerror(ret_val)); } // erase model from map and use a shared pointer for related objects removal @@ -577,7 +589,8 @@ PlatformResult TrainerManager::CreateLayer(int& id, int ret_val = ml_train_layer_create(&n_layer, type); if (ret_val != ML_ERROR_NONE) { LoggerE("Could not create layer: %s", ml_strerror(ret_val)); - return PlatformResult(ErrorCode::ABORT_ERR, ml_strerror(ret_val)); + + return util::ToPlatformResult(ret_val, ml_strerror(ret_val)); } layers_[next_layer_id_] = std::make_shared(n_layer); @@ -605,11 +618,12 @@ PlatformResult TrainerManager::LayerSetProperty(int id, if (ret_val != ML_ERROR_NONE) { LoggerE("Could not set layer property: %d (%s)", ret_val, ml_strerror(ret_val)); - return PlatformResult(ErrorCode::ABORT_ERR, ml_strerror(ret_val)); + + return util::ToPlatformResult(ret_val, ml_strerror(ret_val)); } if (name == "name") { - LoggerI("Layer name set detected - changing to: %s", value.c_str()); + LoggerI("Layer name setting detected - changing to: %s", value.c_str()); layer->setName(value); } return PlatformResult(); @@ -650,7 +664,8 @@ PlatformResult TrainerManager::LayerDispose(int id) { int ret_val = ml_train_layer_destroy(layer->getNative()); if (ret_val != ML_ERROR_NONE) { LoggerE("Could not destroy layer: %d (%s)", ret_val, ml_strerror(ret_val)); - return PlatformResult(ErrorCode::ABORT_ERR, ml_strerror(ret_val)); + + return util::ToPlatformResult(ret_val, ml_strerror(ret_val)); } layers_.erase(id); @@ -668,7 +683,8 @@ PlatformResult TrainerManager::CreateOptimizer(int& id, if (ret_val != ML_ERROR_NONE) { LoggerE("Could not create optimizer: %d (%s)", ret_val, ml_strerror(ret_val)); - return PlatformResult(ErrorCode::ABORT_ERR, ml_strerror(ret_val)); + + return util::ToPlatformResult(ret_val, ml_strerror(ret_val)); } optimizers_[next_optimizer_id_] = @@ -696,7 +712,8 @@ PlatformResult TrainerManager::OptimizerSetProperty(int id, if (ret_val != ML_ERROR_NONE) { LoggerE("Could not set optimizer property: %d (%s)", ret_val, ml_strerror(ret_val)); - return PlatformResult(ErrorCode::ABORT_ERR, ml_strerror(ret_val)); + + return util::ToPlatformResult(ret_val, ml_strerror(ret_val)); } return PlatformResult(); } @@ -723,7 +740,8 @@ PlatformResult TrainerManager::OptimizerDispose(int id) { if (ret_val != ML_ERROR_NONE) { LoggerE("Could not destroy optimizer: %d (%s)", ret_val, ml_strerror(ret_val)); - return PlatformResult(ErrorCode::ABORT_ERR, ml_strerror(ret_val)); + + return util::ToPlatformResult(ret_val, ml_strerror(ret_val)); } optimizers_.erase(id); @@ -758,7 +776,8 @@ PlatformResult TrainerManager::CreateFileDataset(int& id, LoggerE("Could not add train file %s to dataset: %s", tmpString.c_str(), ml_strerror(ret_val)); ml_train_dataset_destroy(n_dataset); - return PlatformResult(ErrorCode::ABORT_ERR, ml_strerror(ret_val)); + + return util::ToPlatformResult(ret_val, ml_strerror(ret_val)); } } @@ -774,7 +793,8 @@ PlatformResult TrainerManager::CreateFileDataset(int& id, LoggerE("Could not add validation file %s to dataset: %s", tmpString.c_str(), ml_strerror(ret_val)); ml_train_dataset_destroy(n_dataset); - return PlatformResult(ErrorCode::ABORT_ERR, ml_strerror(ret_val)); + + return util::ToPlatformResult(ret_val, ml_strerror(ret_val)); } } @@ -790,7 +810,8 @@ PlatformResult TrainerManager::CreateFileDataset(int& id, LoggerE("Could not add test file %s to dataset: %s", tmpString.c_str(), ml_strerror(ret_val)); ml_train_dataset_destroy(n_dataset); - return PlatformResult(ErrorCode::ABORT_ERR, ml_strerror(ret_val)); + + return util::ToPlatformResult(ret_val, ml_strerror(ret_val)); } } @@ -801,8 +822,6 @@ PlatformResult TrainerManager::CreateFileDataset(int& id, return PlatformResult(); } -// MK-TODO Add creating Dataset with generator - PlatformResult TrainerManager::DatasetSetProperty( int id, const std::string& name, @@ -824,7 +843,8 @@ PlatformResult TrainerManager::DatasetSetProperty( if (ret_val != ML_ERROR_NONE) { LoggerE("Could not set dataset property for mode %d: %d (%s)", mode, ret_val, ml_strerror(ret_val)); - return PlatformResult(ErrorCode::ABORT_ERR, ml_strerror(ret_val)); + + return util::ToPlatformResult(ret_val, ml_strerror(ret_val)); } return PlatformResult(); @@ -852,7 +872,8 @@ PlatformResult TrainerManager::DatasetDispose(int id) { if (ret_val != ML_ERROR_NONE) { LoggerE("Could not destroy dataset: %d (%s)", ret_val, ml_strerror(ret_val)); - return PlatformResult(ErrorCode::ABORT_ERR, ml_strerror(ret_val)); + + return util::ToPlatformResult(ret_val, ml_strerror(ret_val)); } datasets_.erase(id); -- 2.7.4 From ba3776a102569303578858a77d96b3b5e43dfcc0 Mon Sep 17 00:00:00 2001 From: Marcin Bialek Date: Wed, 2 Mar 2022 12:58:36 +0100 Subject: [PATCH 13/16] [Notification] Fix memory leak. [Verification] Code compiles. Change-Id: I9e75cfd1d91021eb7a8bb074bcd0505c8002997b --- src/notification/common_notification.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/notification/common_notification.cc b/src/notification/common_notification.cc index cee4084..cd03304 100644 --- a/src/notification/common_notification.cc +++ b/src/notification/common_notification.cc @@ -745,7 +745,7 @@ PlatformResult CommonNotification::GetEventHandler(notification_h noti_handle, notification_event_type_e event_type, app_control_h* event_handler) { ScopeLogger(); - app_control_h handler; + app_control_h handler = nullptr; int ret = notification_get_event_handler(noti_handle, event_type, &handler); if (NOTIFICATION_ERROR_NONE != ret) { @@ -755,6 +755,8 @@ PlatformResult CommonNotification::GetEventHandler(notification_h noti_handle, if (event_handler) { *event_handler = handler; + } else { + app_control_destroy(handler); } return PlatformResult(ErrorCode::NO_ERROR); -- 2.7.4 From 9ba1466075957d0aea0432fd7b8cd935072a8adb Mon Sep 17 00:00:00 2001 From: Marcin Kaminski Date: Wed, 2 Mar 2022 19:52:04 +0100 Subject: [PATCH 14/16] [ML] TODO resolving/removal Changes: - constants sorted in ml_instance.cc - stubs for createGeneratorDataset() removed from all levels - obsolete try-catch removed Change-Id: Ie50592ae1c6af6c9e3a8cfddc1c93dd61bc26da2 --- src/ml/js/ml_trainer.js | 29 ----------------------------- src/ml/ml_instance.cc | 49 +++++++++++++++++++------------------------------ src/ml/ml_instance.h | 1 - 3 files changed, 19 insertions(+), 60 deletions(-) diff --git a/src/ml/js/ml_trainer.js b/src/ml/js/ml_trainer.js index e874baf..e31a241 100755 --- a/src/ml/js/ml_trainer.js +++ b/src/ml/js/ml_trainer.js @@ -766,35 +766,6 @@ MachineLearningTrainer.prototype.createFileDataset = function() { return new Dataset(result.id, 'DATASET_FILE'); }; -MachineLearningTrainer.prototype.createGeneratorDataset = function() { - var args = validator_.validateArgs(arguments, [ - { - name: 'train', - type: types_.FUNCTION - }, - { - name: 'validate', - type: types_.FUNCTION, - optional: true, - nullable: true - }, - { - name: 'test', - type: types_.FUNCTION, - optional: true, - nullable: true - } - ]); - ValidateDatasetPaths( - args.train, - args.has.validate ? args.validate : undefined, - args.has.test ? args.test : undefined - ); - - // TODO - return new Dataset(result.id, 'DATASET_GENERATOR'); -}; - var ValidCreateOptimizerExceptions = [ 'NotSupportedError', 'TypeMismatchError', diff --git a/src/ml/ml_instance.cc b/src/ml/ml_instance.cc index 6e256d7..9d92440 100644 --- a/src/ml/ml_instance.cc +++ b/src/ml/ml_instance.cc @@ -32,11 +32,15 @@ namespace ml { namespace { const int kCustomFilterSuccess = 0; const int kNoId = -1; + const std::string kAsync = "async"; const std::string kBOOLEAN = "BOOLEAN"; const std::string kBuffer = "buffer"; const std::string kCallbackId = "callbackId"; +const std::string kConfigPath = "configPath"; +const std::string kCustomRequirement = "customRequirement"; const std::string kDataId = "dataId"; +const std::string kDatasetId = "datasetId"; const std::string kDefinition = "definition"; const std::string kDimensions = "dimensions"; const std::string kFwType = "fwType"; @@ -44,49 +48,45 @@ const std::string kGetInputMode = "getInputMode"; const std::string kHw = "hw"; const std::string kHwType = "hwType"; const std::string kId = "id"; +const std::string kInTensorsInfo = "inTensorsInfo"; const std::string kIndex = "index"; const std::string kInputTensorsInfoId = "inputTensorsInfoId"; -const std::string kInTensorsInfo = "inTensorsInfo"; const std::string kIsDynamicMode = "isDynamicMode"; +const std::string kLayerId = "layerId"; +const std::string kLevel = "level"; const std::string kListenerName = "listenerName"; const std::string kLocation = "location"; +const std::string kMode = "mode"; const std::string kModelPath = "modelPath"; -const std::string kConfigPath = "configPath"; const std::string kName = "name"; const std::string kNnfw = "nnfw"; -const std::string kCustomRequirement = "customRequirement"; const std::string kNodeName = "nodeName"; const std::string kOpen = "open"; +const std::string kOptimizerId = "optimizerId"; +const std::string kOptions = "options"; const std::string kOtherId = "otherId"; -const std::string kOutputTensorsInfoId = "outputTensorsInfoId"; const std::string kOutTensorsInfo = "outTensorsInfo"; +const std::string kOutputTensorsInfoId = "outputTensorsInfoId"; const std::string kPadName = "padName"; const std::string kPipelineStateChangeListenerName = "listenerName"; const std::string kProperty = "property"; const std::string kRequestId = "requestId"; +const std::string kSTRING = "STRING"; +const std::string kSaveFormat = "saveFormat"; +const std::string kSavePath = "savePath"; const std::string kShape = "shape"; const std::string kSize = "size"; const std::string kStatus = "status"; -const std::string kSTRING = "STRING"; +const std::string kSummary = "summary"; const std::string kTensorsDataId = "tensorsDataId"; const std::string kTensorsInfoId = "tensorsInfoId"; +const std::string kTest = "test"; const std::string kTimeout = "timeout"; +const std::string kTrain = "train"; const std::string kType = "type"; +const std::string kValid = "valid"; const std::string kValue = "value"; -// TODO: sort const -const std::string kTrain = "train"; -const std::string kValid = "valid"; -const std::string kTest = "test"; -const std::string kOptions = "options"; -const std::string kLayerId = "layerId"; -const std::string kDatasetId = "datasetId"; -const std::string kOptimizerId = "optimizerId"; -const std::string kLevel = "level"; -const std::string kSummary = "summary"; -const std::string kSavePath = "savePath"; -const std::string kSaveFormat = "saveFormat"; -const std::string kMode = "mode"; } // namespace using namespace common; @@ -201,7 +201,6 @@ MlInstance::MlInstance() REGISTER_METHOD(MLTrainerModelSetDataset); REGISTER_METHOD(MLTrainerModelSetOptimizer); REGISTER_METHOD(MLTrainerModelDispose); - REGISTER_METHOD(MLTrainerDatasetCreateGenerator); REGISTER_METHOD(MLTrainerDatasetCreateFromFile); REGISTER_METHOD(MLTrainerDatasetSetProperty); REGISTER_METHOD(MLTrainerDatasetDispose); @@ -1920,12 +1919,7 @@ void MlInstance::MLTrainerModelRun(const picojson::value& args, picojson::object auto async_logic = [this, id, options](decltype(out) out) { PlatformResult result; - try { - result = trainer_manager_.ModelRun(id, options); - } catch (...) { // MK-TODO verify why this exception occurs - LoggerE("Unhandled and unexpected exception!!"); - ReportError(result, &out); - } + result = trainer_manager_.ModelRun(id, options); if (!result) { ReportError(result, &out); @@ -2102,11 +2096,6 @@ void MlInstance::MLTrainerModelDispose(const picojson::value& args, ReportSuccess(out); } -void MlInstance::MLTrainerDatasetCreateGenerator(const picojson::value& args, - picojson::object& out) { - ScopeLogger("args: %s", args.serialize().c_str()); -} - void MlInstance::MLTrainerDatasetCreateFromFile(const picojson::value& args, picojson::object& out) { ScopeLogger("args: %s", args.serialize().c_str()); diff --git a/src/ml/ml_instance.h b/src/ml/ml_instance.h index 5fed8fa..6269a6e 100644 --- a/src/ml/ml_instance.h +++ b/src/ml/ml_instance.h @@ -177,7 +177,6 @@ class MlInstance : public common::ParsedInstance { void MLTrainerModelDispose(const picojson::value& args, picojson::object& out); - void MLTrainerDatasetCreateGenerator(const picojson::value& args, picojson::object& out); void MLTrainerDatasetCreateFromFile(const picojson::value& args, picojson::object& out); void MLTrainerDatasetSetProperty(const picojson::value& args, picojson::object& out); void MLTrainerDatasetDispose(const picojson::value& args, -- 2.7.4 From 937fc3e4fd8c9a3dd32974a4e261d82e4db31b73 Mon Sep 17 00:00:00 2001 From: DongHyun Song Date: Tue, 8 Mar 2022 17:35:55 +0900 Subject: [PATCH 15/16] Add 'self' as global scope for web worker In web worker world, 'self' is defined global scope object. This change is necessary to apply tizen webapis on web worker for specific purpose. (i.e. tizen.ml) Change-Id: Ie9602ea4f492589dad2c87e3c0bd8e2602278c02 Signed-off-by: DongHyun Song --- src/utils/utils_api.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/utils/utils_api.js b/src/utils/utils_api.js index 5f7b478..7d184af 100644 --- a/src/utils/utils_api.js +++ b/src/utils/utils_api.js @@ -11,10 +11,12 @@ exports.JSON = JSON_; var _enableJsLogs = false; var _global = {}; -if (typeof window != 'undefined') { +if (typeof window !== 'undefined') { _global = window; -} else if (typeof global != 'undefined') { +} else if (typeof global !== 'undefined') { _global = global; +} else if (typeof self !== 'undefined') { + _global = self; } /** @@ -1655,6 +1657,8 @@ if (typeof window !== 'undefined') { scope = window; } else if (typeof global !== 'undefined') { scope = global; +} else if (typeof self !== 'undefined') { + scope = self; } scope = scope || {}; scope.WebAPIException = WebAPIException; -- 2.7.4 From bd7d748831aa290bb88d6375e8267d78d728f40c Mon Sep 17 00:00:00 2001 From: "Piotr Kosko/Tizen API (PLT) /SRPOL/Engineer/Samsung Electronics" Date: Thu, 10 Mar 2022 15:13:33 +0100 Subject: [PATCH 16/16] [ML] Disable ML Trainer for TV build profile [verification] Compilation succeeds for mobile and tv profile. Mobile profile includes all C++ implementation dependant of nntrainer. TV profile build does not include any C++ implementation of tizen.ml.trainer methods. Tested in chrome console that for Mobile - tizen.ml.trainer is available and working properly. For TV feature is disabled (doesn't work), but there are no crashes. Change-Id: I55dd846d7ba8303a0422deabc9aa2b6dbfe27612 --- packaging/webapi-plugins.spec | 16 + src/ml/ml.gyp | 21 +- src/ml/ml_instance.cc | 697 +++++++++++++++++++++++++++--------------- src/ml/ml_instance.h | 139 ++++++--- src/ml/ml_utils.cc | 3 +- src/ml/ml_utils.h | 4 + 6 files changed, 581 insertions(+), 299 deletions(-) diff --git a/packaging/webapi-plugins.spec b/packaging/webapi-plugins.spec index 98c2979..bf18241 100644 --- a/packaging/webapi-plugins.spec +++ b/packaging/webapi-plugins.spec @@ -60,6 +60,7 @@ Source0: %{name}-%{version}.tar.gz %define tizen_common_feature_messaging_support 0 %define tizen_common_feature_metadata_support 1 %define tizen_common_feature_ml_support 1 +%define tizen_common_feature_ml_nntrainer_support 1 %define tizen_common_feature_nbs_support 0 %define tizen_common_feature_nfc_support 0 %define tizen_common_feature_nfc_emulation_support 0 @@ -124,6 +125,7 @@ Source0: %{name}-%{version}.tar.gz %define tizen_mobile_feature_messaging_support 1 %define tizen_mobile_feature_metadata_support 1 %define tizen_mobile_feature_ml_support 1 +%define tizen_mobile_feature_ml_nntrainer_support 1 %define tizen_mobile_feature_nfc_support 0 %define tizen_mobile_feature_nfc_emulation_support 0 %define tizen_mobile_feature_notification_support 1 @@ -232,6 +234,7 @@ Source0: %{name}-%{version}.tar.gz %define tizen_wearable_feature_messaging_support 0 %define tizen_wearable_feature_metadata_support 1 %define tizen_wearable_feature_ml_support 1 +%define tizen_wearable_feature_ml_nntrainer_support 1 %define tizen_wearable_feature_nfc_support 1 %define tizen_wearable_feature_nfc_emulation_support 0 %define tizen_wearable_feature_notification_support 1 @@ -313,6 +316,8 @@ Source0: %{name}-%{version}.tar.gz %define tizen_tv_feature_messaging_support 0 %define tizen_tv_feature_metadata_support 1 %define tizen_tv_feature_ml_support 1 +#TODO -- enable when native API will be supported on TV +%define tizen_tv_feature_ml_nntrainer_support 0 %define tizen_tv_feature_nbs_support 0 %define tizen_tv_feature_nfc_support 0 %define tizen_tv_feature_nfc_emulation_support 0 @@ -373,6 +378,7 @@ Source0: %{name}-%{version}.tar.gz %define tizen_feature_message_port_support %{expand:%tizen_%{?profile}_feature_message_port_support} %define tizen_feature_messaging_support %{expand:%tizen_%{?profile}_feature_messaging_support} %define tizen_feature_ml_support %{expand:%tizen_%{?profile}_feature_ml_support} +%define tizen_feature_ml_nntrainer_support %{expand:%tizen_%{?profile}_feature_ml_nntrainer_support} %define tizen_feature_nfc_emulation_support %{expand:%tizen_%{?profile}_feature_nfc_emulation_support} %define tizen_feature_nfc_support %{expand:%tizen_%{?profile}_feature_nfc_support} %define tizen_feature_notification_support %{expand:%tizen_%{?profile}_feature_notification_support} @@ -533,10 +539,14 @@ BuildRequires: pkgconfig(db-util) %if "%{?tizen_feature_ml_support}" == "1" || "%{?unified_build}" == "1" BuildRequires: pkgconfig(nnstreamer) BuildRequires: pkgconfig(capi-ml-inference) +%endif + +%if "%{?tizen_feature_ml_nntrainer_support}" == "1" || "%{?unified_build}" == "1" BuildRequires: pkgconfig(nntrainer) BuildRequires: pkgconfig(capi-ml-training) %endif + %if "%{?tizen_feature_badge_support}" == "1" || "%{?unified_build}" == "1" BuildRequires: pkgconfig(badge) %endif @@ -739,6 +749,7 @@ GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_message_port_support=%{?tizen_mobile_f GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_messaging_support=%{?tizen_mobile_feature_messaging_support}" GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_metadata_support=%{?tizen_mobile_feature_metadata_support}" GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_ml_support=%{?tizen_mobile_feature_ml_support}" +GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_ml_nntrainer_support=%{?tizen_mobile_feature_ml_nntrainer_support}" GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_nbs_support=%{?tizen_mobile_feature_nbs_support}" GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_nfc_emulation_support=%{?tizen_mobile_feature_nfc_emulation_support}" GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_nfc_support=%{?tizen_mobile_feature_nfc_support}" @@ -831,6 +842,7 @@ GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_message_port_support=%{?tizen_mobile_f GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_messaging_support=%{?tizen_mobile_feature_messaging_support}" GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_metadata_support=%{?tizen_mobile_feature_metadata_support}" GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_ml_support=%{?tizen_mobile_feature_ml_support}" +GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_ml_nntrainer_support=%{?tizen_mobile_feature_ml_nntrainer_support}" GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_nbs_support=%{?tizen_mobile_feature_nbs_support}" GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_nfc_emulation_support=%{?tizen_mobile_feature_nfc_emulation_support}" GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_nfc_support=%{?tizen_mobile_feature_nfc_support}" @@ -911,6 +923,7 @@ GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_message_port_support=%{?tizen_wearable GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_messaging_support=%{?tizen_wearable_feature_messaging_support}" GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_metadata_support=%{?tizen_wearable_feature_metadata_support}" GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_ml_support=%{?tizen_wearable_feature_ml_support}" +GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_ml_nntrainer_support=%{?tizen_wearable_feature_ml_nntrainer_support}" GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_nbs_support=%{?tizen_wearable_feature_nbs_support}" GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_nfc_emulation_support=%{?tizen_wearable_feature_nfc_emulation_support}" GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_nfc_support=%{?tizen_wearable_feature_nfc_support}" @@ -998,6 +1011,7 @@ GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_message_port_support=%{?tizen_wearable GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_messaging_support=%{?tizen_wearable_feature_messaging_support}" GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_metadata_support=%{?tizen_wearable_feature_metadata_support}" GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_ml_support=%{?tizen_wearable_feature_ml_support}" +GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_ml_nntrainer_support=%{?tizen_wearable_feature_ml_nntrainer_support}" GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_nbs_support=%{?tizen_wearable_feature_nbs_support}" GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_nfc_emulation_support=%{?tizen_wearable_feature_nfc_emulation_support}" GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_nfc_support=%{?tizen_wearable_feature_nfc_support}" @@ -1078,6 +1092,7 @@ GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_message_port_support=%{?tizen_tv_featu GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_messaging_support=%{?tizen_tv_feature_messaging_support}" GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_metadata_support=%{?tizen_tv_feature_metadata_support}" GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_ml_support=%{?tizen_tv_feature_ml_support}" +GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_ml_nntrainer_support=%{?tizen_tv_feature_ml_nntrainer_support}" GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_nbs_support=%{?tizen_tv_feature_nbs_support}" GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_nfc_emulation_support=%{?tizen_tv_feature_nfc_emulation_support}" GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_nfc_support=%{?tizen_tv_feature_nfc_support}" @@ -1156,6 +1171,7 @@ GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_message_port_support=%{?tizen_common_f GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_messaging_support=%{?tizen_common_feature_messaging_support}" GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_metadata_support=%{?tizen_common_feature_metadata_support}" GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_ml_support=%{?tizen_common_feature_ml_support}" +GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_ml_nntrainer_support=%{?tizen_common_feature_ml_nntrainer_support}" GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_nbs_support=%{?tizen_common_feature_nbs_support}" GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_nfc_emulation_support=%{?tizen_common_feature_nfc_emulation_support}" GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_nfc_support=%{?tizen_common_feature_nfc_support}" diff --git a/src/ml/ml.gyp b/src/ml/ml.gyp index 9f3534c..ff6e532 100644 --- a/src/ml/ml.gyp +++ b/src/ml/ml.gyp @@ -37,10 +37,6 @@ 'ml_tensors_info_manager.h', 'ml_single_manager.cc', 'ml_single_manager.h', - 'ml_trainer_manager.cc', - 'ml_trainer_manager.h', - 'ml_trainer_objects.cc', - 'ml_trainer_objects.h', 'ml_singleshot.cc', 'ml_singleshot.h', 'ml_utils.cc', @@ -52,10 +48,25 @@ 'packages': [ 'nnstreamer', 'capi-ml-inference', + ] + }, + }], + ['tizen_feature_ml_nntrainer_support == 1', { + 'variables': { + 'packages': [ 'nntrainer', 'capi-ml-training', - ] + ], }, + 'sources': [ + 'ml_trainer_manager.cc', + 'ml_trainer_manager.h', + 'ml_trainer_objects.cc', + 'ml_trainer_objects.h', + ], + 'defines': [ + 'NNTRAINER_SUPPORTED', + ], }], ], }, diff --git a/src/ml/ml_instance.cc b/src/ml/ml_instance.cc index 9d92440..eec6ca7 100644 --- a/src/ml/ml_instance.cc +++ b/src/ml/ml_instance.cc @@ -15,16 +15,17 @@ */ #include "ml_instance.h" -#include "ml_utils.h" #include "common/converter.h" #include "common/logger.h" #include "common/picojson.h" #include "common/platform_result.h" #include "common/tools.h" +#include "ml_utils.h" static_assert(ML_TENSOR_RANK_LIMIT == 4, - "This implementation requires different ML_TENSOR_RANK_LIMIT. Please fix the code."); + "This implementation requires different ML_TENSOR_RANK_LIMIT. " + "Please fix the code."); namespace extension { namespace ml { @@ -91,17 +92,19 @@ const std::string kValue = "value"; using namespace common; -#define CHECK_EXIST(args, name, out) \ - if (!args.contains(name)) { \ - std::string msg = std::string(name) + " is required argument"; \ - LogAndReportError(PlatformResult(ErrorCode::TYPE_MISMATCH_ERR, msg), &out); \ - return; \ +#define CHECK_EXIST(args, name, out) \ + if (!args.contains(name)) { \ + std::string msg = std::string(name) + " is required argument"; \ + LogAndReportError(PlatformResult(ErrorCode::TYPE_MISMATCH_ERR, msg), \ + &out); \ + return; \ } -// CHECK_TYPE will throw AbortError by default, but it can be changed by providing -// additional parameter to the macro, i.e.: -// CHECK_TYPE(args, "name", std::string, out, ErrorCode::TYPE_MISMATCH_ERR) -#define CHECK_TYPE(...) CHECK_TYPE_X(__VA_ARGS__, CHECK_TYPE_5, CHECK_TYPE_4)(__VA_ARGS__) +// CHECK_TYPE will throw AbortError by default, but it can be changed by +// providing additional parameter to the macro, i.e.: CHECK_TYPE(args, "name", +// std::string, out, ErrorCode::TYPE_MISMATCH_ERR) +#define CHECK_TYPE(...) \ + CHECK_TYPE_X(__VA_ARGS__, CHECK_TYPE_5, CHECK_TYPE_4)(__VA_ARGS__) #define CHECK_TYPE_X(_1, _2, _3, _4, _5, EXC_TYPE, ...) EXC_TYPE #define CHECK_TYPE_5(args, name, type, out, error_type) \ if (!args.get(name).is()) { \ @@ -123,10 +126,13 @@ MlInstance::MlInstance() ScopeLogger(); using namespace std::placeholders; -#define REGISTER_METHOD(M) RegisterSyncHandler(#M, std::bind(&MlInstance::M, this, _1, _2)) -#define REGISTER_BINARY_METHOD(M) RegisterBinaryHandler(std::bind(&MlInstance::M, this, _1, _2, _3)) +#define REGISTER_METHOD(M) \ + RegisterSyncHandler(#M, std::bind(&MlInstance::M, this, _1, _2)) +#define REGISTER_BINARY_METHOD(M) \ + RegisterBinaryHandler(std::bind(&MlInstance::M, this, _1, _2, _3)) #define REGISTER_METHOD_WITH_BINARY_ANWSER(M) \ - RegisterSyncHandlerWithBinaryAnswer(#M, std::bind(&MlInstance::M, this, _1, _2)) + RegisterSyncHandlerWithBinaryAnswer(#M, \ + std::bind(&MlInstance::M, this, _1, _2)) REGISTER_METHOD(MLCheckNNFWAvailability); REGISTER_METHOD(MLTensorsInfoCountGetter); @@ -183,6 +189,7 @@ MlInstance::MlInstance() REGISTER_METHOD(MLPipelineManagerCustomFilterOutput); REGISTER_METHOD(MLPipelineManagerUnregisterCustomFilter); +#ifdef NNTRAINER_SUPPORTED REGISTER_METHOD(MLTrainerLayerSetProperty); REGISTER_METHOD(MLTrainerLayerCreate); REGISTER_METHOD(MLTrainerLayerGetName); @@ -204,6 +211,7 @@ MlInstance::MlInstance() REGISTER_METHOD(MLTrainerDatasetCreateFromFile); REGISTER_METHOD(MLTrainerDatasetSetProperty); REGISTER_METHOD(MLTrainerDatasetDispose); +#endif #undef REGISTER_METHOD } @@ -221,7 +229,8 @@ TensorsDataManager& MlInstance::GetTensorsDataManager() { return tensors_data_manager_; } -void MlInstance::MLCheckNNFWAvailability(const picojson::value& args, picojson::object& out) { +void MlInstance::MLCheckNNFWAvailability(const picojson::value& args, + picojson::object& out) { ScopeLogger("args: %s", args.serialize().c_str()); CHECK_EXIST(args, kNnfw, out) CHECK_EXIST(args, kHw, out) @@ -233,34 +242,41 @@ void MlInstance::MLCheckNNFWAvailability(const picojson::value& args, picojson:: if (args.get(kCustomRequirement).is()) { customRequirement = args.get(kCustomRequirement).get(); } - bool availability_val = util::CheckNNFWAvailability(nnfw, hw, customRequirement); + bool availability_val = + util::CheckNNFWAvailability(nnfw, hw, customRequirement); picojson::value available = picojson::value{availability_val}; ReportSuccess(available, out); } -void MlInstance::MLTensorsInfoCreate(const picojson::value& args, picojson::object& out) { +void MlInstance::MLTensorsInfoCreate(const picojson::value& args, + picojson::object& out) { ScopeLogger("args: %s", args.serialize().c_str()); TensorsInfo* tensorsInfo = GetTensorsInfoManager().CreateTensorsInfo(); if (nullptr == tensorsInfo) { - LogAndReportError(PlatformResult(ErrorCode::ABORT_ERR, "Internal TensorsInfo error"), &out, - ("Could not create new TensorsInfo handle")); + LogAndReportError( + PlatformResult(ErrorCode::ABORT_ERR, "Internal TensorsInfo error"), + &out, ("Could not create new TensorsInfo handle")); return; } out[kId] = picojson::value(static_cast(tensorsInfo->Id())); ReportSuccess(out); } -void MlInstance::MLTensorsInfoCountGetter(const picojson::value& args, picojson::object& out) { +void MlInstance::MLTensorsInfoCountGetter(const picojson::value& args, + picojson::object& out) { ScopeLogger("args: %s", args.serialize().c_str()); CHECK_ARGS(args, kTensorsInfoId, double, out); int tensorsInfoId = static_cast(args.get(kTensorsInfoId).get()); - TensorsInfo* tensorsInfo = GetTensorsInfoManager().GetTensorsInfo(tensorsInfoId); + TensorsInfo* tensorsInfo = + GetTensorsInfoManager().GetTensorsInfo(tensorsInfoId); if (nullptr == tensorsInfo) { - LogAndReportError(PlatformResult(ErrorCode::ABORT_ERR, "Internal TensorsInfo error"), &out, - ("Could not find TensorsInfo handle with given id: %d", tensorsInfoId)); + LogAndReportError( + PlatformResult(ErrorCode::ABORT_ERR, "Internal TensorsInfo error"), + &out, + ("Could not find TensorsInfo handle with given id: %d", tensorsInfoId)); return; } unsigned int count = 0; @@ -273,7 +289,8 @@ void MlInstance::MLTensorsInfoCountGetter(const picojson::value& args, picojson: ReportSuccess(val, out); } -void MlInstance::MLTensorsInfoAddTensorInfo(const picojson::value& args, picojson::object& out) { +void MlInstance::MLTensorsInfoAddTensorInfo(const picojson::value& args, + picojson::object& out) { ScopeLogger("args: %s", args.serialize().c_str()); CHECK_ARGS(args, kTensorsInfoId, double, out); CHECK_ARGS(args, kType, std::string, out); @@ -282,20 +299,26 @@ void MlInstance::MLTensorsInfoAddTensorInfo(const picojson::value& args, picojso CHECK_ARGS(args, kDimensions, picojson::array, out); int tensorsInfoId = static_cast(args.get(kTensorsInfoId).get()); - TensorsInfo* tensorsInfo = GetTensorsInfoManager().GetTensorsInfo(tensorsInfoId); + TensorsInfo* tensorsInfo = + GetTensorsInfoManager().GetTensorsInfo(tensorsInfoId); if (nullptr == tensorsInfo) { - LogAndReportError(PlatformResult(ErrorCode::ABORT_ERR, "Internal TensorsInfo error"), &out, - ("Could not find TensorsInfo handle with given id: %d", tensorsInfoId)); + LogAndReportError( + PlatformResult(ErrorCode::ABORT_ERR, "Internal TensorsInfo error"), + &out, + ("Could not find TensorsInfo handle with given id: %d", tensorsInfoId)); return; } const std::string& tensorType = args.get(kType).get(); ml_tensor_type_e tensorTypeEnum = ML_TENSOR_TYPE_UNKNOWN; - PlatformResult result = types::TensorTypeEnum.getValue(tensorType, &tensorTypeEnum); + PlatformResult result = + types::TensorTypeEnum.getValue(tensorType, &tensorTypeEnum); if (!result) { - LogAndReportError(PlatformResult(ErrorCode::ABORT_ERR, "Error getting value of TensorType"), + LogAndReportError(PlatformResult(ErrorCode::ABORT_ERR, + "Error getting value of TensorType"), &out, - ("TensorTypeEnum.getValue() failed, error: %s", result.message().c_str())); + ("TensorTypeEnum.getValue() failed, error: %s", + result.message().c_str())); return; } @@ -325,16 +348,20 @@ void MlInstance::MLTensorsInfoAddTensorInfo(const picojson::value& args, picojso ReportSuccess(val, out); } -void MlInstance::MLTensorsInfoGetDimensions(const picojson::value& args, picojson::object& out) { +void MlInstance::MLTensorsInfoGetDimensions(const picojson::value& args, + picojson::object& out) { ScopeLogger("args: %s", args.serialize().c_str()); CHECK_ARGS(args, kTensorsInfoId, double, out); CHECK_ARGS(args, kIndex, double, out); int tensorsInfoId = static_cast(args.get(kTensorsInfoId).get()); - TensorsInfo* tensorsInfo = GetTensorsInfoManager().GetTensorsInfo(tensorsInfoId); + TensorsInfo* tensorsInfo = + GetTensorsInfoManager().GetTensorsInfo(tensorsInfoId); if (nullptr == tensorsInfo) { - LogAndReportError(PlatformResult(ErrorCode::ABORT_ERR, "Internal TensorsInfo error"), &out, - ("Could not find TensorsInfo handle with given id: %d", tensorsInfoId)); + LogAndReportError( + PlatformResult(ErrorCode::ABORT_ERR, "Internal TensorsInfo error"), + &out, + ("Could not find TensorsInfo handle with given id: %d", tensorsInfoId)); return; } int index = static_cast(args.get(kIndex).get()); @@ -355,17 +382,21 @@ void MlInstance::MLTensorsInfoGetDimensions(const picojson::value& args, picojso ReportSuccess(val, out); } -void MlInstance::MLTensorsInfoSetDimensions(const picojson::value& args, picojson::object& out) { +void MlInstance::MLTensorsInfoSetDimensions(const picojson::value& args, + picojson::object& out) { ScopeLogger("args: %s", args.serialize().c_str()); CHECK_ARGS(args, kTensorsInfoId, double, out); CHECK_ARGS(args, kIndex, double, out); CHECK_ARGS(args, kDimensions, picojson::array, out); int tensorsInfoId = static_cast(args.get(kTensorsInfoId).get()); - TensorsInfo* tensorsInfo = GetTensorsInfoManager().GetTensorsInfo(tensorsInfoId); + TensorsInfo* tensorsInfo = + GetTensorsInfoManager().GetTensorsInfo(tensorsInfoId); if (nullptr == tensorsInfo) { - LogAndReportError(PlatformResult(ErrorCode::ABORT_ERR, "Internal TensorsInfo error"), &out, - ("Could not find TensorsInfo handle with given id: %d", tensorsInfoId)); + LogAndReportError( + PlatformResult(ErrorCode::ABORT_ERR, "Internal TensorsInfo error"), + &out, + ("Could not find TensorsInfo handle with given id: %d", tensorsInfoId)); return; } @@ -386,16 +417,20 @@ void MlInstance::MLTensorsInfoSetDimensions(const picojson::value& args, picojso ReportSuccess(out); } -void MlInstance::MLTensorsInfoGetTensorName(const picojson::value& args, picojson::object& out) { +void MlInstance::MLTensorsInfoGetTensorName(const picojson::value& args, + picojson::object& out) { ScopeLogger("args: %s", args.serialize().c_str()); CHECK_ARGS(args, kTensorsInfoId, double, out); CHECK_ARGS(args, kIndex, double, out); int tensorsInfoId = static_cast(args.get(kTensorsInfoId).get()); - TensorsInfo* tensorsInfo = GetTensorsInfoManager().GetTensorsInfo(tensorsInfoId); + TensorsInfo* tensorsInfo = + GetTensorsInfoManager().GetTensorsInfo(tensorsInfoId); if (nullptr == tensorsInfo) { - LogAndReportError(PlatformResult(ErrorCode::ABORT_ERR, "Internal TensorsInfo error"), &out, - ("Could not find TensorsInfo handle with given id: %d", tensorsInfoId)); + LogAndReportError( + PlatformResult(ErrorCode::ABORT_ERR, "Internal TensorsInfo error"), + &out, + ("Could not find TensorsInfo handle with given id: %d", tensorsInfoId)); return; } int index = static_cast(args.get(kIndex).get()); @@ -409,17 +444,21 @@ void MlInstance::MLTensorsInfoGetTensorName(const picojson::value& args, picojso ReportSuccess(val, out); } -void MlInstance::MLTensorsInfoSetTensorName(const picojson::value& args, picojson::object& out) { +void MlInstance::MLTensorsInfoSetTensorName(const picojson::value& args, + picojson::object& out) { ScopeLogger("args: %s", args.serialize().c_str()); CHECK_ARGS(args, kTensorsInfoId, double, out); CHECK_ARGS(args, kIndex, double, out); CHECK_ARGS(args, kName, std::string, out); int tensorsInfoId = static_cast(args.get(kTensorsInfoId).get()); - TensorsInfo* tensorsInfo = GetTensorsInfoManager().GetTensorsInfo(tensorsInfoId); + TensorsInfo* tensorsInfo = + GetTensorsInfoManager().GetTensorsInfo(tensorsInfoId); if (nullptr == tensorsInfo) { - LogAndReportError(PlatformResult(ErrorCode::ABORT_ERR, "Internal TensorsInfo error"), &out, - ("Could not find TensorsInfo handle with given id: %d", tensorsInfoId)); + LogAndReportError( + PlatformResult(ErrorCode::ABORT_ERR, "Internal TensorsInfo error"), + &out, + ("Could not find TensorsInfo handle with given id: %d", tensorsInfoId)); return; } @@ -433,16 +472,20 @@ void MlInstance::MLTensorsInfoSetTensorName(const picojson::value& args, picojso ReportSuccess(out); } -void MlInstance::MLTensorsInfoGetTensorSize(const picojson::value& args, picojson::object& out) { +void MlInstance::MLTensorsInfoGetTensorSize(const picojson::value& args, + picojson::object& out) { ScopeLogger("args: %s", args.serialize().c_str()); CHECK_ARGS(args, kTensorsInfoId, double, out); CHECK_ARGS(args, kIndex, double, out); int tensorsInfoId = static_cast(args.get(kTensorsInfoId).get()); - TensorsInfo* tensorsInfo = GetTensorsInfoManager().GetTensorsInfo(tensorsInfoId); + TensorsInfo* tensorsInfo = + GetTensorsInfoManager().GetTensorsInfo(tensorsInfoId); if (nullptr == tensorsInfo) { - LogAndReportError(PlatformResult(ErrorCode::ABORT_ERR, "Internal TensorsInfo error"), &out, - ("Could not find TensorsInfo handle with given id: %d", tensorsInfoId)); + LogAndReportError( + PlatformResult(ErrorCode::ABORT_ERR, "Internal TensorsInfo error"), + &out, + ("Could not find TensorsInfo handle with given id: %d", tensorsInfoId)); return; } int index = static_cast(args.get(kIndex).get()); @@ -457,22 +500,27 @@ void MlInstance::MLTensorsInfoGetTensorSize(const picojson::value& args, picojso ReportSuccess(val, out); } -void MlInstance::MLTensorsInfoGetTensorType(const picojson::value& args, picojson::object& out) { +void MlInstance::MLTensorsInfoGetTensorType(const picojson::value& args, + picojson::object& out) { ScopeLogger("args: %s", args.serialize().c_str()); CHECK_ARGS(args, kTensorsInfoId, double, out); CHECK_ARGS(args, kIndex, double, out); int tensorsInfoId = static_cast(args.get(kTensorsInfoId).get()); - TensorsInfo* tensorsInfo = GetTensorsInfoManager().GetTensorsInfo(tensorsInfoId); + TensorsInfo* tensorsInfo = + GetTensorsInfoManager().GetTensorsInfo(tensorsInfoId); if (nullptr == tensorsInfo) { - LogAndReportError(PlatformResult(ErrorCode::ABORT_ERR, "Internal TensorsInfo error"), &out, - ("Could not find TensorsInfo handle with given id: %d", tensorsInfoId)); + LogAndReportError( + PlatformResult(ErrorCode::ABORT_ERR, "Internal TensorsInfo error"), + &out, + ("Could not find TensorsInfo handle with given id: %d", tensorsInfoId)); return; } int index = static_cast(args.get(kIndex).get()); ml_tensor_type_e tensorTypeEnum = ML_TENSOR_TYPE_UNKNOWN; - PlatformResult result = tensorsInfo->NativeGetTensorType(index, &tensorTypeEnum); + PlatformResult result = + tensorsInfo->NativeGetTensorType(index, &tensorTypeEnum); if (!result) { LogAndReportError(result, &out); return; @@ -480,9 +528,11 @@ void MlInstance::MLTensorsInfoGetTensorType(const picojson::value& args, picojso std::string tensorTypeString; result = types::TensorTypeEnum.getName(tensorTypeEnum, &tensorTypeString); if (!result) { - LogAndReportError(PlatformResult(ErrorCode::ABORT_ERR, "Error getting name of TensorType"), + LogAndReportError(PlatformResult(ErrorCode::ABORT_ERR, + "Error getting name of TensorType"), &out, - ("TensorTypeEnum.getName() failed, error: %s", result.message().c_str())); + ("TensorTypeEnum.getName() failed, error: %s", + result.message().c_str())); return; } @@ -490,27 +540,34 @@ void MlInstance::MLTensorsInfoGetTensorType(const picojson::value& args, picojso ReportSuccess(val, out); } -void MlInstance::MLTensorsInfoSetTensorType(const picojson::value& args, picojson::object& out) { +void MlInstance::MLTensorsInfoSetTensorType(const picojson::value& args, + picojson::object& out) { ScopeLogger("args: %s", args.serialize().c_str()); CHECK_ARGS(args, kTensorsInfoId, double, out); CHECK_ARGS(args, kIndex, double, out); CHECK_ARGS(args, kType, std::string, out); int tensorsInfoId = static_cast(args.get(kTensorsInfoId).get()); - TensorsInfo* tensorsInfo = GetTensorsInfoManager().GetTensorsInfo(tensorsInfoId); + TensorsInfo* tensorsInfo = + GetTensorsInfoManager().GetTensorsInfo(tensorsInfoId); if (nullptr == tensorsInfo) { - LogAndReportError(PlatformResult(ErrorCode::ABORT_ERR, "Internal TensorsInfo error"), &out, - ("Could not find TensorsInfo handle with given id: %d", tensorsInfoId)); + LogAndReportError( + PlatformResult(ErrorCode::ABORT_ERR, "Internal TensorsInfo error"), + &out, + ("Could not find TensorsInfo handle with given id: %d", tensorsInfoId)); return; } const std::string& tensorType = args.get(kType).get(); ml_tensor_type_e tensorTypeEnum = ML_TENSOR_TYPE_UNKNOWN; - PlatformResult result = types::TensorTypeEnum.getValue(tensorType, &tensorTypeEnum); + PlatformResult result = + types::TensorTypeEnum.getValue(tensorType, &tensorTypeEnum); if (!result) { - LogAndReportError(PlatformResult(ErrorCode::ABORT_ERR, "Error getting value of TensorType"), + LogAndReportError(PlatformResult(ErrorCode::ABORT_ERR, + "Error getting value of TensorType"), &out, - ("TensorTypeEnum.getValue() failed, error: %s", result.message().c_str())); + ("TensorTypeEnum.getValue() failed, error: %s", + result.message().c_str())); return; } @@ -523,46 +580,58 @@ void MlInstance::MLTensorsInfoSetTensorType(const picojson::value& args, picojso ReportSuccess(out); } -void MlInstance::MLTensorsInfoGetTensorsData(const picojson::value& args, picojson::object& out) { +void MlInstance::MLTensorsInfoGetTensorsData(const picojson::value& args, + picojson::object& out) { ScopeLogger("args: %s", args.serialize().c_str()); CHECK_ARGS(args, kTensorsInfoId, double, out); int tensorsInfoId = static_cast(args.get(kTensorsInfoId).get()); - TensorsInfo* tensorsInfo = GetTensorsInfoManager().GetTensorsInfo(tensorsInfoId); + TensorsInfo* tensorsInfo = + GetTensorsInfoManager().GetTensorsInfo(tensorsInfoId); if (nullptr == tensorsInfo) { - LogAndReportError(PlatformResult(ErrorCode::ABORT_ERR, "Internal TensorsInfo error"), &out, - ("Could not find TensorsInfo handle with given id: %d", tensorsInfoId)); + LogAndReportError( + PlatformResult(ErrorCode::ABORT_ERR, "Internal TensorsInfo error"), + &out, + ("Could not find TensorsInfo handle with given id: %d", tensorsInfoId)); return; } - TensorsData* tensorsData = GetTensorsInfoManager().CreateTensorsData(tensorsInfo); + TensorsData* tensorsData = + GetTensorsInfoManager().CreateTensorsData(tensorsInfo); if (!tensorsData) { - LogAndReportError(PlatformResult(ErrorCode::ABORT_ERR, "Internal TensorsInfo error"), &out, - ("Could not create TensorsData")); + LogAndReportError( + PlatformResult(ErrorCode::ABORT_ERR, "Internal TensorsInfo error"), + &out, ("Could not create TensorsData")); return; } out[kTensorsDataId] = picojson::value(static_cast(tensorsData->Id())); - out[kTensorsInfoId] = picojson::value(static_cast(tensorsData->TensorsInfoId())); + out[kTensorsInfoId] = + picojson::value(static_cast(tensorsData->TensorsInfoId())); ReportSuccess(out); } -void MlInstance::MLTensorsInfoClone(const picojson::value& args, picojson::object& out) { +void MlInstance::MLTensorsInfoClone(const picojson::value& args, + picojson::object& out) { ScopeLogger("args: %s", args.serialize().c_str()); CHECK_ARGS(args, kTensorsInfoId, double, out); int tensorsInfoId = static_cast(args.get(kTensorsInfoId).get()); - TensorsInfo* tensorsInfo = GetTensorsInfoManager().GetTensorsInfo(tensorsInfoId); + TensorsInfo* tensorsInfo = + GetTensorsInfoManager().GetTensorsInfo(tensorsInfoId); if (nullptr == tensorsInfo) { - LogAndReportError(PlatformResult(ErrorCode::ABORT_ERR, "Internal TensorsInfo error"), &out, - ("Could not find TensorsInfo handle with given id: %d", tensorsInfoId)); + LogAndReportError( + PlatformResult(ErrorCode::ABORT_ERR, "Internal TensorsInfo error"), + &out, + ("Could not find TensorsInfo handle with given id: %d", tensorsInfoId)); return; } TensorsInfo* cloned = GetTensorsInfoManager().CloneTensorsInfo(tensorsInfo); if (nullptr == cloned) { - LogAndReportError(PlatformResult(ErrorCode::ABORT_ERR, "Internal TensorsInfo error"), &out, - ("Could not clone TensorsInfo with given id: %d", tensorsInfoId)); + LogAndReportError( + PlatformResult(ErrorCode::ABORT_ERR, "Internal TensorsInfo error"), + &out, ("Could not clone TensorsInfo with given id: %d", tensorsInfoId)); return; } @@ -570,7 +639,8 @@ void MlInstance::MLTensorsInfoClone(const picojson::value& args, picojson::objec ReportSuccess(out); } -void MlInstance::MLTensorsInfoEquals(const picojson::value& args, picojson::object& out) { +void MlInstance::MLTensorsInfoEquals(const picojson::value& args, + picojson::object& out) { ScopeLogger("args: %s", args.serialize().c_str()); CHECK_ARGS(args, kTensorsInfoId, double, out); CHECK_ARGS(args, kOtherId, double, out); @@ -580,15 +650,18 @@ void MlInstance::MLTensorsInfoEquals(const picojson::value& args, picojson::obje TensorsInfo* first = GetTensorsInfoManager().GetTensorsInfo(firstId); if (nullptr == first) { - LogAndReportError(PlatformResult(ErrorCode::ABORT_ERR, "Internal TensorsInfo error"), &out, - ("Could not find TensorsInfo handle with given id: %d", firstId)); + LogAndReportError( + PlatformResult(ErrorCode::ABORT_ERR, "Internal TensorsInfo error"), + &out, ("Could not find TensorsInfo handle with given id: %d", firstId)); return; } TensorsInfo* second = GetTensorsInfoManager().GetTensorsInfo(secondId); if (nullptr == second) { - LogAndReportError(PlatformResult(ErrorCode::ABORT_ERR, "Internal TensorsInfo error"), &out, - ("Could not find TensorsInfo handle with given id: %d", secondId)); + LogAndReportError( + PlatformResult(ErrorCode::ABORT_ERR, "Internal TensorsInfo error"), + &out, + ("Could not find TensorsInfo handle with given id: %d", secondId)); return; } @@ -597,27 +670,35 @@ void MlInstance::MLTensorsInfoEquals(const picojson::value& args, picojson::obje ReportSuccess(val, out); } -void MlInstance::MLTensorsInfoDispose(const picojson::value& args, picojson::object& out) { +void MlInstance::MLTensorsInfoDispose(const picojson::value& args, + picojson::object& out) { ScopeLogger("args: %s", args.serialize().c_str()); CHECK_ARGS(args, kTensorsInfoId, double, out); int tensorsInfoId = static_cast(args.get(kTensorsInfoId).get()); - PlatformResult result = GetTensorsInfoManager().DisposeTensorsInfo(tensorsInfoId); + PlatformResult result = + GetTensorsInfoManager().DisposeTensorsInfo(tensorsInfoId); if (!result) { LogAndReportError(result, &out); } ReportSuccess(out); } -void MlInstance::MLTensorsDataDispose(const picojson::value& args, picojson::object& out) { +void MlInstance::MLTensorsDataDispose(const picojson::value& args, + picojson::object& out) { ScopeLogger("args: %s", args.serialize().c_str()); CHECK_ARGS(args, kTensorsDataId, double, out); - int tensors_data_id = static_cast(args.get(kTensorsDataId).get()); + int tensors_data_id = + static_cast(args.get(kTensorsDataId).get()); - TensorsData* tensors_data = GetTensorsDataManager().GetTensorsData(tensors_data_id); + TensorsData* tensors_data = + GetTensorsDataManager().GetTensorsData(tensors_data_id); if (nullptr == tensors_data) { - LogAndReportError(PlatformResult(ErrorCode::ABORT_ERR, "Internal TensorsData error"), &out, - ("Could not find TensorsData handle with given id: %d", tensors_data_id)); + LogAndReportError( + PlatformResult(ErrorCode::ABORT_ERR, "Internal TensorsData error"), + &out, + ("Could not find TensorsData handle with given id: %d", + tensors_data_id)); return; } @@ -627,7 +708,8 @@ void MlInstance::MLTensorsDataDispose(const picojson::value& args, picojson::obj } // Dispose underlying tensorsInfo - PlatformResult result = GetTensorsInfoManager().DisposeTensorsInfo(tensors_data->TensorsInfoId()); + PlatformResult result = + GetTensorsInfoManager().DisposeTensorsInfo(tensors_data->TensorsInfoId()); if (!result) { LogAndReportError(result, &out); return; @@ -641,7 +723,8 @@ void MlInstance::MLTensorsDataDispose(const picojson::value& args, picojson::obj ReportSuccess(out); } -void MlInstance::MLTensorsDataGetTensorRawData(const picojson::value& args, picojson::object& out) { +void MlInstance::MLTensorsDataGetTensorRawData(const picojson::value& args, + picojson::object& out) { ScopeLogger("args: %s", args.serialize().c_str()); CHECK_ARGS(args, kTensorsDataId, double, out); CHECK_ARGS(args, kIndex, double, out); @@ -651,31 +734,36 @@ void MlInstance::MLTensorsDataGetTensorRawData(const picojson::value& args, pico int tensor_data_id = static_cast(args.get(kTensorsDataId).get()); int index = static_cast(args.get(kIndex).get()); - TensorsData* tensors_data = GetTensorsDataManager().GetTensorsData(tensor_data_id); + TensorsData* tensors_data = + GetTensorsDataManager().GetTensorsData(tensor_data_id); if (nullptr == tensors_data) { - LogAndReportError(PlatformResult(ErrorCode::ABORT_ERR, "Internal TensorsData error"), &out, - ("Could not find TensorsData handle with given id: %d", tensor_data_id)); + LogAndReportError( + PlatformResult(ErrorCode::ABORT_ERR, "Internal TensorsData error"), + &out, + ("Could not find TensorsData handle with given id: %d", + tensor_data_id)); return; } unsigned int location[ML_TENSOR_RANK_LIMIT] = {}; - PlatformResult result = - util::GetLocationFromJsonArray(args.get(kLocation).get(), location); + PlatformResult result = util::GetLocationFromJsonArray( + args.get(kLocation).get(), location); if (!result) { LogAndReportError(result, &out); return; } unsigned int dimensions[ML_TENSOR_RANK_LIMIT] = {}; - result = tensors_data->GetTensorsInfo()->NativeGetTensorDimensions(index, dimensions); + result = tensors_data->GetTensorsInfo()->NativeGetTensorDimensions( + index, dimensions); if (!result) { LogAndReportError(result, &out); return; } unsigned int size[ML_TENSOR_RANK_LIMIT] = {}; - result = util::GetSizeFromJsonArray(args.get(kSize).get(), location, dimensions, - size); + result = util::GetSizeFromJsonArray(args.get(kSize).get(), + location, dimensions, size); if (!result) { LogAndReportError(result, &out); return; @@ -688,7 +776,8 @@ void MlInstance::MLTensorsDataGetTensorRawData(const picojson::value& args, pico return; } - std::vector out_data{raw_data.data, raw_data.data + raw_data.size_in_bytes}; + std::vector out_data{raw_data.data, + raw_data.data + raw_data.size_in_bytes}; out[kBuffer] = picojson::value(picojson::string_type, true); common::encode_binary_in_string(out_data, out[kBuffer].get()); @@ -702,8 +791,8 @@ void MlInstance::MLTensorsDataGetTensorRawData(const picojson::value& args, pico ReportSuccess(out); } -void MlInstance::MLTensorsDataGetTensorRawDataBinary(const picojson::value& args, - std::vector* out) { +void MlInstance::MLTensorsDataGetTensorRawDataBinary( + const picojson::value& args, std::vector* out) { ScopeLogger("args: %s", args.serialize().c_str()); // TODO handle errors to out // CHECK_ARGS(args, kTensorsDataId, double, out); @@ -714,17 +803,20 @@ void MlInstance::MLTensorsDataGetTensorRawDataBinary(const picojson::value& args int tensor_data_id = static_cast(args.get(kTensorsDataId).get()); int index = static_cast(args.get(kIndex).get()); - TensorsData* tensors_data = GetTensorsDataManager().GetTensorsData(tensor_data_id); + TensorsData* tensors_data = + GetTensorsDataManager().GetTensorsData(tensor_data_id); if (nullptr == tensors_data) { - LoggerE("Could not find TensorsData handle with given id: %d", tensor_data_id); - tools::ReportErrorToBinary(PlatformResult(ErrorCode::ABORT_ERR, "Internal TensorsData error"), - out); + LoggerE("Could not find TensorsData handle with given id: %d", + tensor_data_id); + tools::ReportErrorToBinary( + PlatformResult(ErrorCode::ABORT_ERR, "Internal TensorsData error"), + out); return; } unsigned int location[ML_TENSOR_RANK_LIMIT] = {}; - PlatformResult result = - util::GetLocationFromJsonArray(args.get(kLocation).get(), location); + PlatformResult result = util::GetLocationFromJsonArray( + args.get(kLocation).get(), location); if (!result) { LoggerE("Reporting error."); tools::ReportErrorToBinary(result, out); @@ -732,7 +824,8 @@ void MlInstance::MLTensorsDataGetTensorRawDataBinary(const picojson::value& args } unsigned int dimensions[ML_TENSOR_RANK_LIMIT] = {}; - result = tensors_data->GetTensorsInfo()->NativeGetTensorDimensions(index, dimensions); + result = tensors_data->GetTensorsInfo()->NativeGetTensorDimensions( + index, dimensions); if (!result) { LoggerE("Reporting error."); tools::ReportErrorToBinary(result, out); @@ -740,8 +833,8 @@ void MlInstance::MLTensorsDataGetTensorRawDataBinary(const picojson::value& args } unsigned int size[ML_TENSOR_RANK_LIMIT] = {}; - result = util::GetSizeFromJsonArray(args.get(kSize).get(), location, dimensions, - size); + result = util::GetSizeFromJsonArray(args.get(kSize).get(), + location, dimensions, size); if (!result) { LoggerE("Reporting error."); tools::ReportErrorToBinary(result, out); @@ -766,7 +859,8 @@ void MlInstance::MLTensorsDataGetTensorRawDataBinary(const picojson::value& args } out_json[kShape] = picojson::value{shape}; - std::vector out_data{raw_data.data, raw_data.data + raw_data.size_in_bytes}; + std::vector out_data{raw_data.data, + raw_data.data + raw_data.size_in_bytes}; // FORMAT: // 4 byte === JSON lenght (N) @@ -777,28 +871,36 @@ void MlInstance::MLTensorsDataGetTensorRawDataBinary(const picojson::value& args tools::ReportDataToBinary(out_data, out); } -void MlInstance::MLTensorsDataGetTensorType(const picojson::value& args, picojson::object& out) { +void MlInstance::MLTensorsDataGetTensorType(const picojson::value& args, + picojson::object& out) { ScopeLogger("args: %s", args.serialize().c_str()); CHECK_ARGS(args, kTensorsDataId, double, out); CHECK_ARGS(args, kIndex, double, out); - int tensors_data_id = static_cast(args.get(kTensorsDataId).get()); + int tensors_data_id = + static_cast(args.get(kTensorsDataId).get()); int index = static_cast(args.get(kIndex).get()); - TensorsData* tensors_data = GetTensorsDataManager().GetTensorsData(tensors_data_id); + TensorsData* tensors_data = + GetTensorsDataManager().GetTensorsData(tensors_data_id); if (nullptr == tensors_data) { - LogAndReportError(PlatformResult(ErrorCode::ABORT_ERR, "Internal TensorsData error"), &out, - ("Could not find TensorsData handle with given id: %d", tensors_data_id)); + LogAndReportError( + PlatformResult(ErrorCode::ABORT_ERR, "Internal TensorsData error"), + &out, + ("Could not find TensorsData handle with given id: %d", + tensors_data_id)); return; } std::string tensor_type_string; - PlatformResult result = - types::TensorTypeEnum.getName(tensors_data->GetTensorType(index), &tensor_type_string); + PlatformResult result = types::TensorTypeEnum.getName( + tensors_data->GetTensorType(index), &tensor_type_string); if (!result) { - LogAndReportError(PlatformResult(ErrorCode::ABORT_ERR, "Error getting name of TensorType"), + LogAndReportError(PlatformResult(ErrorCode::ABORT_ERR, + "Error getting name of TensorType"), &out, - ("TensorTypeEnum.getName() failed, error: %s", result.message().c_str())); + ("TensorTypeEnum.getName() failed, error: %s", + result.message().c_str())); return; } @@ -806,46 +908,54 @@ void MlInstance::MLTensorsDataGetTensorType(const picojson::value& args, picojso ReportSuccess(val, out); } -void MlInstance::MLTensorsDataSetTensorRawData(const picojson::value& args, picojson::object& out) { +void MlInstance::MLTensorsDataSetTensorRawData(const picojson::value& args, + picojson::object& out) { ScopeLogger(); CHECK_ARGS(args, kTensorsDataId, double, out); CHECK_ARGS(args, kIndex, double, out); CHECK_ARGS(args, kBuffer, std::string, out); CHECK_ARGS(args, kLocation, picojson::array, out); CHECK_ARGS(args, kSize, picojson::array, out); - LoggerD("%s, %s", kTensorsDataId.c_str(), args.get(kTensorsDataId).serialize().c_str()); + LoggerD("%s, %s", kTensorsDataId.c_str(), + args.get(kTensorsDataId).serialize().c_str()); LoggerD("%s, %s", kIndex.c_str(), args.get(kIndex).serialize().c_str()); LoggerD("%s, %s", kLocation.c_str(), args.get(kLocation).serialize().c_str()); LoggerD("%s, %s", kSize.c_str(), args.get(kSize).serialize().c_str()); - int tensors_data_id = static_cast(args.get(kTensorsDataId).get()); + int tensors_data_id = + static_cast(args.get(kTensorsDataId).get()); int index = static_cast(args.get(kIndex).get()); - TensorsData* tensors_data = GetTensorsDataManager().GetTensorsData(tensors_data_id); + TensorsData* tensors_data = + GetTensorsDataManager().GetTensorsData(tensors_data_id); if (nullptr == tensors_data) { - LogAndReportError(PlatformResult(ErrorCode::ABORT_ERR, "Internal TensorsData error"), &out, - ("Could not find TensorsData handle with given id: %d", tensors_data_id)); + LogAndReportError( + PlatformResult(ErrorCode::ABORT_ERR, "Internal TensorsData error"), + &out, + ("Could not find TensorsData handle with given id: %d", + tensors_data_id)); return; } unsigned int location[ML_TENSOR_RANK_LIMIT] = {}; - PlatformResult result = - util::GetLocationFromJsonArray(args.get(kLocation).get(), location); + PlatformResult result = util::GetLocationFromJsonArray( + args.get(kLocation).get(), location); if (!result) { LogAndReportError(result, &out); return; } unsigned int dimensions[ML_TENSOR_RANK_LIMIT] = {}; - result = tensors_data->GetTensorsInfo()->NativeGetTensorDimensions(index, dimensions); + result = tensors_data->GetTensorsInfo()->NativeGetTensorDimensions( + index, dimensions); if (!result) { LogAndReportError(result, &out); return; } unsigned int size[ML_TENSOR_RANK_LIMIT] = {}; - result = util::GetSizeFromJsonArray(args.get(kSize).get(), location, dimensions, - size); + result = util::GetSizeFromJsonArray(args.get(kSize).get(), + location, dimensions, size); if (!result) { LogAndReportError(result, &out); return; @@ -864,7 +974,8 @@ void MlInstance::MLTensorsDataSetTensorRawData(const picojson::value& args, pico ReportSuccess(out); } -void MlInstance::MLTensorsDataSetTensorRawDataBinary(const char* data, size_t data_size, +void MlInstance::MLTensorsDataSetTensorRawDataBinary(const char* data, + size_t data_size, picojson::object& out) { ScopeLogger(); /* @@ -879,7 +990,8 @@ void MlInstance::MLTensorsDataSetTensorRawDataBinary(const char* data, size_t da */ unsigned int call_args_len_begin = 0; unsigned int call_args_len = static_cast( - (data[call_args_len_begin] << 24) + (data[call_args_len_begin + 1] << 16) + + (data[call_args_len_begin] << 24) + + (data[call_args_len_begin + 1] << 16) + (data[call_args_len_begin + 2] << 8) + (data[call_args_len_begin + 3])); unsigned int buffer_len_begin = call_args_len_begin + 4; @@ -899,46 +1011,54 @@ void MlInstance::MLTensorsDataSetTensorRawDataBinary(const char* data, size_t da CHECK_ARGS(args, kIndex, double, out); CHECK_ARGS(args, kLocation, picojson::array, out); CHECK_ARGS(args, kSize, picojson::array, out); - LoggerD("%s, %s", kTensorsDataId.c_str(), args.get(kTensorsDataId).serialize().c_str()); + LoggerD("%s, %s", kTensorsDataId.c_str(), + args.get(kTensorsDataId).serialize().c_str()); LoggerD("%s, %s", kIndex.c_str(), args.get(kIndex).serialize().c_str()); LoggerD("%s, %s", kLocation.c_str(), args.get(kLocation).serialize().c_str()); LoggerD("%s, %s", kSize.c_str(), args.get(kSize).serialize().c_str()); - int tensors_data_id = static_cast(args.get(kTensorsDataId).get()); + int tensors_data_id = + static_cast(args.get(kTensorsDataId).get()); int index = static_cast(args.get(kIndex).get()); - TensorsData* tensors_data = GetTensorsDataManager().GetTensorsData(tensors_data_id); + TensorsData* tensors_data = + GetTensorsDataManager().GetTensorsData(tensors_data_id); if (nullptr == tensors_data) { - LogAndReportError(PlatformResult(ErrorCode::ABORT_ERR, "Internal TensorsData error"), &out, - ("Could not find TensorsData handle with given id: %d", tensors_data_id)); + LogAndReportError( + PlatformResult(ErrorCode::ABORT_ERR, "Internal TensorsData error"), + &out, + ("Could not find TensorsData handle with given id: %d", + tensors_data_id)); return; } unsigned int location[ML_TENSOR_RANK_LIMIT] = {}; - PlatformResult result = - util::GetLocationFromJsonArray(args.get(kLocation).get(), location); + PlatformResult result = util::GetLocationFromJsonArray( + args.get(kLocation).get(), location); if (!result) { LogAndReportError(result, &out); return; } unsigned int dimensions[ML_TENSOR_RANK_LIMIT] = {}; - result = tensors_data->GetTensorsInfo()->NativeGetTensorDimensions(index, dimensions); + result = tensors_data->GetTensorsInfo()->NativeGetTensorDimensions( + index, dimensions); if (!result) { LogAndReportError(result, &out); return; } unsigned int size[ML_TENSOR_RANK_LIMIT] = {}; - result = util::GetSizeFromJsonArray(args.get(kSize).get(), location, dimensions, - size); + result = util::GetSizeFromJsonArray(args.get(kSize).get(), + location, dimensions, size); if (!result) { LogAndReportError(result, &out); return; } - TensorRawData raw_data{reinterpret_cast(const_cast(data + buffer_begin)), - buffer_len}; + TensorRawData raw_data{ + reinterpret_cast(const_cast(data + buffer_begin)), + buffer_len}; result = tensors_data->SetTensorRawData(index, location, size, raw_data); if (!result) { LogAndReportError(result, &out); @@ -948,7 +1068,8 @@ void MlInstance::MLTensorsDataSetTensorRawDataBinary(const char* data, size_t da ReportSuccess(out); } -void MlInstance::MLSingleManagerOpenModel(const picojson::value& args, picojson::object& out) { +void MlInstance::MLSingleManagerOpenModel(const picojson::value& args, + picojson::object& out) { ScopeLogger("args: %s", args.serialize().c_str()); CHECK_ARGS(args, kModelPath, std::string, out); CHECK_ARGS(args, kInTensorsInfo, double, out); @@ -957,7 +1078,8 @@ void MlInstance::MLSingleManagerOpenModel(const picojson::value& args, picojson: CHECK_ARGS(args, kHwType, std::string, out); CHECK_ARGS(args, kIsDynamicMode, bool, out); - const auto& model_path = common::tools::ConvertUriToPath(args.get(kModelPath).get()); + const auto& model_path = + common::tools::ConvertUriToPath(args.get(kModelPath).get()); CHECK_STORAGE_ACCESS(model_path, &out); TensorsInfo* in_tensors_info = nullptr; @@ -965,8 +1087,10 @@ void MlInstance::MLSingleManagerOpenModel(const picojson::value& args, picojson: if (kNoId != inTensorId) { in_tensors_info = GetTensorsInfoManager().GetTensorsInfo(inTensorId); if (nullptr == in_tensors_info) { - LogAndReportError(PlatformResult(ErrorCode::ABORT_ERR, "Internal TensorsInfo error"), &out, - ("Could not find TensorsInfo handle with given id: %d", inTensorId)); + LogAndReportError( + PlatformResult(ErrorCode::ABORT_ERR, "Internal TensorsInfo error"), + &out, + ("Could not find TensorsInfo handle with given id: %d", inTensorId)); return; } } @@ -976,22 +1100,25 @@ void MlInstance::MLSingleManagerOpenModel(const picojson::value& args, picojson: if (kNoId != outTensorId) { out_tensors_info = GetTensorsInfoManager().GetTensorsInfo(outTensorId); if (nullptr == out_tensors_info) { - LogAndReportError(PlatformResult(ErrorCode::ABORT_ERR, "Internal TensorsInfo error"), &out, - ("Could not find TensorsInfo handle with given id: %d", outTensorId)); + LogAndReportError( + PlatformResult(ErrorCode::ABORT_ERR, "Internal TensorsInfo error"), + &out, + ("Could not find TensorsInfo handle with given id: %d", outTensorId)); return; } } ml_nnfw_type_e nnfw_e = ML_NNFW_TYPE_ANY; - PlatformResult result = - types::NNFWTypeEnum.getValue(args.get(kFwType).get(), &nnfw_e); + PlatformResult result = types::NNFWTypeEnum.getValue( + args.get(kFwType).get(), &nnfw_e); if (!result) { LogAndReportError(result, &out); return; } ml_nnfw_hw_e hw_e = ML_NNFW_HW_ANY; - result = types::HWTypeEnum.getValue(args.get(kHwType).get(), &hw_e); + result = + types::HWTypeEnum.getValue(args.get(kHwType).get(), &hw_e); if (!result) { LogAndReportError(result, &out); return; @@ -999,19 +1126,22 @@ void MlInstance::MLSingleManagerOpenModel(const picojson::value& args, picojson: auto is_dynamic_mode = args.get(kIsDynamicMode).get(); - auto logic = [this, model_path, in_tensors_info, out_tensors_info, nnfw_e, hw_e, - is_dynamic_mode](decltype(out) out) { + auto logic = [this, model_path, in_tensors_info, out_tensors_info, nnfw_e, + hw_e, is_dynamic_mode](decltype(out) out) { PlatformResult result = common::tools::CheckFileAvailability(model_path); if (!result) { LogAndReportError( - PlatformResult(ErrorCode::NOT_FOUND_ERR, "File does not exist or is not accessible"), - &out, ("File does not exist or is not accessible: %s", model_path.c_str())); + PlatformResult(ErrorCode::NOT_FOUND_ERR, + "File does not exist or is not accessible"), + &out, + ("File does not exist or is not accessible: %s", model_path.c_str())); return; } int res_id = -1; - result = single_manager_.OpenModel(model_path, in_tensors_info, out_tensors_info, nnfw_e, hw_e, - is_dynamic_mode, &res_id); + result = + single_manager_.OpenModel(model_path, in_tensors_info, out_tensors_info, + nnfw_e, hw_e, is_dynamic_mode, &res_id); if (!result) { ReportError(result, &out); return; @@ -1021,8 +1151,9 @@ void MlInstance::MLSingleManagerOpenModel(const picojson::value& args, picojson: ReportSuccess(out); }; - bool async = - (args.contains(kAsync) && args.get(kAsync).is()) ? args.get(kAsync).get() : false; + bool async = (args.contains(kAsync) && args.get(kAsync).is()) + ? args.get(kAsync).get() + : false; if (!async) { logic(out); @@ -1043,7 +1174,8 @@ void MlInstance::MLSingleManagerOpenModel(const picojson::value& args, picojson: } } -void MlInstance::MLSingleShotGetTensorsInfo(const picojson::value& args, picojson::object& out) { +void MlInstance::MLSingleShotGetTensorsInfo(const picojson::value& args, + picojson::object& out) { ScopeLogger("args: %s", args.serialize().c_str()); CHECK_ARGS(args, kId, double, out); CHECK_ARGS(args, kGetInputMode, bool, out); @@ -1063,7 +1195,8 @@ void MlInstance::MLSingleShotGetTensorsInfo(const picojson::value& args, picojso ReportSuccess(out); } -void MlInstance::MLSingleShotSetInputInfo(const picojson::value& args, picojson::object& out) { +void MlInstance::MLSingleShotSetInputInfo(const picojson::value& args, + picojson::object& out) { ScopeLogger("args: %s", args.serialize().c_str()); CHECK_ARGS(args, kId, double, out); CHECK_ARGS(args, kInTensorsInfo, double, out); @@ -1071,14 +1204,18 @@ void MlInstance::MLSingleShotSetInputInfo(const picojson::value& args, picojson: auto id = static_cast(args.get(kId).get()); auto inTensorId = static_cast(args.get(kInTensorsInfo).get()); - TensorsInfo* in_tensors_info = GetTensorsInfoManager().GetTensorsInfo(inTensorId); + TensorsInfo* in_tensors_info = + GetTensorsInfoManager().GetTensorsInfo(inTensorId); if (nullptr == in_tensors_info) { - LogAndReportError(PlatformResult(ErrorCode::ABORT_ERR, "Internal TensorsInfo error"), &out, - ("Could not find TensorsInfo handle with given id: %d", inTensorId)); + LogAndReportError( + PlatformResult(ErrorCode::ABORT_ERR, "Internal TensorsInfo error"), + &out, + ("Could not find TensorsInfo handle with given id: %d", inTensorId)); return; } - TensorsInfo* clone = GetTensorsInfoManager().CloneTensorsInfo(in_tensors_info); + TensorsInfo* clone = + GetTensorsInfoManager().CloneTensorsInfo(in_tensors_info); auto ret = single_manager_.SetNativeInputInfo(id, in_tensors_info); if (!ret) { @@ -1090,17 +1227,21 @@ void MlInstance::MLSingleShotSetInputInfo(const picojson::value& args, picojson: ReportSuccess(out); } -void MlInstance::MLSingleShotInvoke(const picojson::value& args, picojson::object& out) { +void MlInstance::MLSingleShotInvoke(const picojson::value& args, + picojson::object& out) { ScopeLogger("args: %s", args.serialize().c_str()); CHECK_ARGS(args, kId, double, out); CHECK_ARGS(args, kTensorsDataId, double, out); int id = static_cast(args.get(kId).get()); - int tensors_data_id = static_cast(args.get(kTensorsDataId).get()); - bool async = - (args.contains(kAsync) && args.get(kAsync).is()) ? args.get(kAsync).get() : false; - - TensorsData* in_tensors_data = GetTensorsDataManager().GetTensorsData(tensors_data_id); + int tensors_data_id = + static_cast(args.get(kTensorsDataId).get()); + bool async = (args.contains(kAsync) && args.get(kAsync).is()) + ? args.get(kAsync).get() + : false; + + TensorsData* in_tensors_data = + GetTensorsDataManager().GetTensorsData(tensors_data_id); if (async && in_tensors_data) { // in case of async flow need to prevent destroying entry data during invoke // from JS, creation of a copy @@ -1108,18 +1249,23 @@ void MlInstance::MLSingleShotInvoke(const picojson::value& args, picojson::objec in_tensors_data->GetTensorsInfo()->Handle(), in_tensors_data->Handle()); } if (nullptr == in_tensors_data) { - LogAndReportError(PlatformResult(ErrorCode::ABORT_ERR, "Internal TensorsData error"), &out, - ("Could not find TensorsData handle with given id: %d", tensors_data_id)); + LogAndReportError( + PlatformResult(ErrorCode::ABORT_ERR, "Internal TensorsData error"), + &out, + ("Could not find TensorsData handle with given id: %d", + tensors_data_id)); return; } - auto logic = [this, id, tensors_data_id, in_tensors_data, async](decltype(out) out) { + auto logic = [this, id, tensors_data_id, in_tensors_data, + async](decltype(out) out) { TensorsData* out_tensors_data = nullptr; auto ret = single_manager_.Invoke(id, in_tensors_data, &out_tensors_data); if (async) { // in case of async flow, the in_tensor_data with underlying TensorsInfo // was copied, thus need to be released here - GetTensorsInfoManager().DisposeTensorsInfo(in_tensors_data->GetTensorsInfo()); + GetTensorsInfoManager().DisposeTensorsInfo( + in_tensors_data->GetTensorsInfo()); GetTensorsDataManager().DisposeTensorsData(in_tensors_data); } if (!ret) { @@ -1127,8 +1273,10 @@ void MlInstance::MLSingleShotInvoke(const picojson::value& args, picojson::objec return; } - out[kTensorsDataId] = picojson::value(static_cast(out_tensors_data->Id())); - out[kTensorsInfoId] = picojson::value(static_cast(out_tensors_data->TensorsInfoId())); + out[kTensorsDataId] = + picojson::value(static_cast(out_tensors_data->Id())); + out[kTensorsInfoId] = + picojson::value(static_cast(out_tensors_data->TensorsInfoId())); ReportSuccess(out); }; @@ -1150,7 +1298,8 @@ void MlInstance::MLSingleShotInvoke(const picojson::value& args, picojson::objec } } -void MlInstance::MLSingleShotGetValue(const picojson::value& args, picojson::object& out) { +void MlInstance::MLSingleShotGetValue(const picojson::value& args, + picojson::object& out) { ScopeLogger("args: %s", args.serialize().c_str()); CHECK_ARGS(args, kId, double, out); CHECK_ARGS(args, kName, std::string, out); @@ -1168,7 +1317,8 @@ void MlInstance::MLSingleShotGetValue(const picojson::value& args, picojson::obj ReportSuccess(val, out); } -void MlInstance::MLSingleShotSetValue(const picojson::value& args, picojson::object& out) { +void MlInstance::MLSingleShotSetValue(const picojson::value& args, + picojson::object& out) { ScopeLogger("args: %s", args.serialize().c_str()); CHECK_ARGS(args, kId, double, out); CHECK_ARGS(args, kName, std::string, out); @@ -1187,7 +1337,8 @@ void MlInstance::MLSingleShotSetValue(const picojson::value& args, picojson::obj ReportSuccess(out); } -void MlInstance::MLSingleShotSetTimeout(const picojson::value& args, picojson::object& out) { +void MlInstance::MLSingleShotSetTimeout(const picojson::value& args, + picojson::object& out) { ScopeLogger("args: %s", args.serialize().c_str()); CHECK_ARGS(args, kId, double, out); CHECK_ARGS(args, kTimeout, double, out); @@ -1204,7 +1355,8 @@ void MlInstance::MLSingleShotSetTimeout(const picojson::value& args, picojson::o ReportSuccess(out); } -void MlInstance::MLSingleShotClose(const picojson::value& args, picojson::object& out) { +void MlInstance::MLSingleShotClose(const picojson::value& args, + picojson::object& out) { ScopeLogger("args: %s", args.serialize().c_str()); CHECK_ARGS(args, kId, double, out); @@ -1226,9 +1378,11 @@ bool CreatePipelineArgumentsAreInvalid(const picojson::value& args) { auto arguments_valid = args.get(kId).is(); arguments_valid &= args.get(kDefinition).is(); - arguments_valid &= (args.get(kPipelineStateChangeListenerName).is() || - args.get(kPipelineStateChangeListenerName).is()); - LoggerD("CreatePipeline arguments are %s", arguments_valid ? "valid" : "invalid"); + arguments_valid &= + (args.get(kPipelineStateChangeListenerName).is() || + args.get(kPipelineStateChangeListenerName).is()); + LoggerD("CreatePipeline arguments are %s", + arguments_valid ? "valid" : "invalid"); return !arguments_valid; } @@ -1240,7 +1394,9 @@ void MlInstance::MLPipelineManagerCreatePipeline(const picojson::value& args, ScopeLogger("args: %s", args.serialize().c_str()); if (CreatePipelineArgumentsAreInvalid(args)) { - ReportError(PlatformResult{ErrorCode::ABORT_ERR, "Could not create pipeline"}, &out); + ReportError( + PlatformResult{ErrorCode::ABORT_ERR, "Could not create pipeline"}, + &out); return; } @@ -1251,7 +1407,8 @@ void MlInstance::MLPipelineManagerCreatePipeline(const picojson::value& args, ? args.get(kPipelineStateChangeListenerName).get() : ""; - auto ret = pipeline_manager_.CreatePipeline(id, definition, state_change_listener_name); + auto ret = pipeline_manager_.CreatePipeline(id, definition, + state_change_listener_name); if (!ret) { ReportError(ret, &out); @@ -1261,7 +1418,8 @@ void MlInstance::MLPipelineManagerCreatePipeline(const picojson::value& args, ReportSuccess(out); } -void MlInstance::MLPipelineGetState(const picojson::value& args, picojson::object& out) { +void MlInstance::MLPipelineGetState(const picojson::value& args, + picojson::object& out) { ScopeLogger("args: %s", args.serialize().c_str()); if (!args.get(kId).is()) { @@ -1282,7 +1440,8 @@ void MlInstance::MLPipelineGetState(const picojson::value& args, picojson::objec ReportSuccess(state_value, out); } -void MlInstance::MLPipelineStart(const picojson::value& args, picojson::object& out) { +void MlInstance::MLPipelineStart(const picojson::value& args, + picojson::object& out) { ScopeLogger("args: %s", args.serialize().c_str()); CHECK_ARGS(args, kId, double, out); @@ -1299,7 +1458,8 @@ void MlInstance::MLPipelineStart(const picojson::value& args, picojson::object& ReportSuccess(out); } -void MlInstance::MLPipelineStop(const picojson::value& args, picojson::object& out) { +void MlInstance::MLPipelineStop(const picojson::value& args, + picojson::object& out) { ScopeLogger("args: %s", args.serialize().c_str()); CHECK_ARGS(args, kId, double, out); @@ -1316,7 +1476,8 @@ void MlInstance::MLPipelineStop(const picojson::value& args, picojson::object& o ReportSuccess(out); } -void MlInstance::MLPipelineDispose(const picojson::value& args, picojson::object& out) { +void MlInstance::MLPipelineDispose(const picojson::value& args, + picojson::object& out) { ScopeLogger("args: %s", args.serialize().c_str()); if (!args.get(kId).is()) { @@ -1336,7 +1497,8 @@ void MlInstance::MLPipelineDispose(const picojson::value& args, picojson::object ReportSuccess(out); } -void MlInstance::MLPipelineGetNodeInfo(const picojson::value& args, picojson::object& out) { +void MlInstance::MLPipelineGetNodeInfo(const picojson::value& args, + picojson::object& out) { ScopeLogger("args: %s", args.serialize().c_str()); CHECK_ARGS(args, kId, double, out); @@ -1355,7 +1517,8 @@ void MlInstance::MLPipelineGetNodeInfo(const picojson::value& args, picojson::ob ReportSuccess(out); } -void MlInstance::MLPipelineGetSource(const picojson::value& args, picojson::object& out) { +void MlInstance::MLPipelineGetSource(const picojson::value& args, + picojson::object& out) { ScopeLogger("args: %s", args.serialize().c_str()); CHECK_ARGS(args, kId, double, out); @@ -1374,7 +1537,8 @@ void MlInstance::MLPipelineGetSource(const picojson::value& args, picojson::obje ReportSuccess(out); } -void MlInstance::MLPipelineGetSwitch(const picojson::value& args, picojson::object& out) { +void MlInstance::MLPipelineGetSwitch(const picojson::value& args, + picojson::object& out) { ScopeLogger("args: %s", args.serialize().c_str()); if (!args.get(kId).is()) { @@ -1403,7 +1567,8 @@ void MlInstance::MLPipelineGetSwitch(const picojson::value& args, picojson::obje ReportSuccess(out); } -void MlInstance::MLPipelineGetValve(const picojson::value& args, picojson::object& out) { +void MlInstance::MLPipelineGetValve(const picojson::value& args, + picojson::object& out) { ScopeLogger("args: %s", args.serialize().c_str()); CHECK_ARGS(args, kId, double, out); @@ -1433,7 +1598,8 @@ void MlInstance::MLPipelineRegisterSinkListener(const picojson::value& args, auto sink_name = args.get(kName).get(); auto listener_name = args.get(kListenerName).get(); - auto ret = pipeline_manager_.RegisterSinkListener(sink_name, pipeline_id, listener_name); + auto ret = pipeline_manager_.RegisterSinkListener(sink_name, pipeline_id, + listener_name); if (!ret) { LogAndReportError(ret, &out); return; @@ -1461,8 +1627,8 @@ void MlInstance::MLPipelineUnregisterSinkListener(const picojson::value& args, ReportSuccess(out); } -void MlInstance::MLPipelineManagerRegisterCustomFilter(const picojson::value& args, - picojson::object& out) { +void MlInstance::MLPipelineManagerRegisterCustomFilter( + const picojson::value& args, picojson::object& out) { ScopeLogger("args: %s", args.serialize().c_str()); CHECK_ARGS(args, kName, std::string, out); @@ -1472,15 +1638,19 @@ void MlInstance::MLPipelineManagerRegisterCustomFilter(const picojson::value& ar const auto& custom_filter_name = args.get(kName).get(); const auto& listener_name = args.get(kListenerName).get(); - auto input_tensors_info_id = static_cast(args.get(kInputTensorsInfoId).get()); - auto output_tensors_info_id = static_cast(args.get(kOutputTensorsInfoId).get()); + auto input_tensors_info_id = + static_cast(args.get(kInputTensorsInfoId).get()); + auto output_tensors_info_id = + static_cast(args.get(kOutputTensorsInfoId).get()); TensorsInfo* input_tensors_info_ptr = GetTensorsInfoManager().GetTensorsInfo(input_tensors_info_id); if (!input_tensors_info_ptr) { LogAndReportError( - PlatformResult(ErrorCode::ABORT_ERR, "Internal TensorsInfo error"), &out, - ("Could not find TensorsInfo handle with given id: %d", input_tensors_info_id)); + PlatformResult(ErrorCode::ABORT_ERR, "Internal TensorsInfo error"), + &out, + ("Could not find TensorsInfo handle with given id: %d", + input_tensors_info_id)); return; } @@ -1488,13 +1658,16 @@ void MlInstance::MLPipelineManagerRegisterCustomFilter(const picojson::value& ar GetTensorsInfoManager().GetTensorsInfo(output_tensors_info_id); if (!output_tensors_info_ptr) { LogAndReportError( - PlatformResult(ErrorCode::ABORT_ERR, "Internal TensorsInfo error"), &out, - ("Could not find TensorsInfo handle with given id: %d", output_tensors_info_id)); + PlatformResult(ErrorCode::ABORT_ERR, "Internal TensorsInfo error"), + &out, + ("Could not find TensorsInfo handle with given id: %d", + output_tensors_info_id)); return; } auto ret = pipeline_manager_.RegisterCustomFilter( - custom_filter_name, listener_name, input_tensors_info_ptr, output_tensors_info_ptr); + custom_filter_name, listener_name, input_tensors_info_ptr, + output_tensors_info_ptr); if (!ret) { LogAndReportError(ret, &out); return; @@ -1503,8 +1676,8 @@ void MlInstance::MLPipelineManagerRegisterCustomFilter(const picojson::value& ar ReportSuccess(out); } -void MlInstance::MLPipelineManagerCustomFilterOutput(const picojson::value& args, - picojson::object& out) { +void MlInstance::MLPipelineManagerCustomFilterOutput( + const picojson::value& args, picojson::object& out) { ScopeLogger("args: %s", args.serialize().c_str()); CHECK_ARGS(args, kName, std::string, out); @@ -1515,7 +1688,8 @@ void MlInstance::MLPipelineManagerCustomFilterOutput(const picojson::value& args auto status = static_cast(args.get(kStatus).get()); auto request_id = static_cast(args.get(kRequestId).get()); - auto ret = pipeline_manager_.CustomFilterOutput(custom_filter_name, request_id, status); + auto ret = pipeline_manager_.CustomFilterOutput(custom_filter_name, + request_id, status); if (!ret) { LogAndReportError(ret, &out); return; @@ -1524,8 +1698,8 @@ void MlInstance::MLPipelineManagerCustomFilterOutput(const picojson::value& args ReportSuccess(out); } -void MlInstance::MLPipelineManagerUnregisterCustomFilter(const picojson::value& args, - picojson::object& out) { +void MlInstance::MLPipelineManagerUnregisterCustomFilter( + const picojson::value& args, picojson::object& out) { ScopeLogger("args: %s", args.serialize().c_str()); CHECK_ARGS(args, kName, std::string, out); @@ -1541,7 +1715,8 @@ void MlInstance::MLPipelineManagerUnregisterCustomFilter(const picojson::value& ReportSuccess(out); } -void MlInstance::MLPipelineNodeInfoGetProperty(const picojson::value& args, picojson::object& out) { +void MlInstance::MLPipelineNodeInfoGetProperty(const picojson::value& args, + picojson::object& out) { ScopeLogger("args: %s", args.serialize().c_str()); CHECK_ARGS(args, kId, double, out); @@ -1554,7 +1729,8 @@ void MlInstance::MLPipelineNodeInfoGetProperty(const picojson::value& args, pico const auto& node_name = args.get(kNodeName).get(); const auto& type = args.get(kType).get(); - PlatformResult result = pipeline_manager_.getProperty(id, node_name, name, type, &out); + PlatformResult result = + pipeline_manager_.getProperty(id, node_name, name, type, &out); if (!result) { LogAndReportError(result, &out); @@ -1564,7 +1740,8 @@ void MlInstance::MLPipelineNodeInfoGetProperty(const picojson::value& args, pico ReportSuccess(out); } -void MlInstance::MLPipelineNodeInfoSetProperty(const picojson::value& args, picojson::object& out) { +void MlInstance::MLPipelineNodeInfoSetProperty(const picojson::value& args, + picojson::object& out) { ScopeLogger("args: %s", args.serialize().c_str()); CHECK_ARGS(args, kId, double, out); @@ -1587,7 +1764,8 @@ void MlInstance::MLPipelineNodeInfoSetProperty(const picojson::value& args, pico } const picojson::value& property = args.get(kProperty); - PlatformResult result = pipeline_manager_.setProperty(id, node_name, name, type, property); + PlatformResult result = + pipeline_manager_.setProperty(id, node_name, name, type, property); if (!result) { LogAndReportError(result, &out); return; @@ -1596,7 +1774,8 @@ void MlInstance::MLPipelineNodeInfoSetProperty(const picojson::value& args, pico ReportSuccess(out); } -void MlInstance::MLPipelineGetInputTensorsInfo(const picojson::value& args, picojson::object& out) { +void MlInstance::MLPipelineGetInputTensorsInfo(const picojson::value& args, + picojson::object& out) { ScopeLogger("args: [%s]", args.serialize().c_str()); CHECK_ARGS(args, kId, double, out); @@ -1606,7 +1785,8 @@ void MlInstance::MLPipelineGetInputTensorsInfo(const picojson::value& args, pico const auto& name = args.get(kName).get(); int res_id = -1; - PlatformResult result = pipeline_manager_.getInputTensorsInfo(id, name, &res_id); + PlatformResult result = + pipeline_manager_.getInputTensorsInfo(id, name, &res_id); if (!result) { LogAndReportError(result, &out); return; @@ -1615,7 +1795,8 @@ void MlInstance::MLPipelineGetInputTensorsInfo(const picojson::value& args, pico ReportSuccess(out); } -void MlInstance::MLPipelineSourceInputData(const picojson::value& args, picojson::object& out) { +void MlInstance::MLPipelineSourceInputData(const picojson::value& args, + picojson::object& out) { ScopeLogger("args: [%s]", args.serialize().c_str()); CHECK_ARGS(args, kId, double, out); @@ -1624,17 +1805,21 @@ void MlInstance::MLPipelineSourceInputData(const picojson::value& args, picojson auto pipeline_id = static_cast(args.get(kId).get()); auto& source_name = args.get(kName).get(); - auto tensor_data_id = static_cast(args.get(kTensorsDataId).get()); + auto tensor_data_id = + static_cast(args.get(kTensorsDataId).get()); - TensorsData* tensors_data = GetTensorsDataManager().GetTensorsData(tensor_data_id); + TensorsData* tensors_data = + GetTensorsDataManager().GetTensorsData(tensor_data_id); if (nullptr == tensors_data) { - LogAndReportError(PlatformResult(ErrorCode::ABORT_ERR, "Internal Source error"), &out, - ("Could not get TensorData handle with given id: %d", tensor_data_id)); + LogAndReportError( + PlatformResult(ErrorCode::ABORT_ERR, "Internal Source error"), &out, + ("Could not get TensorData handle with given id: %d", tensor_data_id)); return; } - auto ret = pipeline_manager_.SourceInputData(pipeline_id, source_name, tensors_data); + auto ret = + pipeline_manager_.SourceInputData(pipeline_id, source_name, tensors_data); if (!ret) { LogAndReportError(ret, &out); return; @@ -1643,7 +1828,8 @@ void MlInstance::MLPipelineSourceInputData(const picojson::value& args, picojson ReportSuccess(out); } -void MlInstance::MLPipelineSwitchGetPadList(const picojson::value& args, picojson::object& out) { +void MlInstance::MLPipelineSwitchGetPadList(const picojson::value& args, + picojson::object& out) { ScopeLogger("args: [%s]", args.serialize().c_str()); CHECK_ARGS(args, kId, double, out); @@ -1653,7 +1839,8 @@ void MlInstance::MLPipelineSwitchGetPadList(const picojson::value& args, picojso auto& switch_name = args.get(kName).get(); picojson::array pad_list; - auto ret = pipeline_manager_.SwitchGetPadList(pipeline_id, switch_name, &pad_list); + auto ret = + pipeline_manager_.SwitchGetPadList(pipeline_id, switch_name, &pad_list); if (!ret) { LogAndReportError(ret, &out); return; @@ -1662,7 +1849,8 @@ void MlInstance::MLPipelineSwitchGetPadList(const picojson::value& args, picojso ReportSuccess(picojson::value{std::move(pad_list)}, out); } -void MlInstance::MLPipelineSwitchSelect(const picojson::value& args, picojson::object& out) { +void MlInstance::MLPipelineSwitchSelect(const picojson::value& args, + picojson::object& out) { ScopeLogger("args: [%s]", args.serialize().c_str()); CHECK_ARGS(args, kId, double, out); @@ -1682,7 +1870,8 @@ void MlInstance::MLPipelineSwitchSelect(const picojson::value& args, picojson::o ReportSuccess(out); } -void MlInstance::MLPipelineValveSetOpen(const picojson::value& args, picojson::object& out) { +void MlInstance::MLPipelineValveSetOpen(const picojson::value& args, + picojson::object& out) { ScopeLogger("args: %s", args.serialize().c_str()); CHECK_ARGS(args, kId, double, out); @@ -1702,7 +1891,8 @@ void MlInstance::MLPipelineValveSetOpen(const picojson::value& args, picojson::o ReportSuccess(out); } -void MlInstance::MLPipelineValveIsOpen(const picojson::value& args, picojson::object& out) { +void MlInstance::MLPipelineValveIsOpen(const picojson::value& args, + picojson::object& out) { ScopeLogger("args: %s", args.serialize().c_str()); CHECK_ARGS(args, kId, double, out); @@ -1721,7 +1911,9 @@ void MlInstance::MLPipelineValveIsOpen(const picojson::value& args, picojson::ob ReportSuccess(picojson::value{open}, out); } -void MlInstance::MLTrainerLayerSetProperty(const picojson::value& args, picojson::object& out) { +#ifdef NNTRAINER_SUPPORTED +void MlInstance::MLTrainerLayerSetProperty(const picojson::value& args, + picojson::object& out) { ScopeLogger("args: %s", args.serialize().c_str()); CHECK_ARGS(args, kId, double, out); CHECK_ARGS(args, kName, std::string, out); @@ -1739,7 +1931,8 @@ void MlInstance::MLTrainerLayerSetProperty(const picojson::value& args, picojson ReportSuccess(out); } -void MlInstance::MLTrainerLayerCreate(const picojson::value& args, picojson::object& out) { +void MlInstance::MLTrainerLayerCreate(const picojson::value& args, + picojson::object& out) { ScopeLogger("args: %s", args.serialize().c_str()); CHECK_ARGS(args, kType, std::string, out); int id = -1; @@ -1794,7 +1987,8 @@ void MlInstance::MLTrainerLayerDispose(const picojson::value& args, ReportSuccess(out); } -void MlInstance::MLTrainerOptimizerSetProperty(const picojson::value& args, picojson::object& out) { +void MlInstance::MLTrainerOptimizerSetProperty(const picojson::value& args, + picojson::object& out) { ScopeLogger("args: %s", args.serialize().c_str()); CHECK_ARGS(args, kId, double, out); CHECK_ARGS(args, kName, std::string, out); @@ -1804,7 +1998,8 @@ void MlInstance::MLTrainerOptimizerSetProperty(const picojson::value& args, pico auto name = args.get(kName).get(); auto value = args.get(kValue).get(); - PlatformResult result = trainer_manager_.OptimizerSetProperty(id, name, value); + PlatformResult result = + trainer_manager_.OptimizerSetProperty(id, name, value); if (!result) { ReportError(result, &out); return; @@ -1812,7 +2007,8 @@ void MlInstance::MLTrainerOptimizerSetProperty(const picojson::value& args, pico ReportSuccess(out); } -void MlInstance::MLTrainerOptimizerCreate(const picojson::value& args, picojson::object& out) { +void MlInstance::MLTrainerOptimizerCreate(const picojson::value& args, + picojson::object& out) { ScopeLogger("args: %s", args.serialize().c_str()); CHECK_ARGS(args, kType, std::string, out); int id = -1; @@ -1849,7 +2045,8 @@ void MlInstance::MLTrainerOptimizerDispose(const picojson::value& args, ReportSuccess(out); } -void MlInstance::MLTrainerModelCreate(const picojson::value& args, picojson::object& out) { +void MlInstance::MLTrainerModelCreate(const picojson::value& args, + picojson::object& out) { ScopeLogger("args: %s", args.serialize().c_str()); int id = -1; PlatformResult result; @@ -1872,7 +2069,8 @@ void MlInstance::MLTrainerModelCreate(const picojson::value& args, picojson::obj ReportSuccess(out); } -void MlInstance::MLTrainerModelCompile(const picojson::value& args, picojson::object& out) { +void MlInstance::MLTrainerModelCompile(const picojson::value& args, + picojson::object& out) { ScopeLogger("args: %s", args.serialize().c_str()); CHECK_ARGS(args, kId, double, out); CHECK_ARGS(args, kOptions, picojson::object, out); @@ -1889,7 +2087,8 @@ void MlInstance::MLTrainerModelCompile(const picojson::value& args, picojson::ob ReportSuccess(out); } -void MlInstance::MLTrainerModelAddLayer(const picojson::value& args, picojson::object& out) { +void MlInstance::MLTrainerModelAddLayer(const picojson::value& args, + picojson::object& out) { ScopeLogger("args: %s", args.serialize().c_str()); CHECK_ARGS(args, kId, double, out); CHECK_ARGS(args, kLayerId, double, out); @@ -1906,7 +2105,8 @@ void MlInstance::MLTrainerModelAddLayer(const picojson::value& args, picojson::o ReportSuccess(out); } -void MlInstance::MLTrainerModelRun(const picojson::value& args, picojson::object& out) { +void MlInstance::MLTrainerModelRun(const picojson::value& args, + picojson::object& out) { ScopeLogger("args: %s", args.serialize().c_str()); CHECK_ARGS(args, kId, double, out); CHECK_ARGS(args, kOptions, picojson::object, out); @@ -1940,7 +2140,8 @@ void MlInstance::MLTrainerModelRun(const picojson::value& args, picojson::object ReportSuccess(out); } -void MlInstance::MLTrainerModelSummarize(const picojson::value& args, picojson::object& out) { +void MlInstance::MLTrainerModelSummarize(const picojson::value& args, + picojson::object& out) { ScopeLogger("args: %s", args.serialize().c_str()); CHECK_ARGS(args, kId, double, out); CHECK_ARGS(args, kLevel, std::string, out); @@ -2047,7 +2248,8 @@ void MlInstance::MLTrainerModelLoad(const picojson::value& args, ReportSuccess(out); } -void MlInstance::MLTrainerModelSetDataset(const picojson::value& args, picojson::object& out) { +void MlInstance::MLTrainerModelSetDataset(const picojson::value& args, + picojson::object& out) { ScopeLogger("args: %s", args.serialize().c_str()); CHECK_ARGS(args, kId, double, out); CHECK_ARGS(args, kDatasetId, double, out); @@ -2064,7 +2266,8 @@ void MlInstance::MLTrainerModelSetDataset(const picojson::value& args, picojson: ReportSuccess(out); } -void MlInstance::MLTrainerModelSetOptimizer(const picojson::value& args, picojson::object& out) { +void MlInstance::MLTrainerModelSetOptimizer(const picojson::value& args, + picojson::object& out) { ScopeLogger("args: %s", args.serialize().c_str()); CHECK_ARGS(args, kId, double, out); CHECK_ARGS(args, kOptimizerId, double, out); @@ -2108,8 +2311,8 @@ void MlInstance::MLTrainerDatasetCreateFromFile(const picojson::value& args, const std::string& valid_file_path = args.get(kValid).get(); const std::string& test_file_path = args.get(kTest).get(); - PlatformResult result = - trainer_manager_.CreateFileDataset(id, train_file_path, valid_file_path, test_file_path); + PlatformResult result = trainer_manager_.CreateFileDataset( + id, train_file_path, valid_file_path, test_file_path); if (!result) { ReportError(result, &out); return; @@ -2118,7 +2321,8 @@ void MlInstance::MLTrainerDatasetCreateFromFile(const picojson::value& args, ReportSuccess(out); } -void MlInstance::MLTrainerDatasetSetProperty(const picojson::value& args, picojson::object& out) { +void MlInstance::MLTrainerDatasetSetProperty(const picojson::value& args, + picojson::object& out) { ScopeLogger("args: %s", args.serialize().c_str()); CHECK_ARGS(args, kId, double, out); CHECK_ARGS(args, kName, std::string, out); @@ -2159,6 +2363,7 @@ void MlInstance::MLTrainerDatasetDispose(const picojson::value& args, } ReportSuccess(out); } +#endif #undef CHECK_EXIST #undef CHECK_TYPE diff --git a/src/ml/ml_instance.h b/src/ml/ml_instance.h index 6269a6e..b78ae46 100644 --- a/src/ml/ml_instance.h +++ b/src/ml/ml_instance.h @@ -19,15 +19,15 @@ #include "common/extension.h" #include "common/worker.h" - #include "ml/ml_pipeline_manager.h" #include "ml/ml_single_manager.h" +#ifdef NNTRAINER_SUPPORTED #include "ml/ml_trainer_manager.h" -#include "nnstreamer/nnstreamer-single.h" -#include "nnstreamer/nnstreamer.h" - +#endif #include "ml_tensors_data_manager.h" #include "ml_tensors_info_manager.h" +#include "nnstreamer/nnstreamer-single.h" +#include "nnstreamer/nnstreamer.h" namespace extension { namespace ml { @@ -40,28 +40,44 @@ class MlInstance : public common::ParsedInstance { TensorsDataManager& GetTensorsDataManager(); private: - void MLCheckNNFWAvailability(const picojson::value& args, picojson::object& out); - void MLTensorsInfoCountGetter(const picojson::value& args, picojson::object& out); + void MLCheckNNFWAvailability(const picojson::value& args, + picojson::object& out); + void MLTensorsInfoCountGetter(const picojson::value& args, + picojson::object& out); void MLTensorsInfoCreate(const picojson::value& args, picojson::object& out); - void MLTensorsInfoAddTensorInfo(const picojson::value& args, picojson::object& out); - void MLTensorsInfoGetDimensions(const picojson::value& args, picojson::object& out); - void MLTensorsInfoSetDimensions(const picojson::value& args, picojson::object& out); - void MLTensorsInfoGetTensorName(const picojson::value& args, picojson::object& out); - void MLTensorsInfoSetTensorName(const picojson::value& args, picojson::object& out); - void MLTensorsInfoGetTensorSize(const picojson::value& args, picojson::object& out); - void MLTensorsInfoGetTensorType(const picojson::value& args, picojson::object& out); - void MLTensorsInfoSetTensorType(const picojson::value& args, picojson::object& out); - void MLTensorsInfoGetTensorsData(const picojson::value& args, picojson::object& out); + void MLTensorsInfoAddTensorInfo(const picojson::value& args, + picojson::object& out); + void MLTensorsInfoGetDimensions(const picojson::value& args, + picojson::object& out); + void MLTensorsInfoSetDimensions(const picojson::value& args, + picojson::object& out); + void MLTensorsInfoGetTensorName(const picojson::value& args, + picojson::object& out); + void MLTensorsInfoSetTensorName(const picojson::value& args, + picojson::object& out); + void MLTensorsInfoGetTensorSize(const picojson::value& args, + picojson::object& out); + void MLTensorsInfoGetTensorType(const picojson::value& args, + picojson::object& out); + void MLTensorsInfoSetTensorType(const picojson::value& args, + picojson::object& out); + void MLTensorsInfoGetTensorsData(const picojson::value& args, + picojson::object& out); void MLTensorsInfoClone(const picojson::value& args, picojson::object& out); void MLTensorsInfoEquals(const picojson::value& args, picojson::object& out); void MLTensorsInfoDispose(const picojson::value& args, picojson::object& out); void MLTensorsDataDispose(const picojson::value& args, picojson::object& out); - void MLTensorsDataGetTensorRawData(const picojson::value& args, picojson::object& out); - void MLTensorsDataGetTensorRawDataBinary(const picojson::value& args, std::vector* vec); - void MLTensorsDataGetTensorType(const picojson::value& args, picojson::object& out); - void MLTensorsDataSetTensorRawData(const picojson::value& args, picojson::object& out); - void MLTensorsDataSetTensorRawDataBinary(const char* data, size_t size, picojson::object& out); + void MLTensorsDataGetTensorRawData(const picojson::value& args, + picojson::object& out); + void MLTensorsDataGetTensorRawDataBinary(const picojson::value& args, + std::vector* vec); + void MLTensorsDataGetTensorType(const picojson::value& args, + picojson::object& out); + void MLTensorsDataSetTensorRawData(const picojson::value& args, + picojson::object& out); + void MLTensorsDataSetTensorRawDataBinary(const char* data, size_t size, + picojson::object& out); /* * ########## IMPORTANT ########## @@ -72,13 +88,17 @@ class MlInstance : public common::ParsedInstance { common::Worker worker_; SingleManager single_manager_; - void MLSingleManagerOpenModel(const picojson::value& args, picojson::object& out); - void MLSingleShotGetTensorsInfo(const picojson::value& args, picojson::object& out); - void MLSingleShotSetInputInfo(const picojson::value& args, picojson::object& out); + void MLSingleManagerOpenModel(const picojson::value& args, + picojson::object& out); + void MLSingleShotGetTensorsInfo(const picojson::value& args, + picojson::object& out); + void MLSingleShotSetInputInfo(const picojson::value& args, + picojson::object& out); void MLSingleShotInvoke(const picojson::value& args, picojson::object& out); void MLSingleShotGetValue(const picojson::value& args, picojson::object& out); void MLSingleShotSetValue(const picojson::value& args, picojson::object& out); - void MLSingleShotSetTimeout(const picojson::value& args, picojson::object& out); + void MLSingleShotSetTimeout(const picojson::value& args, + picojson::object& out); void MLSingleShotClose(const picojson::value& args, picojson::object& out); /* @@ -105,7 +125,8 @@ class MlInstance : public common::ParsedInstance { */ PipelineManager pipeline_manager_; - void MLPipelineManagerCreatePipeline(const picojson::value& args, picojson::object& out); + void MLPipelineManagerCreatePipeline(const picojson::value& args, + picojson::object& out); void MLPipelineGetState(const picojson::value& args, picojson::object& out); @@ -115,7 +136,8 @@ class MlInstance : public common::ParsedInstance { void MLPipelineDispose(const picojson::value& args, picojson::object& out); - void MLPipelineGetNodeInfo(const picojson::value& args, picojson::object& out); + void MLPipelineGetNodeInfo(const picojson::value& args, + picojson::object& out); void MLPipelineGetSource(const picojson::value& args, picojson::object& out); @@ -123,57 +145,79 @@ class MlInstance : public common::ParsedInstance { void MLPipelineGetValve(const picojson::value& args, picojson::object& out); - void MLPipelineRegisterSinkListener(const picojson::value& args, picojson::object& out); + void MLPipelineRegisterSinkListener(const picojson::value& args, + picojson::object& out); - void MLPipelineUnregisterSinkListener(const picojson::value& args, picojson::object& out); + void MLPipelineUnregisterSinkListener(const picojson::value& args, + picojson::object& out); - void MLPipelineManagerRegisterCustomFilter(const picojson::value& args, picojson::object& out); + void MLPipelineManagerRegisterCustomFilter(const picojson::value& args, + picojson::object& out); - void MLPipelineManagerCustomFilterOutput(const picojson::value& args, picojson::object& out); + void MLPipelineManagerCustomFilterOutput(const picojson::value& args, + picojson::object& out); - void MLPipelineManagerUnregisterCustomFilter(const picojson::value& args, picojson::object& out); + void MLPipelineManagerUnregisterCustomFilter(const picojson::value& args, + picojson::object& out); - void MLPipelineNodeInfoGetProperty(const picojson::value& args, picojson::object& out); + void MLPipelineNodeInfoGetProperty(const picojson::value& args, + picojson::object& out); - void MLPipelineNodeInfoSetProperty(const picojson::value& args, picojson::object& out); + void MLPipelineNodeInfoSetProperty(const picojson::value& args, + picojson::object& out); - void MLPipelineGetInputTensorsInfo(const picojson::value& args, picojson::object& out); + void MLPipelineGetInputTensorsInfo(const picojson::value& args, + picojson::object& out); - void MLPipelineSourceInputData(const picojson::value& args, picojson::object& out); + void MLPipelineSourceInputData(const picojson::value& args, + picojson::object& out); - void MLPipelineSwitchGetPadList(const picojson::value& args, picojson::object& out); + void MLPipelineSwitchGetPadList(const picojson::value& args, + picojson::object& out); - void MLPipelineSwitchSelect(const picojson::value& args, picojson::object& out); + void MLPipelineSwitchSelect(const picojson::value& args, + picojson::object& out); - void MLPipelineValveSetOpen(const picojson::value& args, picojson::object& out); + void MLPipelineValveSetOpen(const picojson::value& args, + picojson::object& out); - void MLPipelineValveIsOpen(const picojson::value& args, picojson::object& out); + void MLPipelineValveIsOpen(const picojson::value& args, + picojson::object& out); +#ifdef NNTRAINER_SUPPORTED TrainerManager trainer_manager_; - void MLTrainerLayerSetProperty(const picojson::value& args, picojson::object& out); + void MLTrainerLayerSetProperty(const picojson::value& args, + picojson::object& out); void MLTrainerLayerCreate(const picojson::value& args, picojson::object& out); void MLTrainerLayerGetName(const picojson::value& args, picojson::object& out); void MLTrainerLayerDispose(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 MLTrainerOptimizerSetProperty(const picojson::value& args, + picojson::object& out); + void MLTrainerOptimizerCreate(const picojson::value& args, + picojson::object& out); void MLTrainerOptimizerDispose(const picojson::value& args, picojson::object& out); void MLTrainerModelCreate(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 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 MLTrainerModelSummarize(const picojson::value& args, + picojson::object& out); void MLTrainerModelCheckMetrics(const picojson::value& args, picojson::object& out); void MLTrainerModelSave(const picojson::value& args, picojson::object& out); void MLTrainerModelLoad(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 MLTrainerModelSetDataset(const picojson::value& args, + picojson::object& out); + void MLTrainerModelSetOptimizer(const picojson::value& args, + picojson::object& out); void MLTrainerModelDispose(const picojson::value& args, picojson::object& out); @@ -181,6 +225,7 @@ class MlInstance : public common::ParsedInstance { void MLTrainerDatasetSetProperty(const picojson::value& args, picojson::object& out); void MLTrainerDatasetDispose(const picojson::value& args, picojson::object& out); +#endif }; } // namespace ml diff --git a/src/ml/ml_utils.cc b/src/ml/ml_utils.cc index 92fea3f..7d7a611 100644 --- a/src/ml/ml_utils.cc +++ b/src/ml/ml_utils.cc @@ -64,6 +64,7 @@ const PlatformEnum TensorTypeEnum{ {"INT64", ML_TENSOR_TYPE_INT64}, {"UINT64", ML_TENSOR_TYPE_UINT64}, {"UNKNOWN", ML_TENSOR_TYPE_UNKNOWN}}; +#ifdef NNTRAINER_SUPPORTED const PlatformEnum OptimizerTypeEnum{ {"OPTIMIZER_ADAM", ML_TRAIN_OPTIMIZER_TYPE_ADAM}, {"OPTIMIZER_SGD", ML_TRAIN_OPTIMIZER_TYPE_SGD}, @@ -104,7 +105,7 @@ const PlatformEnum DatasetModeEnum{ {"MODE_TRAIN", ML_TRAIN_DATASET_MODE_TRAIN}, {"MODE_VALID", ML_TRAIN_DATASET_MODE_VALID}, {"MODE_TEST", ML_TRAIN_DATASET_MODE_TEST}}; - +#endif } // namespace types namespace util { diff --git a/src/ml/ml_utils.h b/src/ml/ml_utils.h index 37cd89c..3b06b09 100644 --- a/src/ml/ml_utils.h +++ b/src/ml/ml_utils.h @@ -18,7 +18,9 @@ #define ML_ML_UTILS_H_ #include +#ifdef NNTRAINER_SUPPORTED #include +#endif #if __cplusplus > 201402L #include @@ -45,11 +47,13 @@ extern const PlatformEnum HWTypeEnum; extern const PlatformEnum NNFWTypeEnum; extern const PlatformEnum TensorTypeEnum; +#ifdef NNTRAINER_SUPPORTED extern const PlatformEnum OptimizerTypeEnum; extern const PlatformEnum LayerTypeEnum; extern const PlatformEnum SummaryTypeEnum; extern const PlatformEnum ModelSaveFormatEnum; extern const PlatformEnum DatasetModeEnum; +#endif } // namespace types -- 2.7.4