Skip to content

Commit

Permalink
BH to translated coords and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pjanevskiTT committed Oct 29, 2024
1 parent d753f79 commit af5bf0e
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 0 deletions.
10 changes: 10 additions & 0 deletions device/blackhole/blackhole_coordinate_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,13 @@ std::set<std::size_t> BlackholeCoordinateManager::get_x_coordinates_to_harvest(s
}
return x_to_harvest;
}

tt_translated_coords BlackholeCoordinateManager::to_translated_coords(tt_logical_coords logical_coords) {
tt_virtual_coords virtual_coords = to_virtual_coords(logical_coords);
return tt_translated_coords(virtual_coords.x, virtual_coords.y);
}

tt_logical_coords BlackholeCoordinateManager::to_logical_coords(tt_translated_coords translated_coords) {
tt_virtual_coords virtual_coords = tt_virtual_coords(translated_coords.x, translated_coords.y);
return CoordinateManager::to_logical_coords(virtual_coords);
}
4 changes: 4 additions & 0 deletions device/blackhole/blackhole_coordinate_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ class BlackholeCoordinateManager : public CoordinateManager {
BlackholeCoordinateManager(const tt_xy_pair& worker_grid_size, const std::vector<tt_xy_pair>& workers, std::size_t harvesting_mask)
: CoordinateManager(worker_grid_size, workers, harvesting_mask) {}

tt_translated_coords to_translated_coords(tt_logical_coords logical_coords) override;

tt_logical_coords to_logical_coords(tt_translated_coords translated_coords) override;

protected:
std::set<std::size_t> get_x_coordinates_to_harvest(std::size_t harvesting_mask) override;
};
65 changes: 65 additions & 0 deletions tests/api/test_soc_descriptor_bh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,68 @@ TEST(SocDescriptor, SocDescriptorBHLogicalVirtualMapping) {
}
}
}

// Test logical to translated coordinate translation.
// For the full grid of logical coordinates we expect that there are no duplicates of translated coordinates.
// For the reverse mapping back of translated to logical coordinates we expect that same logical coordinates are returned as from original mapping.
TEST(SocDescriptor, SocDescriptorBHLogicalTranslatedMapping) {

const std::size_t max_num_harvested_x = 14;
tt_SocDescriptor soc_desc = tt_SocDescriptor(test_utils::GetAbsPath("tests/soc_descs/blackhole_140_arch.yaml"));
for (std::size_t harvesting_mask = 0; harvesting_mask < (1 << max_num_harvested_x); harvesting_mask++) {

soc_desc.perform_harvesting(harvesting_mask);

std::map<tt_logical_coords, tt_translated_coords> logical_to_translated;
std::set<tt_translated_coords> translated_coords_set;
tt_xy_pair worker_grid_size = soc_desc.worker_grid_size;

std::size_t num_harvested_x = test_utils::get_num_harvested(harvesting_mask);

for (size_t x = 0; x < worker_grid_size.x - num_harvested_x; x++) {
for (size_t y = 0; y < worker_grid_size.y; y++) {
tt_logical_coords logical_coords = tt_logical_coords(x, y);
tt_translated_coords translated_coords = soc_desc.to_translated_coords(logical_coords);
logical_to_translated[logical_coords] = translated_coords;

// Expect that logical to translated translation is 1-1 mapping. No duplicates for translated coordinates.
EXPECT_EQ(translated_coords_set.count(translated_coords), 0);
translated_coords_set.insert(translated_coords);
}
}

EXPECT_EQ(translated_coords_set.size(), worker_grid_size.y * (worker_grid_size.x - num_harvested_x));

for (auto it : logical_to_translated) {
tt_translated_coords translated_coords = it.second;
tt_logical_coords logical_coords = soc_desc.to_logical_coords(translated_coords);

// Expect that reverse mapping of translated coordinates gives the same logical coordinates
// using which we got the translated coordinates.
EXPECT_EQ(it.first, logical_coords);
}
}
}

// Test that virtual and translated coordinates are same for all logical coordinates.
// This is expected for Blackhole way of harvesting.
TEST(SocDescriptor, SocDescriptorBHVirtualEqualTranslated) {
const std::size_t max_num_harvested_x = 14;
tt_SocDescriptor soc_desc = tt_SocDescriptor(test_utils::GetAbsPath("tests/soc_descs/blackhole_140_arch.yaml"));
for (std::size_t harvesting_mask = 0; harvesting_mask < (1 << max_num_harvested_x); harvesting_mask++) {
soc_desc.perform_harvesting(harvesting_mask);

std::size_t num_harvested_x = test_utils::get_num_harvested(harvesting_mask);

for (std::size_t x = 0; x < soc_desc.worker_grid_size.x - num_harvested_x; x++) {
for (std::size_t y = 0; y < soc_desc.worker_grid_size.y; y++) {
tt_logical_coords logical_coords = tt_logical_coords(x, y);
tt_translated_coords translated_coords = soc_desc.to_translated_coords(logical_coords);
tt_virtual_coords virtual_coords = soc_desc.to_virtual_coords(logical_coords);

// Expect that translated coordinates are same as virtual coordinates.
EXPECT_EQ(translated_coords, virtual_coords);
}
}
}
}

0 comments on commit af5bf0e

Please sign in to comment.