Skip to content

Commit

Permalink
#2680: Make Cluster const
Browse files Browse the repository at this point in the history
  • Loading branch information
abhullar-tt committed Dec 1, 2023
1 parent 30af527 commit f0a5624
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
14 changes: 7 additions & 7 deletions tt_metal/llrt/tt_cluster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand All @@ -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<chip_id_t, tt_SocDescriptor> &input,
const std::unordered_map<chip_id_t, uint32_t> &per_chip_id_harvesting_masks) {
const std::unordered_map<chip_id_t, uint32_t> &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,
Expand Down Expand Up @@ -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(
Expand All @@ -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;

Expand All @@ -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);
Expand Down
20 changes: 10 additions & 10 deletions tt_metal/llrt/tt_cluster.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -134,34 +134,34 @@ 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<chip_id_t, tt_SocDescriptor> &input, const std::unordered_map<chip_id_t, uint32_t> &per_chip_id_harvesting_masks);
void get_metal_desc_from_tt_desc(const std::unordered_map<chip_id_t, tt_SocDescriptor> &input, const std::unordered_map<chip_id_t, uint32_t> &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<chip_id_t, std::unique_ptr<tt_device>> mmio_device_id_to_driver_;
mutable std::unordered_map<chip_id_t, std::unique_ptr<tt_device>> 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
// devices
std::string cluster_desc_path_;
std::unique_ptr<tt_ClusterDescriptor> cluster_desc_;
// There is an entry for every device that can be targeted (MMIO and remote)
std::unordered_map<chip_id_t, metal_SocDescriptor> sdesc_per_chip_;
mutable std::unordered_map<chip_id_t, metal_SocDescriptor> 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<chip_id_t, std::set<chip_id_t>> devices_grouped_by_assoc_mmio_device_;
// Save mapping of device id to associated MMIO device id for fast lookup
std::unordered_map<chip_id_t, chip_id_t> device_to_mmio_device_;
// Holds collection of devices (MMIO and remote) that can be targeted
std::set<chip_id_t> target_device_ids_;
mutable std::set<chip_id_t> target_device_ids_;

tt_device_dram_address_params dram_address_params = {
DRAM_BARRIER_BASE
Expand Down

0 comments on commit f0a5624

Please sign in to comment.