Skip to content

Commit

Permalink
#0: Fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
sminakov-tt committed Oct 23, 2024
1 parent 9585a28 commit 16946d0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
32 changes: 15 additions & 17 deletions tt_metal/impl/buffers/buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,31 +237,29 @@ std::shared_ptr<Buffer> Buffer::create(
void Buffer::deallocate() {
deallocation_requested_.store(true, std::memory_order::relaxed);
device_->push_work([self = weak_self.lock()] {
if (self->allocation_status_.load(std::memory_order::relaxed) == AllocationStatus::ALLOCATED) {
return;
}

if (self->device_->initialized_ && self->size_ != 0) {
// address_ is only modified from this thread, no sync required
detail::BUFFER_MAP.erase({self->device_->id(), self->address_});
detail::DeallocateBuffer(self.get());
}

self->allocation_status_.store(AllocationStatus::DEALLOCATED, std::memory_order::relaxed);
self->deallocate_impl();
});
}

void Buffer::deleter(Buffer* buffer) {
buffer->device_->push_work([buffer] {
std::unique_ptr<Buffer> unique_buffer = std::unique_ptr<Buffer>(buffer);
buffer->deallocate_impl();
});
}

if (!buffer->device_->initialized_ || buffer->size_ == 0) {
return;
}
void Buffer::deallocate_impl() {
if (allocation_status_.load(std::memory_order::relaxed) == AllocationStatus::DEALLOCATED) {
return;
}

detail::BUFFER_MAP.erase({buffer->device_->id(), buffer->address_});
detail::DeallocateBuffer(buffer);
});
if (device_->initialized_ && size_ != 0) {
// address_ is only modified from this thread, no sync required
detail::BUFFER_MAP.erase({device_->id(), address_});
detail::DeallocateBuffer(this);
}

allocation_status_.store(AllocationStatus::DEALLOCATED, std::memory_order::relaxed);
}

bool Buffer::is_allocated() const {
Expand Down
1 change: 1 addition & 0 deletions tt_metal/impl/buffers/buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ class Buffer final {
// Deallocate is allowed to be called multiple times on the same buffer
void deallocate();
static void deleter(Buffer* buffer);
void deallocate_impl();
friend void DeallocateBuffer(Buffer &buffer);

DeviceAddr translate_page_address(uint64_t offset, uint32_t bank_id) const;
Expand Down

0 comments on commit 16946d0

Please sign in to comment.