diff --git a/device/api/umd/device/coordinate_manager.h b/device/api/umd/device/coordinate_manager.h index f580fbd6..295aef1e 100644 --- a/device/api/umd/device/coordinate_manager.h +++ b/device/api/umd/device/coordinate_manager.h @@ -42,6 +42,13 @@ class CoordinateManager { static std::vector get_harvested_indices(const size_t harvesting_mask); + // Harvesting mask is reported by hardware in the order of physical layout. This function returns a more suitable + // representation in logical order: Bit 0 being set means the first row in NOC0 coords is harvested. + static uint32_t shuffle_tensix_harvesting_mask(tt::ARCH arch, uint32_t tensix_harvesting_physical_layout); + // TODO: This function should be removed once the corresponding API is removed from Cluster. + static uint32_t shuffle_tensix_harvesting_mask_to_noc0_coords( + tt::ARCH arch, uint32_t tensix_harvesting_logical_layout); + CoordinateManager(CoordinateManager& other) = default; tt::umd::CoreCoord translate_coord_to(const tt::umd::CoreCoord core_coord, const CoordSystem coord_system); @@ -91,8 +98,6 @@ class CoordinateManager { virtual void assert_coordinate_manager_constructor(); - virtual void shuffle_tensix_harvesting_mask(const std::vector& harvesting_locations); - virtual void translate_tensix_coords(); virtual void translate_dram_coords(); virtual void translate_eth_coords(); diff --git a/device/api/umd/device/tt_soc_descriptor.h b/device/api/umd/device/tt_soc_descriptor.h index 70416e42..d7ff75a1 100644 --- a/device/api/umd/device/tt_soc_descriptor.h +++ b/device/api/umd/device/tt_soc_descriptor.h @@ -140,6 +140,7 @@ class tt_SocDescriptor { int eth_l1_size; bool noc_translation_id_enabled; uint64_t dram_bank_size; + uint32_t tensix_harvesting_mask; private: void create_coordinate_manager( diff --git a/device/blackhole/blackhole_coordinate_manager.cpp b/device/blackhole/blackhole_coordinate_manager.cpp index dfed7ba1..c5df522d 100644 --- a/device/blackhole/blackhole_coordinate_manager.cpp +++ b/device/blackhole/blackhole_coordinate_manager.cpp @@ -37,7 +37,6 @@ BlackholeCoordinateManager::BlackholeCoordinateManager( arc_cores, pcie_grid_size, pcie_cores) { - this->shuffle_tensix_harvesting_mask(blackhole::HARVESTING_NOC_LOCATIONS); initialize(); } diff --git a/device/cluster.cpp b/device/cluster.cpp index eccef433..d9c05584 100644 --- a/device/cluster.cpp +++ b/device/cluster.cpp @@ -267,14 +267,13 @@ void Cluster::create_device( bool Cluster::using_harvested_soc_descriptors() { return perform_harvesting_on_sdesc && performed_harvesting; } std::unordered_map Cluster::get_harvesting_masks_for_soc_descriptors() { - if (using_harvested_soc_descriptors()) { - return harvested_rows_per_target; - } - std::unordered_map default_harvesting_masks = {}; - for (const auto chip : all_chip_ids_) { - default_harvesting_masks.insert({chip, 0}); + std::unordered_map harvesting_masks = {}; + for (const auto& [chip_id, chip] : chips_) { + uint32_t noc0_harvesting_mask = CoordinateManager::shuffle_tensix_harvesting_mask_to_noc0_coords( + chip->get_soc_descriptor().arch, chip->get_soc_descriptor().tensix_harvesting_mask); + harvesting_masks.insert({chip_id, noc0_harvesting_mask}); } - return default_harvesting_masks; + return harvesting_masks; } void Cluster::construct_cluster( @@ -488,7 +487,9 @@ uint32_t Cluster::get_tensix_harvesting_mask( log_info(LogSiliconDriver, "Skipping harvesting for chip {}.", chip_id); return 0; } - uint32_t tensix_harvesting_mask = cluster_desc->get_harvesting_info().at(chip_id); + uint32_t tensix_harvesting_mask_physical_layout = cluster_desc->get_harvesting_info().at(chip_id); + uint32_t tensix_harvesting_mask = CoordinateManager::shuffle_tensix_harvesting_mask( + cluster_desc->get_arch(chip_id), tensix_harvesting_mask_physical_layout); uint32_t simulated_harvesting_mask = (simulated_harvesting_masks.find(chip_id) != simulated_harvesting_masks.end()) ? simulated_harvesting_masks.at(chip_id) : 0; diff --git a/device/coordinate_manager.cpp b/device/coordinate_manager.cpp index 15ee5d04..e024402f 100644 --- a/device/coordinate_manager.cpp +++ b/device/coordinate_manager.cpp @@ -294,24 +294,46 @@ size_t CoordinateManager::get_tensix_harvesting_mask() const { return physical_l size_t CoordinateManager::get_dram_harvesting_mask() const { return dram_harvesting_mask; } -void CoordinateManager::shuffle_tensix_harvesting_mask(const std::vector& harvesting_locations) { +uint32_t CoordinateManager::shuffle_tensix_harvesting_mask(tt::ARCH arch, uint32_t tensix_harvesting_physical_layout) { + std::vector harvesting_locations = + tt::umd::architecture_implementation::create(arch)->get_harvesting_noc_locations(); + std::vector sorted_harvesting_locations = harvesting_locations; std::sort(sorted_harvesting_locations.begin(), sorted_harvesting_locations.end()); size_t new_harvesting_mask = 0; uint32_t pos = 0; - while (tensix_harvesting_mask > 0) { - if (tensix_harvesting_mask & 1) { + while (tensix_harvesting_physical_layout > 0) { + if (tensix_harvesting_physical_layout & 1) { uint32_t sorted_position = std::find( sorted_harvesting_locations.begin(), sorted_harvesting_locations.end(), harvesting_locations[pos]) - sorted_harvesting_locations.begin(); new_harvesting_mask |= (1 << sorted_position); } - tensix_harvesting_mask >>= 1; + tensix_harvesting_physical_layout >>= 1; + pos++; + } + + return new_harvesting_mask; +} + +uint32_t CoordinateManager::shuffle_tensix_harvesting_mask_to_noc0_coords( + tt::ARCH arch, uint32_t tensix_harvesting_logical_layout) { + std::vector sorted_harvesting_locations = + tt::umd::architecture_implementation::create(arch)->get_harvesting_noc_locations(); + + std::sort(sorted_harvesting_locations.begin(), sorted_harvesting_locations.end()); + size_t new_harvesting_mask = 0; + uint32_t pos = 0; + while (tensix_harvesting_logical_layout > 0) { + if (tensix_harvesting_logical_layout & 1) { + new_harvesting_mask |= (1 << sorted_harvesting_locations[pos]); + } + tensix_harvesting_logical_layout >>= 1; pos++; } - tensix_harvesting_mask = new_harvesting_mask; + return new_harvesting_mask; } const std::vector& CoordinateManager::get_physical_pairs(const CoreType core_type) const { diff --git a/device/grayskull/grayskull_coordinate_manager.cpp b/device/grayskull/grayskull_coordinate_manager.cpp index a97e0ffb..f8bfd389 100644 --- a/device/grayskull/grayskull_coordinate_manager.cpp +++ b/device/grayskull/grayskull_coordinate_manager.cpp @@ -35,7 +35,6 @@ GrayskullCoordinateManager::GrayskullCoordinateManager( arc_cores, pcie_grid_size, pcie_cores) { - this->shuffle_tensix_harvesting_mask(grayskull::HARVESTING_NOC_LOCATIONS); initialize(); } diff --git a/device/tt_soc_descriptor.cpp b/device/tt_soc_descriptor.cpp index b8e61088..64048682 100644 --- a/device/tt_soc_descriptor.cpp +++ b/device/tt_soc_descriptor.cpp @@ -222,7 +222,8 @@ tt_SocDescriptor::tt_SocDescriptor( std::string device_descriptor_path, const size_t tensix_harvesting_mask, const size_t dram_harvesting_mask, - const size_t eth_harvesting_mask) { + const size_t eth_harvesting_mask) : + tensix_harvesting_mask(tensix_harvesting_mask) { std::ifstream fdesc(device_descriptor_path); if (fdesc.fail()) { throw std::runtime_error( diff --git a/device/wormhole/wormhole_coordinate_manager.cpp b/device/wormhole/wormhole_coordinate_manager.cpp index 872532c0..e13e14cd 100644 --- a/device/wormhole/wormhole_coordinate_manager.cpp +++ b/device/wormhole/wormhole_coordinate_manager.cpp @@ -35,7 +35,6 @@ WormholeCoordinateManager::WormholeCoordinateManager( arc_cores, pcie_grid_size, pcie_cores) { - this->shuffle_tensix_harvesting_mask(wormhole::HARVESTING_NOC_LOCATIONS); initialize(); } diff --git a/tests/api/test_core_coord_translation_bh.cpp b/tests/api/test_core_coord_translation_bh.cpp index 9704b8d5..a8a94b2a 100644 --- a/tests/api/test_core_coord_translation_bh.cpp +++ b/tests/api/test_core_coord_translation_bh.cpp @@ -35,7 +35,7 @@ TEST(CoordinateManager, CoordinateManagerBlackholeNoHarvesting) { // the logical coordinates if the first row is harvested. TEST(CoordinateManager, CoordinateManagerBlackholeTopLeftCore) { // This is targeting first row of Tensix cores on NOC layout. - const size_t harvesting_mask = (1 << tt::umd::blackhole::LOGICAL_HARVESTING_LAYOUT[0]); + const size_t harvesting_mask = (1 << 0); std::shared_ptr coordinate_manager = CoordinateManager::create_coordinate_manager(tt::ARCH::BLACKHOLE, harvesting_mask); tt_xy_pair tensix_grid_size = tt::umd::blackhole::TENSIX_GRID_SIZE; @@ -208,8 +208,7 @@ TEST(CoordinateManager, CoordinateManagerBlackholeVirtualEqualTranslated) { // Test mapping of the coordinates for harvested DRAM bank. TEST(CoordinateManager, CoordinateManagerBlackholeTransltedMappingHarvested) { - const size_t harvesting_mask = (1 << tt::umd::blackhole::LOGICAL_HARVESTING_LAYOUT[0]) | - (1 << tt::umd::blackhole::LOGICAL_HARVESTING_LAYOUT[1]); + const size_t harvesting_mask = (1 << 0) | (1 << 1); std::shared_ptr coordinate_manager = CoordinateManager::create_coordinate_manager(tt::ARCH::BLACKHOLE, harvesting_mask); @@ -621,3 +620,14 @@ TEST(CoordinateManager, CoordinateManagerBlackholePhysicalLayoutTensixHarvesting EXPECT_EQ(coordinate_manager->get_tensix_harvesting_mask(), harvesting_mask); } } + +// Test whether we properly shuffle the harvesting mask based on the physical layout of the chip. +TEST(CoordinateManager, CoordinateManagerBlackholeHarvestingShuffle) { + for (size_t i = 0; i < tt::umd::blackhole::LOGICAL_HARVESTING_LAYOUT.size(); i++) { + const size_t harvesting_mask_physical_layout = (1 << tt::umd::blackhole::LOGICAL_HARVESTING_LAYOUT[i]); + const size_t harvesting_mask = + CoordinateManager::shuffle_tensix_harvesting_mask(tt::ARCH::BLACKHOLE, harvesting_mask_physical_layout); + + EXPECT_EQ(harvesting_mask, 1 << i); + } +} diff --git a/tests/api/test_core_coord_translation_gs.cpp b/tests/api/test_core_coord_translation_gs.cpp index 161d0ae9..bd1b23df 100644 --- a/tests/api/test_core_coord_translation_gs.cpp +++ b/tests/api/test_core_coord_translation_gs.cpp @@ -53,7 +53,7 @@ TEST(CoordinateManager, CoordinateManagerGrayskullTopLeftCore) { // the logical coordinates if the first row is harvested. TEST(CoordinateManager, CoordinateManagerGrayskullTopLeftCoreHarvesting) { // This is targeting first row of Tensix cores on NOC layout. - const size_t harvesting_mask = (1 << tt::umd::grayskull::LOGICAL_HARVESTING_LAYOUT[0]); + const size_t harvesting_mask = (1 << 0); std::shared_ptr coordinate_manager = CoordinateManager::create_coordinate_manager(tt::ARCH::GRAYSKULL, harvesting_mask); @@ -181,8 +181,7 @@ TEST(CoordinateManager, CoordinateManagerGrayskullLogicalVirtualMapping) { // Test that harvested physical coordinates map to the last row of the virtual coordinates. TEST(CoordinateManager, CoordinateManagerGrayskullPhysicalHarvestedMapping) { // Harvest first and second NOC layout row. - const size_t harvesting_mask = (1 << tt::umd::grayskull::LOGICAL_HARVESTING_LAYOUT[0]) | - (1 << tt::umd::grayskull::LOGICAL_HARVESTING_LAYOUT[1]); + const size_t harvesting_mask = (1 << 0) | (1 << 1); const size_t num_harvested = CoordinateManager::get_num_harvested(harvesting_mask); std::shared_ptr coordinate_manager = CoordinateManager::create_coordinate_manager(tt::ARCH::GRAYSKULL, harvesting_mask); @@ -207,8 +206,7 @@ TEST(CoordinateManager, CoordinateManagerGrayskullPhysicalHarvestedMapping) { // 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 = (1 << tt::umd::grayskull::LOGICAL_HARVESTING_LAYOUT[0]) | - (1 << tt::umd::grayskull::LOGICAL_HARVESTING_LAYOUT[1]); + const size_t harvesting_mask = (1 << 0) | (1 << 1); const size_t num_harvested = CoordinateManager::get_num_harvested(harvesting_mask); std::shared_ptr coordinate_manager = CoordinateManager::create_coordinate_manager(tt::ARCH::GRAYSKULL, harvesting_mask); @@ -325,3 +323,14 @@ TEST(CoordinateManager, CoordinateManagerGrayskullPhysicalLayoutTensixHarvesting EXPECT_EQ(coordinate_manager->get_tensix_harvesting_mask(), harvesting_mask); } } + +// Test whether we properly shuffle the harvesting mask based on the physical layout of the chip. +TEST(CoordinateManager, CoordinateManagerGrayskullHarvestingShuffle) { + for (size_t i = 0; i < tt::umd::grayskull::LOGICAL_HARVESTING_LAYOUT.size(); i++) { + const size_t harvesting_mask_physical_layout = (1 << tt::umd::grayskull::LOGICAL_HARVESTING_LAYOUT[i]); + const size_t harvesting_mask = + CoordinateManager::shuffle_tensix_harvesting_mask(tt::ARCH::GRAYSKULL, harvesting_mask_physical_layout); + + EXPECT_EQ(harvesting_mask, 1 << i); + } +} diff --git a/tests/api/test_core_coord_translation_wh.cpp b/tests/api/test_core_coord_translation_wh.cpp index 248c5f28..7361afc7 100644 --- a/tests/api/test_core_coord_translation_wh.cpp +++ b/tests/api/test_core_coord_translation_wh.cpp @@ -38,7 +38,7 @@ TEST(CoordinateManager, CoordinateManagerWormholeNoHarvesting) { // the logical coordinates if the first row is harvested. TEST(CoordinateManager, CoordinateManagerWormholeTopLeftCore) { // This harvesting mask if targeting first row in NOC layout. - const size_t harvesting_mask = (1 << tt::umd::wormhole::LOGICAL_HARVESTING_LAYOUT[0]); + const size_t harvesting_mask = (1 << 0); std::shared_ptr coordinate_manager = CoordinateManager::create_coordinate_manager(tt::ARCH::WORMHOLE_B0, harvesting_mask); @@ -179,8 +179,7 @@ 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 = - (1 << tt::umd::wormhole::LOGICAL_HARVESTING_LAYOUT[0]) | (1 << tt::umd::wormhole::LOGICAL_HARVESTING_LAYOUT[1]); + const size_t harvesting_mask = (1 << 0) | (1 << 1); const size_t num_harvested = CoordinateManager::get_num_harvested(harvesting_mask); std::shared_ptr coordinate_manager = CoordinateManager::create_coordinate_manager(tt::ARCH::WORMHOLE_B0, harvesting_mask); @@ -205,8 +204,7 @@ TEST(CoordinateManager, CoordinateManagerWormholePhysicalVirtualHarvestedMapping // 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 = - (1 << tt::umd::wormhole::LOGICAL_HARVESTING_LAYOUT[0]) | (1 << tt::umd::wormhole::LOGICAL_HARVESTING_LAYOUT[1]); + const size_t harvesting_mask = (1 << 0) | (1 << 1); const size_t num_harvested = CoordinateManager::get_num_harvested(harvesting_mask); std::shared_ptr coordinate_manager = CoordinateManager::create_coordinate_manager(tt::ARCH::WORMHOLE_B0, harvesting_mask); @@ -380,3 +378,14 @@ TEST(CoordinateManager, CoordinateManagerWormholePhysicalLayoutTensixHarvestingM EXPECT_EQ(coordinate_manager->get_tensix_harvesting_mask(), harvesting_mask); } } + +// Test whether we properly shuffle the harvesting mask based on the physical layout of the chip. +TEST(CoordinateManager, CoordinateManagerWormholeHarvestingShuffle) { + for (size_t i = 0; i < tt::umd::wormhole::LOGICAL_HARVESTING_LAYOUT.size(); i++) { + const size_t harvesting_mask_physical_layout = (1 << tt::umd::wormhole::LOGICAL_HARVESTING_LAYOUT[i]); + const size_t harvesting_mask = + CoordinateManager::shuffle_tensix_harvesting_mask(tt::ARCH::WORMHOLE_B0, harvesting_mask_physical_layout); + + EXPECT_EQ(harvesting_mask, 1 << i); + } +} diff --git a/tests/api/test_soc_descriptor.cpp b/tests/api/test_soc_descriptor.cpp index aae40ee3..e73fe151 100644 --- a/tests/api/test_soc_descriptor.cpp +++ b/tests/api/test_soc_descriptor.cpp @@ -33,7 +33,7 @@ TEST(SocDescriptor, SocDescriptorGrayskullNoHarvesting) { TEST(SocDescriptor, SocDescriptorGrayskullOneRowHarvesting) { const tt_xy_pair grayskull_tensix_grid_size = tt::umd::grayskull::TENSIX_GRID_SIZE; const std::vector grayskull_tensix_cores = tt::umd::grayskull::TENSIX_CORES; - const size_t harvesting_mask = (1 << tt::umd::grayskull::LOGICAL_HARVESTING_LAYOUT[0]); + const size_t harvesting_mask = (1 << 0); tt_SocDescriptor soc_desc(test_utils::GetAbsPath("tests/soc_descs/grayskull_10x12.yaml"), harvesting_mask); @@ -101,7 +101,7 @@ TEST(SocDescriptor, SocDescriptorWormholeDRAM) { TEST(SocDescriptor, SocDescriptorWormholeOneRowHarvesting) { const tt_xy_pair wormhole_tensix_grid_size = tt::umd::wormhole::TENSIX_GRID_SIZE; const std::vector wormhole_tensix_cores = tt::umd::wormhole::TENSIX_CORES; - const size_t harvesting_mask = (1 << tt::umd::wormhole::LOGICAL_HARVESTING_LAYOUT[0]); + const size_t harvesting_mask = (1 << 0); tt_SocDescriptor soc_desc(test_utils::GetAbsPath("tests/soc_descs/wormhole_b0_8x10.yaml"), harvesting_mask);