Skip to content

Commit

Permalink
ETH harvesting (#406)
Browse files Browse the repository at this point in the history
  • Loading branch information
pjanevskiTT authored Dec 23, 2024
1 parent 28a483b commit eab293e
Show file tree
Hide file tree
Showing 14 changed files with 280 additions and 30 deletions.
8 changes: 8 additions & 0 deletions device/api/umd/device/blackhole_coordinate_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,18 @@ class BlackholeCoordinateManager : public CoordinateManager {
const size_t dram_harvesting_mask,
const tt_xy_pair& eth_grid_size,
const std::vector<tt_xy_pair>& eth_cores,
const size_t eth_harvesting_mask,
const tt_xy_pair& arc_grid_size,
const std::vector<tt_xy_pair>& arc_cores,
const tt_xy_pair& pcie_grid_size,
const std::vector<tt_xy_pair>& pcie_cores);

protected:
void assert_coordinate_manager_constructor() override;

void translate_dram_coords() override;
void translate_tensix_coords() override;
void translate_eth_coords() override;

void fill_tensix_physical_translated_mapping() override;
void fill_eth_physical_translated_mapping() override;
Expand All @@ -38,10 +42,14 @@ class BlackholeCoordinateManager : public CoordinateManager {
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;
std::vector<tt::umd::CoreCoord> get_eth_cores() const override;
std::vector<tt::umd::CoreCoord> get_harvested_eth_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_eth_grid_size() const override;
tt_xy_pair get_harvested_tensix_grid_size() const override;
tt_xy_pair get_harvested_dram_grid_size() const override;
tt_xy_pair get_harvested_eth_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
19 changes: 15 additions & 4 deletions device/api/umd/device/coordinate_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,17 @@ class CoordinateManager {
const size_t dram_harvesting_mask,
const tt_xy_pair& eth_grid_size,
const std::vector<tt_xy_pair>& eth_cores,
const size_t eth_harvesting_mask,
const tt_xy_pair& arc_grid_size,
const std::vector<tt_xy_pair>& arc_cores,
const tt_xy_pair& pcie_grid_size,
const std::vector<tt_xy_pair>& pcie_cores);

static std::shared_ptr<CoordinateManager> create_coordinate_manager(
tt::ARCH arch, const size_t tensix_harvesting_mask = 0, const size_t dram_harvesting_mask = 0);
tt::ARCH arch,
const size_t tensix_harvesting_mask = 0,
const size_t dram_harvesting_mask = 0,
const size_t eth_harvesting_mask = 0);

static size_t get_num_harvested(const size_t harvesting_mask);

Expand All @@ -54,10 +58,9 @@ class CoordinateManager {

size_t get_dram_harvesting_mask() const;

private:
static void assert_create_coordinate_manager(
const tt::ARCH arch, const size_t tensix_harvesting_mask, const size_t dram_harvesting_mask);
size_t get_eth_harvesting_mask() const;

private:
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;

Expand All @@ -78,13 +81,16 @@ class CoordinateManager {
const size_t dram_harvesting_mask,
const tt_xy_pair& eth_grid_size,
const std::vector<tt_xy_pair>& eth_cores,
const size_t eth_harvesting_mask,
const tt_xy_pair& arc_grid_size,
const std::vector<tt_xy_pair>& arc_cores,
const tt_xy_pair& pcie_grid_size,
const std::vector<tt_xy_pair>& pcie_cores);

void initialize();

virtual void assert_coordinate_manager_constructor();

virtual void shuffle_tensix_harvesting_mask(const std::vector<uint32_t>& harvesting_locations);

virtual void translate_tensix_coords();
Expand All @@ -100,10 +106,14 @@ class CoordinateManager {
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 std::vector<tt::umd::CoreCoord> get_eth_cores() const;
virtual std::vector<tt::umd::CoreCoord> get_harvested_eth_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_eth_grid_size() const;
virtual tt_xy_pair get_harvested_tensix_grid_size() const;
virtual tt_xy_pair get_harvested_dram_grid_size() const;
virtual tt_xy_pair get_harvested_eth_grid_size() const;

/*
* Fills the logical to translated mapping for the tensix cores.
Expand Down Expand Up @@ -163,6 +173,7 @@ class CoordinateManager {

tt_xy_pair eth_grid_size;
const std::vector<tt_xy_pair> eth_cores;
const size_t eth_harvesting_mask;

tt_xy_pair arc_grid_size;
const std::vector<tt_xy_pair> arc_cores;
Expand Down
1 change: 1 addition & 0 deletions device/api/umd/device/grayskull_coordinate_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class GrayskullCoordinateManager : public CoordinateManager {
const size_t dram_harvesting_mask,
const tt_xy_pair& eth_grid_size,
const std::vector<tt_xy_pair>& eth_cores,
const size_t eth_harvesting_mask,
const tt_xy_pair& arc_grid_size,
const std::vector<tt_xy_pair>& arc_cores,
const tt_xy_pair& pcie_grid_size,
Expand Down
8 changes: 5 additions & 3 deletions device/api/umd/device/tt_soc_descriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ class tt_SocDescriptor {
// Constructor used to build object from device descriptor file.
tt_SocDescriptor(
std::string device_descriptor_path,
const std::size_t tensix_harvesting_mask = 0,
const std::size_t dram_harvesting_mask = 0);
const size_t tensix_harvesting_mask = 0,
const size_t dram_harvesting_mask = 0,
const size_t eth_harvesting_mask = 0);

// Copy constructor
tt_SocDescriptor(const tt_SocDescriptor &other) :
Expand Down Expand Up @@ -143,7 +144,8 @@ class tt_SocDescriptor {
uint64_t dram_bank_size;

private:
void create_coordinate_manager(const std::size_t tensix_harvesting_mask, const std::size_t dram_harvesting_mask);
void create_coordinate_manager(
const size_t tensix_harvesting_mask, const size_t dram_harvesting_mask, const size_t eth_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();
Expand Down
1 change: 1 addition & 0 deletions device/api/umd/device/wormhole_coordinate_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class WormholeCoordinateManager : public CoordinateManager {
const size_t dram_harvesting_mask,
const tt_xy_pair& eth_grid_size,
const std::vector<tt_xy_pair>& eth_cores,
const size_t eth_harvesting_mask,
const tt_xy_pair& arc_grid_size,
const std::vector<tt_xy_pair>& arc_cores,
const tt_xy_pair& pcie_grid_size,
Expand Down
107 changes: 106 additions & 1 deletion device/blackhole/blackhole_coordinate_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
*/
#include "umd/device/blackhole_coordinate_manager.h"

#include "logger.hpp"

using namespace tt::umd;

BlackholeCoordinateManager::BlackholeCoordinateManager(
Expand All @@ -16,6 +18,7 @@ BlackholeCoordinateManager::BlackholeCoordinateManager(
const size_t dram_harvesting_mask,
const tt_xy_pair& eth_grid_size,
const std::vector<tt_xy_pair>& eth_cores,
const size_t eth_harvesting_mask,
const tt_xy_pair& arc_grid_size,
const std::vector<tt_xy_pair>& arc_cores,
const tt_xy_pair& pcie_grid_size,
Expand All @@ -29,6 +32,7 @@ BlackholeCoordinateManager::BlackholeCoordinateManager(
dram_harvesting_mask,
eth_grid_size,
eth_cores,
eth_harvesting_mask,
arc_grid_size,
arc_cores,
pcie_grid_size,
Expand All @@ -37,6 +41,17 @@ BlackholeCoordinateManager::BlackholeCoordinateManager(
initialize();
}

void BlackholeCoordinateManager::assert_coordinate_manager_constructor() {
log_assert(get_num_harvested(dram_harvesting_mask) <= 1, "Only one DRAM bank can be harvested on Blackhole");

// TODO: assert that exactly 2 or all 14 (P100) ETH cores are harvested for Blackhole. This is
// going to be true both for all Blackhole products.
// const size_t num_harvested_eth_cores = get_num_harvested(eth_harvesting_mask);
// log_assert(
// num_harvested_eth_cores == 2 || num_harvested_eth_cores == blackhole::ETH_GRID_SIZE.x, "Exactly 2 or 14 ETH
// cores should be harvested on Blackhole");
}

void BlackholeCoordinateManager::translate_tensix_coords() {
if (CoordinateManager::get_num_harvested(tensix_harvesting_mask) > tensix_grid_size.x) {
tensix_harvesting_mask = 0;
Expand Down Expand Up @@ -135,8 +150,47 @@ void BlackholeCoordinateManager::translate_dram_coords() {
fill_dram_physical_translated_mapping();
}

void BlackholeCoordinateManager::translate_eth_coords() {
size_t num_harvested_x = CoordinateManager::get_num_harvested(eth_harvesting_mask);
size_t grid_size_x = eth_grid_size.x;
size_t grid_size_y = eth_grid_size.y;

size_t logical_x = 0;
size_t x_index = grid_size_x - num_harvested_x;
for (size_t x = 0; x < grid_size_x; x++) {
if (eth_harvesting_mask & (1 << x)) {
for (size_t y = 0; y < grid_size_y; y++) {
const tt_xy_pair& physical_core = eth_cores[x + y * grid_size_x];
const tt_xy_pair& virtual_core = eth_cores[x_index + y * grid_size_x];

CoreCoord virtual_coord =
CoreCoord(virtual_core.x, virtual_core.y, CoreType::ETH, CoordSystem::VIRTUAL);

add_core_translation(virtual_coord, physical_core);
}
x_index++;
} else {
for (size_t y = 0; y < grid_size_y; y++) {
const tt_xy_pair& tensix_core = eth_cores[x + y * grid_size_x];
const tt_xy_pair& virtual_core = eth_cores[logical_x + y * grid_size_x];

CoreCoord logical_coord = CoreCoord(logical_x, y, CoreType::ETH, CoordSystem::LOGICAL);
add_core_translation(logical_coord, tensix_core);

CoreCoord virtual_coord =
CoreCoord(virtual_core.x, virtual_core.y, CoreType::ETH, CoordSystem::VIRTUAL);
add_core_translation(virtual_coord, tensix_core);
}
logical_x++;
}
}

fill_eth_physical_translated_mapping();
}

void BlackholeCoordinateManager::fill_eth_physical_translated_mapping() {
for (size_t x = 0; x < eth_grid_size.x; x++) {
const size_t num_harvested_x = CoordinateManager::get_num_harvested(eth_harvesting_mask);
for (size_t x = 0; x < eth_grid_size.x - num_harvested_x; x++) {
for (size_t y = 0; y < eth_grid_size.y; y++) {
const size_t translated_x = x + blackhole::eth_translated_coordinate_start_x;
const size_t translated_y = y + blackhole::eth_translated_coordinate_start_y;
Expand All @@ -149,6 +203,19 @@ void BlackholeCoordinateManager::fill_eth_physical_translated_mapping() {
add_core_translation(translated_coord, physical_pair);
}
}

// Harvested ETH cores should be mapped to the same physical coordinates.
for (size_t y = 0; y < eth_grid_size.y; y++) {
for (size_t x = 0; x < eth_grid_size.x; x++) {
if (eth_harvesting_mask & (1 << x)) {
const tt_xy_pair& physical_pair = eth_cores[x + y * eth_grid_size.x];
const CoreCoord translated_coord =
CoreCoord(physical_pair.x, physical_pair.y, CoreType::ETH, CoordSystem::TRANSLATED);

add_core_translation(translated_coord, physical_pair);
}
}
}
}

void BlackholeCoordinateManager::fill_pcie_physical_translated_mapping() {
Expand Down Expand Up @@ -317,6 +384,36 @@ std::vector<CoreCoord> BlackholeCoordinateManager::get_harvested_dram_cores() co
return harvested_dram_cores;
}

std::vector<CoreCoord> BlackholeCoordinateManager::get_eth_cores() const {
std::vector<size_t> harvested_x_coords = get_harvested_indices(eth_harvesting_mask);
std::vector<CoreCoord> unharvested_eth_cores;
for (size_t y = 0; y < eth_grid_size.y; y++) {
for (size_t x = 0; x < eth_grid_size.x; x++) {
const tt_xy_pair core = eth_cores[y * eth_grid_size.x + x];
CoreCoord core_coord(core.x, core.y, CoreType::ETH, CoordSystem::PHYSICAL);
if (std::find(harvested_x_coords.begin(), harvested_x_coords.end(), x) == harvested_x_coords.end()) {
unharvested_eth_cores.push_back(core_coord);
}
}
}
return unharvested_eth_cores;
}

std::vector<CoreCoord> BlackholeCoordinateManager::get_harvested_eth_cores() const {
std::vector<size_t> harvested_x_coords = get_harvested_indices(eth_harvesting_mask);
std::vector<CoreCoord> harvested_eth_cores;
for (size_t y = 0; y < eth_grid_size.y; y++) {
for (size_t x = 0; x < eth_grid_size.x; x++) {
const tt_xy_pair core = eth_cores[y * eth_grid_size.x + x];
CoreCoord core_coord(core.x, core.y, CoreType::ETH, CoordSystem::PHYSICAL);
if (std::find(harvested_x_coords.begin(), harvested_x_coords.end(), x) != harvested_x_coords.end()) {
harvested_eth_cores.push_back(core_coord);
}
}
}
return harvested_eth_cores;
}

tt_xy_pair BlackholeCoordinateManager::get_harvested_tensix_grid_size() const {
return {CoordinateManager::get_num_harvested(tensix_harvesting_mask), tensix_grid_size.y};
}
Expand All @@ -325,10 +422,18 @@ 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_harvested_eth_grid_size() const {
return {CoordinateManager::get_num_harvested(eth_harvesting_mask), eth_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};
}

tt_xy_pair BlackholeCoordinateManager::get_eth_grid_size() const {
return {eth_grid_size.x - CoordinateManager::get_num_harvested(eth_harvesting_mask), eth_grid_size.y};
}
Loading

0 comments on commit eab293e

Please sign in to comment.