Skip to content

Commit

Permalink
Add more grayskull tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pjanevskiTT committed Oct 24, 2024
1 parent 91b895c commit a508dac
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 1 deletion.
4 changes: 3 additions & 1 deletion device/tt_soc_descriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,9 @@ class tt_SocDescriptor {
coordinate_manager(other.coordinate_manager) {
}

// Coordinate converters.
// Coordinate conversions.

// Conversions from logical coordinates should be used just for worker cores.
tt_physical_coords logical_to_physical_coords(tt_logical_coords logical_coords);
tt_virtual_coords logical_to_virtual_coords(tt_logical_coords logical_coords);
tt_translated_coords logical_to_translated_coords(tt_logical_coords logical_coords);
Expand Down
69 changes: 69 additions & 0 deletions tests/api/test_soc_descriptor_gs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,72 @@ TEST(SocDescriptor, SocDescriptorGSTranslatingCoords) {
}
}

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

tt_SocDescriptor soc_desc = tt_SocDescriptor(test_utils::GetAbsPath("tests/soc_descs/grayskull_10x12.yaml"));

std::map<tt_logical_coords, tt_physical_coords> logical_to_physical;
std::set<tt_physical_coords> physical_coords_set;
tt_xy_pair worker_grid_size = soc_desc.worker_grid_size;

for (size_t x = 0; x < worker_grid_size.x; x++) {
for (size_t y = 0; y < worker_grid_size.y; y++) {
tt_logical_coords logical_coords = tt_logical_coords(x, y);
tt_physical_coords physical_coords = soc_desc.logical_to_physical_coords(logical_coords);
logical_to_physical[logical_coords] = physical_coords;

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

EXPECT_EQ(physical_coords_set.size(), worker_grid_size.y * worker_grid_size.x);

for (auto it : logical_to_physical) {
tt_physical_coords physical_coords = it.second;
tt_logical_coords logical_coords = soc_desc.physical_to_logical_coords(physical_coords);

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

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

tt_SocDescriptor soc_desc = tt_SocDescriptor(test_utils::GetAbsPath("tests/soc_descs/grayskull_10x12.yaml"));

std::map<tt_logical_coords, tt_virtual_coords> logical_to_virtual;
std::set<tt_virtual_coords> virtual_coords_set;
tt_xy_pair worker_grid_size = soc_desc.worker_grid_size;

for (size_t x = 0; x < worker_grid_size.x; x++) {
for (size_t y = 0; y < worker_grid_size.y; y++) {
tt_logical_coords logical_coords = tt_logical_coords(x, y);
tt_virtual_coords virtual_coords = soc_desc.logical_to_virtual_coords(logical_coords);
logical_to_virtual[logical_coords] = virtual_coords;

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

EXPECT_EQ(virtual_coords_set.size(), worker_grid_size.y * worker_grid_size.x);

for (auto it : logical_to_virtual) {
tt_virtual_coords virtual_coords = it.second;
tt_logical_coords logical_coords = soc_desc.virtual_to_logical_coords(virtual_coords);

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

0 comments on commit a508dac

Please sign in to comment.