From 52c3fc2cf6e94951fc782f14a527d7c4eb2063e8 Mon Sep 17 00:00:00 2001 From: pjanevski Date: Tue, 19 Nov 2024 11:04:00 +0000 Subject: [PATCH] Implement CoreCoord tensix translation --- device/CMakeLists.txt | 1 + .../blackhole_coordinate_manager.cpp | 14 +- .../blackhole/blackhole_coordinate_manager.h | 9 +- device/cluster.cpp | 13 -- device/cluster.h | 4 +- device/coordinate_manager.cpp | 141 ++++++++++++---- device/coordinate_manager.h | 40 ++--- .../grayskull_coordinate_manager.cpp | 16 ++ .../grayskull/grayskull_coordinate_manager.h | 4 + device/tt_core_coordinates.h | 33 ++-- device/tt_soc_descriptor.cpp | 48 +----- device/tt_soc_descriptor.h | 23 +-- device/tt_xy_pair.h | 46 +----- .../wormhole/wormhole_coordinate_manager.cpp | 111 +------------ device/wormhole/wormhole_coordinate_manager.h | 20 +-- tests/api/CMakeLists.txt | 6 +- ...cpp => test_core_coord_translation_bh.cpp} | 58 +++---- ...cpp => test_core_coord_translation_gs.cpp} | 48 +++--- ...cpp => test_core_coord_translation_wh.cpp} | 54 +++--- tests/api/test_core_coordinates.cpp | 156 +++++++++--------- 20 files changed, 348 insertions(+), 497 deletions(-) create mode 100644 device/grayskull/grayskull_coordinate_manager.cpp rename tests/api/{test_soc_descriptor_bh.cpp => test_core_coord_translation_bh.cpp} (79%) rename tests/api/{test_soc_descriptor_gs.cpp => test_core_coord_translation_gs.cpp} (76%) rename tests/api/{test_soc_descriptor_wh.cpp => test_core_coord_translation_wh.cpp} (76%) diff --git a/device/CMakeLists.txt b/device/CMakeLists.txt index 499e521e..e2c60969 100644 --- a/device/CMakeLists.txt +++ b/device/CMakeLists.txt @@ -19,6 +19,7 @@ set(UMD_DEVICE_SRCS coordinate_manager.cpp blackhole/blackhole_coordinate_manager.cpp wormhole/wormhole_coordinate_manager.cpp + grayskull/grayskull_coordinate_manager.cpp pcie/pci_device.cpp hugepage.cpp ) diff --git a/device/blackhole/blackhole_coordinate_manager.cpp b/device/blackhole/blackhole_coordinate_manager.cpp index 32775ece..ee6caf49 100644 --- a/device/blackhole/blackhole_coordinate_manager.cpp +++ b/device/blackhole/blackhole_coordinate_manager.cpp @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: (c) 2023 Tenstorrent Inc. + * SPDX-FileCopyrightText: (c) 2024 Tenstorrent Inc. * * SPDX-License-Identifier: Apache-2.0 */ @@ -18,12 +18,12 @@ std::set 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); +CoreCoord BlackholeCoordinateManager::translated_to_logical_tensix(const CoreCoord core_coord) { + const CoreCoord virtual_coord = CoreCoord(core_coord.x, core_coord.y, CoreType::TENSIX, CoordSystem::VIRTUAL); + return CoordinateManager::to_logical(virtual_coord); } -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); +CoreCoord BlackholeCoordinateManager::logical_to_translated_tensix(const CoreCoord core_coord) { + const CoreCoord virtual_coord = CoordinateManager::to_virtual(core_coord); + return CoreCoord(virtual_coord.x, virtual_coord.y, CoreType::TENSIX, CoordSystem::TRANSLATED); } diff --git a/device/blackhole/blackhole_coordinate_manager.h b/device/blackhole/blackhole_coordinate_manager.h index 6eef92eb..48d63afa 100644 --- a/device/blackhole/blackhole_coordinate_manager.h +++ b/device/blackhole/blackhole_coordinate_manager.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: (c) 2023 Tenstorrent Inc. + * SPDX-FileCopyrightText: (c) 2024 Tenstorrent Inc. * * SPDX-License-Identifier: Apache-2.0 */ @@ -14,10 +14,9 @@ class BlackholeCoordinateManager : public CoordinateManager { BlackholeCoordinateManager(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 to_translated_coords(tt_logical_coords logical_coords) override; +protected: + CoreCoord translated_to_logical_tensix(const CoreCoord core_coord) override; + CoreCoord logical_to_translated_tensix(const CoreCoord core_coord) override; - tt_logical_coords to_logical_coords(tt_translated_coords translated_coords) override; - -protected: std::set get_x_coordinates_to_harvest(std::size_t harvesting_mask) override; }; diff --git a/device/cluster.cpp b/device/cluster.cpp index 4b587468..3950bd94 100644 --- a/device/cluster.cpp +++ b/device/cluster.cpp @@ -2689,17 +2689,4 @@ tt_version Cluster::get_ethernet_fw_version() const { return eth_fw_version; } -// v1 functions -void Cluster::write_to_device(const void *mem_ptr, uint32_t size_in_bytes, chip_id_t chip, CoreCoord_V1 core_coord, uint64_t addr, const std::string& tlb_to_use) { - CoreCoord_V1 physical_core_coord = coordinate_manager->to_physical(core_coord); - - -} - -void Cluster::read_from_device(void* mem_ptr, chip_id_t chip, CoreCoord_V1 core_coord, uint64_t addr, uint32_t size, const std::string& fallback_tlb) { - CoreCoord_V1 physical_core_coord = coordinate_manager->to_physical(core_coord); - - -} - } \ No newline at end of file diff --git a/device/cluster.h b/device/cluster.h index f65753b0..b332e3be 100644 --- a/device/cluster.h +++ b/device/cluster.h @@ -710,8 +710,8 @@ class Cluster: public tt_device PCIDevice *get_pci_device(int device_id) const; // Core coordinates functions - virtual void write_to_device(const void *mem_ptr, uint32_t size_in_bytes, chip_id_t chip, CoreCoord_V1 core_coord, uint64_t addr); - virtual void read_from_device(void* mem_ptr, uint32_t size_in_bytes, chip_id_t chip, CoreCoord_V1 core_coord, uint64_t addr); + // virtual void write_to_device(const void *mem_ptr, uint32_t size_in_bytes, chip_id_t chip, CoreCoord core_coord, uint64_t addr); + // virtual void read_from_device(void* mem_ptr, uint32_t size_in_bytes, chip_id_t chip, CoreCoord core_coord, uint64_t addr); // Destructor virtual ~Cluster (); diff --git a/device/coordinate_manager.cpp b/device/coordinate_manager.cpp index 32406693..0181a143 100644 --- a/device/coordinate_manager.cpp +++ b/device/coordinate_manager.cpp @@ -5,59 +5,118 @@ */ #include "device/coordinate_manager.h" #include +#include #include "coordinate_manager.h" #include "grayskull/grayskull_coordinate_manager.h" +#include "tt_core_coordinates.h" -tt_physical_coords CoordinateManager::to_physical_coords(tt_logical_coords logical_coords) { - return tt_physical_coords(logical_x_to_physical_x[logical_coords.x], logical_y_to_physical_y[logical_coords.y]); -} - -// TODO(pjanevski): this is different for Wormhole and Blackhole. -// investigate and implement -tt_translated_coords CoordinateManager::to_translated_coords(tt_logical_coords logical_coords) { - tt_physical_coords physical_coords = to_physical_coords(logical_coords); - return tt_translated_coords(physical_coords.x, physical_coords.y); -} - -tt_virtual_coords CoordinateManager::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::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_virtual_coords CoordinateManager::to_virtual_coords(tt_physical_coords physical_coords) { - return to_virtual_coords(to_logical_coords(physical_coords)); +CoreCoord CoordinateManager::to_tensix_physical(const CoreCoord core_coord) { + switch (core_coord.coord_system) { + case CoordSystem::LOGICAL: + return CoreCoord{logical_x_to_physical_x[core_coord.x], logical_y_to_physical_y[core_coord.y], CoreType::TENSIX, CoordSystem::PHYSICAL}; + case CoordSystem::PHYSICAL: + return core_coord; + case CoordSystem::VIRTUAL: + return CoreCoord{logical_x_to_physical_x[virtual_x_to_logical_x[core_coord.x]], logical_y_to_physical_y[virtual_y_to_logical_y[core_coord.y]], CoreType::TENSIX, CoordSystem::PHYSICAL}; + case CoordSystem::TRANSLATED: + return to_tensix_physical(translated_to_logical_tensix(core_coord)); + } } -tt_translated_coords CoordinateManager::to_translated_coords(tt_physical_coords physical_coords) { - return to_translated_coords(to_logical_coords(physical_coords)); +CoreCoord CoordinateManager::to_tensix_virtual(const CoreCoord core_coord) { + switch (core_coord.coord_system) { + case CoordSystem::LOGICAL: + return CoreCoord{logical_x_to_virtual_x[core_coord.x], logical_y_to_virtual_y[core_coord.y], CoreType::TENSIX, CoordSystem::VIRTUAL}; + case CoordSystem::PHYSICAL: + return CoreCoord{virtual_x_to_logical_x[core_coord.x], virtual_y_to_logical_y[core_coord.y], CoreType::TENSIX, CoordSystem::VIRTUAL}; + case CoordSystem::VIRTUAL: + return core_coord; + case CoordSystem::TRANSLATED: + return to_tensix_virtual(to_tensix_logical(core_coord)); + } } -tt_logical_coords CoordinateManager::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]); +CoreCoord CoordinateManager::to_tensix_logical(const CoreCoord core_coord) { + switch (core_coord.coord_system) { + case CoordSystem::LOGICAL: + return core_coord; + case CoordSystem::PHYSICAL: + return CoreCoord{physical_x_to_logical_x[core_coord.x], physical_y_to_logical_y[core_coord.y], CoreType::TENSIX, CoordSystem::LOGICAL}; + case CoordSystem::VIRTUAL: + return CoreCoord{virtual_x_to_logical_x[core_coord.x], virtual_y_to_logical_y[core_coord.y], CoreType::TENSIX, CoordSystem::LOGICAL}; + case CoordSystem::TRANSLATED: + return translated_to_logical_tensix(core_coord); + } } -tt_physical_coords CoordinateManager::to_physical_coords(tt_virtual_coords virtual_coords) { - return to_physical_coords(to_logical_coords(virtual_coords)); +CoreCoord CoordinateManager::to_tensix_translated(const CoreCoord core_coord) { + switch (core_coord.coord_system) { + case CoordSystem::LOGICAL: + return logical_to_translated_tensix(core_coord); + case CoordSystem::PHYSICAL: + return to_translated(to_tensix_logical(core_coord)); + case CoordSystem::VIRTUAL: + return to_translated(to_tensix_logical(core_coord)); + case CoordSystem::TRANSLATED: + return core_coord; + } } -tt_translated_coords CoordinateManager::to_translated_coords(tt_virtual_coords virtual_coords) { - return to_translated_coords(to_logical_coords(virtual_coords)); +CoreCoord CoordinateManager::to_physical(const CoreCoord core_coord) { + switch (core_coord.core_type) { + case CoreType::TENSIX: + return to_tensix_physical(core_coord); + case CoreType::DRAM: + case CoreType::ARC: + case CoreType::ACTIVE_ETH: + case CoreType::IDLE_ETH: + case CoreType::PCIE: + case CoreType::ROUTER_ONLY: + throw std::runtime_error("Core type is not supported for conversion to physical coordinates"); + } + throw std::runtime_error("Invalid coordinate system"); } -tt_logical_coords CoordinateManager::to_logical_coords(tt_translated_coords translated_coords) { - tt_physical_coords physical_coords = tt_physical_coords(translated_coords.x, translated_coords.y); - return to_logical_coords(physical_coords); +CoreCoord CoordinateManager::to_virtual(const CoreCoord core_coord) { + switch (core_coord.core_type) { + case CoreType::TENSIX: + return to_tensix_virtual(core_coord); + case CoreType::DRAM: + case CoreType::ARC: + case CoreType::ACTIVE_ETH: + case CoreType::IDLE_ETH: + case CoreType::PCIE: + case CoreType::ROUTER_ONLY: + throw std::runtime_error("Core type is not supported for conversion to virtual coordinates"); + } } -tt_physical_coords CoordinateManager::to_physical_coords(tt_translated_coords translated_coords) { - return to_physical_coords(to_logical_coords(translated_coords)); +CoreCoord CoordinateManager::to_logical(const CoreCoord core_coord) { + switch (core_coord.core_type) { + case CoreType::TENSIX: + return to_tensix_logical(core_coord); + case CoreType::DRAM: + case CoreType::ARC: + case CoreType::ACTIVE_ETH: + case CoreType::IDLE_ETH: + case CoreType::PCIE: + case CoreType::ROUTER_ONLY: + throw std::runtime_error("Core type is not supported for conversion to logical coordinates"); + } } -tt_virtual_coords CoordinateManager::to_virtual_coords(tt_translated_coords translated_coords) { - return to_virtual_coords(to_logical_coords(translated_coords)); +CoreCoord CoordinateManager::to_translated(const CoreCoord core_coord) { + switch (core_coord.core_type) { + case CoreType::TENSIX: + return to_tensix_translated(core_coord); + case CoreType::DRAM: + case CoreType::ARC: + case CoreType::ACTIVE_ETH: + case CoreType::IDLE_ETH: + case CoreType::PCIE: + case CoreType::ROUTER_ONLY: + throw std::runtime_error("Core type is not supported for conversion to translated coordinates"); + } } void CoordinateManager::clear_harvesting_structures() { @@ -190,3 +249,13 @@ std::unique_ptr CoordinateManager::get_coordinate_manager( throw std::runtime_error("Invalid architecture for creating coordinate manager"); } + +// TODO(pjanevski): these functions should be deleted once +// deep copy of CoordinateManager for SocDescriptor is implemented +CoreCoord CoordinateManager::translated_to_logical_tensix(const CoreCoord core_coord) { + return core_coord; +} + +CoreCoord CoordinateManager::logical_to_translated_tensix(const CoreCoord core_coord) { + return core_coord; +} \ No newline at end of file diff --git a/device/coordinate_manager.h b/device/coordinate_manager.h index 814f7756..864f844b 100644 --- a/device/coordinate_manager.h +++ b/device/coordinate_manager.h @@ -22,22 +22,6 @@ class CoordinateManager { virtual void perform_harvesting(std::size_t harvesting_mask); - virtual tt_physical_coords to_physical_coords(tt_logical_coords logical_coords); - virtual tt_translated_coords to_translated_coords(tt_logical_coords logical_coords); - virtual tt_virtual_coords to_virtual_coords(tt_logical_coords logical_coords); - - virtual tt_logical_coords to_logical_coords(tt_physical_coords physical_coords); - virtual tt_virtual_coords to_virtual_coords(tt_physical_coords physical_coords); - virtual tt_translated_coords to_translated_coords(tt_physical_coords physical_coords); - - virtual tt_logical_coords to_logical_coords(tt_virtual_coords virtual_coords); - virtual tt_physical_coords to_physical_coords(tt_virtual_coords virtual_coords); - virtual tt_translated_coords to_translated_coords(tt_virtual_coords virtual_coords); - - virtual tt_logical_coords to_logical_coords(tt_translated_coords translated_coords); - virtual tt_physical_coords to_physical_coords(tt_translated_coords translated_coords); - virtual tt_virtual_coords to_virtual_coords(tt_translated_coords translated_coords); - static std::unique_ptr get_coordinate_manager( tt::ARCH arch, const tt_xy_pair& worker_grid_size, @@ -46,14 +30,10 @@ class CoordinateManager { CoordinateManager(CoordinateManager& other) = default; - // v1 functions - // We need only one function per coordinate system for all core types. - virtual CoreCoord_V1 to_physical(const CoreCoord_V1 core_coords); - - // v2 functions - // We need as many functions as there are core types for each coordinate system. - virtual TensixCoreCoord_V2 to_physical(const TensixCoreCoord_V2 tensix_coords); - virtual DramCoreCoord_V2 to_physical(const DramCoreCoord_V2 dram_coords); + CoreCoord to_physical(const CoreCoord core_coord); + CoreCoord to_logical(const CoreCoord core_coord); + CoreCoord to_virtual(const CoreCoord core_coord); + CoreCoord to_translated(const CoreCoord core_coord); virtual ~CoordinateManager() = default; @@ -68,9 +48,15 @@ class CoordinateManager { const std::set& physical_x_unharvested, const std::set& physical_y_unharvested); virtual void fill_logical_to_virtual_mapping(const std::set& physical_x_unharvested, const std::set& physical_y_unharvested); - // Helper functions for V1. - virtual CoreCoord_V1 to_tensix_physical(const CoreCoord_V1 core_coords); - virtual CoreCoord_V1 to_dram_physical(const CoreCoord_V1 core_coords); + CoreCoord to_tensix_physical(const CoreCoord core_coord); + CoreCoord to_tensix_logical(const CoreCoord core_coord); + CoreCoord to_tensix_virtual(const CoreCoord core_coord); + CoreCoord to_tensix_translated(const CoreCoord core_coord); + + // TODO(pjanevski): this should be abstract functions + // Making deep copy of SocDescriptor is harded if these are abstract + virtual CoreCoord translated_to_logical_tensix(const CoreCoord core_coord); + virtual CoreCoord logical_to_translated_tensix(const CoreCoord core_coord); std::map physical_y_to_logical_y; std::map physical_x_to_logical_x; diff --git a/device/grayskull/grayskull_coordinate_manager.cpp b/device/grayskull/grayskull_coordinate_manager.cpp new file mode 100644 index 00000000..e61685c4 --- /dev/null +++ b/device/grayskull/grayskull_coordinate_manager.cpp @@ -0,0 +1,16 @@ +/* + * SPDX-FileCopyrightText: (c) 2024 Tenstorrent Inc. + * + * SPDX-License-Identifier: Apache-2.0 + */ +#include "grayskull_coordinate_manager.h" + +CoreCoord GrayskullCoordinateManager::translated_to_logical_tensix(const CoreCoord core_coord) { + const CoreCoord physical_coord = CoreCoord(core_coord.x, core_coord.y, CoreType::TENSIX, CoordSystem::PHYSICAL); + return CoordinateManager::to_logical(physical_coord); +} + +CoreCoord GrayskullCoordinateManager::logical_to_translated_tensix(const CoreCoord core_coord) { + const CoreCoord physical_coord = CoordinateManager::to_physical(core_coord); + return CoreCoord(physical_coord.x, physical_coord.y, CoreType::TENSIX, CoordSystem::TRANSLATED); +} \ No newline at end of file diff --git a/device/grayskull/grayskull_coordinate_manager.h b/device/grayskull/grayskull_coordinate_manager.h index ac6ee60d..0de31ecc 100644 --- a/device/grayskull/grayskull_coordinate_manager.h +++ b/device/grayskull/grayskull_coordinate_manager.h @@ -13,4 +13,8 @@ class GrayskullCoordinateManager : public CoordinateManager { public: GrayskullCoordinateManager(const tt_xy_pair& worker_grid_size, const std::vector& workers, std::size_t harvesting_mask) : CoordinateManager(worker_grid_size, workers, harvesting_mask) {} + +protected: + CoreCoord translated_to_logical_tensix(const CoreCoord core_coord) override; + CoreCoord logical_to_translated_tensix(const CoreCoord core_coord) override; }; diff --git a/device/tt_core_coordinates.h b/device/tt_core_coordinates.h index 660d6a08..44fbc4ee 100644 --- a/device/tt_core_coordinates.h +++ b/device/tt_core_coordinates.h @@ -12,7 +12,6 @@ /* * CoordSystem is an enum class that represents all types of coordinate * systems that can be used to represent a core's location. - * This is used both for V1 and V2. */ enum class CoordSystem { LOGICAL, @@ -21,9 +20,6 @@ enum class CoordSystem { TRANSLATED, }; -// ************************************************************************************************ -// V1 - /* * CoreType is an enum class that represents all types of cores * present on the Tenstorrent chip. @@ -31,27 +27,22 @@ enum class CoordSystem { enum class CoreType { ARC, DRAM, - ETH, + ACTIVE_ETH, + IDLE_ETH, PCIE, TENSIX, ROUTER_ONLY, + // TODO: this keeps compatibility with existing code in SocDescriptor + // but it won't be needed later on + HARVESTED, + ETH, }; - struct CoreCoord_V1 : public tt_xy_pair { - CoreType core_type; - CoordSystem coord_system; - }; + struct CoreCoord : public tt_xy_pair { + CoreCoord() {} + CoreCoord(const size_t x, const size_t y, const CoreType type, const CoordSystem coord_system) + : tt_xy_pair(x, y), core_type(type), coord_system(coord_system) {} -// ************************************************************************************************ -// V2 -struct CoreCoord_V2 : public tt_xy_pair { + CoreType core_type; CoordSystem coord_system; -}; - -struct TensixCoreCoord_V2 : public CoreCoord_V2 { - -}; - -struct DramCoreCoord_V2 : public CoreCoord_V2 { - -}; \ No newline at end of file + }; \ No newline at end of file diff --git a/device/tt_soc_descriptor.cpp b/device/tt_soc_descriptor.cpp index ecfecc4b..86d1f618 100644 --- a/device/tt_soc_descriptor.cpp +++ b/device/tt_soc_descriptor.cpp @@ -174,52 +174,20 @@ void tt_SocDescriptor::perform_harvesting(std::size_t harvesting_mask) { coordinate_manager->perform_harvesting(harvesting_mask); } -tt_physical_coords tt_SocDescriptor::to_physical_coords(tt_logical_coords logical_coords) { - return coordinate_manager->to_physical_coords(logical_coords); +CoreCoord tt_SocDescriptor::to_physical(const CoreCoord core_coord) { + return coordinate_manager->to_physical(core_coord); } -tt_virtual_coords tt_SocDescriptor::to_virtual_coords(tt_logical_coords logical_coords) { - return coordinate_manager->to_virtual_coords(logical_coords); +CoreCoord tt_SocDescriptor::to_logical(const CoreCoord core_coord) { + return coordinate_manager->to_logical(core_coord); } -tt_translated_coords tt_SocDescriptor::to_translated_coords(tt_logical_coords logical_coords) { - return coordinate_manager->to_translated_coords(logical_coords); +CoreCoord tt_SocDescriptor::to_virtual(const CoreCoord core_coord) { + return coordinate_manager->to_virtual(core_coord); } -tt_logical_coords tt_SocDescriptor::to_logical_coords(tt_physical_coords physical_coords) { - return coordinate_manager->to_logical_coords(physical_coords); -} - -tt_virtual_coords tt_SocDescriptor::to_virtual_coords(tt_physical_coords physical_coords) { - return coordinate_manager->to_virtual_coords(physical_coords); -} - -tt_translated_coords tt_SocDescriptor::to_translated_coords(tt_physical_coords physical_coords) { - return coordinate_manager->to_translated_coords(physical_coords); -} - -tt_logical_coords tt_SocDescriptor::to_logical_coords(tt_virtual_coords virtual_coords) { - return coordinate_manager->to_logical_coords(virtual_coords); -} - -tt_physical_coords tt_SocDescriptor::to_physical_coords(tt_virtual_coords virtual_coords) { - return coordinate_manager->to_physical_coords(virtual_coords); -} - -tt_translated_coords tt_SocDescriptor::to_translated_coords(tt_virtual_coords virtual_coords) { - return coordinate_manager->to_translated_coords(virtual_coords); -} - -tt_logical_coords tt_SocDescriptor::to_logical_coords(tt_translated_coords translated_coords) { - return coordinate_manager->to_logical_coords(translated_coords); -} - -tt_physical_coords tt_SocDescriptor::to_physical_coords(tt_translated_coords translated_coords) { - return coordinate_manager->to_physical_coords(translated_coords); -} - -tt_virtual_coords tt_SocDescriptor::to_virtual_coords(tt_translated_coords translated_coords) { - return coordinate_manager->to_virtual_coords(translated_coords); +CoreCoord tt_SocDescriptor::to_translated(const CoreCoord core_coord) { + return coordinate_manager->to_translated(core_coord); } tt_SocDescriptor::tt_SocDescriptor(std::string device_descriptor_path, std::size_t harvesting_mask) { diff --git a/device/tt_soc_descriptor.h b/device/tt_soc_descriptor.h index 0b91cd5f..1b9dfcbd 100644 --- a/device/tt_soc_descriptor.h +++ b/device/tt_soc_descriptor.h @@ -156,24 +156,11 @@ class tt_SocDescriptor { coordinate_manager.reset(new CoordinateManager(*other.coordinate_manager)); } - // Coordinate conversions. - - // Conversions from logical coordinates should be used just for worker cores. - tt_physical_coords to_physical_coords(tt_logical_coords logical_coords); - tt_virtual_coords to_virtual_coords(tt_logical_coords logical_coords); - tt_translated_coords to_translated_coords(tt_logical_coords logical_coords); - - tt_logical_coords to_logical_coords(tt_physical_coords physical_coords); - tt_virtual_coords to_virtual_coords(tt_physical_coords physical_coords); - tt_translated_coords to_translated_coords(tt_physical_coords physical_coords); - - tt_logical_coords to_logical_coords(tt_virtual_coords virtual_coords); - tt_physical_coords to_physical_coords(tt_virtual_coords virtual_coords); - tt_translated_coords to_translated_coords(tt_virtual_coords virtual_coords); - - tt_logical_coords to_logical_coords(tt_translated_coords translated_coords); - tt_physical_coords to_physical_coords(tt_translated_coords translated_coords); - tt_virtual_coords to_virtual_coords(tt_translated_coords translated_coords); + // CoreCoord conversions. + CoreCoord to_physical(const CoreCoord core_coord); + CoreCoord to_logical(const CoreCoord core_coord); + CoreCoord to_virtual(const CoreCoord core_coord); + CoreCoord to_translated(const CoreCoord core_coord); void perform_harvesting(std::size_t harvesting_mask); diff --git a/device/tt_xy_pair.h b/device/tt_xy_pair.h index fde3b457..ba2d817e 100644 --- a/device/tt_xy_pair.h +++ b/device/tt_xy_pair.h @@ -11,48 +11,4 @@ #include "device/xy_pair.h" using tt_xy_pair = tt::umd::xy_pair; -using tt_cxy_pair = tt::umd::cxy_pair; - -struct tt_physical_coords : public tt_xy_pair { - tt_physical_coords() : tt_xy_pair() {} - tt_physical_coords(std::size_t x, std::size_t y) : tt_xy_pair(x, y) {} -}; - -struct tt_chip_physical_coords : public tt_cxy_pair { - tt_chip_physical_coords() : tt_cxy_pair() {} - tt_chip_physical_coords(std::size_t ichip, xy_pair pair) : tt_cxy_pair(ichip, pair) {} - tt_chip_physical_coords(std::size_t ichip, std::size_t x, std::size_t y) : tt_cxy_pair(ichip, x, y) {} -}; - -struct tt_logical_coords : public tt_xy_pair { - tt_logical_coords() : tt_xy_pair() {} - tt_logical_coords(std::size_t x, std::size_t y) : tt_xy_pair(x, y) {} -}; - -struct tt_chip_logical_coords : public tt_cxy_pair { - tt_chip_logical_coords() : tt_cxy_pair() {} - tt_chip_logical_coords(std::size_t ichip, xy_pair pair) : tt_cxy_pair(ichip, pair) {} - tt_chip_logical_coords(std::size_t ichip, std::size_t x, std::size_t y) : tt_cxy_pair(ichip, x, y) {} -}; - -struct tt_virtual_coords : public tt_xy_pair { - tt_virtual_coords() : tt_xy_pair() {} - tt_virtual_coords(std::size_t x, std::size_t y) : tt_xy_pair(x, y) {} -}; - -struct tt_chip_virtual_coords : public tt_cxy_pair { - tt_chip_virtual_coords() : tt_cxy_pair() {} - tt_chip_virtual_coords(std::size_t ichip, xy_pair pair) : tt_cxy_pair(ichip, pair) {} - tt_chip_virtual_coords(std::size_t ichip, std::size_t x, std::size_t y) : tt_cxy_pair(ichip, x, y) {} -}; - -struct tt_translated_coords : public tt_xy_pair { - tt_translated_coords() : tt_xy_pair() {} - tt_translated_coords(std::size_t x, std::size_t y) : tt_xy_pair(x, y) {} -}; - -struct tt_chip_translated_coords : public tt_cxy_pair { - tt_chip_translated_coords() : tt_cxy_pair() {} - tt_chip_translated_coords(std::size_t ichip, xy_pair pair) : tt_cxy_pair(ichip, pair) {} - tt_chip_translated_coords(std::size_t ichip, std::size_t x, std::size_t y) : tt_cxy_pair(ichip, x, y) {} -}; +using tt_cxy_pair = tt::umd::cxy_pair; \ No newline at end of file diff --git a/device/wormhole/wormhole_coordinate_manager.cpp b/device/wormhole/wormhole_coordinate_manager.cpp index 67915470..e163f48d 100644 --- a/device/wormhole/wormhole_coordinate_manager.cpp +++ b/device/wormhole/wormhole_coordinate_manager.cpp @@ -18,111 +18,10 @@ std::set WormholeCoordinateManager::get_y_coordinates_to_harvest(st return y_to_harvest; } -tt_translated_coords WormholeCoordinateManager::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); +CoreCoord WormholeCoordinateManager::translated_to_logical_tensix(const CoreCoord core_coord) { + return CoreCoord{core_coord.x - translated_coordinate_start_x, core_coord.y - translated_coordinate_start_y, CoreType::TENSIX, CoordSystem::LOGICAL}; } -tt_logical_coords WormholeCoordinateManager::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); -} - -// General ways of how we translate coordinates is not a key part of this PR. -// Main things to look at here is the way we are using the functions to translate coordinates -// To understand how the translations works for V1 and V2, based on struct types. - -// v1 functions -CoreCoord_V1 WormholeCoordinateManager::to_tensix_physical(CoreCoord_V1 core_coords) { - CoreCoord_V1 physical_tensix_coords; - physical_tensix_coords.coord_system = CoordSystem::PHYSICAL; - physical_tensix_coords.core_type = CoreType::TENSIX; - switch (core_coords.coord_system) { - case CoordSystem::LOGICAL: - physical_tensix_coords.x = logical_x_to_physical_x[core_coords.x]; - physical_tensix_coords.y = logical_y_to_physical_y[core_coords.y]; - case CoordSystem::PHYSICAL: - return core_coords; - case CoordSystem::VIRTUAL: - physical_tensix_coords.x = logical_x_to_physical_x[virtual_x_to_logical_x[core_coords.x]]; - physical_tensix_coords.y = logical_y_to_physical_y[virtual_y_to_logical_y[core_coords.y]]; - case CoordSystem::TRANSLATED: - physical_tensix_coords.x = logical_x_to_physical_x[core_coords.x - translated_coordinate_start_x]; - physical_tensix_coords.y = logical_y_to_physical_y[core_coords.y - translated_coordinate_start_y]; - } - - return physical_tensix_coords; -} - -CoreCoord_V1 WormholeCoordinateManager::to_dram_physical(CoreCoord_V1 core_coords) { - CoreCoord_V1 physical_dram_coords; - physical_dram_coords.coord_system = CoordSystem::PHYSICAL; - physical_dram_coords.core_type = CoreType::DRAM; - switch(core_coords.coord_system) { - case CoordSystem::LOGICAL: - - case CoordSystem::PHYSICAL: - return core_coords; - case CoordSystem::VIRTUAL: - physical_dram_coords.x = core_coords.x; - physical_dram_coords.y = core_coords.y; - case CoordSystem::TRANSLATED: - physical_dram_coords.x = core_coords.x; - physical_dram_coords.y = core_coords.y; - } - - return physical_dram_coords; -} - -CoreCoord_V1 WormholeCoordinateManager::to_physical(CoreCoord_V1 core_coords) { - switch (core_coords.core_type) { - case CoreType::TENSIX: - return to_tensix_physical(core_coords); - case CoreType::DRAM: - return to_dram_physical(core_coords); - } - - throw std::runtime_error("Invalid core type"); -} - -// v2 functions -TensixCoreCoord_V2 WormholeCoordinateManager::to_physical(TensixCoreCoord_V2 tensix_coords) { - TensixCoreCoord_V2 physical_tensix_coords; - physical_tensix_coords.coord_system = CoordSystem::PHYSICAL; - switch (tensix_coords.coord_system) { - case CoordSystem::LOGICAL: - physical_tensix_coords.x = logical_x_to_physical_x[tensix_coords.x]; - physical_tensix_coords.y = logical_y_to_physical_y[tensix_coords.y]; - case CoordSystem::PHYSICAL: - return tensix_coords; - case CoordSystem::VIRTUAL: - physical_tensix_coords.x = logical_x_to_physical_x[virtual_x_to_logical_x[tensix_coords.x]]; - physical_tensix_coords.y = logical_y_to_physical_y[virtual_y_to_logical_y[tensix_coords.y]]; - case CoordSystem::TRANSLATED: - physical_tensix_coords.x = logical_x_to_physical_x[tensix_coords.x - translated_coordinate_start_x]; - physical_tensix_coords.y = logical_y_to_physical_y[tensix_coords.y - translated_coordinate_start_y]; - } - - return physical_tensix_coords; -} - -DramCoreCoord_V2 WormholeCoordinateManager::to_physical(DramCoreCoord_V2 dram_coords) { - DramCoreCoord_V2 physical_dram_coords; - physical_dram_coords.coord_system = CoordSystem::PHYSICAL; - switch(dram_coords.coord_system) { - case CoordSystem::LOGICAL: - // TODO implement logical to physical translation for dram coordinates - // but that for review it is not important how that logic is going to look like - return dram_coords; - case CoordSystem::PHYSICAL: - return dram_coords; - case CoordSystem::VIRTUAL: - // virtual coords for DRAM same as physical for Wormhole. - physical_dram_coords.x = dram_coords.x; - physical_dram_coords.y = dram_coords.y; - case CoordSystem::TRANSLATED: - // translated coords for DRAM same as physical for Wormhole. - physical_dram_coords.x = dram_coords.x; - physical_dram_coords.y = dram_coords.y; - } - - return physical_dram_coords; -} +CoreCoord WormholeCoordinateManager::logical_to_translated_tensix(const CoreCoord core_coord) { + return CoreCoord{core_coord.x + translated_coordinate_start_x, core_coord.y + translated_coordinate_start_y, CoreType::TENSIX, CoordSystem::TRANSLATED}; +} \ No newline at end of file diff --git a/device/wormhole/wormhole_coordinate_manager.h b/device/wormhole/wormhole_coordinate_manager.h index fefaeedc..38d16feb 100644 --- a/device/wormhole/wormhole_coordinate_manager.h +++ b/device/wormhole/wormhole_coordinate_manager.h @@ -13,24 +13,12 @@ class WormholeCoordinateManager : public CoordinateManager { public: 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 to_translated_coords(tt_logical_coords logical_coords) override; - - tt_logical_coords to_logical_coords(tt_translated_coords translated_coords) override; - - // v1 functions - CoreCoord_V1 to_physical(CoreCoord_V1 core_coords) override; - - // v2 functions - TensixCoreCoord_V2 to_physical(TensixCoreCoord_V2 tensix_coords) override; - DramCoreCoord_V2 to_physical(DramCoreCoord_V2 dram_coords) override; - -protected: +protected: + CoreCoord translated_to_logical_tensix(const CoreCoord core_coord) override; + CoreCoord logical_to_translated_tensix(const CoreCoord core_coord) override; + std::set get_y_coordinates_to_harvest(std::size_t harvesting_mask) override; - CoreCoord_V1 to_tensix_physical(const CoreCoord_V1 core_coords) override; - CoreCoord_V1 to_dram_physical(const CoreCoord_V1 core_coords) override; - 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 243da1b3..bf6c14cd 100644 --- a/tests/api/CMakeLists.txt +++ b/tests/api/CMakeLists.txt @@ -2,9 +2,9 @@ set(API_TESTS_SRCS test_chip.cpp test_cluster_descriptor.cpp test_cluster.cpp - test_soc_descriptor_gs.cpp - test_soc_descriptor_wh.cpp - test_soc_descriptor_bh.cpp + test_core_coord_translation_gs.cpp + test_core_coord_translation_wh.cpp + test_core_coord_translation_bh.cpp test_mockup_device.cpp test_core_coordinates.cpp ) diff --git a/tests/api/test_soc_descriptor_bh.cpp b/tests/api/test_core_coord_translation_bh.cpp similarity index 79% rename from tests/api/test_soc_descriptor_bh.cpp rename to tests/api/test_core_coord_translation_bh.cpp index 8032d02c..a05544fa 100644 --- a/tests/api/test_soc_descriptor_bh.cpp +++ b/tests/api/test_core_coord_translation_bh.cpp @@ -35,9 +35,9 @@ TEST(SocDescriptor, SocDescriptorBHNoHarvesting) { 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.to_virtual_coords(logical_coords); - tt_physical_coords physical_coords = soc_desc.to_physical_coords(logical_coords); + CoreCoord logical_coords = CoreCoord(x, y, CoreType::TENSIX, CoordSystem::LOGICAL); + CoreCoord virtual_coords = soc_desc.to_virtual(logical_coords); + CoreCoord physical_coords = soc_desc.to_physical(logical_coords); // Virtual and physical coordinates should be the same. EXPECT_EQ(physical_coords, virtual_coords); @@ -52,15 +52,15 @@ 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); + CoreCoord logical_coords = CoreCoord(0, 0, CoreType::TENSIX, CoordSystem::LOGICAL); // Always expect same virtual coordinate for (0, 0) logical coordinate. - tt_virtual_coords virtual_cords = soc_desc.to_virtual_coords(logical_coords); - EXPECT_EQ(virtual_cords, tt_virtual_coords(1, 2)); + CoreCoord virtual_cords = soc_desc.to_virtual(logical_coords); + EXPECT_EQ(virtual_cords, CoreCoord(1, 2, CoreType::TENSIX, CoordSystem::VIRTUAL)); // This depends on harvesting mask. So expected physical coord is specific to this test and Blackhole arch. - tt_physical_coords physical_cords = soc_desc.to_physical_coords(logical_coords); - EXPECT_EQ(physical_cords, tt_physical_coords(2, 2)); + CoreCoord physical_cords = soc_desc.to_physical(logical_coords); + EXPECT_EQ(physical_cords, CoreCoord(2, 2, CoreType::TENSIX, CoordSystem::PHYSICAL)); } // Test logical to physical coordinate translation. @@ -74,16 +74,16 @@ TEST(SocDescriptor, SocDescriptorBHLogicalPhysicalMapping) { soc_desc.perform_harvesting(harvesting_mask); - std::map logical_to_physical; - std::set physical_coords_set; + 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.to_physical_coords(logical_coords); + CoreCoord logical_coords = CoreCoord(x, y, CoreType::TENSIX, CoordSystem::LOGICAL); + CoreCoord physical_coords = soc_desc.to_physical(logical_coords); logical_to_physical[logical_coords] = physical_coords; // Expect that logical to physical translation is 1-1 mapping. No duplicates for physical coordinates. @@ -95,8 +95,8 @@ TEST(SocDescriptor, SocDescriptorBHLogicalPhysicalMapping) { 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.to_logical_coords(physical_coords); + CoreCoord physical_coords = it.second; + CoreCoord logical_coords = soc_desc.to_logical(physical_coords); // Expect that reverse mapping of physical coordinates gives the same logical coordinates // using which we got the physical coordinates. @@ -116,16 +116,16 @@ TEST(SocDescriptor, SocDescriptorBHLogicalVirtualMapping) { soc_desc.perform_harvesting(harvesting_mask); - std::map logical_to_virtual; - std::set virtual_coords_set; + 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.to_virtual_coords(logical_coords); + CoreCoord logical_coords = CoreCoord(x, y, CoreType::TENSIX, CoordSystem::LOGICAL); + CoreCoord virtual_coords = soc_desc.to_virtual(logical_coords); logical_to_virtual[logical_coords] = virtual_coords; // Expect that logical to virtual translation is 1-1 mapping. No duplicates for virtual coordinates. @@ -137,8 +137,8 @@ TEST(SocDescriptor, SocDescriptorBHLogicalVirtualMapping) { 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.to_logical_coords(virtual_coords); + CoreCoord virtual_coords = it.second; + CoreCoord logical_coords = soc_desc.to_logical(virtual_coords); // Expect that reverse mapping of virtual coordinates gives the same logical coordinates // using which we got the virtual coordinates. @@ -158,16 +158,16 @@ TEST(SocDescriptor, SocDescriptorBHLogicalTranslatedMapping) { soc_desc.perform_harvesting(harvesting_mask); - std::map logical_to_translated; - std::set translated_coords_set; + std::map logical_to_translated; + std::set 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); + CoreCoord logical_coords = CoreCoord(x, y, CoreType::TENSIX, CoordSystem::LOGICAL); + CoreCoord translated_coords = soc_desc.to_translated(logical_coords); logical_to_translated[logical_coords] = translated_coords; // Expect that logical to translated translation is 1-1 mapping. No duplicates for translated coordinates. @@ -179,8 +179,8 @@ TEST(SocDescriptor, SocDescriptorBHLogicalTranslatedMapping) { 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); + CoreCoord translated_coords = it.second; + CoreCoord logical_coords = soc_desc.to_logical(translated_coords); // Expect that reverse mapping of translated coordinates gives the same logical coordinates // using which we got the translated coordinates. @@ -201,9 +201,9 @@ TEST(SocDescriptor, SocDescriptorBHVirtualEqualTranslated) { 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); + CoreCoord logical_coords = CoreCoord(x, y, CoreType::TENSIX, CoordSystem::LOGICAL); + CoreCoord translated_coords = soc_desc.to_translated(logical_coords); + CoreCoord virtual_coords = soc_desc.to_virtual(logical_coords); // Expect that translated coordinates are same as virtual coordinates. EXPECT_EQ(translated_coords, virtual_coords); diff --git a/tests/api/test_soc_descriptor_gs.cpp b/tests/api/test_core_coord_translation_gs.cpp similarity index 76% rename from tests/api/test_soc_descriptor_gs.cpp rename to tests/api/test_core_coord_translation_gs.cpp index 1c72449b..00938809 100644 --- a/tests/api/test_soc_descriptor_gs.cpp +++ b/tests/api/test_core_coord_translation_gs.cpp @@ -34,9 +34,9 @@ TEST(SocDescriptor, SocDescriptorGSNoHarvesting) { 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.to_virtual_coords(logical_coords); - tt_physical_coords physical_coords = soc_desc.to_physical_coords(logical_coords); + CoreCoord logical_coords = CoreCoord(x, y, CoreType::TENSIX, CoordSystem::LOGICAL); + CoreCoord virtual_coords = soc_desc.to_virtual(logical_coords); + CoreCoord physical_coords = soc_desc.to_physical(logical_coords); // Virtual and physical coordinates should be the same. EXPECT_EQ(physical_coords, virtual_coords); @@ -52,15 +52,15 @@ 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); + CoreCoord logical_coords = CoreCoord(0, 0, CoreType::TENSIX, CoordSystem::LOGICAL); // Always expect same virtual coordinate for (0, 0) logical coordinate. - tt_virtual_coords virtual_cords = soc_desc.to_virtual_coords(logical_coords); - EXPECT_EQ(virtual_cords, tt_virtual_coords(1, 1)); + CoreCoord virtual_cords = soc_desc.to_virtual(logical_coords); + EXPECT_EQ(virtual_cords, CoreCoord(1, 1, CoreType::TENSIX, CoordSystem::VIRTUAL)); // This depends on harvesting mask. So expected physical coord is specific to this test and Wormhole arch. - tt_physical_coords physical_cords = soc_desc.to_physical_coords(logical_coords); - EXPECT_EQ(physical_cords, tt_physical_coords(1, 1)); + CoreCoord physical_cords = soc_desc.to_physical(logical_coords); + EXPECT_EQ(physical_cords, CoreCoord(1, 1, CoreType::TENSIX, CoordSystem::PHYSICAL)); } // Test logical to physical, virtual and translated coordinates. @@ -71,10 +71,10 @@ TEST(SocDescriptor, SocDescriptorGSTranslatingCoords) { 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.to_virtual_coords(logical_coords); - tt_physical_coords physical_coords = soc_desc.to_physical_coords(logical_coords); - tt_translated_coords translated_coords = soc_desc.to_translated_coords(logical_coords); + CoreCoord logical_coords = CoreCoord(x, y, CoreType::TENSIX, CoordSystem::LOGICAL); + CoreCoord virtual_coords = soc_desc.to_virtual(logical_coords); + CoreCoord physical_coords = soc_desc.to_physical(logical_coords); + CoreCoord translated_coords = soc_desc.to_translated(logical_coords); // Virtual, physical and translated coordinates should be the same. EXPECT_EQ(physical_coords, virtual_coords); @@ -90,14 +90,14 @@ 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; + 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.to_physical_coords(logical_coords); + CoreCoord logical_coords = CoreCoord(x, y, CoreType::TENSIX, CoordSystem::LOGICAL); + CoreCoord physical_coords = soc_desc.to_physical(logical_coords); logical_to_physical[logical_coords] = physical_coords; // Expect that logical to physical translation is 1-1 mapping. No duplicates for physical coordinates. @@ -109,8 +109,8 @@ TEST(SocDescriptor, SocDescriptorGSLogicalPhysicalMapping) { 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.to_logical_coords(physical_coords); + CoreCoord physical_coords = it.second; + CoreCoord logical_coords = soc_desc.to_logical(physical_coords); // Expect that reverse mapping of physical coordinates gives the same logical coordinates // using which we got the physical coordinates. @@ -125,14 +125,14 @@ 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; + 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.to_virtual_coords(logical_coords); + CoreCoord logical_coords = CoreCoord(x, y, CoreType::TENSIX, CoordSystem::LOGICAL); + CoreCoord virtual_coords = soc_desc.to_virtual(logical_coords); logical_to_virtual[logical_coords] = virtual_coords; // Expect that logical to virtual translation is 1-1 mapping. No duplicates for virtual coordinates. @@ -144,8 +144,8 @@ TEST(SocDescriptor, SocDescriptorGSLogicalVirtualMapping) { 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.to_logical_coords(virtual_coords); + CoreCoord virtual_coords = it.second; + CoreCoord logical_coords = soc_desc.to_logical(virtual_coords); // Expect that reverse mapping of virtual coordinates gives the same logical coordinates // using which we got the virtual coordinates. diff --git a/tests/api/test_soc_descriptor_wh.cpp b/tests/api/test_core_coord_translation_wh.cpp similarity index 76% rename from tests/api/test_soc_descriptor_wh.cpp rename to tests/api/test_core_coord_translation_wh.cpp index 37923210..9a9dee84 100644 --- a/tests/api/test_soc_descriptor_wh.cpp +++ b/tests/api/test_core_coord_translation_wh.cpp @@ -37,9 +37,9 @@ TEST(SocDescriptor, SocDescriptorWHNoHarvesting) { 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.to_virtual_coords(logical_coords); - tt_physical_coords physical_coords = soc_desc.to_physical_coords(logical_coords); + CoreCoord logical_coords = CoreCoord(x, y, CoreType::TENSIX, CoordSystem::LOGICAL); + CoreCoord virtual_coords = soc_desc.to_virtual(logical_coords); + CoreCoord physical_coords = soc_desc.to_physical(logical_coords); // Virtual and physical coordinates should be the same. EXPECT_EQ(physical_coords, virtual_coords); @@ -57,15 +57,15 @@ TEST(SocDescriptor, SocDescriptorWHTopLeftCore) { 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); + CoreCoord logical_coords = CoreCoord(0, 0, CoreType::TENSIX, CoordSystem::LOGICAL); // Always expect same virtual coordinate for (0, 0) logical coordinate. - tt_virtual_coords virtual_cords = soc_desc.to_virtual_coords(logical_coords); - EXPECT_EQ(virtual_cords, tt_virtual_coords(1, 1)); + CoreCoord virtual_cords = soc_desc.to_virtual(logical_coords); + EXPECT_EQ(virtual_cords, CoreCoord(1, 1, CoreType::TENSIX, CoordSystem::VIRTUAL)); // This depends on harvesting mask. So expected physical coord is specific to this test and Wormhole arch. - tt_physical_coords physical_cords = soc_desc.to_physical_coords(logical_coords); - EXPECT_EQ(physical_cords, tt_physical_coords(1, 2)); + CoreCoord physical_cords = soc_desc.to_physical(logical_coords); + EXPECT_EQ(physical_cords, CoreCoord(1, 2, CoreType::TENSIX, CoordSystem::PHYSICAL)); } // Test logical to physical coordinate translation. @@ -79,16 +79,16 @@ TEST(SocDescriptor, SocDescriptorWHLogicalPhysicalMapping) { soc_desc.perform_harvesting(harvesting_mask); - std::map logical_to_physical; - std::set physical_coords_set; + 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.to_physical_coords(logical_coords); + CoreCoord logical_coords = CoreCoord(x, y, CoreType::TENSIX, CoordSystem::LOGICAL); + CoreCoord physical_coords = soc_desc.to_physical(logical_coords); logical_to_physical[logical_coords] = physical_coords; // Expect that logical to physical translation is 1-1 mapping. No duplicates for physical coordinates. @@ -101,8 +101,8 @@ TEST(SocDescriptor, SocDescriptorWHLogicalPhysicalMapping) { 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.to_logical_coords(physical_coords); + CoreCoord physical_coords = it.second; + CoreCoord logical_coords = soc_desc.to_logical(physical_coords); // Expect that reverse mapping of physical coordinates gives the same logical coordinates // using which we got the physical coordinates. @@ -122,16 +122,16 @@ TEST(SocDescriptor, SocDescriptorWHLogicalVirtualMapping) { soc_desc.perform_harvesting(harvesting_mask); - std::map logical_to_virtual; - std::set virtual_coords_set; + 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.to_virtual_coords(logical_coords); + CoreCoord logical_coords = CoreCoord(x, y, CoreType::TENSIX, CoordSystem::LOGICAL); + CoreCoord virtual_coords = soc_desc.to_virtual(logical_coords); logical_to_virtual[logical_coords] = virtual_coords; // Expect that logical to virtual translation is 1-1 mapping. No duplicates for virtual coordinates. @@ -141,8 +141,8 @@ TEST(SocDescriptor, SocDescriptorWHLogicalVirtualMapping) { } for (auto it : logical_to_virtual) { - tt_virtual_coords virtual_coords = it.second; - tt_logical_coords logical_coords = soc_desc.to_logical_coords(virtual_coords); + CoreCoord virtual_coords = it.second; + CoreCoord logical_coords = soc_desc.to_logical(virtual_coords); // Expect that reverse mapping of virtual coordinates gives the same logical coordinates // using which we got the virtual coordinates. @@ -156,7 +156,7 @@ 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 CoreCoord expected_translated_coords = CoreCoord(translated_x_start, translated_y_start, CoreType::TENSIX, CoordSystem::TRANSLATED); 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")); @@ -168,13 +168,13 @@ TEST(SocDescriptor, SocDescriptorWHLogicalTranslatedTopLeft) { 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.to_physical_coords(logical_coords); - tt_virtual_coords virtual_coords = soc_desc.to_virtual_coords(logical_coords); + CoreCoord logical_coords = CoreCoord(0, 0, CoreType::TENSIX, CoordSystem::LOGICAL); + CoreCoord physical_coords = soc_desc.to_physical(logical_coords); + CoreCoord virtual_coords = soc_desc.to_virtual(logical_coords); - tt_translated_coords translated_from_logical = soc_desc.to_translated_coords(logical_coords); - tt_translated_coords translated_from_physical = soc_desc.to_translated_coords(physical_coords); - tt_translated_coords translated_from_virtual = soc_desc.to_translated_coords(virtual_coords); + CoreCoord translated_from_logical = soc_desc.to_translated(logical_coords); + CoreCoord translated_from_physical = soc_desc.to_translated(physical_coords); + CoreCoord translated_from_virtual = soc_desc.to_translated(virtual_coords); EXPECT_EQ(translated_from_logical, expected_translated_coords); EXPECT_EQ(translated_from_physical, expected_translated_coords); diff --git a/tests/api/test_core_coordinates.cpp b/tests/api/test_core_coordinates.cpp index bd1b595d..0916ceb3 100644 --- a/tests/api/test_core_coordinates.cpp +++ b/tests/api/test_core_coordinates.cpp @@ -5,115 +5,115 @@ #include #include -#include "device/tt_device.h" +// #include "device/tt_device.h" -TEST(CoreCoordinates, CoreCoordinatesReadWriteV1) { +// TEST(CoreCoordinates, CoreCoordinatesReadWriteV1) { - tt_SiliconDevice device = tt_SiliconDevice(); +// Cluster device = Cluster(); - device.start_device(); +// device.start_device(); - std::vector vector_to_write = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; - std::vector readback_vec = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +// std::vector vector_to_write = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; +// std::vector readback_vec = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; - const uint32_t address = 0; - const uint32_t chip = 0; +// const uint32_t address = 0; +// const uint32_t chip = 0; - tt_xy_pair worker_grid_size = device.get_worker_grid_size(); +// tt_xy_pair worker_grid_size = device.get_worker_grid_size(); - // Write to tensix cores. - for (size_t x = 0; x < worker_grid_size.x; x++) { - for (size_t y = 0; y < worker_grid_size.y; y++) { +// // Write to tensix cores. +// for (size_t x = 0; x < worker_grid_size.x; x++) { +// for (size_t y = 0; y < worker_grid_size.y; y++) { - // Construct the core coordinates. - CoreCoord_V1 tensix_core_coords; - tensix_core_coords.x = x; - tensix_core_coords.y = y; - tensix_core_coords.coord_system = CoordSystem::LOGICAL; - // This step is not needed for V2 coordinates. - tensix_core_coords.core_type = CoreType::TENSIX; +// // Construct the core coordinates. +// CoreCoord_V1 tensix_core_coords; +// tensix_core_coords.x = x; +// tensix_core_coords.y = y; +// tensix_core_coords.coord_system = CoordSystem::LOGICAL; +// // This step is not needed for V2 coordinates. +// tensix_core_coords.core_type = CoreType::TENSIX; - device.write_to_device(vector_to_write.data(), vector_to_write.size() * sizeof(std::uint32_t), chip, tensix_core_coords, address); +// device.write_to_device(vector_to_write.data(), vector_to_write.size() * sizeof(std::uint32_t), chip, tensix_core_coords, address); - device_read_from_device(readback_vec.data(), readback_vec.size() * sizeof(std::uint32_t), chip, tensix_core_coords, address); +// device_read_from_device(readback_vec.data(), readback_vec.size() * sizeof(std::uint32_t), chip, tensix_core_coords, address); - EXPECT_EQ(vector_to_write, readback_vec); - } - } +// EXPECT_EQ(vector_to_write, readback_vec); +// } +// } - // Write to DRAM cores. - const uint32_t num_channels = 6; - const uint32_t num_subchannels = 2; +// // Write to DRAM cores. +// const uint32_t num_channels = 6; +// const uint32_t num_subchannels = 2; - for (std::uint32_t channel = 0; channel < num_channels; channel++) { - for (std::uint32_t subchannel = 0; subchannel < num_subchannels; subchannel++) { - CoreCoord_V1 dram_core_coords; - dram_core_coords.x = channel; - dram_core_coords.y = subchannel; - dram_core_coords.coord_system = CoordSystem::LOGICAL; - // This step is not needed for V2 coordinates. - dram_core_coords.core_type = CoreType::DRAM; +// for (std::uint32_t channel = 0; channel < num_channels; channel++) { +// for (std::uint32_t subchannel = 0; subchannel < num_subchannels; subchannel++) { +// CoreCoord_V1 dram_core_coords; +// dram_core_coords.x = channel; +// dram_core_coords.y = subchannel; +// dram_core_coords.coord_system = CoordSystem::LOGICAL; +// // This step is not needed for V2 coordinates. +// dram_core_coords.core_type = CoreType::DRAM; - device.write_to_device(vector_to_write.data(), vector_to_write.size() * sizeof(std::uint32_t), chip, dram_core_coords, address); +// device.write_to_device(vector_to_write.data(), vector_to_write.size() * sizeof(std::uint32_t), chip, dram_core_coords, address); - device_read_from_device(readback_vec.data(), readback_vec.size() * sizeof(std::uint32_t), chip, dram_core_coords, address); +// device_read_from_device(readback_vec.data(), readback_vec.size() * sizeof(std::uint32_t), chip, dram_core_coords, address); - EXPECT_EQ(vector_to_write, readback_vec); - } - } +// EXPECT_EQ(vector_to_write, readback_vec); +// } +// } - device.close_device(); -} +// device.close_device(); +// } -TEST(CoreCoordinates, CoreCoordinatesReadWriteV1) { +// TEST(CoreCoordinates, CoreCoordinatesReadWriteV1) { - tt_SiliconDevice device = tt_SiliconDevice(); +// Cluster device = Cluster(); - device.start_device(); +// device.start_device(); - std::vector vector_to_write = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; - std::vector readback_vec = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +// std::vector vector_to_write = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; +// std::vector readback_vec = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; - const uint32_t address = 0; - const uint32_t chip = 0; +// const uint32_t address = 0; +// const uint32_t chip = 0; - tt_xy_pair worker_grid_size = device.get_worker_grid_size(); +// tt_xy_pair worker_grid_size = device.get_worker_grid_size(); - // Write to tensix cores. - for (size_t x = 0; x < worker_grid_size.x; x++) { - for (size_t y = 0; y < worker_grid_size.y; y++) { +// // Write to tensix cores. +// for (size_t x = 0; x < worker_grid_size.x; x++) { +// for (size_t y = 0; y < worker_grid_size.y; y++) { - TensixCoreCoord_V2 tensix_core_coords; - tensix_core_coords.x = x; - tensix_core_coords.y = y; - tensix_core_coords.coord_system = CoordSystem::LOGICAL; +// TensixCoreCoord_V2 tensix_core_coords; +// tensix_core_coords.x = x; +// tensix_core_coords.y = y; +// tensix_core_coords.coord_system = CoordSystem::LOGICAL; - device.write_to_device(vector_to_write.data(), vector_to_write.size() * sizeof(std::uint32_t), chip, tensix_core_coords, address); +// device.write_to_device(vector_to_write.data(), vector_to_write.size() * sizeof(std::uint32_t), chip, tensix_core_coords, address); - device_read_from_device(readback_vec.data(), readback_vec.size() * sizeof(std::uint32_t), chip, tensix_core_coords, address); +// device_read_from_device(readback_vec.data(), readback_vec.size() * sizeof(std::uint32_t), chip, tensix_core_coords, address); - EXPECT_EQ(vector_to_write, readback_vec); - } - } +// EXPECT_EQ(vector_to_write, readback_vec); +// } +// } - // Write to DRAM cores. - const uint32_t num_channels = 6; - const uint32_t num_subchannels = 2; +// // Write to DRAM cores. +// const uint32_t num_channels = 6; +// const uint32_t num_subchannels = 2; - for (std::uint32_t channel = 0; channel < num_channels; channel++) { - for (std::uint32_t subchannel = 0; subchannel < num_subchannels; subchannel++) { - DramCoreCoord_V2 dram_core_coords; - dram_core_coords.x = channel; - dram_core_coords.y = subchannel; - dram_core_coords.coord_system = CoordSystem::LOGICAL; +// for (std::uint32_t channel = 0; channel < num_channels; channel++) { +// for (std::uint32_t subchannel = 0; subchannel < num_subchannels; subchannel++) { +// DramCoreCoord_V2 dram_core_coords; +// dram_core_coords.x = channel; +// dram_core_coords.y = subchannel; +// dram_core_coords.coord_system = CoordSystem::LOGICAL; - device.write_to_device(vector_to_write.data(), vector_to_write.size() * sizeof(std::uint32_t), chip, dram_core_coords, address); +// device.write_to_device(vector_to_write.data(), vector_to_write.size() * sizeof(std::uint32_t), chip, dram_core_coords, address); - device_read_from_device(readback_vec.data(), readback_vec.size() * sizeof(std::uint32_t), chip, dram_core_coords, address); +// device_read_from_device(readback_vec.data(), readback_vec.size() * sizeof(std::uint32_t), chip, dram_core_coords, address); - EXPECT_EQ(vector_to_write, readback_vec); - } - } +// EXPECT_EQ(vector_to_write, readback_vec); +// } +// } - device.close_device(); -} +// device.close_device(); +// }