From fdc8ac6960e80f3e202c59e9afd0558d07765b65 Mon Sep 17 00:00:00 2001 From: Lukasz Bardeli Date: Fri, 29 Jan 2021 12:43:15 +0100 Subject: [PATCH] [ML][Pipeline] Input data ACR: TWDAPI-274 [Verification] Code compiles without error. Tested in chrome console. var pipeline_input = tizen.ml.pipeline.createPipeline("appsrc name=srcx ! other/tensor,dimension=(string)1:1:1:1,type=(string)int8,framerate=(fraction)0/1 ! tensor_sink name=sinkx") var source_input = pipeline_input.getSource("srcx") var ti = new tizen.ml.TensorsInfo(); ti.addTensorInfo("tensor1", "UINT8", [1, 1]) var td = ti.getTensorsData(); console.log(td.count) source_input.inputData(td) tensor_input = source_input.inputTensorsInfo td_input = tensor_input.getTensorsData() tt = td_input.tensorsInfo console.log(tt.getTensorName(0)) Change-Id: I4dd4c3cec5d77d36598551a5d3aa8d8a9fbc9b5a Signed-off-by: Lukasz Bardeli --- src/ml/js/ml_pipeline.js | 34 +++++++++++++++++++++++++++++++--- src/ml/ml_instance.cc | 27 +++++++++++++++++++++++++++ src/ml/ml_instance.h | 2 +- src/ml/ml_pipeline.cc | 10 ++++++++++ src/ml/ml_pipeline.h | 3 ++- src/ml/ml_pipeline_manager.cc | 11 +++++++++++ src/ml/ml_pipeline_manager.h | 3 ++- src/ml/ml_pipeline_source.cc | 15 +++++++++++++++ src/ml/ml_pipeline_source.h | 3 +++ 9 files changed, 102 insertions(+), 6 deletions(-) diff --git a/src/ml/js/ml_pipeline.js b/src/ml/js/ml_pipeline.js index cf92f3f5..5429ba7b 100755 --- a/src/ml/js/ml_pipeline.js +++ b/src/ml/js/ml_pipeline.js @@ -509,12 +509,40 @@ NodeInfo.prototype.setProperty = function() { }; //NodeInfo::setProperty() end -//Source::inputTensorsInfo begin +//Source::inputData() begin +var ValidSourceInputDataExceptions = [ + 'InvalidStateError', + 'NotFoundError', + 'NotSupportedError', + 'AbortError' +]; +Source.prototype.inputData = function() { + var args = validator_.validateArgs(arguments, [ + { + name: 'data', + type: types_.PLATFORM_OBJECT, + values: TensorsData + } + ]); + + var nativeArgs = { + id: this._pipeline_id, + name: this.name, + tensorsDataId: args.data._id + }; -//Source::inputTensorsInfo end + var result = native_.callSync('MLPipelineSourceInputData', nativeArgs); -//Source::inputData() begin + if (native_.isFailure(result)) { + throw native_.getErrorObjectAndValidate( + result, + ValidSourceInputDataExceptions, + AbortError + ); + } + return result.result; +}; //Source::inputData() end //Switch::getPadList() begin diff --git a/src/ml/ml_instance.cc b/src/ml/ml_instance.cc index 6e4262e4..51b18258 100644 --- a/src/ml/ml_instance.cc +++ b/src/ml/ml_instance.cc @@ -133,6 +133,7 @@ MlInstance::MlInstance() REGISTER_METHOD(MLPipelineNodeInfoSetProperty); REGISTER_METHOD(MLPipelineGetSource); REGISTER_METHOD(MLPipelineGetInputTensorsInfo); + REGISTER_METHOD(MLPipelineSourceInputData); // Pipeline API end #undef REGISTER_METHOD @@ -1073,7 +1074,33 @@ void MlInstance::MLPipelineGetInputTensorsInfo(const picojson::value& args, pico // Source::inputTensorsInfo end // Source::inputData() begin +void MlInstance::MLPipelineSourceInputData(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); + CHECK_ARGS(args, kTensorsDataId, double, out); + 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()); + + 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)); + return; + } + + auto ret = pipeline_manager_.SourceInputData(pipeline_id, source_name, tensors_data); + if (!ret) { + LogAndReportError(ret, &out); + return; + } + + ReportSuccess(out); +} // Source::inputData() end // Switch::getPadList() begin diff --git a/src/ml/ml_instance.h b/src/ml/ml_instance.h index a6f1b9f8..981badc7 100644 --- a/src/ml/ml_instance.h +++ b/src/ml/ml_instance.h @@ -143,7 +143,7 @@ class MlInstance : public common::ParsedInstance { // Source::inputTensorsInfo end // Source::inputData() begin - + void MLPipelineSourceInputData(const picojson::value& args, picojson::object& out); // Source::inputData() end // Switch::getPadList() begin diff --git a/src/ml/ml_pipeline.cc b/src/ml/ml_pipeline.cc index 1d1cce50..a180d4e4 100644 --- a/src/ml/ml_pipeline.cc +++ b/src/ml/ml_pipeline.cc @@ -356,7 +356,17 @@ PlatformResult Pipeline::getInputTensorsInfo(const std::string& name, ml_tensors // Source::inputTensorsInfo end // Source::inputData() begin +PlatformResult Pipeline::SourceInputData(const std::string& name, TensorsData* tensors_data) { + ScopeLogger(); + + auto source_it = sources_.find(name); + if (sources_.end() == source_it) { + LoggerD("Source [%s] not found", name.c_str()); + return PlatformResult{ErrorCode::NOT_FOUND_ERR, "Source not found"}; + } + return source_it->second->SourceInputData(tensors_data); +} // Source::inputData() end // Switch::getPadList() begin diff --git a/src/ml/ml_pipeline.h b/src/ml/ml_pipeline.h index d6606c85..49b681ee 100644 --- a/src/ml/ml_pipeline.h +++ b/src/ml/ml_pipeline.h @@ -30,6 +30,7 @@ #include "ml_pipeline_source.h" #include "ml_pipeline_switch.h" #include "ml_pipeline_valve.h" +#include "ml_tensors_data_manager.h" using common::PlatformResult; using namespace extension::ml::pipeline; @@ -119,7 +120,7 @@ class Pipeline { // Source::inputTensorsInfo end // Source::inputData() begin - + PlatformResult SourceInputData(const std::string& name, TensorsData* tensors_data); // Source::inputData() end // Switch::getPadList() begin diff --git a/src/ml/ml_pipeline_manager.cc b/src/ml/ml_pipeline_manager.cc index 32512296..7d898710 100644 --- a/src/ml/ml_pipeline_manager.cc +++ b/src/ml/ml_pipeline_manager.cc @@ -260,7 +260,18 @@ PlatformResult PipelineManager::getInputTensorsInfo(int id, const std::string& n // Source::inputTensorsInfo end // Source::inputData() begin +PlatformResult PipelineManager::SourceInputData(int id, const std::string& name, + TensorsData* tensors_data) { + ScopeLogger(); + + auto pipeline_it = pipelines_.find(id); + if (pipelines_.end() == pipeline_it) { + LoggerD("Pipeline not found: [%d]", id); + return PlatformResult{ErrorCode::NOT_FOUND_ERR, "Pipeline not found"}; + } + return pipeline_it->second->SourceInputData(name, tensors_data); +} // Source::inputData() end // Switch::getPadList() begin diff --git a/src/ml/ml_pipeline_manager.h b/src/ml/ml_pipeline_manager.h index 18e8c4f7..b76d3a66 100644 --- a/src/ml/ml_pipeline_manager.h +++ b/src/ml/ml_pipeline_manager.h @@ -22,6 +22,7 @@ #include "common/platform_result.h" #include "ml_pipeline.h" +#include "ml_tensors_data_manager.h" #include "ml_tensors_info_manager.h" using common::PlatformResult; @@ -107,7 +108,7 @@ class PipelineManager { // Source::inputTensorsInfo end // Source::inputData() begin - + PlatformResult SourceInputData(int id, const std::string& name, TensorsData* tensors_data); // Source::inputData() end // Switch::getPadList() begin diff --git a/src/ml/ml_pipeline_source.cc b/src/ml/ml_pipeline_source.cc index 7ac0104b..418b4522 100644 --- a/src/ml/ml_pipeline_source.cc +++ b/src/ml/ml_pipeline_source.cc @@ -81,6 +81,21 @@ PlatformResult Source::getInputTensorsInfo(ml_tensors_info_h* result) { return PlatformResult{}; } +PlatformResult Source::SourceInputData(TensorsData* tensors_data) { + ScopeLogger(); + + ml_tensors_data_h tensor_data_handle = tensors_data ? tensors_data->Handle() : nullptr; + + auto ret = + ml_pipeline_src_input_data(source_, tensor_data_handle, ML_PIPELINE_BUF_POLICY_DO_NOT_FREE); + if (ML_ERROR_NONE != ret) { + LoggerE(" ml_pipeline_src_input_data failed: %d (%s)", ret, get_error_message(ret)); + return util::ToPlatformResult(ret, "Failed to get tensor info"); + } + + return PlatformResult{}; +} + } // namespace pipeline } // namespace ml } // namespace extension \ No newline at end of file diff --git a/src/ml/ml_pipeline_source.h b/src/ml/ml_pipeline_source.h index cdd0154e..e0cf981f 100644 --- a/src/ml/ml_pipeline_source.h +++ b/src/ml/ml_pipeline_source.h @@ -24,6 +24,8 @@ #include "common/platform_result.h" +#include "ml_tensors_data_manager.h" + using common::PlatformResult; namespace extension { @@ -38,6 +40,7 @@ class Source { ~Source(); PlatformResult getInputTensorsInfo(ml_tensors_info_h* result); + PlatformResult SourceInputData(TensorsData* tensors_data); Source(const Source&) = delete; Source& operator=(const Source&) = delete; -- 2.34.1