Skip to content

Commit

Permalink
Soc descriptor API for all coordinate systems (#442)
Browse files Browse the repository at this point in the history
  • Loading branch information
pjanevskiTT authored Jan 3, 2025
1 parent e13960a commit fff1d4c
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 17 deletions.
8 changes: 6 additions & 2 deletions device/api/umd/device/tt_soc_descriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,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 @@ -116,6 +118,8 @@ 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);
std::vector<tt::umd::CoreCoord> translate_coordinates(
const std::vector<tt::umd::CoreCoord> &physical_cores, 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
Expand Down
6 changes: 6 additions & 0 deletions device/coordinate_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,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 @@ -474,6 +477,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
43 changes: 28 additions & 15 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 @@ -315,6 +316,12 @@ void tt_SocDescriptor::get_cores_and_grid_size_from_coordinate_manager() {
harvested_cores_map.insert({CoreType::ETH, coordinate_manager->get_harvested_cores(CoreType::ETH)});
harvested_grid_size_map.insert({CoreType::ETH, coordinate_manager->get_harvested_grid_size(CoreType::ETH)});

harvested_cores_map.insert({CoreType::ARC, 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, 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);
const tt_xy_pair dram_grid_size = grid_size_map.at(CoreType::DRAM);

Expand All @@ -337,31 +344,37 @@ 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 {};
std::vector<CoreCoord> tt_SocDescriptor::translate_coordinates(
const std::vector<CoreCoord> &physical_cores, const CoordSystem coord_system) const {
std::vector<CoreCoord> translated_cores;
for (const auto &core : physical_cores) {
translated_cores.push_back(translate_coord_to(core, coord_system));
}
return cores_map.at(core_type);
return translated_cores;
}

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_cores(
const CoreType core_type, const CoordSystem coord_system) const {
auto cores_map_it = cores_map.find(core_type);
if (coord_system != CoordSystem::PHYSICAL) {
return translate_coordinates(cores_map_it->second, coord_system);
}
return harvested_cores_map.at(core_type);
return cores_map_it->second;
}

tt_xy_pair tt_SocDescriptor::get_grid_size(const CoreType core_type) const {
if (grid_size_map.find(core_type) == grid_size_map.end()) {
return {0, 0};
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");
auto harvested_cores_map_it = harvested_cores_map.find(core_type);
if (coord_system != CoordSystem::PHYSICAL) {
return translate_coordinates(harvested_cores_map_it->second, coord_system);
}
return grid_size_map.at(core_type);
return harvested_cores_map_it->second;
}

tt_xy_pair tt_SocDescriptor::get_grid_size(const CoreType core_type) const { return grid_size_map.at(core_type); }

tt_xy_pair tt_SocDescriptor::get_harvested_grid_size(const CoreType core_type) const {
if (harvested_grid_size_map.find(core_type) == harvested_grid_size_map.end()) {
return {0, 0};
}
return harvested_grid_size_map.at(core_type);
}

Expand Down
105 changes: 105 additions & 0 deletions tests/api/test_soc_descriptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,3 +342,108 @@ TEST(SocDescriptor, CustomSocDescriptor) {

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

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

const std::vector<tt_xy_pair> cores_physical = tt::umd::grayskull::TENSIX_CORES;

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

for (const tt_xy_pair& physical_core : cores_physical) {
const CoreCoord core(physical_core.x, physical_core.y, CoreType::TENSIX, CoordSystem::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(virtual_from_physical == cores_virtual);
EXPECT_TRUE(logical_from_physical == cores_logical);
EXPECT_TRUE(translated_from_physical == cores_translated);
}

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

const std::vector<tt_xy_pair> cores_physical = tt::umd::wormhole::TENSIX_CORES;

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

for (const tt_xy_pair& physical_core : cores_physical) {
const CoreCoord core(physical_core.x, physical_core.y, CoreType::TENSIX, CoordSystem::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(virtual_from_physical == cores_virtual);
EXPECT_TRUE(logical_from_physical == cores_logical);
EXPECT_TRUE(translated_from_physical == cores_translated);
}

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

const std::vector<tt_xy_pair> cores_physical = tt::umd::blackhole::TENSIX_CORES;

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

for (const tt_xy_pair& physical_core : cores_physical) {
const CoreCoord core(physical_core.x, physical_core.y, CoreType::TENSIX, CoordSystem::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(virtual_from_physical == cores_virtual);
EXPECT_TRUE(logical_from_physical == cores_logical);
EXPECT_TRUE(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 fff1d4c

Please sign in to comment.