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

Method AllocateMem

driver/cpu/cpu_runner.cpp:851–980  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

849}
850
851bool CPURunner::AllocateMem(Subgraph* sub_graph)
852{
853 const std::vector<Node*>& seq_nodes = sub_graph->seq_nodes;
854
855 /*
856 first, check if any nodes supports new memory interface
857 this memory block is only for tempory use and so that it can be shared
858 between operators
859 */
860
861 unsigned int max_shared_mem_size = 0;
862
863 for(unsigned int i = 0; i < seq_nodes.size(); i++)
864 {
865 Node* node = seq_nodes[i];
866
867 if(!node->ExistAttr(ATTR_NODE_OPS))
868 continue;
869
870 NodeOps* node_ops = any_cast<NodeOps*>(node->GetAttr(ATTR_NODE_OPS));
871 unsigned int mem_size = 0;
872
873 if(node_ops->GetSharedMemorySize(node, mem_size) && mem_size > max_shared_mem_size)
874 {
875 max_shared_mem_size = mem_size;
876 }
877 }
878
879 if(max_shared_mem_size > 0)
880 {
881 void* shared_memory = mem_alloc(max_shared_mem_size + 128+MEM_ALIGN_SIZE);
882 sub_graph->SetAttr("shared_temp_memory", shared_memory);
883
884 shared_memory=(void *)(((long)(shared_memory)+MEM_ALIGN_SIZE-1)&(MEM_ALIGN_MASK));
885
886 for(unsigned int i = 0; i < seq_nodes.size(); i++)
887 {
888 Node* node = seq_nodes[i];
889
890 if(!node->ExistAttr(ATTR_NODE_OPS))
891 continue;
892
893 NodeOps* node_ops = any_cast<NodeOps*>(node->GetAttr(ATTR_NODE_OPS));
894
895 unsigned int mem_size = 0;
896
897 if(node_ops->GetSharedMemorySize(node, mem_size))
898 node_ops->SetSharedMemoryAddr(node, shared_memory, mem_size);
899 }
900
901 // std::cout<<"max shared memory: "<<max_shared_mem_size<<"\n";
902 }
903
904 /*
905 * now, calculate the maximum input and output memory blocks to run the graph
906 */
907
908 std::vector<int> mem_blocks;

Callers

nothing calls this directly

Calls 15

CalculateMemBlocksFunction · 0.85
get_tensor_memFunction · 0.85
set_tensor_memFunction · 0.85
IsDynamicShapeMethod · 0.80
GetTotalSizeMethod · 0.80
AddRefMethod · 0.80
GetNameMethod · 0.80
FreeMethod · 0.80
sizeMethod · 0.45
ExistAttrMethod · 0.45
GetAttrMethod · 0.45
GetSharedMemorySizeMethod · 0.45

Tested by

no test coverage detected