diff --git a/device/api/umd/device/blackhole_implementation.h b/device/api/umd/device/blackhole_implementation.h index 77437d66..a408d179 100644 --- a/device/api/umd/device/blackhole_implementation.h +++ b/device/api/umd/device/blackhole_implementation.h @@ -122,7 +122,8 @@ static const std::vector ETH_LOCATIONS = ETH_CORES; // Return to std::array instead of std::vector once we get std::span support in C++20 static const std::vector T6_X_LOCATIONS = {1, 2, 3, 4, 5, 6, 7, 10, 11, 12, 13, 14, 15, 16}; static const std::vector T6_Y_LOCATIONS = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; -static const std::vector HARVESTING_NOC_LOCATIONS = {}; +static const std::vector HARVESTING_NOC_LOCATIONS = {1, 16, 2, 15, 3, 14, 4, 13, 5, 12, 6, 11, 7, 10}; +static const std::vector LOGICAL_HARVESTING_LAYOUT = {0, 2, 4, 6, 8, 10, 12, 13, 11, 9, 7, 5, 3, 1}; static constexpr uint32_t STATIC_TLB_SIZE = 1024 * 1024; // TODO: Copied from wormhole. Need to verify. diff --git a/device/api/umd/device/coordinate_manager.h b/device/api/umd/device/coordinate_manager.h index 4e44ae71..f609cb94 100644 --- a/device/api/umd/device/coordinate_manager.h +++ b/device/api/umd/device/coordinate_manager.h @@ -44,11 +44,22 @@ class CoordinateManager { virtual ~CoordinateManager() = default; + size_t get_tensix_harvesting_mask() const; + + size_t get_dram_harvesting_mask() const; + private: static void assert_create_coordinate_manager( const tt::ARCH arch, const size_t tensix_harvesting_mask, const size_t dram_harvesting_mask); protected: + /* + * Constructor for Coordinate Manager. + * Tensix harvesting mask is supposed to be passed as original harvesting mask that is + * returned from create-ethernet-map, so each bit is responsible for one row of the actual physical + * row of the tensix cores on the chip. Harvesting mask is shuffled in constructor to match the NOC + * layout of the tensix cores. + */ CoordinateManager( const tt_xy_pair& tensix_grid_size, const std::vector& tensix_cores, @@ -65,6 +76,8 @@ class CoordinateManager { void initialize(); + 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(); @@ -124,6 +137,7 @@ class CoordinateManager { const tt_xy_pair tensix_grid_size; const std::vector& tensix_cores; size_t tensix_harvesting_mask; + const size_t physical_layout_tensix_harvesting_mask; const tt_xy_pair dram_grid_size; const std::vector& dram_cores; diff --git a/device/api/umd/device/grayskull_implementation.h b/device/api/umd/device/grayskull_implementation.h index a3167b71..886e0361 100644 --- a/device/api/umd/device/grayskull_implementation.h +++ b/device/api/umd/device/grayskull_implementation.h @@ -140,6 +140,7 @@ static const std::array ETH_LOCATIONS = {}; static const std::vector T6_X_LOCATIONS = {12, 1, 11, 2, 10, 3, 9, 4, 8, 5, 7, 6}; static const std::vector T6_Y_LOCATIONS = {11, 1, 10, 2, 9, 3, 8, 4, 7, 5}; static const std::vector HARVESTING_NOC_LOCATIONS = {5, 7, 4, 8, 3, 9, 2, 10, 1, 11}; +static const std::vector LOGICAL_HARVESTING_LAYOUT = {8, 6, 4, 2, 0, 1, 3, 5, 7, 9}; static constexpr uint32_t STATIC_TLB_SIZE = 1024 * 1024; diff --git a/device/api/umd/device/wormhole_implementation.h b/device/api/umd/device/wormhole_implementation.h index c80c5450..e882e878 100644 --- a/device/api/umd/device/wormhole_implementation.h +++ b/device/api/umd/device/wormhole_implementation.h @@ -166,6 +166,7 @@ static const std::vector ETH_LOCATIONS = ETH_CORES; static const std::vector T6_X_LOCATIONS = {1, 2, 3, 4, 6, 7, 8, 9}; static const std::vector T6_Y_LOCATIONS = {1, 2, 3, 4, 5, 7, 8, 9, 10, 11}; static const std::vector HARVESTING_NOC_LOCATIONS = {11, 1, 10, 2, 9, 3, 8, 4, 7, 5}; +static const std::vector LOGICAL_HARVESTING_LAYOUT = {1, 3, 5, 7, 9, 8, 6, 4, 2, 0}; static constexpr uint32_t STATIC_TLB_SIZE = 1024 * 1024; diff --git a/device/blackhole/blackhole_coordinate_manager.cpp b/device/blackhole/blackhole_coordinate_manager.cpp index f0bbbccd..7a6f605a 100644 --- a/device/blackhole/blackhole_coordinate_manager.cpp +++ b/device/blackhole/blackhole_coordinate_manager.cpp @@ -33,6 +33,7 @@ BlackholeCoordinateManager::BlackholeCoordinateManager( arc_cores, pcie_grid_size, pcie_cores) { + this->shuffle_tensix_harvesting_mask(blackhole::HARVESTING_NOC_LOCATIONS); initialize(); } diff --git a/device/coordinate_manager.cpp b/device/coordinate_manager.cpp index 595421f3..84ce2a22 100644 --- a/device/coordinate_manager.cpp +++ b/device/coordinate_manager.cpp @@ -28,6 +28,7 @@ CoordinateManager::CoordinateManager( tensix_grid_size(tensix_grid_size), tensix_cores(tensix_cores), tensix_harvesting_mask(tensix_harvesting_mask), + physical_layout_tensix_harvesting_mask(tensix_harvesting_mask), dram_grid_size(dram_grid_size), dram_cores(dram_cores), dram_harvesting_mask(dram_harvesting_mask), @@ -277,6 +278,10 @@ void CoordinateManager::fill_arc_physical_translated_mapping() { } } +size_t CoordinateManager::get_tensix_harvesting_mask() const { return physical_layout_tensix_harvesting_mask; } + +size_t CoordinateManager::get_dram_harvesting_mask() const { return dram_harvesting_mask; } + void CoordinateManager::assert_create_coordinate_manager( const tt::ARCH arch, const size_t tensix_harvesting_mask, const size_t dram_harvesting_mask) { log_assert( @@ -287,6 +292,26 @@ void CoordinateManager::assert_create_coordinate_manager( } } +void CoordinateManager::shuffle_tensix_harvesting_mask(const std::vector& harvesting_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) { + 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; + pos++; + } + + tensix_harvesting_mask = new_harvesting_mask; +} + std::shared_ptr CoordinateManager::create_coordinate_manager( tt::ARCH arch, const size_t tensix_harvesting_mask, const size_t dram_harvesting_mask) { assert_create_coordinate_manager(arch, tensix_harvesting_mask, dram_harvesting_mask); diff --git a/device/grayskull/grayskull_coordinate_manager.cpp b/device/grayskull/grayskull_coordinate_manager.cpp index 2f4eef99..d474601f 100644 --- a/device/grayskull/grayskull_coordinate_manager.cpp +++ b/device/grayskull/grayskull_coordinate_manager.cpp @@ -33,6 +33,7 @@ GrayskullCoordinateManager::GrayskullCoordinateManager( arc_cores, pcie_grid_size, pcie_cores) { + this->shuffle_tensix_harvesting_mask(grayskull::HARVESTING_NOC_LOCATIONS); initialize(); } diff --git a/device/wormhole/wormhole_coordinate_manager.cpp b/device/wormhole/wormhole_coordinate_manager.cpp index 375aaaa1..7873c692 100644 --- a/device/wormhole/wormhole_coordinate_manager.cpp +++ b/device/wormhole/wormhole_coordinate_manager.cpp @@ -33,6 +33,7 @@ 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 e468f590..4a2f63b5 100644 --- a/tests/api/test_core_coord_translation_bh.cpp +++ b/tests/api/test_core_coord_translation_bh.cpp @@ -34,8 +34,10 @@ TEST(CoordinateManager, CoordinateManagerBlackholeNoHarvesting) { // We expect that the top left core will have virtual and physical coordinates (1, 2) and (2, 2) for // 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]); std::shared_ptr coordinate_manager = - CoordinateManager::create_coordinate_manager(tt::ARCH::BLACKHOLE, 1); + CoordinateManager::create_coordinate_manager(tt::ARCH::BLACKHOLE, harvesting_mask); tt_xy_pair tensix_grid_size = tt::umd::blackhole::TENSIX_GRID_SIZE; CoreCoord logical_coords = CoreCoord(0, 0, CoreType::TENSIX, CoordSystem::LOGICAL); @@ -203,7 +205,8 @@ TEST(CoordinateManager, CoordinateManagerBlackholeVirtualEqualTranslated) { // Test mapping of the coordinates for harvested DRAM bank. TEST(CoordinateManager, CoordinateManagerBlackholeTransltedMappingHarvested) { - const size_t harvesting_mask = 3; + const size_t harvesting_mask = (1 << tt::umd::blackhole::LOGICAL_HARVESTING_LAYOUT[0]) | + (1 << tt::umd::blackhole::LOGICAL_HARVESTING_LAYOUT[1]); std::shared_ptr coordinate_manager = CoordinateManager::create_coordinate_manager(tt::ARCH::BLACKHOLE, harvesting_mask); @@ -545,3 +548,15 @@ TEST(CoordinateManager, CoordinateManagerBlackholeETHTranslation) { } } } + +// Test that we properly get harvesting mask that is based on the physical layout of the chip. +TEST(CoordinateManager, CoordinateManagerBlackholePhysicalLayoutTensixHarvestingMask) { + const size_t max_num_harvested_x = 14; + + for (size_t harvesting_mask = 0; harvesting_mask < (1 << max_num_harvested_x); harvesting_mask++) { + std::shared_ptr coordinate_manager = + CoordinateManager::create_coordinate_manager(tt::ARCH::BLACKHOLE, harvesting_mask); + + EXPECT_EQ(coordinate_manager->get_tensix_harvesting_mask(), harvesting_mask); + } +} diff --git a/tests/api/test_core_coord_translation_gs.cpp b/tests/api/test_core_coord_translation_gs.cpp index 1bbe2387..a8b6d2d7 100644 --- a/tests/api/test_core_coord_translation_gs.cpp +++ b/tests/api/test_core_coord_translation_gs.cpp @@ -52,8 +52,10 @@ TEST(CoordinateManager, CoordinateManagerGrayskullTopLeftCore) { // We expect that the top left core will have virtual and physical coordinates (1, 1) and (1, 2) for // 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]); std::shared_ptr coordinate_manager = - CoordinateManager::create_coordinate_manager(tt::ARCH::GRAYSKULL, 1); + CoordinateManager::create_coordinate_manager(tt::ARCH::GRAYSKULL, harvesting_mask); CoreCoord logical_coords = CoreCoord(0, 0, CoreType::TENSIX, CoordSystem::LOGICAL); @@ -175,12 +177,13 @@ TEST(CoordinateManager, CoordinateManagerGrayskullLogicalVirtualMapping) { } // Test that harvested physical coordinates map to the last row of the virtual coordinates. -TEST(CoordinateManager, CoordinateManagerWormholePhysicalGrayskullHarvestedMapping) { +TEST(CoordinateManager, CoordinateManagerGrayskullPhysicalHarvestedMapping) { // Harvest first and second NOC layout row. - const size_t harvesting_mask = 3; + const size_t harvesting_mask = (1 << tt::umd::grayskull::LOGICAL_HARVESTING_LAYOUT[0]) | + (1 << tt::umd::grayskull::LOGICAL_HARVESTING_LAYOUT[1]); const size_t num_harvested = CoordinateManager::get_num_harvested(harvesting_mask); std::shared_ptr coordinate_manager = - CoordinateManager::create_coordinate_manager(tt::ARCH::GRAYSKULL, 3); + CoordinateManager::create_coordinate_manager(tt::ARCH::GRAYSKULL, harvesting_mask); const std::vector tensix_cores = tt::umd::grayskull::TENSIX_CORES; const tt_xy_pair tensix_grid_size = tt::umd::grayskull::TENSIX_GRID_SIZE; @@ -202,10 +205,11 @@ TEST(CoordinateManager, CoordinateManagerWormholePhysicalGrayskullHarvestedMappi // 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 harvesting_mask = (1 << tt::umd::grayskull::LOGICAL_HARVESTING_LAYOUT[0]) | + (1 << tt::umd::grayskull::LOGICAL_HARVESTING_LAYOUT[1]); const size_t num_harvested = CoordinateManager::get_num_harvested(harvesting_mask); std::shared_ptr coordinate_manager = - CoordinateManager::create_coordinate_manager(tt::ARCH::GRAYSKULL, 3); + CoordinateManager::create_coordinate_manager(tt::ARCH::GRAYSKULL, harvesting_mask); const std::vector tensix_cores = tt::umd::grayskull::TENSIX_CORES; const tt_xy_pair tensix_grid_size = tt::umd::grayskull::TENSIX_GRID_SIZE; @@ -298,3 +302,15 @@ TEST(CoordinateManager, CoordinateManagerGrayskullARCTranslation) { TEST(CoordinateManager, CoordinateManagerGrayskullDRAMHarvestingAssert) { EXPECT_THROW(CoordinateManager::create_coordinate_manager(tt::ARCH::GRAYSKULL, 0, 1), std::runtime_error); } + +// Test that we properly get harvesting mask that is based on the physical layout of the chip. +TEST(CoordinateManager, CoordinateManagerGrayskullPhysicalLayoutTensixHarvestingMask) { + const size_t max_num_harvested_y = 10; + + for (size_t harvesting_mask = 0; harvesting_mask < (1 << max_num_harvested_y); harvesting_mask++) { + std::shared_ptr coordinate_manager = + CoordinateManager::create_coordinate_manager(tt::ARCH::GRAYSKULL, harvesting_mask); + + EXPECT_EQ(coordinate_manager->get_tensix_harvesting_mask(), harvesting_mask); + } +} diff --git a/tests/api/test_core_coord_translation_wh.cpp b/tests/api/test_core_coord_translation_wh.cpp index 019d220b..933499b4 100644 --- a/tests/api/test_core_coord_translation_wh.cpp +++ b/tests/api/test_core_coord_translation_wh.cpp @@ -37,7 +37,8 @@ TEST(CoordinateManager, CoordinateManagerWormholeNoHarvesting) { // We expect that the top left core will have virtual and physical coordinates (1, 1) and (1, 2) for // the logical coordinates if the first row is harvested. TEST(CoordinateManager, CoordinateManagerWormholeTopLeftCore) { - const size_t harvesting_mask = 1; + // This harvesting mask if targeting first row in NOC layout. + const size_t harvesting_mask = (1 << tt::umd::wormhole::LOGICAL_HARVESTING_LAYOUT[0]); std::shared_ptr coordinate_manager = CoordinateManager::create_coordinate_manager(tt::ARCH::WORMHOLE_B0, harvesting_mask); @@ -174,10 +175,11 @@ 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 harvesting_mask = + (1 << tt::umd::wormhole::LOGICAL_HARVESTING_LAYOUT[0]) | (1 << tt::umd::wormhole::LOGICAL_HARVESTING_LAYOUT[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, 3); + CoordinateManager::create_coordinate_manager(tt::ARCH::WORMHOLE_B0, harvesting_mask); const std::vector tensix_cores = tt::umd::wormhole::TENSIX_CORES; const tt_xy_pair tensix_grid_size = tt::umd::wormhole::TENSIX_GRID_SIZE; @@ -199,10 +201,11 @@ 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 = 3; + const size_t harvesting_mask = + (1 << tt::umd::wormhole::LOGICAL_HARVESTING_LAYOUT[0]) | (1 << tt::umd::wormhole::LOGICAL_HARVESTING_LAYOUT[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, 3); + CoordinateManager::create_coordinate_manager(tt::ARCH::WORMHOLE_B0, harvesting_mask); const std::vector tensix_cores = tt::umd::wormhole::TENSIX_CORES; const tt_xy_pair tensix_grid_size = tt::umd::wormhole::TENSIX_GRID_SIZE; @@ -351,3 +354,15 @@ TEST(CoordinateManager, CoordinateManagerWormholePCIETranslation) { TEST(CoordinateManager, CoordinateManagerWormholeDRAMHarvestingAssert) { EXPECT_THROW(CoordinateManager::create_coordinate_manager(tt::ARCH::WORMHOLE_B0, 0, 1), std::runtime_error); } + +// Test that we properly get harvesting mask that is based on the physical layout of the chip. +TEST(CoordinateManager, CoordinateManagerWormholePhysicalLayoutTensixHarvestingMask) { + const size_t max_num_harvested_y = 10; + + for (size_t harvesting_mask = 0; harvesting_mask < (1 << max_num_harvested_y); harvesting_mask++) { + std::shared_ptr coordinate_manager = + CoordinateManager::create_coordinate_manager(tt::ARCH::WORMHOLE_B0, harvesting_mask); + + EXPECT_EQ(coordinate_manager->get_tensix_harvesting_mask(), harvesting_mask); + } +}