From d9f7483d9f65defe06c2d735b9760bb9c44ca62a Mon Sep 17 00:00:00 2001 From: pjanevski Date: Mon, 9 Dec 2024 15:01:57 +0000 Subject: [PATCH 1/5] Implement Cluster CoreCoord API --- device/api/umd/device/cluster.h | 209 ++++++++++++++----- device/api/umd/device/coordinate_manager.h | 2 +- device/api/umd/device/tt_core_coordinates.h | 7 + device/api/umd/device/tt_soc_descriptor.h | 2 +- device/cluster.cpp | 109 +++++++++- device/coordinate_manager.cpp | 2 +- device/tt_core_coordinates.cpp | 16 ++ device/tt_soc_descriptor.cpp | 7 +- tests/api/test_cluster.cpp | 131 +++++++----- tests/api/test_core_coord_translation_bh.cpp | 79 ++++--- tests/api/test_core_coord_translation_gs.cpp | 52 +++-- tests/api/test_core_coord_translation_wh.cpp | 67 +++--- tests/api/test_soc_descriptor.cpp | 22 +- 13 files changed, 485 insertions(+), 220 deletions(-) create mode 100644 device/tt_core_coordinates.cpp diff --git a/device/api/umd/device/cluster.h b/device/api/umd/device/cluster.h index a8a80f26..7b81ce09 100644 --- a/device/api/umd/device/cluster.h +++ b/device/api/umd/device/cluster.h @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -73,6 +74,15 @@ class tt_device { throw std::runtime_error("---- tt_device::configure_tlb is not implemented\n"); } + virtual void configure_tlb( + chip_id_t logical_device_id, + tt::umd::CoreCoord core, + int32_t tlb_index, + uint64_t address, + uint64_t ordering = TLB_DATA::Relaxed) { + throw std::runtime_error("---- tt_device::configure_tlb is not implemented\n"); + } + /** * Set ordering mode for dynamic/fallback TLBs (passed into driver constructor). * @@ -98,6 +108,12 @@ class tt_device { "---- tt_device::configure_active_ethernet_cores_for_mmio_device is not implemented\n"); } + virtual void configure_active_ethernet_cores_for_mmio_device( + const std::unordered_set& active_eth_cores_per_chip, chip_id_t mmio_chip) { + throw std::runtime_error( + "---- tt_device::configure_active_ethernet_cores_for_mmio_device is not implemented\n"); + } + /** * On Silicon: Assert soft Tensix reset, deassert RiscV reset, set power state to busy (ramp up AICLK), initialize * iATUs for PCIe devices and ethernet queues for remote chips. @@ -125,6 +141,13 @@ class tt_device { throw std::runtime_error("---- tt_device::deassert_risc_reset_at_core is not implemented\n"); } + virtual void deassert_risc_reset_at_core( + const chip_id_t chip, + const tt::umd::CoreCoord core, + const TensixSoftResetOptions& soft_resets = TENSIX_DEASSERT_SOFT_RESET) { + throw std::runtime_error("---- tt_device::deassert_risc_reset_at_core is not implemented\n"); + } + /** * Broadcast assert soft Tensix Reset to the entire device. */ @@ -141,6 +164,10 @@ class tt_device { throw std::runtime_error("---- tt_device::assert_risc_reset_at_core is not implemented\n"); } + virtual void assert_risc_reset_at_core(const chip_id_t chip, const tt::umd::CoreCoord core) { + throw std::runtime_error("---- tt_device::assert_risc_reset_at_core is not implemented\n"); + } + /** * To be called at the end of a run. * Set power state to idle, assert tensix reset at all cores. @@ -180,6 +207,16 @@ class tt_device { throw std::runtime_error("---- tt_device::write_to_device is not implemented\n"); } + virtual void write_to_device( + const void* mem_ptr, + uint32_t size_in_bytes, + chip_id_t chip, + tt::umd::CoreCoord core, + uint64_t addr, + const std::string& tlb_to_use) { + throw std::runtime_error("---- tt_device::write_to_device is not implemented\n"); + } + virtual void broadcast_write_to_cluster( const void* mem_ptr, uint32_t size_in_bytes, @@ -206,6 +243,16 @@ class tt_device { throw std::runtime_error("---- tt_device::read_from_device is not implemented\n"); } + virtual void read_from_device( + void* mem_ptr, + chip_id_t chip, + tt::umd::CoreCoord core, + uint64_t addr, + uint32_t size, + const std::string& fallback_tlb) { + throw std::runtime_error("---- tt_device::read_from_device is not implemented\n"); + } + /** * Write uint32_t vector to specified address and channel on host (defined for Silicon). * @@ -229,6 +276,11 @@ class tt_device { throw std::runtime_error("---- tt_device::l1_membar is not implemented\n"); } + virtual void l1_membar( + const chip_id_t chip, const std::unordered_set& cores, const std::string& fallback_tlb) { + throw std::runtime_error("---- tt_device::l1_membar is not implemented\n"); + } + virtual void dram_membar( const chip_id_t chip, const std::string& fallback_tlb, const std::unordered_set& channels = {}) { throw std::runtime_error("---- tt_device::dram_membar is not implemented\n"); @@ -239,6 +291,11 @@ class tt_device { throw std::runtime_error("---- tt_device::dram_membar is not implemented\n"); } + virtual void dram_membar( + const chip_id_t chip, const std::unordered_set& cores, const std::string& fallback_tlb) { + throw std::runtime_error("---- tt_device::dram_membar is not implemented\n"); + } + // Misc. Functions to Query/Set Device State /** * Query post harvesting SOC descriptors from UMD in virtual coordinates. @@ -510,28 +567,78 @@ class Cluster : public tt_device { */ static std::unique_ptr create_mock_cluster(); - // Setup/Teardown Functions + // Existing API we want to keep. UMD is transitioning to use CoreCoord instead of tt_xy_pair. + // This set of function shouldn't be removed even after the transition. + // TODO: regroup the functions from this set into setup/teardown, runtime, and misc functions. virtual void set_barrier_address_params(const barrier_address_params& barrier_address_params_); + virtual void set_fallback_tlb_ordering_mode(const std::string& fallback_tlb, uint64_t ordering = TLB_DATA::Posted); + virtual void start_device(const tt_device_params& device_params); + virtual void assert_risc_reset(); + virtual void deassert_risc_reset(); + virtual void close_device(); + virtual void write_to_sysmem( + const void* mem_ptr, std::uint32_t size, uint64_t addr, uint16_t channel, chip_id_t src_device_id); + virtual void read_from_sysmem( + void* mem_ptr, uint64_t addr, uint16_t channel, uint32_t size, chip_id_t src_device_id); + virtual void wait_for_non_mmio_flush(); + virtual void wait_for_non_mmio_flush(const chip_id_t chip_id); + void dram_membar( + const chip_id_t chip, const std::string& fallback_tlb, const std::unordered_set& channels); + void bar_write32(int logical_device_id, uint32_t addr, uint32_t data); + uint32_t bar_read32(int logical_device_id, uint32_t addr); + /** + * This API allows you to write directly to device memory that is addressable by a static TLB + */ + std::function get_fast_pcie_static_tlb_write_callable(int device_id); + // Misc. Functions to Query/Set Device State + virtual int arc_msg( + int logical_device_id, + uint32_t msg_code, + bool wait_for_done = true, + uint32_t arg0 = 0, + uint32_t arg1 = 0, + int timeout = 1, + uint32_t* return_3 = nullptr, + uint32_t* return_4 = nullptr); + virtual std::unordered_map get_harvesting_masks_for_soc_descriptors(); + virtual tt_ClusterDescriptor* get_cluster_description(); + static int detect_number_of_chips(); + static std::vector detect_available_device_ids(); + virtual std::set get_target_mmio_device_ids(); + virtual std::set get_target_remote_device_ids(); + virtual std::set get_target_device_ids(); + virtual std::map get_clocks(); + virtual void* host_dma_address(std::uint64_t offset, chip_id_t src_device_id, uint16_t channel) const; + virtual std::uint64_t get_pcie_base_addr_from_device(const chip_id_t chip_id) const; + virtual std::uint32_t get_num_dram_channels(std::uint32_t device_id); + virtual std::uint64_t get_dram_channel_size(std::uint32_t device_id, std::uint32_t channel); + virtual std::uint32_t get_num_host_channels(std::uint32_t device_id); + virtual std::uint32_t get_host_channel_size(std::uint32_t device_id, std::uint32_t channel); + virtual std::uint32_t get_numa_node_for_pcie_device(std::uint32_t device_id); + virtual tt_version get_ethernet_fw_version() const; + // TODO: This should be accessible through public API, probably to be moved to tt_device. + PCIDevice* get_pci_device(int device_id) const; + TTDevice* get_tt_device(chip_id_t device_id) const; + const tt_SocDescriptor& get_soc_descriptor(chip_id_t chip_id) const; + + // Existing API we want to remove. UMD is transitioning to use CoreCoord instead of tt_xy_pair. + // This set of functions is supposed to be removed one the transition for clients (tt-metal, tt-lens) is complete. + // TODO: remove this set of functions once the transition for clients is completed. + std::unordered_map get_virtual_soc_descriptors(); virtual void configure_tlb( chip_id_t logical_device_id, tt_xy_pair core, int32_t tlb_index, uint64_t address, uint64_t ordering = TLB_DATA::Posted); - virtual void set_fallback_tlb_ordering_mode(const std::string& fallback_tlb, uint64_t ordering = TLB_DATA::Posted); virtual void configure_active_ethernet_cores_for_mmio_device( chip_id_t mmio_chip, const std::unordered_set& active_eth_cores_per_chip); - virtual void start_device(const tt_device_params& device_params); - virtual void assert_risc_reset(); - virtual void deassert_risc_reset(); virtual void deassert_risc_reset_at_core( tt_cxy_pair core, const TensixSoftResetOptions& soft_resets = TENSIX_DEASSERT_SOFT_RESET); virtual void assert_risc_reset_at_core(tt_cxy_pair core); - virtual void close_device(); - - // Runtime Functions virtual void write_to_device( const void* mem_ptr, uint32_t size_in_bytes, tt_cxy_pair core, uint64_t addr, const std::string& tlb_to_use); + // TODO: Add CoreCoord API for this function. void broadcast_write_to_cluster( const void* mem_ptr, uint32_t size_in_bytes, @@ -540,34 +647,16 @@ class Cluster : public tt_device { std::set& rows_to_exclude, std::set& columns_to_exclude, const std::string& fallback_tlb); - virtual void read_from_device( void* mem_ptr, tt_cxy_pair core, uint64_t addr, uint32_t size, const std::string& fallback_tlb); - virtual void write_to_sysmem( - const void* mem_ptr, std::uint32_t size, uint64_t addr, uint16_t channel, chip_id_t src_device_id); - virtual void read_from_sysmem( - void* mem_ptr, uint64_t addr, uint16_t channel, uint32_t size, chip_id_t src_device_id); - virtual void wait_for_non_mmio_flush(); - virtual void wait_for_non_mmio_flush(const chip_id_t chip_id); void l1_membar( const chip_id_t chip, const std::string& fallback_tlb, const std::unordered_set& cores = {}); - void dram_membar( - const chip_id_t chip, const std::string& fallback_tlb, const std::unordered_set& channels); void dram_membar( const chip_id_t chip, const std::string& fallback_tlb, const std::unordered_set& cores = {}); - // These functions are used by Debuda, so make them public - void bar_write32(int logical_device_id, uint32_t addr, uint32_t data); - uint32_t bar_read32(int logical_device_id, uint32_t addr); - /** * If the tlbs are initialized, returns a tuple with the TLB base address and its size */ std::optional> get_tlb_data_from_target(const tt_cxy_pair& target); - /** - * This API allows you to write directly to device memory that is addressable by a static TLB - */ - std::function get_fast_pcie_static_tlb_write_callable(int device_id); - /** * Provide fast write access to a statically-mapped TLB. * It is the caller's responsibility to ensure that @@ -579,29 +668,8 @@ class Cluster : public tt_device { * @param target The target chip and core to write to. */ tt::Writer get_static_tlb_writer(tt_cxy_pair target); - - // Misc. Functions to Query/Set Device State - virtual int arc_msg( - int logical_device_id, - uint32_t msg_code, - bool wait_for_done = true, - uint32_t arg0 = 0, - uint32_t arg1 = 0, - int timeout = 1, - uint32_t* return_3 = nullptr, - uint32_t* return_4 = nullptr); virtual bool using_harvested_soc_descriptors(); - virtual std::unordered_map get_harvesting_masks_for_soc_descriptors(); virtual void translate_to_noc_table_coords(chip_id_t device_id, std::size_t& r, std::size_t& c); - virtual tt_ClusterDescriptor* get_cluster_description(); - static int detect_number_of_chips(); - static std::vector detect_available_device_ids(); - virtual std::set get_target_mmio_device_ids(); - virtual std::set get_target_remote_device_ids(); - virtual std::set get_target_device_ids(); - virtual std::map get_clocks(); - virtual void* host_dma_address(std::uint64_t offset, chip_id_t src_device_id, uint16_t channel) const; - virtual std::uint64_t get_pcie_base_addr_from_device(const chip_id_t chip_id) const; static std::vector extract_rows_to_remove( const tt::ARCH& arch, const int worker_grid_rows, const int harvested_rows); static void remove_worker_row_from_descriptor( @@ -609,18 +677,43 @@ class Cluster : public tt_device { static void harvest_rows_in_soc_descriptor(tt::ARCH arch, tt_SocDescriptor& sdesc, uint32_t harvested_rows); static std::unordered_map create_harvested_coord_translation( const tt::ARCH arch, bool identity_map); - virtual std::uint32_t get_num_dram_channels(std::uint32_t device_id); - virtual std::uint64_t get_dram_channel_size(std::uint32_t device_id, std::uint32_t channel); - virtual std::uint32_t get_num_host_channels(std::uint32_t device_id); - virtual std::uint32_t get_host_channel_size(std::uint32_t device_id, std::uint32_t channel); - virtual std::uint32_t get_numa_node_for_pcie_device(std::uint32_t device_id); - virtual tt_version get_ethernet_fw_version() const; - - TTDevice* get_tt_device(chip_id_t device_id) const; - const tt_SocDescriptor& get_soc_descriptor(chip_id_t chip_id) const; - // TODO: This function should be removed. - std::unordered_map get_virtual_soc_descriptors(); + // New API. UMD is transitioning to use CoreCoord instead of tt_xy_pair. + // This is new set of functions that should be used once the transition for clients (tt-metal, tt-lens) is complete. + virtual void configure_tlb( + chip_id_t logical_device_id, + tt::umd::CoreCoord core, + int32_t tlb_index, + uint64_t address, + uint64_t ordering = TLB_DATA::Posted); + virtual void deassert_risc_reset_at_core( + const chip_id_t chip, + const tt::umd::CoreCoord core, + const TensixSoftResetOptions& soft_resets = TENSIX_DEASSERT_SOFT_RESET); + virtual void assert_risc_reset_at_core(const chip_id_t chip, const tt::umd::CoreCoord core); + virtual void write_to_device( + const void* mem_ptr, + uint32_t size_in_bytes, + chip_id_t chip, + tt::umd::CoreCoord core, + uint64_t addr, + const std::string& tlb_to_use); + virtual void read_from_device( + void* mem_ptr, + chip_id_t chip, + tt::umd::CoreCoord core, + uint64_t addr, + uint32_t size, + const std::string& fallback_tlb); + std::optional> get_tlb_data_from_target( + const chip_id_t chip, const tt::umd::CoreCoord core); + tt::Writer get_static_tlb_writer(const chip_id_t chip, const tt::umd::CoreCoord target); + virtual void configure_active_ethernet_cores_for_mmio_device( + const std::unordered_set& active_eth_cores_per_chip, chip_id_t mmio_chip); + virtual void l1_membar( + const chip_id_t chip, const std::unordered_set& cores, const std::string& fallback_tlb); + virtual void dram_membar( + const chip_id_t chip, const std::unordered_set& cores, const std::string& fallback_tlb); // Destructor virtual ~Cluster(); diff --git a/device/api/umd/device/coordinate_manager.h b/device/api/umd/device/coordinate_manager.h index 66033692..56a453d8 100644 --- a/device/api/umd/device/coordinate_manager.h +++ b/device/api/umd/device/coordinate_manager.h @@ -40,7 +40,7 @@ class CoordinateManager { CoordinateManager(CoordinateManager& other) = default; - tt::umd::CoreCoord to(const tt::umd::CoreCoord core_coord, const CoordSystem coord_system); + tt::umd::CoreCoord translate_coord_to(const tt::umd::CoreCoord core_coord, const CoordSystem coord_system); std::vector get_cores(const CoreType core_type) const; tt_xy_pair get_grid_size(const CoreType core_type) const; diff --git a/device/api/umd/device/tt_core_coordinates.h b/device/api/umd/device/tt_core_coordinates.h index 3e0b5803..8235db2f 100644 --- a/device/api/umd/device/tt_core_coordinates.h +++ b/device/api/umd/device/tt_core_coordinates.h @@ -83,3 +83,10 @@ struct CoreCoord : public tt_xy_pair { }; } // namespace tt::umd + +namespace std { +template <> +struct hash { + size_t operator()(const tt::umd::CoreCoord& core_coord) const; +}; +} // namespace std diff --git a/device/api/umd/device/tt_soc_descriptor.h b/device/api/umd/device/tt_soc_descriptor.h index 1669ff5a..0c9b66c7 100644 --- a/device/api/umd/device/tt_soc_descriptor.h +++ b/device/api/umd/device/tt_soc_descriptor.h @@ -90,7 +90,7 @@ class tt_SocDescriptor { harvested_grid_size_map(other.harvested_grid_size_map) {} // CoreCoord conversions. - tt::umd::CoreCoord to(const tt::umd::CoreCoord core_coord, const CoordSystem coord_system) const; + tt::umd::CoreCoord translate_coord_to(const tt::umd::CoreCoord core_coord, const CoordSystem coord_system) const; static std::string get_soc_descriptor_path(tt::ARCH arch); diff --git a/device/cluster.cpp b/device/cluster.cpp index 125cc2c5..7afa93f4 100644 --- a/device/cluster.cpp +++ b/device/cluster.cpp @@ -36,6 +36,7 @@ #include #include +#include "api/umd/device/tt_core_coordinates.h" #include "logger.hpp" #include "umd/device/architecture_implementation.h" #include "umd/device/chip/local_chip.h" @@ -503,8 +504,8 @@ std::unique_ptr Cluster::construct_chip_from_cluster(chip_id_t chip_id, tt // true. // TODO: This should be changed, harvesting should be done in tt_socdescriptor's constructor and not as part of // cluster class. - // uint32_t harvesting_info = cluster_desc->get_harvesting_info().at(chip_id); - tt_SocDescriptor soc_desc = tt_SocDescriptor(soc_desc_path /*, harvesting_info*/); + uint32_t tensix_harvesting_mask = cluster_desc->get_harvesting_info().at(chip_id); + tt_SocDescriptor soc_desc = tt_SocDescriptor(soc_desc_path, tensix_harvesting_mask /*, harvesting_info*/); return construct_chip_from_cluster(chip_id, cluster_desc, soc_desc); } @@ -683,6 +684,18 @@ void Cluster::configure_active_ethernet_cores_for_mmio_device( non_mmio_transfer_cores_customized = true; } +void Cluster::configure_active_ethernet_cores_for_mmio_device( + const std::unordered_set& active_eth_cores_per_chip, chip_id_t mmio_chip) { + std::unordered_set active_eth_cores_xy; + const tt_SocDescriptor& soc_desc = get_soc_descriptor(mmio_chip); + for (const auto& core : active_eth_cores_per_chip) { + CoreCoord virtual_coord = soc_desc.translate_coord_to(core, CoordSystem::VIRTUAL); + active_eth_cores_xy.insert(tt_xy_pair(virtual_coord.x, virtual_coord.y)); + } + + configure_active_ethernet_cores_for_mmio_device(mmio_chip, active_eth_cores_xy); +} + void Cluster::populate_cores() { std::uint32_t count = 0; for (const auto& [chip_id, chip] : chips_) { @@ -996,6 +1009,16 @@ void Cluster::deassert_risc_reset_at_core(tt_cxy_pair core, const TensixSoftRese } } +void Cluster::deassert_risc_reset_at_core( + const chip_id_t chip, const CoreCoord core, const TensixSoftResetOptions& soft_resets) { + tt_cxy_pair virtual_core; + virtual_core.chip = chip; + const CoreCoord virtual_coord = get_soc_descriptor(chip).translate_coord_to(core, CoordSystem::VIRTUAL); + virtual_core.x = virtual_coord.x; + virtual_core.y = virtual_coord.y; + deassert_risc_reset_at_core(virtual_core, soft_resets); +} + void Cluster::assert_risc_reset_at_core(tt_cxy_pair core) { // Get Target Device to query soc descriptor and determine location in cluster std::uint32_t target_device = core.chip; @@ -1016,6 +1039,15 @@ void Cluster::assert_risc_reset_at_core(tt_cxy_pair core) { } } +void Cluster::assert_risc_reset_at_core(const chip_id_t chip, const CoreCoord core) { + tt_cxy_pair virtual_core; + virtual_core.chip = chip; + const CoreCoord virtual_coord = get_soc_descriptor(chip).translate_coord_to(core, CoordSystem::VIRTUAL); + virtual_core.x = virtual_coord.x; + virtual_core.y = virtual_coord.y; + assert_risc_reset_at_core(virtual_core); +} + // Free memory during teardown, and remove (clean/unlock) from any leftover mutexes. void Cluster::cleanup_shared_host_state() { for (auto& mutex : hardware_resource_mutex_map) { @@ -1078,6 +1110,15 @@ tt::Writer Cluster::get_static_tlb_writer(tt_cxy_pair target) { return tt::Writer(base + tlb_offset, tlb_size); } +tt::Writer Cluster::get_static_tlb_writer(const chip_id_t chip, const CoreCoord target) { + tt_cxy_pair virtual_core; + virtual_core.chip = chip; + const CoreCoord virtual_coord = get_soc_descriptor(chip).translate_coord_to(target, CoordSystem::VIRTUAL); + virtual_core.x = virtual_coord.x; + virtual_core.y = virtual_coord.y; + return get_static_tlb_writer(virtual_core); +} + void Cluster::write_device_memory( const void* mem_ptr, uint32_t size_in_bytes, @@ -1323,6 +1364,15 @@ std::optional> Cluster::get_tlb_data_from_target( return get_tt_device(target.chip)->get_architecture_implementation()->describe_tlb(tlb_index); } +std::optional> Cluster::get_tlb_data_from_target(const chip_id_t chip, CoreCoord core) { + tt_cxy_pair virtual_core; + virtual_core.chip = chip; + const CoreCoord virtual_coord = get_soc_descriptor(chip).translate_coord_to(core, CoordSystem::VIRTUAL); + virtual_core.x = virtual_coord.x; + virtual_core.y = virtual_coord.y; + return get_tlb_data_from_target(virtual_core); +} + void Cluster::configure_tlb( chip_id_t logical_device_id, tt_xy_pair core, int32_t tlb_index, uint64_t address, uint64_t ordering) { log_assert( @@ -1353,6 +1403,16 @@ void Cluster::configure_tlb( map_core_to_tlb_per_chip.at(logical_device_id).insert({core, tlb_index}); } +void Cluster::configure_tlb( + chip_id_t logical_device_id, tt::umd::CoreCoord core, int32_t tlb_index, uint64_t address, uint64_t ordering) { + tt_xy_pair virtual_core; + const CoreCoord virtual_coord = + get_soc_descriptor(logical_device_id).translate_coord_to(core, CoordSystem::VIRTUAL); + virtual_core.x = virtual_coord.x; + virtual_core.y = virtual_coord.y; + configure_tlb(logical_device_id, virtual_core, tlb_index, address, ordering); +} + void Cluster::set_fallback_tlb_ordering_mode(const std::string& fallback_tlb, uint64_t ordering) { log_assert( ordering == TLB_DATA::Strict || ordering == TLB_DATA::Posted || ordering == TLB_DATA::Relaxed, @@ -2932,6 +2992,16 @@ void Cluster::l1_membar( } } +void Cluster::l1_membar( + const chip_id_t chip, const std::unordered_set& cores, const std::string& fallback_tlb) { + std::unordered_set cores_xy; + for (const auto& core : cores) { + const CoreCoord virtual_core = get_soc_descriptor(chip).translate_coord_to(core, CoordSystem::VIRTUAL); + cores_xy.insert({virtual_core.x, virtual_core.y}); + } + l1_membar(chip, fallback_tlb, cores_xy); +} + void Cluster::dram_membar( const chip_id_t chip, const std::string& fallback_tlb, const std::unordered_set& cores) { if (cluster_desc->is_chip_mmio_capable(chip)) { @@ -2950,6 +3020,16 @@ void Cluster::dram_membar( } } +void Cluster::dram_membar( + const chip_id_t chip, const std::unordered_set& cores, const std::string& fallback_tlb) { + std::unordered_set cores_xy; + for (const auto& core : cores) { + const CoreCoord virtual_core = get_soc_descriptor(chip).translate_coord_to(core, CoordSystem::VIRTUAL); + cores_xy.insert({virtual_core.x, virtual_core.y}); + } + dram_membar(chip, fallback_tlb, cores_xy); +} + void Cluster::dram_membar( const chip_id_t chip, const std::string& fallback_tlb, const std::unordered_set& channels) { if (cluster_desc->is_chip_mmio_capable(chip)) { @@ -2987,6 +3067,21 @@ void Cluster::write_to_device( } } +void Cluster::write_to_device( + const void* mem_ptr, + uint32_t size_in_bytes, + chip_id_t chip, + CoreCoord core, + uint64_t addr, + const std::string& tlb_to_use) { + tt_cxy_pair virtual_core; + virtual_core.chip = chip; + CoreCoord virtual_coord = get_soc_descriptor(chip).translate_coord_to(core, CoordSystem::VIRTUAL); + virtual_core.x = virtual_coord.x; + virtual_core.y = virtual_coord.y; + write_to_device(mem_ptr, size_in_bytes, virtual_core, addr, tlb_to_use); +} + void Cluster::read_mmio_device_register( void* mem_ptr, tt_cxy_pair core, uint64_t addr, uint32_t size, const std::string& fallback_tlb) { TTDevice* tt_device = get_tt_device(core.chip); @@ -3046,6 +3141,16 @@ void Cluster::read_from_device( } } +void Cluster::read_from_device( + void* mem_ptr, chip_id_t chip, CoreCoord core, uint64_t addr, uint32_t size, const std::string& fallback_tlb) { + tt_cxy_pair virtual_core; + virtual_core.chip = chip; + CoreCoord virtual_coord = get_soc_descriptor(chip).translate_coord_to(core, CoordSystem::VIRTUAL); + virtual_core.x = virtual_coord.x; + virtual_core.y = virtual_coord.y; + read_from_device(mem_ptr, virtual_core, addr, size, fallback_tlb); +} + int Cluster::arc_msg( int logical_device_id, uint32_t msg_code, diff --git a/device/coordinate_manager.cpp b/device/coordinate_manager.cpp index 3102dab2..e218e467 100644 --- a/device/coordinate_manager.cpp +++ b/device/coordinate_manager.cpp @@ -81,7 +81,7 @@ void CoordinateManager::identity_map_physical_cores() { } } -CoreCoord CoordinateManager::to(const CoreCoord core_coord, const CoordSystem coord_system) { +CoreCoord CoordinateManager::translate_coord_to(const CoreCoord core_coord, const CoordSystem coord_system) { return from_physical_map.at({to_physical_map.at(core_coord), coord_system}); } diff --git a/device/tt_core_coordinates.cpp b/device/tt_core_coordinates.cpp new file mode 100644 index 00000000..ca0413ae --- /dev/null +++ b/device/tt_core_coordinates.cpp @@ -0,0 +1,16 @@ +// SPDX-FileCopyrightText: (c) 2024 Tenstorrent Inc. +// +// SPDX-License-Identifier: Apache-2.0 + +#include "umd/device/tt_core_coordinates.h" + +namespace std { +std::size_t operator()(const CoreCoord& core_coord) const { + size_t seed = 0; + seed = std::hash{}(core_coord.x) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed = std::hash{}(core_coord.y) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed = std::hash{}(core_coord.core_type) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed = std::hash{}(core_coord.coord_system) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + return seed; +} +} // namespace std diff --git a/device/tt_soc_descriptor.cpp b/device/tt_soc_descriptor.cpp index a3b8ed30..c0a5db3e 100644 --- a/device/tt_soc_descriptor.cpp +++ b/device/tt_soc_descriptor.cpp @@ -211,8 +211,9 @@ void tt_SocDescriptor::create_coordinate_manager( get_cores_and_grid_size_from_coordinate_manager(); } -tt::umd::CoreCoord tt_SocDescriptor::to(const tt::umd::CoreCoord core_coord, const CoordSystem coord_system) const { - return coordinate_manager->to(core_coord, coord_system); +tt::umd::CoreCoord tt_SocDescriptor::translate_coord_to( + const tt::umd::CoreCoord core_coord, const CoordSystem coord_system) const { + return coordinate_manager->translate_coord_to(core_coord, coord_system); } tt_SocDescriptor::tt_SocDescriptor( @@ -269,7 +270,7 @@ tt_xy_pair tt_SocDescriptor::get_core_for_dram_channel(int dram_chan, int subcha CoreCoord tt_SocDescriptor::get_dram_core_for_channel(int dram_chan, int subchannel) const { const CoreCoord logical_dram_coord = CoreCoord(dram_chan, subchannel, CoreType::DRAM, CoordSystem::LOGICAL); - return to(logical_dram_coord, CoordSystem::PHYSICAL); + return translate_coord_to(logical_dram_coord, CoordSystem::PHYSICAL); } bool tt_SocDescriptor::is_ethernet_core(const tt_xy_pair &core) const { diff --git a/tests/api/test_cluster.cpp b/tests/api/test_cluster.cpp index 690c8579..5a32be5e 100644 --- a/tests/api/test_cluster.cpp +++ b/tests/api/test_cluster.cpp @@ -12,6 +12,7 @@ #include #include "fmt/xchar.h" +#include "l1_address_map.h" #include "tests/test_utils/generate_cluster_desc.hpp" #include "umd/device/chip/local_chip.h" #include "umd/device/chip/mock_chip.h" @@ -101,37 +102,25 @@ TEST(ApiClusterTest, SimpleIOAllChips) { for (auto chip_id : umd_cluster->get_target_device_ids()) { const tt_SocDescriptor& soc_desc = umd_cluster->get_soc_descriptor(chip_id); - // TODO: figure out if core locations should contain chip_id - tt_xy_pair any_core = soc_desc.workers[0]; - tt_cxy_pair any_core_global(chip_id, any_core); - - if (cluster_desc->is_chip_remote(chip_id) && soc_desc.arch != tt::ARCH::WORMHOLE_B0) { - std::cout << "Skipping remote chip " << chip_id << " because it is not a wormhole_b0 chip." << std::endl; - continue; - } + CoreCoord any_core = soc_desc.get_cores(CoreType::TENSIX)[0]; std::cout << "Writing to chip " << chip_id << " core " << any_core.str() << std::endl; - umd_cluster->write_to_device(data.data(), data_size, any_core_global, 0, "LARGE_WRITE_TLB"); + umd_cluster->write_to_device(data.data(), data_size, chip_id, any_core, 0, "LARGE_WRITE_TLB"); + + umd_cluster->wait_for_non_mmio_flush(chip_id); } // Now read back the data. for (auto chip_id : umd_cluster->get_target_device_ids()) { const tt_SocDescriptor& soc_desc = umd_cluster->get_soc_descriptor(chip_id); - // TODO: figure out if core locations should contain chip_id - tt_xy_pair any_core = soc_desc.workers[0]; - tt_cxy_pair any_core_global(chip_id, any_core); - - if (cluster_desc->is_chip_remote(chip_id) && soc_desc.arch != tt::ARCH::WORMHOLE_B0) { - std::cout << "Skipping remote chip " << chip_id << " because it is not a wormhole_b0 chip." << std::endl; - continue; - } + CoreCoord any_core = soc_desc.get_cores(CoreType::TENSIX)[0]; std::cout << "Reading from chip " << chip_id << " core " << any_core.str() << std::endl; std::vector readback_data(data_size, 0); - umd_cluster->read_from_device(readback_data.data(), any_core_global, 0, data_size, "LARGE_READ_TLB"); + umd_cluster->read_from_device(readback_data.data(), chip_id, any_core, 0, data_size, "LARGE_READ_TLB"); ASSERT_EQ(data, readback_data); } @@ -156,9 +145,7 @@ TEST(ApiClusterTest, RemoteFlush) { for (auto chip_id : umd_cluster->get_target_remote_device_ids()) { const tt_SocDescriptor& soc_desc = umd_cluster->get_soc_descriptor(chip_id); - // TODO: figure out if core locations should contain chip_id - tt_xy_pair any_core = soc_desc.workers[0]; - tt_cxy_pair any_core_global(chip_id, any_core); + const CoreCoord any_core = soc_desc.get_cores(CoreType::TENSIX)[0]; if (!cluster_desc->is_chip_remote(chip_id)) { std::cout << "Chip " << chip_id << " skipped because it is not a remote chip." << std::endl; @@ -171,31 +158,17 @@ TEST(ApiClusterTest, RemoteFlush) { } std::cout << "Writing to chip " << chip_id << " core " << any_core.str() << std::endl; - umd_cluster->write_to_device(data.data(), data_size, any_core_global, 0, "LARGE_WRITE_TLB"); + umd_cluster->write_to_device(data.data(), data_size, chip_id, any_core, 0, "LARGE_WRITE_TLB"); std::cout << "Waiting for remote chip flush " << chip_id << std::endl; umd_cluster->wait_for_non_mmio_flush(chip_id); - std::cout << "Waiting again for flush " << chip_id << ", should be no-op" << std::endl; - umd_cluster->wait_for_non_mmio_flush(chip_id); - } + std::cout << "Reading from chip " << chip_id << " core " << any_core.str() << std::endl; + std::vector readback_data(data_size, 0); + umd_cluster->read_from_device(readback_data.data(), chip_id, any_core, 0, data_size, "LARGE_READ_TLB"); - chip_id_t any_remote_chip = *umd_cluster->get_target_remote_device_ids().begin(); - const tt_SocDescriptor& soc_desc = umd_cluster->get_soc_descriptor(any_remote_chip); - tt_xy_pair any_core = soc_desc.workers[0]; - tt_cxy_pair any_core_global(any_remote_chip, any_core); - if (soc_desc.arch != tt::ARCH::WORMHOLE_B0) { - std::cout << "Skipping whole cluster wait because it is not a wormhole_b0 chip." << std::endl; - return; + ASSERT_EQ(data, readback_data); } - std::cout << "Writing to chip " << any_remote_chip << " core " << any_core.str() << std::endl; - umd_cluster->write_to_device(data.data(), data_size, any_core_global, 0, "LARGE_WRITE_TLB"); - - std::cout << "Testing whole cluster wait for remote chip flush." << std::endl; - umd_cluster->wait_for_non_mmio_flush(); - - std::cout << "Testing whole cluster wait for remote chip flush again, should be no-op." << std::endl; - umd_cluster->wait_for_non_mmio_flush(); } TEST(ApiClusterTest, SimpleIOSpecificChips) { @@ -223,38 +196,80 @@ TEST(ApiClusterTest, SimpleIOSpecificChips) { for (auto chip_id : umd_cluster->get_target_device_ids()) { const tt_SocDescriptor& soc_desc = umd_cluster->get_soc_descriptor(chip_id); - // TODO: figure out if core locations should contain chip_id - tt_xy_pair any_core = soc_desc.workers[0]; - tt_cxy_pair any_core_global(chip_id, any_core); - - if (cluster_desc->is_chip_remote(chip_id) && soc_desc.arch != tt::ARCH::WORMHOLE_B0) { - std::cout << "Skipping remote chip " << chip_id << " because it is not a wormhole_b0 chip." << std::endl; - continue; - } + const CoreCoord any_core = soc_desc.get_cores(CoreType::TENSIX)[0]; std::cout << "Writing to chip " << chip_id << " core " << any_core.str() << std::endl; - umd_cluster->write_to_device(data.data(), data_size, any_core_global, 0, "LARGE_WRITE_TLB"); + umd_cluster->write_to_device(data.data(), data_size, chip_id, any_core, 0, "LARGE_WRITE_TLB"); + + umd_cluster->wait_for_non_mmio_flush(chip_id); } // Now read back the data. for (auto chip_id : umd_cluster->get_target_device_ids()) { const tt_SocDescriptor& soc_desc = umd_cluster->get_soc_descriptor(chip_id); - // TODO: figure out if core locations should contain chip_id - tt_xy_pair any_core = soc_desc.workers[0]; - tt_cxy_pair any_core_global(chip_id, any_core); - - if (cluster_desc->is_chip_remote(chip_id) && soc_desc.arch != tt::ARCH::WORMHOLE_B0) { - std::cout << "Skipping remote chip " << chip_id << " because it is not a wormhole_b0 chip." << std::endl; - continue; - } + const CoreCoord any_core = soc_desc.get_cores(CoreType::TENSIX)[0]; std::cout << "Reading from chip " << chip_id << " core " << any_core.str() << std::endl; std::vector readback_data(data_size, 0); - umd_cluster->read_from_device(readback_data.data(), any_core_global, 0, data_size, "LARGE_READ_TLB"); + umd_cluster->read_from_device(readback_data.data(), chip_id, any_core, 0, data_size, "LARGE_READ_TLB"); ASSERT_EQ(data, readback_data); } } + +TEST(ClusterAPI, DynamicTLB_RW) { + // Don't use any static TLBs in this test. All writes go through a dynamic TLB that needs to be reconfigured for + // each transaction + + std::unique_ptr cluster = get_cluster(); + + tt_device_params default_params; + cluster->start_device(default_params); + cluster->deassert_risc_reset(); + + std::vector vector_to_write = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + std::vector zeros = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + std::vector readback_vec = zeros; + + static const uint32_t num_loops = 100; + + std::set target_devices = cluster->get_target_device_ids(); + for (const chip_id_t chip : target_devices) { + std::uint32_t address = l1_mem::address_map::NCRISC_FIRMWARE_BASE; + // Write to each core a 100 times at different statically mapped addresses + const tt_SocDescriptor& soc_desc = cluster->get_soc_descriptor(chip); + std::vector tensix_cores = soc_desc.get_cores(CoreType::TENSIX); + for (int loop = 0; loop < num_loops; loop++) { + for (auto& core : tensix_cores) { + cluster->write_to_device( + vector_to_write.data(), + vector_to_write.size() * sizeof(std::uint32_t), + chip, + core, + address, + "SMALL_READ_WRITE_TLB"); + + // Barrier to ensure that all writes over ethernet were commited + cluster->wait_for_non_mmio_flush(); + cluster->read_from_device(readback_vec.data(), chip, core, address, 40, "SMALL_READ_WRITE_TLB"); + + ASSERT_EQ(vector_to_write, readback_vec) + << "Vector read back from core " << core.x << "-" << core.y << "does not match what was written"; + + cluster->wait_for_non_mmio_flush(); + + cluster->write_to_device( + zeros.data(), zeros.size() * sizeof(std::uint32_t), chip, core, address, "SMALL_READ_WRITE_TLB"); + + cluster->wait_for_non_mmio_flush(); + + readback_vec = zeros; + } + address += 0x20; // Increment by uint32_t size for each write + } + } + cluster->close_device(); +} diff --git a/tests/api/test_core_coord_translation_bh.cpp b/tests/api/test_core_coord_translation_bh.cpp index 4a2f63b5..b1b92991 100644 --- a/tests/api/test_core_coord_translation_bh.cpp +++ b/tests/api/test_core_coord_translation_bh.cpp @@ -20,8 +20,8 @@ TEST(CoordinateManager, CoordinateManagerBlackholeNoHarvesting) { for (size_t x = 0; x < tensix_grid_size.x; x++) { for (size_t y = 0; y < tensix_grid_size.y; y++) { CoreCoord logical_coords = CoreCoord(x, y, CoreType::TENSIX, CoordSystem::LOGICAL); - CoreCoord virtual_coords = coordinate_manager->to(logical_coords, CoordSystem::VIRTUAL); - CoreCoord physical_coords = coordinate_manager->to(logical_coords, CoordSystem::PHYSICAL); + CoreCoord virtual_coords = coordinate_manager->translate_coord_to(logical_coords, CoordSystem::VIRTUAL); + CoreCoord physical_coords = coordinate_manager->translate_coord_to(logical_coords, CoordSystem::PHYSICAL); // Virtual and physical coordinates should be the same. EXPECT_EQ(physical_coords.x, virtual_coords.x); @@ -43,11 +43,11 @@ TEST(CoordinateManager, CoordinateManagerBlackholeTopLeftCore) { CoreCoord logical_coords = CoreCoord(0, 0, CoreType::TENSIX, CoordSystem::LOGICAL); // Always expect same virtual coordinate for (0, 0) logical coordinate. - CoreCoord virtual_cords = coordinate_manager->to(logical_coords, CoordSystem::VIRTUAL); + CoreCoord virtual_cords = coordinate_manager->translate_coord_to(logical_coords, CoordSystem::VIRTUAL); 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. - CoreCoord physical_cords = coordinate_manager->to(logical_coords, CoordSystem::PHYSICAL); + CoreCoord physical_cords = coordinate_manager->translate_coord_to(logical_coords, CoordSystem::PHYSICAL); EXPECT_EQ(physical_cords, CoreCoord(2, 2, CoreType::TENSIX, CoordSystem::PHYSICAL)); } @@ -71,7 +71,8 @@ TEST(CoordinateManager, CoordinateManagerBlackholeLogicalPhysicalMapping) { for (size_t x = 0; x < tensix_grid_size.x - num_harvested_x; x++) { for (size_t y = 0; y < tensix_grid_size.y; y++) { CoreCoord logical_coords = CoreCoord(x, y, CoreType::TENSIX, CoordSystem::LOGICAL); - CoreCoord physical_coords = coordinate_manager->to(logical_coords, CoordSystem::PHYSICAL); + CoreCoord physical_coords = + coordinate_manager->translate_coord_to(logical_coords, CoordSystem::PHYSICAL); logical_to_physical[logical_coords] = physical_coords; // Expect that logical to physical translation is 1-1 mapping. No duplicates for physical coordinates. @@ -84,7 +85,7 @@ TEST(CoordinateManager, CoordinateManagerBlackholeLogicalPhysicalMapping) { for (auto it : logical_to_physical) { CoreCoord physical_coords = it.second; - CoreCoord logical_coords = coordinate_manager->to(physical_coords, CoordSystem::LOGICAL); + CoreCoord logical_coords = coordinate_manager->translate_coord_to(physical_coords, CoordSystem::LOGICAL); // Expect that reverse mapping of physical coordinates gives the same logical coordinates // using which we got the physical coordinates. @@ -113,7 +114,7 @@ TEST(CoordinateManager, CoordinateManagerBlackholeLogicalVirtualMapping) { for (size_t x = 0; x < tensix_grid_size.x - num_harvested_x; x++) { for (size_t y = 0; y < tensix_grid_size.y; y++) { CoreCoord logical_coords = CoreCoord(x, y, CoreType::TENSIX, CoordSystem::LOGICAL); - CoreCoord virtual_coords = coordinate_manager->to(logical_coords, CoordSystem::VIRTUAL); + CoreCoord virtual_coords = coordinate_manager->translate_coord_to(logical_coords, CoordSystem::VIRTUAL); logical_to_virtual[logical_coords] = virtual_coords; // Expect that logical to virtual translation is 1-1 mapping. No duplicates for virtual coordinates. @@ -126,7 +127,7 @@ TEST(CoordinateManager, CoordinateManagerBlackholeLogicalVirtualMapping) { for (auto it : logical_to_virtual) { CoreCoord virtual_coords = it.second; - CoreCoord logical_coords = coordinate_manager->to(virtual_coords, CoordSystem::LOGICAL); + CoreCoord logical_coords = coordinate_manager->translate_coord_to(virtual_coords, CoordSystem::LOGICAL); // Expect that reverse mapping of virtual coordinates gives the same logical coordinates // using which we got the virtual coordinates. @@ -155,7 +156,8 @@ TEST(CoordinateManager, CoordinateManagerBlackholeLogicalTranslatedMapping) { for (size_t x = 0; x < tensix_grid_size.x - num_harvested_x; x++) { for (size_t y = 0; y < tensix_grid_size.y; y++) { CoreCoord logical_coords = CoreCoord(x, y, CoreType::TENSIX, CoordSystem::LOGICAL); - CoreCoord translated_coords = coordinate_manager->to(logical_coords, CoordSystem::TRANSLATED); + CoreCoord translated_coords = + coordinate_manager->translate_coord_to(logical_coords, CoordSystem::TRANSLATED); logical_to_translated[logical_coords] = translated_coords; // Expect that logical to translated translation is 1-1 mapping. No duplicates for translated @@ -169,7 +171,7 @@ TEST(CoordinateManager, CoordinateManagerBlackholeLogicalTranslatedMapping) { for (auto it : logical_to_translated) { CoreCoord translated_coords = it.second; - CoreCoord logical_coords = coordinate_manager->to(translated_coords, CoordSystem::LOGICAL); + CoreCoord logical_coords = coordinate_manager->translate_coord_to(translated_coords, CoordSystem::LOGICAL); // Expect that reverse mapping of translated coordinates gives the same logical coordinates // using which we got the translated coordinates. @@ -192,8 +194,9 @@ TEST(CoordinateManager, CoordinateManagerBlackholeVirtualEqualTranslated) { for (size_t x = 0; x < tt::umd::blackhole::TENSIX_GRID_SIZE.x - num_harvested_x; x++) { for (size_t y = 0; y < tt::umd::blackhole::TENSIX_GRID_SIZE.y; y++) { CoreCoord logical_coords = CoreCoord(x, y, CoreType::TENSIX, CoordSystem::LOGICAL); - CoreCoord translated_coords = coordinate_manager->to(logical_coords, CoordSystem::TRANSLATED); - CoreCoord virtual_coords = coordinate_manager->to(logical_coords, CoordSystem::VIRTUAL); + CoreCoord translated_coords = + coordinate_manager->translate_coord_to(logical_coords, CoordSystem::TRANSLATED); + CoreCoord virtual_coords = coordinate_manager->translate_coord_to(logical_coords, CoordSystem::VIRTUAL); // Expect that translated coordinates are same as virtual coordinates. EXPECT_EQ(translated_coords.x, virtual_coords.x); @@ -221,11 +224,13 @@ TEST(CoordinateManager, CoordinateManagerBlackholeTransltedMappingHarvested) { for (size_t cnt = 0; cnt < num_harvested_x * tensix_grid_size.y; cnt++) { CoreCoord physical_core = CoreCoord(tensix_cores[index].x, tensix_cores[index].y, CoreType::TENSIX, CoordSystem::PHYSICAL); - const CoreCoord translated_core = coordinate_manager->to(physical_core, CoordSystem::TRANSLATED); + const CoreCoord translated_core = + coordinate_manager->translate_coord_to(physical_core, CoordSystem::TRANSLATED); const CoreCoord virtual_core = CoreCoord( tensix_cores[virtual_index].x, tensix_cores[virtual_index].y, CoreType::TENSIX, CoordSystem::VIRTUAL); - const CoreCoord translated_core_from_virtual = coordinate_manager->to(virtual_core, CoordSystem::TRANSLATED); + const CoreCoord translated_core_from_virtual = + coordinate_manager->translate_coord_to(virtual_core, CoordSystem::TRANSLATED); EXPECT_EQ(translated_core, translated_core_from_virtual); @@ -267,7 +272,7 @@ TEST(CoordinateManager, CoordinateManagerBlackholeDRAMNoHarvesting) { CoreType::DRAM, CoordSystem::PHYSICAL); - const CoreCoord dram_physical = coordinate_manager->to(dram_logical, CoordSystem::PHYSICAL); + const CoreCoord dram_physical = coordinate_manager->translate_coord_to(dram_logical, CoordSystem::PHYSICAL); EXPECT_EQ(dram_physical, expected_physical); } @@ -282,7 +287,8 @@ TEST(CoordinateManager, CoordinateManagerBlackholeDRAMTopLeft) { const CoreCoord top_left_dram_logical = CoreCoord(0, 0, CoreType::DRAM, CoordSystem::LOGICAL); const CoreCoord expected_top_left_physical = CoreCoord(0, 2, CoreType::DRAM, CoordSystem::PHYSICAL); - const CoreCoord top_left_physical = coordinate_manager->to(top_left_dram_logical, CoordSystem::PHYSICAL); + const CoreCoord top_left_physical = + coordinate_manager->translate_coord_to(top_left_dram_logical, CoordSystem::PHYSICAL); EXPECT_EQ(top_left_physical, expected_top_left_physical); } @@ -313,7 +319,8 @@ TEST(CoordinateManager, CoordinateManagerBlackholeDRAMLogicalPhysicalMapping) { for (size_t x = 0; x < num_dram_banks - num_banks_harvested; x++) { for (size_t y = 0; y < num_noc_ports_per_bank; y++) { const CoreCoord logical_coords = CoreCoord(x, y, CoreType::DRAM, CoordSystem::LOGICAL); - const CoreCoord physical_coords = coordinate_manager->to(logical_coords, CoordSystem::PHYSICAL); + const CoreCoord physical_coords = + coordinate_manager->translate_coord_to(logical_coords, CoordSystem::PHYSICAL); logical_to_physical[logical_coords] = physical_coords; // Expect that logical to physical translation is 1-1 mapping. No duplicates for physical coordinates. @@ -326,7 +333,8 @@ TEST(CoordinateManager, CoordinateManagerBlackholeDRAMLogicalPhysicalMapping) { for (auto it : logical_to_physical) { const CoreCoord physical_coords = it.second; - const CoreCoord logical_coords = coordinate_manager->to(physical_coords, CoordSystem::LOGICAL); + const CoreCoord logical_coords = + coordinate_manager->translate_coord_to(physical_coords, CoordSystem::LOGICAL); // Expect that reverse mapping of physical coordinates gives the same logical coordinates // using which we got the physical coordinates. @@ -360,7 +368,7 @@ TEST(CoordinateManager, CoordinateManagerBlackholeDRAMLogicalVirtualMapping) { for (size_t x = 0; x < num_dram_banks - num_harvested_banks; x++) { for (size_t y = 0; y < num_noc_ports_per_bank; y++) { CoreCoord logical_coords = CoreCoord(x, y, CoreType::DRAM, CoordSystem::LOGICAL); - CoreCoord virtual_coords = coordinate_manager->to(logical_coords, CoordSystem::VIRTUAL); + CoreCoord virtual_coords = coordinate_manager->translate_coord_to(logical_coords, CoordSystem::VIRTUAL); logical_to_virtual[logical_coords] = virtual_coords; // Expect that logical to virtual translation is 1-1 mapping. No duplicates for virtual coordinates. @@ -371,7 +379,7 @@ TEST(CoordinateManager, CoordinateManagerBlackholeDRAMLogicalVirtualMapping) { for (auto it : logical_to_virtual) { CoreCoord virtual_coords = it.second; - CoreCoord logical_coords = coordinate_manager->to(virtual_coords, CoordSystem::LOGICAL); + CoreCoord logical_coords = coordinate_manager->translate_coord_to(virtual_coords, CoordSystem::LOGICAL); // Expect that reverse mapping of virtual coordinates gives the same logical coordinates // using which we got the virtual coordinates. @@ -402,7 +410,8 @@ TEST(CoordinateManager, CoordinateManagerBlackholeDRAMTranslatedMapping) { for (size_t x = 0; x < num_dram_banks - num_harvested_banks; x++) { for (size_t y = 0; y < num_noc_ports_per_bank; y++) { const CoreCoord logical_coords = CoreCoord(x, y, CoreType::DRAM, CoordSystem::LOGICAL); - const CoreCoord translated_coords = coordinate_manager->to(logical_coords, CoordSystem::TRANSLATED); + const CoreCoord translated_coords = + coordinate_manager->translate_coord_to(logical_coords, CoordSystem::TRANSLATED); EXPECT_GE(translated_coords.x, tt::umd::blackhole::dram_translated_coordinate_start_x); EXPECT_GE(translated_coords.y, tt::umd::blackhole::dram_translated_coordinate_start_y); @@ -418,7 +427,8 @@ TEST(CoordinateManager, CoordinateManagerBlackholeDRAMTranslatedMapping) { for (auto it : logical_to_translated) { const CoreCoord translated_coords = it.second; - const CoreCoord logical_coords = coordinate_manager->to(translated_coords, CoordSystem::LOGICAL); + const CoreCoord logical_coords = + coordinate_manager->translate_coord_to(translated_coords, CoordSystem::LOGICAL); // Expect that reverse mapping of translated coordinates gives the same logical coordinates // using which we got the translated coordinates. @@ -452,14 +462,15 @@ TEST(CoordinateManager, CoordinateManagerBlackholeDRAMVirtualPhysicalMapping) { const tt_xy_pair virtual_pair = dram_cores[virtual_index + noc_port]; CoreCoord physical_core = CoreCoord(physical_pair.x, physical_pair.y, CoreType::DRAM, CoordSystem::PHYSICAL); - CoreCoord virtual_from_physical = coordinate_manager->to(physical_core, CoordSystem::VIRTUAL); + CoreCoord virtual_from_physical = coordinate_manager->translate_coord_to(physical_core, CoordSystem::VIRTUAL); CoreCoord virtual_core = CoreCoord(virtual_pair.x, virtual_pair.y, CoreType::DRAM, CoordSystem::VIRTUAL); EXPECT_EQ(virtual_from_physical, virtual_core); - CoreCoord translated_core = coordinate_manager->to(physical_core, CoordSystem::TRANSLATED); - CoreCoord translated_from_virtual = coordinate_manager->to(virtual_core, CoordSystem::TRANSLATED); + CoreCoord translated_core = coordinate_manager->translate_coord_to(physical_core, CoordSystem::TRANSLATED); + CoreCoord translated_from_virtual = + coordinate_manager->translate_coord_to(virtual_core, CoordSystem::TRANSLATED); EXPECT_EQ(translated_core, translated_from_virtual); @@ -493,8 +504,8 @@ TEST(CoordinateManager, CoordinateManagerBlackholePCIETranslation) { for (size_t x = 0; x < pcie_grid_size.x; x++) { for (size_t y = 0; y < pcie_grid_size.y; y++) { const CoreCoord arc_logical = CoreCoord(x, y, CoreType::PCIE, CoordSystem::LOGICAL); - const CoreCoord arc_virtual = coordinate_manager->to(arc_logical, CoordSystem::VIRTUAL); - const CoreCoord arc_physical = coordinate_manager->to(arc_logical, CoordSystem::PHYSICAL); + const CoreCoord arc_virtual = coordinate_manager->translate_coord_to(arc_logical, CoordSystem::VIRTUAL); + const CoreCoord arc_physical = coordinate_manager->translate_coord_to(arc_logical, CoordSystem::PHYSICAL); EXPECT_EQ(arc_virtual.x, arc_physical.x); EXPECT_EQ(arc_virtual.y, arc_physical.y); @@ -511,9 +522,10 @@ TEST(CoordinateManager, CoordinateManagerBlackholeARCTranslation) { for (size_t x = 0; x < arc_grid_size.x; x++) { for (size_t y = 0; y < arc_grid_size.y; y++) { const CoreCoord arc_logical = CoreCoord(x, y, CoreType::ARC, CoordSystem::LOGICAL); - const CoreCoord arc_virtual = coordinate_manager->to(arc_logical, CoordSystem::VIRTUAL); - const CoreCoord arc_physical = coordinate_manager->to(arc_logical, CoordSystem::PHYSICAL); - const CoreCoord arc_translated = coordinate_manager->to(arc_logical, CoordSystem::TRANSLATED); + const CoreCoord arc_virtual = coordinate_manager->translate_coord_to(arc_logical, CoordSystem::VIRTUAL); + const CoreCoord arc_physical = coordinate_manager->translate_coord_to(arc_logical, CoordSystem::PHYSICAL); + const CoreCoord arc_translated = + coordinate_manager->translate_coord_to(arc_logical, CoordSystem::TRANSLATED); EXPECT_EQ(arc_virtual.x, arc_physical.x); EXPECT_EQ(arc_virtual.y, arc_physical.y); @@ -536,9 +548,10 @@ TEST(CoordinateManager, CoordinateManagerBlackholeETHTranslation) { for (size_t x = 0; x < eth_grid_size.x; x++) { for (size_t y = 0; y < eth_grid_size.y; y++) { const CoreCoord eth_logical = CoreCoord(x, y, CoreType::ETH, CoordSystem::LOGICAL); - const CoreCoord eth_virtual = coordinate_manager->to(eth_logical, CoordSystem::VIRTUAL); - const CoreCoord eth_physical = coordinate_manager->to(eth_logical, CoordSystem::PHYSICAL); - const CoreCoord eth_translated = coordinate_manager->to(eth_logical, CoordSystem::TRANSLATED); + const CoreCoord eth_virtual = coordinate_manager->translate_coord_to(eth_logical, CoordSystem::VIRTUAL); + const CoreCoord eth_physical = coordinate_manager->translate_coord_to(eth_logical, CoordSystem::PHYSICAL); + const CoreCoord eth_translated = + coordinate_manager->translate_coord_to(eth_logical, CoordSystem::TRANSLATED); EXPECT_EQ(eth_virtual.x, eth_physical.x); EXPECT_EQ(eth_virtual.y, eth_physical.y); diff --git a/tests/api/test_core_coord_translation_gs.cpp b/tests/api/test_core_coord_translation_gs.cpp index a8b6d2d7..1294c4f0 100644 --- a/tests/api/test_core_coord_translation_gs.cpp +++ b/tests/api/test_core_coord_translation_gs.cpp @@ -20,8 +20,8 @@ TEST(CoordinateManager, CoordinateManagerGrayskullNoHarvesting) { for (size_t x = 0; x < tensix_grid_size.x; x++) { for (size_t y = 0; y < tensix_grid_size.y; y++) { CoreCoord logical_coords = CoreCoord(x, y, CoreType::TENSIX, CoordSystem::LOGICAL); - CoreCoord virtual_coords = coordinate_manager->to(logical_coords, CoordSystem::VIRTUAL); - CoreCoord physical_coords = coordinate_manager->to(logical_coords, CoordSystem::PHYSICAL); + CoreCoord virtual_coords = coordinate_manager->translate_coord_to(logical_coords, CoordSystem::VIRTUAL); + CoreCoord physical_coords = coordinate_manager->translate_coord_to(logical_coords, CoordSystem::PHYSICAL); // Virtual and physical coordinates should be the same. EXPECT_EQ(physical_coords.x, virtual_coords.x); @@ -40,11 +40,11 @@ TEST(CoordinateManager, CoordinateManagerGrayskullTopLeftCore) { CoreCoord logical_coords = CoreCoord(0, 0, CoreType::TENSIX, CoordSystem::LOGICAL); // Always expect same virtual coordinate for (0, 0) logical coordinate. - CoreCoord virtual_cords = coordinate_manager->to(logical_coords, CoordSystem::VIRTUAL); + CoreCoord virtual_cords = coordinate_manager->translate_coord_to(logical_coords, CoordSystem::VIRTUAL); 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. - CoreCoord physical_cords = coordinate_manager->to(logical_coords, CoordSystem::PHYSICAL); + CoreCoord physical_cords = coordinate_manager->translate_coord_to(logical_coords, CoordSystem::PHYSICAL); EXPECT_EQ(physical_cords, CoreCoord(1, 1, CoreType::TENSIX, CoordSystem::PHYSICAL)); } @@ -60,11 +60,11 @@ TEST(CoordinateManager, CoordinateManagerGrayskullTopLeftCoreHarvesting) { CoreCoord logical_coords = CoreCoord(0, 0, CoreType::TENSIX, CoordSystem::LOGICAL); // Always expect same virtual coordinate for (0, 0) logical coordinate. - CoreCoord virtual_cords = coordinate_manager->to(logical_coords, CoordSystem::VIRTUAL); + CoreCoord virtual_cords = coordinate_manager->translate_coord_to(logical_coords, CoordSystem::VIRTUAL); 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. - CoreCoord physical_cords = coordinate_manager->to(logical_coords, CoordSystem::PHYSICAL); + CoreCoord physical_cords = coordinate_manager->translate_coord_to(logical_coords, CoordSystem::PHYSICAL); EXPECT_EQ(physical_cords, CoreCoord(1, 2, CoreType::TENSIX, CoordSystem::PHYSICAL)); } @@ -78,9 +78,10 @@ TEST(CoordinateManager, CoordinateManagerGrayskullTranslatingCoords) { for (size_t x = 0; x < tensix_grid_size.x; x++) { for (size_t y = 0; y < tensix_grid_size.y; y++) { CoreCoord logical_coords = CoreCoord(x, y, CoreType::TENSIX, CoordSystem::LOGICAL); - CoreCoord virtual_coords = coordinate_manager->to(logical_coords, CoordSystem::VIRTUAL); - CoreCoord physical_coords = coordinate_manager->to(logical_coords, CoordSystem::PHYSICAL); - CoreCoord translated_coords = coordinate_manager->to(logical_coords, CoordSystem::TRANSLATED); + CoreCoord virtual_coords = coordinate_manager->translate_coord_to(logical_coords, CoordSystem::VIRTUAL); + CoreCoord physical_coords = coordinate_manager->translate_coord_to(logical_coords, CoordSystem::PHYSICAL); + CoreCoord translated_coords = + coordinate_manager->translate_coord_to(logical_coords, CoordSystem::TRANSLATED); // Virtual, physical and translated coordinates should be the same. EXPECT_EQ(physical_coords.x, virtual_coords.x); @@ -112,7 +113,8 @@ TEST(CoordinateManager, CoordinateManagerGrayskullLogicalPhysicalMapping) { for (size_t x = 0; x < tensix_grid_size.x; x++) { for (size_t y = 0; y < tensix_grid_size.y - num_harvested_y; y++) { CoreCoord logical_coords = CoreCoord(x, y, CoreType::TENSIX, CoordSystem::LOGICAL); - CoreCoord physical_coords = coordinate_manager->to(logical_coords, CoordSystem::PHYSICAL); + CoreCoord physical_coords = + coordinate_manager->translate_coord_to(logical_coords, CoordSystem::PHYSICAL); logical_to_physical[logical_coords] = physical_coords; // Expect that logical to physical translation is 1-1 mapping. No duplicates for physical coordinates. @@ -127,7 +129,7 @@ TEST(CoordinateManager, CoordinateManagerGrayskullLogicalPhysicalMapping) { for (auto it : logical_to_physical) { CoreCoord physical_coords = it.second; - CoreCoord logical_coords = coordinate_manager->to(physical_coords, CoordSystem::LOGICAL); + CoreCoord logical_coords = coordinate_manager->translate_coord_to(physical_coords, CoordSystem::LOGICAL); // Expect that reverse mapping of physical coordinates gives the same logical coordinates // using which we got the physical coordinates. @@ -156,7 +158,7 @@ TEST(CoordinateManager, CoordinateManagerGrayskullLogicalVirtualMapping) { for (size_t x = 0; x < tensix_grid_size.x; x++) { for (size_t y = 0; y < tensix_grid_size.y - num_harvested_y; y++) { CoreCoord logical_coords = CoreCoord(x, y, CoreType::TENSIX, CoordSystem::LOGICAL); - CoreCoord virtual_coords = coordinate_manager->to(logical_coords, CoordSystem::VIRTUAL); + CoreCoord virtual_coords = coordinate_manager->translate_coord_to(logical_coords, CoordSystem::VIRTUAL); logical_to_virtual[logical_coords] = virtual_coords; // Expect that logical to virtual translation is 1-1 mapping. No duplicates for virtual coordinates. @@ -167,7 +169,7 @@ TEST(CoordinateManager, CoordinateManagerGrayskullLogicalVirtualMapping) { for (auto it : logical_to_virtual) { CoreCoord virtual_coords = it.second; - CoreCoord logical_coords = coordinate_manager->to(virtual_coords, CoordSystem::LOGICAL); + CoreCoord logical_coords = coordinate_manager->translate_coord_to(virtual_coords, CoordSystem::LOGICAL); // Expect that reverse mapping of virtual coordinates gives the same logical coordinates // using which we got the virtual coordinates. @@ -193,7 +195,7 @@ TEST(CoordinateManager, CoordinateManagerGrayskullPhysicalHarvestedMapping) { for (size_t index = 0; index < num_harvested * tensix_grid_size.x; index++) { const CoreCoord physical_core = CoreCoord(tensix_cores[index].x, tensix_cores[index].y, CoreType::TENSIX, CoordSystem::PHYSICAL); - const CoreCoord virtual_core = coordinate_manager->to(physical_core, CoordSystem::VIRTUAL); + const CoreCoord virtual_core = coordinate_manager->translate_coord_to(physical_core, CoordSystem::VIRTUAL); EXPECT_EQ(virtual_core.x, tensix_cores[virtual_index].x); EXPECT_EQ(virtual_core.y, tensix_cores[virtual_index].y); @@ -219,11 +221,13 @@ TEST(CoordinateManager, CoordinateManagerGrayskullPhysicalTranslatedHarvestedMap for (size_t index = 0; index < num_harvested * tensix_grid_size.x; index++) { const CoreCoord physical_core = CoreCoord(tensix_cores[index].x, tensix_cores[index].y, CoreType::TENSIX, CoordSystem::PHYSICAL); - const CoreCoord translated_core = coordinate_manager->to(physical_core, CoordSystem::TRANSLATED); + const CoreCoord translated_core = + coordinate_manager->translate_coord_to(physical_core, CoordSystem::TRANSLATED); const CoreCoord virtual_core = CoreCoord( tensix_cores[virtual_index].x, tensix_cores[virtual_index].y, CoreType::TENSIX, CoordSystem::VIRTUAL); - const CoreCoord translated_core_from_virtual = coordinate_manager->to(virtual_core, CoordSystem::TRANSLATED); + const CoreCoord translated_core_from_virtual = + coordinate_manager->translate_coord_to(virtual_core, CoordSystem::TRANSLATED); EXPECT_EQ(translated_core, translated_core_from_virtual); @@ -248,7 +252,7 @@ TEST(CoordinateManager, CoordinateManagerGrayskullDRAMNoHarvesting) { const CoreCoord expected_physical = CoreCoord(dram_cores[dram_bank].x, dram_cores[dram_bank].y, CoreType::DRAM, CoordSystem::PHYSICAL); - const CoreCoord dram_physical = coordinate_manager->to(dram_logical, CoordSystem::PHYSICAL); + const CoreCoord dram_physical = coordinate_manager->translate_coord_to(dram_logical, CoordSystem::PHYSICAL); EXPECT_EQ(dram_physical, expected_physical); } @@ -263,9 +267,10 @@ TEST(CoordinateManager, CoordinateManagerGrayskullPCIETranslation) { for (size_t x = 0; x < pcie_grid_size.x; x++) { for (size_t y = 0; y < pcie_grid_size.y; y++) { const CoreCoord pcie_logical = CoreCoord(x, y, CoreType::PCIE, CoordSystem::LOGICAL); - const CoreCoord pcie_virtual = coordinate_manager->to(pcie_logical, CoordSystem::VIRTUAL); - const CoreCoord pcie_physical = coordinate_manager->to(pcie_logical, CoordSystem::PHYSICAL); - const CoreCoord pcie_translated = coordinate_manager->to(pcie_logical, CoordSystem::TRANSLATED); + const CoreCoord pcie_virtual = coordinate_manager->translate_coord_to(pcie_logical, CoordSystem::VIRTUAL); + const CoreCoord pcie_physical = coordinate_manager->translate_coord_to(pcie_logical, CoordSystem::PHYSICAL); + const CoreCoord pcie_translated = + coordinate_manager->translate_coord_to(pcie_logical, CoordSystem::TRANSLATED); EXPECT_EQ(pcie_virtual.x, pcie_physical.x); EXPECT_EQ(pcie_virtual.y, pcie_physical.y); @@ -285,9 +290,10 @@ TEST(CoordinateManager, CoordinateManagerGrayskullARCTranslation) { for (size_t x = 0; x < arc_grid_size.x; x++) { for (size_t y = 0; y < arc_grid_size.y; y++) { const CoreCoord arc_logical = CoreCoord(x, y, CoreType::ARC, CoordSystem::LOGICAL); - const CoreCoord arc_virtual = coordinate_manager->to(arc_logical, CoordSystem::VIRTUAL); - const CoreCoord arc_physical = coordinate_manager->to(arc_logical, CoordSystem::PHYSICAL); - const CoreCoord arc_translated = coordinate_manager->to(arc_logical, CoordSystem::TRANSLATED); + const CoreCoord arc_virtual = coordinate_manager->translate_coord_to(arc_logical, CoordSystem::VIRTUAL); + const CoreCoord arc_physical = coordinate_manager->translate_coord_to(arc_logical, CoordSystem::PHYSICAL); + const CoreCoord arc_translated = + coordinate_manager->translate_coord_to(arc_logical, CoordSystem::TRANSLATED); EXPECT_EQ(arc_virtual.x, arc_physical.x); EXPECT_EQ(arc_virtual.y, arc_physical.y); diff --git a/tests/api/test_core_coord_translation_wh.cpp b/tests/api/test_core_coord_translation_wh.cpp index 933499b4..b9b4718a 100644 --- a/tests/api/test_core_coord_translation_wh.cpp +++ b/tests/api/test_core_coord_translation_wh.cpp @@ -13,18 +13,18 @@ using namespace tt::umd; // Tests that all physical coordinates are same as all virtual coordinates // when there is no harvesting. TEST(CoordinateManager, CoordinateManagerWormholeNoHarvesting) { - const size_t harvesting_mask = 0; - std::shared_ptr coordinate_manager = - CoordinateManager::create_coordinate_manager(tt::ARCH::WORMHOLE_B0, 0, 0); + CoordinateManager::create_coordinate_manager(tt::ARCH::WORMHOLE_B0); // We expect full grid size since there is no harvesting. tt_xy_pair tensix_grid_size = tt::umd::wormhole::TENSIX_GRID_SIZE; for (size_t x = 0; x < tensix_grid_size.x; x++) { for (size_t y = 0; y < tensix_grid_size.y; y++) { const CoreCoord logical_coords = CoreCoord(x, y, CoreType::TENSIX, CoordSystem::LOGICAL); - const CoreCoord virtual_coords = coordinate_manager->to(logical_coords, CoordSystem::VIRTUAL); - const CoreCoord physical_coords = coordinate_manager->to(logical_coords, CoordSystem::PHYSICAL); + const CoreCoord virtual_coords = + coordinate_manager->translate_coord_to(logical_coords, CoordSystem::VIRTUAL); + const CoreCoord physical_coords = + coordinate_manager->translate_coord_to(logical_coords, CoordSystem::PHYSICAL); // Virtual and physical coordinates should be the same. EXPECT_EQ(physical_coords.x, virtual_coords.x); @@ -47,11 +47,11 @@ TEST(CoordinateManager, CoordinateManagerWormholeTopLeftCore) { CoreCoord logical_coords = CoreCoord(0, 0, CoreType::TENSIX, CoordSystem::LOGICAL); // Always expect same virtual coordinate for (0, 0) logical coordinate. - CoreCoord virtual_cords = coordinate_manager->to(logical_coords, CoordSystem::VIRTUAL); + CoreCoord virtual_cords = coordinate_manager->translate_coord_to(logical_coords, CoordSystem::VIRTUAL); 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. - CoreCoord physical_cords = coordinate_manager->to(logical_coords, CoordSystem::PHYSICAL); + CoreCoord physical_cords = coordinate_manager->translate_coord_to(logical_coords, CoordSystem::PHYSICAL); EXPECT_EQ(physical_cords, CoreCoord(1, 2, CoreType::TENSIX, CoordSystem::PHYSICAL)); } @@ -75,7 +75,8 @@ TEST(CoordinateManager, CoordinateManagerWormholeLogicalPhysicalMapping) { for (size_t x = 0; x < tensix_grid_size.x; x++) { for (size_t y = 0; y < tensix_grid_size.y - num_harvested_y; y++) { CoreCoord logical_coords = CoreCoord(x, y, CoreType::TENSIX, CoordSystem::LOGICAL); - CoreCoord physical_coords = coordinate_manager->to(logical_coords, CoordSystem::PHYSICAL); + CoreCoord physical_coords = + coordinate_manager->translate_coord_to(logical_coords, CoordSystem::PHYSICAL); logical_to_physical[logical_coords] = physical_coords; // Expect that logical to physical translation is 1-1 mapping. No duplicates for physical coordinates. @@ -90,7 +91,7 @@ TEST(CoordinateManager, CoordinateManagerWormholeLogicalPhysicalMapping) { for (auto it : logical_to_physical) { CoreCoord physical_coords = it.second; - CoreCoord logical_coords = coordinate_manager->to(physical_coords, CoordSystem::LOGICAL); + CoreCoord logical_coords = coordinate_manager->translate_coord_to(physical_coords, CoordSystem::LOGICAL); // Expect that reverse mapping of physical coordinates gives the same logical coordinates // using which we got the physical coordinates. @@ -119,7 +120,7 @@ TEST(CoordinateManager, CoordinateManagerWormholeLogicalVirtualMapping) { for (size_t x = 0; x < tensix_grid_size.x; x++) { for (size_t y = 0; y < tensix_grid_size.y - num_harvested_y; y++) { CoreCoord logical_coords = CoreCoord(x, y, CoreType::TENSIX, CoordSystem::LOGICAL); - CoreCoord virtual_coords = coordinate_manager->to(logical_coords, CoordSystem::VIRTUAL); + CoreCoord virtual_coords = coordinate_manager->translate_coord_to(logical_coords, CoordSystem::VIRTUAL); logical_to_virtual[logical_coords] = virtual_coords; // Expect that logical to virtual translation is 1-1 mapping. No duplicates for virtual coordinates. @@ -130,7 +131,7 @@ TEST(CoordinateManager, CoordinateManagerWormholeLogicalVirtualMapping) { for (auto it : logical_to_virtual) { CoreCoord virtual_coords = it.second; - CoreCoord logical_coords = coordinate_manager->to(virtual_coords, CoordSystem::LOGICAL); + CoreCoord logical_coords = coordinate_manager->translate_coord_to(virtual_coords, CoordSystem::LOGICAL); // Expect that reverse mapping of virtual coordinates gives the same logical coordinates // using which we got the virtual coordinates. @@ -159,12 +160,15 @@ TEST(CoordinateManager, CoordinateManagerWormholeLogicalTranslatedTopLeft) { size_t num_harvested_y = CoordinateManager::get_num_harvested(harvesting_mask); CoreCoord logical_coords = CoreCoord(0, 0, CoreType::TENSIX, CoordSystem::LOGICAL); - CoreCoord physical_coords = coordinate_manager->to(logical_coords, CoordSystem::PHYSICAL); - CoreCoord virtual_coords = coordinate_manager->to(logical_coords, CoordSystem::VIRTUAL); + CoreCoord physical_coords = coordinate_manager->translate_coord_to(logical_coords, CoordSystem::PHYSICAL); + CoreCoord virtual_coords = coordinate_manager->translate_coord_to(logical_coords, CoordSystem::VIRTUAL); - CoreCoord translated_from_logical = coordinate_manager->to(logical_coords, CoordSystem::TRANSLATED); - CoreCoord translated_from_physical = coordinate_manager->to(physical_coords, CoordSystem::TRANSLATED); - CoreCoord translated_from_virtual = coordinate_manager->to(virtual_coords, CoordSystem::TRANSLATED); + CoreCoord translated_from_logical = + coordinate_manager->translate_coord_to(logical_coords, CoordSystem::TRANSLATED); + CoreCoord translated_from_physical = + coordinate_manager->translate_coord_to(physical_coords, CoordSystem::TRANSLATED); + CoreCoord translated_from_virtual = + coordinate_manager->translate_coord_to(virtual_coords, CoordSystem::TRANSLATED); EXPECT_EQ(translated_from_logical, expected_translated_coords); EXPECT_EQ(translated_from_physical, expected_translated_coords); @@ -189,7 +193,7 @@ TEST(CoordinateManager, CoordinateManagerWormholePhysicalVirtualHarvestedMapping for (size_t index = 0; index < num_harvested * tensix_grid_size.x; index++) { const CoreCoord physical_core = CoreCoord(tensix_cores[index].x, tensix_cores[index].y, CoreType::TENSIX, CoordSystem::PHYSICAL); - const CoreCoord virtual_core = coordinate_manager->to(physical_core, CoordSystem::VIRTUAL); + const CoreCoord virtual_core = coordinate_manager->translate_coord_to(physical_core, CoordSystem::VIRTUAL); EXPECT_EQ(virtual_core.x, tensix_cores[virtual_index].x); EXPECT_EQ(virtual_core.y, tensix_cores[virtual_index].y); @@ -221,11 +225,13 @@ TEST(CoordinateManager, CoordinateManagerWormholePhysicalTranslatedHarvestedMapp for (size_t index = 0; index < num_harvested * tensix_grid_size.x; index++) { const CoreCoord physical_core = CoreCoord(tensix_cores[index].x, tensix_cores[index].y, CoreType::TENSIX, CoordSystem::PHYSICAL); - const CoreCoord translated_core = coordinate_manager->to(physical_core, CoordSystem::TRANSLATED); + const CoreCoord translated_core = + coordinate_manager->translate_coord_to(physical_core, CoordSystem::TRANSLATED); const CoreCoord virtual_core = CoreCoord( tensix_cores[virtual_index].x, tensix_cores[virtual_index].y, CoreType::TENSIX, CoordSystem::VIRTUAL); - const CoreCoord translated_core_from_virtual = coordinate_manager->to(virtual_core, CoordSystem::TRANSLATED); + const CoreCoord translated_core_from_virtual = + coordinate_manager->translate_coord_to(virtual_core, CoordSystem::TRANSLATED); EXPECT_EQ(translated_core, translated_core_from_virtual); @@ -263,7 +269,7 @@ TEST(CoordinateManager, CoordinateManagerWormholeDRAMNoHarvesting) { CoreType::DRAM, CoordSystem::PHYSICAL); - const CoreCoord dram_physical = coordinate_manager->to(dram_logical, CoordSystem::PHYSICAL); + const CoreCoord dram_physical = coordinate_manager->translate_coord_to(dram_logical, CoordSystem::PHYSICAL); EXPECT_EQ(dram_physical, expected_physical); } @@ -280,8 +286,8 @@ TEST(CoordinateManager, CoordinateManagerWormholeETHPhysicalEqualVirtual) { for (size_t x = 0; x < eth_grid_size.x; x++) { for (size_t y = 0; y < eth_grid_size.y; y++) { const CoreCoord eth_logical = CoreCoord(x, y, CoreType::ETH, CoordSystem::LOGICAL); - const CoreCoord eth_virtual = coordinate_manager->to(eth_logical, CoordSystem::VIRTUAL); - const CoreCoord eth_physical = coordinate_manager->to(eth_logical, CoordSystem::PHYSICAL); + const CoreCoord eth_virtual = coordinate_manager->translate_coord_to(eth_logical, CoordSystem::VIRTUAL); + const CoreCoord eth_physical = coordinate_manager->translate_coord_to(eth_logical, CoordSystem::PHYSICAL); EXPECT_EQ(eth_virtual.x, eth_physical.x); EXPECT_EQ(eth_virtual.y, eth_physical.y); @@ -298,7 +304,8 @@ TEST(CoordinateManager, CoordinateManagerWormholeETHLogicalToTranslated) { for (size_t x = 0; x < eth_grid_size.x; x++) { for (size_t y = 0; y < eth_grid_size.y; y++) { const CoreCoord eth_logical = CoreCoord(x, y, CoreType::ETH, CoordSystem::LOGICAL); - const CoreCoord eth_translated = coordinate_manager->to(eth_logical, CoordSystem::TRANSLATED); + const CoreCoord eth_translated = + coordinate_manager->translate_coord_to(eth_logical, CoordSystem::TRANSLATED); EXPECT_EQ(eth_translated.x, x + 18); EXPECT_EQ(eth_translated.y, y + 16); @@ -315,9 +322,10 @@ TEST(CoordinateManager, CoordinateManagerWormholeARCTranslation) { for (size_t x = 0; x < arc_grid_size.x; x++) { for (size_t y = 0; y < arc_grid_size.y; y++) { const CoreCoord arc_logical = CoreCoord(x, y, CoreType::ARC, CoordSystem::LOGICAL); - const CoreCoord arc_virtual = coordinate_manager->to(arc_logical, CoordSystem::VIRTUAL); - const CoreCoord arc_physical = coordinate_manager->to(arc_logical, CoordSystem::PHYSICAL); - const CoreCoord arc_translated = coordinate_manager->to(arc_logical, CoordSystem::TRANSLATED); + const CoreCoord arc_virtual = coordinate_manager->translate_coord_to(arc_logical, CoordSystem::VIRTUAL); + const CoreCoord arc_physical = coordinate_manager->translate_coord_to(arc_logical, CoordSystem::PHYSICAL); + const CoreCoord arc_translated = + coordinate_manager->translate_coord_to(arc_logical, CoordSystem::TRANSLATED); EXPECT_EQ(arc_virtual.x, arc_physical.x); EXPECT_EQ(arc_virtual.y, arc_physical.y); @@ -337,9 +345,10 @@ TEST(CoordinateManager, CoordinateManagerWormholePCIETranslation) { for (size_t x = 0; x < pcie_grid_size.x; x++) { for (size_t y = 0; y < pcie_grid_size.y; y++) { const CoreCoord pcie_logical = CoreCoord(x, y, CoreType::PCIE, CoordSystem::LOGICAL); - const CoreCoord pcie_virtual = coordinate_manager->to(pcie_logical, CoordSystem::VIRTUAL); - const CoreCoord pcie_physical = coordinate_manager->to(pcie_logical, CoordSystem::PHYSICAL); - const CoreCoord pcie_translated = coordinate_manager->to(pcie_logical, CoordSystem::TRANSLATED); + const CoreCoord pcie_virtual = coordinate_manager->translate_coord_to(pcie_logical, CoordSystem::VIRTUAL); + const CoreCoord pcie_physical = coordinate_manager->translate_coord_to(pcie_logical, CoordSystem::PHYSICAL); + const CoreCoord pcie_translated = + coordinate_manager->translate_coord_to(pcie_logical, CoordSystem::TRANSLATED); EXPECT_EQ(pcie_virtual.x, pcie_physical.x); EXPECT_EQ(pcie_virtual.y, pcie_physical.y); diff --git a/tests/api/test_soc_descriptor.cpp b/tests/api/test_soc_descriptor.cpp index 993d028e..00a02eec 100644 --- a/tests/api/test_soc_descriptor.cpp +++ b/tests/api/test_soc_descriptor.cpp @@ -112,8 +112,8 @@ TEST(SocDescriptor, SocDescriptorWormholeETHLogicalToPhysical) { for (size_t y = 0; y < eth_grid_size.y; y++) { for (size_t x = 0; x < eth_grid_size.x; x++) { const CoreCoord eth_logical = CoreCoord(x, y, CoreType::ETH, CoordSystem::LOGICAL); - const CoreCoord eth_physical = soc_desc.to(eth_logical, CoordSystem::PHYSICAL); - const CoreCoord eth_virtual = soc_desc.to(eth_logical, CoordSystem::VIRTUAL); + const CoreCoord eth_physical = soc_desc.translate_coord_to(eth_logical, CoordSystem::PHYSICAL); + const CoreCoord eth_virtual = soc_desc.translate_coord_to(eth_logical, CoordSystem::VIRTUAL); EXPECT_EQ(eth_physical.x, wormhole_eth_cores[index].x); EXPECT_EQ(eth_physical.y, wormhole_eth_cores[index].y); @@ -216,9 +216,9 @@ TEST(SocDescriptor, CustomSocDescriptor) { tt_SocDescriptor soc_desc(test_utils::GetAbsPath("tests/soc_descs/blackhole_simulation_1x2.yaml"), 0, 0); const CoreCoord tensix_core_01 = CoreCoord(0, 1, CoreType::TENSIX, CoordSystem::PHYSICAL); - const CoreCoord tensix_core_01_virtual = soc_desc.to(tensix_core_01, CoordSystem::VIRTUAL); - const CoreCoord tensix_core_01_logical = soc_desc.to(tensix_core_01, CoordSystem::LOGICAL); - const CoreCoord tensix_core_01_translated = soc_desc.to(tensix_core_01, CoordSystem::TRANSLATED); + const CoreCoord tensix_core_01_virtual = soc_desc.translate_coord_to(tensix_core_01, CoordSystem::VIRTUAL); + const CoreCoord tensix_core_01_logical = soc_desc.translate_coord_to(tensix_core_01, CoordSystem::LOGICAL); + const CoreCoord tensix_core_01_translated = soc_desc.translate_coord_to(tensix_core_01, CoordSystem::TRANSLATED); EXPECT_EQ(tensix_core_01_virtual.x, tensix_core_01.x); EXPECT_EQ(tensix_core_01_virtual.y, tensix_core_01.y); @@ -230,9 +230,9 @@ TEST(SocDescriptor, CustomSocDescriptor) { EXPECT_EQ(tensix_core_01_logical.y, 0); const CoreCoord tensix_core_11 = CoreCoord(1, 1, CoreType::TENSIX, CoordSystem::PHYSICAL); - const CoreCoord tensix_core_11_virtual = soc_desc.to(tensix_core_11, CoordSystem::VIRTUAL); - const CoreCoord tensix_core_11_logical = soc_desc.to(tensix_core_11, CoordSystem::LOGICAL); - const CoreCoord tensix_core_11_translated = soc_desc.to(tensix_core_11, CoordSystem::TRANSLATED); + const CoreCoord tensix_core_11_virtual = soc_desc.translate_coord_to(tensix_core_11, CoordSystem::VIRTUAL); + const CoreCoord tensix_core_11_logical = soc_desc.translate_coord_to(tensix_core_11, CoordSystem::LOGICAL); + const CoreCoord tensix_core_11_translated = soc_desc.translate_coord_to(tensix_core_11, CoordSystem::TRANSLATED); EXPECT_EQ(tensix_core_11_virtual.x, tensix_core_11.x); EXPECT_EQ(tensix_core_11_virtual.y, tensix_core_11.y); @@ -253,9 +253,9 @@ TEST(SocDescriptor, CustomSocDescriptor) { EXPECT_TRUE(harvested_tensix_cores.empty()); const CoreCoord dram_core_10 = CoreCoord(1, 0, CoreType::DRAM, CoordSystem::PHYSICAL); - const CoreCoord dram_core_10_virtual = soc_desc.to(dram_core_10, CoordSystem::VIRTUAL); - const CoreCoord dram_core_10_logical = soc_desc.to(dram_core_10, CoordSystem::LOGICAL); - const CoreCoord dram_core_10_translated = soc_desc.to(dram_core_10, CoordSystem::TRANSLATED); + const CoreCoord dram_core_10_virtual = soc_desc.translate_coord_to(dram_core_10, CoordSystem::VIRTUAL); + const CoreCoord dram_core_10_logical = soc_desc.translate_coord_to(dram_core_10, CoordSystem::LOGICAL); + const CoreCoord dram_core_10_translated = soc_desc.translate_coord_to(dram_core_10, CoordSystem::TRANSLATED); EXPECT_EQ(dram_core_10_virtual.x, dram_core_10.x); EXPECT_EQ(dram_core_10_virtual.y, dram_core_10.y); From 3015bada5127a65764dcdf64a9d7bc2bb20c1b4b Mon Sep 17 00:00:00 2001 From: pjanevski Date: Wed, 18 Dec 2024 15:56:25 +0000 Subject: [PATCH 2/5] Shorter functions --- device/cluster.cpp | 43 ++++++++----------------------------------- 1 file changed, 8 insertions(+), 35 deletions(-) diff --git a/device/cluster.cpp b/device/cluster.cpp index 7afa93f4..e99c30a3 100644 --- a/device/cluster.cpp +++ b/device/cluster.cpp @@ -690,7 +690,7 @@ void Cluster::configure_active_ethernet_cores_for_mmio_device( const tt_SocDescriptor& soc_desc = get_soc_descriptor(mmio_chip); for (const auto& core : active_eth_cores_per_chip) { CoreCoord virtual_coord = soc_desc.translate_coord_to(core, CoordSystem::VIRTUAL); - active_eth_cores_xy.insert(tt_xy_pair(virtual_coord.x, virtual_coord.y)); + active_eth_cores_xy.insert(virtual_coord); } configure_active_ethernet_cores_for_mmio_device(mmio_chip, active_eth_cores_xy); @@ -1011,12 +1011,8 @@ void Cluster::deassert_risc_reset_at_core(tt_cxy_pair core, const TensixSoftRese void Cluster::deassert_risc_reset_at_core( const chip_id_t chip, const CoreCoord core, const TensixSoftResetOptions& soft_resets) { - tt_cxy_pair virtual_core; - virtual_core.chip = chip; const CoreCoord virtual_coord = get_soc_descriptor(chip).translate_coord_to(core, CoordSystem::VIRTUAL); - virtual_core.x = virtual_coord.x; - virtual_core.y = virtual_coord.y; - deassert_risc_reset_at_core(virtual_core, soft_resets); + deassert_risc_reset_at_core({(size_t)chip, virtual_coord}, soft_resets); } void Cluster::assert_risc_reset_at_core(tt_cxy_pair core) { @@ -1040,12 +1036,8 @@ void Cluster::assert_risc_reset_at_core(tt_cxy_pair core) { } void Cluster::assert_risc_reset_at_core(const chip_id_t chip, const CoreCoord core) { - tt_cxy_pair virtual_core; - virtual_core.chip = chip; const CoreCoord virtual_coord = get_soc_descriptor(chip).translate_coord_to(core, CoordSystem::VIRTUAL); - virtual_core.x = virtual_coord.x; - virtual_core.y = virtual_coord.y; - assert_risc_reset_at_core(virtual_core); + assert_risc_reset_at_core({(size_t)chip, virtual_coord}); } // Free memory during teardown, and remove (clean/unlock) from any leftover mutexes. @@ -1111,12 +1103,8 @@ tt::Writer Cluster::get_static_tlb_writer(tt_cxy_pair target) { } tt::Writer Cluster::get_static_tlb_writer(const chip_id_t chip, const CoreCoord target) { - tt_cxy_pair virtual_core; - virtual_core.chip = chip; const CoreCoord virtual_coord = get_soc_descriptor(chip).translate_coord_to(target, CoordSystem::VIRTUAL); - virtual_core.x = virtual_coord.x; - virtual_core.y = virtual_coord.y; - return get_static_tlb_writer(virtual_core); + return get_static_tlb_writer({(size_t)chip, virtual_coord}); } void Cluster::write_device_memory( @@ -1365,12 +1353,8 @@ std::optional> Cluster::get_tlb_data_from_target( } std::optional> Cluster::get_tlb_data_from_target(const chip_id_t chip, CoreCoord core) { - tt_cxy_pair virtual_core; - virtual_core.chip = chip; const CoreCoord virtual_coord = get_soc_descriptor(chip).translate_coord_to(core, CoordSystem::VIRTUAL); - virtual_core.x = virtual_coord.x; - virtual_core.y = virtual_coord.y; - return get_tlb_data_from_target(virtual_core); + return get_tlb_data_from_target({(size_t)chip, virtual_coord}); } void Cluster::configure_tlb( @@ -1405,12 +1389,9 @@ void Cluster::configure_tlb( void Cluster::configure_tlb( chip_id_t logical_device_id, tt::umd::CoreCoord core, int32_t tlb_index, uint64_t address, uint64_t ordering) { - tt_xy_pair virtual_core; const CoreCoord virtual_coord = get_soc_descriptor(logical_device_id).translate_coord_to(core, CoordSystem::VIRTUAL); - virtual_core.x = virtual_coord.x; - virtual_core.y = virtual_coord.y; - configure_tlb(logical_device_id, virtual_core, tlb_index, address, ordering); + configure_tlb(logical_device_id, {virtual_coord.x, virtual_coord.y}, tlb_index, address, ordering); } void Cluster::set_fallback_tlb_ordering_mode(const std::string& fallback_tlb, uint64_t ordering) { @@ -3074,12 +3055,8 @@ void Cluster::write_to_device( CoreCoord core, uint64_t addr, const std::string& tlb_to_use) { - tt_cxy_pair virtual_core; - virtual_core.chip = chip; CoreCoord virtual_coord = get_soc_descriptor(chip).translate_coord_to(core, CoordSystem::VIRTUAL); - virtual_core.x = virtual_coord.x; - virtual_core.y = virtual_coord.y; - write_to_device(mem_ptr, size_in_bytes, virtual_core, addr, tlb_to_use); + write_to_device(mem_ptr, size_in_bytes, {(size_t)chip, virtual_coord}, addr, tlb_to_use); } void Cluster::read_mmio_device_register( @@ -3143,12 +3120,8 @@ void Cluster::read_from_device( void Cluster::read_from_device( void* mem_ptr, chip_id_t chip, CoreCoord core, uint64_t addr, uint32_t size, const std::string& fallback_tlb) { - tt_cxy_pair virtual_core; - virtual_core.chip = chip; CoreCoord virtual_coord = get_soc_descriptor(chip).translate_coord_to(core, CoordSystem::VIRTUAL); - virtual_core.x = virtual_coord.x; - virtual_core.y = virtual_coord.y; - read_from_device(mem_ptr, virtual_core, addr, size, fallback_tlb); + read_from_device(mem_ptr, {(size_t)chip, virtual_coord}, addr, size, fallback_tlb); } int Cluster::arc_msg( From 4e062db8ebfcf188ed45345b7e54e8aa3e7bfb7c Mon Sep 17 00:00:00 2001 From: pjanevski Date: Thu, 19 Dec 2024 16:21:07 +0000 Subject: [PATCH 3/5] Harvesting to another soc desc path --- device/cluster.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/device/cluster.cpp b/device/cluster.cpp index e99c30a3..8371c194 100644 --- a/device/cluster.cpp +++ b/device/cluster.cpp @@ -590,11 +590,8 @@ Cluster::Cluster( "Target device {} not present in current cluster!", chip_id); - // Note that initially soc_descriptors are not harvested, but will be harvested later if perform_harvesting is - // true. - // TODO: This should be changed, harvesting should be done in tt_socdescriptor's constructor and not as part of - // cluster class. - tt_SocDescriptor soc_desc = tt_SocDescriptor(sdesc_path); + size_t tensix_harvesting_mask = cluster_desc->get_harvesting_info().at(chip_id); + tt_SocDescriptor soc_desc = tt_SocDescriptor(sdesc_path, tensix_harvesting_mask); log_assert( cluster_desc->get_arch(chip_id) == soc_desc.arch, "Passed soc descriptor has {} arch, but for chip id {} has arch {}", From 7673425776850b3dde3bcafe55b7e552e90dc986 Mon Sep 17 00:00:00 2001 From: pjanevski Date: Thu, 19 Dec 2024 16:46:59 +0000 Subject: [PATCH 4/5] Cluster helper function for translation --- device/api/umd/device/cluster.h | 2 ++ device/cluster.cpp | 27 +++++++++++++++------------ 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/device/api/umd/device/cluster.h b/device/api/umd/device/cluster.h index 7b81ce09..08797d35 100644 --- a/device/api/umd/device/cluster.h +++ b/device/api/umd/device/cluster.h @@ -866,6 +866,8 @@ class Cluster : public tt_device { const bool clean_system_resources, bool perform_harvesting, std::unordered_map simulated_harvesting_masks); + tt::umd::CoreCoord translate_chip_coord( + const chip_id_t chip, const tt::umd::CoreCoord core_coord, const CoordSystem coord_system) const; // State variables tt_device_dram_address_params dram_address_params; diff --git a/device/cluster.cpp b/device/cluster.cpp index 8371c194..ffc626f9 100644 --- a/device/cluster.cpp +++ b/device/cluster.cpp @@ -684,9 +684,8 @@ void Cluster::configure_active_ethernet_cores_for_mmio_device( void Cluster::configure_active_ethernet_cores_for_mmio_device( const std::unordered_set& active_eth_cores_per_chip, chip_id_t mmio_chip) { std::unordered_set active_eth_cores_xy; - const tt_SocDescriptor& soc_desc = get_soc_descriptor(mmio_chip); for (const auto& core : active_eth_cores_per_chip) { - CoreCoord virtual_coord = soc_desc.translate_coord_to(core, CoordSystem::VIRTUAL); + CoreCoord virtual_coord = translate_chip_coord(mmio_chip, core, CoordSystem::VIRTUAL); active_eth_cores_xy.insert(virtual_coord); } @@ -1008,7 +1007,7 @@ void Cluster::deassert_risc_reset_at_core(tt_cxy_pair core, const TensixSoftRese void Cluster::deassert_risc_reset_at_core( const chip_id_t chip, const CoreCoord core, const TensixSoftResetOptions& soft_resets) { - const CoreCoord virtual_coord = get_soc_descriptor(chip).translate_coord_to(core, CoordSystem::VIRTUAL); + const CoreCoord virtual_coord = translate_chip_coord(chip, core, CoordSystem::VIRTUAL); deassert_risc_reset_at_core({(size_t)chip, virtual_coord}, soft_resets); } @@ -1033,7 +1032,7 @@ void Cluster::assert_risc_reset_at_core(tt_cxy_pair core) { } void Cluster::assert_risc_reset_at_core(const chip_id_t chip, const CoreCoord core) { - const CoreCoord virtual_coord = get_soc_descriptor(chip).translate_coord_to(core, CoordSystem::VIRTUAL); + const CoreCoord virtual_coord = translate_chip_coord(chip, core, CoordSystem::VIRTUAL); assert_risc_reset_at_core({(size_t)chip, virtual_coord}); } @@ -1100,7 +1099,7 @@ tt::Writer Cluster::get_static_tlb_writer(tt_cxy_pair target) { } tt::Writer Cluster::get_static_tlb_writer(const chip_id_t chip, const CoreCoord target) { - const CoreCoord virtual_coord = get_soc_descriptor(chip).translate_coord_to(target, CoordSystem::VIRTUAL); + const CoreCoord virtual_coord = translate_chip_coord(chip, target, CoordSystem::VIRTUAL); return get_static_tlb_writer({(size_t)chip, virtual_coord}); } @@ -1350,7 +1349,7 @@ std::optional> Cluster::get_tlb_data_from_target( } std::optional> Cluster::get_tlb_data_from_target(const chip_id_t chip, CoreCoord core) { - const CoreCoord virtual_coord = get_soc_descriptor(chip).translate_coord_to(core, CoordSystem::VIRTUAL); + const CoreCoord virtual_coord = translate_chip_coord(chip, core, CoordSystem::VIRTUAL); return get_tlb_data_from_target({(size_t)chip, virtual_coord}); } @@ -1386,8 +1385,7 @@ void Cluster::configure_tlb( void Cluster::configure_tlb( chip_id_t logical_device_id, tt::umd::CoreCoord core, int32_t tlb_index, uint64_t address, uint64_t ordering) { - const CoreCoord virtual_coord = - get_soc_descriptor(logical_device_id).translate_coord_to(core, CoordSystem::VIRTUAL); + const CoreCoord virtual_coord = translate_chip_coord(logical_device_id, core, CoordSystem::VIRTUAL); configure_tlb(logical_device_id, {virtual_coord.x, virtual_coord.y}, tlb_index, address, ordering); } @@ -2974,7 +2972,7 @@ void Cluster::l1_membar( const chip_id_t chip, const std::unordered_set& cores, const std::string& fallback_tlb) { std::unordered_set cores_xy; for (const auto& core : cores) { - const CoreCoord virtual_core = get_soc_descriptor(chip).translate_coord_to(core, CoordSystem::VIRTUAL); + const CoreCoord virtual_core = translate_chip_coord(chip, core, CoordSystem::VIRTUAL); cores_xy.insert({virtual_core.x, virtual_core.y}); } l1_membar(chip, fallback_tlb, cores_xy); @@ -3002,7 +3000,7 @@ void Cluster::dram_membar( const chip_id_t chip, const std::unordered_set& cores, const std::string& fallback_tlb) { std::unordered_set cores_xy; for (const auto& core : cores) { - const CoreCoord virtual_core = get_soc_descriptor(chip).translate_coord_to(core, CoordSystem::VIRTUAL); + const CoreCoord virtual_core = translate_chip_coord(chip, core, CoordSystem::VIRTUAL); cores_xy.insert({virtual_core.x, virtual_core.y}); } dram_membar(chip, fallback_tlb, cores_xy); @@ -3052,7 +3050,7 @@ void Cluster::write_to_device( CoreCoord core, uint64_t addr, const std::string& tlb_to_use) { - CoreCoord virtual_coord = get_soc_descriptor(chip).translate_coord_to(core, CoordSystem::VIRTUAL); + CoreCoord virtual_coord = translate_chip_coord(chip, core, CoordSystem::VIRTUAL); write_to_device(mem_ptr, size_in_bytes, {(size_t)chip, virtual_coord}, addr, tlb_to_use); } @@ -3117,7 +3115,7 @@ void Cluster::read_from_device( void Cluster::read_from_device( void* mem_ptr, chip_id_t chip, CoreCoord core, uint64_t addr, uint32_t size, const std::string& fallback_tlb) { - CoreCoord virtual_coord = get_soc_descriptor(chip).translate_coord_to(core, CoordSystem::VIRTUAL); + CoreCoord virtual_coord = translate_chip_coord(chip, core, CoordSystem::VIRTUAL); read_from_device(mem_ptr, {(size_t)chip, virtual_coord}, addr, size, fallback_tlb); } @@ -3404,4 +3402,9 @@ void Cluster::set_barrier_address_params(const barrier_address_params& barrier_a dram_address_params.DRAM_BARRIER_BASE = barrier_address_params_.dram_barrier_base; } +tt::umd::CoreCoord Cluster::translate_chip_coord( + const chip_id_t chip, const tt::umd::CoreCoord core_coord, const CoordSystem coord_system) const { + return get_soc_descriptor(chip).translate_coord_to(core_coord, coord_system); +} + } // namespace tt::umd From 1bd57f27ba5fdab533bc091498c93a37a0bfe6a3 Mon Sep 17 00:00:00 2001 From: pjanevski Date: Thu, 19 Dec 2024 17:23:22 +0000 Subject: [PATCH 5/5] Fix tests --- device/blackhole/blackhole_coordinate_manager.cpp | 3 +++ device/coordinate_manager.cpp | 3 +++ 2 files changed, 6 insertions(+) diff --git a/device/blackhole/blackhole_coordinate_manager.cpp b/device/blackhole/blackhole_coordinate_manager.cpp index 2ed09be6..ac8ad3f3 100644 --- a/device/blackhole/blackhole_coordinate_manager.cpp +++ b/device/blackhole/blackhole_coordinate_manager.cpp @@ -38,6 +38,9 @@ BlackholeCoordinateManager::BlackholeCoordinateManager( } void BlackholeCoordinateManager::translate_tensix_coords() { + if (CoordinateManager::get_num_harvested(tensix_harvesting_mask) > tensix_grid_size.x) { + tensix_harvesting_mask = 0; + } size_t num_harvested_x = CoordinateManager::get_num_harvested(tensix_harvesting_mask); size_t grid_size_x = tensix_grid_size.x; size_t grid_size_y = tensix_grid_size.y; diff --git a/device/coordinate_manager.cpp b/device/coordinate_manager.cpp index e218e467..99b052fe 100644 --- a/device/coordinate_manager.cpp +++ b/device/coordinate_manager.cpp @@ -86,6 +86,9 @@ CoreCoord CoordinateManager::translate_coord_to(const CoreCoord core_coord, cons } void CoordinateManager::translate_tensix_coords() { + if (CoordinateManager::get_num_harvested(tensix_harvesting_mask) > tensix_grid_size.y) { + tensix_harvesting_mask = 0; + } size_t num_harvested_y = CoordinateManager::get_num_harvested(tensix_harvesting_mask); size_t grid_size_x = tensix_grid_size.x; size_t grid_size_y = tensix_grid_size.y;