| 295 | } |
| 296 | |
| 297 | TinyNNStatus parse_device_model( |
| 298 | DeviceModel* model, CombineModel* c_model, |
| 299 | ns(DeviceModel_table_t) fbs_device_model) { |
| 300 | //! parse tensor |
| 301 | ns(Tensor_vec_t) fbs_tensors = ns(DeviceModel_tensor_pool(fbs_device_model)); |
| 302 | int nr_tensor = ns(Tensor_vec_len(fbs_tensors)); |
| 303 | LOG_DEBUG("device model tensor number: %d\n", nr_tensor); |
| 304 | model->nr_tensor = nr_tensor; |
| 305 | model->tensors = tinynn_malloc(sizeof(Tensor) * nr_tensor); |
| 306 | memset(model->tensors, 0, sizeof(Tensor) * nr_tensor); |
| 307 | for (int i = 0; i < nr_tensor; i++) { |
| 308 | LOG_DEBUG("parse tensor id: %d\n", i); |
| 309 | ns(Tensor_table_t) fbs_tensor = ns(Tensor_vec_at(fbs_tensors, i)); |
| 310 | Tensor* tensor = model->tensors + i; |
| 311 | if (parse_tensor(tensor, fbs_tensor, i) != TinyNN_SUCCESS) { |
| 312 | LOG_ERROR("parse tensor error!\n"); |
| 313 | goto exit; |
| 314 | } |
| 315 | } |
| 316 | |
| 317 | //! parse instructions |
| 318 | ns(Instruction_union_vec_t) fbs_instructions_union = |
| 319 | ns(DeviceModel_instructions_union(fbs_device_model)); |
| 320 | int nr_instruction = ns(Instruction_union_vec_len(fbs_instructions_union)); |
| 321 | LOG_DEBUG("device model instruction number: %d\n", nr_instruction); |
| 322 | model->nr_instruction = nr_instruction; |
| 323 | model->instructions = tinynn_malloc(sizeof(Instruction) * nr_instruction); |
| 324 | memset(model->instructions, 0, sizeof(Instruction) * nr_instruction); |
| 325 | for (int i = 0; i < nr_instruction; i++) { |
| 326 | LOG_DEBUG("parse instruction id: %d\n", i); |
| 327 | ns(Instruction_union_t) fbs_instruction_union = |
| 328 | ns(Instruction_union_vec_at(fbs_instructions_union, i)); |
| 329 | Instruction* inst = model->instructions + i; |
| 330 | if (vm_instruction_load((VM*)(c_model->vm), fbs_instruction_union, inst) != |
| 331 | TinyNN_SUCCESS) { |
| 332 | goto exit; |
| 333 | } |
| 334 | } |
| 335 | |
| 336 | //! inputs |
| 337 | flatbuffers_int32_vec_t fbs_inputs = ns(DeviceModel_inputs(fbs_device_model)); |
| 338 | model->nr_input = flatbuffers_int32_vec_len(fbs_inputs); |
| 339 | model->inputs = tinynn_malloc(model->nr_input * sizeof(Tensor*)); |
| 340 | memset(model->inputs, 0, model->nr_input * sizeof(Tensor*)); |
| 341 | for (int i = 0; i < model->nr_input; i++) { |
| 342 | int index = flatbuffers_int32_vec_at(fbs_inputs, i); |
| 343 | *(model->inputs + i) = model->tensors + index; |
| 344 | (*(model->inputs + i))->is_input = 1; |
| 345 | } |
| 346 | //! outputs |
| 347 | flatbuffers_int32_vec_t fbs_outputs = ns(DeviceModel_outputs(fbs_device_model)); |
| 348 | flatbuffers_int32_vec_t fbs_weight_outputs = |
| 349 | ns(DeviceModel_weight_outputs(fbs_device_model)); |
| 350 | flatbuffers_string_vec_t fbs_weight_outputs_name = |
| 351 | ns(DeviceModel_weight_outputs_name(fbs_device_model)); |
| 352 | int nr_outputs = flatbuffers_int32_vec_len(fbs_outputs); |
| 353 | int nr_weight_outputs = flatbuffers_int32_vec_len(fbs_weight_outputs); |
| 354 | TINYNN_ASSERT( |
no test coverage detected