From f24f01460310fff06ba1c5d89942130a21e94d3c Mon Sep 17 00:00:00 2001 From: Bojan Rosko Date: Fri, 28 Feb 2025 11:25:13 +0000 Subject: [PATCH] removal --- .../deprecated/tt_emulation_device.cpp | 227 ---------- .../deprecated/tt_emulation_device.h | 105 ----- .../deprecated/tt_emulation_stub.cpp | 119 ------ .../deprecated/tt_versim_device.cpp | 391 ------------------ .../simulation/deprecated/tt_versim_device.h | 123 ------ .../simulation/deprecated/tt_versim_stub.cpp | 138 ------- 6 files changed, 1103 deletions(-) delete mode 100644 device/simulation/deprecated/tt_emulation_device.cpp delete mode 100644 device/simulation/deprecated/tt_emulation_device.h delete mode 100644 device/simulation/deprecated/tt_emulation_stub.cpp delete mode 100644 device/simulation/deprecated/tt_versim_device.cpp delete mode 100644 device/simulation/deprecated/tt_versim_device.h delete mode 100644 device/simulation/deprecated/tt_versim_stub.cpp diff --git a/device/simulation/deprecated/tt_emulation_device.cpp b/device/simulation/deprecated/tt_emulation_device.cpp deleted file mode 100644 index bb2ce4fc..00000000 --- a/device/simulation/deprecated/tt_emulation_device.cpp +++ /dev/null @@ -1,227 +0,0 @@ -/* - * SPDX-FileCopyrightText: (c) 2023 Tenstorrent Inc. - * - * SPDX-License-Identifier: Apache-2.0 - */ -#include "tt_emulation_device.h" - -#include -#include - -#include "common/logger.hpp" -#include "device/tt_cluster_descriptor.h" -#include "tt_emu_zemi3_wrapper.h" - -tt_emulation_device::tt_emulation_device(const std::string& sdesc_path) : tt_device(sdesc_path) { - soc_descriptor_per_chip.emplace(0, tt_SocDescriptor(sdesc_path)); - cluster_descriptor = tt_ClusterDescriptor::create_mock_cluster({0}); - tt_zebu_wrapper_inst = new tt_emu_zemi3_wrapper(); - - log_info(tt::LogEmulationDriver, "Created Emulation Device "); -} - -tt_emulation_device::~tt_emulation_device() { - cluster_descriptor.reset(); - delete tt_zebu_wrapper_inst; - log_info(tt::LogEmulationDriver, "Destroyed Emulation Device "); -} - -void tt_emulation_device::write(tt_cxy_pair core, uint64_t addr, const std::vector& data) { - const uint32_t size = static_cast(data.size()); - tt_zebu_wrapper_inst->axi_write(0, core.x, core.y, addr, size, data); - log_info(tt::LogEmulationDriver, "Wrote {} bytes to address {:#016x}, core {},{}", size, addr, core.x, core.y); -} - -std::vector tt_emulation_device::read(tt_cxy_pair core, uint64_t addr, uint32_t size) { - std::vector data(size); - tt_zebu_wrapper_inst->axi_read(0, core.x, core.y, addr, size, data); - log_info(tt::LogEmulationDriver, "Read {} bytes from address {:#016x}", size, addr); - - return data; -} - -void tt_emulation_device::start_device(const tt_device_params& device_params) { - tt_zebu_wrapper_inst->zebu_start(); - tt_zebu_wrapper_inst->zebu_enable_waveform_dump(tt_zebu_wrapper::WAVEFORM_DUMP_QIWC); - log_info(tt::LogEmulationDriver, "Started Emulation Device "); -} - -void tt_emulation_device::deassert_risc_reset() { - tt_zebu_wrapper_inst->all_tensix_reset_deassert(); - log_info(tt::LogEmulationDriver, "Deasserted all tensix RISC Reset "); -} - -void tt_emulation_device::assert_risc_reset() { - tt_zebu_wrapper_inst->all_tensix_reset_assert(); - log_info(tt::LogEmulationDriver, "Asserted all tensix RISC Reset "); -} - -void tt_emulation_device::deassert_risc_reset_at_core(tt_cxy_pair core, const TensixSoftResetOptions& soft_resets) { - tt_zebu_wrapper_inst->tensix_reset_deassert(core.x, core.y); -} - -void tt_emulation_device::assert_risc_reset_at_core(tt_cxy_pair core, const TensixSoftResetOptions& soft_resets) { - tt_zebu_wrapper_inst->tensix_reset_assert(core.x, core.y); -} - -void tt_emulation_device::close_device() { - log_info(tt::LogEmulationDriver, "Closing Emulation Device "); - tt_zebu_wrapper_inst->zebu_finish(); -} - -void tt_emulation_device::start( - std::vector plusargs, - std::vector dump_cores, - bool no_checkers, - bool /*init_device*/, - bool /*skip_driver_allocs*/ -) { - log_info(tt::LogEmulationDriver, "Starting Emulation Device "); -} - -void tt_emulation_device::broadcast_write_to_cluster( - const void* mem_ptr, - uint32_t size_in_bytes, - uint64_t address, - const std::set& chips_to_exclude, - std::set& rows_to_exclude, - std::set& cols_to_exclude, - const std::string& fallback_tlb) { - for (const auto& core : get_soc_descriptor(0)->get_all_cores()) { - // if(cols_to_exclude.find(core.first.x) == cols_to_exclude.end() and rows_to_exclude.find(core.first.y) == - // rows_to_exclude.end() and core.second.type != CoreType::HARVESTED) { - // write_to_device(mem_ptr, size_in_bytes, tt_cxy_pair(0, core.first.x, core.first.y), address, ""); - // } - // MT: Iterate through all the worker cores for bcast: - // if (get_soc_descriptor(0)->is_worker_core(core.first)) { - // write_to_device(mem_ptr, size_in_bytes, tt_cxy_pair(0, core.first.x, core.first.y), address, ""); - // } - // Emulation only broadcasts to all Tensix cores or all DRAM cores. - // differentiate which bcast pattern to use based on exclude columns - if (cols_to_exclude.find(0) == cols_to_exclude.end()) { - // Detect DRAM bcast - if (core.core_type == CoreType::DRAM) { - write_to_device(mem_ptr, size_in_bytes, tt_cxy_pair(0, core.first.x, core.first.y), address, ""); - } - } else { - if (core.core_type == CoreType::TENSIX) { - write_to_device(mem_ptr, size_in_bytes, tt_cxy_pair(0, core.first.x, core.first.y), address, ""); - } - } - } -} - -void tt_emulation_device::rolled_write_to_device( - std::vector& base_vec, - uint32_t unroll_count, - tt_cxy_pair core, - uint64_t base_addr, - const std::string& tlb_to_use) { - std::vector vec = base_vec; - uint32_t byte_increment = 4 * vec.size(); - for (uint32_t i = 0; i < unroll_count; ++i) { - vec[0] = i; // slot id for debug - uint64_t offset_addr = base_addr + i * byte_increment; - write_to_device(vec, core, offset_addr, tlb_to_use); - } -} - -void tt_emulation_device::write_to_device( - const void* mem_ptr, - uint32_t size, - tt_cxy_pair core, - uint64_t addr, - const std::string& tlb_to_use, - bool send_epoch_cmd, - bool last_send_epoch_cmd, - bool ordered_with_prev_remote_write) { - log_assert(!(size % 4), "Writes to Emulation Backend should be 4 byte aligned!"); - - std::vector mem_vector((uint32_t*)mem_ptr, (uint32_t*)mem_ptr + size / sizeof(uint32_t)); - write_to_device( - mem_vector, core, addr, tlb_to_use, send_epoch_cmd, last_send_epoch_cmd, ordered_with_prev_remote_write); -} - -void tt_emulation_device::write_to_device( - std::vector& vec, - tt_cxy_pair core, - uint64_t addr, - const std::string& tlb_to_use, - bool send_epoch_cmd, - bool last_send_epoch_cmd, - bool ordered_with_prev_remote_write) { - std::vector byte_data(vec.size() * sizeof(uint32_t)); - std::memcpy(byte_data.data(), vec.data(), byte_data.size()); - - write(core, addr, byte_data); -} - -void tt_emulation_device::l1_membar( - const chip_id_t chip, const std::string& fallback_tlb, const std::unordered_set& cores) { - // Placeholder - implement later - https://yyz-gitlab.local.tenstorrent.com/tenstorrent/open-umd/-/issues/26 -} - -void tt_emulation_device::dram_membar( - const chip_id_t chip, const std::string& fallback_tlb, const std::unordered_set& cores) { - // Placeholder - implement later - https://yyz-gitlab.local.tenstorrent.com/tenstorrent/open-umd/-/issues/26 -} - -void tt_emulation_device::dram_membar( - const chip_id_t chip, const std::string& fallback_tlb, const std::unordered_set& channels) { - // Placeholder - implement later - https://yyz-gitlab.local.tenstorrent.com/tenstorrent/open-umd/-/issues/26 -} - -void tt_emulation_device::read_from_device( - std::vector& vec, tt_cxy_pair core, uint64_t addr, uint32_t size, const std::string& /*tlb_to_use*/) { - std::vector byte_data = read(core, addr, size); - - // Verify that the received byte data can be converted to uint32_t - // if (byte_data.size() % sizeof(uint32_t) != 0) { - // throw std::runtime_error("Received byte data size is not a multiple of uint32_t size."); - // } - - vec.clear(); - vec.resize(byte_data.size() / sizeof(uint32_t)); - std::memcpy(vec.data(), byte_data.data(), byte_data.size()); -} - -void tt_emulation_device::translate_to_noc_table_coords(chip_id_t device_id, std::size_t& r, std::size_t& c) { - // No translation is performed - return; -} - -tt_ClusterDescriptor* tt_emulation_device::get_cluster_description() { return cluster_descriptor.get(); } - -std::set tt_emulation_device::get_target_mmio_device_ids() { - log_error("LogEmulationDriver: get_target_mmio_device_ids not implemented"); - return {}; -} - -std::set tt_emulation_device::get_target_remote_device_ids() { - log_error("LogEmulationDriver: get_target_remote_device_ids not implemented"); - return {}; -} - -void tt_emulation_device::set_device_dram_address_params(const tt_device_dram_address_params& dram_address_params_) { - dram_address_params = dram_address_params_; -} - -int tt_emulation_device::get_number_of_chips_in_cluster() { return detect_number_of_chips(); } - -std::unordered_set tt_emulation_device::get_all_chips_in_cluster() { return {0}; } - -int tt_emulation_device::detect_number_of_chips() { return 1; } - -bool tt_emulation_device::using_harvested_soc_descriptors() { return false; } - -bool tt_emulation_device::noc_translation_en() { return false; } - -std::unordered_map tt_emulation_device::get_harvesting_masks_for_soc_descriptors() { - return {{0, 0}}; -} - -std::map tt_emulation_device::get_clocks() { return std::map(); } - -void tt_emulation_device::set_device_l1_address_params(const tt_device_l1_address_params& l1_address_params_) { - l1_address_params = l1_address_params_; -} diff --git a/device/simulation/deprecated/tt_emulation_device.h b/device/simulation/deprecated/tt_emulation_device.h deleted file mode 100644 index da31548f..00000000 --- a/device/simulation/deprecated/tt_emulation_device.h +++ /dev/null @@ -1,105 +0,0 @@ -/* - * SPDX-FileCopyrightText: (c) 2023 Tenstorrent Inc. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#pragma once - -#include -#include -#include - -#include "cluster.h" -#include "tt_soc_descriptor.h" -#include "tt_xy_pair.h" - -// use forward declaration here so we do not need to include tt_zebu_wrapper.h -class tt_zebu_wrapper; - -class tt_emulation_device : public tt_device { -public: - virtual void set_device_l1_address_params(const tt_device_l1_address_params& l1_address_params_); // Dont care - tt_emulation_device(const std::string& sdesc_path); - virtual void start( - std::vector plusargs, - std::vector dump_cores, - bool no_checkers, - bool init_device, - bool skip_driver_allocs); - virtual void start_device(const tt_device_params& device_params); - virtual void close_device(); - virtual void deassert_risc_reset(); - virtual void deassert_risc_reset_at_core( - tt_cxy_pair core, const TensixSoftResetOptions& soft_resets = TENSIX_DEASSERT_SOFT_RESET); - virtual void assert_risc_reset(); - virtual void assert_risc_reset_at_core( - tt_cxy_pair core, const TensixSoftResetOptions& soft_resets = TENSIX_ASSERT_SOFT_RESET); - virtual void write_to_device( - std::vector& vec, - tt_cxy_pair core, - uint64_t addr, - const std::string& tlb_to_use, - bool send_epoch_cmd = false, - bool last_send_epoch_cmd = true, - bool ordered_with_prev_remote_write = false); - virtual void write_to_device( - const void* mem_ptr, - uint32_t size_in_bytes, - tt_cxy_pair core, - uint64_t addr, - const std::string& tlb_to_use, - bool send_epoch_cmd = false, - bool last_send_epoch_cmd = true, - bool ordered_with_prev_remote_write = false); - virtual void broadcast_write_to_cluster( - const void* mem_ptr, - uint32_t size_in_bytes, - uint64_t address, - const std::set& chips_to_exclude, - std::set& rows_to_exclude, - std::set& columns_to_exclude, - const std::string& fallback_tlb); - - void l1_membar( - const chip_id_t chip, const std::string& fallback_tlb, const std::unordered_set& cores = {}); - void dram_membar( - const chip_id_t chip, const std::string& fallback_tlb, const std::unordered_set& channels); - void dram_membar( - const chip_id_t chip, const std::string& fallback_tlb, const std::unordered_set& cores = {}); - - virtual void rolled_write_to_device( - std::vector& base_vec, - uint32_t unroll_count, - tt_cxy_pair core, - uint64_t base_addr, - const std::string& tlb_to_use); // See Versim Implementation - virtual void read_from_device( - std::vector& vec, tt_cxy_pair core, uint64_t addr, uint32_t size, const std::string& tlb_to_use); - - virtual void translate_to_noc_table_coords(chip_id_t device_id, std::size_t& r, std::size_t& c); - virtual bool using_harvested_soc_descriptors(); - virtual std::unordered_map get_harvesting_masks_for_soc_descriptors(); - virtual bool noc_translation_en(); - virtual std::set get_target_mmio_device_ids(); - virtual std::set get_target_remote_device_ids(); - virtual ~tt_emulation_device(); - virtual tt_ClusterDescriptor* get_cluster_description(); - virtual void set_device_dram_address_params(const tt_device_dram_address_params& dram_address_params_); - virtual int get_number_of_chips_in_cluster(); - virtual std::unordered_set get_all_chips_in_cluster(); - static int detect_number_of_chips(); - virtual std::map get_clocks(); - -private: - tt_device_l1_address_params l1_address_params; - std::shared_ptr cluster_descriptor; - tt_device_dram_address_params dram_address_params; - - // zebu wrapper, provides interface to zebu emulator device through axi and command transactors - tt_zebu_wrapper* tt_zebu_wrapper_inst = NULL; - - // These functions implement the "protocol" between the RTL simulation and the UMD - void write(tt_cxy_pair core, uint64_t addr, const std::vector& data); - std::vector read(tt_cxy_pair core, uint64_t addr, uint32_t size); -}; diff --git a/device/simulation/deprecated/tt_emulation_stub.cpp b/device/simulation/deprecated/tt_emulation_stub.cpp deleted file mode 100644 index 8e9ccd9b..00000000 --- a/device/simulation/deprecated/tt_emulation_stub.cpp +++ /dev/null @@ -1,119 +0,0 @@ -/* - * SPDX-FileCopyrightText: (c) 2023 Tenstorrent Inc. - * - * SPDX-License-Identifier: Apache-2.0 - */ -#include -#include - -#include "common/logger.hpp" -#include "tt_emulation_device.h" - -tt_emulation_device::tt_emulation_device(const std::string& sdesc_path) : tt_device(sdesc_path) { - throw std::runtime_error("tt_emulation_device() -- Zebu Emulation is not supported in this build\n"); -} - -tt_emulation_device::~tt_emulation_device() {} - -void tt_emulation_device::write(tt_cxy_pair core, uint64_t addr, const std::vector& data) {} - -std::vector tt_emulation_device::read(tt_cxy_pair core, uint64_t addr, uint32_t size) { return {}; } - -void tt_emulation_device::start_device(const tt_device_params& device_params) {} - -void tt_emulation_device::deassert_risc_reset() {} - -void tt_emulation_device::assert_risc_reset() {} - -void tt_emulation_device::deassert_risc_reset_at_core(tt_cxy_pair core, const TensixSoftResetOptions& soft_resets) {} - -void tt_emulation_device::assert_risc_reset_at_core(tt_cxy_pair core, const TensixSoftResetOptions& soft_resets) {} - -void tt_emulation_device::close_device() {} - -void tt_emulation_device::start( - std::vector plusargs, - std::vector dump_cores, - bool no_checkers, - bool /*init_device*/, - bool /*skip_driver_allocs*/) {} - -void tt_emulation_device::broadcast_write_to_cluster( - const void* mem_ptr, - uint32_t size_in_bytes, - uint64_t address, - const std::set& chips_to_exclude, - std::set& rows_to_exclude, - std::set& cols_to_exclude, - const std::string& fallback_tlb) {} - -void tt_emulation_device::rolled_write_to_device( - std::vector& base_vec, - uint32_t unroll_count, - tt_cxy_pair core, - uint64_t base_addr, - const std::string& tlb_to_use) {} - -void tt_emulation_device::write_to_device( - std::vector& vec, - tt_cxy_pair core, - uint64_t addr, - const std::string& tlb_to_use, - bool send_epoch_cmd, - bool last_send_epoch_cmd, - bool ordered_with_prev_remote_write) {} - -void tt_emulation_device::write_to_device( - const void* mem_ptr, - uint32_t size_in_bytes, - tt_cxy_pair core, - uint64_t addr, - const std::string& tlb_to_use, - bool send_epoch_cmd, - bool last_send_epoch_cmd, - bool ordered_with_prev_remote_write){}; - -void tt_emulation_device::read_from_device( - std::vector& vec, tt_cxy_pair core, uint64_t addr, uint32_t size, const std::string& /*tlb_to_use*/) {} - -void tt_emulation_device::l1_membar( - const chip_id_t chip, const std::string& fallback_tlb, const std::unordered_set& cores) {} - -void tt_emulation_device::dram_membar( - const chip_id_t chip, const std::string& fallback_tlb, const std::unordered_set& cores) {} - -void tt_emulation_device::dram_membar( - const chip_id_t chip, const std::string& fallback_tlb, const std::unordered_set& channels) {} - -// ------------------------- -// Not sure how to implement these functions below, leaving them blank/default for now -void tt_emulation_device::translate_to_noc_table_coords(chip_id_t device_id, std::size_t& r, std::size_t& c) { - // No translation is performed - return; -} - -tt_ClusterDescriptor* tt_emulation_device::get_cluster_description() { return cluster_descriptor.get(); } - -std::set tt_emulation_device::get_target_mmio_device_ids() { return {}; } - -std::set tt_emulation_device::get_target_remote_device_ids() { return {}; } - -void tt_emulation_device::set_device_dram_address_params(const tt_device_dram_address_params& dram_address_params_) {} - -int tt_emulation_device::get_number_of_chips_in_cluster() { return detect_number_of_chips(); } - -std::unordered_set tt_emulation_device::get_all_chips_in_cluster() { return {0}; } - -int tt_emulation_device::detect_number_of_chips() { return 1; } - -bool tt_emulation_device::using_harvested_soc_descriptors() { return false; } - -bool tt_emulation_device::noc_translation_en() { return false; } - -std::unordered_map tt_emulation_device::get_harvesting_masks_for_soc_descriptors() { - return {{0, 0}}; -} - -std::map tt_emulation_device::get_clocks() { return std::map(); } - -void tt_emulation_device::set_device_l1_address_params(const tt_device_l1_address_params& l1_address_params_) {} diff --git a/device/simulation/deprecated/tt_versim_device.cpp b/device/simulation/deprecated/tt_versim_device.cpp deleted file mode 100644 index 903f9fa2..00000000 --- a/device/simulation/deprecated/tt_versim_device.cpp +++ /dev/null @@ -1,391 +0,0 @@ -// SPDX-FileCopyrightText: (c) 2023 Tenstorrent Inc. -// -// SPDX-License-Identifier: Apache-2.0 - -#include -#include -#include -#include - -#include "cluster.h" -#include "common/logger.hpp" -#include "device/driver_atomics.h" -#include "yaml-cpp/yaml.h" - -// TODO: Remove dependency on command_assembler + soc -#include "command_assembler/soc.h" -#include "device/tt_cluster_descriptor.h" -namespace CA = CommandAssembler; - -void translate_soc_descriptor_to_ca_soc(CA::Soc& soc, const tt_SocDescriptor soc_descriptor) { - for (auto& core : soc_descriptor.cores) { - CA::SocNocNode node; - CA::xy_pair CA_coord(core.first.x, core.first.y); - node.noc_coord = CA_coord; - node.memory_size = core.second.l1_size; - switch (core.second.type) { - case CoreType::ARC: - node.arc = true; - break; - case CoreType::DRAM: { - node.dram = true; -#ifdef EN_DRAM_ALIAS - node.dram_channel_id = std::get<0>(soc_descriptor.dram_core_channel_map.at(core.first)); -#endif - } break; - case CoreType::ETH: - node.eth = true; - break; - case CoreType::PCIE: - node.pcie = true; - break; - case CoreType::WORKER: - node.worker = true; - break; - case CoreType::HARVESTED: - node.harvested = true; - break; - case CoreType::ROUTER_ONLY: - node.router_only = true; - break; - default: - std::cout << " Error: Unsupported CoreType type: " << static_cast(core.second.type) << std::endl; - break; - } - soc.SetNodeProperties(node.noc_coord, node); - } -} - -//////// -// Device Versim -//////// - -#include - -#include "device.h" -#include "sim_interactive.h" - -tt_VersimDevice::tt_VersimDevice(const std::string& sdesc_path, const std::string& ndesc_path) : tt_device(sdesc_path) { - soc_descriptor_per_chip.emplace(0, tt_SocDescriptor(sdesc_path)); - if (ndesc_path == "") { - cluster_descriptor = tt_ClusterDescriptor::create_mock_cluster({0}); - } else { - cluster_descriptor = tt_ClusterDescriptor::create_from_yaml(ndesc_path); - } -} - -tt_ClusterDescriptor* tt_VersimDevice::get_cluster_description() { return cluster_descriptor.get(); } - -void tt_VersimDevice::start_device(const tt_device_params& device_params) { - bool no_checkers = true; - std::vector dump_cores = device_params.unroll_vcd_dump_cores(get_soc_descriptor(0)->grid_size); - start(device_params.expand_plusargs(), dump_cores, no_checkers, device_params.init_device, false); -} - -void tt_VersimDevice::close_device() { stop(); } - -void tt_VersimDevice::start( - std::vector plusargs, - std::vector dump_cores, - bool no_checkers, - bool /*init_device*/, - bool /*skip_driver_allocs*/ -) { - std::cout << "Start Versim Device " << std::endl; - std::string device_descriptor_dir = "./"; - - std::optional vcd_suffix; - if (dump_cores.size() > 0) { - vcd_suffix = "core_dump.vcd"; - } - - std::vector vcd_cores; - - // TODO: For now create a temporary stuff from CA and populate from descriptor before passing back to versim-core - // interface. mainly bypasses arch_configs etc from llir. We can populate soc directly - // MT: have to preserve ca_soc_descriptor object since versim references it at runtime - CA::xy_pair CA_grid_size( - (soc_descriptor_per_chip.begin()->second).grid_size.x, (soc_descriptor_per_chip.begin()->second).grid_size.y); - // CA::Soc ca_soc_manager(CA_grid_size); - std::unique_ptr p_ca_soc_manager_unique = std::make_unique(CA_grid_size); - translate_soc_descriptor_to_ca_soc(*p_ca_soc_manager_unique, (soc_descriptor_per_chip.begin()->second)); - // TODO: End - - std::cout << "Versim Device: turn_on_device "; - std::vector trisc_sizes = { - static_cast(l1_address_params.trisc0_size), - static_cast(l1_address_params.trisc1_size), - static_cast(l1_address_params.trisc2_size)}; - std::unique_ptr versim_unique = versim::turn_on_device( - CA_grid_size, - *p_ca_soc_manager_unique, - plusargs, - vcd_suffix, - dump_cores, - no_checkers, - l1_address_params.trisc_base, - trisc_sizes); - versim = versim_unique.release(); - - std::cout << "Versim Device: write info to tvm db " << std::endl; - versim::write_info_to_tvm_db(l1_address_params.trisc_base, trisc_sizes); - versim::build_and_connect_tvm_phase(); - - versim->spin_threads(*p_ca_soc_manager_unique, false); - versim::assert_reset(*versim); - - p_ca_soc_manager = (void*)(p_ca_soc_manager_unique.release()); - - std::cout << "Versim Device: Done start " << std::endl; -} - -tt_VersimDevice::~tt_VersimDevice() { cluster_descriptor.reset(); } - -// bool tt_VersimDevice::run() { -// std::cout << "Versim Device: Run " << std::endl; - -// // Run Versim main_loop -// versim::startup_versim_main_loop(*versim); - -// return true; -// } - -void tt_VersimDevice::deassert_risc_reset() { - std::cout << "Versim Device: Deassert risc resets start" << std::endl; - versim::handle_resetting_triscs(*versim); - std::cout << "Versim Device: Start main loop " << std::endl; - versim::startup_versim_main_loop(*versim); -} - -void tt_VersimDevice::deassert_risc_reset_at_core(tt_cxy_pair core, const TensixSoftResetOptions& soft_resets) { - // This function deasserts reset on the full versim device (don't need core level granularity for versim) - deassert_risc_reset(); -} - -void tt_VersimDevice::assert_risc_reset() { - std::cout << "Pause all the cores" << std::endl; - versim::pause(*versim); - - std::cout << "Wait for cores to go to paused state" << std::endl; - versim::sleep_wait_for_paused(*versim); - - std::cout << "Assert riscv reset" << std::endl; - versim::assert_riscv_reset(*versim); -} - -void tt_VersimDevice::assert_risc_reset_at_core(tt_cxy_pair core, const TensixSoftResetOptions& soft_resets) { - // This function asserts reset on the full versim device (don't need core level granularity for versim) - assert_risc_reset(); -} - -void tt_VersimDevice::rolled_write_to_device( - std::vector& vec, uint32_t unroll_count, tt_cxy_pair core, uint64_t addr, const std::string& tlb_to_use) { - uint32_t byte_increment = vec.size() * 4; - for (int i = 0; i < unroll_count; i++) { - vec[0] = i; // slot id for debug - write_to_device(vec, core, addr + i * byte_increment, tlb_to_use); - } -} - -void tt_VersimDevice::rolled_write_to_device( - uint32_t* mem_ptr, - uint32_t len, - uint32_t unroll_count, - tt_cxy_pair core, - uint64_t addr, - const std::string& fallback_tlb) { - std::vector mem_vector(mem_ptr, mem_ptr + len); - rolled_write_to_device(mem_vector, unroll_count, core, addr, fallback_tlb); -} - -void tt_VersimDevice::write_to_device( - std::vector& vec, - tt_cxy_pair core, - uint64_t addr, - const std::string& tlb_to_use, - bool send_epoch_cmd, - bool last_send_epoch_cmd, - bool ordered_with_prev_remote_write) { - log_debug( - tt::LogSiliconDriver, - "Versim Device ({}): Write vector at target core {}, address: {}", - get_sim_time(*versim), - core.str(), - addr); - - bool aligned_32B = (soc_descriptor_per_chip.begin()->second).cores.at(core).type == CoreType::DRAM; - // MT: Remove these completely - CommandAssembler::xy_pair CA_target(core.x, core.y); - CommandAssembler::memory CA_tensor_memory(addr, vec); - - nuapi::device::write_memory_to_core(*versim, CA_target, CA_tensor_memory); -} - -void tt_VersimDevice::write_to_device( - const void* mem_ptr, - uint32_t size, - tt_cxy_pair core, - uint64_t addr, - const std::string& tlb_to_use, - bool send_epoch_cmd, - bool last_send_epoch_cmd, - bool ordered_with_prev_remote_write) { - log_assert(!(size % 4), "Writes to Versim Backend should be 4 byte aligned!"); - - std::vector mem_vector((uint32_t*)mem_ptr, (uint32_t*)mem_ptr + size / sizeof(uint32_t)); - write_to_device( - mem_vector, core, addr, tlb_to_use, send_epoch_cmd, last_send_epoch_cmd, ordered_with_prev_remote_write); -} - -void tt_VersimDevice::broadcast_write_to_cluster( - const void* mem_ptr, - uint32_t size_in_bytes, - uint64_t address, - const std::set& chips_to_exclude, - std::set& rows_to_exclude, - std::set& cols_to_exclude, - const std::string& fallback_tlb) { - for (const auto& core : get_soc_descriptor(0)->cores) { - if (cols_to_exclude.find(core.first.x) == cols_to_exclude.end() and - rows_to_exclude.find(core.first.y) == rows_to_exclude.end() and core.second.type != CoreType::HARVESTED) { - write_to_device(mem_ptr, size_in_bytes, tt_cxy_pair(0, core.first.x, core.first.y), address, ""); - } - } -} - -void tt_VersimDevice::wait_for_non_mmio_flush() { - // Do nothing, since Versim does not simulate non-mmio mapped chips -} - -void tt_VersimDevice::l1_membar( - const chip_id_t chip, const std::string& fallback_tlb, const std::unordered_set& cores) { - tt_driver_atomics::mfence(); // Ensure no reordering of loads/stores around this -} - -void tt_VersimDevice::dram_membar( - const chip_id_t chip, const std::string& fallback_tlb, const std::unordered_set& channels) { - tt_driver_atomics::mfence(); // Ensure no reordering of loads/stores around this -} - -void tt_VersimDevice::dram_membar( - const chip_id_t chip, const std::string& fallback_tlb, const std::unordered_set& dram_cores) { - tt_driver_atomics::mfence(); // Ensure no reordering of loads/stores around this -} - -void tt_VersimDevice::read_from_device( - std::vector& vec, tt_cxy_pair core, uint64_t addr, uint32_t size, const std::string& tlb_to_use) { - log_debug( - tt::LogSiliconDriver, - "Versim Device ({}): Read vector from address: {}, with size: {} Bytes", - get_sim_time(*versim), - addr, - size); - - CommandAssembler::xy_pair CA_target(core.x, core.y); - - size_t size_in_words = size / 4; - auto result = nuapi::device::read_memory_from_core(*versim, CA_target, addr, size_in_words); - vec = result; -} - -void tt_VersimDevice::read_from_device( - void* mem_ptr, tt_cxy_pair core, uint64_t addr, uint32_t size, const std::string& tlb_to_use) { - log_debug( - tt::LogSiliconDriver, - "Versim Device ({}): Read vector from address: {}, with size: {} Bytes", - get_sim_time(*versim), - addr, - size); - log_assert(!(size % 4), "Reads from Versim backend should be 4 byte aligned!"); - - CommandAssembler::xy_pair CA_target(core.x, core.y); - - size_t size_in_words = size / 4; - auto result = nuapi::device::read_memory_from_core(*versim, CA_target, addr, size_in_words); - memcpy(mem_ptr, result.data(), result.size() * sizeof(uint32_t)); -} - -void tt_VersimDevice::translate_to_noc_table_coords(chip_id_t device_id, std::size_t& r, std::size_t& c) { - // No translation is performed - return; -} - -std::set tt_VersimDevice::get_target_mmio_device_ids() { - // Must only be used for silicon - return {}; -} - -std::set tt_VersimDevice::get_target_remote_device_ids() { - // Must only be used for silicon - return {}; -} - -bool versim_check_dram_core_exists( - const std::vector>& dram_core_channels, tt_xy_pair target_core) { - bool dram_core_exists = false; - for (const auto& dram_cores_in_channel : dram_core_channels) { - for (const auto& dram_core : dram_cores_in_channel) { - if (dram_core.x == target_core.x && dram_core.y == target_core.y) { - return true; - } - } - } - return false; -} - -int tt_VersimDevice::get_number_of_chips_in_cluster() { return detect_number_of_chips(); } - -std::unordered_set tt_VersimDevice::get_all_chips_in_cluster() { return {0}; } - -int tt_VersimDevice::detect_number_of_chips() { return 1; } - -bool tt_VersimDevice::using_harvested_soc_descriptors() { return false; } - -bool tt_VersimDevice::noc_translation_en() { return false; } - -std::unordered_map tt_VersimDevice::get_harvesting_masks_for_soc_descriptors() { return {{0, 0}}; } - -// Meant to breakout running functions for simulator -bool tt_VersimDevice::stop() { - std::cout << "Versim Device: Stop " << std::endl; - - versim::turn_off_device(*versim); - versim->shutdown(); - // Force free of all versim cores - for (auto x = 0; x < versim->grid_size.x; x++) { - for (auto y = 0; y < versim->grid_size.y; y++) { - delete versim->core_grid.at(x).at(y); - } - } - std::cout << "Versim Device: Stop completed " << std::endl; - delete versim; - return true; -} - -std::map tt_VersimDevice::get_clocks() { return std::map(); } - -void tt_VersimDevice::set_device_l1_address_params(const tt_device_l1_address_params& l1_address_params_) { - l1_address_params = l1_address_params_; -} - -void tt_VersimDevice::set_device_dram_address_params(const tt_device_dram_address_params& dram_address_params_) { - dram_address_params = dram_address_params_; -} - -std::uint32_t tt_VersimDevice::get_num_dram_channels(std::uint32_t device_id) { - return get_soc_descriptor(device_id)->get_num_dram_channels(); -} - -std::uint64_t tt_VersimDevice::get_dram_channel_size(std::uint32_t 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_VersimDevice::get_num_host_channels(std::uint32_t device_id) { - // Host buffers not allocated for Versim Devices - return 0; -} - -std::uint32_t tt_VersimDevice::get_host_channel_size(std::uint32_t device_id, std::uint32_t channel) { - // Host buffers not allocated for Versim Devices - return 0; -} diff --git a/device/simulation/deprecated/tt_versim_device.h b/device/simulation/deprecated/tt_versim_device.h deleted file mode 100644 index c881b3c4..00000000 --- a/device/simulation/deprecated/tt_versim_device.h +++ /dev/null @@ -1,123 +0,0 @@ -/* - * SPDX-FileCopyrightText: (c) 2023 Tenstorrent Inc. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#pragma once - -#include "cluster.h" -#include "tt_soc_descriptor.h" -#include "tt_xy_pair.h" - -class c_versim_core; - -namespace nuapi { -namespace device { -template -class Simulator; -} -} // namespace nuapi - -namespace versim { -struct VersimSimulatorState; -using VersimSimulator = nuapi::device::Simulator; -} // namespace versim - -/** - * @brief Versim Backend Class, derived from the tt_device class - * Implements APIs to communicate with a simulated (using Verilator) Tenstorrent Device. - */ -class tt_VersimDevice : public tt_device { -public: - virtual void set_device_l1_address_params(const tt_device_l1_address_params& l1_address_params_); - virtual void set_device_dram_address_params(const tt_device_dram_address_params& dram_address_params_); - tt_VersimDevice(const std::string& sdesc_path, const std::string& ndesc_path); - virtual void start( - std::vector plusargs, - std::vector dump_cores, - bool no_checkers, - bool init_device, - bool skip_driver_allocs); - virtual void start_device(const tt_device_params& device_params); - virtual void close_device(); - virtual void deassert_risc_reset(); - virtual void deassert_risc_reset_at_core( - tt_cxy_pair core, const TensixSoftResetOptions& soft_resets = TENSIX_DEASSERT_SOFT_RESET); - virtual void assert_risc_reset(); - virtual void assert_risc_reset_at_core( - tt_cxy_pair core, const TensixSoftResetOptions& soft_resets = TENSIX_ASSERT_SOFT_RESET); - virtual void write_to_device( - std::vector& vec, - tt_cxy_pair core, - uint64_t addr, - const std::string& tlb_to_use, - bool send_epoch_cmd = false, - bool last_send_epoch_cmd = true, - bool ordered_with_prev_remote_write = false); - virtual void broadcast_write_to_cluster( - const void* mem_ptr, - uint32_t size_in_bytes, - uint64_t address, - const std::set& chips_to_exclude, - std::set& rows_to_exclude, - std::set& columns_to_exclude, - const std::string& fallback_tlb); - virtual void rolled_write_to_device( - std::vector& vec, - uint32_t unroll_count, - tt_cxy_pair core, - uint64_t addr, - const std::string& tlb_to_use); - virtual void read_from_device( - std::vector& vec, tt_cxy_pair core, uint64_t addr, uint32_t size, const std::string& tlb_to_use); - virtual void rolled_write_to_device( - uint32_t* mem_ptr, - uint32_t size_in_bytes, - uint32_t unroll_count, - tt_cxy_pair core, - uint64_t addr, - const std::string& fallback_tlb); - virtual void write_to_device( - const void* mem_ptr, - uint32_t size_in_bytes, - tt_cxy_pair core, - uint64_t addr, - const std::string& tlb_to_use, - bool send_epoch_cmd = false, - bool last_send_epoch_cmd = true, - bool ordered_with_prev_remote_write = false); - virtual void read_from_device( - void* mem_ptr, tt_cxy_pair core, uint64_t addr, uint32_t size, const std::string& tlb_to_use); - virtual void wait_for_non_mmio_flush(); - void l1_membar( - const chip_id_t chip, const std::string& fallback_tlb, const std::unordered_set& cores = {}); - void dram_membar( - const chip_id_t chip, const std::string& fallback_tlb, const std::unordered_set& channels); - void dram_membar( - const chip_id_t chip, const std::string& fallback_tlb, const std::unordered_set& cores = {}); - virtual void translate_to_noc_table_coords(chip_id_t device_id, std::size_t& r, std::size_t& c); - virtual bool using_harvested_soc_descriptors(); - virtual std::unordered_map get_harvesting_masks_for_soc_descriptors(); - virtual bool noc_translation_en(); - virtual std::set get_target_mmio_device_ids(); - virtual std::set get_target_remote_device_ids(); - virtual ~tt_VersimDevice(); - virtual tt_ClusterDescriptor* get_cluster_description(); - virtual int get_number_of_chips_in_cluster(); - virtual std::unordered_set get_all_chips_in_cluster(); - static int detect_number_of_chips(); - virtual std::map get_clocks(); - 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); - -private: - bool stop(); - tt_device_l1_address_params l1_address_params; - tt_device_dram_address_params dram_address_params; - versim::VersimSimulator* versim; - std::shared_ptr cluster_descriptor; - void* p_ca_soc_manager; -}; diff --git a/device/simulation/deprecated/tt_versim_stub.cpp b/device/simulation/deprecated/tt_versim_stub.cpp deleted file mode 100644 index f682732c..00000000 --- a/device/simulation/deprecated/tt_versim_stub.cpp +++ /dev/null @@ -1,138 +0,0 @@ -// SPDX-FileCopyrightText: (c) 2023 Tenstorrent Inc. -// -// SPDX-License-Identifier: Apache-2.0 - -#include -#include -#include -#include - -#include "cluster.h" - -tt_VersimDevice::tt_VersimDevice(const std::string& sdesc_path, const std::string& ndesc_path) : tt_device(sdesc_path) { - throw std::runtime_error("tt_VersimDevice() -- VERSIM is not supported in this build\n"); -} - -tt_VersimDevice::~tt_VersimDevice() {} - -int tt_VersimDevice::get_number_of_chips_in_cluster() { return detect_number_of_chips(); } - -std::unordered_set tt_VersimDevice::get_all_chips_in_cluster() { return {}; } - -int tt_VersimDevice::detect_number_of_chips() { return 0; } - -void tt_VersimDevice::start_device(const tt_device_params& device_params) {} - -void tt_VersimDevice::close_device() {} - -void tt_VersimDevice::write_to_device( - std::vector& vec, - tt_cxy_pair core, - uint64_t addr, - const std::string& tlb_to_use, - bool send_epoch_cmd, - bool last_send_epoch_cmd, - bool ordered_with_prev_remote_write) {} - -void tt_VersimDevice::broadcast_write_to_cluster( - const void* mem_ptr, - uint32_t size_in_bytes, - uint64_t address, - const std::set& chips_to_exclude, - std::set& rows_to_exclude, - std::set& cols_to_exclude, - const std::string& fallback_tlb) {} - -void tt_VersimDevice::read_from_device( - std::vector& vec, tt_cxy_pair core, uint64_t addr, uint32_t size, const std::string& tlb_to_use) {} - -void tt_VersimDevice::rolled_write_to_device( - std::vector& vec, uint32_t unroll_count, tt_cxy_pair core, uint64_t addr, const std::string& tlb_to_use) { -} - -void tt_VersimDevice::write_to_device( - const void* mem_ptr, - uint32_t len, - tt_cxy_pair core, - uint64_t addr, - const std::string& tlb_to_use, - bool send_epoch_cmd, - bool last_send_epoch_cmd, - bool ordered_with_prev_remote_write) {} - -void tt_VersimDevice::read_from_device( - void* mem_ptr, tt_cxy_pair core, uint64_t addr, uint32_t size, const std::string& tlb_to_use) {} - -void tt_VersimDevice::rolled_write_to_device( - uint32_t* mem_ptr, - uint32_t len, - uint32_t unroll_count, - tt_cxy_pair core, - uint64_t addr, - const std::string& fallback_tlb) {} - -void tt_VersimDevice::wait_for_non_mmio_flush() {} - -void tt_VersimDevice::l1_membar( - const chip_id_t chip, const std::string& fallback_tlb, const std::unordered_set& cores) {} - -void tt_VersimDevice::dram_membar( - const chip_id_t chip, const std::string& fallback_tlb, const std::unordered_set& channels) {} - -void tt_VersimDevice::dram_membar( - const chip_id_t chip, const std::string& fallback_tlb, const std::unordered_set& dram_cores) {} - -void tt_VersimDevice::start( - std::vector plusargs, - std::vector dump_cores, - bool no_checkers, - bool /*init_device*/, - bool /*skip_driver_allocs*/ -) {} - -void tt_VersimDevice::deassert_risc_reset() {} - -void tt_VersimDevice::deassert_risc_reset_at_core(tt_cxy_pair core, const TensixSoftResetOptions& soft_resets) {} - -void tt_VersimDevice::assert_risc_reset() {} - -void tt_VersimDevice::assert_risc_reset_at_core(tt_cxy_pair core, const TensixSoftResetOptions& soft_resets) {} - -void tt_VersimDevice::translate_to_noc_table_coords(chip_id_t device_id, std::size_t& r, std::size_t& c){}; - -// void tt_VersimDevice::dump_wall_clock_mailbox(std::string output_path, int device_id) {} - -std::set tt_VersimDevice::get_target_mmio_device_ids() { return {}; } - -std::set tt_VersimDevice::get_target_remote_device_ids() { return {}; } - -bool versim_check_dram_core_exists( - const std::vector>& dram_core_channels, tt_xy_pair target_core) { - return false; -} - -bool tt_VersimDevice::using_harvested_soc_descriptors() { return false; } - -bool tt_VersimDevice::noc_translation_en() { return false; } - -std::unordered_map tt_VersimDevice::get_harvesting_masks_for_soc_descriptors() { - return std::unordered_map(); -} - -bool tt_VersimDevice::stop() { return true; } - -void tt_VersimDevice::set_device_l1_address_params(const tt_device_l1_address_params& l1_address_params_) {} - -void tt_VersimDevice::set_device_dram_address_params(const tt_device_dram_address_params& dram_address_params_) {} - -std::uint32_t tt_VersimDevice::get_num_dram_channels(std::uint32_t device_id) { return 0; } - -std::uint64_t tt_VersimDevice::get_dram_channel_size(std::uint32_t device_id, std::uint32_t channel) { return 0; } - -std::uint32_t tt_VersimDevice::get_num_host_channels(std::uint32_t device_id) { return 0; } - -std::uint32_t tt_VersimDevice::get_host_channel_size(std::uint32_t device_id, std::uint32_t channel) { return 0; } - -std::map tt_VersimDevice::get_clocks() { return std::map(); } - -tt_ClusterDescriptor* tt_VersimDevice::get_cluster_description() { return cluster_descriptor.get(); }