Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#18058: Move init_sync_registers to TRISC0 #18393

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tt_metal/api/tt-metalium/dev_msgs.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ constexpr uint32_t RUN_SYNC_MSG_GO = 0x80;
// Trigger loading CBs (and IRAM) before actually running the kernel.
constexpr uint32_t RUN_SYNC_MSG_LOAD = 0x1;
constexpr uint32_t RUN_SYNC_MSG_WAITING_FOR_RESET = 0x2;
constexpr uint32_t RUN_SYNC_MSG_INIT_SYNC_REGISTERS = 0x3;
constexpr uint32_t RUN_SYNC_MSG_DONE = 0;
constexpr uint32_t RUN_SYNC_MSG_ALL_GO = 0x80808080;
constexpr uint32_t RUN_SYNC_MSG_ALL_SLAVES_DONE = 0;
Expand Down
22 changes: 10 additions & 12 deletions tt_metal/hw/firmware/src/brisc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -269,17 +269,6 @@ void device_setup() {
// core.ex_sem_init(semaphore::CFG_STATE_BUSY, MAX_CONFIG_STATES, 0, instrn_buf[0]);
}

void init_sync_registers() {
volatile tt_reg_ptr uint* tiles_received_ptr;
volatile tt_reg_ptr uint* tiles_acked_ptr;
for (uint32_t operand = 0; operand < NUM_CIRCULAR_BUFFERS; operand++) {
tiles_received_ptr = get_cb_tiles_received_ptr(operand);
tiles_received_ptr[0] = 0;
tiles_acked_ptr = get_cb_tiles_acked_ptr(operand);
tiles_acked_ptr[0] = 0;
}
}

inline void init_ncrisc_iram() {
#if NCRISC_FIRMWARE_IN_IRAM
uint16_t fw_size16 = mailboxes->launch[mailboxes->launch_msg_rd_ptr].kernel_config.ncrisc_kernel_size16;
Expand Down Expand Up @@ -326,6 +315,11 @@ inline void set_ncrisc_kernel_resume_deassert_address() {
}

inline void run_triscs(dispatch_core_processor_masks enables) {
// Wait for init_sync_registers to complete. Should always be done by the time we get here.
while (mailboxes->slave_sync.trisc0 != RUN_SYNC_MSG_DONE) {
invalidate_l1_cache();
}

if (enables & DISPATCH_CLASS_MASK_TENSIX_ENABLE_COMPUTE) {
mailboxes->slave_sync.trisc0 = RUN_SYNC_MSG_GO;
mailboxes->slave_sync.trisc1 = RUN_SYNC_MSG_GO;
Expand Down Expand Up @@ -371,6 +365,8 @@ inline void wait_ncrisc_trisc() {
WAYPOINT("NTD");
}

inline void trigger_sync_register_init() { mailboxes->slave_sync.trisc0 = RUN_SYNC_MSG_INIT_SYNC_REGISTERS; }

int main() {
configure_l1_data_cache();
DIRTY_STACK_MEMORY();
Expand Down Expand Up @@ -405,6 +401,7 @@ int main() {
noc_init(MEM_NOC_ATOMIC_RET_VAL_ADDR);
noc_local_state_init(noc_index);
uint8_t prev_noc_mode = DM_DEDICATED_NOC;
trigger_sync_register_init();


#if defined(ARCH_BLACKHOLE)
Expand All @@ -416,7 +413,6 @@ int main() {
#endif

while (1) {
init_sync_registers();
reset_ncrisc_with_iram();

WAYPOINT("GW");
Expand Down Expand Up @@ -550,6 +546,8 @@ int main() {

wait_ncrisc_trisc();

trigger_sync_register_init();

if (noc_mode == DM_DYNAMIC_NOC) {
// barrier to make sure all writes are finished
while (!ncrisc_dynamic_noc_nonposted_writes_flushed<proc_type>(noc_index));
Expand Down
18 changes: 18 additions & 0 deletions tt_metal/hw/firmware/src/trisc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "circular_buffer.h"
#include "circular_buffer_init.h"
#endif
#include "circular_buffer_constants.h"
// clang-format on

#if defined(PROFILE_KERNEL)
Expand Down Expand Up @@ -75,6 +76,17 @@ constexpr bool cb_init_write = false;

using namespace ckernel;

void init_sync_registers() {
volatile tt_reg_ptr uint* tiles_received_ptr;
volatile tt_reg_ptr uint* tiles_acked_ptr;
for (uint32_t operand = 0; operand < NUM_CIRCULAR_BUFFERS; operand++) {
tiles_received_ptr = get_cb_tiles_received_ptr(operand);
tiles_received_ptr[0] = 0;
tiles_acked_ptr = get_cb_tiles_acked_ptr(operand);
tiles_acked_ptr[0] = 0;
}
}

int main(int argc, char *argv[]) {
configure_l1_data_cache();
DIRTY_STACK_MEMORY();
Expand All @@ -92,6 +104,12 @@ int main(int argc, char *argv[]) {
while (1) {
WAYPOINT("W");
while (*trisc_run != RUN_SYNC_MSG_GO) {
if constexpr (COMPILE_FOR_TRISC == 0) {
if (*trisc_run == RUN_SYNC_MSG_INIT_SYNC_REGISTERS) {
init_sync_registers();
*trisc_run = RUN_SYNC_MSG_DONE;
}
}
invalidate_l1_cache();
}
DeviceZoneScopedMainN("TRISC-FW");
Expand Down
2 changes: 2 additions & 0 deletions tt_metal/impl/debug/watcher_device_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,8 @@ void WatcherDeviceReader::DumpRunState(CoreDescriptor& core, const launch_msg_t*
code = 'L';
} else if (state == RUN_SYNC_MSG_WAITING_FOR_RESET) {
code = 'W';
} else if (state == RUN_SYNC_MSG_INIT_SYNC_REGISTERS) {
code = 'S';
}
if (code == 'U') {
LogRunningKernels(core, launch_msg);
Expand Down
Loading