From a508dac02f47c2716a68aacf70785870b96811dc Mon Sep 17 00:00:00 2001 From: pjanevski Date: Thu, 24 Oct 2024 12:56:07 +0000 Subject: [PATCH] Add more grayskull tests --- device/tt_soc_descriptor.h | 4 +- tests/api/test_soc_descriptor_gs.cpp | 69 ++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 1 deletion(-) diff --git a/device/tt_soc_descriptor.h b/device/tt_soc_descriptor.h index 5834647e..9faf8abd 100644 --- a/device/tt_soc_descriptor.h +++ b/device/tt_soc_descriptor.h @@ -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); diff --git a/tests/api/test_soc_descriptor_gs.cpp b/tests/api/test_soc_descriptor_gs.cpp index 56c10a54..b122ce56 100644 --- a/tests/api/test_soc_descriptor_gs.cpp +++ b/tests/api/test_soc_descriptor_gs.cpp @@ -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 logical_to_physical; + std::set 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 logical_to_virtual; + std::set 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); + } +}