[ml] Add customRequirement to tizen.ml.checkNNFWAvailability 66/263366/1
authorPawel Wasowski <p.wasowski2@samsung.com>
Tue, 31 Aug 2021 12:24:44 +0000 (14:24 +0200)
committerPawel Wasowski <p.wasowski2@samsung.com>
Tue, 31 Aug 2021 12:38:21 +0000 (14:38 +0200)
ACR: TWDAPI-282

[Verification] Tested on TM1 in Chrome DevTools with the snippets below

tizen.ml.checkNNFWAvailability("TENSORFLOW_LITE", "CPU") // true

tizen.ml.checkNNFWAvailability("TENSORFLOW_LITE", "CPU",
                               'test custom requirement'); // true

The native implementation is not ready and returns the same value
whether the customRequirement is passed or not. That's why
tizen.ml.checkNNFWAvailability also returns "true" twice above

Change-Id: I971a5f49d4ea389ad953c28fc08da21bafb59ee2
Signed-off-by: Pawel Wasowski <p.wasowski2@samsung.com>
src/ml/js/ml_manager.js
src/ml/ml_instance.cc
src/ml/ml_utils.cc
src/ml/ml_utils.h

index 05dcef0..b094dfb 100755 (executable)
@@ -75,11 +75,17 @@ MachineLearningManager.prototype.checkNNFWAvailability = function() {
             type: types_.ENUM,
             values: Object.values(HWType),
             optional: false
+        },
+        {
+            name: 'customRequirement',
+            type: types_.STRING,
+            optional: true
         }
     ]);
     var callArgs = {
         nnfw: args.nnfw,
-        hw: args.hw
+        hw: args.hw,
+        customRequirement: args.customRequirement || null
     };
 
     var result = native_.callSync('MLCheckNNFWAvailability', callArgs);
index 63ac32d..ff31270 100644 (file)
@@ -53,6 +53,7 @@ const std::string kLocation = "location";
 const std::string kModelPath = "modelPath";
 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 kOtherId = "otherId";
@@ -184,10 +185,15 @@ void MlInstance::MLCheckNNFWAvailability(const picojson::value& args, picojson::
   ScopeLogger("args: %s", args.serialize().c_str());
   CHECK_EXIST(args, kNnfw, out)
   CHECK_EXIST(args, kHw, out)
+  CHECK_EXIST(args, kCustomRequirement, out)
 
   std::string nnfw = args.get(kNnfw).get<std::string>();
   std::string hw = args.get(kHw).get<std::string>();
-  bool availability_val = util::CheckNNFWAvailability(nnfw, hw);
+  optional<std::string> customRequirement;
+  if (args.get(kCustomRequirement).is<std::string>()) {
+    customRequirement = args.get(kCustomRequirement).get<std::string>();
+  }
+  bool availability_val = util::CheckNNFWAvailability(nnfw, hw, customRequirement);
 
   picojson::value available = picojson::value{availability_val};
   ReportSuccess(available, out);
index fe0f5a8..2cd17b7 100644 (file)
@@ -93,7 +93,8 @@ PlatformResult ToPlatformResult(int ml_error_code, const std::string& error_mess
   }
 }
 
-bool CheckNNFWAvailability(const std::string& nnfw, const std::string& hw) {
+bool CheckNNFWAvailability(const std::string& nnfw, const std::string& hw,
+                           optional<std::string> customRequirement) {
   ScopeLogger();
   ml_nnfw_type_e nnfw_e = ML_NNFW_TYPE_ANY;
   ml_nnfw_hw_e hw_e = ML_NNFW_HW_ANY;
@@ -108,15 +109,16 @@ bool CheckNNFWAvailability(const std::string& nnfw, const std::string& hw) {
     LoggerE("HWTypeEnum.getValue() failed, error: %s", result.message().c_str());
     return false;
   }
+  const char* customRequirementPtr = customRequirement ? customRequirement->c_str() : nullptr;
   bool available = false;
-  int ret = ml_check_nnfw_availability(nnfw_e, hw_e, &available);
+  int ret = ml_check_nnfw_availability_full(nnfw_e, hw_e, customRequirementPtr, &available);
 
   if (ML_ERROR_NONE != ret) {
-    LoggerE("ml_check_nnfw_availability failed: %d (%s)", ret, get_error_message(ret));
+    LoggerE("ml_check_nnfw_availability_full failed: %d (%s)", ret, get_error_message(ret));
     return false;
   }
 
-  LoggerD("ml_check_nnfw_availability: %s", available ? "true" : "false");
+  LoggerD("ml_check_nnfw_availability_full: %s", available ? "true" : "false");
   return available;
 }
 
index 34dbb63..e91b5aa 100644 (file)
 
 #include <nnstreamer/nnstreamer.h>
 
+#if __cplusplus > 201402L
+#include <optional>
+using std::optional;
+#else
+#include "common/optional.h"
+using common::optional;
+#endif
+
 #include "common/picojson.h"
 #include "common/platform_enum.h"
 #include "common/platform_result.h"
@@ -42,7 +50,8 @@ namespace util {
 
 PlatformResult ToPlatformResult(int ml_error_code, const std::string& error_message);
 
-bool CheckNNFWAvailability(const std::string& nnfw, const std::string& hw);
+bool CheckNNFWAvailability(const std::string& nnfw, const std::string& hw,
+                           const optional<std::string> customRequirement);
 
 PlatformResult GetDimensionsFromJsonArray(const picojson::array& dim,
                                           unsigned int dimensions[ML_TENSOR_RANK_LIMIT]);