From fff1d4cf1ffe96e9f67036bae3fbf6e8d0eee209 Mon Sep 17 00:00:00 2001 From: Pavle Janevski <165378935+pjanevskiTT@users.noreply.github.com> Date: Fri, 3 Jan 2025 13:59:48 +0100 Subject: [PATCH] Soc descriptor API for all coordinate systems (#442) --- device/api/umd/device/tt_soc_descriptor.h | 8 +- device/coordinate_manager.cpp | 6 ++ device/tt_soc_descriptor.cpp | 43 +++++---- tests/api/test_soc_descriptor.cpp | 105 ++++++++++++++++++++++ 4 files changed, 145 insertions(+), 17 deletions(-) diff --git a/device/api/umd/device/tt_soc_descriptor.h b/device/api/umd/device/tt_soc_descriptor.h index 68772866..96953660 100644 --- a/device/api/umd/device/tt_soc_descriptor.h +++ b/device/api/umd/device/tt_soc_descriptor.h @@ -60,8 +60,10 @@ class tt_SocDescriptor { static std::string get_soc_descriptor_path(tt::ARCH arch); - std::vector get_cores(const CoreType core_type) const; - std::vector get_harvested_cores(const CoreType core_type) const; + std::vector get_cores( + const CoreType core_type, const CoordSystem coord_system = CoordSystem::PHYSICAL) const; + std::vector get_harvested_cores( + const CoreType core_type, const CoordSystem coord_system = CoordSystem::PHYSICAL) const; tt_xy_pair get_grid_size(const CoreType core_type) const; tt_xy_pair get_harvested_grid_size(const CoreType core_type) const; @@ -116,6 +118,8 @@ class tt_SocDescriptor { void get_cores_and_grid_size_from_coordinate_manager(); static tt_xy_pair calculate_grid_size(const std::vector &cores); + std::vector translate_coordinates( + const std::vector &physical_cores, const CoordSystem coord_system) const; // TODO: change this to unique pointer as soon as copying of tt_SocDescriptor // is not needed anymore. Soc descriptor and coordinate manager should be diff --git a/device/coordinate_manager.cpp b/device/coordinate_manager.cpp index e024402f..b475f50d 100644 --- a/device/coordinate_manager.cpp +++ b/device/coordinate_manager.cpp @@ -453,6 +453,9 @@ std::vector CoordinateManager::get_harvested_cores(const Cor return get_harvested_dram_cores(); case CoreType::ETH: return get_harvested_eth_cores(); + case CoreType::ARC: + case CoreType::PCIE: + return {}; default: throw std::runtime_error("Core type is not supported for getting harvested cores"); } @@ -474,6 +477,9 @@ tt_xy_pair CoordinateManager::get_harvested_grid_size(const CoreType core_type) return get_harvested_dram_grid_size(); case CoreType::ETH: return get_harvested_eth_grid_size(); + case CoreType::ARC: + case CoreType::PCIE: + return {0, 0}; default: throw std::runtime_error("Core type is not supported for getting harvested grid size"); } diff --git a/device/tt_soc_descriptor.cpp b/device/tt_soc_descriptor.cpp index 64048682..8627bcf7 100644 --- a/device/tt_soc_descriptor.cpp +++ b/device/tt_soc_descriptor.cpp @@ -14,6 +14,7 @@ #include "api/umd/device/tt_soc_descriptor.h" #include "fmt/core.h" +#include "logger.hpp" #include "utils.hpp" #include "yaml-cpp/yaml.h" @@ -315,6 +316,12 @@ void tt_SocDescriptor::get_cores_and_grid_size_from_coordinate_manager() { harvested_cores_map.insert({CoreType::ETH, coordinate_manager->get_harvested_cores(CoreType::ETH)}); harvested_grid_size_map.insert({CoreType::ETH, coordinate_manager->get_harvested_grid_size(CoreType::ETH)}); + harvested_cores_map.insert({CoreType::ARC, coordinate_manager->get_harvested_cores(CoreType::ARC)}); + harvested_grid_size_map.insert({CoreType::ARC, coordinate_manager->get_harvested_grid_size(CoreType::ARC)}); + + harvested_cores_map.insert({CoreType::PCIE, coordinate_manager->get_harvested_cores(CoreType::PCIE)}); + harvested_grid_size_map.insert({CoreType::PCIE, coordinate_manager->get_harvested_grid_size(CoreType::PCIE)}); + const std::vector dram_cores = cores_map.at(CoreType::DRAM); const tt_xy_pair dram_grid_size = grid_size_map.at(CoreType::DRAM); @@ -337,31 +344,37 @@ void tt_SocDescriptor::get_cores_and_grid_size_from_coordinate_manager() { } } -std::vector tt_SocDescriptor::get_cores(const CoreType core_type) const { - if (cores_map.find(core_type) == cores_map.end()) { - return {}; +std::vector tt_SocDescriptor::translate_coordinates( + const std::vector &physical_cores, const CoordSystem coord_system) const { + std::vector translated_cores; + for (const auto &core : physical_cores) { + translated_cores.push_back(translate_coord_to(core, coord_system)); } - return cores_map.at(core_type); + return translated_cores; } -std::vector tt_SocDescriptor::get_harvested_cores(const CoreType core_type) const { - if (harvested_cores_map.find(core_type) == harvested_cores_map.end()) { - return {}; +std::vector tt_SocDescriptor::get_cores( + const CoreType core_type, const CoordSystem coord_system) const { + auto cores_map_it = cores_map.find(core_type); + if (coord_system != CoordSystem::PHYSICAL) { + return translate_coordinates(cores_map_it->second, coord_system); } - return harvested_cores_map.at(core_type); + return cores_map_it->second; } -tt_xy_pair tt_SocDescriptor::get_grid_size(const CoreType core_type) const { - if (grid_size_map.find(core_type) == grid_size_map.end()) { - return {0, 0}; +std::vector tt_SocDescriptor::get_harvested_cores( + const CoreType core_type, const CoordSystem coord_system) const { + log_assert(coord_system != CoordSystem::LOGICAL, "Harvested cores are not supported for logical coordinates"); + auto harvested_cores_map_it = harvested_cores_map.find(core_type); + if (coord_system != CoordSystem::PHYSICAL) { + return translate_coordinates(harvested_cores_map_it->second, coord_system); } - return grid_size_map.at(core_type); + return harvested_cores_map_it->second; } +tt_xy_pair tt_SocDescriptor::get_grid_size(const CoreType core_type) const { return grid_size_map.at(core_type); } + tt_xy_pair tt_SocDescriptor::get_harvested_grid_size(const CoreType core_type) const { - if (harvested_grid_size_map.find(core_type) == harvested_grid_size_map.end()) { - return {0, 0}; - } return harvested_grid_size_map.at(core_type); } diff --git a/tests/api/test_soc_descriptor.cpp b/tests/api/test_soc_descriptor.cpp index e73fe151..955c8cb3 100644 --- a/tests/api/test_soc_descriptor.cpp +++ b/tests/api/test_soc_descriptor.cpp @@ -342,3 +342,108 @@ TEST(SocDescriptor, CustomSocDescriptor) { EXPECT_EQ(soc_desc.get_num_dram_channels(), 1); } + +TEST(SocDescriptor, SocDescriptorGrayskullMultipleCoordinateSystems) { + tt_SocDescriptor soc_desc(test_utils::GetAbsPath("tests/soc_descs/grayskull_10x12.yaml")); + + const std::vector cores_physical = tt::umd::grayskull::TENSIX_CORES; + + std::vector virtual_from_physical; + std::vector logical_from_physical; + std::vector translated_from_physical; + + for (const tt_xy_pair& physical_core : cores_physical) { + const CoreCoord core(physical_core.x, physical_core.y, CoreType::TENSIX, CoordSystem::PHYSICAL); + virtual_from_physical.push_back(soc_desc.translate_coord_to(core, CoordSystem::VIRTUAL)); + logical_from_physical.push_back(soc_desc.translate_coord_to(core, CoordSystem::LOGICAL)); + translated_from_physical.push_back(soc_desc.translate_coord_to(core, CoordSystem::TRANSLATED)); + } + + std::vector cores_virtual = soc_desc.get_cores(CoreType::TENSIX, CoordSystem::VIRTUAL); + std::vector cores_logical = soc_desc.get_cores(CoreType::TENSIX, CoordSystem::LOGICAL); + std::vector cores_translated = soc_desc.get_cores(CoreType::TENSIX, CoordSystem::TRANSLATED); + + EXPECT_TRUE(virtual_from_physical == cores_virtual); + EXPECT_TRUE(logical_from_physical == cores_logical); + EXPECT_TRUE(translated_from_physical == cores_translated); +} + +TEST(SocDescriptor, SocDescriptorWormholeMultipleCoordinateSystems) { + tt_SocDescriptor soc_desc(test_utils::GetAbsPath("tests/soc_descs/wormhole_b0_8x10.yaml")); + + const std::vector cores_physical = tt::umd::wormhole::TENSIX_CORES; + + std::vector virtual_from_physical; + std::vector logical_from_physical; + std::vector translated_from_physical; + + for (const tt_xy_pair& physical_core : cores_physical) { + const CoreCoord core(physical_core.x, physical_core.y, CoreType::TENSIX, CoordSystem::PHYSICAL); + virtual_from_physical.push_back(soc_desc.translate_coord_to(core, CoordSystem::VIRTUAL)); + logical_from_physical.push_back(soc_desc.translate_coord_to(core, CoordSystem::LOGICAL)); + translated_from_physical.push_back(soc_desc.translate_coord_to(core, CoordSystem::TRANSLATED)); + } + + std::vector cores_virtual = soc_desc.get_cores(CoreType::TENSIX, CoordSystem::VIRTUAL); + std::vector cores_logical = soc_desc.get_cores(CoreType::TENSIX, CoordSystem::LOGICAL); + std::vector cores_translated = soc_desc.get_cores(CoreType::TENSIX, CoordSystem::TRANSLATED); + + EXPECT_TRUE(virtual_from_physical == cores_virtual); + EXPECT_TRUE(logical_from_physical == cores_logical); + EXPECT_TRUE(translated_from_physical == cores_translated); +} + +TEST(SocDescriptor, SocDescriptorBlackholeMultipleCoordinateSystems) { + tt_SocDescriptor soc_desc(test_utils::GetAbsPath("tests/soc_descs/blackhole_140_arch_no_eth.yaml")); + + const std::vector cores_physical = tt::umd::blackhole::TENSIX_CORES; + + std::vector virtual_from_physical; + std::vector logical_from_physical; + std::vector translated_from_physical; + + for (const tt_xy_pair& physical_core : cores_physical) { + const CoreCoord core(physical_core.x, physical_core.y, CoreType::TENSIX, CoordSystem::PHYSICAL); + virtual_from_physical.push_back(soc_desc.translate_coord_to(core, CoordSystem::VIRTUAL)); + logical_from_physical.push_back(soc_desc.translate_coord_to(core, CoordSystem::LOGICAL)); + translated_from_physical.push_back(soc_desc.translate_coord_to(core, CoordSystem::TRANSLATED)); + } + + std::vector cores_virtual = soc_desc.get_cores(CoreType::TENSIX, CoordSystem::VIRTUAL); + std::vector cores_logical = soc_desc.get_cores(CoreType::TENSIX, CoordSystem::LOGICAL); + std::vector cores_translated = soc_desc.get_cores(CoreType::TENSIX, CoordSystem::TRANSLATED); + + EXPECT_TRUE(virtual_from_physical == cores_virtual); + EXPECT_TRUE(logical_from_physical == cores_logical); + EXPECT_TRUE(translated_from_physical == cores_translated); +} + +TEST(SocDescriptor, SocDescriptorGrayskullNoLogicalForHarvestedCores) { + tt_SocDescriptor soc_desc(test_utils::GetAbsPath("tests/soc_descs/grayskull_10x12.yaml"), 1); + + EXPECT_THROW(soc_desc.get_harvested_cores(CoreType::TENSIX, CoordSystem::LOGICAL), std::runtime_error); + + EXPECT_THROW(soc_desc.get_harvested_cores(CoreType::DRAM, CoordSystem::LOGICAL), std::runtime_error); + + EXPECT_THROW(soc_desc.get_harvested_cores(CoreType::ETH, CoordSystem::LOGICAL), std::runtime_error); +} + +TEST(SocDescriptor, SocDescriptorWormholeNoLogicalForHarvestedCores) { + tt_SocDescriptor soc_desc(test_utils::GetAbsPath("tests/soc_descs/wormhole_b0_8x10.yaml"), 1); + + EXPECT_THROW(soc_desc.get_harvested_cores(CoreType::TENSIX, CoordSystem::LOGICAL), std::runtime_error); + + EXPECT_THROW(soc_desc.get_harvested_cores(CoreType::DRAM, CoordSystem::LOGICAL), std::runtime_error); + + EXPECT_THROW(soc_desc.get_harvested_cores(CoreType::ETH, CoordSystem::LOGICAL), std::runtime_error); +} + +TEST(SocDescriptor, SocDescriptorBlackholeNoLogicalForHarvestedCores) { + tt_SocDescriptor soc_desc(test_utils::GetAbsPath("tests/soc_descs/blackhole_140_arch.yaml"), 1); + + EXPECT_THROW(soc_desc.get_harvested_cores(CoreType::TENSIX, CoordSystem::LOGICAL), std::runtime_error); + + EXPECT_THROW(soc_desc.get_harvested_cores(CoreType::DRAM, CoordSystem::LOGICAL), std::runtime_error); + + EXPECT_THROW(soc_desc.get_harvested_cores(CoreType::ETH, CoordSystem::LOGICAL), std::runtime_error); +}