| 129 | } |
| 130 | |
| 131 | bool TmSerializer::LoadModel(const std::vector<std::string>& file_list, StaticGraph* graph) |
| 132 | { |
| 133 | int fd; |
| 134 | void* mmap_buf; |
| 135 | int mmap_size; |
| 136 | |
| 137 | if(file_list.size() != GetFileNum()) |
| 138 | return false; |
| 139 | |
| 140 | if(!LoadBinaryFile(file_list[0].c_str(), fd, mmap_buf, mmap_size)) |
| 141 | return false; |
| 142 | |
| 143 | SetGraphSource(graph, file_list[0]); |
| 144 | SetGraphSourceFormat(graph, "tengine"); |
| 145 | SetGraphConstTensorFile(graph, file_list[0]); |
| 146 | |
| 147 | const uint16_t* ver_main = reinterpret_cast<const uint16_t*>(mmap_buf); |
| 148 | TmSerializerPtr tm_serializer; |
| 149 | if(*ver_main < 2) |
| 150 | { |
| 151 | LOG_WARN() |
| 152 | << "The input tengine model file is in old format, please regenerate it by using tengine convert tool.\n"; |
| 153 | TmSerializerManager::SafeGet("tm_v1", tm_serializer); |
| 154 | } |
| 155 | else |
| 156 | TmSerializerManager::SafeGet("tm_v2", tm_serializer); |
| 157 | |
| 158 | bool ret = tm_serializer->LoadModelFromMem(mmap_buf, graph); |
| 159 | |
| 160 | munmap(const_cast<void*>(mmap_buf), mmap_size); |
| 161 | close(fd); |
| 162 | return ret; |
| 163 | } |
| 164 | |
| 165 | bool TmSerializer::LoadModel(const std::vector<const void*>& addr_list, const std::vector<int>& size_list, |
| 166 | StaticGraph* graph, bool transfer_mem) |