diff --git a/dory/Hardware_targets/PULP/GAP9/Utils_files/net_utils.h b/dory/Hardware_targets/PULP/GAP9/Utils_files/net_utils.h index 1ed57c63..0464d0f4 100644 --- a/dory/Hardware_targets/PULP/GAP9/Utils_files/net_utils.h +++ b/dory/Hardware_targets/PULP/GAP9/Utils_files/net_utils.h @@ -2,6 +2,7 @@ #define __PERF_UTILS_H__ #include #include +#include "monitor.h" // Padding flags @@ -11,6 +12,10 @@ #define NET_UTILS_PAD_LEFT (1 << 0) #define NET_UTILS_NO_PAD (0) +typedef struct { + Monitor input, output, store_conf; +} TaskMonitors; + typedef struct { unsigned int L3_input; unsigned int L3_output; @@ -23,6 +28,7 @@ typedef struct { unsigned int ram; unsigned int padding; unsigned int layer_id; + TaskMonitors *monitor; } layer_args_t; void print_perf(const char *name, const int cycles, const int macs); diff --git a/dory/Hardware_targets/PULP/GAP9_NE16/Templates/layer_templates/layer_L2_c_conv_ne16_multicore_template.c b/dory/Hardware_targets/PULP/GAP9_NE16/Templates/layer_templates/layer_L2_c_conv_ne16_multicore_template.c index ed95ed9f..9a9abcae 100644 --- a/dory/Hardware_targets/PULP/GAP9_NE16/Templates/layer_templates/layer_L2_c_conv_ne16_multicore_template.c +++ b/dory/Hardware_targets/PULP/GAP9_NE16/Templates/layer_templates/layer_L2_c_conv_ne16_multicore_template.c @@ -182,10 +182,6 @@ static int inc(int index, int end) { #define BUFFER_SIZE (2) -typedef struct { - Monitor input, output, store_conf; -} TaskMonitors; - struct layer_task_fork_args_t { uint32_t L2_input; uint32_t L2_weights; @@ -360,29 +356,6 @@ void ${func_name}(void *args) { layer_args_t *layer_args = (layer_args_t *)args; - // Initialization - TaskMonitors monitor; - - int err = 0; - - if (err = monitor_init(&monitor.input, BUFFER_SIZE)) { - printf("Input monitor initialization failed with status %d.\n", err); - return; - } - - if (err = monitor_init(&monitor.output, BUFFER_SIZE)) { - printf("Output monitor initialization failed with status %d.\n", err); - monitor_term(monitor.input); - return; - } - - if (err = monitor_init(&monitor.store_conf, BUFFER_SIZE)) { - printf("Store conf monitor initialization failed with status %d.\n", err); - monitor_term(monitor.input); - monitor_term(monitor.output); - return; - } - // Init nnx tasks ne16_task_t ne16_tasks[BUFFER_SIZE]; for (int i = 0; i < BUFFER_SIZE; i++) { @@ -417,14 +390,10 @@ void ${func_name}(void *args) { .ne16_tasks = ne16_tasks, .tiles = tiles, .store_conf = store_conf, - .monitor = &monitor, + .monitor = layer_args->monitor, }; pi_cl_team_fork(CORES, layer_task_fork, (void *)&layer_task_fork_args); // Terminate - - monitor_term(monitor.input); - monitor_term(monitor.output); - monitor_term(monitor.store_conf); } diff --git a/dory/Hardware_targets/PULP/GAP9_NE16/Templates/network_c_template.c b/dory/Hardware_targets/PULP/GAP9_NE16/Templates/network_c_template.c index cfbf6096..ac443d03 100644 --- a/dory/Hardware_targets/PULP/GAP9_NE16/Templates/network_c_template.c +++ b/dory/Hardware_targets/PULP/GAP9_NE16/Templates/network_c_template.c @@ -216,6 +216,27 @@ void ${prefix}network_run_cluster(void *args) { const ne16_pulp_conf_t ne16_pulp_conf = {.max_stall = 8}; ne16_nnx_init(ne16_pulp_get_dev(), &ne16_pulp_conf); + TaskMonitors monitor; + + int err = 0; + + if (err = monitor_init(&monitor.input, 2)) { + printf("Input monitor initialization failed with status %d.\n", err); + return; + } + + if (err = monitor_init(&monitor.output, 2)) { + printf("Output monitor initialization failed with status %d.\n", err); + monitor_term(monitor.input); + return; + } + + if (err = monitor_init(&monitor.store_conf, 2)) { + printf("Store conf monitor initialization failed with status %d.\n", err); + monitor_term(monitor.input); + monitor_term(monitor.output); + return; + } /* ---------------------------------- */ /* --------- SECTION 0 END ---------- */ /* ---------------------------------- */ @@ -317,7 +338,8 @@ void ${prefix}network_run_cluster(void *args) { .L1_buffer = 0, .ram = (unsigned int) get_ram_ptr(), .padding = NET_UTILS_PAD_TOP | NET_UTILS_PAD_BOTTOM, - .layer_id = i + .layer_id = i, + .monitor = &monitor, }; % if 'Yes' in performance or 'Perf_final' in verbose_level: @@ -514,4 +536,7 @@ void ${prefix}network_run_cluster(void *args) { /* ---------------------------------- */ ne16_nnx_term(ne16_pulp_get_dev()); + monitor_term(monitor.input); + monitor_term(monitor.output); + monitor_term(monitor.store_conf); } diff --git a/dory/Hardware_targets/PULP/GAP9_NE16/Utils_files/monitor.c b/dory/Hardware_targets/PULP/GAP9_NE16/Utils_files/monitor.c new file mode 100644 index 00000000..730a2c45 --- /dev/null +++ b/dory/Hardware_targets/PULP/GAP9_NE16/Utils_files/monitor.c @@ -0,0 +1,42 @@ +#include "monitor.h" +#include "pmsis.h" + + +int monitor_init(Monitor * const monitor, int buffer_size) { + monitor->empty = pi_cl_sem_alloc(); + if (monitor->empty == 0) { + return -1; + } + + monitor->full = pi_cl_sem_alloc(); + if (monitor->full == 0) { + pi_cl_sem_free(monitor->empty); + return -2; + } + + pi_cl_sem_set(monitor->full, 0); + pi_cl_sem_set(monitor->empty, buffer_size); + + return 0; +} + +void monitor_term(Monitor monitor) { + pi_cl_sem_free(monitor.empty); + pi_cl_sem_free(monitor.full); +} + +void monitor_produce_begin(Monitor monitor) { + pi_cl_sem_dec(monitor.empty); +} + +void monitor_produce_end(Monitor monitor) { + pi_cl_sem_inc(monitor.full, 1); +} + +void monitor_consume_begin(Monitor monitor) { + pi_cl_sem_dec(monitor.full); +} + +void monitor_consume_end(Monitor monitor) { + pi_cl_sem_inc(monitor.empty, 1); +} diff --git a/dory/Hardware_targets/PULP/GAP9_NE16/Utils_files/monitor.h b/dory/Hardware_targets/PULP/GAP9_NE16/Utils_files/monitor.h index f1179401..b471d994 100644 --- a/dory/Hardware_targets/PULP/GAP9_NE16/Utils_files/monitor.h +++ b/dory/Hardware_targets/PULP/GAP9_NE16/Utils_files/monitor.h @@ -1,4 +1,8 @@ -#include "pmsis.h" +#ifndef __MONITOR_H__ +#define __MONITOR_H__ + +#include + typedef struct Monitor { uint32_t empty; @@ -6,42 +10,11 @@ typedef struct Monitor { } Monitor; -static int monitor_init(Monitor * const monitor, int buffer_size) { - monitor->empty = pi_cl_sem_alloc(); - if (monitor->empty == 0) { - return -1; - } - - monitor->full = pi_cl_sem_alloc(); - if (monitor->full == 0) { - pi_cl_sem_free(monitor->empty); - return -2; - } - - pi_cl_sem_set(monitor->full, 0); - pi_cl_sem_set(monitor->empty, buffer_size); - - return 0; -} - -static void monitor_term(Monitor monitor) { - pi_cl_sem_free(monitor.empty); - pi_cl_sem_free(monitor.full); -} - -static void monitor_produce_begin(Monitor monitor) { - pi_cl_sem_dec(monitor.empty); -} - -static void monitor_produce_end(Monitor monitor) { - pi_cl_sem_inc(monitor.full, 1); -} - -static void monitor_consume_begin(Monitor monitor) { - pi_cl_sem_dec(monitor.full); -} - -static void monitor_consume_end(Monitor monitor) { - pi_cl_sem_inc(monitor.empty, 1); -} +int monitor_init(Monitor * const monitor, int buffer_size); +void monitor_term(Monitor monitor); +void monitor_produce_begin(Monitor monitor); +void monitor_produce_end(Monitor monitor); +void monitor_consume_begin(Monitor monitor); +void monitor_consume_end(Monitor monitor); +#endif // __MONITOR_H__