Skip to content

Commit

Permalink
Harvesting mask NOC layout (#369)
Browse files Browse the repository at this point in the history
  • Loading branch information
pjanevskiTT authored Dec 12, 2024
1 parent bf740bd commit f5bf430
Show file tree
Hide file tree
Showing 11 changed files with 105 additions and 14 deletions.
3 changes: 2 additions & 1 deletion device/api/umd/device/blackhole_implementation.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ static const std::vector<tt_xy_pair> 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<uint32_t> T6_X_LOCATIONS = {1, 2, 3, 4, 5, 6, 7, 10, 11, 12, 13, 14, 15, 16};
static const std::vector<uint32_t> T6_Y_LOCATIONS = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
static const std::vector<uint32_t> HARVESTING_NOC_LOCATIONS = {};
static const std::vector<uint32_t> HARVESTING_NOC_LOCATIONS = {1, 16, 2, 15, 3, 14, 4, 13, 5, 12, 6, 11, 7, 10};
static const std::vector<uint32_t> 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.

Expand Down
14 changes: 14 additions & 0 deletions device/api/umd/device/coordinate_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<tt_xy_pair>& tensix_cores,
Expand All @@ -65,6 +76,8 @@ class CoordinateManager {

void initialize();

virtual void shuffle_tensix_harvesting_mask(const std::vector<uint32_t>& harvesting_locations);

virtual void translate_tensix_coords();
virtual void translate_dram_coords();
virtual void translate_eth_coords();
Expand Down Expand Up @@ -124,6 +137,7 @@ class CoordinateManager {
const tt_xy_pair tensix_grid_size;
const std::vector<tt_xy_pair>& 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<tt_xy_pair>& dram_cores;
Expand Down
1 change: 1 addition & 0 deletions device/api/umd/device/grayskull_implementation.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ static const std::array<xy_pair, 0> ETH_LOCATIONS = {};
static const std::vector<uint32_t> T6_X_LOCATIONS = {12, 1, 11, 2, 10, 3, 9, 4, 8, 5, 7, 6};
static const std::vector<uint32_t> T6_Y_LOCATIONS = {11, 1, 10, 2, 9, 3, 8, 4, 7, 5};
static const std::vector<uint32_t> HARVESTING_NOC_LOCATIONS = {5, 7, 4, 8, 3, 9, 2, 10, 1, 11};
static const std::vector<uint32_t> LOGICAL_HARVESTING_LAYOUT = {8, 6, 4, 2, 0, 1, 3, 5, 7, 9};

static constexpr uint32_t STATIC_TLB_SIZE = 1024 * 1024;

Expand Down
1 change: 1 addition & 0 deletions device/api/umd/device/wormhole_implementation.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ static const std::vector<tt_xy_pair> ETH_LOCATIONS = ETH_CORES;
static const std::vector<uint32_t> T6_X_LOCATIONS = {1, 2, 3, 4, 6, 7, 8, 9};
static const std::vector<uint32_t> T6_Y_LOCATIONS = {1, 2, 3, 4, 5, 7, 8, 9, 10, 11};
static const std::vector<uint32_t> HARVESTING_NOC_LOCATIONS = {11, 1, 10, 2, 9, 3, 8, 4, 7, 5};
static const std::vector<uint32_t> LOGICAL_HARVESTING_LAYOUT = {1, 3, 5, 7, 9, 8, 6, 4, 2, 0};

static constexpr uint32_t STATIC_TLB_SIZE = 1024 * 1024;

Expand Down
1 change: 1 addition & 0 deletions device/blackhole/blackhole_coordinate_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ BlackholeCoordinateManager::BlackholeCoordinateManager(
arc_cores,
pcie_grid_size,
pcie_cores) {
this->shuffle_tensix_harvesting_mask(blackhole::HARVESTING_NOC_LOCATIONS);
initialize();
}

Expand Down
25 changes: 25 additions & 0 deletions device/coordinate_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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(
Expand All @@ -287,6 +292,26 @@ void CoordinateManager::assert_create_coordinate_manager(
}
}

void CoordinateManager::shuffle_tensix_harvesting_mask(const std::vector<uint32_t>& harvesting_locations) {
std::vector<uint32_t> 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> 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);
Expand Down
1 change: 1 addition & 0 deletions device/grayskull/grayskull_coordinate_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ GrayskullCoordinateManager::GrayskullCoordinateManager(
arc_cores,
pcie_grid_size,
pcie_cores) {
this->shuffle_tensix_harvesting_mask(grayskull::HARVESTING_NOC_LOCATIONS);
initialize();
}

Expand Down
1 change: 1 addition & 0 deletions device/wormhole/wormhole_coordinate_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ WormholeCoordinateManager::WormholeCoordinateManager(
arc_cores,
pcie_grid_size,
pcie_cores) {
this->shuffle_tensix_harvesting_mask(wormhole::HARVESTING_NOC_LOCATIONS);
initialize();
}

Expand Down
19 changes: 17 additions & 2 deletions tests/api/test_core_coord_translation_bh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<CoordinateManager> 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);
Expand Down Expand Up @@ -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<CoordinateManager> coordinate_manager =
CoordinateManager::create_coordinate_manager(tt::ARCH::BLACKHOLE, harvesting_mask);

Expand Down Expand Up @@ -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<CoordinateManager> coordinate_manager =
CoordinateManager::create_coordinate_manager(tt::ARCH::BLACKHOLE, harvesting_mask);

EXPECT_EQ(coordinate_manager->get_tensix_harvesting_mask(), harvesting_mask);
}
}
28 changes: 22 additions & 6 deletions tests/api/test_core_coord_translation_gs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<CoordinateManager> 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);

Expand Down Expand Up @@ -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<CoordinateManager> coordinate_manager =
CoordinateManager::create_coordinate_manager(tt::ARCH::GRAYSKULL, 3);
CoordinateManager::create_coordinate_manager(tt::ARCH::GRAYSKULL, harvesting_mask);

const std::vector<tt_xy_pair> tensix_cores = tt::umd::grayskull::TENSIX_CORES;
const tt_xy_pair tensix_grid_size = tt::umd::grayskull::TENSIX_GRID_SIZE;
Expand All @@ -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<CoordinateManager> coordinate_manager =
CoordinateManager::create_coordinate_manager(tt::ARCH::GRAYSKULL, 3);
CoordinateManager::create_coordinate_manager(tt::ARCH::GRAYSKULL, harvesting_mask);

const std::vector<tt_xy_pair> tensix_cores = tt::umd::grayskull::TENSIX_CORES;
const tt_xy_pair tensix_grid_size = tt::umd::grayskull::TENSIX_GRID_SIZE;
Expand Down Expand Up @@ -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<CoordinateManager> coordinate_manager =
CoordinateManager::create_coordinate_manager(tt::ARCH::GRAYSKULL, harvesting_mask);

EXPECT_EQ(coordinate_manager->get_tensix_harvesting_mask(), harvesting_mask);
}
}
25 changes: 20 additions & 5 deletions tests/api/test_core_coord_translation_wh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<CoordinateManager> coordinate_manager =
CoordinateManager::create_coordinate_manager(tt::ARCH::WORMHOLE_B0, harvesting_mask);
Expand Down Expand Up @@ -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<CoordinateManager> coordinate_manager =
CoordinateManager::create_coordinate_manager(tt::ARCH::WORMHOLE_B0, 3);
CoordinateManager::create_coordinate_manager(tt::ARCH::WORMHOLE_B0, harvesting_mask);

const std::vector<tt_xy_pair> tensix_cores = tt::umd::wormhole::TENSIX_CORES;
const tt_xy_pair tensix_grid_size = tt::umd::wormhole::TENSIX_GRID_SIZE;
Expand All @@ -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<CoordinateManager> coordinate_manager =
CoordinateManager::create_coordinate_manager(tt::ARCH::WORMHOLE_B0, 3);
CoordinateManager::create_coordinate_manager(tt::ARCH::WORMHOLE_B0, harvesting_mask);

const std::vector<tt_xy_pair> tensix_cores = tt::umd::wormhole::TENSIX_CORES;
const tt_xy_pair tensix_grid_size = tt::umd::wormhole::TENSIX_GRID_SIZE;
Expand Down Expand Up @@ -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<CoordinateManager> coordinate_manager =
CoordinateManager::create_coordinate_manager(tt::ARCH::WORMHOLE_B0, harvesting_mask);

EXPECT_EQ(coordinate_manager->get_tensix_harvesting_mask(), harvesting_mask);
}
}

0 comments on commit f5bf430

Please sign in to comment.