Skip to content

Commit

Permalink
more refactorings
Browse files Browse the repository at this point in the history
  • Loading branch information
broskoTT committed Nov 30, 2024
1 parent 0002448 commit 812a64d
Show file tree
Hide file tree
Showing 16 changed files with 269 additions and 243 deletions.
4 changes: 2 additions & 2 deletions device/api/umd/device/architecture_implementation.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
#include <vector>

#include "umd/device/tlb.h"
#include "umd/device/types.h"
#include "umd/device/xy_pair.h"
#include "umd/device/types/arch.h"
#include "umd/device/types/xy_pair.h"

struct tt_driver_host_address_params;
struct tt_driver_eth_interface_params;
Expand Down
189 changes: 3 additions & 186 deletions device/api/umd/device/cluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
#include "umd/device/pci_device.hpp"
#include "umd/device/tlb.h"
#include "umd/device/tt_io.hpp"
#include "umd/device/types.h"
#include "umd/device/types/arch.h"
#include "umd/device/types/cluster_descriptor_types.h"
#include "umd/device/types/cluster_types.h"

using TLB_DATA = tt::umd::tlb_data;

Expand All @@ -35,191 +37,6 @@ class named_mutex;

class tt_ClusterDescriptor;

enum tt_DevicePowerState { BUSY, SHORT_IDLE, LONG_IDLE };

enum tt_MemBarFlag {
SET = 0xaa,
RESET = 0xbb,
};

inline std::ostream& operator<<(std::ostream& os, const tt_DevicePowerState power_state) {
switch (power_state) {
case tt_DevicePowerState::BUSY:
os << "Busy";
break;
case tt_DevicePowerState::SHORT_IDLE:
os << "SHORT_IDLE";
break;
case tt_DevicePowerState::LONG_IDLE:
os << "LONG_IDLE";
break;
default:
throw("Unknown DevicePowerState");
}
return os;
}

struct tt_device_dram_address_params {
std::uint32_t DRAM_BARRIER_BASE = 0;
};

/**
* Struct encapsulating all L1 Address Map parameters required by UMD.
* These parameters are passed to the constructor.
*/
struct tt_device_l1_address_params {
std::uint32_t tensix_l1_barrier_base = 0;
std::uint32_t eth_l1_barrier_base = 0;
std::uint32_t fw_version_addr = 0;
};

/**
* Struct encapsulating all Host Address Map parameters required by UMD.
* These parameters are passed to the constructor and are needed for non-MMIO transactions.
*/
struct tt_driver_host_address_params {
std::uint32_t eth_routing_block_size = 0;
std::uint32_t eth_routing_buffers_start = 0;
};

struct tt_driver_noc_params {
std::uint32_t noc_addr_local_bits = 0;
std::uint32_t noc_addr_node_id_bits = 0;
};

/**
* Struct encapsulating all ERISC Firmware parameters required by UMD.
* These parameters are passed to the constructor and are needed for non-MMIO transactions.
*/
struct tt_driver_eth_interface_params {
std::uint32_t eth_rack_coord_width = 0;
std::uint32_t cmd_buf_size_mask = 0;
std::uint32_t max_block_size = 0;
std::uint32_t request_cmd_queue_base = 0;
std::uint32_t response_cmd_queue_base = 0;
std::uint32_t cmd_counters_size_bytes = 0;
std::uint32_t remote_update_ptr_size_bytes = 0;
std::uint32_t cmd_data_block = 0;
std::uint32_t cmd_wr_req = 0;
std::uint32_t cmd_wr_ack = 0;
std::uint32_t cmd_rd_req = 0;
std::uint32_t cmd_rd_data = 0;
std::uint32_t cmd_buf_size = 0;
std::uint32_t cmd_data_block_dram = 0;
std::uint32_t eth_routing_data_buffer_addr = 0;
std::uint32_t request_routing_cmd_queue_base = 0;
std::uint32_t response_routing_cmd_queue_base = 0;
std::uint32_t cmd_buf_ptr_mask = 0;
std::uint32_t cmd_ordered = 0;
std::uint32_t cmd_broadcast = 0;
};

struct tt_version {
std::uint16_t major = 0xffff;
std::uint8_t minor = 0xff;
std::uint8_t patch = 0xff;

tt_version() {}

tt_version(std::uint16_t major_, std::uint8_t minor_, std::uint8_t patch_) {
major = major_;
minor = minor_;
patch = patch_;
}

tt_version(std::uint32_t version) {
major = (version >> 16) & 0xff;
minor = (version >> 12) & 0xf;
patch = version & 0xfff;
}

std::string str() const { return fmt::format("{}.{}.{}", major, minor, patch); }
};

struct tt_device_params {
bool register_monitor = false;
bool enable_perf_scoreboard = false;
std::vector<std::string> vcd_dump_cores;
std::vector<std::string> plusargs;
bool init_device = true;
bool early_open_device = false;
int aiclk = 0;

// The command-line input for vcd_dump_cores can have the following format:
// {"*-2", "1-*", "*-*", "1-2"}
// '*' indicates we must dump all the cores in that dimension.
// This function takes the vector above and unrolles the coords with '*' in one or both dimensions.
std::vector<std::string> unroll_vcd_dump_cores(tt_xy_pair grid_size) const {
std::vector<std::string> unrolled_dump_core;
for (auto& dump_core : vcd_dump_cores) {
// If the input is a single *, then dump all cores.
if (dump_core == "*") {
for (size_t x = 0; x < grid_size.x; x++) {
for (size_t y = 0; y < grid_size.y; y++) {
std::string current_core_coord = fmt::format("{}-{}", x, y);
if (std::find(
std::begin(unrolled_dump_core), std::end(unrolled_dump_core), current_core_coord) ==
std::end(unrolled_dump_core)) {
unrolled_dump_core.push_back(current_core_coord);
}
}
}
continue;
}
// Each core coordinate must contain three characters: "core.x-core.y".
assert(dump_core.size() <= 5);
size_t delimiter_pos = dump_core.find('-');
assert(delimiter_pos != std::string::npos); // y-dim should exist in core coord.

std::string core_dim_x = dump_core.substr(0, delimiter_pos);
size_t core_dim_y_start = delimiter_pos + 1;
std::string core_dim_y = dump_core.substr(core_dim_y_start, dump_core.length() - core_dim_y_start);

if (core_dim_x == "*" && core_dim_y == "*") {
for (size_t x = 0; x < grid_size.x; x++) {
for (size_t y = 0; y < grid_size.y; y++) {
std::string current_core_coord = fmt::format("{}-{}", x, y);
if (std::find(
std::begin(unrolled_dump_core), std::end(unrolled_dump_core), current_core_coord) ==
std::end(unrolled_dump_core)) {
unrolled_dump_core.push_back(current_core_coord);
}
}
}
} else if (core_dim_x == "*") {
for (size_t x = 0; x < grid_size.x; x++) {
std::string current_core_coord = fmt::format("{}-{}", x, core_dim_y);
if (std::find(std::begin(unrolled_dump_core), std::end(unrolled_dump_core), current_core_coord) ==
std::end(unrolled_dump_core)) {
unrolled_dump_core.push_back(current_core_coord);
}
}
} else if (core_dim_y == "*") {
for (size_t y = 0; y < grid_size.y; y++) {
std::string current_core_coord = fmt::format("{}-{}", core_dim_x, y);
if (std::find(std::begin(unrolled_dump_core), std::end(unrolled_dump_core), current_core_coord) ==
std::end(unrolled_dump_core)) {
unrolled_dump_core.push_back(current_core_coord);
}
}
} else {
unrolled_dump_core.push_back(dump_core);
}
}
return unrolled_dump_core;
}

std::vector<std::string> expand_plusargs() const {
std::vector<std::string> all_plusargs{
fmt::format("+enable_perf_scoreboard={}", enable_perf_scoreboard),
fmt::format("+register_monitor={}", register_monitor)};

all_plusargs.insert(all_plusargs.end(), plusargs.begin(), plusargs.end());

return all_plusargs;
}
};

// TODO: This class is to be removed once we move Simulation and Mockup devices to be Chips instead of Clusters.
/**
* Parent class for Cluster (Silicon Driver).
Expand Down
2 changes: 1 addition & 1 deletion device/api/umd/device/coordinate_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <vector>

#include "umd/device/tt_xy_pair.h"
#include "umd/device/types.h"
#include "umd/device/types/arch.h"

class CoordinateManager {
public:
Expand Down
2 changes: 1 addition & 1 deletion device/api/umd/device/hugepage.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <cstdint>
#include <string>

#include "umd/device/types.h"
#include "umd/device/types/cluster_descriptor_types.h"

namespace tt::umd {

Expand Down
2 changes: 1 addition & 1 deletion device/api/umd/device/pci_device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include "umd/device/semver.hpp"
#include "umd/device/tlb.h"
#include "umd/device/tt_xy_pair.h"
#include "umd/device/types.h"
#include "umd/device/types/arch.h"

// TODO: this is used up in cluster.cpp but that logic ought to be
// lowered into the PCIDevice class since it is specific to PCIe cards.
Expand Down
3 changes: 2 additions & 1 deletion device/api/umd/device/tt_cluster_descriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
#include <vector>

#include "umd/device/tt_xy_pair.h"
#include "umd/device/types.h"
#include "umd/device/types/arch.h"
#include "umd/device/types/cluster_descriptor_types.h"

namespace YAML {
class Node;
Expand Down
2 changes: 1 addition & 1 deletion device/api/umd/device/tt_soc_descriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "tt_xy_pair.h"
#include "umd/device/coordinate_manager.h"
#include "umd/device/tt_xy_pair.h"
#include "umd/device/types.h"
#include "umd/device/types/arch.h"

namespace YAML {
class Node;
Expand Down
3 changes: 2 additions & 1 deletion device/api/umd/device/tt_xy_pair.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@

#include <regex>

#include "umd/device/xy_pair.h"
#include "umd/device/types/xy_pair.h"

// TODO: These usings and this whole file are to be removed.
using tt_xy_pair = tt::umd::xy_pair;
using tt_cxy_pair = tt::umd::cxy_pair;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,17 @@

#pragma once

#include <cctype>
#include <functional>
#include <tuple>
#include <algorithm>
#include <ostream>

// Small performant hash combiner taken from boost library.
// Not using boost::hash_combine due to dependency complications.
inline void boost_hash_combine(std::size_t &seed, const int value) {
seed ^= value + 0x9e3779b9 + (seed << 6) + (seed >> 2);
}
namespace tt::umd {

static inline std::string to_lower(const std::string &str) {
std::string res = str;
std::transform(res.begin(), res.end(), res.begin(), ::tolower);
return res;
}

namespace tt::umd {

/**
* Enums for different architectures.
*/
Expand All @@ -39,7 +32,7 @@ static inline tt::umd::Arch arch_from_str(const std::string &arch_str) {

if (arch_str_lower == "grayskull") {
return tt::umd::Arch::GRAYSKULL;
} else if ((arch_str_lower == "wormhole") || (arch_str == "wormhole_b0")) {
} else if ((arch_str_lower == "wormhole") || (arch_str_lower == "wormhole_b0")) {
return tt::umd::Arch::WORMHOLE_B0;
} else if (arch_str_lower == "blackhole") {
return tt::umd::Arch::BLACKHOLE;
Expand All @@ -64,40 +57,6 @@ static inline std::string arch_to_str(const tt::umd::Arch arch) {

} // namespace tt::umd

using chip_id_t = int;
using ethernet_channel_t = int;

struct eth_coord_t {
int cluster_id; // This is the same for connected chips.
int x;
int y;
int rack;
int shelf;

// in C++20 this should be defined as:
// constexpr bool operator==(const eth_coord_t &other) const noexcept = default;
constexpr bool operator==(const eth_coord_t &other) const noexcept {
return (
cluster_id == other.cluster_id and x == other.x and y == other.y and rack == other.rack and
shelf == other.shelf);
}
};

static inline std::ostream &operator<<(std::ostream &out, const tt::umd::Arch &arch) {
return out << arch_to_str(arch);
}

namespace std {
template <>
struct hash<eth_coord_t> {
std::size_t operator()(eth_coord_t const &c) const {
std::size_t seed = 0;
boost_hash_combine(seed, c.cluster_id);
boost_hash_combine(seed, c.x);
boost_hash_combine(seed, c.y);
boost_hash_combine(seed, c.rack);
boost_hash_combine(seed, c.shelf);
return seed;
}
};
} // namespace std
Loading

0 comments on commit 812a64d

Please sign in to comment.