Skip to content

Commit

Permalink
Coordinate manager refactors
Browse files Browse the repository at this point in the history
  • Loading branch information
pjanevskiTT committed Nov 28, 2024
1 parent 3328276 commit 321811e
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 89 deletions.
8 changes: 4 additions & 4 deletions device/api/umd/device/blackhole_coordinate_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@ class BlackholeCoordinateManager : public CoordinateManager {
arc_cores,
pcie_grid_size,
pcie_cores) {
this->tensix_harvesting(tensix_harvesting_mask);
this->dram_harvesting(dram_harvesting_mask);
this->translate_tensix_coords();
this->translate_dram_coords();
this->translate_eth_coords();
this->translate_arc_coords();
this->translate_pcie_coords();
}

protected:
void dram_harvesting(const size_t dram_harvesting_mask) override;
void tensix_harvesting(const size_t tensix_harvesting_mask) override;
void translate_dram_coords() override;
void translate_tensix_coords() override;

void fill_tensix_logical_to_translated() override;
void fill_eth_logical_to_translated() override;
Expand Down
7 changes: 2 additions & 5 deletions device/api/umd/device/coordinate_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,12 @@ class CoordinateManager {
tt::umd::CoreCoord to_translated(const tt::umd::CoreCoord core_coord);

protected:
virtual void tensix_harvesting(const size_t harvesting_mask);
virtual void dram_harvesting(const size_t dram_harvesting_mask);
virtual void translate_tensix_coords();
virtual void translate_dram_coords();
virtual void translate_eth_coords();
virtual void translate_arc_coords();
virtual void translate_pcie_coords();

void clear_tensix_harvesting_structures();
void clear_dram_harvesting_structures();

/*
* Fills the logical to translated mapping for the tensix cores.
* By default, translated coordinates are the same as physical coordinates.
Expand Down
4 changes: 2 additions & 2 deletions device/api/umd/device/grayskull_coordinate_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ class GrayskullCoordinateManager : public CoordinateManager {
arc_cores,
pcie_grid_size,
pcie_cores) {
this->tensix_harvesting(tensix_harvesting_mask);
this->dram_harvesting(dram_harvesting_mask);
this->translate_tensix_coords();
this->translate_dram_coords();
this->translate_eth_coords();
this->translate_arc_coords();
this->translate_pcie_coords();
Expand Down
4 changes: 2 additions & 2 deletions device/api/umd/device/wormhole_coordinate_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ class WormholeCoordinateManager : public CoordinateManager {
arc_cores,
pcie_grid_size,
pcie_cores) {
this->tensix_harvesting(tensix_harvesting_mask);
this->dram_harvesting(dram_harvesting_mask);
this->translate_tensix_coords();
this->translate_dram_coords();
this->translate_eth_coords();
this->translate_arc_coords();
this->translate_pcie_coords();
Expand Down
58 changes: 24 additions & 34 deletions device/blackhole/blackhole_coordinate_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,16 @@

using namespace tt::umd;

void BlackholeCoordinateManager::tensix_harvesting(const size_t tensix_harvesting_mask) {
CoordinateManager::tensix_harvesting_mask = tensix_harvesting_mask;
CoordinateManager::clear_tensix_harvesting_structures();

void BlackholeCoordinateManager::translate_tensix_coords() {
size_t num_harvested_x = __builtin_popcount(tensix_harvesting_mask);
size_t grid_size_x = CoordinateManager::tensix_grid_size.x;
size_t grid_size_y = CoordinateManager::tensix_grid_size.y;
size_t grid_size_x = tensix_grid_size.x;
size_t grid_size_y = tensix_grid_size.y;

size_t logical_x = 0;
for (size_t x = 0; x < grid_size_x; x++) {
if (!(tensix_harvesting_mask & (1 << x))) {
for (size_t y = 0; y < grid_size_y; y++) {
const tt_xy_pair& tensix_core = CoordinateManager::tensix_cores[x + y * grid_size_x];
const tt_xy_pair& tensix_core = tensix_cores[x + y * grid_size_x];
tensix_logical_to_physical[{logical_x, y}] =
CoreCoord(tensix_core.x, tensix_core.y, CoreType::TENSIX, CoordSystem::PHYSICAL);
tensix_physical_to_logical[tensix_core] =
Expand All @@ -31,7 +28,7 @@ void BlackholeCoordinateManager::tensix_harvesting(const size_t tensix_harvestin

for (size_t x = 0; x < grid_size_x - num_harvested_x; x++) {
for (size_t y = 0; y < grid_size_y; y++) {
const tt_xy_pair& tensix_core = CoordinateManager::tensix_cores[x + y * grid_size_x];
const tt_xy_pair& tensix_core = tensix_cores[x + y * grid_size_x];
tensix_logical_to_virtual[{x, y}] =
CoreCoord(tensix_core.x, tensix_core.y, CoreType::TENSIX, CoordSystem::VIRTUAL);
tensix_virtual_to_logical[tensix_core] = CoreCoord(x, y, CoreType::TENSIX, CoordSystem::LOGICAL);
Expand All @@ -42,74 +39,67 @@ void BlackholeCoordinateManager::tensix_harvesting(const size_t tensix_harvestin
}

void BlackholeCoordinateManager::fill_tensix_logical_to_translated() {
const size_t num_harvested_x = __builtin_popcount(CoordinateManager::tensix_harvesting_mask);
const size_t grid_size_x = CoordinateManager::tensix_grid_size.x;
const size_t grid_size_y = CoordinateManager::tensix_grid_size.y;
const size_t num_harvested_x = __builtin_popcount(tensix_harvesting_mask);
const size_t grid_size_x = tensix_grid_size.x;
const size_t grid_size_y = tensix_grid_size.y;

for (size_t x = 0; x < grid_size_x - num_harvested_x; x++) {
for (size_t y = 0; y < grid_size_y; y++) {
const CoreCoord virtual_coord = CoordinateManager::tensix_logical_to_virtual[{x, y}];
const CoreCoord virtual_coord = tensix_logical_to_virtual[{x, y}];
const size_t translated_x = virtual_coord.x;
const size_t translated_y = virtual_coord.y;
CoordinateManager::tensix_logical_to_translated[{x, y}] =
tensix_logical_to_translated[{x, y}] =
CoreCoord(translated_x, translated_y, CoreType::TENSIX, CoordSystem::TRANSLATED);
CoordinateManager::tensix_translated_to_logical[{translated_x, translated_y}] =
tensix_translated_to_logical[{translated_x, translated_y}] =
CoreCoord(x, y, CoreType::TENSIX, CoordSystem::LOGICAL);
}
}
}

void BlackholeCoordinateManager::dram_harvesting(const size_t dram_harvesting_mask) {
CoordinateManager::dram_harvesting_mask = dram_harvesting_mask;
CoordinateManager::clear_dram_harvesting_structures();

void BlackholeCoordinateManager::translate_dram_coords() {
size_t num_harvested_banks = __builtin_popcount(dram_harvesting_mask);

for (size_t x = 0; x < dram_grid_size.x - num_harvested_banks; x++) {
for (size_t y = 0; y < dram_grid_size.y; y++) {
const tt_xy_pair& dram_core = CoordinateManager::dram_cores[x * dram_grid_size.y + y];
CoordinateManager::dram_logical_to_virtual[{x, y}] =
CoreCoord(dram_core.x, dram_core.y, CoreType::DRAM, CoordSystem::VIRTUAL);
CoordinateManager::dram_virtual_to_logical[dram_core] =
CoreCoord(x, y, CoreType::DRAM, CoordSystem::LOGICAL);
const tt_xy_pair& dram_core = dram_cores[x * dram_grid_size.y + y];
dram_logical_to_virtual[{x, y}] = CoreCoord(dram_core.x, dram_core.y, CoreType::DRAM, CoordSystem::VIRTUAL);
dram_virtual_to_logical[dram_core] = CoreCoord(x, y, CoreType::DRAM, CoordSystem::LOGICAL);
}
}

size_t logical_x = 0;
for (size_t x = 0; x < dram_grid_size.x; x++) {
if (!(dram_harvesting_mask & (1 << x))) {
for (size_t y = 0; y < dram_grid_size.y; y++) {
const tt_xy_pair& dram_core = CoordinateManager::dram_cores[x * dram_grid_size.y + y];
CoordinateManager::dram_logical_to_physical[{logical_x, y}] =
const tt_xy_pair& dram_core = dram_cores[x * dram_grid_size.y + y];
dram_logical_to_physical[{logical_x, y}] =
CoreCoord(dram_core.x, dram_core.y, CoreType::DRAM, CoordSystem::PHYSICAL);
CoordinateManager::dram_physical_to_logical[dram_core] =
CoreCoord(logical_x, y, CoreType::DRAM, CoordSystem::LOGICAL);
dram_physical_to_logical[dram_core] = CoreCoord(logical_x, y, CoreType::DRAM, CoordSystem::LOGICAL);
}
logical_x++;
}
}
}

void BlackholeCoordinateManager::fill_eth_logical_to_translated() {
for (size_t x = 0; x < CoordinateManager::eth_grid_size.x; x++) {
for (size_t y = 0; y < CoordinateManager::eth_grid_size.y; y++) {
for (size_t x = 0; x < eth_grid_size.x; x++) {
for (size_t y = 0; y < eth_grid_size.y; y++) {
const size_t translated_x = x + eth_translated_coordinate_start_x;
const size_t translated_y = y + eth_translated_coordinate_start_y;
CoordinateManager::eth_logical_to_translated[{x, y}] =
eth_logical_to_translated[{x, y}] =
CoreCoord(translated_x, translated_y, CoreType::ETH, CoordSystem::TRANSLATED);
CoordinateManager::eth_translated_to_logical[{translated_x, translated_y}] =
eth_translated_to_logical[{translated_x, translated_y}] =
CoreCoord(x, y, CoreType::ETH, CoordSystem::LOGICAL);
}
}
}

void BlackholeCoordinateManager::fill_pcie_logical_to_translated() {
CoordinateManager::pcie_logical_to_translated[{0, 0}] = CoreCoord(
pcie_logical_to_translated[{0, 0}] = CoreCoord(
pcie_translated_coordinate_start_x,
pcie_translated_coordinate_start_y,
CoreType::PCIE,
CoordSystem::TRANSLATED);
CoordinateManager::pcie_translated_to_logical[{
pcie_translated_coordinate_start_x, pcie_translated_coordinate_start_y}] =
pcie_translated_to_logical[{pcie_translated_coordinate_start_x, pcie_translated_coordinate_start_y}] =
CoreCoord(0, 0, CoreType::PCIE, CoordSystem::LOGICAL);
}
32 changes: 4 additions & 28 deletions device/coordinate_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,35 +198,14 @@ CoreCoord CoordinateManager::to(const CoreCoord core_coord, const CoordSystem co
}
}

void CoordinateManager::clear_tensix_harvesting_structures() {
tensix_logical_to_physical.clear();
tensix_logical_to_virtual.clear();
tensix_physical_to_logical.clear();
tensix_virtual_to_logical.clear();
tensix_logical_to_translated.clear();
tensix_translated_to_logical.clear();
}

void CoordinateManager::clear_dram_harvesting_structures() {
dram_logical_to_virtual.clear();
dram_logical_to_physical.clear();
dram_virtual_to_logical.clear();
dram_physical_to_logical.clear();
dram_logical_to_translated.clear();
dram_translated_to_logical.clear();
}

void CoordinateManager::tensix_harvesting(const size_t harvesting_mask) {
this->tensix_harvesting_mask = harvesting_mask;
clear_tensix_harvesting_structures();

size_t num_harvested_y = __builtin_popcount(harvesting_mask);
void CoordinateManager::translate_tensix_coords() {
size_t num_harvested_y = __builtin_popcount(tensix_harvesting_mask);
size_t grid_size_x = tensix_grid_size.x;
size_t grid_size_y = tensix_grid_size.y;

size_t logical_y = 0;
for (size_t y = 0; y < grid_size_y; y++) {
if (!(harvesting_mask & (1 << y))) {
if (!(tensix_harvesting_mask & (1 << y))) {
for (size_t x = 0; x < grid_size_x; x++) {
const tt_xy_pair& tensix_core = tensix_cores[y * grid_size_x + x];
tensix_logical_to_physical[{x, logical_y}] =
Expand Down Expand Up @@ -266,10 +245,7 @@ void CoordinateManager::fill_tensix_logical_to_translated() {
}
}

void CoordinateManager::dram_harvesting(const size_t dram_harvesting_mask) {
this->dram_harvesting_mask = dram_harvesting_mask;
clear_dram_harvesting_structures();

void CoordinateManager::translate_dram_coords() {
for (size_t x = 0; x < dram_grid_size.x; x++) {
for (size_t y = 0; y < dram_grid_size.y; y++) {
const tt_xy_pair dram_core = dram_cores[x * dram_grid_size.y + y];
Expand Down
10 changes: 5 additions & 5 deletions device/grayskull/grayskull_coordinate_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
using namespace tt::umd;

void GrayskullCoordinateManager::fill_eth_logical_to_translated() {
for (size_t x = 0; x < CoordinateManager::eth_grid_size.x; x++) {
for (size_t y = 0; y < CoordinateManager::eth_grid_size.y; y++) {
const CoreCoord physical_coord = CoordinateManager::eth_logical_to_physical[{x, y}];
for (size_t x = 0; x < eth_grid_size.x; x++) {
for (size_t y = 0; y < eth_grid_size.y; y++) {
const CoreCoord physical_coord = eth_logical_to_physical[{x, y}];
const size_t translated_x = physical_coord.x;
const size_t translated_y = physical_coord.y;
CoordinateManager::eth_logical_to_translated[{x, y}] =
eth_logical_to_translated[{x, y}] =
CoreCoord(translated_x, translated_y, CoreType::ETH, CoordSystem::TRANSLATED);
CoordinateManager::eth_translated_to_logical[{translated_x, translated_y}] =
eth_translated_to_logical[{translated_x, translated_y}] =
CoreCoord(x, y, CoreType::ETH, CoordSystem::LOGICAL);
}
}
Expand Down
18 changes: 9 additions & 9 deletions device/wormhole/wormhole_coordinate_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,28 @@
using namespace tt::umd;

void WormholeCoordinateManager::fill_tensix_logical_to_translated() {
size_t num_harvested_y = __builtin_popcount(CoordinateManager::tensix_harvesting_mask);
size_t num_harvested_y = __builtin_popcount(tensix_harvesting_mask);

for (size_t y = 0; y < CoordinateManager::tensix_grid_size.y - num_harvested_y; y++) {
for (size_t x = 0; x < CoordinateManager::tensix_grid_size.x; x++) {
for (size_t y = 0; y < tensix_grid_size.y - num_harvested_y; y++) {
for (size_t x = 0; x < tensix_grid_size.x; x++) {
const size_t translated_x = x + tensix_translated_coordinate_start_x;
const size_t translated_y = y + tensix_translated_coordinate_start_y;
CoordinateManager::tensix_logical_to_translated[{x, y}] =
tensix_logical_to_translated[{x, y}] =
CoreCoord(translated_x, translated_y, CoreType::TENSIX, CoordSystem::TRANSLATED);
CoordinateManager::tensix_translated_to_logical[tt_xy_pair(translated_x, translated_y)] =
tensix_translated_to_logical[tt_xy_pair(translated_x, translated_y)] =
CoreCoord(x, y, CoreType::TENSIX, CoordSystem::LOGICAL);
}
}
}

void WormholeCoordinateManager::fill_eth_logical_to_translated() {
for (size_t x = 0; x < CoordinateManager::eth_grid_size.x; x++) {
for (size_t y = 0; y < CoordinateManager::eth_grid_size.y; y++) {
for (size_t x = 0; x < eth_grid_size.x; x++) {
for (size_t y = 0; y < eth_grid_size.y; y++) {
const size_t translated_x = x + eth_translated_coordinate_start_x;
const size_t translated_y = y + eth_translated_coordinate_start_y;
CoordinateManager::eth_logical_to_translated[{x, y}] =
eth_logical_to_translated[{x, y}] =
CoreCoord(translated_x, translated_y, CoreType::ETH, CoordSystem::TRANSLATED);
CoordinateManager::eth_translated_to_logical[{translated_x, translated_y}] =
eth_translated_to_logical[{translated_x, translated_y}] =
CoreCoord(x, y, CoreType::ETH, CoordSystem::LOGICAL);
}
}
Expand Down

0 comments on commit 321811e

Please sign in to comment.