MCPcopy Create free account
hub / github.com/OAID/Tengine / SaveTmSubgraph

Method SaveTmSubgraph

serializer/tengine/v2/tm2_serializer.cpp:303–414  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

301}
302
303tm_uoffset_t TmSerializer2::SaveTmSubgraph(void* const start_ptr, tm_uoffset_t* cur_pos, Graph* graph)
304{
305 TM2_Subgraph tm_subgraph;
306 tm_subgraph.subgraph_id = 0; /* subgraph_id starts from 0 */
307 tm_subgraph.offset_s_sname = TM2_NOT_SET;
308
309 tm_subgraph.graph_layout = graph->GetLayout();
310 tm_subgraph.model_layout = graph->GetModelLayout();
311
312 unsigned int tensor_num = 0;
313 unsigned int buffer_num = 0;
314 std::vector<Tensor*> tensor_ptrs;
315 std::vector<void*> buf_ptrs;
316 std::vector<unsigned int> buf_sizes;
317 name_map_t tensor_name_map; /* map of tensor name and tensor index */
318 bool tm_no_data = !IsSaveData();
319
320 /* Write the nodes */
321 size_t vector_size = sizeof(tm_size_t) + sizeof(tm_uoffset_t) * graph->seq_nodes.size();
322 TM2_Vector_offsets* v_nodes = ( TM2_Vector_offsets* )malloc(vector_size);
323 v_nodes->v_num = graph->seq_nodes.size();
324 for(unsigned int i = 0; i < graph->seq_nodes.size(); i++)
325 {
326 Node* p_node = graph->seq_nodes[i];
327 for(unsigned int k = 0; k < p_node->GetOutputNum(); k++)
328 {
329 Tensor* p_tensor = p_node->GetOutputTensor(k);
330 tensor_ptrs.push_back(p_tensor);
331 tensor_name_map[p_tensor->GetName()] = tensor_num;
332 tensor_num++;
333 }
334 v_nodes->offsets[i] = SaveTmNode(start_ptr, cur_pos, p_node, tensor_name_map);
335 }
336 /* Write the vector of nodes */
337 tm_subgraph.offset_vo_seq_nodes = WriteTmObject(start_ptr, cur_pos, v_nodes, vector_size);
338
339 /* Write the tensors */
340 vector_size = sizeof(tm_size_t) + sizeof(tm_uoffset_t) * tensor_num;
341 TM2_Vector_offsets* v_tensors = ( TM2_Vector_offsets* )malloc(vector_size);
342 v_tensors->v_num = tensor_num;
343 for(unsigned int i = 0; i < tensor_num; i++)
344 {
345 Tensor* p_tensor = tensor_ptrs[i];
346 if(p_tensor->GetType() == kConstTensor)
347 {
348 buf_ptrs.push_back(p_tensor->GetMemAddr());
349 buf_sizes.push_back(p_tensor->GetTotalSize());
350 buffer_num++;
351 }
352
353 v_tensors->offsets[i] = SaveTmTensor(start_ptr, cur_pos, p_tensor, i, buffer_num - 1);
354 }
355 /* Write the vector of tensors */
356 tm_subgraph.offset_vo_tensors = WriteTmObject(start_ptr, cur_pos, v_tensors, vector_size);
357
358 /* Write the buffers */
359 vector_size = sizeof(tm_size_t) + sizeof(tm_uoffset_t) * buffer_num;
360 TM2_Vector_offsets* v_buffers = ( TM2_Vector_offsets* )malloc(vector_size);

Callers

nothing calls this directly

Calls 12

WriteTmObjectFunction · 0.85
WriteTmFileAlign1Function · 0.85
GetLayoutMethod · 0.80
GetModelLayoutMethod · 0.80
GetNameMethod · 0.80
GetMemAddrMethod · 0.80
GetTotalSizeMethod · 0.80
GetNodeIndexMethod · 0.80
sizeMethod · 0.45
GetOutputNumMethod · 0.45
GetOutputTensorMethod · 0.45
GetTypeMethod · 0.45

Tested by

no test coverage detected