Skip to content

Commit

Permalink
[runtime] Add basic setup for kernel tracing
Browse files Browse the repository at this point in the history
  • Loading branch information
zero9178 committed Jun 7, 2024
1 parent 2fb4c21 commit 66ceffc
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 9 deletions.
15 changes: 12 additions & 3 deletions runtime/runtime/src/Quidditch/dispatch/dispatch.c
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@

#include "dispatch.h"

#include <iree/base/alignment.h>

#include <assert.h>
#include <cluster_interrupt_decls.h>
#include <encoding.h>
#include <perf_decls.h>
#include <riscv_decls.h>
#include <ssr_decls.h>
#include <stdatomic.h>
#include <stdbool.h>
#include <stdint.h>
#include <team_decls.h>

#include "iree/base/alignment.h"

// TODO: This should be cluster local.
static struct worker_metadata_t {
atomic_uint workers_waiting;
Expand Down Expand Up @@ -67,10 +69,17 @@ int quidditch_dispatch_enter_worker_loop() {
while (!worker_metadata.exit) {
park_worker();
if (worker_metadata.exit) break;


read_csr(mcycle);
if (configuredKernel(configuredEnvironment, configuredDispatchState,
&configuredWorkgroupState[snrt_cluster_core_idx()]))
error = true;

// Required to make sure that we only read the mcycle once the FPU has
// actually finished. Otherwise, we are measuring cycles that are too short!
// This is only required for measurement, not in real programs.
snrt_fpu_fence();
read_csr(mcycle);
}

snrt_interrupt_disable(IRQ_M_CLUSTER);
Expand Down
1 change: 1 addition & 0 deletions runtime/samples/nsnet2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ target_link_libraries(
samples_util
nsnet2_module
snRuntime
Quidditch::dispatch::dispatch
)
4 changes: 4 additions & 0 deletions runtime/samples/nsnet2/main.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
#include <Quidditch/dispatch/dispatch.h>

#include <nsnet2.h>
#include <nsnet2_module.h>
#include <team_decls.h>
#include <util/run_model.h>

int main() {
if (!snrt_is_dm_core()) return quidditch_dispatch_enter_worker_loop();

float data[161];

for (int i = 0; i < IREE_ARRAYSIZE(data); i++) {
Expand Down
6 changes: 0 additions & 6 deletions runtime/samples/util/run_model.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,6 @@ static iree_status_t setup_instance_and_device(
}

iree_status_t run_model(const model_config_t* config) {
if (!snrt_is_dm_core()) {
int ret = quidditch_dispatch_enter_worker_loop();
if (!ret) return iree_ok_status();
return iree_make_status(IREE_STATUS_UNKNOWN);
}

iree_allocator_t host_allocator = iree_allocator_system();

iree_vm_instance_t* vmInstance;
Expand Down
1 change: 1 addition & 0 deletions runtime/samples/vec_multiply/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ target_link_libraries(
samples_util
simple_add_module
snRuntime
Quidditch::dispatch::dispatch
)

3 changes: 3 additions & 0 deletions runtime/samples/vec_multiply/main.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#include <Quidditch/dispatch/dispatch.h>

#include <simple_add.h>
#include <simple_add_module.h>
#include <team_decls.h>
#include <util/run_model.h>

int main() {
double data[4];
if (!snrt_is_dm_core()) return quidditch_dispatch_enter_worker_loop();

for (int i = 0; i < IREE_ARRAYSIZE(data); i++) {
data[i] = (i + 1);
Expand Down
4 changes: 4 additions & 0 deletions runtime/snitch_cluster/api/ssr_decls.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

#pragma once

void snrt_fpu_fence();
3 changes: 3 additions & 0 deletions runtime/snitch_cluster/rtl/src/snrt.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@
#include "riscv.c"
#include "snitch_cluster_memory.c"
#include "snitch_cluster_start.c"
#include "ssr.h"
#include "stack_decls.h"
#include "sync.c"
#include "team.c"

extern void snrt_fpu_fence();

uint32_t snrt_get_stack_size_per_core() { return 1 << SNRT_LOG2_STACK_SIZE; }

0 comments on commit 66ceffc

Please sign in to comment.