Skip to content

Commit

Permalink
#17307: Move ncrisc copy into ncrisc firmware
Browse files Browse the repository at this point in the history
By moving the NCRISC kernel copy into the NCRISC firmware (on wormhole) we can do it in parallel with setting up CBs.
  • Loading branch information
jbaumanTT committed Feb 10, 2025
1 parent 11adf58 commit ee37db8
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
6 changes: 3 additions & 3 deletions tt_metal/hw/firmware/src/brisc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ constexpr uint32_t RISCV_IC_TRISC_ALL_MASK = RISCV_IC_TRISC0_MASK | RISCV_IC_TRI

#define NCRISC_FIRMWARE_IN_IRAM (defined(ARCH_GRAYSKULL))

#ifdef NCRISC_HAS_IRAM
#if NCRISC_FIRMWARE_IN_IRAM
constexpr uint32_t num_cbs_to_early_init = 4; // safe small number to overlap w/ ncrisc copy
#else
constexpr uint32_t num_cbs_to_early_init = 0;
Expand Down Expand Up @@ -183,7 +183,7 @@ void set_deassert_addresses() {
}

void l1_to_ncrisc_iram_copy(uint32_t src_addr, uint16_t size, uint32_t address_offset = 0) {
#ifdef NCRISC_HAS_IRAM
#if NCRISC_FIRMWARE_IN_IRAM
// Always copy ncrisc even if its size is 0 (save branch)...
// Copy NCRISC firmware from L1 to local IRAM using tensix DMA
tdma_xmov(
Expand All @@ -196,7 +196,7 @@ void l1_to_ncrisc_iram_copy(uint32_t src_addr, uint16_t size, uint32_t address_o
}

void l1_to_ncrisc_iram_copy_wait() {
#ifdef NCRISC_HAS_IRAM
#if NCRISC_FIRMWARE_IN_IRAM
// Wait for DMA to finish
wait_tdma_movers_done(RISCV_TDMA_STATUS_FLAG_MOVER0_BUSY_MASK);
#endif
Expand Down
26 changes: 25 additions & 1 deletion tt_metal/hw/firmware/src/ncrisc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "risc_attribs.h"
#include "circular_buffer.h"
#include "circular_buffer_init.h"
#include "tdma_xmov.h"

#include "debug/waypoint.h"
#include "debug/dprint.h"
Expand Down Expand Up @@ -84,6 +85,20 @@ inline __attribute__((always_inline)) void signal_ncrisc_completion() {
#endif
}

#if defined(ARCH_WORMHOLE)
#define MEM_MOVER_VIEW_IRAM_BASE_ADDR (0x4 << 12)
void l1_to_ncrisc_iram_copy(uint32_t src_addr, uint16_t size, uint32_t address_offset = 0) {
// Always copy ncrisc even if its size is 0 (save branch)...
// Copy NCRISC firmware from L1 to local IRAM using tensix DMA
tdma_xmov(TDMA_MOVER0, src_addr, MEM_MOVER_VIEW_IRAM_BASE_ADDR + address_offset, size, XMOV_L1_TO_L0);
}

void l1_to_ncrisc_iram_copy_wait() {
// Wait for DMA to finish
wait_tdma_movers_done(RISCV_TDMA_STATUS_FLAG_MOVER0_BUSY_MASK);
}
#endif

int main(int argc, char *argv[]) {
configure_l1_data_cache();
DIRTY_STACK_MEMORY();
Expand All @@ -109,17 +124,26 @@ int main(int argc, char *argv[]) {
launch_msg_t* launch_msg = &(mailboxes->launch[launch_msg_rd_ptr]);

uint32_t kernel_config_base = firmware_config_init(mailboxes, ProgrammableCoreType::TENSIX, DISPATCH_CLASS_TENSIX_DM1);
int index = static_cast<std::underlying_type<TensixProcessorTypes>::type>(TensixProcessorTypes::DM1);

#if defined(ARCH_WORMHOLE)
uint32_t ncrisc_kernel_src_address = kernel_config_base + launch_msg->kernel_config.kernel_text_offset[index];
l1_to_ncrisc_iram_copy(ncrisc_kernel_src_address >> 4, launch_msg->kernel_config.ncrisc_kernel_size16, 0);
#endif
uint32_t tt_l1_ptr* cb_l1_base =
(uint32_t tt_l1_ptr*)(kernel_config_base + launch_msg->kernel_config.local_cb_offset);
uint32_t end_cb_index = launch_msg->kernel_config.max_local_cb_end_index;
setup_local_cb_read_write_interfaces(cb_l1_base, 0, end_cb_index, true, true, false);

#if defined(ARCH_WORMHOLE)
l1_to_ncrisc_iram_copy_wait();
#endif

cb_l1_base = (uint32_t tt_l1_ptr*)(kernel_config_base + launch_msg->kernel_config.remote_cb_offset);
end_cb_index = launch_msg->kernel_config.min_remote_cb_start_index;
experimental::setup_remote_cb_interfaces(cb_l1_base, end_cb_index);
WAYPOINT("R");

int index = static_cast<std::underlying_type<TensixProcessorTypes>::type>(TensixProcessorTypes::DM1);
void (*kernel_address)(uint32_t) = (void (*)(uint32_t))
(kernel_config_base + launch_msg->kernel_config.kernel_text_offset[index]);
#ifdef ARCH_BLACKHOLE
Expand Down
7 changes: 3 additions & 4 deletions tt_metal/jit_build/build.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,18 +219,17 @@ void JitBuildState::finish_init() {
std::string build_dir =
llrt::RunTimeOptions::get_instance().get_root_dir() + "runtime/hw/lib/" + get_alias(env_.arch_) + "/";
if (this->is_fw_) {
if (this->target_name_ == "brisc") {
if (this->target_name_ == "brisc" and this->env_.arch_ == tt::ARCH::GRAYSKULL) {
this->link_objs_ += build_dir + "tdma_xmov.o ";
}
if (this->target_name_ != "erisc") {
this->link_objs_ += build_dir + "tmu-crt0.o ";
}
if (this->target_name_ == "ncrisc" and
((this->env_.arch_ == tt::ARCH::GRAYSKULL or this->env_.arch_ == tt::ARCH::WORMHOLE_B0))) {
if (this->target_name_ == "ncrisc" and this->env_.arch_ == tt::ARCH::GRAYSKULL) {
this->link_objs_ += build_dir + "ncrisc-halt.o ";
}
if (this->target_name_ == "ncrisc" and this->env_.arch_ == tt::ARCH::WORMHOLE_B0) {
this->link_objs_ += build_dir + "ncrisc-halt-wormhole.o ";
this->link_objs_ += build_dir + "ncrisc-halt-wormhole.o tdma_xmov.o ";
}
} else {
if (this->target_name_ == "ncrisc" and this->env_.arch_ == tt::ARCH::WORMHOLE_B0) {
Expand Down

0 comments on commit ee37db8

Please sign in to comment.