Skip to content

Commit

Permalink
#0: Preload kernel before starting
Browse files Browse the repository at this point in the history
  • Loading branch information
jbaumanTT committed Nov 13, 2024
1 parent a28571f commit 87bd9a2
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 6 deletions.
3 changes: 2 additions & 1 deletion tt_metal/hostdevcommon/dprint_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
#if !defined(KERNEL_BUILD) && !defined(FW_BUILD) // SW
#include "common/tt_backend_api_types.hpp"
typedef tt::DataFormat CommonDataFormat;
#else // HW already includes tensix_types.h
#else
#include "tensix_types.h"
typedef DataFormat CommonDataFormat;
#endif

Expand Down
3 changes: 2 additions & 1 deletion tt_metal/hw/firmware/src/brisc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,8 @@ int main() {

WAYPOINT("GW");
uint8_t go_message_signal = RUN_MSG_DONE;
while ((go_message_signal = mailboxes->go_message.signal) != RUN_MSG_GO) {
while (((go_message_signal = mailboxes->go_message.signal) != RUN_MSG_GO) &&
!(mailboxes->launch[mailboxes->launch_msg_rd_ptr].kernel_config.enables & DISPATCH_ENABLE_FLAG_PRELOAD)) {
// While the go signal for kernel execution is not sent, check if the worker was signalled
// to reset its launch message read pointer.
if (go_message_signal == RUN_MSG_RESET_READ_PTR) {
Expand Down
5 changes: 5 additions & 0 deletions tt_metal/hw/firmware/src/brisck.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ extern uint32_t __kernel_init_local_l1_base[];
extern uint32_t __fw_export_end_text[];

void kernel_launch(uint32_t kernel_base_addr) {
uint8_t go_message_signal;
tt_l1_ptr mailboxes_t *const mailboxes = (tt_l1_ptr mailboxes_t *)(MEM_MAILBOX_BASE);

while ((go_message_signal = mailboxes->go_message.signal) != RUN_MSG_GO) {
}

#if defined(DEBUG_NULL_KERNELS) && !defined(DISPATCH_KERNEL)
#ifdef KERNEL_RUN_TIME
Expand Down
15 changes: 11 additions & 4 deletions tt_metal/hw/firmware/src/ncrisck.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
//
// SPDX-License-Identifier: Apache-2.0

#include "risc_common.h"
#include "tensix.h"
#include "tensix_types.h"
#include <cstdint>

#include "noc.h"
#include "noc_overlay_parameters.h"
#include "noc_nonblocking_api.h"
#include "noc_overlay_parameters.h"
#include "risc_attribs.h"
#include "risc_common.h"
#include "stream_io_map.h"
#include "tensix.h"
#include "tensix_types.h"
#ifdef PERF_DUMP
#include "risc_perf.h"
#endif
Expand All @@ -30,7 +33,11 @@ extern uint32_t __kernel_init_local_l1_base[];
extern uint32_t __fw_export_end_text[];

void kernel_launch(uint32_t kernel_base_addr) {
uint8_t go_message_signal;
tt_l1_ptr mailboxes_t *const mailboxes = (tt_l1_ptr mailboxes_t *)(MEM_MAILBOX_BASE);

while ((go_message_signal = mailboxes->go_message.signal) != RUN_MSG_GO) {
}
DeviceZoneScopedMainChildN("NCRISC-KERNEL");
#if defined(DEBUG_NULL_KERNELS) && !defined(DISPATCH_KERNEL)
#ifdef KERNEL_RUN_TIME
Expand Down
5 changes: 5 additions & 0 deletions tt_metal/hw/firmware/src/trisck.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ extern uint32_t __fw_export_end_text[];

void kernel_launch(uint32_t kernel_base_addr)
{
uint8_t go_message_signal;
tt_l1_ptr mailboxes_t *const mailboxes = (tt_l1_ptr mailboxes_t *)(MEM_MAILBOX_BASE);

while ((go_message_signal = mailboxes->go_message.signal) != RUN_MSG_GO) {
}
DeviceZoneScopedMainChildN("TRISC-KERNEL");
#if defined(DEBUG_NULL_KERNELS) && !defined(DISPATCH_KERNEL)
#ifdef KERNEL_RUN_TIME
Expand Down
5 changes: 5 additions & 0 deletions tt_metal/hw/inc/dev_msgs.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ struct rta_offset_t {
volatile uint16_t crta_offset;
};

enum dispatchenable_flags {
DISPATCH_ENABLE_FLAG_PRELOAD = 1 << 7,
};

struct kernel_config_msg_t {
volatile uint16_t watcher_kernel_ids[DISPATCH_CLASS_MAX];
volatile uint16_t ncrisc_kernel_size16; // size in 16 byte units
Expand All @@ -107,6 +111,7 @@ struct kernel_config_msg_t {
volatile uint8_t brisc_noc_mode;
volatile uint8_t max_cb_index;
volatile uint8_t exit_erisc_kernel;
// Or of enable_flags and dispatch_core_processor_masks.
volatile uint8_t enables;
volatile uint8_t pad2[12];
} __attribute__((packed));
Expand Down
1 change: 1 addition & 0 deletions tt_metal/hw/inc/grayskull/noc_nonblocking_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "noc_parameters.h"
#include "dev_msgs.h"
#include "risc_attribs.h"

////

Expand Down
5 changes: 5 additions & 0 deletions tt_metal/impl/dispatch/command_queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1020,6 +1020,7 @@ void EnqueueProgramCommand::assemble_device_commands(
uint32_t programmable_core_index = hal.get_programmable_core_type_index(HalProgrammableCoreType::TENSIX);
for (KernelGroup& kernel_group : program.get_kernel_groups(programmable_core_index)) {
kernel_group.launch_msg.kernel_config.mode = DISPATCH_MODE_DEV;
kernel_group.launch_msg.kernel_config.enables |= DISPATCH_ENABLE_FLAG_PRELOAD;
for (uint32_t i = 0; i < kernel_config_addrs.size(); i++) {
kernel_group.launch_msg.kernel_config.kernel_config_base[i] = kernel_config_addrs[i].addr;
}
Expand Down Expand Up @@ -1052,6 +1053,7 @@ void EnqueueProgramCommand::assemble_device_commands(
if (programmable_core_index != -1) {
for (KernelGroup& kernel_group : program.get_kernel_groups(programmable_core_index)) {
kernel_group.launch_msg.kernel_config.mode = DISPATCH_MODE_DEV;
kernel_group.launch_msg.kernel_config.enables |= DISPATCH_ENABLE_FLAG_PRELOAD;
for (uint32_t i = 0; i < kernel_config_addrs.size(); i++) {
kernel_group.launch_msg.kernel_config.kernel_config_base[i] = kernel_config_addrs[i].addr;
}
Expand Down Expand Up @@ -1084,6 +1086,8 @@ void EnqueueProgramCommand::assemble_device_commands(
// if not, check if the program is active on workers. If active, have dispatch_d issue a write barrier
cmd_sequence_sizeB += (this->device->dispatch_s_enabled() || program_transfer_info.num_active_cores > 0) * CQ_PREFETCH_CMD_BARE_MIN_SIZE;

// Wait for eveything to be written to before launch.
cmd_sequence_sizeB += CQ_PREFETCH_CMD_BARE_MIN_SIZE;
// either dispatch_s or dispatch_d will send the go signal (go_signal_mcast command)
cmd_sequence_sizeB += CQ_PREFETCH_CMD_BARE_MIN_SIZE;

Expand Down Expand Up @@ -1201,6 +1205,7 @@ void EnqueueProgramCommand::assemble_device_commands(
kernel_bins_prefetch_subcmds[i].size());
}

device_command_sequence.add_dispatch_wait(/*barrier*/ true, 0, 0, false, false, /*do_wait */ false);
// Go Signals
program_command_sequence.go_signals.reserve(
multicast_go_signal_sub_cmds.size() + unicast_go_signal_sub_cmds.size());
Expand Down

0 comments on commit 87bd9a2

Please sign in to comment.