Skip to content

Commit

Permalink
Make chip_id, ethernet_channel, and eth_coord strong types
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickroberts committed Sep 9, 2024
1 parent 17d2283 commit 360f6d4
Show file tree
Hide file tree
Showing 10 changed files with 261 additions and 225 deletions.
6 changes: 3 additions & 3 deletions device/cpuset_lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ bool tt_cpuset_allocator::init_find_tt_pci_devices_packages_numanodes(){

std::string pci_bus_id_str = get_pci_bus_id(pci_device_obj);
std::string pci_device_dir = "/sys/bus/pci/devices/" + pci_bus_id_str + "/tenstorrent/";
int physical_device_id = -1;
auto physical_device_id = umd::chip_id::none;

log_trace(LogSiliconDriver, "Found TT device with pci_bus_id_str: {} num_devices_by_pci_device_id: {}", pci_bus_id_str, m_num_tt_device_by_pci_device_id_map[device_id_revision]);

Expand All @@ -108,14 +108,14 @@ bool tt_cpuset_allocator::init_find_tt_pci_devices_packages_numanodes(){
auto entry_str = entry.path().string();

if (std::smatch device_match; std::regex_search(entry_str, device_match, tt_device_re) and (stoi(device_match[1]) >= 0)){
physical_device_id = stoi(device_match[1]);
physical_device_id = umd::chip_id{stoi(device_match[1])};
m_all_tt_devices.push_back(physical_device_id);
log_debug(LogSiliconDriver, "Found physical_device_id: {} from file: {}", physical_device_id, entry_str);
break;
}
}

if (physical_device_id == -1){
if (physical_device_id == umd::chip_id::none){
log_warning(LogSiliconDriver, "Did not find file containing physical_device_id in {}", pci_device_dir);
return false;
}
Expand Down
6 changes: 3 additions & 3 deletions device/cpuset_lib.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,16 @@ struct tt_cpuset_allocator {
pid_t m_pid;

// Items calculated by parsing system info, used by allocation algorithm:
std::map<int, std::vector<int>> m_package_id_to_devices_map;
std::map<int, std::string> m_physical_device_id_to_pci_bus_id_map; // Debug/Info
std::map<int, std::vector<umd::chip_id>> m_package_id_to_devices_map;
std::map<umd::chip_id, std::string> m_physical_device_id_to_pci_bus_id_map; // Debug/Info
std::map<std::pair<uint16_t, uint16_t>, int> m_num_tt_device_by_pci_device_id_map;

std::map<chip_id_t, std::vector<hwloc_cpuset_t>> m_physical_device_id_to_cpusets_map;
std::map<chip_id_t, int> m_physical_device_id_to_package_id_map;

bool m_enable_cpuset_allocator = true; // Enable feature, otherwise do nothing.
int m_num_packages = 0;
std::vector<int> m_all_tt_devices = {};
std::vector<umd::chip_id> m_all_tt_devices = {};

hwloc_obj_type_t m_object_per_alloc_slot = HWLOC_OBJ_L3CACHE; // Default

Expand Down
10 changes: 8 additions & 2 deletions device/kmdif.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,16 @@ typedef std::uint32_t DWORD;

struct TTDevice;

namespace tt::umd {

enum class chip_id : int;

} // namespace tt::umd

struct PCIdevice {
unsigned int id = 0;
tt::umd::chip_id id{0};
TTDevice *hdev = nullptr;
unsigned int logical_id;
tt::umd::chip_id logical_id;
std::uint16_t vendor_id;
std::uint16_t device_id;
std::uint16_t subsystem_vendor_id;
Expand Down
31 changes: 15 additions & 16 deletions device/simulation/tt_simulation_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@

tt_SimulationDevice::tt_SimulationDevice(const std::string &sdesc_path) : tt_device(sdesc_path){
log_info(tt::LogEmulationDriver, "Instantiating simulation device");
soc_descriptor_per_chip.emplace(0, tt_SocDescriptor(sdesc_path));
std::set<chip_id_t> target_devices = {0};

soc_descriptor_per_chip.emplace(tt::umd::chip_id{}, tt_SocDescriptor(sdesc_path));

// Start VCS simulator in a separate process
TT_ASSERT(std::getenv("TT_REMOTE_EXE"), "TT_REMOTE_EXE not set, please provide path to the VCS binary");
uv_loop_t *loop = uv_default_loop();
Expand All @@ -45,7 +44,7 @@ tt_SimulationDevice::tt_SimulationDevice(const std::string &sdesc_path) : tt_dev

tt_SimulationDevice::~tt_SimulationDevice() {
log_info(tt::LogEmulationDriver, "Sending exit signal to remote...");
auto builder = create_flatbuffer(DEVICE_COMMAND_EXIT, std::vector<uint32_t>(1, 0), {0, 0, 0}, 0);
auto builder = create_flatbuffer(DEVICE_COMMAND_EXIT, std::vector<uint32_t>(1, 0), {}, 0);
host.send_to_device(builder.GetBufferPointer(), builder.GetSize());
}

Expand Down Expand Up @@ -85,7 +84,7 @@ void tt_SimulationDevice::start_device(const tt_device_params &device_params) {

void tt_SimulationDevice::assert_risc_reset() {
log_info(tt::LogEmulationDriver, "Sending assert_risc_reset signal..");
auto wr_buffer = create_flatbuffer(DEVICE_COMMAND_ALL_TENSIX_RESET_ASSERT, std::vector<uint32_t>(1, 0), {0, 0, 0}, 0);
auto wr_buffer = create_flatbuffer(DEVICE_COMMAND_ALL_TENSIX_RESET_ASSERT, std::vector<uint32_t>(1, 0), {}, 0);
uint8_t *wr_buffer_ptr = wr_buffer.GetBufferPointer();
size_t wr_buffer_size = wr_buffer.GetSize();

Expand All @@ -95,7 +94,7 @@ void tt_SimulationDevice::assert_risc_reset() {

void tt_SimulationDevice::deassert_risc_reset() {
log_info(tt::LogEmulationDriver, "Sending 'deassert_risc_reset' signal..");
auto wr_buffer = create_flatbuffer(DEVICE_COMMAND_ALL_TENSIX_RESET_DEASSERT, std::vector<uint32_t>(1, 0), {0, 0, 0}, 0);
auto wr_buffer = create_flatbuffer(DEVICE_COMMAND_ALL_TENSIX_RESET_DEASSERT, std::vector<uint32_t>(1, 0), {}, 0);
uint8_t *wr_buffer_ptr = wr_buffer.GetBufferPointer();
size_t wr_buffer_size = wr_buffer.GetSize();

Expand Down Expand Up @@ -161,19 +160,19 @@ void tt_SimulationDevice::dram_membar(const chip_id_t chip, const std::string& f

// Misc. Functions to Query/Set Device State
std::unordered_map<chip_id_t, uint32_t> tt_SimulationDevice::get_harvesting_masks_for_soc_descriptors() {
return {{0, 0}};
return {{{}, 0}};
}

std::vector<chip_id_t> tt_SimulationDevice::detect_available_device_ids() {
return {0};
return {{}};
}

std::set<chip_id_t> tt_SimulationDevice::get_target_remote_device_ids() {
return target_remote_chips;
}

std::map<int,int> tt_SimulationDevice::get_clocks() {
return {{0, 0}};
std::map<tt::umd::chip_id,int> tt_SimulationDevice::get_clocks() {
return {{{}, 0}};
}

void *tt_SimulationDevice::host_dma_address(std::uint64_t offset, chip_id_t src_device_id, uint16_t channel) const {
Expand All @@ -193,20 +192,20 @@ std::uint64_t tt_SimulationDevice::get_pcie_base_addr_from_device() const {
}
}

std::uint32_t tt_SimulationDevice::get_num_dram_channels(std::uint32_t device_id) {
std::uint32_t tt_SimulationDevice::get_num_dram_channels(tt::umd::chip_id device_id) {
return get_soc_descriptor(device_id)->get_num_dram_channels();
}

std::uint64_t tt_SimulationDevice::get_dram_channel_size(std::uint32_t device_id, std::uint32_t channel) {
std::uint64_t tt_SimulationDevice::get_dram_channel_size(tt::umd::chip_id device_id, std::uint32_t channel) {
return get_soc_descriptor(device_id)->dram_bank_size; // Space per channel is identical for now
}

std::uint32_t tt_SimulationDevice::get_num_host_channels(std::uint32_t device_id) {
std::uint32_t tt_SimulationDevice::get_num_host_channels(tt::umd::chip_id device_id) {
return 1;
}

std::uint32_t tt_SimulationDevice::get_host_channel_size(std::uint32_t device_id, std::uint32_t channel) {return 0;}
std::uint32_t tt_SimulationDevice::get_numa_node_for_pcie_device(std::uint32_t device_id) {return 0;}
std::uint32_t tt_SimulationDevice::get_host_channel_size(tt::umd::chip_id device_id, std::uint32_t channel) {return 0;}
std::uint32_t tt_SimulationDevice::get_numa_node_for_pcie_device(tt::umd::chip_id device_id) {return 0;}

flatbuffers::FlatBufferBuilder tt_SimulationDevice::create_flatbuffer(DEVICE_COMMAND rw, std::vector<uint32_t> vec, tt_cxy_pair core_, uint64_t addr, uint64_t size_){
flatbuffers::FlatBufferBuilder builder;
Expand All @@ -222,7 +221,7 @@ void tt_SimulationDevice::print_flatbuffer(const DeviceRequestResponse *buf){
std::vector<uint32_t> data_vec(buf->data()->begin(), buf->data()->end());
uint64_t addr = buf->address();
uint32_t size = buf->size();
tt_cxy_pair core = {0, buf->core()->x(), buf->core()->y()};
tt_xy_pair core = {buf->core()->x(), buf->core()->y()};

std::stringstream ss;
ss << std::hex << reinterpret_cast<uintptr_t>(addr);
Expand Down
12 changes: 6 additions & 6 deletions device/simulation/tt_simulation_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ class tt_SimulationDevice: public tt_device {
// virtual tt_ClusterDescriptor* get_cluster_description();
static std::vector<chip_id_t> detect_available_device_ids();
virtual std::set<chip_id_t> get_target_remote_device_ids();
virtual std::map<int,int> get_clocks();
virtual std::map<tt::umd::chip_id,int> get_clocks();
// virtual void *channel_0_address(std::uint32_t offset, std::uint32_t device_id) const;
virtual void *host_dma_address(std::uint64_t offset, chip_id_t src_device_id, uint16_t channel) const;
virtual std::uint64_t get_pcie_base_addr_from_device() const;
virtual std::uint32_t get_num_dram_channels(std::uint32_t device_id);
virtual std::uint64_t get_dram_channel_size(std::uint32_t device_id, std::uint32_t channel);
virtual std::uint32_t get_num_host_channels(std::uint32_t device_id);
virtual std::uint32_t get_host_channel_size(std::uint32_t device_id, std::uint32_t channel);
virtual std::uint32_t get_numa_node_for_pcie_device(std::uint32_t device_id);
virtual std::uint32_t get_num_dram_channels(tt::umd::chip_id device_id);
virtual std::uint64_t get_dram_channel_size(tt::umd::chip_id device_id, std::uint32_t channel);
virtual std::uint32_t get_num_host_channels(tt::umd::chip_id device_id);
virtual std::uint32_t get_host_channel_size(tt::umd::chip_id device_id, std::uint32_t channel);
virtual std::uint32_t get_numa_node_for_pcie_device(tt::umd::chip_id device_id);
// virtual tt_version get_ethernet_fw_version() const;

private:
Expand Down
Loading

0 comments on commit 360f6d4

Please sign in to comment.