Skip to content

Commit

Permalink
Store cores in soc descriptor
Browse files Browse the repository at this point in the history
  • Loading branch information
pjanevskiTT committed Dec 12, 2024
1 parent d58d69c commit 4b6774d
Show file tree
Hide file tree
Showing 6 changed files with 215 additions and 124 deletions.
10 changes: 8 additions & 2 deletions device/api/umd/device/blackhole_coordinate_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,14 @@ class BlackholeCoordinateManager : public CoordinateManager {
void fill_pcie_physical_translated_mapping() override;
void fill_dram_physical_translated_mapping() override;

void fill_tensix_core_structures() override;
void fill_dram_core_structures() override;
std::vector<tt::umd::CoreCoord> get_tensix_cores() const override;
std::vector<tt::umd::CoreCoord> get_harvested_tensix_cores() const override;
std::vector<tt::umd::CoreCoord> get_dram_cores() const override;
std::vector<tt::umd::CoreCoord> get_harvested_dram_cores() const override;
tt_xy_pair get_tensix_grid_size() const override;
tt_xy_pair get_dram_grid_size() const override;
tt_xy_pair get_harvested_tensix_grid_size() const override;
tt_xy_pair get_harvested_dram_grid_size() const override;

private:
void map_column_of_dram_banks(const size_t start_bank, const size_t end_bank, const size_t x_coord);
Expand Down
38 changes: 16 additions & 22 deletions device/api/umd/device/coordinate_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ class CoordinateManager {
static void assert_create_coordinate_manager(
const tt::ARCH arch, const size_t tensix_harvesting_mask, const size_t dram_harvesting_mask);

const std::vector<tt_xy_pair>& get_physical_pairs(const CoreType core_type) const;
std::vector<tt::umd::CoreCoord> get_all_physical_cores(const CoreType core_type) const;

protected:
/*
* Constructor for Coordinate Manager.
Expand Down Expand Up @@ -93,12 +96,14 @@ class CoordinateManager {
void identity_map_physical_cores();
void add_core_translation(const tt::umd::CoreCoord& core_coord, const tt_xy_pair& physical_pair);

void fill_core_structures();
virtual void fill_tensix_core_structures();
virtual void fill_dram_core_structures();
virtual void fill_eth_core_structures();
virtual void fill_arc_core_structures();
virtual void fill_pcie_core_structures();
virtual std::vector<tt::umd::CoreCoord> get_tensix_cores() const;
virtual std::vector<tt::umd::CoreCoord> get_harvested_tensix_cores() const;
virtual std::vector<tt::umd::CoreCoord> get_dram_cores() const;
virtual std::vector<tt::umd::CoreCoord> get_harvested_dram_cores() const;
virtual tt_xy_pair get_tensix_grid_size() const;
virtual tt_xy_pair get_dram_grid_size() const;
virtual tt_xy_pair get_harvested_tensix_grid_size() const;
virtual tt_xy_pair get_harvested_dram_grid_size() const;

/*
* Fills the logical to translated mapping for the tensix cores.
Expand Down Expand Up @@ -148,31 +153,20 @@ class CoordinateManager {
std::map<std::pair<tt_xy_pair, CoordSystem>, tt::umd::CoreCoord> from_physical_map;

tt_xy_pair tensix_grid_size;
const std::vector<tt_xy_pair>& tensix_cores;
std::vector<tt::umd::CoreCoord> unharvested_tensix_cores;
tt_xy_pair harvested_tensix_grid_size;
std::vector<tt::umd::CoreCoord> harvested_tensix_cores;
const std::vector<tt_xy_pair> tensix_cores;
size_t tensix_harvesting_mask;
const size_t physical_layout_tensix_harvesting_mask;

tt_xy_pair dram_grid_size;
const std::vector<tt_xy_pair>& dram_cores;
std::vector<tt::umd::CoreCoord> unharvested_dram_cores;
tt_xy_pair harvested_dram_grid_size;
std::vector<tt::umd::CoreCoord> harvested_dram_cores;
const std::vector<tt_xy_pair> dram_cores;
size_t dram_harvesting_mask;

tt_xy_pair eth_grid_size;
const std::vector<tt_xy_pair>& eth_cores;
std::vector<tt::umd::CoreCoord> unharvested_eth_cores;
const std::vector<tt_xy_pair> eth_cores;

tt_xy_pair arc_grid_size;
const std::vector<tt_xy_pair>& arc_cores;
std::vector<tt::umd::CoreCoord> unharvested_arc_cores;
const std::vector<tt_xy_pair> arc_cores;

tt_xy_pair pcie_grid_size;
const std::vector<tt_xy_pair>& pcie_cores;
std::vector<tt::umd::CoreCoord> unharvested_pcie_cores;
const std::vector<tt_xy_pair> pcie_cores;
};

// friend
11 changes: 10 additions & 1 deletion device/api/umd/device/tt_soc_descriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@ class tt_SocDescriptor {
eth_l1_size(other.eth_l1_size),
noc_translation_id_enabled(other.noc_translation_id_enabled),
dram_bank_size(other.dram_bank_size),
coordinate_manager(other.coordinate_manager) {}
coordinate_manager(other.coordinate_manager),
cores_map(other.cores_map),
grid_size_map(other.grid_size_map),
harvested_cores_map(other.harvested_cores_map),
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;
Expand Down Expand Up @@ -139,13 +143,18 @@ class tt_SocDescriptor {
void create_coordinate_manager(const std::size_t tensix_harvesting_mask, const std::size_t dram_harvesting_mask);
void load_core_descriptors_from_device_descriptor(YAML::Node &device_descriptor_yaml);
void load_soc_features_from_device_descriptor(YAML::Node &device_descriptor_yaml);
void get_cores_and_grid_size_from_coordinate_manager();

static tt_xy_pair calculate_grid_size(const std::vector<tt_xy_pair> &cores);

// TODO: change this to unique pointer as soon as copying of tt_SocDescriptor
// is not needed anymore. Soc descriptor and coordinate manager should be
// created once per chip.
std::shared_ptr<CoordinateManager> coordinate_manager = nullptr;
std::map<CoreType, std::vector<tt::umd::CoreCoord>> cores_map;
std::map<CoreType, tt_xy_pair> grid_size_map;
std::map<CoreType, std::vector<tt::umd::CoreCoord>> harvested_cores_map;
std::map<CoreType, tt_xy_pair> harvested_grid_size_map;
};

// Allocates a new soc descriptor on the heap. Returns an owning pointer.
Expand Down
72 changes: 55 additions & 17 deletions device/blackhole/blackhole_coordinate_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,40 +254,78 @@ void BlackholeCoordinateManager::fill_dram_physical_translated_mapping() {
}
}

void BlackholeCoordinateManager::fill_tensix_core_structures() {
std::vector<CoreCoord> BlackholeCoordinateManager::get_tensix_cores() const {
std::vector<size_t> harvested_x_coords = get_harvested_indices(tensix_harvesting_mask);
std::vector<CoreCoord> unharvested_tensix_cores;
for (size_t y = 0; y < tensix_grid_size.y; y++) {
for (size_t x = 0; x < tensix_grid_size.x; x++) {
const tt_xy_pair core = tensix_cores[y * tensix_grid_size.x + x];
CoreCoord core_coord(core.x, core.y, CoreType::TENSIX, CoordSystem::PHYSICAL);
if (std::find(harvested_x_coords.begin(), harvested_x_coords.end(), x) == harvested_x_coords.end()) {
unharvested_tensix_cores.push_back(core_coord);
} else {
}
}
}
return unharvested_tensix_cores;
}

std::vector<CoreCoord> BlackholeCoordinateManager::get_harvested_tensix_cores() const {
std::vector<size_t> harvested_x_coords = get_harvested_indices(tensix_harvesting_mask);
std::vector<CoreCoord> harvested_tensix_cores;
for (size_t y = 0; y < tensix_grid_size.y; y++) {
for (size_t x = 0; x < tensix_grid_size.x; x++) {
const tt_xy_pair core = tensix_cores[y * tensix_grid_size.x + x];
CoreCoord core_coord(core.x, core.y, CoreType::TENSIX, CoordSystem::PHYSICAL);
if (std::find(harvested_x_coords.begin(), harvested_x_coords.end(), x) != harvested_x_coords.end()) {
harvested_tensix_cores.push_back(core_coord);
}
}
}
const size_t num_harvested_x = harvested_x_coords.size();
tensix_grid_size.x -= num_harvested_x;
harvested_tensix_grid_size.x = num_harvested_x;
harvested_tensix_grid_size.y = tensix_grid_size.y;
return harvested_tensix_cores;
}

void BlackholeCoordinateManager::fill_dram_core_structures() {
std::vector<CoreCoord> BlackholeCoordinateManager::get_dram_cores() const {
std::vector<size_t> harvested_banks = get_harvested_indices(dram_harvesting_mask);
for (size_t bank = 0; bank < dram_grid_size.x; bank++) {
for (size_t port = 0; port < dram_grid_size.y; port++) {
const tt_xy_pair core = dram_cores[bank * dram_grid_size.y + port];
CoreCoord core_coord(core.x, core.y, CoreType::DRAM, CoordSystem::PHYSICAL);
if (std::find(harvested_banks.begin(), harvested_banks.end(), bank) == harvested_banks.end()) {
std::vector<CoreCoord> unharvested_dram_cores;
for (size_t x = 0; x < dram_grid_size.x; x++) {
if (std::find(harvested_banks.begin(), harvested_banks.end(), x) == harvested_banks.end()) {
for (size_t y = 0; y < dram_grid_size.y; y++) {
const tt_xy_pair core = dram_cores[x * dram_grid_size.y + y];
CoreCoord core_coord(core.x, core.y, CoreType::DRAM, CoordSystem::PHYSICAL);
unharvested_dram_cores.push_back(core_coord);
} else {
}
}
}
return unharvested_dram_cores;
}

std::vector<CoreCoord> BlackholeCoordinateManager::get_harvested_dram_cores() const {
std::vector<size_t> harvested_banks = get_harvested_indices(dram_harvesting_mask);
std::vector<CoreCoord> harvested_dram_cores;
for (size_t x = 0; x < dram_grid_size.x; x++) {
if (std::find(harvested_banks.begin(), harvested_banks.end(), x) != harvested_banks.end()) {
for (size_t y = 0; y < dram_grid_size.y; y++) {
const tt_xy_pair core = dram_cores[x * dram_grid_size.y + y];
CoreCoord core_coord(core.x, core.y, CoreType::DRAM, CoordSystem::PHYSICAL);
harvested_dram_cores.push_back(core_coord);
}
}
}
const size_t num_harvested_banks = harvested_banks.size();
dram_grid_size.x -= num_harvested_banks;
harvested_dram_grid_size.x = num_harvested_banks;
harvested_dram_grid_size.y = dram_grid_size.y;
return harvested_dram_cores;
}

tt_xy_pair BlackholeCoordinateManager::get_harvested_tensix_grid_size() const {
return {CoordinateManager::get_num_harvested(tensix_harvesting_mask), tensix_grid_size.y};
}

tt_xy_pair BlackholeCoordinateManager::get_harvested_dram_grid_size() const {
return {CoordinateManager::get_num_harvested(dram_harvesting_mask), dram_grid_size.y};
}

tt_xy_pair BlackholeCoordinateManager::get_tensix_grid_size() const {
return {tensix_grid_size.x - CoordinateManager::get_num_harvested(tensix_harvesting_mask), tensix_grid_size.y};
}

tt_xy_pair BlackholeCoordinateManager::get_dram_grid_size() const {
return {dram_grid_size.x - CoordinateManager::get_num_harvested(dram_harvesting_mask), dram_grid_size.y};
}
Loading

0 comments on commit 4b6774d

Please sign in to comment.