From 950feee947dbc73e6cbd7a41261e04691d748148 Mon Sep 17 00:00:00 2001 From: pjanevski Date: Wed, 23 Oct 2024 16:52:20 +0000 Subject: [PATCH] Grayskull tests and full API - Add grayskull tests for harvesting - Implement API for full coordinate translation to any system - Separate soc desc tests per arch --- device/coordinate_manager.cpp | 43 ++- device/coordinate_manager.h | 11 +- device/tt_soc_descriptor.cpp | 32 +- device/tt_soc_descriptor.h | 15 +- .../wormhole/wormhole_coordinate_manager.cpp | 8 + device/wormhole/wormhole_coordinate_manager.h | 10 +- tests/api/CMakeLists.txt | 14 +- tests/api/test_soc_descriptor.cpp | 305 ------------------ tests/api/test_soc_descriptor_bh.cpp | 143 ++++++++ tests/api/test_soc_descriptor_gs.cpp | 149 +++++++++ tests/api/test_soc_descriptor_wh.cpp | 178 ++++++++++ tests/soc_descs/grayskull_10x12.yaml | 24 +- tests/test_utils/soc_desc_test_utils.hpp | 21 ++ 13 files changed, 613 insertions(+), 340 deletions(-) delete mode 100644 tests/api/test_soc_descriptor.cpp create mode 100644 tests/api/test_soc_descriptor_bh.cpp create mode 100644 tests/api/test_soc_descriptor_gs.cpp create mode 100644 tests/api/test_soc_descriptor_wh.cpp create mode 100644 tests/test_utils/soc_desc_test_utils.hpp diff --git a/device/coordinate_manager.cpp b/device/coordinate_manager.cpp index 2ef3695b..ca12b92b 100644 --- a/device/coordinate_manager.cpp +++ b/device/coordinate_manager.cpp @@ -4,34 +4,57 @@ #include "grayskull/grayskull_coordinate_manager.h" tt_physical_coords CoordinateManager::logical_to_physical_coords(tt_logical_coords logical_coords) { - // log_assert(logical_coords.x < logical_x_to_physical_x.size()); - // log_assert(logical_coords.y < logical_y_to_physical_y.size()); return tt_physical_coords(logical_x_to_physical_x[logical_coords.x], logical_y_to_physical_y[logical_coords.y]); } -// TODO(pjanevski): is it enough just to add 18 to the logical coordinates -// in order to get the translated coordinates? +// TODO(pjanevski): this is different for Wormhole and Blackhole. +// investigate and implement tt_translated_coords CoordinateManager::logical_to_translated_coords(tt_logical_coords logical_coords) { - static const std::size_t translated_offset = 18; - return tt_translated_coords(logical_coords.x + translated_offset, logical_coords.y + translated_offset); + tt_physical_coords physical_coords = logical_to_physical_coords(logical_coords); + return tt_translated_coords(physical_coords.x, physical_coords.y); +} + +tt_virtual_coords CoordinateManager::logical_to_virtual_coords(tt_logical_coords logical_coords) { + return tt_virtual_coords(logical_x_to_virtual_x[logical_coords.x], logical_y_to_virtual_y[logical_coords.y]); } tt_logical_coords CoordinateManager::physical_to_logical_coords(tt_physical_coords physical_coords) { return tt_logical_coords(physical_x_to_logical_x[physical_coords.x], physical_y_to_logical_y[physical_coords.y]); } -tt_translated_coords CoordinateManager::physical_to_translated_coords(tt_physical_coords physical_coords) { - return tt_translated_coords(0, 0); +tt_virtual_coords CoordinateManager::physical_to_virtual_coords(tt_physical_coords physical_coords) { + return logical_to_virtual_coords(physical_to_logical_coords(physical_coords)); } -tt_virtual_coords CoordinateManager::logical_to_virtual_coords(tt_logical_coords logical_coords) { - return tt_virtual_coords(logical_x_to_virtual_x[logical_coords.x], logical_y_to_virtual_y[logical_coords.y]); +tt_translated_coords CoordinateManager::physical_to_translated_coords(tt_physical_coords physical_coords) { + return logical_to_translated_coords(physical_to_logical_coords(physical_coords)); } tt_logical_coords CoordinateManager::virtual_to_logical_coords(tt_virtual_coords virtual_coords) { return tt_logical_coords(virtual_x_to_logical_x[virtual_coords.x], virtual_y_to_logical_y[virtual_coords.y]); } +tt_physical_coords CoordinateManager::virtual_to_physical_coords(tt_virtual_coords virtual_coords) { + return logical_to_physical_coords(virtual_to_logical_coords(virtual_coords)); +} + +tt_translated_coords CoordinateManager::virtual_to_translated_coords(tt_virtual_coords virtual_coords) { + return logical_to_translated_coords(virtual_to_logical_coords(virtual_coords)); +} + +tt_logical_coords CoordinateManager::translated_to_logical_coords(tt_translated_coords translated_coords) { + tt_physical_coords physical_coords = tt_physical_coords(translated_coords.x, translated_coords.y); + return physical_to_logical_coords(physical_coords); +} + +tt_physical_coords CoordinateManager::translated_to_physical_coords(tt_translated_coords translated_coords) { + return logical_to_physical_coords(translated_to_logical_coords(translated_coords)); +} + +tt_virtual_coords CoordinateManager::translated_to_virtual_coords(tt_translated_coords translated_coords) { + return logical_to_virtual_coords(translated_to_logical_coords(translated_coords)); +} + void CoordinateManager::clear_harvesting_structures() { logical_x_to_physical_x.clear(); logical_y_to_physical_y.clear(); diff --git a/device/coordinate_manager.h b/device/coordinate_manager.h index 86b2f1f5..0f24dac5 100644 --- a/device/coordinate_manager.h +++ b/device/coordinate_manager.h @@ -27,10 +27,19 @@ class CoordinateManager { virtual tt_physical_coords logical_to_physical_coords(tt_logical_coords logical_coords); virtual tt_translated_coords logical_to_translated_coords(tt_logical_coords logical_coords); + virtual tt_virtual_coords logical_to_virtual_coords(tt_logical_coords logical_coords); + virtual tt_logical_coords physical_to_logical_coords(tt_physical_coords physical_coords); + virtual tt_virtual_coords physical_to_virtual_coords(tt_physical_coords physical_coords); virtual tt_translated_coords physical_to_translated_coords(tt_physical_coords physical_coords); - virtual tt_virtual_coords logical_to_virtual_coords(tt_logical_coords logical_coords); + virtual tt_logical_coords virtual_to_logical_coords(tt_virtual_coords virtual_coords); + virtual tt_physical_coords virtual_to_physical_coords(tt_virtual_coords virtual_coords); + virtual tt_translated_coords virtual_to_translated_coords(tt_virtual_coords virtual_coords); + + virtual tt_logical_coords translated_to_logical_coords(tt_translated_coords translated_coords); + virtual tt_physical_coords translated_to_physical_coords(tt_translated_coords translated_coords); + virtual tt_virtual_coords translated_to_virtual_coords(tt_translated_coords translated_coords); static CoordinateManager* get_coordinate_manager( tt::ARCH arch, diff --git a/device/tt_soc_descriptor.cpp b/device/tt_soc_descriptor.cpp index b8164ed9..a8b222f8 100644 --- a/device/tt_soc_descriptor.cpp +++ b/device/tt_soc_descriptor.cpp @@ -178,6 +178,10 @@ tt_physical_coords tt_SocDescriptor::logical_to_physical_coords(tt_logical_coord return coordinate_manager->logical_to_physical_coords(logical_coords); } +tt_virtual_coords tt_SocDescriptor::logical_to_virtual_coords(tt_logical_coords logical_coords) { + return coordinate_manager->logical_to_virtual_coords(logical_coords); +} + tt_translated_coords tt_SocDescriptor::logical_to_translated_coords(tt_logical_coords logical_coords) { return coordinate_manager->logical_to_translated_coords(logical_coords); } @@ -186,18 +190,38 @@ tt_logical_coords tt_SocDescriptor::physical_to_logical_coords(tt_physical_coord return coordinate_manager->physical_to_logical_coords(physical_coords); } -tt_translated_coords tt_SocDescriptor::physical_to_translated_coords(tt_physical_coords physical_coords) { - return coordinate_manager->physical_to_translated_coords(physical_coords); +tt_virtual_coords tt_SocDescriptor::physical_to_virtual_coords(tt_physical_coords physical_coords) { + return coordinate_manager->physical_to_virtual_coords(physical_coords); } -tt_virtual_coords tt_SocDescriptor::logical_to_virtual_coords(tt_logical_coords logical_coords) { - return coordinate_manager->logical_to_virtual_coords(logical_coords); +tt_translated_coords tt_SocDescriptor::physical_to_translated_coords(tt_physical_coords physical_coords) { + return coordinate_manager->physical_to_translated_coords(physical_coords); } tt_logical_coords tt_SocDescriptor::virtual_to_logical_coords(tt_virtual_coords virtual_coords) { return coordinate_manager->virtual_to_logical_coords(virtual_coords); } +tt_physical_coords tt_SocDescriptor::virtual_to_physical_coords(tt_virtual_coords virtual_coords) { + return coordinate_manager->virtual_to_physical_coords(virtual_coords); +} + +tt_translated_coords tt_SocDescriptor::virtual_to_translated_coords(tt_virtual_coords virtual_coords) { + return coordinate_manager->virtual_to_translated_coords(virtual_coords); +} + +tt_logical_coords tt_SocDescriptor::translated_to_logical_coords(tt_translated_coords translated_coords) { + return coordinate_manager->translated_to_logical_coords(translated_coords); +} + +tt_physical_coords tt_SocDescriptor::translated_to_physical_coords(tt_translated_coords translated_coords) { + return coordinate_manager->translated_to_physical_coords(translated_coords); +} + +tt_virtual_coords tt_SocDescriptor::translated_to_virtual_coords(tt_translated_coords translated_coords) { + return coordinate_manager->translated_to_virtual_coords(translated_coords); +} + tt_SocDescriptor::tt_SocDescriptor(std::string device_descriptor_path, std::size_t harvesting_mask) { std::ifstream fdesc(device_descriptor_path); if (fdesc.fail()) { diff --git a/device/tt_soc_descriptor.h b/device/tt_soc_descriptor.h index f136111e..9faf8abd 100644 --- a/device/tt_soc_descriptor.h +++ b/device/tt_soc_descriptor.h @@ -171,13 +171,24 @@ 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); + tt_logical_coords physical_to_logical_coords(tt_physical_coords physical_coords); + tt_virtual_coords physical_to_virtual_coords(tt_physical_coords physical_coords); tt_translated_coords physical_to_translated_coords(tt_physical_coords physical_coords); - tt_virtual_coords logical_to_virtual_coords(tt_logical_coords logical_coords); + tt_logical_coords virtual_to_logical_coords(tt_virtual_coords virtual_coords); + tt_physical_coords virtual_to_physical_coords(tt_virtual_coords virtual_coords); + tt_translated_coords virtual_to_translated_coords(tt_virtual_coords virtual_coords); + + tt_logical_coords translated_to_logical_coords(tt_translated_coords translated_coords); + tt_physical_coords translated_to_physical_coords(tt_translated_coords translated_coords); + tt_virtual_coords translated_to_virtual_coords(tt_translated_coords translated_coords); void perform_harvesting(std::size_t harvesting_mask); diff --git a/device/wormhole/wormhole_coordinate_manager.cpp b/device/wormhole/wormhole_coordinate_manager.cpp index 016e3a6b..a1c9ab0e 100644 --- a/device/wormhole/wormhole_coordinate_manager.cpp +++ b/device/wormhole/wormhole_coordinate_manager.cpp @@ -12,3 +12,11 @@ std::set WormholeCoordinateManager::get_y_coordinates_to_harvest(st } return y_to_harvest; } + +tt_translated_coords WormholeCoordinateManager::logical_to_translated_coords(tt_logical_coords logical_coords) { + return tt_translated_coords(logical_coords.x + translated_coordinate_start_x, logical_coords.y + translated_coordinate_start_y); +} + +tt_logical_coords WormholeCoordinateManager::translated_to_logical_coords(tt_translated_coords translated_coords) { + return tt_logical_coords(translated_coords.x - translated_coordinate_start_x, translated_coords.y - translated_coordinate_start_y); +} \ No newline at end of file diff --git a/device/wormhole/wormhole_coordinate_manager.h b/device/wormhole/wormhole_coordinate_manager.h index a9c30b6e..477b5a53 100644 --- a/device/wormhole/wormhole_coordinate_manager.h +++ b/device/wormhole/wormhole_coordinate_manager.h @@ -21,6 +21,14 @@ class WormholeCoordinateManager : public CoordinateManager { WormholeCoordinateManager(const tt_xy_pair& worker_grid_size, const std::vector& workers, std::size_t harvesting_mask) : CoordinateManager(worker_grid_size, workers, harvesting_mask) {} + tt_translated_coords logical_to_translated_coords(tt_logical_coords logical_coords) override; + + tt_logical_coords translated_to_logical_coords(tt_translated_coords translated_coords) override; + protected: std::set get_y_coordinates_to_harvest(std::size_t harvesting_mask) override; -}; \ No newline at end of file + +private: + static const std::size_t translated_coordinate_start_x = 18; + static const std::size_t translated_coordinate_start_y = 18; +}; diff --git a/tests/api/CMakeLists.txt b/tests/api/CMakeLists.txt index 7c51f7f9..1779d3a5 100644 --- a/tests/api/CMakeLists.txt +++ b/tests/api/CMakeLists.txt @@ -1,12 +1,18 @@ set(API_TESTS_SRCS test_cluster.cpp test_cluster_descriptor.cpp - test_soc_descriptor.cpp + test_soc_descriptor_gs.cpp + test_soc_descriptor_wh.cpp + test_soc_descriptor_bh.cpp ) add_executable(api_tests ${API_TESTS_SRCS}) target_link_libraries(api_tests PRIVATE test_common) -set_target_properties(api_tests PROPERTIES - RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/test/umd/api - OUTPUT_NAME api_tests +set_target_properties( + api_tests + PROPERTIES + RUNTIME_OUTPUT_DIRECTORY + ${CMAKE_BINARY_DIR}/test/umd/api + OUTPUT_NAME + api_tests ) diff --git a/tests/api/test_soc_descriptor.cpp b/tests/api/test_soc_descriptor.cpp deleted file mode 100644 index da1768f8..00000000 --- a/tests/api/test_soc_descriptor.cpp +++ /dev/null @@ -1,305 +0,0 @@ -#include -#include -#include - -#include "gtest/gtest.h" -#include "tt_device.h" -#include "eth_l1_address_map.h" -#include "l1_address_map.h" -#include "eth_l1_address_map.h" -#include "eth_interface.h" -#include "host_mem_address_map.h" - -#include "device/tt_cluster_descriptor.h" -#include "device/wormhole/wormhole_implementation.h" -#include "tests/test_utils/generate_cluster_desc.hpp" -#include "tests/test_utils/device_test_utils.hpp" - -// Wormhole workers - x-y annotation -// functional_workers: -// [ -// 1-1, 2-1, 3-1, 4-1, 6-1, 7-1, 8-1, 9-1, -// 1-2, 2-2, 3-2, 4-2, 6-2, 7-2, 8-2, 9-2, -// 1-3, 2-3, 3-3, 4-3, 6-3, 7-3, 8-3, 9-3, -// 1-4, 2-4, 3-4, 4-4, 6-4, 7-4, 8-4, 9-4, -// 1-5, 2-5, 3-5, 4-5, 6-5, 7-5, 8-5, 9-5, -// 1-7, 2-7, 3-7, 4-7, 6-7, 7-7, 8-7, 9-7, -// 1-8, 2-8, 3-8, 4-8, 6-8, 7-8, 8-8, 9-8, -// 1-9, 2-9, 3-9, 4-9, 6-9, 7-9, 8-9, 9-9, -// 1-10, 2-10, 3-10, 4-10, 6-10, 7-10, 8-10, 9-10, -// 1-11, 2-11, 3-11, 4-11, 6-11, 7-11, 8-11, 9-11, -// ] - -// Blackhole workers - x-y annotation -// functional_workers: -// [ -// 1-2, 2-2, 3-2, 4-2, 5-2, 6-2, 7-2, 10-2, 11-2, 12-2, 13-2, 14-2, 15-2, 16-2, -// 1-3, 2-3, 3-3, 4-3, 5-3, 6-3, 7-3, 10-3, 11-3, 12-3, 13-3, 14-3, 15-3, 16-3, -// 1-4, 2-4, 3-4, 4-4, 5-4, 6-4, 7-4, 10-4, 11-4, 12-4, 13-4, 14-4, 15-4, 16-4, -// 1-5, 2-5, 3-5, 4-5, 5-5, 6-5, 7-5, 10-5, 11-5, 12-5, 13-5, 14-5, 15-5, 16-5, -// 1-6, 2-6, 3-6, 4-6, 5-6, 6-6, 7-6, 10-6, 11-6, 12-6, 13-6, 14-6, 15-6, 16-6, -// 1-7, 2-7, 3-7, 4-7, 5-7, 6-7, 7-7, 10-7, 11-7, 12-7, 13-7, 14-7, 15-7, 16-7, -// 1-8, 2-8, 3-8, 4-8, 5-8, 6-8, 7-8, 10-8, 11-8, 12-8, 13-8, 14-8, 15-8, 16-8, -// 1-9, 2-9, 3-9, 4-9, 5-9, 6-9, 7-9, 10-9, 11-9, 12-9, 13-9, 14-9, 15-9, 16-9, -// 1-10, 2-10, 3-10, 4-10, 5-10, 6-10, 7-10, 10-10, 11-10, 12-10, 13-10, 14-10, 15-10, 16-10, -// 1-11, 2-11, 3-11, 4-11, 5-11, 6-11, 7-11, 10-11, 11-11, 12-11, 13-11, 14-11, 15-11, 16-11, -// ] - -std::size_t get_num_harvested(std::size_t harvesting_mask) { - std::size_t num_harvested = 0; - while (harvesting_mask > 0) { - if (harvesting_mask & 1) { - num_harvested++; - } - harvesting_mask >>= 1; - } - return num_harvested; -} - -// Tests that all physical coordinates are same as all virtual coordinates -// when there is no harvesting. -TEST(SocDescriptor, SocDescriptorWHNoHarvesting) { - - const std::size_t harvesting_mask = 0; - - tt_SocDescriptor soc_desc = tt_SocDescriptor(test_utils::GetAbsPath("tests/soc_descs/wormhole_b0_8x10.yaml"), harvesting_mask); - - // We expect full grid size since there is no harvesting. - 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); - tt_physical_coords physical_coords = soc_desc.logical_to_physical_coords(logical_coords); - - // Virtual and physical coordinates should be the same. - EXPECT_EQ(physical_coords, virtual_coords); - } - } -} - -// Tests that all physical coordinates are same as all virtual coordinates -// when there is no harvesting. -TEST(SocDescriptor, SocDescriptorBHNoHarvesting) { - - tt_SocDescriptor soc_desc = tt_SocDescriptor(test_utils::GetAbsPath("tests/soc_descs/blackhole_140_arch_no_eth.yaml"), 0); - - // We expect full grid size since there is no harvesting. - 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); - tt_physical_coords physical_coords = soc_desc.logical_to_physical_coords(logical_coords); - - // Virtual and physical coordinates should be the same. - EXPECT_EQ(physical_coords, virtual_coords); - } - } -} - -// Test basic translation to virtual and physical noc coordinates. -// 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(SocDescriptor, SocDescriptorWHTopLeftCore) { - - const std::size_t harvesting_mask = 1; - - tt_SocDescriptor soc_desc = tt_SocDescriptor(test_utils::GetAbsPath("tests/soc_descs/wormhole_b0_8x10.yaml"), harvesting_mask); - tt_xy_pair worker_grid_size = soc_desc.worker_grid_size; - - tt_logical_coords logical_coords = tt_logical_coords(0, 0); - - // Always expect same virtual coordinate for (0, 0) logical coordinate. - tt_virtual_coords virtual_cords = soc_desc.logical_to_virtual_coords(logical_coords); - EXPECT_EQ(virtual_cords, tt_virtual_coords(1, 1)); - - // This depends on harvesting mask. So expected physical coord is specific to this test and Wormhole arch. - tt_physical_coords physical_cords = soc_desc.logical_to_physical_coords(logical_coords); - EXPECT_EQ(physical_cords, tt_physical_coords(1, 2)); -} - -// Test basic translation to virtual and physical noc coordinates. -// 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(SocDescriptor, SocDescriptorBHTopLeftCore) { - tt_SocDescriptor soc_desc = tt_SocDescriptor(test_utils::GetAbsPath("tests/soc_descs/blackhole_140_arch_no_eth.yaml"), 1); - tt_xy_pair worker_grid_size = soc_desc.worker_grid_size; - - tt_logical_coords logical_coords = tt_logical_coords(0, 0); - - // Always expect same virtual coordinate for (0, 0) logical coordinate. - tt_virtual_coords virtual_cords = soc_desc.logical_to_virtual_coords(logical_coords); - EXPECT_EQ(virtual_cords, tt_virtual_coords(1, 2)); - - // This depends on harvesting mask. So expected physical coord is specific to this test and Blackhole arch. - tt_physical_coords physical_cords = soc_desc.logical_to_physical_coords(logical_coords); - EXPECT_EQ(physical_cords, tt_physical_coords(2, 2)); -} - -// 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, SocDescriptorWHLogicalPhysicalMapping) { - - const std::size_t max_num_harvested_y = 10; - tt_SocDescriptor soc_desc = tt_SocDescriptor(test_utils::GetAbsPath("tests/soc_descs/wormhole_b0_8x10.yaml")); - for (std::size_t harvesting_mask = 0; harvesting_mask < (1 << max_num_harvested_y); harvesting_mask++) { - - soc_desc.perform_harvesting(harvesting_mask); - - std::map logical_to_physical; - std::set physical_coords_set; - tt_xy_pair worker_grid_size = soc_desc.worker_grid_size; - - std::size_t num_harvested_y = get_num_harvested(harvesting_mask); - - for (size_t x = 0; x < worker_grid_size.x; x++) { - for (size_t y = 0; y < worker_grid_size.y - num_harvested_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 that the number of physical coordinates is equal to the number of workers minus the number of harvested rows. - EXPECT_EQ(physical_coords_set.size(), worker_grid_size.x * (worker_grid_size.y - num_harvested_y)); - - 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 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, SocDescriptorBHLogicalPhysicalMapping) { - - 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 logical_to_physical; - std::set physical_coords_set; - tt_xy_pair worker_grid_size = soc_desc.worker_grid_size; - - std::size_t num_harvested_x = 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_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 - num_harvested_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, SocDescriptorWHLogicalVirtualMapping) { - - const std::size_t max_num_harvested_y = 10; - tt_SocDescriptor soc_desc = tt_SocDescriptor(test_utils::GetAbsPath("tests/soc_descs/wormhole_b0_8x10.yaml")); - for (std::size_t harvesting_mask = 0; harvesting_mask < (1 << max_num_harvested_y); harvesting_mask++) { - - soc_desc.perform_harvesting(harvesting_mask); - - std::map logical_to_virtual; - std::set virtual_coords_set; - tt_xy_pair worker_grid_size = soc_desc.worker_grid_size; - - std::size_t num_harvested_y = get_num_harvested(harvesting_mask); - - for (size_t x = 0; x < worker_grid_size.x; x++) { - for (size_t y = 0; y < worker_grid_size.y - num_harvested_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); - } - } - - 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); - } - } -} - -// 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, SocDescriptorBHLogicalVirtualMapping) { - - 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 logical_to_virtual; - std::set virtual_coords_set; - tt_xy_pair worker_grid_size = soc_desc.worker_grid_size; - - std::size_t num_harvested_x = 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_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 - num_harvested_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); - } - } -} diff --git a/tests/api/test_soc_descriptor_bh.cpp b/tests/api/test_soc_descriptor_bh.cpp new file mode 100644 index 00000000..46c5269d --- /dev/null +++ b/tests/api/test_soc_descriptor_bh.cpp @@ -0,0 +1,143 @@ +#include "gtest/gtest.h" + +#include "device/tt_soc_descriptor.h" +#include "tests/test_utils/generate_cluster_desc.hpp" +#include "tests/test_utils/soc_desc_test_utils.hpp" + + +// Blackhole workers - x-y annotation +// functional_workers: +// [ +// 1-2, 2-2, 3-2, 4-2, 5-2, 6-2, 7-2, 10-2, 11-2, 12-2, 13-2, 14-2, 15-2, 16-2, +// 1-3, 2-3, 3-3, 4-3, 5-3, 6-3, 7-3, 10-3, 11-3, 12-3, 13-3, 14-3, 15-3, 16-3, +// 1-4, 2-4, 3-4, 4-4, 5-4, 6-4, 7-4, 10-4, 11-4, 12-4, 13-4, 14-4, 15-4, 16-4, +// 1-5, 2-5, 3-5, 4-5, 5-5, 6-5, 7-5, 10-5, 11-5, 12-5, 13-5, 14-5, 15-5, 16-5, +// 1-6, 2-6, 3-6, 4-6, 5-6, 6-6, 7-6, 10-6, 11-6, 12-6, 13-6, 14-6, 15-6, 16-6, +// 1-7, 2-7, 3-7, 4-7, 5-7, 6-7, 7-7, 10-7, 11-7, 12-7, 13-7, 14-7, 15-7, 16-7, +// 1-8, 2-8, 3-8, 4-8, 5-8, 6-8, 7-8, 10-8, 11-8, 12-8, 13-8, 14-8, 15-8, 16-8, +// 1-9, 2-9, 3-9, 4-9, 5-9, 6-9, 7-9, 10-9, 11-9, 12-9, 13-9, 14-9, 15-9, 16-9, +// 1-10, 2-10, 3-10, 4-10, 5-10, 6-10, 7-10, 10-10, 11-10, 12-10, 13-10, 14-10, 15-10, 16-10, +// 1-11, 2-11, 3-11, 4-11, 5-11, 6-11, 7-11, 10-11, 11-11, 12-11, 13-11, 14-11, 15-11, 16-11, +// ] + +// Tests that all physical coordinates are same as all virtual coordinates +// when there is no harvesting. +TEST(SocDescriptor, SocDescriptorBHNoHarvesting) { + + tt_SocDescriptor soc_desc = tt_SocDescriptor(test_utils::GetAbsPath("tests/soc_descs/blackhole_140_arch_no_eth.yaml"), 0); + + // We expect full grid size since there is no harvesting. + 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); + tt_physical_coords physical_coords = soc_desc.logical_to_physical_coords(logical_coords); + + // Virtual and physical coordinates should be the same. + EXPECT_EQ(physical_coords, virtual_coords); + } + } +} + +// Test basic translation to virtual and physical noc coordinates. +// 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(SocDescriptor, SocDescriptorBHTopLeftCore) { + tt_SocDescriptor soc_desc = tt_SocDescriptor(test_utils::GetAbsPath("tests/soc_descs/blackhole_140_arch_no_eth.yaml"), 1); + tt_xy_pair worker_grid_size = soc_desc.worker_grid_size; + + tt_logical_coords logical_coords = tt_logical_coords(0, 0); + + // Always expect same virtual coordinate for (0, 0) logical coordinate. + tt_virtual_coords virtual_cords = soc_desc.logical_to_virtual_coords(logical_coords); + EXPECT_EQ(virtual_cords, tt_virtual_coords(1, 2)); + + // This depends on harvesting mask. So expected physical coord is specific to this test and Blackhole arch. + tt_physical_coords physical_cords = soc_desc.logical_to_physical_coords(logical_coords); + EXPECT_EQ(physical_cords, tt_physical_coords(2, 2)); +} + +// 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, SocDescriptorBHLogicalPhysicalMapping) { + + 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 logical_to_physical; + std::set physical_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_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 - num_harvested_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, SocDescriptorBHLogicalVirtualMapping) { + + 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 logical_to_virtual; + std::set virtual_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_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 - num_harvested_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); + } + } +} diff --git a/tests/api/test_soc_descriptor_gs.cpp b/tests/api/test_soc_descriptor_gs.cpp new file mode 100644 index 00000000..b122ce56 --- /dev/null +++ b/tests/api/test_soc_descriptor_gs.cpp @@ -0,0 +1,149 @@ +#include "gtest/gtest.h" + +#include "device/tt_soc_descriptor.h" +#include "tests/test_utils/generate_cluster_desc.hpp" +#include "tests/test_utils/soc_desc_test_utils.hpp" + +// Grayskull workers - x-y annotation +// functional_workers: +// [ +// 1-1, 2-1, 3-1, 4-1, 5-1, 6-1, 7-1, 8-1, 9-1, 10-1, 11-1, 12-1, +// 1-2, 2-2, 3-2, 4-2, 5-2, 6-2, 7-2, 8-2, 9-2, 10-2, 11-2, 12-2, +// 1-3, 2-3, 3-3, 4-3, 5-3, 6-3, 7-3, 8-3, 9-3, 10-3, 11-3, 12-3, +// 1-4, 2-4, 3-4, 4-4, 5-4, 6-4, 7-4, 8-4, 9-4, 10-4, 11-4, 12-4, +// 1-5, 2-5, 3-5, 4-5, 5-5, 6-5, 7-5, 8-5, 9-5, 10-5, 11-5, 12-5, +// 1-7, 2-7, 3-7, 4-7, 5-7, 6-7, 7-7, 8-7, 9-7, 10-7, 11-7, 12-7, +// 1-8, 2-8, 3-8, 4-8, 5-8, 6-8, 7-8, 8-8, 9-8, 10-8, 11-8, 12-8, +// 1-9, 2-9, 3-9, 4-9, 5-9, 6-9, 7-9, 8-9, 9-9, 10-9, 11-9, 12-9, +// 1-10, 2-10, 3-10, 4-10, 5-10, 6-10, 7-10, 8-10, 9-10, 10-10, 11-10, 12-10, +// 1-11, 2-11, 3-11, 4-11, 5-11, 6-11, 7-11, 8-11, 9-11, 10-11, 11-11, 12-11 +// ] + +// Tests that all physical coordinates are same as all virtual coordinates +// when there is no harvesting. +TEST(SocDescriptor, SocDescriptorGSNoHarvesting) { + + tt_SocDescriptor soc_desc = tt_SocDescriptor(test_utils::GetAbsPath("tests/soc_descs/grayskull_10x12.yaml")); + + // We expect full grid size since there is no harvesting. + 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); + tt_physical_coords physical_coords = soc_desc.logical_to_physical_coords(logical_coords); + + // Virtual and physical coordinates should be the same. + EXPECT_EQ(physical_coords, virtual_coords); + } + } +} + +// Test basic translation to virtual and physical noc coordinates. +// 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(SocDescriptor, SocDescriptorGSTopLeftCore) { + + tt_SocDescriptor soc_desc = tt_SocDescriptor(test_utils::GetAbsPath("tests/soc_descs/grayskull_10x12.yaml")); + tt_xy_pair worker_grid_size = soc_desc.worker_grid_size; + + tt_logical_coords logical_coords = tt_logical_coords(0, 0); + + // Always expect same virtual coordinate for (0, 0) logical coordinate. + tt_virtual_coords virtual_cords = soc_desc.logical_to_virtual_coords(logical_coords); + EXPECT_EQ(virtual_cords, tt_virtual_coords(1, 1)); + + // This depends on harvesting mask. So expected physical coord is specific to this test and Wormhole arch. + tt_physical_coords physical_cords = soc_desc.logical_to_physical_coords(logical_coords); + EXPECT_EQ(physical_cords, tt_physical_coords(1, 1)); +} + +// Test logical to physical, virtual and translated coordinates. +// We always expect that physical, virtual and translated coordinates are the same. +TEST(SocDescriptor, SocDescriptorGSTranslatingCoords) { + tt_SocDescriptor soc_desc = tt_SocDescriptor(test_utils::GetAbsPath("tests/soc_descs/grayskull_10x12.yaml")); + 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); + tt_physical_coords physical_coords = soc_desc.logical_to_physical_coords(logical_coords); + tt_translated_coords translated_coords = soc_desc.logical_to_translated_coords(logical_coords); + + // Virtual, physical and translated coordinates should be the same. + EXPECT_EQ(physical_coords, virtual_coords); + EXPECT_EQ(physical_coords, translated_coords); + } + } +} + +// 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); + } +} diff --git a/tests/api/test_soc_descriptor_wh.cpp b/tests/api/test_soc_descriptor_wh.cpp new file mode 100644 index 00000000..b7ed5088 --- /dev/null +++ b/tests/api/test_soc_descriptor_wh.cpp @@ -0,0 +1,178 @@ +#include "gtest/gtest.h" + +#include "device/tt_soc_descriptor.h" +#include "tests/test_utils/generate_cluster_desc.hpp" +#include "tests/test_utils/soc_desc_test_utils.hpp" + + +// Wormhole workers - x-y annotation +// functional_workers: +// [ +// 1-1, 2-1, 3-1, 4-1, 6-1, 7-1, 8-1, 9-1, +// 1-2, 2-2, 3-2, 4-2, 6-2, 7-2, 8-2, 9-2, +// 1-3, 2-3, 3-3, 4-3, 6-3, 7-3, 8-3, 9-3, +// 1-4, 2-4, 3-4, 4-4, 6-4, 7-4, 8-4, 9-4, +// 1-5, 2-5, 3-5, 4-5, 6-5, 7-5, 8-5, 9-5, +// 1-7, 2-7, 3-7, 4-7, 6-7, 7-7, 8-7, 9-7, +// 1-8, 2-8, 3-8, 4-8, 6-8, 7-8, 8-8, 9-8, +// 1-9, 2-9, 3-9, 4-9, 6-9, 7-9, 8-9, 9-9, +// 1-10, 2-10, 3-10, 4-10, 6-10, 7-10, 8-10, 9-10, +// 1-11, 2-11, 3-11, 4-11, 6-11, 7-11, 8-11, 9-11, +// ] + +// Tests that all physical coordinates are same as all virtual coordinates +// when there is no harvesting. +TEST(SocDescriptor, SocDescriptorWHNoHarvesting) { + + const std::size_t harvesting_mask = 0; + + tt_SocDescriptor soc_desc = tt_SocDescriptor(test_utils::GetAbsPath("tests/soc_descs/wormhole_b0_8x10.yaml"), harvesting_mask); + + // We expect full grid size since there is no harvesting. + 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); + tt_physical_coords physical_coords = soc_desc.logical_to_physical_coords(logical_coords); + + // Virtual and physical coordinates should be the same. + EXPECT_EQ(physical_coords, virtual_coords); + } + } +} + +// Test basic translation to virtual and physical noc coordinates. +// 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(SocDescriptor, SocDescriptorWHTopLeftCore) { + + const std::size_t harvesting_mask = 1; + + tt_SocDescriptor soc_desc = tt_SocDescriptor(test_utils::GetAbsPath("tests/soc_descs/wormhole_b0_8x10.yaml"), harvesting_mask); + tt_xy_pair worker_grid_size = soc_desc.worker_grid_size; + + tt_logical_coords logical_coords = tt_logical_coords(0, 0); + + // Always expect same virtual coordinate for (0, 0) logical coordinate. + tt_virtual_coords virtual_cords = soc_desc.logical_to_virtual_coords(logical_coords); + EXPECT_EQ(virtual_cords, tt_virtual_coords(1, 1)); + + // This depends on harvesting mask. So expected physical coord is specific to this test and Wormhole arch. + tt_physical_coords physical_cords = soc_desc.logical_to_physical_coords(logical_coords); + EXPECT_EQ(physical_cords, tt_physical_coords(1, 2)); +} + +// 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, SocDescriptorWHLogicalPhysicalMapping) { + + const std::size_t max_num_harvested_y = 10; + tt_SocDescriptor soc_desc = tt_SocDescriptor(test_utils::GetAbsPath("tests/soc_descs/wormhole_b0_8x10.yaml")); + for (std::size_t harvesting_mask = 0; harvesting_mask < (1 << max_num_harvested_y); harvesting_mask++) { + + soc_desc.perform_harvesting(harvesting_mask); + + std::map logical_to_physical; + std::set physical_coords_set; + tt_xy_pair worker_grid_size = soc_desc.worker_grid_size; + + std::size_t num_harvested_y = test_utils::get_num_harvested(harvesting_mask); + + for (size_t x = 0; x < worker_grid_size.x; x++) { + for (size_t y = 0; y < worker_grid_size.y - num_harvested_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 that the number of physical coordinates is equal to the number of workers minus the number of harvested rows. + EXPECT_EQ(physical_coords_set.size(), worker_grid_size.x * (worker_grid_size.y - num_harvested_y)); + + 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, SocDescriptorWHLogicalVirtualMapping) { + + const std::size_t max_num_harvested_y = 10; + tt_SocDescriptor soc_desc = tt_SocDescriptor(test_utils::GetAbsPath("tests/soc_descs/wormhole_b0_8x10.yaml")); + for (std::size_t harvesting_mask = 0; harvesting_mask < (1 << max_num_harvested_y); harvesting_mask++) { + + soc_desc.perform_harvesting(harvesting_mask); + + std::map logical_to_virtual; + std::set virtual_coords_set; + tt_xy_pair worker_grid_size = soc_desc.worker_grid_size; + + std::size_t num_harvested_y = test_utils::get_num_harvested(harvesting_mask); + + for (size_t x = 0; x < worker_grid_size.x; x++) { + for (size_t y = 0; y < worker_grid_size.y - num_harvested_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); + } + } + + 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); + } + } +} + +// Test top left corner translation from logical to translated coordinates. +TEST(SocDescriptor, SocDescriptorWHLogicalTranslatedTopLeft) { + + const std::size_t translated_x_start = 18; + const std::size_t translated_y_start = 18; + const tt_translated_coords expected_translated_coords = tt_translated_coords(translated_x_start, translated_y_start); + + const std::size_t max_num_harvested_y = 10; + tt_SocDescriptor soc_desc = tt_SocDescriptor(test_utils::GetAbsPath("tests/soc_descs/wormhole_b0_8x10.yaml")); + // We go up to numbers less than 2^10 - 1 to test all possible harvesting masks, we don't want to try to convert if everything is harvested. + for (std::size_t harvesting_mask = 0; harvesting_mask < (1 << max_num_harvested_y) - 1; harvesting_mask++) { + soc_desc.perform_harvesting(harvesting_mask); + + tt_xy_pair worker_grid_size = soc_desc.worker_grid_size; + + std::size_t num_harvested_y = test_utils::get_num_harvested(harvesting_mask); + + tt_logical_coords logical_coords = tt_logical_coords(0, 0); + tt_physical_coords physical_coords = soc_desc.logical_to_physical_coords(logical_coords); + tt_virtual_coords virtual_coords = soc_desc.logical_to_virtual_coords(logical_coords); + + tt_translated_coords translated_from_logical = soc_desc.logical_to_translated_coords(logical_coords); + tt_translated_coords translated_from_physical = soc_desc.physical_to_translated_coords(physical_coords); + tt_translated_coords translated_from_virtual = soc_desc.virtual_to_translated_coords(virtual_coords); + + EXPECT_EQ(translated_from_logical, expected_translated_coords); + EXPECT_EQ(translated_from_physical, expected_translated_coords); + EXPECT_EQ(translated_from_virtual, expected_translated_coords); + } +} diff --git a/tests/soc_descs/grayskull_10x12.yaml b/tests/soc_descs/grayskull_10x12.yaml index 77f20f52..761128dd 100644 --- a/tests/soc_descs/grayskull_10x12.yaml +++ b/tests/soc_descs/grayskull_10x12.yaml @@ -16,20 +16,18 @@ eth: functional_workers: [ - 1-1, 1-2, 1-3, 1-4, 1-5, 1-7, 1-8, 1-9, 1-10, 1-11, - 2-1, 2-2, 2-3, 2-4, 2-5, 2-7, 2-8, 2-9, 2-10, 2-11, - 3-1, 3-2, 3-3, 3-4, 3-5, 3-7, 3-8, 3-9, 3-10, 3-11, - 4-1, 4-2, 4-3, 4-4, 4-5, 4-7, 4-8, 4-9, 4-10, 4-11, - 5-1, 5-2, 5-3, 5-4, 5-5, 5-7, 5-8, 5-9, 5-10, 5-11, - 6-1, 6-2, 6-3, 6-4, 6-5, 6-7, 6-8, 6-9, 6-10, 6-11, - 7-1, 7-2, 7-3, 7-4, 7-5, 7-7, 7-8, 7-9, 7-10, 7-11, - 8-1, 8-2, 8-3, 8-4, 8-5, 8-7, 8-8, 8-9, 8-10, 8-11, - 9-1, 9-2, 9-3, 9-4, 9-5, 9-7, 9-8, 9-9, 9-10, 9-11, - 10-1, 10-2, 10-3, 10-4, 10-5, 10-7, 10-8, 10-9, 10-10, 10-11, - 11-1, 11-2, 11-3, 11-4, 11-5, 11-7, 11-8, 11-9, 11-10, 11-11, - 12-1, 12-2, 12-3, 12-4, 12-5, 12-7, 12-8, 12-9, 12-10, 12-11 + 1-1, 2-1, 3-1, 4-1, 5-1, 6-1, 7-1, 8-1, 9-1, 10-1, 11-1, 12-1, + 1-2, 2-2, 3-2, 4-2, 5-2, 6-2, 7-2, 8-2, 9-2, 10-2, 11-2, 12-2, + 1-3, 2-3, 3-3, 4-3, 5-3, 6-3, 7-3, 8-3, 9-3, 10-3, 11-3, 12-3, + 1-4, 2-4, 3-4, 4-4, 5-4, 6-4, 7-4, 8-4, 9-4, 10-4, 11-4, 12-4, + 1-5, 2-5, 3-5, 4-5, 5-5, 6-5, 7-5, 8-5, 9-5, 10-5, 11-5, 12-5, + 1-7, 2-7, 3-7, 4-7, 5-7, 6-7, 7-7, 8-7, 9-7, 10-7, 11-7, 12-7, + 1-8, 2-8, 3-8, 4-8, 5-8, 6-8, 7-8, 8-8, 9-8, 10-8, 11-8, 12-8, + 1-9, 2-9, 3-9, 4-9, 5-9, 6-9, 7-9, 8-9, 9-9, 10-9, 11-9, 12-9, + 1-10, 2-10, 3-10, 4-10, 5-10, 6-10, 7-10, 8-10, 9-10, 10-10, 11-10, 12-10, + 1-11, 2-11, 3-11, 4-11, 5-11, 6-11, 7-11, 8-11, 9-11, 10-11, 11-11, 12-11 ] - + harvested_workers: [] diff --git a/tests/test_utils/soc_desc_test_utils.hpp b/tests/test_utils/soc_desc_test_utils.hpp new file mode 100644 index 00000000..e966418c --- /dev/null +++ b/tests/test_utils/soc_desc_test_utils.hpp @@ -0,0 +1,21 @@ +#pragma once + +#include +#include +#include + + +namespace test_utils { + +static std::size_t get_num_harvested(std::size_t harvesting_mask) { + std::size_t num_harvested = 0; + while (harvesting_mask > 0) { + if (harvesting_mask & 1) { + num_harvested++; + } + harvesting_mask >>= 1; + } + return num_harvested; +} + +}