namespace extension {
namespace ml {
-TensorsInfo::TensorsInfo(ml_tensors_info_h handle, int id) : handle_(handle), id_(id), count_(0) {
+TensorsInfo::TensorsInfo(ml_tensors_info_h handle, int id) : handle_(handle), id_(id), count_(-1) {
ScopeLogger();
}
}
int TensorsInfo::Count() {
+ if (-1 == count_) {
+ LoggerD("Lazy initialization of count_ property.");
+ unsigned int c;
+ if (NativeGetCount(&c)) {
+ count_ = c;
+ } else {
+ LoggerE("Could not fetch TensorsInfo count from native layer");
+ }
+ }
return this->count_;
}
return nullptr;
}
auto t = std::make_shared<TensorsInfo>(clone_h, cloneId);
- t->count_ = this->Count();
return t;
}
return t.get();
};
+TensorsInfo* TensorsInfoManager::CreateTensorsInfo(ml_tensors_info_h handle) {
+ ScopeLogger();
+
+ int id = nextId_++;
+ auto t = std::make_shared<TensorsInfo>(handle, id);
+ map_by_id_[id] = t;
+ map_by_handle_[handle] = t;
+
+ return t.get();
+};
+
TensorsInfo* TensorsInfoManager::CloneTensorsInfo(TensorsInfo* src) {
ScopeLogger();
if (nullptr == src) {
TensorsInfoManager();
~TensorsInfoManager();
TensorsInfo* CreateTensorsInfo();
+ // handle will be destroyed on TensorsInfo object destruction
+ TensorsInfo* CreateTensorsInfo(ml_tensors_info_h handle);
TensorsInfo* CloneTensorsInfo(TensorsInfo* src);
TensorsInfo* GetTensorsInfo(int id);