| 610 | } |
| 611 | |
| 612 | bool TmSerializer2::LoadGraph(StaticGraph* graph, const TM2_Model* tm_model, void* mmap_buf) |
| 613 | { |
| 614 | const TM2_Vector_offsets* v_graphs = GetTmPtr<TM2_Vector_offsets>(mmap_buf, tm_model->offset_vo_subgraphs); |
| 615 | const TM2_Subgraph* tm_graph = GetTmPtr<TM2_Subgraph>(mmap_buf, v_graphs->offsets[0]); |
| 616 | |
| 617 | const TM2_Vector_offsets* v_nodes = GetTmPtr<TM2_Vector_offsets>(mmap_buf, tm_graph->offset_vo_seq_nodes); |
| 618 | const TM2_Vector_offsets* v_tensors = GetTmPtr<TM2_Vector_offsets>(mmap_buf, tm_graph->offset_vo_tensors); |
| 619 | const TM2_Vector_offsets* v_buffers = GetTmPtr<TM2_Vector_offsets>(mmap_buf, tm_graph->offset_vo_buffers); |
| 620 | |
| 621 | SetGraphLayout(graph, tm_graph->graph_layout); |
| 622 | SetModelLayout(graph, tm_graph->model_layout); |
| 623 | |
| 624 | /* Load const tensors */ |
| 625 | for(unsigned int i = 0; i < v_tensors->v_num; i++) |
| 626 | { |
| 627 | const TM2_Tensor* tm_tensor = GetTmPtr<TM2_Tensor>(mmap_buf, v_tensors->offsets[i]); |
| 628 | const TM2_Buffer* tm_buf; |
| 629 | if(tm_tensor->type == kConstTensor) |
| 630 | tm_buf = GetTmPtr<TM2_Buffer>(mmap_buf, v_buffers->offsets[tm_tensor->buffer_id]); |
| 631 | else |
| 632 | tm_buf = nullptr; |
| 633 | LoadTensor(graph, tm_tensor, tm_buf, mmap_buf); |
| 634 | } |
| 635 | |
| 636 | /* Create static nodes */ |
| 637 | unsigned int i; |
| 638 | for(i = 0; i < v_nodes->v_num; i++) |
| 639 | { |
| 640 | const TM2_Node* tm_node = GetTmPtr<TM2_Node>(mmap_buf, v_nodes->offsets[i]); |
| 641 | int idx = tm_node->node_id; |
| 642 | std::string tm_node_name; |
| 643 | if(tm_node->offset_s_nname == TM2_NOT_SET) |
| 644 | tm_node_name = "node_" + std::to_string(idx); |
| 645 | else |
| 646 | { |
| 647 | const TM2_String* tm_str = GetTmPtr<TM2_String>(mmap_buf, tm_node->offset_s_nname); |
| 648 | tm_node_name.assign(GetTmPtr<char>(mmap_buf, tm_str->offset_data), tm_str->size - 1); |
| 649 | } |
| 650 | |
| 651 | const TM2_Operator* tm_operator = GetTmPtr<TM2_Operator>(mmap_buf, tm_node->offset_t_operator); |
| 652 | const std::string& tm_op_name = GetOpStr(tm_operator->operator_type); |
| 653 | |
| 654 | if(!FindOpLoadMethod(tm_op_name)) |
| 655 | { |
| 656 | LOG_ERROR() << "cannot find load function for operator: " << tm_op_name << "\n"; |
| 657 | break; |
| 658 | } |
| 659 | |
| 660 | StaticNode* node = CreateStaticNode(graph, tm_node_name); |
| 661 | if(!LoadNode(graph, node, tm_node, mmap_buf)) |
| 662 | break; |
| 663 | |
| 664 | op_load_t op_func = any_cast<op_load_t>(GetOpLoadMethod(tm_op_name)); |
| 665 | |
| 666 | if(!op_func(graph, node, mmap_buf, tm_operator)) |
| 667 | break; |
| 668 | |
| 669 | /* Set the dynamic shape of the operator */ |
nothing calls this directly
no test coverage detected