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

Method BFCAllocator

tensorflow/core/common_runtime/bfc_allocator.cc:32–71  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

30namespace tensorflow {
31
32BFCAllocator::BFCAllocator(SubAllocator* sub_allocator, size_t total_memory,
33 bool allow_growth, const string& name,
34 bool garbage_collection)
35 : garbage_collection_(garbage_collection),
36 sub_allocator_(sub_allocator),
37 name_(name),
38 free_chunks_list_(kInvalidChunkHandle),
39 next_allocation_id_(1) {
40 if (allow_growth) {
41 // 1MiB smallest initial allocation, unless total memory available
42 // is less.
43 curr_region_allocation_bytes_ =
44 RoundedBytes(std::min(total_memory, size_t{1048576}));
45 } else {
46 curr_region_allocation_bytes_ = RoundedBytes(total_memory);
47 }
48
49 // Allocate the requested amount of memory.
50 memory_limit_ = total_memory;
51 stats_.bytes_limit = static_cast<int64>(total_memory);
52
53 // Create a bunch of bins of various good sizes.
54
55 // We create bins to fit all possible ranges that cover the
56 // memory_limit_ starting from allocations up to 256 bytes to
57 // allocations up to (and including) the memory limit.
58 VLOG(1) << "Creating new BFCAllocator named: " << name;
59 for (BinNum b = 0; b < kNumBins; b++) {
60 size_t bin_size = BinNumToSize(b);
61 VLOG(1) << "Creating bin of max chunk size "
62 << strings::HumanReadableNumBytes(bin_size);
63 new (BinFromIndex(b)) Bin(this, bin_size);
64 CHECK_EQ(BinForSize(bin_size), BinFromIndex(b));
65 CHECK_EQ(BinForSize(bin_size + 255), BinFromIndex(b));
66 CHECK_EQ(BinForSize(bin_size * 2 - 1), BinFromIndex(b));
67 if (b + 1 < kNumBins) {
68 CHECK_NE(BinForSize(bin_size * 2), BinFromIndex(b));
69 }
70 }
71}
72
73BFCAllocator::~BFCAllocator() {
74 // Return memory back.

Callers

nothing calls this directly

Calls 3

RoundedBytesFunction · 0.70
minFunction · 0.50
HumanReadableNumBytesFunction · 0.50

Tested by

no test coverage detected