MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / BatchAllocate

Method BatchAllocate

tensorflow/core/framework/ev_allocator.h:301–337  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

299 }
300
301 size_t BatchAllocate(size_t num, void** ret) {
302 mutex_lock l(mu_);
303 auto allocated = free_queue_.PopBatch(num, ret);
304 auto remains = num - allocated;
305 if (remains == 0) {
306 return num;
307 }
308
309 void** cur = ret + allocated;
310 allocated = current_chunk_->BatchAllocate(remains, cur);
311 remains -= allocated;
312 if (remains == 0) {
313 return num;
314 }
315
316 cur += allocated;
317 if (remains < current_chunk_->Count()) {
318 current_chunk_ = CreateChunk();
319
320 allocated = current_chunk_->BatchAllocate(remains, cur);
321 return num - (remains - allocated);
322 }
323
324 // Allocate in multiple chunks.
325 auto chunk_num = remains / current_chunk_->Count();
326 for (int i = 0; i < chunk_num; ++i) {
327 current_chunk_ = CreateChunk();
328 allocated = current_chunk_->FullAllocate(cur);
329
330 cur += allocated;
331 remains -= allocated;
332 }
333
334 current_chunk_ = CreateChunk();
335 allocated = current_chunk_->BatchAllocate(remains, cur);
336 return num - (remains - allocated);
337 }
338
339 void BatchDeallocate(std::vector<void *> &ptrs) {
340 mutex_lock l(mu_);

Callers 7

BatchAllocateMethod · 0.45
AllocateMethod · 0.45
BatchAllocateMethod · 0.45
BatchAllocateMethod · 0.45
BatchAllocateMethod · 0.45
BatchAllocateRawMethod · 0.45
BatchAllocateRawMethod · 0.45

Calls 3

FullAllocateMethod · 0.80
PopBatchMethod · 0.45
CountMethod · 0.45

Tested by

no test coverage detected