Skip to content

Commit

Permalink
Soc descriptor API for all coordinate systems
Browse files Browse the repository at this point in the history
  • Loading branch information
pjanevskiTT committed Dec 26, 2024
1 parent 087bbe2 commit fbcdf73
Show file tree
Hide file tree
Showing 4 changed files with 176 additions and 22 deletions.
14 changes: 10 additions & 4 deletions device/api/umd/device/tt_soc_descriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,10 @@ class tt_SocDescriptor {

static std::string get_soc_descriptor_path(tt::ARCH arch);

std::vector<tt::umd::CoreCoord> get_cores(const CoreType core_type) const;
std::vector<tt::umd::CoreCoord> get_harvested_cores(const CoreType core_type) const;
std::vector<tt::umd::CoreCoord> get_cores(
const CoreType core_type, const CoordSystem coord_system = CoordSystem::PHYSICAL) const;
std::vector<tt::umd::CoreCoord> get_harvested_cores(
const CoreType core_type, const CoordSystem coord_system = CoordSystem::PHYSICAL) const;
tt_xy_pair get_grid_size(const CoreType core_type) const;
tt_xy_pair get_harvested_grid_size(const CoreType core_type) const;

Expand Down Expand Up @@ -149,14 +151,18 @@ class tt_SocDescriptor {
void get_cores_and_grid_size_from_coordinate_manager();

static tt_xy_pair calculate_grid_size(const std::vector<tt_xy_pair> &cores);
void translate_coordinates(
std::map<std::pair<CoreType, CoordSystem>, std::vector<tt::umd::CoreCoord>> &core_coord_map,
const CoreType core_type,
const CoordSystem coord_system) const;

// 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;
mutable std::map<std::pair<CoreType, CoordSystem>, 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;
mutable std::map<std::pair<CoreType, CoordSystem>, std::vector<tt::umd::CoreCoord>> harvested_cores_map;
std::map<CoreType, tt_xy_pair> harvested_grid_size_map;

// DRAM cores are kept in additional vector struct since one DRAM bank
Expand Down
6 changes: 6 additions & 0 deletions device/coordinate_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,9 @@ std::vector<tt::umd::CoreCoord> CoordinateManager::get_harvested_cores(const Cor
return get_harvested_dram_cores();
case CoreType::ETH:
return get_harvested_eth_cores();
case CoreType::ARC:
case CoreType::PCIE:
return {};
default:
throw std::runtime_error("Core type is not supported for getting harvested cores");
}
Expand All @@ -452,6 +455,9 @@ tt_xy_pair CoordinateManager::get_harvested_grid_size(const CoreType core_type)
return get_harvested_dram_grid_size();
case CoreType::ETH:
return get_harvested_eth_grid_size();
case CoreType::ARC:
case CoreType::PCIE:
return {0, 0};
default:
throw std::runtime_error("Core type is not supported for getting harvested grid size");
}
Expand Down
63 changes: 45 additions & 18 deletions device/tt_soc_descriptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include "api/umd/device/tt_soc_descriptor.h"
#include "fmt/core.h"
#include "logger.hpp"
#include "utils.hpp"
#include "yaml-cpp/yaml.h"

Expand Down Expand Up @@ -290,31 +291,42 @@ std::string tt_SocDescriptor::get_soc_descriptor_path(tt::ARCH arch) {
}

void tt_SocDescriptor::get_cores_and_grid_size_from_coordinate_manager() {
cores_map.insert({CoreType::TENSIX, coordinate_manager->get_cores(CoreType::TENSIX)});
cores_map.insert({{CoreType::TENSIX, CoordSystem::PHYSICAL}, coordinate_manager->get_cores(CoreType::TENSIX)});
grid_size_map.insert({CoreType::TENSIX, coordinate_manager->get_grid_size(CoreType::TENSIX)});

cores_map.insert({CoreType::DRAM, coordinate_manager->get_cores(CoreType::DRAM)});
cores_map.insert({{CoreType::DRAM, CoordSystem::PHYSICAL}, coordinate_manager->get_cores(CoreType::DRAM)});
grid_size_map.insert({CoreType::DRAM, coordinate_manager->get_grid_size(CoreType::DRAM)});

cores_map.insert({CoreType::ETH, coordinate_manager->get_cores(CoreType::ETH)});
cores_map.insert({{CoreType::ETH, CoordSystem::PHYSICAL}, coordinate_manager->get_cores(CoreType::ETH)});
grid_size_map.insert({CoreType::ETH, coordinate_manager->get_grid_size(CoreType::ETH)});

cores_map.insert({CoreType::ARC, coordinate_manager->get_cores(CoreType::ARC)});
cores_map.insert({{CoreType::ARC, CoordSystem::PHYSICAL}, coordinate_manager->get_cores(CoreType::ARC)});
grid_size_map.insert({CoreType::ARC, coordinate_manager->get_grid_size(CoreType::ARC)});

cores_map.insert({CoreType::PCIE, coordinate_manager->get_cores(CoreType::PCIE)});
cores_map.insert({{CoreType::PCIE, CoordSystem::PHYSICAL}, coordinate_manager->get_cores(CoreType::PCIE)});
grid_size_map.insert({CoreType::PCIE, coordinate_manager->get_grid_size(CoreType::PCIE)});

harvested_cores_map.insert({CoreType::TENSIX, coordinate_manager->get_harvested_cores(CoreType::TENSIX)});
harvested_cores_map.insert(
{{CoreType::TENSIX, CoordSystem::PHYSICAL}, coordinate_manager->get_harvested_cores(CoreType::TENSIX)});
harvested_grid_size_map.insert({CoreType::TENSIX, coordinate_manager->get_harvested_grid_size(CoreType::TENSIX)});

harvested_cores_map.insert({CoreType::DRAM, coordinate_manager->get_harvested_cores(CoreType::DRAM)});
harvested_cores_map.insert(
{{CoreType::DRAM, CoordSystem::PHYSICAL}, coordinate_manager->get_harvested_cores(CoreType::DRAM)});
harvested_grid_size_map.insert({CoreType::DRAM, coordinate_manager->get_harvested_grid_size(CoreType::DRAM)});

harvested_cores_map.insert({CoreType::ETH, coordinate_manager->get_harvested_cores(CoreType::ETH)});
harvested_cores_map.insert(
{{CoreType::ETH, CoordSystem::PHYSICAL}, coordinate_manager->get_harvested_cores(CoreType::ETH)});
harvested_grid_size_map.insert({CoreType::ETH, coordinate_manager->get_harvested_grid_size(CoreType::ETH)});

const std::vector<CoreCoord> dram_cores = cores_map.at(CoreType::DRAM);
harvested_cores_map.insert(
{{CoreType::ARC, CoordSystem::PHYSICAL}, coordinate_manager->get_harvested_cores(CoreType::ARC)});
harvested_grid_size_map.insert({CoreType::ARC, coordinate_manager->get_harvested_grid_size(CoreType::ARC)});

harvested_cores_map.insert(
{{CoreType::PCIE, CoordSystem::PHYSICAL}, coordinate_manager->get_harvested_cores(CoreType::PCIE)});
harvested_grid_size_map.insert({CoreType::PCIE, coordinate_manager->get_harvested_grid_size(CoreType::PCIE)});

const std::vector<CoreCoord> dram_cores = cores_map.at({CoreType::DRAM, CoordSystem::PHYSICAL});
const tt_xy_pair dram_grid_size = grid_size_map.at(CoreType::DRAM);

dram_cores_core_coord.resize(dram_grid_size.x);
Expand All @@ -324,7 +336,7 @@ void tt_SocDescriptor::get_cores_and_grid_size_from_coordinate_manager() {
}
}

const std::vector<CoreCoord> harvested_dram_cores = harvested_cores_map.at(CoreType::DRAM);
const std::vector<CoreCoord> harvested_dram_cores = harvested_cores_map.at({CoreType::DRAM, CoordSystem::PHYSICAL});
const tt_xy_pair harvested_dram_grid_size = harvested_grid_size_map.at(CoreType::DRAM);

harvested_dram_cores_core_coord.resize(harvested_dram_grid_size.x);
Expand All @@ -336,18 +348,33 @@ void tt_SocDescriptor::get_cores_and_grid_size_from_coordinate_manager() {
}
}

std::vector<tt::umd::CoreCoord> tt_SocDescriptor::get_cores(const CoreType core_type) const {
if (cores_map.find(core_type) == cores_map.end()) {
return {};
void tt_SocDescriptor::translate_coordinates(
std::map<std::pair<CoreType, CoordSystem>, std::vector<CoreCoord>> &core_coord_map,
const CoreType core_type,
const CoordSystem coord_system) const {
std::vector<CoreCoord> cores = core_coord_map.at({core_type, CoordSystem::PHYSICAL});
std::vector<CoreCoord> translated_cores;
for (const auto &core : cores) {
translated_cores.push_back(translate_coord_to(core, coord_system));
}
core_coord_map.insert({{core_type, coord_system}, translated_cores});
}

std::vector<tt::umd::CoreCoord> tt_SocDescriptor::get_cores(
const CoreType core_type, const CoordSystem coord_system) const {
if (cores_map.find({core_type, coord_system}) == cores_map.end()) {
translate_coordinates(cores_map, core_type, coord_system);
}
return cores_map.at(core_type);
return cores_map.at({core_type, coord_system});
}

std::vector<tt::umd::CoreCoord> tt_SocDescriptor::get_harvested_cores(const CoreType core_type) const {
if (harvested_cores_map.find(core_type) == harvested_cores_map.end()) {
return {};
std::vector<tt::umd::CoreCoord> tt_SocDescriptor::get_harvested_cores(
const CoreType core_type, const CoordSystem coord_system) const {
log_assert(coord_system != CoordSystem::LOGICAL, "Harvested cores are not supported for logical coordinates");
if (harvested_cores_map.find({core_type, coord_system}) == harvested_cores_map.end()) {
translate_coordinates(harvested_cores_map, core_type, coord_system);
}
return harvested_cores_map.at(core_type);
return harvested_cores_map.at({core_type, coord_system});
}

tt_xy_pair tt_SocDescriptor::get_grid_size(const CoreType core_type) const {
Expand Down
115 changes: 115 additions & 0 deletions tests/api/test_soc_descriptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,3 +342,118 @@ TEST(SocDescriptor, CustomSocDescriptor) {

EXPECT_EQ(soc_desc.get_num_dram_channels(), 1);
}

bool core_coord_vectors_equal(const std::vector<CoreCoord>& vec1, const std::vector<CoreCoord>& vec2) {
if (vec1.size() != vec2.size()) {
return false;
}

for (size_t i = 0; i < vec1.size(); i++) {
if (vec1[i] != vec2[i]) {
return false;
}
}
return true;
}

TEST(SocDescriptor, SocDescriptorGrayskullMultipleCoordinateSystems) {
tt_SocDescriptor soc_desc(test_utils::GetAbsPath("tests/soc_descs/grayskull_10x12.yaml"));

std::vector<CoreCoord> cores_physical = soc_desc.get_cores(CoreType::TENSIX, CoordSystem::PHYSICAL);

std::vector<CoreCoord> virtual_from_physical;
std::vector<CoreCoord> logical_from_physical;
std::vector<CoreCoord> translated_from_physical;

for (const CoreCoord& core : cores_physical) {
virtual_from_physical.push_back(soc_desc.translate_coord_to(core, CoordSystem::VIRTUAL));
logical_from_physical.push_back(soc_desc.translate_coord_to(core, CoordSystem::LOGICAL));
translated_from_physical.push_back(soc_desc.translate_coord_to(core, CoordSystem::TRANSLATED));
}

std::vector<CoreCoord> cores_virtual = soc_desc.get_cores(CoreType::TENSIX, CoordSystem::VIRTUAL);
std::vector<CoreCoord> cores_logical = soc_desc.get_cores(CoreType::TENSIX, CoordSystem::LOGICAL);
std::vector<CoreCoord> cores_translated = soc_desc.get_cores(CoreType::TENSIX, CoordSystem::TRANSLATED);

EXPECT_TRUE(core_coord_vectors_equal(virtual_from_physical, cores_virtual));
EXPECT_TRUE(core_coord_vectors_equal(logical_from_physical, cores_logical));
EXPECT_TRUE(core_coord_vectors_equal(translated_from_physical, cores_translated));
}

TEST(SocDescriptor, SocDescriptorWormholeMultipleCoordinateSystems) {
tt_SocDescriptor soc_desc(test_utils::GetAbsPath("tests/soc_descs/wormhole_b0_8x10.yaml"));

std::vector<CoreCoord> cores_physical = soc_desc.get_cores(CoreType::TENSIX, CoordSystem::PHYSICAL);

std::vector<CoreCoord> virtual_from_physical;
std::vector<CoreCoord> logical_from_physical;
std::vector<CoreCoord> translated_from_physical;

for (const CoreCoord& core : cores_physical) {
virtual_from_physical.push_back(soc_desc.translate_coord_to(core, CoordSystem::VIRTUAL));
logical_from_physical.push_back(soc_desc.translate_coord_to(core, CoordSystem::LOGICAL));
translated_from_physical.push_back(soc_desc.translate_coord_to(core, CoordSystem::TRANSLATED));
}

std::vector<CoreCoord> cores_virtual = soc_desc.get_cores(CoreType::TENSIX, CoordSystem::VIRTUAL);
std::vector<CoreCoord> cores_logical = soc_desc.get_cores(CoreType::TENSIX, CoordSystem::LOGICAL);
std::vector<CoreCoord> cores_translated = soc_desc.get_cores(CoreType::TENSIX, CoordSystem::TRANSLATED);

EXPECT_TRUE(core_coord_vectors_equal(virtual_from_physical, cores_virtual));
EXPECT_TRUE(core_coord_vectors_equal(logical_from_physical, cores_logical));
EXPECT_TRUE(core_coord_vectors_equal(translated_from_physical, cores_translated));
}

TEST(SocDescriptor, SocDescriptorBlackholeMultipleCoordinateSystems) {
tt_SocDescriptor soc_desc(test_utils::GetAbsPath("tests/soc_descs/blackhole_140_arch_no_eth.yaml"));

std::vector<CoreCoord> cores_physical = soc_desc.get_cores(CoreType::TENSIX, CoordSystem::PHYSICAL);

std::vector<CoreCoord> virtual_from_physical;
std::vector<CoreCoord> logical_from_physical;
std::vector<CoreCoord> translated_from_physical;

for (const CoreCoord& core : cores_physical) {
virtual_from_physical.push_back(soc_desc.translate_coord_to(core, CoordSystem::VIRTUAL));
logical_from_physical.push_back(soc_desc.translate_coord_to(core, CoordSystem::LOGICAL));
translated_from_physical.push_back(soc_desc.translate_coord_to(core, CoordSystem::TRANSLATED));
}

std::vector<CoreCoord> cores_virtual = soc_desc.get_cores(CoreType::TENSIX, CoordSystem::VIRTUAL);
std::vector<CoreCoord> cores_logical = soc_desc.get_cores(CoreType::TENSIX, CoordSystem::LOGICAL);
std::vector<CoreCoord> cores_translated = soc_desc.get_cores(CoreType::TENSIX, CoordSystem::TRANSLATED);

EXPECT_TRUE(core_coord_vectors_equal(virtual_from_physical, cores_virtual));
EXPECT_TRUE(core_coord_vectors_equal(logical_from_physical, cores_logical));
EXPECT_TRUE(core_coord_vectors_equal(translated_from_physical, cores_translated));
}

TEST(SocDescriptor, SocDescriptorGrayskullNoLogicalForHarvestedCores) {
tt_SocDescriptor soc_desc(test_utils::GetAbsPath("tests/soc_descs/grayskull_10x12.yaml"), 1);

EXPECT_THROW(soc_desc.get_harvested_cores(CoreType::TENSIX, CoordSystem::LOGICAL), std::runtime_error);

EXPECT_THROW(soc_desc.get_harvested_cores(CoreType::DRAM, CoordSystem::LOGICAL), std::runtime_error);

EXPECT_THROW(soc_desc.get_harvested_cores(CoreType::ETH, CoordSystem::LOGICAL), std::runtime_error);
}

TEST(SocDescriptor, SocDescriptorWormholeNoLogicalForHarvestedCores) {
tt_SocDescriptor soc_desc(test_utils::GetAbsPath("tests/soc_descs/wormhole_b0_8x10.yaml"), 1);

EXPECT_THROW(soc_desc.get_harvested_cores(CoreType::TENSIX, CoordSystem::LOGICAL), std::runtime_error);

EXPECT_THROW(soc_desc.get_harvested_cores(CoreType::DRAM, CoordSystem::LOGICAL), std::runtime_error);

EXPECT_THROW(soc_desc.get_harvested_cores(CoreType::ETH, CoordSystem::LOGICAL), std::runtime_error);
}

TEST(SocDescriptor, SocDescriptorBlackholeNoLogicalForHarvestedCores) {
tt_SocDescriptor soc_desc(test_utils::GetAbsPath("tests/soc_descs/blackhole_140_arch.yaml"), 1);

EXPECT_THROW(soc_desc.get_harvested_cores(CoreType::TENSIX, CoordSystem::LOGICAL), std::runtime_error);

EXPECT_THROW(soc_desc.get_harvested_cores(CoreType::DRAM, CoordSystem::LOGICAL), std::runtime_error);

EXPECT_THROW(soc_desc.get_harvested_cores(CoreType::ETH, CoordSystem::LOGICAL), std::runtime_error);
}

0 comments on commit fbcdf73

Please sign in to comment.