| 110 | } |
| 111 | |
| 112 | void TensorPoolAllocator::Init() { |
| 113 | bool tmp = false; |
| 114 | if (initing_.compare_exchange_strong(tmp, true)) { |
| 115 | signal(SIGUSR1, signal_handler); |
| 116 | auto lifetime_policy = mem_planner_->BestLifetimePolicy(); |
| 117 | lifetime_policy->Dump(); |
| 118 | |
| 119 | alignment_ = lifetime_policy->Alignment(); |
| 120 | alignment_offset_ = lifetime_policy->AlignmentOffset(); |
| 121 | |
| 122 | auto policy_large_bins = lifetime_policy->GetLargeBins(); |
| 123 | for (auto rit = policy_large_bins.rbegin(); |
| 124 | rit != policy_large_bins.rend(); ++rit) { |
| 125 | auto bin_info = rit->second; |
| 126 | auto bin = new Bin(bin_info->BlockSize(), bin_info->ChunkSize(), |
| 127 | bin_info->Alignment(), bin_info->VBlocks(), |
| 128 | sub_allocator_.get(), this); |
| 129 | large_lifetime_bins_.emplace(rit->first, bin); |
| 130 | } |
| 131 | auto policy_bins = lifetime_policy->GetBins(); |
| 132 | large_bin_index_ = policy_bins.size(); |
| 133 | lifetime_bins_.resize(large_bin_index_); |
| 134 | |
| 135 | // create bigger bin first |
| 136 | for (auto it = policy_bins.rbegin(); it != policy_bins.rend(); |
| 137 | ++it) { |
| 138 | Bin* bin = nullptr; |
| 139 | if ((*it)->BlockSize() > 0 || (*it)->VBlocks().size() > 0) { |
| 140 | bin = new Bin((*it)->BlockSize(), (*it)->ChunkSize(), |
| 141 | (*it)->Alignment(), (*it)->VBlocks(), |
| 142 | sub_allocator_.get(), this); |
| 143 | } |
| 144 | lifetime_bins_[(*it)->BinIndex()] = bin; |
| 145 | } |
| 146 | LOG(INFO) << "TensorPoolAllocator enabled"; |
| 147 | inited_ = true; |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | void* TensorPoolAllocator::AllocateRaw(size_t alignment, |
| 152 | size_t num_bytes) { |
nothing calls this directly
no test coverage detected