[ML][Pipeline] Input data 39/252639/2
authorLukasz Bardeli <l.bardeli@samsung.com>
Fri, 29 Jan 2021 11:43:15 +0000 (12:43 +0100)
committerLukasz Bardeli <l.bardeli@samsung.com>
Tue, 2 Feb 2021 13:52:26 +0000 (14:52 +0100)
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 <l.bardeli@samsung.com>
src/ml/js/ml_pipeline.js
src/ml/ml_instance.cc
src/ml/ml_instance.h
src/ml/ml_pipeline.cc
src/ml/ml_pipeline.h
src/ml/ml_pipeline_manager.cc
src/ml/ml_pipeline_manager.h
src/ml/ml_pipeline_source.cc
src/ml/ml_pipeline_source.h

index cf92f3f58def3ab8fab70c150f03d9e7c886076f..5429ba7b99e7b29ee62907f7a7f274507707162e 100755 (executable)
@@ -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
index 6e4262e4cc650a153e086251dc1241dc5eb8a873..51b182580788535e8767407ea8b206d4b6e50ff6 100644 (file)
@@ -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<int>(args.get(kId).get<double>());
+  auto& source_name = args.get(kName).get<std::string>();
+  auto tensor_data_id = static_cast<int>(args.get(kTensorsDataId).get<double>());
+
+  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
index a6f1b9f8efa182babc8a59f76b2a10a4a3897dc6..981badc73a78f57c916a32aea433f04bff5834d4 100644 (file)
@@ -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
index 1d1cce50b00a31012168463c6f6a539f581d659b..a180d4e43f54c684ce27e4bf1755235706a2317f 100644 (file)
@@ -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
index d6606c85594071da29d712a73833e85413116046..49b681ee942614d409baf7d97dc104af066c2e49 100644 (file)
@@ -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
index 32512296625347ae265b35eb5242bc8e3514c676..7d898710313e9315d16066ab4c4460efef8e8a57 100644 (file)
@@ -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
index 18e8c4f7b692d1e80dd37b7c2015a3fc590eb877..b76d3a6629022f86315d94fc9eb2eb5f427ddf14 100644 (file)
@@ -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
index 7ac0104ba7b741fe12d6ea22f41dc69dfa7a53e1..418b45227131b6702192106be457950aacddbafe 100644 (file)
@@ -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
index cdd0154ea24708cf34b10e489e0bdd78675afc79..e0cf981f0c5381f6f406fd488c49d3eecfb795b8 100644 (file)
@@ -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;