Address comments around bfc arena (#3460)

* rename setting

* todo comments

* fix build

Co-authored-by: Ethan Tao <ettao@microsoft.com>
This commit is contained in:
ytaous 2020-04-08 19:35:32 -07:00 committed by GitHub
parent a298556600
commit a08f16471a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -13,6 +13,10 @@ BFCArena::BFCArena(std::unique_ptr<IDeviceAllocator> resource_allocator,
info_(device_allocator_->Info().name, OrtAllocatorType::OrtArenaAllocator,
device_allocator_->Info().device, device_allocator_->Info().id, device_allocator_->Info().mem_type) {
LOGS_DEFAULT(INFO) << "Creating BFCArena for " << device_allocator_->Info().name;
// TODO - consider to make the initial chunk size and max 'fragmentation' (kMaxDeadBytesInChunk) values configurable.
// But first we need to add a mechanism to allow that sort of low level configuration to be done
// without adding separate parameters to SessionOptions for every single one of them.
curr_region_allocation_bytes_ = RoundedBytes(std::min(total_memory, size_t{1048576}));
// Allocate the requested amount of memory.
@ -300,11 +304,11 @@ void* BFCArena::FindChunkPtr(BinNum bin_num, size_t rounded_bytes,
// If we can break the size of the chunk into two reasonably large
// pieces, do so. In any case don't waste more than
// kMaxInternalFragmentation bytes on padding this alloc.
const int64_t kMaxInternalFragmentation = 128 << 20; // 128mb
// kMaxDeadBytesInChunk bytes on padding this alloc.
const int64_t kMaxDeadBytesInChunk = 128 << 20; // 128mb
if (chunk->size >= rounded_bytes * 2 ||
static_cast<int64_t>(chunk->size) - rounded_bytes >=
kMaxInternalFragmentation) {
kMaxDeadBytesInChunk) {
SplitChunk(h, rounded_bytes);
chunk = ChunkFromHandle(h); // Update chunk pointer in case it moved
}