diff --git a/tt_metal/llrt/tt_cluster.cpp b/tt_metal/llrt/tt_cluster.cpp index 8c11189d9d7..2f4c9e6bbea 100644 --- a/tt_metal/llrt/tt_cluster.cpp +++ b/tt_metal/llrt/tt_cluster.cpp @@ -31,7 +31,7 @@ static constexpr uint32_t DYNAMIC_TLB_BASE_INDEX = DEVICE_DATA.MEM_LARGE_READ_TL namespace tt { -Cluster &Cluster::instance() { +const Cluster &Cluster::instance() { static Cluster inst; return inst; } @@ -91,7 +91,7 @@ Cluster::Cluster() { } } -void Cluster::initialize_device_driver(chip_id_t device_id) { +void Cluster::initialize_device_driver(chip_id_t device_id) const { chip_id_t assoc_mmio_device_id = this->device_to_mmio_device_.at(device_id); if (this->mmio_device_id_to_driver_.count(assoc_mmio_device_id) and this->mmio_device_id_to_driver_.at(assoc_mmio_device_id) != nullptr) { TT_FATAL(this->target_device_ids_.find(device_id) != this->target_device_ids_.end(), "Expected UMD containing device {} to be initialized with group for MMIO device {}!", device_id, assoc_mmio_device_id); @@ -111,14 +111,14 @@ void Cluster::initialize_device_driver(chip_id_t device_id) { void Cluster::get_metal_desc_from_tt_desc( const std::unordered_map &input, - const std::unordered_map &per_chip_id_harvesting_masks) { + const std::unordered_map &per_chip_id_harvesting_masks) const { for (const auto it : input) { chip_id_t id = it.first; this->sdesc_per_chip_.emplace(id, metal_SocDescriptor(it.second, per_chip_id_harvesting_masks.at(id))); } } -void Cluster::open_device(chip_id_t device_id, const bool &skip_driver_allocs) { +void Cluster::open_device(chip_id_t device_id, const bool &skip_driver_allocs) const { #ifdef ARCH_GRAYSKULL TT_FATAL( this->arch_ == tt::ARCH::GRAYSKULL, @@ -250,7 +250,7 @@ std::int32_t get_static_tlb_index(CoreCoord target) { } #endif -void Cluster::configure_static_tlbs(chip_id_t mmio_device_id) { +void Cluster::configure_static_tlbs(chip_id_t mmio_device_id) const { auto sdesc = get_soc_desc(mmio_device_id); auto statically_mapped_cores = sdesc.workers; statically_mapped_cores.insert( @@ -273,7 +273,7 @@ void Cluster::configure_static_tlbs(chip_id_t mmio_device_id) { this->get_driver(mmio_device_id).setup_core_to_tlb_map([](CoreCoord core) { return get_static_tlb_index(core); }); } -void Cluster::start_device(chip_id_t device_id, tt_device_params &device_params) { +void Cluster::start_device(chip_id_t device_id, tt_device_params &device_params) const { chip_id_t mmio_device_id = this->device_to_mmio_device_.at(device_id); device_params.init_device = true; @@ -286,7 +286,7 @@ void Cluster::start_device(chip_id_t device_id, tt_device_params &device_params) this->mmio_device_id_to_driver_.at(mmio_device_id)->start_device(device_params); } -void Cluster::close_device_driver(chip_id_t device_id) { +void Cluster::close_device_driver(chip_id_t device_id) const { log_info(tt::LogDevice, "Closing device driver"); chip_id_t mmio_device_id = this->device_to_mmio_device_.at(device_id); diff --git a/tt_metal/llrt/tt_cluster.hpp b/tt_metal/llrt/tt_cluster.hpp index 64c09182834..fa2e4be02a9 100644 --- a/tt_metal/llrt/tt_cluster.hpp +++ b/tt_metal/llrt/tt_cluster.hpp @@ -41,15 +41,15 @@ class Cluster { Cluster(const Cluster &) = delete; Cluster(Cluster &&other) noexcept = delete; - static Cluster &instance(); + static const Cluster &instance(); size_t number_of_devices() const { return this->cluster_desc_->get_number_of_chips(); } size_t number_of_pci_devices() const { return this->cluster_desc_->get_chips_with_mmio().size(); } ARCH arch() const { return this->arch_; } - void initialize_device_driver(chip_id_t device_id); - void close_device_driver(chip_id_t device_id); + void initialize_device_driver(chip_id_t device_id) const; + void close_device_driver(chip_id_t device_id) const; const metal_SocDescriptor &get_soc_desc(chip_id_t chip) const; uint32_t get_harvested_rows(chip_id_t chip) const; @@ -134,19 +134,19 @@ class Cluster { Cluster(); ~Cluster(); - void open_device(chip_id_t device_id, const bool &skip_driver_allocs = false); - void start_device(chip_id_t device_id, tt_device_params &device_params); + void open_device(chip_id_t device_id, const bool &skip_driver_allocs = false) const; + void start_device(chip_id_t device_id, tt_device_params &device_params) const; tt_device &get_driver(chip_id_t device_id) const; - void get_metal_desc_from_tt_desc(const std::unordered_map &input, const std::unordered_map &per_chip_id_harvesting_masks); + void get_metal_desc_from_tt_desc(const std::unordered_map &input, const std::unordered_map &per_chip_id_harvesting_masks) const; tt_cxy_pair convert_physical_cxy_to_virtual(const tt_cxy_pair &physical_cxy) const; - void configure_static_tlbs(chip_id_t mmio_device_id); + void configure_static_tlbs(chip_id_t mmio_device_id) const; ARCH arch_; TargetDevice target_type_; // There is one device driver per PCIe card. This map points id of the MMIO device points to the associated device driver - std::unordered_map> mmio_device_id_to_driver_; + mutable std::unordered_map> mmio_device_id_to_driver_; // Need to hold reference to cluster descriptor to detect total number of devices available in cluster // UMD static APIs `detect_available_device_ids` and `detect_number_of_chips` only returns number of MMIO mapped @@ -154,14 +154,14 @@ class Cluster { std::string cluster_desc_path_; std::unique_ptr cluster_desc_; // There is an entry for every device that can be targeted (MMIO and remote) - std::unordered_map sdesc_per_chip_; + mutable std::unordered_map sdesc_per_chip_; // Collections of devices that are grouped based on the associated MMIO device. MMIO device is included in the grouping std::unordered_map> devices_grouped_by_assoc_mmio_device_; // Save mapping of device id to associated MMIO device id for fast lookup std::unordered_map device_to_mmio_device_; // Holds collection of devices (MMIO and remote) that can be targeted - std::set target_device_ids_; + mutable std::set target_device_ids_; tt_device_dram_address_params dram_address_params = { DRAM_BARRIER_BASE