Skip to content

Commit

Permalink
#0: Swap unordered_map for map in global circular buffer since this o…
Browse files Browse the repository at this point in the history
…bject needs to be hashed
  • Loading branch information
tt-aho committed Dec 6, 2024
1 parent f3b1b50 commit ee9faa4
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 22 deletions.
10 changes: 5 additions & 5 deletions tests/tt_metal/tt_metal/api/test_global_circular_buffers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ TEST_F(DispatchFixture, TensixCreateGlobalCircularBuffers) {

auto device = devices_[0];
{
std::unordered_map<CoreCoord, CoreRangeSet> sender_receiver_core_mapping;
std::map<CoreCoord, CoreRangeSet> sender_receiver_core_mapping;
sender_receiver_core_mapping[CoreCoord(0, 0)] = cores;
auto global_cb = tt::tt_metal::v1::experimental::CreateGlobalCircularBuffer(
device, sender_receiver_core_mapping, 3200, tt::tt_metal::BufferType::L1);
auto buffer_address = global_cb->buffer_address();
auto config_address = global_cb->config_address();
}
{
std::unordered_map<CoreCoord, CoreRangeSet> sender_receiver_core_mapping;
std::map<CoreCoord, CoreRangeSet> sender_receiver_core_mapping;
sender_receiver_core_mapping[CoreCoord(0, 0)] = cores;
sender_receiver_core_mapping[CoreCoord(1, 1)] = cores3;
// sender receiver cores overlap
Expand All @@ -39,7 +39,7 @@ TEST_F(DispatchFixture, TensixCreateGlobalCircularBuffers) {
std::exception);
}
{
std::unordered_map<CoreCoord, CoreRangeSet> sender_receiver_core_mapping;
std::map<CoreCoord, CoreRangeSet> sender_receiver_core_mapping;
sender_receiver_core_mapping[CoreCoord(0, 0)] = cores;
sender_receiver_core_mapping[CoreCoord(0, 1)] = cores2;
// receiver cores overlap
Expand All @@ -60,11 +60,11 @@ TEST_F(DispatchFixture, TensixProgramGlobalCircularBuffers) {
tt::DataFormat tile_format = tt::DataFormat::Float16_b;
auto all_cores = sender_cores.merge(receiver_cores).merge(dummy_receiver_cores);
auto device = devices_[0];
std::unordered_map<CoreCoord, CoreRangeSet> sender_receiver_core_mapping;
std::map<CoreCoord, CoreRangeSet> sender_receiver_core_mapping;
sender_receiver_core_mapping[CoreCoord(0, 0)] = receiver_cores;
auto global_cb = tt::tt_metal::v1::experimental::CreateGlobalCircularBuffer(
device, sender_receiver_core_mapping, 3200, tt::tt_metal::BufferType::L1);
std::unordered_map<CoreCoord, CoreRangeSet> dummy_sender_receiver_core_mapping;
std::map<CoreCoord, CoreRangeSet> dummy_sender_receiver_core_mapping;
dummy_sender_receiver_core_mapping[CoreCoord(0, 0)] = dummy_receiver_cores;
auto dummy_global_cb = tt::tt_metal::v1::experimental::CreateGlobalCircularBuffer(
device, dummy_sender_receiver_core_mapping, 3200, tt::tt_metal::BufferType::L1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ create_programs(
tt_metal::Device* device,
const CoreRangeSet& dram_reader_core,
const CoreRangeSet& l1_receiver_cores,
const std::unordered_map<CoreCoord, CoreRangeSet>& sender_receiver_core_mapping,
const std::map<CoreCoord, CoreRangeSet>& sender_receiver_core_mapping,
const uint32_t& single_tile_size,
const tt::DataFormat& tile_format,
uint32_t k,
Expand Down Expand Up @@ -721,7 +721,7 @@ int main(int argc, char** argv) {
l1_receiver_core_coord_range = CoreRange{CoreCoord{1, 0}, CoreCoord{num_receivers, 0}};
}
CoreRangeSet l1_receiver_core{std::set<CoreRange>{l1_receiver_core_coord_range}};
std::unordered_map<CoreCoord, CoreRangeSet> sender_receiver_core_mapping;
std::map<CoreCoord, CoreRangeSet> sender_receiver_core_mapping;
sender_receiver_core_mapping[dram_reader_core_coord] = l1_receiver_core;
if (use_sub_devices) {
SubDevice sender_sub_device = SubDevice(std::array{dram_reader_core});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ create_programs(
tt_metal::Device* device,
const CoreRangeSet& dram_reader_core,
const CoreRangeSet& l1_receiver_cores,
const std::unordered_map<CoreCoord, CoreRangeSet>& sender_receiver_core_mapping,
const std::map<CoreCoord, CoreRangeSet>& sender_receiver_core_mapping,
const uint32_t& single_tile_size,
const tt::DataFormat& tile_format,
uint32_t m,
Expand Down Expand Up @@ -700,7 +700,7 @@ int main(int argc, char** argv) {
l1_receiver_core_coord_range = CoreRange{CoreCoord{1, 0}, CoreCoord{num_receivers, 0}};
}
CoreRangeSet l1_receiver_core{std::set<CoreRange>{l1_receiver_core_coord_range}};
std::unordered_map<CoreCoord, CoreRangeSet> sender_receiver_core_mapping;
std::map<CoreCoord, CoreRangeSet> sender_receiver_core_mapping;
sender_receiver_core_mapping[dram_reader_core_coord] = l1_receiver_core;
if (use_sub_devices) {
SubDevice sender_sub_device = SubDevice(std::array{dram_reader_core});
Expand Down
4 changes: 2 additions & 2 deletions tt_metal/impl/buffers/global_circular_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace experimental {

GlobalCircularBuffer::GlobalCircularBuffer(
Device* device,
const std::unordered_map<CoreCoord, CoreRangeSet>& sender_receiver_core_mapping,
const std::map<CoreCoord, CoreRangeSet>& sender_receiver_core_mapping,
uint32_t size,
BufferType buffer_type) :
device_(device), sender_receiver_core_mapping_(sender_receiver_core_mapping), size_(size) {
Expand Down Expand Up @@ -134,7 +134,7 @@ void GlobalCircularBuffer::setup_cb_buffers(BufferType buffer_type, uint32_t max

std::shared_ptr<GlobalCircularBuffer> GlobalCircularBuffer::create(
Device* device,
const std::unordered_map<CoreCoord, CoreRangeSet>& sender_receiver_core_mapping,
const std::map<CoreCoord, CoreRangeSet>& sender_receiver_core_mapping,
uint32_t size,
BufferType buffer_type) {
return std::make_unique<GlobalCircularBuffer>(device, sender_receiver_core_mapping, size, buffer_type);
Expand Down
6 changes: 3 additions & 3 deletions tt_metal/impl/buffers/global_circular_buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class GlobalCircularBuffer {
public:
GlobalCircularBuffer(
Device* device,
const std::unordered_map<CoreCoord, CoreRangeSet>& sender_receiver_core_mapping,
const std::map<CoreCoord, CoreRangeSet>& sender_receiver_core_mapping,
uint32_t size,
BufferType buffer_type);

Expand All @@ -40,7 +40,7 @@ class GlobalCircularBuffer {

static std::shared_ptr<GlobalCircularBuffer> create(
Device* device,
const std::unordered_map<CoreCoord, CoreRangeSet>& sender_receiver_core_mapping,
const std::map<CoreCoord, CoreRangeSet>& sender_receiver_core_mapping,
uint32_t size,
BufferType buffer_type = BufferType::L1);

Expand All @@ -64,7 +64,7 @@ class GlobalCircularBuffer {
std::shared_ptr<Buffer> cb_buffer_;
std::shared_ptr<Buffer> cb_config_buffer_;
Device* device_;
std::unordered_map<CoreCoord, CoreRangeSet> sender_receiver_core_mapping_;
std::map<CoreCoord, CoreRangeSet> sender_receiver_core_mapping_;
CoreRangeSet sender_cores_;
CoreRangeSet receiver_cores_;
CoreRangeSet all_cores_;
Expand Down
2 changes: 1 addition & 1 deletion tt_metal/include/tt_metal/global_circular_buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace experimental {
*/
std::shared_ptr<GlobalCircularBuffer> CreateGlobalCircularBuffer(
Device* device,
const std::unordered_map<CoreCoord, CoreRangeSet>& sender_receiver_core_mapping,
const std::map<CoreCoord, CoreRangeSet>& sender_receiver_core_mapping,
uint32_t size,
BufferType buffer_type = BufferType::L1);

Expand Down
2 changes: 1 addition & 1 deletion tt_metal/tt_metal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1369,7 +1369,7 @@ namespace experimental {

std::shared_ptr<GlobalCircularBuffer> CreateGlobalCircularBuffer(
Device* device,
const std::unordered_map<CoreCoord, CoreRangeSet>& sender_receiver_core_mapping,
const std::map<CoreCoord, CoreRangeSet>& sender_receiver_core_mapping,
uint32_t size,
BufferType buffer_type) {
return GlobalCircularBuffer::create(device, sender_receiver_core_mapping, size, buffer_type);
Expand Down
4 changes: 2 additions & 2 deletions ttnn/cpp/pybind11/global_circular_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void py_module(py::module& module) {
// Single Device APIs
module.def(
"create_global_circular_buffer",
py::overload_cast<Device*, const std::unordered_map<CoreCoord, CoreRangeSet>&, uint32_t, BufferType>(
py::overload_cast<Device*, const std::map<CoreCoord, CoreRangeSet>&, uint32_t, BufferType>(
&create_global_circular_buffer),
py::arg("device"),
py::arg("sender_receiver_core_mapping"),
Expand All @@ -38,7 +38,7 @@ void py_module(py::module& module) {
// Multi Device APIs
module.def(
"create_global_circular_buffer",
py::overload_cast<MeshDevice*, const std::unordered_map<CoreCoord, CoreRangeSet>&, uint32_t, BufferType>(
py::overload_cast<MeshDevice*, const std::map<CoreCoord, CoreRangeSet>&, uint32_t, BufferType>(
&create_global_circular_buffer),
py::arg("mesh_device"),
py::arg("sender_receiver_core_mapping"),
Expand Down
4 changes: 2 additions & 2 deletions ttnn/cpp/ttnn/global_circular_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ MultiDeviceGlobalCircularBuffer::MultiDeviceGlobalCircularBuffer(MeshDevice* mes

std::shared_ptr<GlobalCircularBuffer> create_global_circular_buffer(
Device* device,
const std::unordered_map<CoreCoord, CoreRangeSet>& sender_receiver_core_mapping,
const std::map<CoreCoord, CoreRangeSet>& sender_receiver_core_mapping,
uint32_t size,
BufferType buffer_type) {
std::shared_ptr<GlobalCircularBuffer> global_cb;
Expand All @@ -34,7 +34,7 @@ std::shared_ptr<GlobalCircularBuffer> create_global_circular_buffer(

MultiDeviceGlobalCircularBuffer create_global_circular_buffer(
MeshDevice* mesh_device,
const std::unordered_map<CoreCoord, CoreRangeSet>& sender_receiver_core_mapping,
const std::map<CoreCoord, CoreRangeSet>& sender_receiver_core_mapping,
uint32_t size,
BufferType buffer_type) {
MultiDeviceGlobalCircularBuffer multi_device_global_cb(mesh_device);
Expand Down
4 changes: 2 additions & 2 deletions ttnn/cpp/ttnn/global_circular_buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ struct MultiDeviceGlobalCircularBuffer {
// Single Device APIs
std::shared_ptr<GlobalCircularBuffer> create_global_circular_buffer(
Device* device,
const std::unordered_map<CoreCoord, CoreRangeSet>& sender_receiver_core_mapping,
const std::map<CoreCoord, CoreRangeSet>& sender_receiver_core_mapping,
uint32_t size,
BufferType buffer_type = BufferType::L1);

// Multi Device APIs
MultiDeviceGlobalCircularBuffer create_global_circular_buffer(
MeshDevice* mesh_device,
const std::unordered_map<CoreCoord, CoreRangeSet>& sender_receiver_core_mapping,
const std::map<CoreCoord, CoreRangeSet>& sender_receiver_core_mapping,
uint32_t size,
BufferType buffer_type = BufferType::L1);

Expand Down

0 comments on commit ee9faa4

Please sign in to comment.