Skip to content

Commit

Permalink
move harvesting to be logical on coordinatemanager api
Browse files Browse the repository at this point in the history
  • Loading branch information
broskoTT committed Dec 27, 2024
1 parent ef3b11e commit 7eaa2f2
Show file tree
Hide file tree
Showing 12 changed files with 89 additions and 34 deletions.
9 changes: 7 additions & 2 deletions device/api/umd/device/coordinate_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ class CoordinateManager {

static std::vector<size_t> 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);
Expand Down Expand Up @@ -91,8 +98,6 @@ class CoordinateManager {

virtual void assert_coordinate_manager_constructor();

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
1 change: 1 addition & 0 deletions device/api/umd/device/tt_soc_descriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
1 change: 0 additions & 1 deletion device/blackhole/blackhole_coordinate_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ BlackholeCoordinateManager::BlackholeCoordinateManager(
arc_cores,
pcie_grid_size,
pcie_cores) {
this->shuffle_tensix_harvesting_mask(blackhole::HARVESTING_NOC_LOCATIONS);
initialize();
}

Expand Down
17 changes: 9 additions & 8 deletions device/cluster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,14 +267,13 @@ void Cluster::create_device(
bool Cluster::using_harvested_soc_descriptors() { return perform_harvesting_on_sdesc && performed_harvesting; }

std::unordered_map<chip_id_t, uint32_t> Cluster::get_harvesting_masks_for_soc_descriptors() {
if (using_harvested_soc_descriptors()) {
return harvested_rows_per_target;
}
std::unordered_map<chip_id_t, uint32_t> default_harvesting_masks = {};
for (const auto chip : all_chip_ids_) {
default_harvesting_masks.insert({chip, 0});
std::unordered_map<chip_id_t, uint32_t> 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(
Expand Down Expand Up @@ -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;
Expand Down
32 changes: 27 additions & 5 deletions device/coordinate_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint32_t>& harvesting_locations) {
uint32_t CoordinateManager::shuffle_tensix_harvesting_mask(tt::ARCH arch, uint32_t tensix_harvesting_physical_layout) {
std::vector<uint32_t> harvesting_locations =
tt::umd::architecture_implementation::create(arch)->get_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) {
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<uint32_t> 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<tt_xy_pair>& CoordinateManager::get_physical_pairs(const CoreType core_type) const {
Expand Down
1 change: 0 additions & 1 deletion device/grayskull/grayskull_coordinate_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ GrayskullCoordinateManager::GrayskullCoordinateManager(
arc_cores,
pcie_grid_size,
pcie_cores) {
this->shuffle_tensix_harvesting_mask(grayskull::HARVESTING_NOC_LOCATIONS);
initialize();
}

Expand Down
3 changes: 2 additions & 1 deletion device/tt_soc_descriptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
1 change: 0 additions & 1 deletion device/wormhole/wormhole_coordinate_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ WormholeCoordinateManager::WormholeCoordinateManager(
arc_cores,
pcie_grid_size,
pcie_cores) {
this->shuffle_tensix_harvesting_mask(wormhole::HARVESTING_NOC_LOCATIONS);
initialize();
}

Expand Down
16 changes: 13 additions & 3 deletions tests/api/test_core_coord_translation_bh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<CoordinateManager> coordinate_manager =
CoordinateManager::create_coordinate_manager(tt::ARCH::BLACKHOLE, harvesting_mask);
tt_xy_pair tensix_grid_size = tt::umd::blackhole::TENSIX_GRID_SIZE;
Expand Down Expand Up @@ -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<CoordinateManager> coordinate_manager =
CoordinateManager::create_coordinate_manager(tt::ARCH::BLACKHOLE, harvesting_mask);

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

Expand Down Expand Up @@ -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<CoordinateManager> coordinate_manager =
CoordinateManager::create_coordinate_manager(tt::ARCH::GRAYSKULL, harvesting_mask);
Expand All @@ -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<CoordinateManager> coordinate_manager =
CoordinateManager::create_coordinate_manager(tt::ARCH::GRAYSKULL, harvesting_mask);
Expand Down Expand Up @@ -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);
}
}
19 changes: 14 additions & 5 deletions tests/api/test_core_coord_translation_wh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<CoordinateManager> coordinate_manager =
CoordinateManager::create_coordinate_manager(tt::ARCH::WORMHOLE_B0, harvesting_mask);
Expand Down Expand Up @@ -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<CoordinateManager> coordinate_manager =
CoordinateManager::create_coordinate_manager(tt::ARCH::WORMHOLE_B0, harvesting_mask);
Expand All @@ -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<CoordinateManager> coordinate_manager =
CoordinateManager::create_coordinate_manager(tt::ARCH::WORMHOLE_B0, harvesting_mask);
Expand Down Expand Up @@ -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);
}
}
4 changes: 2 additions & 2 deletions tests/api/test_soc_descriptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<tt_xy_pair> 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);

Expand Down Expand Up @@ -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<tt_xy_pair> 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);

Expand Down

0 comments on commit 7eaa2f2

Please sign in to comment.