Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix BFCAllocator::Extend alignment issues #19483

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions tensorflow/core/common_runtime/bfc_allocator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ BFCAllocator::Chunk* BFCAllocator::ChunkFromHandle(ChunkHandle h) {
return &(chunks_[h]);
}

bool BFCAllocator::Extend(size_t rounded_bytes) {
bool BFCAllocator::Extend(size_t alignment, size_t rounded_bytes) {
size_t available_bytes = memory_limit_ - total_region_allocated_bytes_;
// Rounds available_bytes down to the nearest multiple of kMinAllocationSize.
available_bytes = (available_bytes / kMinAllocationSize) * kMinAllocationSize;
Expand All @@ -108,7 +108,7 @@ bool BFCAllocator::Extend(size_t rounded_bytes) {

// Try allocating.
size_t bytes = std::min(curr_region_allocation_bytes_, available_bytes);
void* mem_addr = suballocator_->Alloc(32, bytes);
void* mem_addr = suballocator_->Alloc(alignment, bytes);
if (mem_addr == nullptr && !started_backpedal_) {
// Only backpedal once.
started_backpedal_ = true;
Expand All @@ -119,7 +119,7 @@ bool BFCAllocator::Extend(size_t rounded_bytes) {
while (mem_addr == nullptr) {
bytes = RoundedBytes(bytes * kBackpedalFactor);
if (bytes < rounded_bytes) break;
mem_addr = suballocator_->Alloc(32, bytes);
mem_addr = suballocator_->Alloc(alignment, bytes);
}
}

Expand Down Expand Up @@ -261,7 +261,7 @@ void* BFCAllocator::AllocateRawInternal(size_t unused_alignment,
}

// Try to extend
if (Extend(rounded_bytes)) {
if (Extend(unused_alignment, rounded_bytes)) {
ptr = FindChunkPtr(bin_num, rounded_bytes, num_bytes);
if (ptr != nullptr) {
return ptr;
Expand Down
3 changes: 2 additions & 1 deletion tensorflow/core/common_runtime/bfc_allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,8 @@ class BFCAllocator : public VisitableAllocator {
// Try to add a new memory region that can satisfy an allocation of
// 'rounded_bytes' bytes. Returns true on success and false on
// failure.
bool Extend(size_t rounded_bytes) EXCLUSIVE_LOCKS_REQUIRED(lock_);
bool Extend(size_t alignment, size_t rounded_bytes)
EXCLUSIVE_LOCKS_REQUIRED(lock_);

// Returns a pointer to an underlying allocated chunk of size
// 'rounded_bytes'.
Expand Down