Skip to content

Commit

Permalink
Optimize coord translation
Browse files Browse the repository at this point in the history
  • Loading branch information
pjanevskiTT committed Nov 22, 2024
1 parent 3fb5a0b commit 5665a44
Show file tree
Hide file tree
Showing 11 changed files with 269 additions and 415 deletions.
79 changes: 56 additions & 23 deletions device/blackhole/blackhole_coordinate_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,49 +4,82 @@
* SPDX-License-Identifier: Apache-2.0
*/
#include "blackhole_coordinate_manager.h"
#include <iostream>
void BlackholeCoordinateManager::tensix_harvesting(const std::size_t tensix_harvesting_mask) {
CoordinateManager::tensix_harvesting_mask = tensix_harvesting_mask;
CoordinateManager::clear_tensix_harvesting_structures();

std::size_t num_harvested_x = __builtin_popcount(tensix_harvesting_mask);
std::size_t grid_size_x = CoordinateManager::tensix_grid_size.x;
std::size_t grid_size_y = CoordinateManager::tensix_grid_size.y;

std::set<std::size_t> BlackholeCoordinateManager::get_x_coordinates_to_harvest(std::size_t harvesting_mask) {
std::set<std::size_t> x_to_harvest;
std::size_t logical_x = 0;
while (harvesting_mask > 0) {
if (harvesting_mask & 1) {
x_to_harvest.insert(logical_x);
for (std::size_t x = 0; x < grid_size_x; x++) {
if (!(tensix_harvesting_mask & (1 << x))) {
for (std::size_t y = 0; y < grid_size_y; y++) {
const tt_xy_pair& tensix_core = CoordinateManager::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] = CoreCoord(logical_x, y, CoreType::TENSIX, CoordSystem::LOGICAL);
}
logical_x++;
}
}
// std::cout << "tensix harvesting mask: " << tensix_harvesting_mask << std::endl;
// std::cout << "num harvested x: " << num_harvested_x << std::endl;
for (std::size_t x = 0; x < grid_size_x - num_harvested_x; x++) {
for (std::size_t y = 0; y < grid_size_y; y++) {
const tt_xy_pair& tensix_core = CoordinateManager::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);
}
logical_x++;
harvesting_mask >>= 1;
}
return x_to_harvest;
}

CoreCoord BlackholeCoordinateManager::translated_to_logical_tensix(const CoreCoord core_coord) {
const CoreCoord virtual_coord = CoreCoord(core_coord.x, core_coord.y, CoreType::TENSIX, CoordSystem::VIRTUAL);
return CoordinateManager::to_logical(virtual_coord);
BlackholeCoordinateManager::fill_tensix_logical_to_translated();
}

CoreCoord BlackholeCoordinateManager::logical_to_translated_tensix(const CoreCoord core_coord) {
const CoreCoord virtual_coord = CoordinateManager::to_virtual(core_coord);
return CoreCoord(virtual_coord.x, virtual_coord.y, CoreType::TENSIX, CoordSystem::TRANSLATED);
void BlackholeCoordinateManager::fill_tensix_logical_to_translated() {
const std::size_t num_harvested_x = __builtin_popcount(CoordinateManager::tensix_harvesting_mask);
const std::size_t grid_size_x = CoordinateManager::tensix_grid_size.x;
const std::size_t grid_size_y = CoordinateManager::tensix_grid_size.y;

// std::cout << "tensix harvesting mask: " << CoordinateManager::tensix_harvesting_mask << std::endl;

// std::cout << "num harvested x translated: " << num_harvested_x << std::endl;

for (std::size_t x = 0; x < grid_size_x - num_harvested_x; x++) {
for (std::size_t y = 0; y < grid_size_y; y++) {
const CoreCoord virtual_coord = CoordinateManager::tensix_logical_to_virtual[{x, y}];
const std::size_t translated_x = virtual_coord.x;
const std::size_t translated_y = virtual_coord.y;
CoordinateManager::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)] = CoreCoord(x, y, CoreType::TENSIX, CoordSystem::LOGICAL);
}
}
}

void BlackholeCoordinateManager::dram_harvesting(const std::size_t dram_harvesting_mask) {

std::size_t get_num_harvested_x = __builtin_popcount(dram_harvesting_mask);
CoordinateManager::dram_harvesting_mask = dram_harvesting_mask;
CoordinateManager::clear_dram_harvesting_structures();

std::size_t num_harvested_banks = __builtin_popcount(dram_harvesting_mask);

for (std::size_t x = 0; x < dram_grid_size.x - get_num_harvested_x; x++) {
for (std::size_t x = 0; x < dram_grid_size.x - num_harvested_banks; x++) {
for (std::size_t y = 0; y < dram_grid_size.y; y++) {
CoordinateManager::dram_logical_to_virtual[{x, y}] = CoordinateManager::dram_cores[x * dram_grid_size.y + y];
CoordinateManager::dram_virtual_to_logical[dram_cores[x * dram_grid_size.y + y]] = {x, 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);
}
}

std::size_t logical_x = 0;
for (std::size_t x = 0; x < dram_grid_size.x; x++) {
if (!(dram_harvesting_mask & (1 << x))) {
for (std::size_t y = 0; y < dram_grid_size.y; y++) {
CoordinateManager::dram_logical_to_physical[{logical_x , y}] = CoordinateManager::dram_cores[x * dram_grid_size.y + y];
CoordinateManager::dram_physical_to_logical[dram_cores[x * dram_grid_size.y + y]] = {logical_x, y};
const tt_xy_pair& dram_core = CoordinateManager::dram_cores[x * dram_grid_size.y + y];
CoordinateManager::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);
}
logical_x++;
}
}
}
}
7 changes: 3 additions & 4 deletions device/blackhole/blackhole_coordinate_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ class BlackholeCoordinateManager : public CoordinateManager {

void dram_harvesting(const std::size_t dram_harvesting_mask) override;

protected:
CoreCoord translated_to_logical_tensix(const CoreCoord core_coord) override;
CoreCoord logical_to_translated_tensix(const CoreCoord core_coord) override;
void tensix_harvesting(const std::size_t tensix_harvesting_mask) override;

std::set<std::size_t> get_x_coordinates_to_harvest(std::size_t harvesting_mask) override;
protected:
void fill_tensix_logical_to_translated() override;
};
Loading

0 comments on commit 5665a44

Please sign in to comment.