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

Method Allocate

driver/cpu/cpu_runner.cpp:160–190  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

158 }
159
160 void* Allocate(Tensor* tensor, int size)
161 {
162 int block_num = block_list.size();
163
164 MemBlock* p_block = nullptr;
165 int i;
166
167 for(i = 0; i < block_num; i++)
168 {
169 if(block_list[i].ref_count == 0 && block_list[i].size >= size)
170 {
171 p_block = &block_list[i];
172 break;
173 }
174 }
175
176 if(p_block == nullptr)
177 {
178 XLOG_ERROR() << "cannot allocate memory for tensor: " << tensor->GetName() << "\n";
179 return nullptr;
180 }
181
182 int ref_count = tensor->consumer.size() ? tensor->consumer.size() : 1;
183 p_block->ref_count = ref_count;
184 p_block->alloc_count++;
185
186 // record this
187 addr_map[p_block->addr] = i;
188
189 return p_block->addr;
190 }
191
192 void AddRef(Tensor* tensor)
193 {

Callers 1

AllocateMemMethod · 0.45

Calls 2

GetNameMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected