Skip to content

Commit

Permalink
buffer unique id generator to atomic
Browse files Browse the repository at this point in the history
  • Loading branch information
mbezuljTT committed Nov 26, 2024
1 parent c8ce757 commit 8d15695
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions tt_metal/impl/buffers/buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "tt_metal/types.hpp"

#include <algorithm>
#include <atomic>
#include <mutex>
#include <utility>
#include "tt_metal/common/base.hpp"
Expand All @@ -25,7 +26,7 @@ namespace tt {

namespace tt_metal {

size_t Buffer::next_unique_id = 0;
std::atomic<size_t> Buffer::next_unique_id = 0;

std::ostream& operator<<(std::ostream& os, const ShardSpec& spec) {
tt::stl::reflection::operator<<(os, spec);
Expand Down Expand Up @@ -249,7 +250,7 @@ Buffer::Buffer(
if (size != 0) {
validate_buffer_size_and_page_size(size, page_size, buffer_type, buffer_layout, shard_parameters);
}
unique_id_ = next_unique_id++;
unique_id_ = next_unique_id.fetch_add(1);
}

std::shared_ptr<Buffer> Buffer::create(
Expand Down
2 changes: 1 addition & 1 deletion tt_metal/impl/buffers/buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ class Buffer final {

std::weak_ptr<Buffer> weak_self;
size_t unique_id_;
static size_t next_unique_id;
static std::atomic<size_t> next_unique_id;
};

} // namespace v0
Expand Down

0 comments on commit 8d15695

Please sign in to comment.