| 326 | } |
| 327 | |
| 328 | void* TensorPoolAllocator::BigAllocate(size_t alignment, |
| 329 | size_t num_bytes) { |
| 330 | auto header_size = std::max(sizeof(Header), alignment); |
| 331 | auto total = num_bytes + header_size; |
| 332 | if (!inited_.load()) { |
| 333 | mem_planner_->TrackAllocate(alignment, total); |
| 334 | auto ptr = sub_allocator_->Alloc(alignment, total); |
| 335 | return SetDefaultHeader(!inited_.load(), ptr, total, header_size); |
| 336 | } |
| 337 | |
| 338 | auto id = Index(total, alignment_, alignment_offset_); |
| 339 | if (unlikely(id < 0)) { |
| 340 | auto ptr = sub_allocator_->Alloc(alignment, total); |
| 341 | return SetDefaultHeader(!inited_.load(), ptr, total, header_size); |
| 342 | } |
| 343 | |
| 344 | auto b = GetBin(id); |
| 345 | if (unlikely(b == nullptr)) { |
| 346 | auto ptr = sub_allocator_->Alloc(alignment, total); |
| 347 | return SetDefaultHeader(!inited_.load(), ptr, total, header_size); |
| 348 | } |
| 349 | |
| 350 | auto ptr = b->Allocate(total, header_size); |
| 351 | if (likely(ptr != nullptr)) { |
| 352 | return ptr; |
| 353 | } |
| 354 | ptr = sub_allocator_->Alloc(alignment, total); |
| 355 | return SetDefaultHeader(!inited_.load(), ptr, total, header_size); |
| 356 | } |
| 357 | |
| 358 | // unlikely execute this path which do some atomic operations |
| 359 | void* TensorPoolAllocator::BigAllocateStatistic(size_t alignment, |
nothing calls this directly
no test coverage detected