Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
broskoTT committed Jan 3, 2025
1 parent 8c5aa30 commit d5bba47
Show file tree
Hide file tree
Showing 11 changed files with 135 additions and 152 deletions.
59 changes: 15 additions & 44 deletions device/api/umd/device/tt_soc_descriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,40 +55,6 @@ class tt_SocDescriptor {
const size_t dram_harvesting_mask = 0,
const size_t eth_harvesting_mask = 0);

// Copy constructor
tt_SocDescriptor(const tt_SocDescriptor &other) :
arch(other.arch),
grid_size(other.grid_size),
worker_grid_size(other.worker_grid_size),
cores(other.cores),
arc_cores(other.arc_cores),
workers(other.workers),
harvested_workers(other.harvested_workers),
pcie_cores(other.pcie_cores),
worker_log_to_routing_x(other.worker_log_to_routing_x),
worker_log_to_routing_y(other.worker_log_to_routing_y),
routing_x_to_worker_x(other.routing_x_to_worker_x),
routing_y_to_worker_y(other.routing_y_to_worker_y),
dram_cores(other.dram_cores),
dram_core_channel_map(other.dram_core_channel_map),
ethernet_cores(other.ethernet_cores),
ethernet_core_channel_map(other.ethernet_core_channel_map),
trisc_sizes(other.trisc_sizes),
device_descriptor_file_path(other.device_descriptor_file_path),
overlay_version(other.overlay_version),
unpacker_version(other.unpacker_version),
dst_size_alignment(other.dst_size_alignment),
packer_version(other.packer_version),
worker_l1_size(other.worker_l1_size),
eth_l1_size(other.eth_l1_size),
noc_translation_id_enabled(other.noc_translation_id_enabled),
dram_bank_size(other.dram_bank_size),
coordinate_manager(other.coordinate_manager),
cores_map(other.cores_map),
grid_size_map(other.grid_size_map),
harvested_cores_map(other.harvested_cores_map),
harvested_grid_size_map(other.harvested_grid_size_map) {}

// CoreCoord conversions.
tt::umd::CoreCoord translate_coord_to(const tt::umd::CoreCoord core_coord, const CoordSystem coord_system) const;

Expand All @@ -114,21 +80,11 @@ class tt_SocDescriptor {
bool is_ethernet_core(const tt_xy_pair &core) const;

tt::ARCH arch;
tt_xy_pair grid_size;
tt_xy_pair worker_grid_size;
std::unordered_map<tt_xy_pair, CoreDescriptor> cores;
std::vector<tt_xy_pair> arc_cores;
std::vector<tt_xy_pair> workers;
std::vector<tt_xy_pair> harvested_workers;
std::vector<tt_xy_pair> pcie_cores;
std::unordered_map<int, int> worker_log_to_routing_x;
std::unordered_map<int, int> worker_log_to_routing_y;
std::unordered_map<int, int> routing_x_to_worker_x;
std::unordered_map<int, int> routing_y_to_worker_y;
std::vector<std::vector<tt_xy_pair>> dram_cores; // per channel list of dram cores
std::unordered_map<tt_xy_pair, std::tuple<int, int>> dram_core_channel_map; // map dram core to chan/subchan
std::vector<tt_xy_pair> ethernet_cores; // ethernet cores (index == channel id)
std::unordered_map<tt_xy_pair, int> ethernet_core_channel_map;
std::vector<std::size_t> trisc_sizes; // Most of software stack assumes same trisc size for whole chip..
std::string device_descriptor_file_path = std::string("");

Expand All @@ -141,6 +97,11 @@ class tt_SocDescriptor {
bool noc_translation_id_enabled;
uint64_t dram_bank_size;

// TODO: Move to private when remove_worker_row_from_descriptor is removed.
tt_xy_pair worker_grid_size;
std::vector<tt_xy_pair> workers;
std::vector<tt_xy_pair> harvested_workers;

private:
void create_coordinate_manager(
const size_t tensix_harvesting_mask, const size_t dram_harvesting_mask, const size_t eth_harvesting_mask);
Expand All @@ -163,6 +124,16 @@ class tt_SocDescriptor {
// has multiple NOC endpoints, so some UMD clients prefer vector of vectors returned.
std::vector<std::vector<tt::umd::CoreCoord>> dram_cores_core_coord;
std::vector<std::vector<tt::umd::CoreCoord>> harvested_dram_cores_core_coord;

// Internal structures filled from soc descriptor yaml
tt_xy_pair grid_size;
std::vector<tt_xy_pair> arc_cores;
std::vector<tt_xy_pair> pcie_cores;
std::vector<std::vector<tt_xy_pair>> dram_cores; // per channel list of dram cores
std::unordered_map<tt_xy_pair, std::tuple<int, int>> dram_core_channel_map; // map dram core to chan/subchan
std::vector<tt_xy_pair> ethernet_cores; // ethernet cores (index == channel id)
std::unordered_map<tt_xy_pair, int> ethernet_core_channel_map;
std::vector<tt_xy_pair> router_cores;
};

// Allocates a new soc descriptor on the heap. Returns an owning pointer.
Expand Down
53 changes: 31 additions & 22 deletions device/cluster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,9 @@ void Cluster::construct_cluster(
}
remote_transfer_ethernet_cores.at(logical_mmio_chip_id)
.push_back(tt_cxy_pair(
logical_mmio_chip_id, soc_desc.ethernet_cores.at(i).x, soc_desc.ethernet_cores.at(i).y));
logical_mmio_chip_id,
soc_desc.get_cores(CoreType::ETH).at(i).x,
soc_desc.get_cores(CoreType::ETH).at(i).y));
}
}
}
Expand Down Expand Up @@ -618,7 +620,7 @@ void Cluster::configure_active_ethernet_cores_for_mmio_device(
get_soc_descriptor(mmio_chip).arch == tt::ARCH::WORMHOLE_B0,
"{} can only be called for Wormhole arch",
__FUNCTION__);
auto& eth_cores = get_soc_descriptor(mmio_chip).ethernet_cores;
auto eth_cores = get_soc_descriptor(mmio_chip).get_cores(CoreType::ETH);
// Cores 0, 1, 6, 7 are only available if in the active set
static std::unordered_set<tt_xy_pair> eth_cores_available_if_active = {
eth_cores.at(0), eth_cores.at(1), eth_cores.at(6), eth_cores.at(7)};
Expand Down Expand Up @@ -652,9 +654,12 @@ void Cluster::populate_cores() {
for (const auto& [chip_id, chip] : chips_) {
auto& soc_desc = chip->get_soc_descriptor();
workers_per_chip.insert(
{chip_id, std::unordered_set<tt_xy_pair>(soc_desc.workers.begin(), soc_desc.workers.end())});
{chip_id,
std::unordered_set<tt_xy_pair>(
soc_desc.get_cores(CoreType::TENSIX).begin(), soc_desc.get_cores(CoreType::TENSIX).end())});
if (count == 0) {
eth_cores = std::unordered_set<tt_xy_pair>(soc_desc.ethernet_cores.begin(), soc_desc.ethernet_cores.end());
eth_cores = std::unordered_set<tt_xy_pair>(
soc_desc.get_cores(CoreType::ETH).begin(), soc_desc.get_cores(CoreType::ETH).end());
for (std::uint32_t dram_idx = 0; dram_idx < soc_desc.get_num_dram_channels(); dram_idx++) {
dram_cores.insert(soc_desc.get_core_for_dram_channel(dram_idx, 0));
}
Expand Down Expand Up @@ -689,6 +694,7 @@ std::vector<int> Cluster::extract_rows_to_remove(
return row_coordinates_to_remove;
}

// TODO: This will be removed very soon.
void Cluster::remove_worker_row_from_descriptor(
tt_SocDescriptor& full_soc_descriptor, const std::vector<int>& row_coordinates_to_remove) {
std::vector<tt_xy_pair> workers_to_keep;
Expand Down Expand Up @@ -720,10 +726,11 @@ void Cluster::remove_worker_row_from_descriptor(
}

void Cluster::harvest_rows_in_soc_descriptor(tt::ARCH arch, tt_SocDescriptor& sdesc, uint32_t harvested_rows) {
std::uint32_t max_row_to_remove =
(*std::max_element((sdesc.workers).begin(), (sdesc.workers).end(), [](const auto& a, const auto& b) {
return a.y < b.y;
})).y;
std::uint32_t max_row_to_remove = (*std::max_element(
(sdesc.get_cores(CoreType::TENSIX)).begin(),
(sdesc.get_cores(CoreType::TENSIX)).end(),
[](const auto& a, const auto& b) { return a.y < b.y; }))
.y;
std::vector<int> row_coordinates_to_remove = extract_rows_to_remove(arch, max_row_to_remove, harvested_rows);
remove_worker_row_from_descriptor(sdesc, row_coordinates_to_remove);
}
Expand Down Expand Up @@ -944,12 +951,13 @@ void Cluster::deassert_risc_reset_at_core(tt_cxy_pair core, const TensixSoftRese
std::uint32_t target_device = core.chip;
log_assert(
std::find(
get_soc_descriptor(target_device).workers.begin(), get_soc_descriptor(target_device).workers.end(), core) !=
get_soc_descriptor(target_device).workers.end() ||
get_soc_descriptor(target_device).get_cores(CoreType::TENSIX).begin(),
get_soc_descriptor(target_device).get_cores(CoreType::TENSIX).end(),
core) != get_soc_descriptor(target_device).get_cores(CoreType::TENSIX).end() ||
std::find(
get_soc_descriptor(target_device).ethernet_cores.begin(),
get_soc_descriptor(target_device).ethernet_cores.end(),
core) != get_soc_descriptor(target_device).ethernet_cores.end(),
get_soc_descriptor(target_device).get_cores(CoreType::ETH).begin(),
get_soc_descriptor(target_device).get_cores(CoreType::ETH).end(),
core) != get_soc_descriptor(target_device).get_cores(CoreType::ETH).end(),
"Cannot deassert reset on a non-tensix or harvested core");
bool target_is_mmio_capable = cluster_desc->is_chip_mmio_capable(target_device);
if (target_is_mmio_capable) {
Expand All @@ -971,12 +979,13 @@ void Cluster::assert_risc_reset_at_core(tt_cxy_pair core, const TensixSoftResetO
std::uint32_t target_device = core.chip;
log_assert(
std::find(
get_soc_descriptor(target_device).workers.begin(), get_soc_descriptor(target_device).workers.end(), core) !=
get_soc_descriptor(target_device).workers.end() ||
get_soc_descriptor(target_device).get_cores(CoreType::TENSIX).begin(),
get_soc_descriptor(target_device).get_cores(CoreType::TENSIX).end(),
core) != get_soc_descriptor(target_device).get_cores(CoreType::TENSIX).end() ||
std::find(
get_soc_descriptor(target_device).ethernet_cores.begin(),
get_soc_descriptor(target_device).ethernet_cores.end(),
core) != get_soc_descriptor(target_device).ethernet_cores.end(),
get_soc_descriptor(target_device).get_cores(CoreType::ETH).begin(),
get_soc_descriptor(target_device).get_cores(CoreType::ETH).end(),
core) != get_soc_descriptor(target_device).get_cores(CoreType::ETH).end(),
"Cannot assert reset on a non-tensix or harvested core");
bool target_is_mmio_capable = cluster_desc->is_chip_mmio_capable(target_device);
if (target_is_mmio_capable) {
Expand Down Expand Up @@ -2714,7 +2723,7 @@ int Cluster::remote_arc_msg(
constexpr uint64_t ARC_RESET_SCRATCH_ADDR = 0x880030060;
constexpr uint64_t ARC_RESET_MISC_CNTL_ADDR = 0x880030100;

auto core = tt_cxy_pair(chip, get_soc_descriptor(chip).arc_cores.at(0));
auto core = tt_cxy_pair(chip, get_soc_descriptor(chip).get_cores(CoreType::ARC).at(0));

if ((msg_code & 0xff00) != 0xaa00) {
log_error("Malformed message. msg_code is 0x{:x} but should be 0xaa..", msg_code);
Expand Down Expand Up @@ -2957,7 +2966,7 @@ void Cluster::write_to_device(
} else {
log_assert(arch_name != tt::ARCH::BLACKHOLE, "Non-MMIO targets not supported in Blackhole");
log_assert(
(get_soc_descriptor(core.chip).ethernet_cores).size() > 0 && chips_.size() > 1,
(get_soc_descriptor(core.chip).get_cores(CoreType::ETH)).size() > 0 && chips_.size() > 1,
"Cannot issue ethernet writes to a single chip cluster!");
write_to_non_mmio_device(mem_ptr, size, core, addr);
}
Expand Down Expand Up @@ -3027,7 +3036,7 @@ void Cluster::read_from_device(
arch_name != tt::ARCH::BLACKHOLE,
"Non-MMIO targets not supported in Blackhole"); // MT: Use only dynamic TLBs and never program static
log_assert(
(get_soc_descriptor(core.chip).ethernet_cores).size() > 0 && chips_.size() > 1,
(get_soc_descriptor(core.chip).get_cores(CoreType::ETH)).size() > 0 && chips_.size() > 1,
"Cannot issue ethernet reads from a single chip cluster!");
read_from_non_mmio_device(mem_ptr, core, addr, size);
}
Expand Down Expand Up @@ -3208,7 +3217,7 @@ void Cluster::verify_eth_fw() {
for (const auto& chip : all_chip_ids_) {
uint32_t fw_version;
std::vector<uint32_t> fw_versions;
for (const tt_xy_pair& eth_core : get_soc_descriptor(chip).ethernet_cores) {
for (const tt_xy_pair& eth_core : get_soc_descriptor(chip).get_cores(CoreType::ETH)) {
read_from_device(
&fw_version,
tt_cxy_pair(chip, eth_core),
Expand Down
14 changes: 7 additions & 7 deletions tests/api/test_chip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ using namespace tt::umd;
inline tt_cxy_pair get_tensix_chip_core_coord(const std::unique_ptr<Cluster>& umd_cluster) {
chip_id_t any_mmio_chip = *umd_cluster->get_target_mmio_device_ids().begin();
const tt_SocDescriptor& soc_desc = umd_cluster->get_soc_descriptor(any_mmio_chip);
tt_xy_pair core = soc_desc.workers[0];
tt_xy_pair core = soc_desc.get_cores(CoreType::TENSIX)[0];
return tt_cxy_pair(any_mmio_chip, core);
}

Expand All @@ -50,14 +50,14 @@ TEST(ApiChipTest, ManualTLBConfiguration) {
if (!remote_chips.empty()) {
chip_id_t any_remote_chip = *remote_chips.begin();
const tt_SocDescriptor& soc_desc = umd_cluster->get_soc_descriptor(any_remote_chip);
tt_xy_pair core = soc_desc.workers[0];
tt_xy_pair core = soc_desc.get_cores(CoreType::TENSIX)[0];
EXPECT_THROW(umd_cluster->get_static_tlb_writer(tt_cxy_pair(any_remote_chip, core)), std::runtime_error);
}

// Expect to throw for non configured mmio chip.
chip_id_t any_mmio_chip = *umd_cluster->get_target_mmio_device_ids().begin();
const tt_SocDescriptor& soc_desc = umd_cluster->get_soc_descriptor(any_mmio_chip);
tt_xy_pair core = soc_desc.workers[0];
tt_xy_pair core = soc_desc.get_cores(CoreType::TENSIX)[0];
EXPECT_THROW(umd_cluster->get_static_tlb_writer(tt_cxy_pair(any_mmio_chip, core)), std::runtime_error);

// TODO: This should be part of TTDevice interface, not Cluster or Chip.
Expand All @@ -77,7 +77,7 @@ TEST(ApiChipTest, ManualTLBConfiguration) {
// Each MMIO chip has it's own set of TLBs, so needs its own configuration.
for (chip_id_t mmio_chip : umd_cluster->get_target_mmio_device_ids()) {
const tt_SocDescriptor& soc_desc = umd_cluster->get_soc_descriptor(mmio_chip);
for (tt_xy_pair core : soc_desc.workers) {
for (tt_xy_pair core : soc_desc.get_cores(CoreType::TENSIX)) {
umd_cluster->configure_tlb(mmio_chip, core, get_static_tlb_index(core), c_zero_address);
}
}
Expand All @@ -86,10 +86,10 @@ TEST(ApiChipTest, ManualTLBConfiguration) {
EXPECT_NO_THROW(umd_cluster->get_static_tlb_writer(tt_cxy_pair(any_mmio_chip, core)));

// Expect to throw for non worker cores.
tt_xy_pair dram_core = soc_desc.dram_cores[0][0];
tt_xy_pair dram_core = soc_desc.get_dram_cores()[0][0];
EXPECT_THROW(umd_cluster->get_static_tlb_writer(tt_cxy_pair(any_mmio_chip, dram_core)), std::runtime_error);
if (!soc_desc.ethernet_cores.empty()) {
tt_xy_pair eth_core = soc_desc.ethernet_cores[0];
if (!soc_desc.get_cores(CoreType::ETH).empty()) {
tt_xy_pair eth_core = soc_desc.get_cores(CoreType::ETH)[0];
EXPECT_THROW(umd_cluster->get_static_tlb_writer(tt_cxy_pair(any_mmio_chip, eth_core)), std::runtime_error);
}
}
Expand Down
Loading

0 comments on commit d5bba47

Please sign in to comment.