Skip to content

Commit

Permalink
#0: Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
sminakov-tt committed Oct 23, 2024
1 parent 5c17e5b commit 05ae26f
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions tt_metal/impl/buffers/buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,16 +233,16 @@ std::shared_ptr<Buffer> Buffer::create(
auto expected_status = AllocationStatus::ALLOCATION_REQUESTED;
if (!buffer->allocation_status_.compare_exchange_strong(expected_status, AllocationStatus::ALLOCATING)) {
// Buffer was already deallocated before we got here
buffer->allocation_status_.notify_all();
return;
}

buffer->allocate_impl();

// We need compare exchange here to handle the case of deallocation being requested before we finished allocating
expected_status = AllocationStatus::ALLOCATING;
if (buffer->allocation_status_.compare_exchange_strong(expected_status, AllocationStatus::ALLOCATED)) {
buffer->allocation_status_.notify_all();
}
buffer->allocation_status_.compare_exchange_strong(expected_status, AllocationStatus::ALLOCATED);
buffer->allocation_status_.notify_all();
});

return buffer;
Expand All @@ -261,15 +261,13 @@ bool Buffer::prepare_deallocation(std::atomic<AllocationStatus>& status) {
case AllocationStatus::ALLOCATION_REQUESTED:
// Allocation was requested but not started, canceling allocation, nothing else to be done
if (status.compare_exchange_weak(current_status, AllocationStatus::DEALLOCATED)) {
status.notify_all();
return false;
}
break;
case AllocationStatus::ALLOCATING:
case AllocationStatus::ALLOCATED:
// Allocation already started, will have to deallocate
if (status.compare_exchange_weak(current_status, AllocationStatus::DEALLOCATION_REQUESTED)) {
status.notify_all();
return true;
}
break;
Expand Down

0 comments on commit 05ae26f

Please sign in to comment.