Skip to content

Commit

Permalink
Versim setup and VCS fixes (#180)
Browse files Browse the repository at this point in the history
Changes for Versim setup:
- modify `tt_SimulationDevice` start and close device
- update the flatbuffer used to communicate with the backend

Changes for VCS fixes:
- forgot to modify `write_to_device` signature when I did my initial UMD
cleanup
- revert `test_simulation_device` to not use
`test::utils::read_from_device` since it's using simulation not silicon
device
  • Loading branch information
vtangTT authored and mbezuljTT committed Nov 1, 2024
1 parent d567e50 commit ff87f03
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 39 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ add_subdirectory(<path to umd>)
apt install ./umd-dev-x.y.z-Linux.deb
```

## Simulator Integration
You can run UMD tests without silicon by following setup instructions [here](https://yyz-gitlab.local.tenstorrent.com/tenstorrent/tt-metal).

For UMD, sample tests can be found in `tests/simulation/test_simulation_device.cpp`

# Pre-commit Hook Integration for Formatting and Linting

As part of maintaining consistent code formatting across the project, we have integrated the [pre-commit](https://pre-commit.com/) framework into our workflow. The pre-commit hooks will help automatically check and format code before commits are made, ensuring that we adhere to the project's coding standards.
Expand Down
16 changes: 5 additions & 11 deletions device/simulation/tt_simulation_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +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);
host.send_to_device(builder.GetBufferPointer(), builder.GetSize());
close_device();
}

// Setup/Teardown Functions
Expand Down Expand Up @@ -114,11 +112,13 @@ void tt_SimulationDevice::assert_risc_reset_at_core(tt_cxy_pair core) {

void tt_SimulationDevice::close_device() {
// disconnect from remote connection
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);
host.send_to_device(builder.GetBufferPointer(), builder.GetSize());
}

// Runtime Functions
void tt_SimulationDevice::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_SimulationDevice::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) {
log_info(tt::LogEmulationDriver, "Device writing");
std::vector<std::uint32_t> data((uint32_t*)mem_ptr, (uint32_t*)mem_ptr + size_in_bytes / sizeof(uint32_t));
auto wr_buffer = create_flatbuffer(DEVICE_COMMAND_WRITE, data, core, addr);
Expand Down Expand Up @@ -148,12 +148,6 @@ void tt_SimulationDevice::read_from_device(void* mem_ptr, tt_cxy_pair core, uint
nng_free(rd_resp, rd_rsp_sz);
}

// For fd cqs
void tt_SimulationDevice::write_to_sysmem(std::vector<uint32_t>& vec, uint64_t addr, uint16_t channel, chip_id_t src_device_id) {}
void tt_SimulationDevice::write_to_sysmem(const void* mem_ptr, std::uint32_t size, uint64_t addr, uint16_t channel, chip_id_t src_device_id) {}
void tt_SimulationDevice::read_from_sysmem(std::vector<uint32_t> &vec, uint64_t addr, uint16_t channel, uint32_t size, chip_id_t src_device_id) {}
void tt_SimulationDevice::read_from_sysmem(void* mem_ptr, uint64_t addr, uint16_t channel, uint32_t size, chip_id_t src_device_id) {}

void tt_SimulationDevice::wait_for_non_mmio_flush() {}
void tt_SimulationDevice::wait_for_non_mmio_flush(const chip_id_t chip) {}
void tt_SimulationDevice::l1_membar(const chip_id_t chip, const std::string& fallback_tlb, const std::unordered_set<tt_xy_pair>& cores) {}
Expand Down
11 changes: 5 additions & 6 deletions device/simulation/tt_simulation_device.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
enum DEVICE_COMMAND : byte {
WRITE = 0,
READ = 1,
WRITE_SYSMEM = 2,
READ_SYSMEM = 3,
ALL_TENSIX_RESET_DEASSERT = 4,
ALL_TENSIX_RESET_ASSERT = 5,
EXIT = 6,
ALL_TENSIX_RESET_DEASSERT = 2,
ALL_TENSIX_RESET_ASSERT = 3,
START = 4,
EXIT = 5,
}

struct tt_vcs_core {
Expand All @@ -23,4 +22,4 @@ table DeviceRequestResponse {
size : uint32;
}

root_type DeviceRequestResponse;
root_type DeviceRequestResponse;
9 changes: 2 additions & 7 deletions device/simulation/tt_simulation_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,15 @@ class tt_SimulationDevice: public tt_device {
virtual void close_device();

// Runtime Functions
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 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);
virtual void read_from_device(void* mem_ptr, tt_cxy_pair core, uint64_t addr, uint32_t size, const std::string& fallback_tlb);
virtual void write_to_sysmem(std::vector<uint32_t>& vec, uint64_t addr, uint16_t channel, chip_id_t src_device_id);
virtual void write_to_sysmem(const void* mem_ptr, std::uint32_t size, uint64_t addr, uint16_t channel, chip_id_t src_device_id);
virtual void read_from_sysmem(std::vector<uint32_t> &vec, uint64_t addr, uint16_t channel, uint32_t size, chip_id_t src_device_id);
virtual void read_from_sysmem(void* mem_ptr, uint64_t addr, uint16_t channel, uint32_t size, chip_id_t src_device_id);


virtual void wait_for_non_mmio_flush();
virtual void wait_for_non_mmio_flush(const chip_id_t chip);
void l1_membar(const chip_id_t chip, const std::string& fallback_tlb, const std::unordered_set<tt_xy_pair>& cores = {});
void dram_membar(const chip_id_t chip, const std::string& fallback_tlb, const std::unordered_set<uint32_t>& channels);
void dram_membar(const chip_id_t chip, const std::string& fallback_tlb, const std::unordered_set<tt_xy_pair>& cores = {});


// Misc. Functions to Query/Set Device State
// virtual bool using_harvested_soc_descriptors();
virtual std::unordered_map<chip_id_t, uint32_t> get_harvesting_masks_for_soc_descriptors();
Expand Down
19 changes: 8 additions & 11 deletions device/simulation/tt_simulation_device_generated.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,36 +21,33 @@ struct DeviceRequestResponseBuilder;
enum DEVICE_COMMAND : int8_t {
DEVICE_COMMAND_WRITE = 0,
DEVICE_COMMAND_READ = 1,
DEVICE_COMMAND_WRITE_SYSMEM = 2,
DEVICE_COMMAND_READ_SYSMEM = 3,
DEVICE_COMMAND_ALL_TENSIX_RESET_DEASSERT = 4,
DEVICE_COMMAND_ALL_TENSIX_RESET_ASSERT = 5,
DEVICE_COMMAND_EXIT = 6,
DEVICE_COMMAND_ALL_TENSIX_RESET_DEASSERT = 2,
DEVICE_COMMAND_ALL_TENSIX_RESET_ASSERT = 3,
DEVICE_COMMAND_START = 4,
DEVICE_COMMAND_EXIT = 5,
DEVICE_COMMAND_MIN = DEVICE_COMMAND_WRITE,
DEVICE_COMMAND_MAX = DEVICE_COMMAND_EXIT
};

inline const DEVICE_COMMAND (&EnumValuesDEVICE_COMMAND())[7] {
inline const DEVICE_COMMAND (&EnumValuesDEVICE_COMMAND())[6] {
static const DEVICE_COMMAND values[] = {
DEVICE_COMMAND_WRITE,
DEVICE_COMMAND_READ,
DEVICE_COMMAND_WRITE_SYSMEM,
DEVICE_COMMAND_READ_SYSMEM,
DEVICE_COMMAND_ALL_TENSIX_RESET_DEASSERT,
DEVICE_COMMAND_ALL_TENSIX_RESET_ASSERT,
DEVICE_COMMAND_START,
DEVICE_COMMAND_EXIT
};
return values;
}

inline const char * const *EnumNamesDEVICE_COMMAND() {
static const char * const names[8] = {
static const char * const names[7] = {
"WRITE",
"READ",
"WRITE_SYSMEM",
"READ_SYSMEM",
"ALL_TENSIX_RESET_DEASSERT",
"ALL_TENSIX_RESET_ASSERT",
"START",
"EXIT",
nullptr
};
Expand Down
8 changes: 4 additions & 4 deletions tests/simulation/test_simulation_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ TEST_P(LoopbackAllCoresParam, LoopbackSingleTensix){
tt_cxy_pair core = {0, GetParam()};

device->write_to_device(wdata.data(), wdata.size()*sizeof(uint32_t), core, 0x100, "");
test_utils::read_data_from_device(*device, rdata, core, 0x100, wdata.size()*sizeof(uint32_t), "");
device->read_from_device(rdata.data(), core, 0x100, rdata.size()*sizeof(uint32_t), "");

ASSERT_EQ(wdata, rdata);
}
Expand All @@ -50,7 +50,7 @@ bool loopback_stress_size(std::unique_ptr<tt_SimulationDevice> &device, tt_xy_pa
std::vector<uint32_t> rdata(wdata.size(), 0);

device->write_to_device(wdata.data(), wdata.size()*sizeof(uint32_t), tt_cxy_pair{0, core}, addr, "");
test_utils::read_data_from_device(*device, rdata, tt_cxy_pair{0, core}, addr, wdata.size()*sizeof(uint32_t), "");
device->read_from_device(rdata.data(), tt_cxy_pair{0, core}, addr, rdata.size()*sizeof(uint32_t), "");

return wdata == rdata;
}
Expand Down Expand Up @@ -80,8 +80,8 @@ TEST_F(SimulationDeviceFixture, LoopbackTwoTensix){
device->write_to_device(wdata1.data(), wdata1.size()*sizeof(uint32_t), core1, 0x100, "");
device->write_to_device(wdata2.data(), wdata2.size()*sizeof(uint32_t), core2, 0x100, "");

test_utils::read_data_from_device(*device, rdata1, core1, 0x100, wdata1.size()*sizeof(uint32_t), "");
test_utils::read_data_from_device(*device, rdata2, core2, 0x100, wdata2.size()*sizeof(uint32_t), "");
device->read_from_device(rdata1.data(), core1, 0x100, rdata1.size()*sizeof(uint32_t), "");
device->read_from_device(rdata2.data(), core2, 0x100, rdata2.size()*sizeof(uint32_t), "");

ASSERT_EQ(wdata1, rdata1);
ASSERT_EQ(wdata2, rdata2);
Expand Down

0 comments on commit ff87f03

Please sign in to comment.