Skip to content

Commit

Permalink
Harvesting mask shuffle
Browse files Browse the repository at this point in the history
  • Loading branch information
pjanevskiTT committed Dec 4, 2024
1 parent 1d8c9dd commit 1f3a409
Show file tree
Hide file tree
Showing 11 changed files with 314 additions and 232 deletions.
2 changes: 2 additions & 0 deletions device/api/umd/device/blackhole_coordinate_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class BlackholeCoordinateManager : public CoordinateManager {
const std::vector<tt_xy_pair>& pcie_cores);

protected:
void shuffle_tensix_harvesting_mask() override;

void translate_dram_coords() override;
void translate_tensix_coords() override;

Expand Down
2 changes: 1 addition & 1 deletion device/api/umd/device/blackhole_implementation.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ 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 constexpr uint32_t STATIC_TLB_SIZE = 1024 * 1024; // TODO: Copied from wormhole. Need to verify.

Expand Down
2 changes: 2 additions & 0 deletions device/api/umd/device/coordinate_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ class CoordinateManager {
const tt::ARCH arch, const size_t tensix_harvesting_mask, const size_t dram_harvesting_mask);

protected:
virtual void shuffle_tensix_harvesting_mask() = 0;

virtual void translate_tensix_coords();
virtual void translate_dram_coords();
virtual void translate_eth_coords();
Expand Down
2 changes: 2 additions & 0 deletions device/api/umd/device/grayskull_coordinate_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,7 @@ class GrayskullCoordinateManager : public CoordinateManager {
const std::vector<tt_xy_pair>& pcie_cores);

protected:
void shuffle_tensix_harvesting_mask() override;

void fill_eth_logical_to_translated() override;
};
2 changes: 2 additions & 0 deletions device/api/umd/device/wormhole_coordinate_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class WormholeCoordinateManager : public CoordinateManager {
const std::vector<tt_xy_pair>& pcie_cores);

protected:
void shuffle_tensix_harvesting_mask() override;

void fill_tensix_logical_to_translated() override;
void fill_eth_logical_to_translated() override;
};
22 changes: 22 additions & 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();
this->translate_tensix_coords();
this->translate_dram_coords();
this->translate_eth_coords();
Expand Down Expand Up @@ -185,3 +186,24 @@ void BlackholeCoordinateManager::fill_dram_logical_to_translated() {
blackhole::dram_translated_coordinate_start_x + 1);
}
}

void BlackholeCoordinateManager::shuffle_tensix_harvesting_mask() {
std::vector<uint32_t> harvesting_locations = blackhole::HARVESTING_NOC_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;
}
22 changes: 22 additions & 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();
this->translate_tensix_coords();
this->translate_dram_coords();
this->translate_eth_coords();
Expand All @@ -53,3 +54,24 @@ void GrayskullCoordinateManager::fill_eth_logical_to_translated() {
}
}
}

void GrayskullCoordinateManager::shuffle_tensix_harvesting_mask() {
std::vector<uint32_t> harvesting_locations = grayskull::HARVESTING_NOC_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;
}
22 changes: 22 additions & 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();
this->translate_tensix_coords();
this->translate_dram_coords();
this->translate_eth_coords();
Expand Down Expand Up @@ -67,3 +68,24 @@ void WormholeCoordinateManager::fill_eth_logical_to_translated() {
}
}
}

void WormholeCoordinateManager::shuffle_tensix_harvesting_mask() {
std::vector<uint32_t> harvesting_locations = wormhole::HARVESTING_NOC_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;
}
4 changes: 3 additions & 1 deletion 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 << 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
4 changes: 3 additions & 1 deletion 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 << 8);
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
Loading

0 comments on commit 1f3a409

Please sign in to comment.