// OpenModelSuccessCallback
// SingleShot interface (input & output)
+var ValidInputExceptions = ['TypeMismatch', 'AbortError'];
var SingleShot = function(id) {
Object.defineProperties(this, {
+ input: {
+ get: function() {
+ var result = native_.callSync('MLSingleShotGetInputInfo', {
+ id: this._id
+ });
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObjectAndValidate(
+ result,
+ ValidInputExceptions,
+ AbortError
+ );
+ }
+
+ return new TensorsInfo(result.id);
+ },
+ set: function(v) {
+ /* TODO*/
+ }
+ },
_id: { value: id, writable: false, enumerable: false }
});
};
CHECK_EXIST(args, name, out) \
CHECK_TYPE(args, name, type, out)
-MlInstance::MlInstance() : pipeline_manager_{this} {
+MlInstance::MlInstance() : single_manager_{&tensors_info_manager_}, pipeline_manager_{this} {
ScopeLogger();
using namespace std::placeholders;
REGISTER_METHOD(MLSingleManagerOpenModel);
// MachineLearningSingle::openModelAsync()
// OpenModelSuccessCallback
- // SingleShot input
+ REGISTER_METHOD(MLSingleShotGetInputInfo);
// SingleShot output
// SingleShot::invoke()
// SingleShot::getValue()
// OpenModelSuccessCallback
// SingleShot input
+void MlInstance::MLSingleShotGetInputInfo(const picojson::value& args, picojson::object& out) {
+ ScopeLogger("args: %s", args.serialize().c_str());
+ CHECK_ARGS(args, kId, double, out);
+
+ auto id = static_cast<int>(args.get(kId).get<double>());
+
+ int res_id = -1;
+ auto ret = single_manager_.GetNativeInputInfo(id, &res_id);
+ if (!ret) {
+ ReportError(ret, &out);
+ return;
+ }
+
+ out["id"] = picojson::value(static_cast<double>(res_id));
+ ReportSuccess(out);
+}
// SingleShot output
void MLSingleManagerOpenModel(const picojson::value& args, picojson::object& out);
// MachineLearningSingle::openModelAsync()
// OpenModelSuccessCallback
- // SingleShot input
+ void MLSingleShotGetInputInfo(const picojson::value& args, picojson::object& out);
// SingleShot output
// SingleShot::invoke()
// SingleShot::getValue()
namespace extension {
namespace ml {
-SingleManager::SingleManager() : nextId_{0} {
+SingleManager::SingleManager(TensorsInfoManager* tim) : nextId_{0}, tim_{tim} {
ScopeLogger();
}
// MachineLearningSingle::openModelAsync()
// OpenModelSuccessCallback
// SingleShot input
+SingleShot* SingleManager::GetSingleShot(int id) {
+ ScopeLogger("id: %d", id);
+
+ if (singles_.end() != singles_.find(id)) {
+ return singles_[id].get();
+ }
+
+ return nullptr;
+}
+
+PlatformResult SingleManager::GetNativeInputInfo(int id, int* res_id) {
+ ScopeLogger();
+
+ SingleShot* single = GetSingleShot(id);
+ if (!single) {
+ LoggerE("Could not find singleShot handle");
+ return PlatformResult(ErrorCode::ABORT_ERR);
+ }
+
+ ml_tensors_info_h in_info = nullptr;
+ PlatformResult ret = single->GetInputInfo(&in_info);
+ if (!ret) {
+ return ret;
+ }
+
+ auto tensor_info = tim_->CreateTensorsInfo(in_info);
+ *res_id = tensor_info->Id();
+ return PlatformResult{};
+}
// SingleShot output
// SingleShot::invoke()
// SingleShot::getValue()
class SingleManager {
public:
- SingleManager();
+ SingleManager(TensorsInfoManager* tim);
~SingleManager();
+ SingleManager() = delete;
SingleManager(const SingleManager&) = delete;
SingleManager& operator=(const SingleManager&) = delete;
bool isDynamicMode, int* res_id);
// MachineLearningSingle::openModelAsync()
// OpenModelSuccessCallback
- // SingleShot input
+ PlatformResult GetNativeInputInfo(int id, int* res_id);
// SingleShot output
// SingleShot::invoke()
// SingleShot::getValue()
private:
int nextId_;
std::map<int, std::unique_ptr<SingleShot>> singles_;
+ TensorsInfoManager* tim_;
+ SingleShot* GetSingleShot(int id);
};
} // namespace ml
}
}
-// SingleShot input
+PlatformResult SingleShot::GetInputInfo(ml_tensors_info_h* result) {
+ ScopeLogger();
+ ml_tensors_info_h info = nullptr;
+ int ret = ml_single_get_input_info(handle_, &info);
+ if (ML_ERROR_NONE != ret) {
+ LoggerE("ml_single_get_input_info failed: %d (%s)", ret, get_error_message(ret));
+ return util::ToPlatformResult(ret, "Failed to get tensor dimension");
+ }
+
+ *result = info;
+ return PlatformResult{};
+}
// SingleShot output
SingleShot& operator=(SingleShot&& o) = delete;
~SingleShot();
- // SingleShot input
+ PlatformResult GetInputInfo(ml_tensors_info_h* result);
// SingleShot output