From 44bec365ab6f4d8921c2320e4889d6d45c36aa9f Mon Sep 17 00:00:00 2001 From: pjanevski Date: Thu, 5 Dec 2024 11:15:29 +0000 Subject: [PATCH] Coordinate manager maps redesign --- device/api/umd/device/coordinate_manager.h | 49 +-- device/api/umd/device/tt_core_coordinates.h | 22 ++ .../blackhole_coordinate_manager.cpp | 171 +++++++-- device/coordinate_manager.cpp | 340 +++++++----------- .../grayskull_coordinate_manager.cpp | 15 +- .../wormhole/wormhole_coordinate_manager.cpp | 38 +- tests/api/test_core_coord_translation_bh.cpp | 84 +++++ tests/api/test_core_coord_translation_gs.cpp | 56 +++ tests/api/test_core_coord_translation_wh.cpp | 90 ++++- 9 files changed, 552 insertions(+), 313 deletions(-) diff --git a/device/api/umd/device/coordinate_manager.h b/device/api/umd/device/coordinate_manager.h index 438cbd7a..44d54631 100644 --- a/device/api/umd/device/coordinate_manager.h +++ b/device/api/umd/device/coordinate_manager.h @@ -118,53 +118,8 @@ class CoordinateManager { */ virtual void fill_arc_logical_to_translated(); - std::map tensix_logical_to_translated; - std::map tensix_logical_to_virtual; - std::map tensix_logical_to_physical; - - std::map tensix_physical_to_logical; - std::map tensix_virtual_to_logical; - std::map tensix_translated_to_logical; - - std::map dram_logical_to_translated; - std::map dram_logical_to_virtual; - std::map dram_logical_to_physical; - - std::map dram_physical_to_logical; - std::map dram_virtual_to_logical; - std::map dram_translated_to_logical; - - std::map eth_logical_to_translated; - std::map eth_logical_to_virtual; - std::map eth_logical_to_physical; - - std::map eth_physical_to_logical; - std::map eth_virtual_to_logical; - std::map eth_translated_to_logical; - - std::map arc_logical_to_translated; - std::map arc_logical_to_virtual; - std::map arc_logical_to_physical; - - std::map arc_physical_to_logical; - std::map arc_virtual_to_logical; - std::map arc_translated_to_logical; - - std::map pcie_logical_to_translated; - std::map pcie_logical_to_virtual; - std::map pcie_logical_to_physical; - - std::map pcie_physical_to_logical; - std::map pcie_virtual_to_logical; - std::map pcie_translated_to_logical; - - std::map& get_logical_to_translated(CoreType core_type); - std::map& get_logical_to_virtual(CoreType core_type); - std::map& get_logical_to_physical(CoreType core_type); - - std::map& get_physical_to_logical(CoreType core_type); - std::map& get_virtual_to_logical(CoreType core_type); - std::map& get_translated_to_logical(CoreType core_type); + std::map to_physical_map; + std::map, tt::umd::CoreCoord> from_physical_map; const tt_xy_pair tensix_grid_size; const std::vector& tensix_cores; diff --git a/device/api/umd/device/tt_core_coordinates.h b/device/api/umd/device/tt_core_coordinates.h index 3083540b..4d5e8770 100644 --- a/device/api/umd/device/tt_core_coordinates.h +++ b/device/api/umd/device/tt_core_coordinates.h @@ -56,6 +56,28 @@ struct CoreCoord : public tt_xy_pair { return this->x == other.x && this->y == other.y && this->core_type == other.core_type && this->coord_system == other.coord_system; } + + bool operator<(const CoreCoord& o) const { + if (x < o.x) { + return true; + } + if (x > o.x) { + return false; + } + if (y < o.y) { + return true; + } + if (y > o.y) { + return false; + } + if (core_type < o.core_type) { + return true; + } + if (core_type > o.core_type) { + return false; + } + return coord_system < o.coord_system; + } }; } // namespace tt::umd diff --git a/device/blackhole/blackhole_coordinate_manager.cpp b/device/blackhole/blackhole_coordinate_manager.cpp index 6ff3de50..b9ccdedc 100644 --- a/device/blackhole/blackhole_coordinate_manager.cpp +++ b/device/blackhole/blackhole_coordinate_manager.cpp @@ -41,7 +41,7 @@ BlackholeCoordinateManager::BlackholeCoordinateManager( } void BlackholeCoordinateManager::translate_tensix_coords() { - size_t num_harvested_x = __builtin_popcount(tensix_harvesting_mask); + size_t num_harvested_x = CoordinateManager::get_num_harvested(tensix_harvesting_mask); size_t grid_size_x = tensix_grid_size.x; size_t grid_size_y = tensix_grid_size.y; @@ -50,10 +50,10 @@ void BlackholeCoordinateManager::translate_tensix_coords() { if (!(tensix_harvesting_mask & (1 << x))) { for (size_t y = 0; y < grid_size_y; y++) { const tt_xy_pair& tensix_core = tensix_cores[x + y * grid_size_x]; - tensix_logical_to_physical[{logical_x, y}] = - CoreCoord(tensix_core.x, tensix_core.y, CoreType::TENSIX, CoordSystem::PHYSICAL); - tensix_physical_to_logical[tensix_core] = - CoreCoord(logical_x, y, CoreType::TENSIX, CoordSystem::LOGICAL); + + CoreCoord logical_coord = CoreCoord(logical_x, y, CoreType::TENSIX, CoordSystem::LOGICAL); + to_physical_map[logical_coord] = {tensix_core.x, tensix_core.y}; + from_physical_map[{{tensix_core.x, tensix_core.y}, CoordSystem::LOGICAL}] = logical_coord; } logical_x++; } @@ -62,9 +62,34 @@ void BlackholeCoordinateManager::translate_tensix_coords() { for (size_t x = 0; x < grid_size_x - num_harvested_x; x++) { for (size_t y = 0; y < grid_size_y; y++) { const tt_xy_pair& tensix_core = tensix_cores[x + y * grid_size_x]; - tensix_logical_to_virtual[{x, y}] = - CoreCoord(tensix_core.x, tensix_core.y, CoreType::TENSIX, CoordSystem::VIRTUAL); - tensix_virtual_to_logical[tensix_core] = CoreCoord(x, y, CoreType::TENSIX, CoordSystem::LOGICAL); + CoreCoord virtual_coord = CoreCoord(tensix_core.x, tensix_core.y, CoreType::TENSIX, CoordSystem::VIRTUAL); + + CoreCoord logical_coord = CoreCoord(x, y, CoreType::TENSIX, CoordSystem::LOGICAL); + const tt_xy_pair physical_pair = to_physical_map[logical_coord]; + + to_physical_map[virtual_coord] = {physical_pair.x, physical_pair.y}; + from_physical_map[{{physical_pair.x, physical_pair.y}, CoordSystem::VIRTUAL}] = virtual_coord; + } + } + + size_t x_index = grid_size_x - num_harvested_x; + for (size_t x = 0; x < grid_size_x; x++) { + if (tensix_harvesting_mask & (1 << x)) { + size_t y_index = 0; + for (size_t y = 0; y < grid_size_y; y++) { + const tt_xy_pair& physical_core = tensix_cores[x + y * grid_size_x]; + const tt_xy_pair& virtual_core = tensix_cores[x_index + y_index * grid_size_x]; + + const size_t translated_x = virtual_core.x; + const size_t translated_y = virtual_core.y; + + CoreCoord virtual_coord = CoreCoord(translated_x, translated_y, CoreType::TENSIX, CoordSystem::VIRTUAL); + + to_physical_map[virtual_coord] = {physical_core.x, physical_core.y}; + from_physical_map[{{physical_core.x, physical_core.y}, CoordSystem::VIRTUAL}] = virtual_coord; + y_index++; + } + x_index++; } } @@ -72,44 +97,85 @@ void BlackholeCoordinateManager::translate_tensix_coords() { } void BlackholeCoordinateManager::fill_tensix_logical_to_translated() { - const size_t num_harvested_x = __builtin_popcount(tensix_harvesting_mask); + const size_t num_harvested_x = CoordinateManager::get_num_harvested(tensix_harvesting_mask); const size_t grid_size_x = tensix_grid_size.x; const size_t grid_size_y = tensix_grid_size.y; for (size_t x = 0; x < grid_size_x - num_harvested_x; x++) { for (size_t y = 0; y < grid_size_y; y++) { - const CoreCoord virtual_coord = tensix_logical_to_virtual[{x, y}]; + CoreCoord logical_coord = CoreCoord(x, y, CoreType::TENSIX, CoordSystem::LOGICAL); + const tt_xy_pair physical_pair = to_physical_map[logical_coord]; + CoreCoord virtual_coord = from_physical_map[{{physical_pair.x, physical_pair.y}, CoordSystem::VIRTUAL}]; const size_t translated_x = virtual_coord.x; const size_t translated_y = virtual_coord.y; - tensix_logical_to_translated[{x, y}] = + + CoreCoord translated_coord = CoreCoord(translated_x, translated_y, CoreType::TENSIX, CoordSystem::TRANSLATED); - tensix_translated_to_logical[{translated_x, translated_y}] = - CoreCoord(x, y, CoreType::TENSIX, CoordSystem::LOGICAL); + to_physical_map[translated_coord] = physical_pair; + from_physical_map[{{physical_pair.x, physical_pair.y}, CoordSystem::TRANSLATED}] = translated_coord; + } + } + + for (size_t x = 0; x < grid_size_x; x++) { + if (tensix_harvesting_mask & (1 << x)) { + size_t y_index = 0; + for (size_t y = 0; y < grid_size_y; y++) { + const tt_xy_pair& physical_core = tensix_cores[x + y * grid_size_x]; + CoreCoord virtual_coord = from_physical_map[{{physical_core.x, physical_core.y}, CoordSystem::VIRTUAL}]; + + CoreCoord translated_coord = + CoreCoord(virtual_coord.x, virtual_coord.y, CoreType::TENSIX, CoordSystem::TRANSLATED); + + to_physical_map[translated_coord] = {physical_core.x, physical_core.y}; + from_physical_map[{{physical_core.x, physical_core.y}, CoordSystem::TRANSLATED}] = translated_coord; + } } } } void BlackholeCoordinateManager::translate_dram_coords() { - size_t num_harvested_banks = __builtin_popcount(dram_harvesting_mask); + size_t num_harvested_banks = CoordinateManager::get_num_harvested(dram_harvesting_mask); + + size_t logical_x = 0; + for (size_t x = 0; x < dram_grid_size.x; x++) { + if (!(dram_harvesting_mask & (1 << x))) { + for (size_t y = 0; y < dram_grid_size.y; y++) { + const tt_xy_pair& dram_core = dram_cores[x * dram_grid_size.y + y]; + + CoreCoord logical_coord = CoreCoord(logical_x, y, CoreType::DRAM, CoordSystem::LOGICAL); + to_physical_map[logical_coord] = {dram_core.x, dram_core.y}; + from_physical_map[{{dram_core.x, dram_core.y}, CoordSystem::LOGICAL}] = logical_coord; + } + logical_x++; + } + } for (size_t x = 0; x < dram_grid_size.x - num_harvested_banks; x++) { for (size_t y = 0; y < dram_grid_size.y; y++) { const tt_xy_pair& dram_core = dram_cores[x * dram_grid_size.y + y]; - dram_logical_to_virtual[{x, y}] = CoreCoord(dram_core.x, dram_core.y, CoreType::DRAM, CoordSystem::VIRTUAL); - dram_virtual_to_logical[dram_core] = CoreCoord(x, y, CoreType::DRAM, CoordSystem::LOGICAL); + CoreCoord dram_logical = CoreCoord(x, y, CoreType::DRAM, CoordSystem::LOGICAL); + CoreCoord dram_virtual = CoreCoord(dram_core.x, dram_core.y, CoreType::DRAM, CoordSystem::VIRTUAL); + + const tt_xy_pair physical_pair = to_physical_map[dram_logical]; + + to_physical_map[dram_virtual] = physical_pair; + from_physical_map[{{physical_pair.x, physical_pair.y}, CoordSystem::VIRTUAL}] = dram_virtual; } } - size_t logical_x = 0; + size_t harvested_index = (dram_grid_size.x - num_harvested_banks) * dram_grid_size.y; for (size_t x = 0; x < dram_grid_size.x; x++) { - if (!(dram_harvesting_mask & (1 << x))) { + if (dram_harvesting_mask & (1 << x)) { for (size_t y = 0; y < dram_grid_size.y; y++) { const tt_xy_pair& dram_core = dram_cores[x * dram_grid_size.y + y]; - dram_logical_to_physical[{logical_x, y}] = - CoreCoord(dram_core.x, dram_core.y, CoreType::DRAM, CoordSystem::PHYSICAL); - dram_physical_to_logical[dram_core] = CoreCoord(logical_x, y, CoreType::DRAM, CoordSystem::LOGICAL); + const tt_xy_pair& virtual_core = dram_cores[harvested_index++]; + + CoreCoord virtual_coord = + CoreCoord(virtual_core.x, virtual_core.y, CoreType::DRAM, CoordSystem::VIRTUAL); + + to_physical_map[virtual_coord] = {dram_core.x, dram_core.y}; + from_physical_map[{{dram_core.x, dram_core.y}, CoordSystem::VIRTUAL}] = virtual_coord; } - logical_x++; } } @@ -121,23 +187,31 @@ void BlackholeCoordinateManager::fill_eth_logical_to_translated() { for (size_t y = 0; y < eth_grid_size.y; y++) { const size_t translated_x = x + blackhole::eth_translated_coordinate_start_x; const size_t translated_y = y + blackhole::eth_translated_coordinate_start_y; - eth_logical_to_translated[{x, y}] = - CoreCoord(translated_x, translated_y, CoreType::ETH, CoordSystem::TRANSLATED); - eth_translated_to_logical[{translated_x, translated_y}] = - CoreCoord(x, y, CoreType::ETH, CoordSystem::LOGICAL); + + CoreCoord logical_coord = CoreCoord(x, y, CoreType::ETH, CoordSystem::LOGICAL); + const tt_xy_pair physical_pair = to_physical_map[logical_coord]; + + CoreCoord translated_coord = CoreCoord(translated_x, translated_y, CoreType::ETH, CoordSystem::TRANSLATED); + + to_physical_map[translated_coord] = physical_pair; + from_physical_map[{{physical_pair.x, physical_pair.y}, CoordSystem::TRANSLATED}] = translated_coord; } } } void BlackholeCoordinateManager::fill_pcie_logical_to_translated() { - pcie_logical_to_translated[{0, 0}] = CoreCoord( + CoreCoord logical_coord = CoreCoord(0, 0, CoreType::PCIE, CoordSystem::LOGICAL); + + const tt_xy_pair physical_pair = to_physical_map[logical_coord]; + + CoreCoord translated_coord = CoreCoord( blackhole::pcie_translated_coordinate_start_x, blackhole::pcie_translated_coordinate_start_y, CoreType::PCIE, CoordSystem::TRANSLATED); - pcie_translated_to_logical[{ - blackhole::pcie_translated_coordinate_start_x, blackhole::pcie_translated_coordinate_start_y}] = - CoreCoord(0, 0, CoreType::PCIE, CoordSystem::LOGICAL); + + to_physical_map[translated_coord] = physical_pair; + from_physical_map[{{physical_pair.x, physical_pair.y}, CoordSystem::TRANSLATED}] = translated_coord; } void BlackholeCoordinateManager::map_column_of_dram_banks( @@ -145,10 +219,14 @@ void BlackholeCoordinateManager::map_column_of_dram_banks( size_t translated_y = blackhole::dram_translated_coordinate_start_y; for (size_t bank = start_bank; bank < end_bank; bank++) { for (size_t port = 0; port < blackhole::NUM_NOC_PORTS_PER_DRAM_BANK; port++) { - dram_logical_to_translated[{bank, port}] = - CoreCoord(x_coord, translated_y, CoreType::DRAM, CoordSystem::TRANSLATED); - dram_translated_to_logical[{x_coord, translated_y}] = - CoreCoord(bank, port, CoreType::DRAM, CoordSystem::LOGICAL); + CoreCoord logical_coord = CoreCoord(bank, port, CoreType::DRAM, CoordSystem::LOGICAL); + const tt_xy_pair physical_pair = to_physical_map[logical_coord]; + + CoreCoord translated_coord = CoreCoord(x_coord, translated_y, CoreType::DRAM, CoordSystem::TRANSLATED); + + to_physical_map[translated_coord] = physical_pair; + from_physical_map[{{physical_pair.x, physical_pair.y}, CoordSystem::TRANSLATED}] = translated_coord; + translated_y++; } } @@ -184,4 +262,29 @@ void BlackholeCoordinateManager::fill_dram_logical_to_translated() { blackhole::NUM_DRAM_BANKS - 1, blackhole::dram_translated_coordinate_start_x + 1); } + + const size_t virtual_index = (dram_grid_size.x - 1) * dram_grid_size.y; + const size_t physical_index = harvested_bank * dram_grid_size.y; + + const size_t harvested_bank_translated_x = blackhole::dram_translated_coordinate_start_x + 1; + const size_t harvested_bank_translated_y = + blackhole::dram_translated_coordinate_start_y + (dram_grid_size.x / 2 - 1) * dram_grid_size.y; + + for (size_t noc_port = 0; noc_port < dram_grid_size.y; noc_port++) { + const tt_xy_pair& physical_core = dram_cores[physical_index + noc_port]; + const tt_xy_pair& virtual_core = dram_cores[virtual_index + noc_port]; + + CoreCoord virtual_coord = CoreCoord(virtual_core.x, virtual_core.y, CoreType::DRAM, CoordSystem::VIRTUAL); + + to_physical_map[virtual_coord] = {physical_core.x, physical_core.y}; + from_physical_map[{{physical_core.x, physical_core.y}, CoordSystem::VIRTUAL}] = virtual_coord; + + CoreCoord translated_coord = CoreCoord( + harvested_bank_translated_x, + harvested_bank_translated_y + noc_port, + CoreType::DRAM, + CoordSystem::TRANSLATED); + to_physical_map[translated_coord] = {physical_core.x, physical_core.y}; + from_physical_map[{{physical_core.x, physical_core.y}, CoordSystem::TRANSLATED}] = translated_coord; + } } diff --git a/device/coordinate_manager.cpp b/device/coordinate_manager.cpp index 01bba5c6..c0fab068 100644 --- a/device/coordinate_manager.cpp +++ b/device/coordinate_manager.cpp @@ -38,179 +38,53 @@ CoordinateManager::CoordinateManager( pcie_grid_size(pcie_grid_size), pcie_cores(pcie_cores) {} -std::map& CoordinateManager::get_logical_to_translated(CoreType core_type) { - switch (core_type) { - case CoreType::TENSIX: - return tensix_logical_to_translated; - case CoreType::DRAM: - return dram_logical_to_translated; - case CoreType::ACTIVE_ETH: - case CoreType::IDLE_ETH: - case CoreType::ETH: - return eth_logical_to_translated; - case CoreType::ARC: - return arc_logical_to_translated; - case CoreType::PCIE: - return pcie_logical_to_translated; - default: - throw std::runtime_error("Core type is not supported for getting logical to translated mapping"); - } -} - -std::map& CoordinateManager::get_logical_to_virtual(CoreType core_type) { - switch (core_type) { - case CoreType::TENSIX: - return tensix_logical_to_virtual; - case CoreType::DRAM: - return dram_logical_to_virtual; - case CoreType::ACTIVE_ETH: - case CoreType::IDLE_ETH: - case CoreType::ETH: - return eth_logical_to_virtual; - case CoreType::ARC: - return arc_logical_to_virtual; - case CoreType::PCIE: - return pcie_logical_to_virtual; - default: - throw std::runtime_error("Core type is not supported for getting logical to virtual mapping"); - } -} - -std::map& CoordinateManager::get_logical_to_physical(CoreType core_type) { - switch (core_type) { - case CoreType::TENSIX: - return tensix_logical_to_physical; - case CoreType::DRAM: - return dram_logical_to_physical; - case CoreType::ACTIVE_ETH: - case CoreType::IDLE_ETH: - case CoreType::ETH: - return eth_logical_to_physical; - case CoreType::ARC: - return arc_logical_to_physical; - case CoreType::PCIE: - return pcie_logical_to_physical; - default: - throw std::runtime_error("Core type is not supported for getting logical to physical mapping"); - } -} - -std::map& CoordinateManager::get_physical_to_logical(CoreType core_type) { - switch (core_type) { - case CoreType::TENSIX: - return tensix_physical_to_logical; - case CoreType::DRAM: - return dram_physical_to_logical; - case CoreType::ACTIVE_ETH: - case CoreType::IDLE_ETH: - case CoreType::ETH: - return eth_physical_to_logical; - case CoreType::ARC: - return arc_physical_to_logical; - case CoreType::PCIE: - return pcie_physical_to_logical; - default: - throw std::runtime_error("Core type is not supported for getting physical to logical mapping"); - } -} - -std::map& CoordinateManager::get_virtual_to_logical(CoreType core_type) { - switch (core_type) { - case CoreType::TENSIX: - return tensix_virtual_to_logical; - case CoreType::DRAM: - return dram_virtual_to_logical; - case CoreType::ACTIVE_ETH: - case CoreType::IDLE_ETH: - case CoreType::ETH: - return eth_virtual_to_logical; - case CoreType::ARC: - return arc_virtual_to_logical; - case CoreType::PCIE: - return pcie_virtual_to_logical; - default: - throw std::runtime_error("Core type is not supported for getting virtual to logical mapping"); - } -} - -std::map& CoordinateManager::get_translated_to_logical(CoreType core_type) { - switch (core_type) { - case CoreType::TENSIX: - return tensix_translated_to_logical; - case CoreType::DRAM: - return dram_translated_to_logical; - case CoreType::ACTIVE_ETH: - case CoreType::IDLE_ETH: - case CoreType::ETH: - return eth_translated_to_logical; - case CoreType::ARC: - return arc_translated_to_logical; - case CoreType::PCIE: - return pcie_translated_to_logical; - default: - throw std::runtime_error("Core type is not supported for getting translated to logical mapping"); - } -} - CoreCoord CoordinateManager::to_physical(const CoreCoord core_coord) { switch (core_coord.coord_system) { case CoordSystem::PHYSICAL: return core_coord; case CoordSystem::VIRTUAL: case CoordSystem::TRANSLATED: - return to_physical(to_logical(core_coord)); + case CoordSystem::LOGICAL: { + const tt_xy_pair physical_pair = to_physical_map[core_coord]; + return CoreCoord(physical_pair.x, physical_pair.y, core_coord.core_type, CoordSystem::PHYSICAL); + } } - - // Coord system is surely logical. - auto& logical_mapping = get_logical_to_physical(core_coord.core_type); - return logical_mapping[{core_coord.x, core_coord.y}]; } CoreCoord CoordinateManager::to_virtual(const CoreCoord core_coord) { switch (core_coord.coord_system) { - case CoordSystem::TRANSLATED: - case CoordSystem::PHYSICAL: - return to_virtual(to_logical(core_coord)); case CoordSystem::VIRTUAL: return core_coord; + case CoordSystem::PHYSICAL: + return from_physical_map[{{core_coord.x, core_coord.y}, CoordSystem::VIRTUAL}]; + case CoordSystem::TRANSLATED: + case CoordSystem::LOGICAL: + return to_virtual(to_physical(core_coord)); } - - // Coord system is surely logical. - auto& logical_mapping = get_logical_to_virtual(core_coord.core_type); - return logical_mapping[{core_coord.x, core_coord.y}]; } CoreCoord CoordinateManager::to_logical(const CoreCoord core_coord) { switch (core_coord.coord_system) { case CoordSystem::LOGICAL: return core_coord; - case CoordSystem::PHYSICAL: { - auto& physical_mapping = get_physical_to_logical(core_coord.core_type); - return physical_mapping[{core_coord.x, core_coord.y}]; - } - case CoordSystem::VIRTUAL: { - auto& virtual_mapping = get_virtual_to_logical(core_coord.core_type); - return virtual_mapping[{core_coord.x, core_coord.y}]; - } - case CoordSystem::TRANSLATED: { - auto& translated_mapping = get_translated_to_logical(core_coord.core_type); - return translated_mapping[{core_coord.x, core_coord.y}]; - } + case CoordSystem::PHYSICAL: + return from_physical_map[{{core_coord.x, core_coord.y}, CoordSystem::LOGICAL}]; + case CoordSystem::VIRTUAL: + case CoordSystem::TRANSLATED: + return to_logical(to_physical(core_coord)); } } CoreCoord CoordinateManager::to_translated(const CoreCoord core_coord) { switch (core_coord.coord_system) { case CoordSystem::PHYSICAL: + return from_physical_map[{{core_coord.x, core_coord.y}, CoordSystem::TRANSLATED}]; + case CoordSystem::LOGICAL: case CoordSystem::VIRTUAL: - return to_translated(to_logical(core_coord)); + return to_translated(to_physical(core_coord)); case CoordSystem::TRANSLATED: return core_coord; } - - // Coord system is surely logical. - auto& logical_mapping = get_logical_to_translated(core_coord.core_type); - return logical_mapping[{core_coord.x, core_coord.y}]; } CoreCoord CoordinateManager::to(const CoreCoord core_coord, const CoordSystem coord_system) { @@ -227,7 +101,7 @@ CoreCoord CoordinateManager::to(const CoreCoord core_coord, const CoordSystem co } void CoordinateManager::translate_tensix_coords() { - size_t num_harvested_y = __builtin_popcount(tensix_harvesting_mask); + size_t num_harvested_y = CoordinateManager::get_num_harvested(tensix_harvesting_mask); size_t grid_size_x = tensix_grid_size.x; size_t grid_size_y = tensix_grid_size.y; @@ -236,10 +110,10 @@ void CoordinateManager::translate_tensix_coords() { if (!(tensix_harvesting_mask & (1 << y))) { for (size_t x = 0; x < grid_size_x; x++) { const tt_xy_pair& tensix_core = tensix_cores[y * grid_size_x + x]; - tensix_logical_to_physical[{x, logical_y}] = - CoreCoord(tensix_core.x, tensix_core.y, CoreType::TENSIX, CoordSystem::PHYSICAL); - tensix_physical_to_logical[tensix_core] = - CoreCoord(x, logical_y, CoreType::TENSIX, CoordSystem::LOGICAL); + CoreCoord logical_coord = CoreCoord(x, logical_y, CoreType::TENSIX, CoordSystem::LOGICAL); + + to_physical_map.insert({logical_coord, {tensix_core.x, tensix_core.y}}); + from_physical_map.insert({{{tensix_core.x, tensix_core.y}, CoordSystem::LOGICAL}, logical_coord}); } logical_y++; } @@ -248,9 +122,29 @@ void CoordinateManager::translate_tensix_coords() { for (size_t y = 0; y < grid_size_y - num_harvested_y; y++) { for (size_t x = 0; x < grid_size_x; x++) { const tt_xy_pair& tensix_core = tensix_cores[y * grid_size_x + x]; - tensix_logical_to_virtual[{x, y}] = - CoreCoord(tensix_core.x, tensix_core.y, CoreType::TENSIX, CoordSystem::VIRTUAL); - tensix_virtual_to_logical[tensix_core] = CoreCoord(x, y, CoreType::TENSIX, CoordSystem::LOGICAL); + CoreCoord virtual_coord = CoreCoord(tensix_core.x, tensix_core.y, CoreType::TENSIX, CoordSystem::VIRTUAL); + + CoreCoord logical_coord = CoreCoord(x, y, CoreType::TENSIX, CoordSystem::LOGICAL); + const tt_xy_pair physical_pair = to_physical_map[logical_coord]; + + to_physical_map[virtual_coord] = physical_pair; + from_physical_map[{physical_pair, CoordSystem::VIRTUAL}] = virtual_coord; + } + } + + size_t harvested_index = (grid_size_y - num_harvested_y) * grid_size_x; + for (size_t y = 0; y < grid_size_y; y++) { + if (tensix_harvesting_mask & (1 << y)) { + for (size_t x = 0; x < grid_size_x; x++) { + const tt_xy_pair& physical_core = tensix_cores[y * grid_size_x + x]; + const tt_xy_pair& virtual_core = tensix_cores[harvested_index++]; + + CoreCoord virtual_coord = + CoreCoord(virtual_core.x, virtual_core.y, CoreType::TENSIX, CoordSystem::VIRTUAL); + + to_physical_map[virtual_coord] = {physical_core.x, physical_core.y}; + from_physical_map[{{physical_core.x, physical_core.y}, CoordSystem::VIRTUAL}] = virtual_coord; + } } } @@ -258,17 +152,36 @@ void CoordinateManager::translate_tensix_coords() { } void CoordinateManager::fill_tensix_logical_to_translated() { - size_t num_harvested_y = __builtin_popcount(tensix_harvesting_mask); + size_t num_harvested_y = CoordinateManager::get_num_harvested(tensix_harvesting_mask); for (size_t x = 0; x < tensix_grid_size.x; x++) { for (size_t y = 0; y < tensix_grid_size.y - num_harvested_y; y++) { - const CoreCoord physical_coord = tensix_logical_to_physical[{x, y}]; - const size_t translated_x = physical_coord.x; - const size_t translated_y = physical_coord.y; - tensix_logical_to_translated[{x, y}] = + CoreCoord logical_coord = CoreCoord(x, y, CoreType::TENSIX, CoordSystem::LOGICAL); + const tt_xy_pair physical_pair = to_physical_map[logical_coord]; + const size_t translated_x = physical_pair.x; + const size_t translated_y = physical_pair.y; + + CoreCoord translated_coord = CoreCoord(translated_x, translated_y, CoreType::TENSIX, CoordSystem::TRANSLATED); - tensix_translated_to_logical[tt_xy_pair(translated_x, translated_y)] = - CoreCoord(x, y, CoreType::TENSIX, CoordSystem::LOGICAL); + to_physical_map[translated_coord] = physical_pair; + from_physical_map[{{physical_pair.x, physical_pair.y}, CoordSystem::TRANSLATED}] = translated_coord; + } + } + + size_t harvested_index = (tensix_grid_size.y - num_harvested_y) * tensix_grid_size.x; + for (size_t y = 0; y < tensix_grid_size.y; y++) { + if (tensix_harvesting_mask & (1 << y)) { + for (size_t x = 0; x < tensix_grid_size.x; x++) { + const tt_xy_pair& physical_core = tensix_cores[y * tensix_grid_size.x + x]; + const size_t translated_x = physical_core.x; + const size_t translated_y = physical_core.y; + + CoreCoord translated_coord = + CoreCoord(translated_x, translated_y, CoreType::TENSIX, CoordSystem::TRANSLATED); + + to_physical_map[translated_coord] = {physical_core.x, physical_core.y}; + from_physical_map[{{physical_core.x, physical_core.y}, CoordSystem::TRANSLATED}] = translated_coord; + } } } } @@ -277,12 +190,15 @@ void CoordinateManager::translate_dram_coords() { for (size_t x = 0; x < dram_grid_size.x; x++) { for (size_t y = 0; y < dram_grid_size.y; y++) { const tt_xy_pair dram_core = dram_cores[x * dram_grid_size.y + y]; - dram_logical_to_virtual[{x, y}] = CoreCoord(dram_core.x, dram_core.y, CoreType::DRAM, CoordSystem::VIRTUAL); - dram_virtual_to_logical[dram_core] = CoreCoord(x, y, CoreType::DRAM, CoordSystem::LOGICAL); - dram_logical_to_physical[{x, y}] = - CoreCoord(dram_core.x, dram_core.y, CoreType::DRAM, CoordSystem::PHYSICAL); - dram_physical_to_logical[dram_core] = CoreCoord(x, y, CoreType::DRAM, CoordSystem::LOGICAL); + CoreCoord logical_coord = CoreCoord(x, y, CoreType::DRAM, CoordSystem::LOGICAL); + CoreCoord virtual_coord = CoreCoord(dram_core.x, dram_core.y, CoreType::DRAM, CoordSystem::VIRTUAL); + + to_physical_map[logical_coord] = {dram_core.x, dram_core.y}; + from_physical_map[{{dram_core.x, dram_core.y}, CoordSystem::LOGICAL}] = logical_coord; + + to_physical_map[virtual_coord] = {dram_core.x, dram_core.y}; + from_physical_map[{{dram_core.x, dram_core.y}, CoordSystem::VIRTUAL}] = virtual_coord; } } @@ -293,11 +209,15 @@ void CoordinateManager::translate_eth_coords() { for (size_t x = 0; x < eth_grid_size.x; x++) { for (size_t y = 0; y < eth_grid_size.y; y++) { const tt_xy_pair eth_core = eth_cores[x * eth_grid_size.y + y]; - eth_logical_to_virtual[{x, y}] = CoreCoord(eth_core.x, eth_core.y, CoreType::ETH, CoordSystem::VIRTUAL); - eth_virtual_to_logical[eth_core] = CoreCoord(x, y, CoreType::ETH, CoordSystem::LOGICAL); - eth_logical_to_physical[{x, y}] = CoreCoord(eth_core.x, eth_core.y, CoreType::ETH, CoordSystem::PHYSICAL); - eth_physical_to_logical[eth_core] = CoreCoord(x, y, CoreType::ETH, CoordSystem::LOGICAL); + CoreCoord logical_coord = CoreCoord(x, y, CoreType::ETH, CoordSystem::LOGICAL); + CoreCoord virtual_coord = CoreCoord(eth_core.x, eth_core.y, CoreType::ETH, CoordSystem::VIRTUAL); + + to_physical_map[logical_coord] = {eth_core.x, eth_core.y}; + from_physical_map[{{eth_core.x, eth_core.y}, CoordSystem::LOGICAL}] = logical_coord; + + to_physical_map[virtual_coord] = {eth_core.x, eth_core.y}; + from_physical_map[{{eth_core.x, eth_core.y}, CoordSystem::VIRTUAL}] = virtual_coord; } } @@ -308,15 +228,15 @@ void CoordinateManager::translate_arc_coords() { for (size_t x = 0; x < arc_grid_size.x; x++) { for (size_t y = 0; y < arc_grid_size.y; y++) { const tt_xy_pair arc_core = arc_cores[x * arc_grid_size.y + y]; - arc_logical_to_virtual[{x, y}] = CoreCoord(arc_core.x, arc_core.y, CoreType::ARC, CoordSystem::VIRTUAL); - arc_virtual_to_logical[arc_core] = CoreCoord(x, y, CoreType::ARC, CoordSystem::LOGICAL); - arc_logical_to_physical[{x, y}] = CoreCoord(arc_core.x, arc_core.y, CoreType::ARC, CoordSystem::PHYSICAL); - arc_physical_to_logical[arc_core] = CoreCoord(x, y, CoreType::ARC, CoordSystem::LOGICAL); + CoreCoord logical_coord = CoreCoord(x, y, CoreType::ARC, CoordSystem::LOGICAL); + CoreCoord virtual_coord = CoreCoord(arc_core.x, arc_core.y, CoreType::ARC, CoordSystem::VIRTUAL); + + to_physical_map[logical_coord] = {arc_core.x, arc_core.y}; + from_physical_map[{{arc_core.x, arc_core.y}, CoordSystem::LOGICAL}] = logical_coord; - arc_logical_to_translated[{x, y}] = - CoreCoord(arc_core.x, arc_core.y, CoreType::ARC, CoordSystem::TRANSLATED); - arc_translated_to_logical[arc_core] = CoreCoord(x, y, CoreType::ARC, CoordSystem::LOGICAL); + to_physical_map[virtual_coord] = {arc_core.x, arc_core.y}; + from_physical_map[{{arc_core.x, arc_core.y}, CoordSystem::VIRTUAL}] = virtual_coord; } } @@ -327,12 +247,14 @@ void CoordinateManager::translate_pcie_coords() { for (size_t x = 0; x < pcie_grid_size.x; x++) { for (size_t y = 0; y < pcie_grid_size.y; y++) { const tt_xy_pair pcie_core = pcie_cores[x * pcie_grid_size.y + y]; - pcie_logical_to_virtual[{x, y}] = CoreCoord(pcie_core.x, pcie_core.y, CoreType::PCIE, CoordSystem::VIRTUAL); - pcie_virtual_to_logical[pcie_core] = CoreCoord(x, y, CoreType::PCIE, CoordSystem::LOGICAL); + CoreCoord logical_coord = CoreCoord(x, y, CoreType::PCIE, CoordSystem::LOGICAL); + CoreCoord virtual_coord = CoreCoord(pcie_core.x, pcie_core.y, CoreType::PCIE, CoordSystem::VIRTUAL); + + to_physical_map[logical_coord] = {pcie_core.x, pcie_core.y}; + from_physical_map[{{pcie_core.x, pcie_core.y}, CoordSystem::LOGICAL}] = logical_coord; - pcie_logical_to_physical[{x, y}] = - CoreCoord(pcie_core.x, pcie_core.y, CoreType::PCIE, CoordSystem::PHYSICAL); - pcie_physical_to_logical[pcie_core] = CoreCoord(x, y, CoreType::PCIE, CoordSystem::LOGICAL); + to_physical_map[virtual_coord] = {pcie_core.x, pcie_core.y}; + from_physical_map[{{pcie_core.x, pcie_core.y}, CoordSystem::VIRTUAL}] = virtual_coord; } } @@ -342,13 +264,14 @@ void CoordinateManager::translate_pcie_coords() { void CoordinateManager::fill_eth_logical_to_translated() { for (size_t x = 0; x < eth_grid_size.x; x++) { for (size_t y = 0; y < eth_grid_size.y; y++) { - const CoreCoord physical_coord = eth_logical_to_physical[{x, y}]; - const size_t translated_x = physical_coord.x; - const size_t translated_y = physical_coord.y; - eth_logical_to_translated[{x, y}] = - CoreCoord(translated_x, translated_y, CoreType::ETH, CoordSystem::TRANSLATED); - eth_translated_to_logical[{translated_x, translated_y}] = - CoreCoord(x, y, CoreType::ETH, CoordSystem::LOGICAL); + CoreCoord logical_coord = CoreCoord(x, y, CoreType::ETH, CoordSystem::LOGICAL); + const tt_xy_pair physical_pair = to_physical_map[logical_coord]; + const size_t translated_x = physical_pair.x; + const size_t translated_y = physical_pair.y; + + CoreCoord translated_coord = CoreCoord(translated_x, translated_y, CoreType::ETH, CoordSystem::TRANSLATED); + to_physical_map[translated_coord] = physical_pair; + from_physical_map[{{physical_pair.x, physical_pair.y}, CoordSystem::TRANSLATED}] = translated_coord; } } } @@ -356,13 +279,14 @@ void CoordinateManager::fill_eth_logical_to_translated() { void CoordinateManager::fill_dram_logical_to_translated() { for (size_t x = 0; x < dram_grid_size.x; x++) { for (size_t y = 0; y < dram_grid_size.y; y++) { - const CoreCoord physical_coord = dram_logical_to_physical[{x, y}]; - const size_t translated_x = physical_coord.x; - const size_t translated_y = physical_coord.y; - dram_logical_to_translated[{x, y}] = - CoreCoord(translated_x, translated_y, CoreType::DRAM, CoordSystem::TRANSLATED); - dram_translated_to_logical[{translated_x, translated_y}] = - CoreCoord(x, y, CoreType::DRAM, CoordSystem::LOGICAL); + CoreCoord logical_coord = CoreCoord(x, y, CoreType::DRAM, CoordSystem::LOGICAL); + const tt_xy_pair physical_pair = to_physical_map[logical_coord]; + const size_t translated_x = physical_pair.x; + const size_t translated_y = physical_pair.y; + + CoreCoord translated_coord = CoreCoord(translated_x, translated_y, CoreType::DRAM, CoordSystem::TRANSLATED); + to_physical_map[translated_coord] = physical_pair; + from_physical_map[{{physical_pair.x, physical_pair.y}, CoordSystem::TRANSLATED}] = translated_coord; } } } @@ -370,13 +294,14 @@ void CoordinateManager::fill_dram_logical_to_translated() { void CoordinateManager::fill_pcie_logical_to_translated() { for (size_t x = 0; x < pcie_grid_size.x; x++) { for (size_t y = 0; y < pcie_grid_size.y; y++) { - const CoreCoord physical_coord = pcie_logical_to_physical[{x, y}]; - const size_t translated_x = physical_coord.x; - const size_t translated_y = physical_coord.y; - pcie_logical_to_translated[{x, y}] = - CoreCoord(translated_x, translated_y, CoreType::PCIE, CoordSystem::TRANSLATED); - pcie_translated_to_logical[{translated_x, translated_y}] = - CoreCoord(x, y, CoreType::PCIE, CoordSystem::LOGICAL); + CoreCoord logical_coord = CoreCoord(x, y, CoreType::PCIE, CoordSystem::LOGICAL); + const tt_xy_pair physical_pair = to_physical_map[logical_coord]; + const size_t translated_x = physical_pair.x; + const size_t translated_y = physical_pair.y; + + CoreCoord translated_coord = CoreCoord(translated_x, translated_y, CoreType::PCIE, CoordSystem::TRANSLATED); + to_physical_map[translated_coord] = physical_pair; + from_physical_map[{{physical_pair.x, physical_pair.y}, CoordSystem::TRANSLATED}] = translated_coord; } } } @@ -384,13 +309,14 @@ void CoordinateManager::fill_pcie_logical_to_translated() { void CoordinateManager::fill_arc_logical_to_translated() { for (size_t x = 0; x < arc_grid_size.x; x++) { for (size_t y = 0; y < arc_grid_size.y; y++) { - const CoreCoord physical_coord = arc_logical_to_physical[{x, y}]; - const size_t translated_x = physical_coord.x; - const size_t translated_y = physical_coord.y; - arc_logical_to_translated[{x, y}] = - CoreCoord(translated_x, translated_y, CoreType::ARC, CoordSystem::TRANSLATED); - arc_translated_to_logical[{translated_x, translated_y}] = - CoreCoord(x, y, CoreType::ARC, CoordSystem::LOGICAL); + CoreCoord logical_coord = CoreCoord(x, y, CoreType::ARC, CoordSystem::LOGICAL); + const tt_xy_pair physical_pair = to_physical_map[logical_coord]; + const size_t translated_x = physical_pair.x; + const size_t translated_y = physical_pair.y; + + CoreCoord translated_coord = CoreCoord(translated_x, translated_y, CoreType::ARC, CoordSystem::TRANSLATED); + to_physical_map[translated_coord] = physical_pair; + from_physical_map[{{physical_pair.x, physical_pair.y}, CoordSystem::TRANSLATED}] = translated_coord; } } } diff --git a/device/grayskull/grayskull_coordinate_manager.cpp b/device/grayskull/grayskull_coordinate_manager.cpp index 3232717f..17f893e0 100644 --- a/device/grayskull/grayskull_coordinate_manager.cpp +++ b/device/grayskull/grayskull_coordinate_manager.cpp @@ -43,13 +43,14 @@ GrayskullCoordinateManager::GrayskullCoordinateManager( void GrayskullCoordinateManager::fill_eth_logical_to_translated() { for (size_t x = 0; x < eth_grid_size.x; x++) { for (size_t y = 0; y < eth_grid_size.y; y++) { - const CoreCoord physical_coord = eth_logical_to_physical[{x, y}]; - const size_t translated_x = physical_coord.x; - const size_t translated_y = physical_coord.y; - eth_logical_to_translated[{x, y}] = - CoreCoord(translated_x, translated_y, CoreType::ETH, CoordSystem::TRANSLATED); - eth_translated_to_logical[{translated_x, translated_y}] = - CoreCoord(x, y, CoreType::ETH, CoordSystem::LOGICAL); + CoreCoord logical_coord = CoreCoord(x, y, CoreType::ETH, CoordSystem::LOGICAL); + const tt_xy_pair physical_pair = to_physical_map[logical_coord]; + const size_t translated_x = physical_pair.x; + const size_t translated_y = physical_pair.y; + + CoreCoord translated_coord = CoreCoord(translated_x, translated_y, CoreType::ETH, CoordSystem::TRANSLATED); + to_physical_map[translated_coord] = physical_pair; + from_physical_map[{{physical_pair.x, physical_pair.y}, CoordSystem::TRANSLATED}] = translated_coord; } } } diff --git a/device/wormhole/wormhole_coordinate_manager.cpp b/device/wormhole/wormhole_coordinate_manager.cpp index 4ba6dc52..0f351cf0 100644 --- a/device/wormhole/wormhole_coordinate_manager.cpp +++ b/device/wormhole/wormhole_coordinate_manager.cpp @@ -41,16 +41,37 @@ WormholeCoordinateManager::WormholeCoordinateManager( } void WormholeCoordinateManager::fill_tensix_logical_to_translated() { - size_t num_harvested_y = __builtin_popcount(tensix_harvesting_mask); + size_t num_harvested_y = CoordinateManager::get_num_harvested(tensix_harvesting_mask); for (size_t y = 0; y < tensix_grid_size.y - num_harvested_y; y++) { for (size_t x = 0; x < tensix_grid_size.x; x++) { + CoreCoord logical_coord = CoreCoord(x, y, CoreType::TENSIX, CoordSystem::LOGICAL); + const tt_xy_pair physical_pair = to_physical_map[logical_coord]; const size_t translated_x = x + wormhole::tensix_translated_coordinate_start_x; const size_t translated_y = y + wormhole::tensix_translated_coordinate_start_y; - tensix_logical_to_translated[{x, y}] = + + CoreCoord translated_coord = CoreCoord(translated_x, translated_y, CoreType::TENSIX, CoordSystem::TRANSLATED); - tensix_translated_to_logical[tt_xy_pair(translated_x, translated_y)] = - CoreCoord(x, y, CoreType::TENSIX, CoordSystem::LOGICAL); + + to_physical_map[translated_coord] = {physical_pair.x, physical_pair.y}; + from_physical_map[{{physical_pair.x, physical_pair.y}, CoordSystem::TRANSLATED}] = translated_coord; + } + } + + size_t harvested_index = (tensix_grid_size.y - num_harvested_y) * tensix_grid_size.x; + size_t translated_y = wormhole::tensix_translated_coordinate_start_y + tensix_grid_size.y - num_harvested_y; + for (size_t y = 0; y < tensix_grid_size.y; y++) { + if (tensix_harvesting_mask & (1 << y)) { + for (size_t x = 0; x < tensix_grid_size.x; x++) { + const tt_xy_pair physical_core = tensix_cores[y * tensix_grid_size.x + x]; + const size_t translated_x = x + wormhole::tensix_translated_coordinate_start_x; + CoreCoord translated_coord = + CoreCoord(translated_x, translated_y, CoreType::TENSIX, CoordSystem::TRANSLATED); + + to_physical_map[translated_coord] = {physical_core.x, physical_core.y}; + from_physical_map[{{physical_core.x, physical_core.y}, CoordSystem::TRANSLATED}] = translated_coord; + } + translated_y++; } } } @@ -60,10 +81,11 @@ void WormholeCoordinateManager::fill_eth_logical_to_translated() { for (size_t y = 0; y < eth_grid_size.y; y++) { const size_t translated_x = x + wormhole::eth_translated_coordinate_start_x; const size_t translated_y = y + wormhole::eth_translated_coordinate_start_y; - eth_logical_to_translated[{x, y}] = - CoreCoord(translated_x, translated_y, CoreType::ETH, CoordSystem::TRANSLATED); - eth_translated_to_logical[{translated_x, translated_y}] = - CoreCoord(x, y, CoreType::ETH, CoordSystem::LOGICAL); + CoreCoord logical_coord = CoreCoord(x, y, CoreType::ETH, CoordSystem::LOGICAL); + const tt_xy_pair physical_pair = to_physical_map[logical_coord]; + CoreCoord translated_coord = CoreCoord(translated_x, translated_y, CoreType::ETH, CoordSystem::TRANSLATED); + to_physical_map[translated_coord] = {physical_pair.x, physical_pair.y}; + from_physical_map[{{physical_pair.x, physical_pair.y}, CoordSystem::TRANSLATED}] = translated_coord; } } } diff --git a/tests/api/test_core_coord_translation_bh.cpp b/tests/api/test_core_coord_translation_bh.cpp index 95cbe155..e468f590 100644 --- a/tests/api/test_core_coord_translation_bh.cpp +++ b/tests/api/test_core_coord_translation_bh.cpp @@ -201,6 +201,49 @@ TEST(CoordinateManager, CoordinateManagerBlackholeVirtualEqualTranslated) { } } +// Test mapping of the coordinates for harvested DRAM bank. +TEST(CoordinateManager, CoordinateManagerBlackholeTransltedMappingHarvested) { + const size_t harvesting_mask = 3; + std::shared_ptr coordinate_manager = + CoordinateManager::create_coordinate_manager(tt::ARCH::BLACKHOLE, harvesting_mask); + + const tt_xy_pair tensix_grid_size = tt::umd::blackhole::TENSIX_GRID_SIZE; + const std::vector tensix_cores = tt::umd::blackhole::TENSIX_CORES; + + size_t num_harvested_x = CoordinateManager::get_num_harvested(harvesting_mask); + + size_t index = 0; + size_t virtual_index = tensix_grid_size.x - num_harvested_x; + + for (size_t cnt = 0; cnt < num_harvested_x * tensix_grid_size.y; cnt++) { + CoreCoord physical_core = + CoreCoord(tensix_cores[index].x, tensix_cores[index].y, CoreType::TENSIX, CoordSystem::PHYSICAL); + const CoreCoord translated_core = coordinate_manager->to(physical_core, CoordSystem::TRANSLATED); + + const CoreCoord virtual_core = CoreCoord( + tensix_cores[virtual_index].x, tensix_cores[virtual_index].y, CoreType::TENSIX, CoordSystem::VIRTUAL); + const CoreCoord translated_core_from_virtual = coordinate_manager->to(virtual_core, CoordSystem::TRANSLATED); + + EXPECT_EQ(translated_core, translated_core_from_virtual); + + EXPECT_EQ(translated_core.x, tensix_cores[virtual_index].x); + EXPECT_EQ(translated_core.y, tensix_cores[virtual_index].y); + + index += tensix_grid_size.x; + virtual_index += tensix_grid_size.x; + + if (index >= tensix_cores.size()) { + index = index % tensix_cores.size(); + index++; + } + + if (virtual_index >= tensix_cores.size()) { + virtual_index = virtual_index % tensix_cores.size(); + virtual_index++; + } + } +} + // Test mapping of DRAM coordinates from logical to physical. When there is no DRAM harvesting, logical // coordinates should cover all physical coordinates. TEST(CoordinateManager, CoordinateManagerBlackholeDRAMNoHarvesting) { @@ -381,6 +424,47 @@ TEST(CoordinateManager, CoordinateManagerBlackholeDRAMTranslatedMapping) { } } +// Test DRAM translated/virtual/physical mapping +TEST(CoordinateManager, CoordinateManagerBlackholeDRAMVirtualPhysicalMapping) { + const size_t max_num_banks_harvested = tt::umd::blackhole::NUM_DRAM_BANKS; + const size_t num_dram_banks = tt::umd::blackhole::NUM_DRAM_BANKS; + const size_t num_noc_ports_per_bank = tt::umd::blackhole::NUM_NOC_PORTS_PER_DRAM_BANK; + + const std::vector dram_cores = tt::umd::blackhole::DRAM_CORES; + + const size_t dram_harvesting_mask = 1; + + std::shared_ptr coordinate_manager = + CoordinateManager::create_coordinate_manager(tt::ARCH::BLACKHOLE, 0, dram_harvesting_mask); + + const size_t physical_index = 0; + const size_t virtual_index = (num_dram_banks - 1) * num_noc_ports_per_bank; + + const size_t harvested_translated_bank_x = tt::umd::blackhole::dram_translated_coordinate_start_x + 1; + const size_t harvested_translated_bank_y = + tt::umd::blackhole::dram_translated_coordinate_start_y + 3 * num_noc_ports_per_bank; + + for (size_t noc_port = 0; noc_port < num_noc_ports_per_bank; noc_port++) { + const tt_xy_pair physical_pair = dram_cores[physical_index + noc_port]; + const tt_xy_pair virtual_pair = dram_cores[virtual_index + noc_port]; + + CoreCoord physical_core = CoreCoord(physical_pair.x, physical_pair.y, CoreType::DRAM, CoordSystem::PHYSICAL); + CoreCoord virtual_from_physical = coordinate_manager->to(physical_core, CoordSystem::VIRTUAL); + + CoreCoord virtual_core = CoreCoord(virtual_pair.x, virtual_pair.y, CoreType::DRAM, CoordSystem::VIRTUAL); + + EXPECT_EQ(virtual_from_physical, virtual_core); + + CoreCoord translated_core = coordinate_manager->to(physical_core, CoordSystem::TRANSLATED); + CoreCoord translated_from_virtual = coordinate_manager->to(virtual_core, CoordSystem::TRANSLATED); + + EXPECT_EQ(translated_core, translated_from_virtual); + + EXPECT_EQ(translated_core.x, harvested_translated_bank_x); + EXPECT_EQ(translated_core.y, harvested_translated_bank_y + noc_port); + } +} + // Test that we cannot create a coordinate manager with more than one DRAM bank harvested. TEST(CoordinateManager, CoordinateManagerBlackholeDRAMPMoreThanOneDRAMBankHarvested) { const size_t max_num_banks_harvested = tt::umd::blackhole::NUM_DRAM_BANKS; diff --git a/tests/api/test_core_coord_translation_gs.cpp b/tests/api/test_core_coord_translation_gs.cpp index 233cb9e3..1bbe2387 100644 --- a/tests/api/test_core_coord_translation_gs.cpp +++ b/tests/api/test_core_coord_translation_gs.cpp @@ -174,6 +174,62 @@ TEST(CoordinateManager, CoordinateManagerGrayskullLogicalVirtualMapping) { } } +// Test that harvested physical coordinates map to the last row of the virtual coordinates. +TEST(CoordinateManager, CoordinateManagerWormholePhysicalGrayskullHarvestedMapping) { + // Harvest first and second NOC layout row. + const size_t harvesting_mask = 3; + const size_t num_harvested = CoordinateManager::get_num_harvested(harvesting_mask); + std::shared_ptr coordinate_manager = + CoordinateManager::create_coordinate_manager(tt::ARCH::GRAYSKULL, 3); + + const std::vector tensix_cores = tt::umd::grayskull::TENSIX_CORES; + const tt_xy_pair tensix_grid_size = tt::umd::grayskull::TENSIX_GRID_SIZE; + + size_t virtual_index = (tensix_grid_size.y - num_harvested) * tensix_grid_size.x; + + for (size_t index = 0; index < num_harvested * tensix_grid_size.x; index++) { + const CoreCoord physical_core = + CoreCoord(tensix_cores[index].x, tensix_cores[index].y, CoreType::TENSIX, CoordSystem::PHYSICAL); + const CoreCoord virtual_core = coordinate_manager->to(physical_core, CoordSystem::VIRTUAL); + + EXPECT_EQ(virtual_core.x, tensix_cores[virtual_index].x); + EXPECT_EQ(virtual_core.y, tensix_cores[virtual_index].y); + + virtual_index++; + } +} + +// Test that harvested physical coordinates map to the last row of the virtual coordinates. +TEST(CoordinateManager, CoordinateManagerGrayskullPhysicalTranslatedHarvestedMapping) { + // Harvest first and second NOC layout row. + const size_t harvesting_mask = 3; + const size_t num_harvested = CoordinateManager::get_num_harvested(harvesting_mask); + std::shared_ptr coordinate_manager = + CoordinateManager::create_coordinate_manager(tt::ARCH::GRAYSKULL, 3); + + const std::vector tensix_cores = tt::umd::grayskull::TENSIX_CORES; + const tt_xy_pair tensix_grid_size = tt::umd::grayskull::TENSIX_GRID_SIZE; + + size_t virtual_index = (tensix_grid_size.y - num_harvested) * tensix_grid_size.x; + + for (size_t index = 0; index < num_harvested * tensix_grid_size.x; index++) { + const CoreCoord physical_core = + CoreCoord(tensix_cores[index].x, tensix_cores[index].y, CoreType::TENSIX, CoordSystem::PHYSICAL); + const CoreCoord translated_core = coordinate_manager->to(physical_core, CoordSystem::TRANSLATED); + + const CoreCoord virtual_core = CoreCoord( + tensix_cores[virtual_index].x, tensix_cores[virtual_index].y, CoreType::TENSIX, CoordSystem::VIRTUAL); + const CoreCoord translated_core_from_virtual = coordinate_manager->to(virtual_core, CoordSystem::TRANSLATED); + + EXPECT_EQ(translated_core, translated_core_from_virtual); + + EXPECT_EQ(physical_core.x, translated_core.x); + EXPECT_EQ(physical_core.y, translated_core.y); + + virtual_index++; + } +} + // Test mapping of DRAM coordinates from logical to physical. We have no DRAM harvesting on Grayskull, // so logical coordinates should cover all physical coordinates. TEST(CoordinateManager, CoordinateManagerGrayskullDRAMNoHarvesting) { diff --git a/tests/api/test_core_coord_translation_wh.cpp b/tests/api/test_core_coord_translation_wh.cpp index d19539a8..019d220b 100644 --- a/tests/api/test_core_coord_translation_wh.cpp +++ b/tests/api/test_core_coord_translation_wh.cpp @@ -8,6 +8,7 @@ #include "umd/device/wormhole_implementation.h" using namespace tt::umd; +#include // Tests that all physical coordinates are same as all virtual coordinates // when there is no harvesting. @@ -146,8 +147,8 @@ TEST(CoordinateManager, CoordinateManagerWormholeLogicalTranslatedTopLeft) { const size_t max_num_harvested_y = 10; - // We go up to numbers less than 2^10 - 1 to test all possible harvesting masks, we fon't want to try to convert if - // everything is harvested. + // We go up to numbers less than 2^10 - 1 to test all possible harvesting masks, we fon't want to try to convert + // if everything is harvested. for (size_t harvesting_mask = 0; harvesting_mask < (1 << max_num_harvested_y) - 1; harvesting_mask++) { std::shared_ptr coordinate_manager = CoordinateManager::create_coordinate_manager(tt::ARCH::WORMHOLE_B0, harvesting_mask); @@ -170,6 +171,75 @@ TEST(CoordinateManager, CoordinateManagerWormholeLogicalTranslatedTopLeft) { } } +// Test that harvested physical coordinates map to the last row of the virtual coordinates. +TEST(CoordinateManager, CoordinateManagerWormholePhysicalVirtualHarvestedMapping) { + // Harvest first and second NOC layout row. + const size_t harvesting_mask = 3; + const size_t num_harvested = CoordinateManager::get_num_harvested(harvesting_mask); + std::shared_ptr coordinate_manager = + CoordinateManager::create_coordinate_manager(tt::ARCH::WORMHOLE_B0, 3); + + const std::vector tensix_cores = tt::umd::wormhole::TENSIX_CORES; + const tt_xy_pair tensix_grid_size = tt::umd::wormhole::TENSIX_GRID_SIZE; + + size_t virtual_index = (tensix_grid_size.y - num_harvested) * tensix_grid_size.x; + + for (size_t index = 0; index < num_harvested * tensix_grid_size.x; index++) { + const CoreCoord physical_core = + CoreCoord(tensix_cores[index].x, tensix_cores[index].y, CoreType::TENSIX, CoordSystem::PHYSICAL); + const CoreCoord virtual_core = coordinate_manager->to(physical_core, CoordSystem::VIRTUAL); + + EXPECT_EQ(virtual_core.x, tensix_cores[virtual_index].x); + EXPECT_EQ(virtual_core.y, tensix_cores[virtual_index].y); + + virtual_index++; + } +} + +// Test that harvested physical coordinates map to the last row of the virtual coordinates. +TEST(CoordinateManager, CoordinateManagerWormholePhysicalTranslatedHarvestedMapping) { + // Harvest first and second NOC layout row. + const size_t harvesting_mask = 3; + const size_t num_harvested = CoordinateManager::get_num_harvested(harvesting_mask); + std::shared_ptr coordinate_manager = + CoordinateManager::create_coordinate_manager(tt::ARCH::WORMHOLE_B0, 3); + + const std::vector tensix_cores = tt::umd::wormhole::TENSIX_CORES; + const tt_xy_pair tensix_grid_size = tt::umd::wormhole::TENSIX_GRID_SIZE; + + size_t virtual_index = (tensix_grid_size.y - num_harvested) * tensix_grid_size.x; + + const size_t translated_x_start = tt::umd::wormhole::tensix_translated_coordinate_start_x; + const size_t translated_y_start = tt::umd::wormhole::tensix_translated_coordinate_start_y; + + size_t logical_x = 0; + size_t logical_y = tensix_grid_size.y - num_harvested; + + for (size_t index = 0; index < num_harvested * tensix_grid_size.x; index++) { + const CoreCoord physical_core = + CoreCoord(tensix_cores[index].x, tensix_cores[index].y, CoreType::TENSIX, CoordSystem::PHYSICAL); + const CoreCoord translated_core = coordinate_manager->to(physical_core, CoordSystem::TRANSLATED); + + const CoreCoord virtual_core = CoreCoord( + tensix_cores[virtual_index].x, tensix_cores[virtual_index].y, CoreType::TENSIX, CoordSystem::VIRTUAL); + const CoreCoord translated_core_from_virtual = coordinate_manager->to(virtual_core, CoordSystem::TRANSLATED); + + EXPECT_EQ(translated_core, translated_core_from_virtual); + + EXPECT_EQ(translated_core.x, translated_x_start + logical_x); + EXPECT_EQ(translated_core.y, translated_y_start + logical_y); + + logical_x++; + + if (logical_x == tensix_grid_size.x) { + logical_x = 0; + logical_y++; + } + + virtual_index++; + } +} + // Test translation of DRAM core coordinates. There is no DRAM harvesting on Wormhole, // so logical coordinates should cover all physical coordinates. TEST(CoordinateManager, CoordinateManagerWormholeDRAMNoHarvesting) { @@ -263,16 +333,16 @@ TEST(CoordinateManager, CoordinateManagerWormholePCIETranslation) { for (size_t x = 0; x < pcie_grid_size.x; x++) { for (size_t y = 0; y < pcie_grid_size.y; y++) { - const CoreCoord arc_logical = CoreCoord(x, y, CoreType::PCIE, CoordSystem::LOGICAL); - const CoreCoord arc_virtual = coordinate_manager->to(arc_logical, CoordSystem::VIRTUAL); - const CoreCoord arc_physical = coordinate_manager->to(arc_logical, CoordSystem::PHYSICAL); - const CoreCoord arc_translated = coordinate_manager->to(arc_logical, CoordSystem::TRANSLATED); + const CoreCoord pcie_logical = CoreCoord(x, y, CoreType::PCIE, CoordSystem::LOGICAL); + const CoreCoord pcie_virtual = coordinate_manager->to(pcie_logical, CoordSystem::VIRTUAL); + const CoreCoord pcie_physical = coordinate_manager->to(pcie_logical, CoordSystem::PHYSICAL); + const CoreCoord pcie_translated = coordinate_manager->to(pcie_logical, CoordSystem::TRANSLATED); - EXPECT_EQ(arc_virtual.x, arc_physical.x); - EXPECT_EQ(arc_virtual.y, arc_physical.y); + EXPECT_EQ(pcie_virtual.x, pcie_physical.x); + EXPECT_EQ(pcie_virtual.y, pcie_physical.y); - EXPECT_EQ(arc_physical.x, arc_translated.x); - EXPECT_EQ(arc_physical.y, arc_translated.y); + EXPECT_EQ(pcie_virtual.x, pcie_translated.x); + EXPECT_EQ(pcie_virtual.y, pcie_translated.y); } } }