From ccc835b9fb5eb10c0566b1070a12ab076d9b1dfc Mon Sep 17 00:00:00 2001 From: Luka Macan Date: Thu, 18 Jan 2024 14:29:23 +0100 Subject: [PATCH] Fix formatting --- neureka/hal/neureka_task.c | 44 ++++++++++++++++++--------------- neureka/hal/neureka_task_defs.h | 5 ++-- test/app/src/main.c | 12 ++++----- test/app/src/nnx_layer.c | 28 ++++++++++----------- 4 files changed, 47 insertions(+), 42 deletions(-) diff --git a/neureka/hal/neureka_task.c b/neureka/hal/neureka_task.c index 941fcde..2097af7 100644 --- a/neureka/hal/neureka_task.c +++ b/neureka/hal/neureka_task.c @@ -48,19 +48,19 @@ void neureka_task_init(neureka_task_t *task, const uint8_t kernel_shape, const uint32_t weights_offset_factor, neureka_quant_t quant, neureka_norm_t norm, const uint8_t stride) { - *task = (neureka_task_t){ - .outbytes = output_bits / 8, - .qw = weights_bits, - .stride_shift = stride == 2 ? 1 : 0, - .output_channel_throughput = depthwise - ? NEUREKA_INPUT_CHANNEL_THROUGHPUT_3x3 - : NEUREKA_OUTPUT_CHANNEL_THROUGHPUT, - .input_channel_throughput = kernel_shape == 3 - ? NEUREKA_INPUT_CHANNEL_THROUGHPUT_3x3 - : NEUREKA_INPUT_CHANNEL_THROUGHPUT_1x1, - .kernel_shape = kernel_shape, - .depthwise = depthwise, - .data = {0}}; + *task = (neureka_task_t){.outbytes = output_bits / 8, + .qw = weights_bits, + .stride_shift = stride == 2 ? 1 : 0, + .output_channel_throughput = + depthwise ? NEUREKA_INPUT_CHANNEL_THROUGHPUT_3x3 + : NEUREKA_OUTPUT_CHANNEL_THROUGHPUT, + .input_channel_throughput = + kernel_shape == 3 + ? NEUREKA_INPUT_CHANNEL_THROUGHPUT_3x3 + : NEUREKA_INPUT_CHANNEL_THROUGHPUT_1x1, + .kernel_shape = kernel_shape, + .depthwise = depthwise, + .data = {0}}; const int flag_mode = kernel_shape == 1 ? NEUREKA_FLAG_MODE_1x1 : depthwise == 1 ? NEUREKA_FLAG_MODE_3x3_DW @@ -122,15 +122,15 @@ void neureka_task_set_strides(neureka_task_t *task, const uint32_t k_in, const neureka_stride_t output_stride = { .d0 = 32, // TODO: should depend on outbytes. Probably 32 / outbytes .d1 = k_out_stride * task->outbytes, - .d2 = k_out_stride * task->outbytes * w_out_stride - }; + .d2 = k_out_stride * task->outbytes * w_out_stride}; task->data.cfg.output_stride = output_stride; task->data.cfg.weights_stride.d0 = NEUREKA_WEIGHT_D0_STRIDE; if (task->kernel_shape == 1) { // 1x1 task->data.cfg.weights_stride.d1 = NEUREKA_WEIGHT_D0_STRIDE * num_k_in; } else if (!task->depthwise) { // 3x3 - task->data.cfg.weights_stride.d1 = NEUREKA_WEIGHT_D0_STRIDE * task->qw * num_k_in; + task->data.cfg.weights_stride.d1 = + NEUREKA_WEIGHT_D0_STRIDE * task->qw * num_k_in; } else { // 3x3 depthwise task->data.cfg.weights_stride.d1 = 0; } @@ -151,10 +151,14 @@ void neureka_task_set_counters(neureka_task_t *task, const uint32_t k_in, const uint16_t rem_Ki = remainder(k_in, task->input_channel_throughput); const uint16_t rem_Ho = remainder(h_out, NEUREKA_COMPUTE_SIZE_HEIGHT); const uint16_t rem_Wo = remainder(w_out, NEUREKA_COMPUTE_SIZE_WIDTH); - const uint16_t rem_Hi = rem_Ho == 0 ? 0 : (task->kernel_shape == 1 ? rem_Ho : rem_Ho + 2) - - padding_bottom; // TODO: Check padding bottom - const uint16_t rem_Wi = rem_Wo == 0 ? 0 : (task->kernel_shape == 1 ? rem_Wo : rem_Wo + 2) - - padding_right; // TODO: Check padding right + const uint16_t rem_Hi = + rem_Ho == 0 ? 0 + : (task->kernel_shape == 1 ? rem_Ho : rem_Ho + 2) - + padding_bottom; // TODO: Check padding bottom + const uint16_t rem_Wi = + rem_Wo == 0 ? 0 + : (task->kernel_shape == 1 ? rem_Wo : rem_Wo + 2) - + padding_right; // TODO: Check padding right const neureka_subtile_t subtile = { .number = {.KoKi = concat_half(num_Ko, num_Ki), diff --git a/neureka/hal/neureka_task_defs.h b/neureka/hal/neureka_task_defs.h index f720061..952d7b2 100644 --- a/neureka/hal/neureka_task_defs.h +++ b/neureka/hal/neureka_task_defs.h @@ -78,7 +78,8 @@ #define NEUREKA_QUANT_MODE_32BIT (2 << 21) // conf0[20:16] - quantization shift amount #define NEUREKA_FLAG_WEIGHT_OFFSET_SYMMETRIC (0 << 15) // Unimplemented in gvsoc -#define NEUREKA_FLAG_WEIGHT_OFFSET_LAYER_WISE (1 << 15) // Unimplemented in gvsoc +#define NEUREKA_FLAG_WEIGHT_OFFSET_LAYER_WISE \ + (1 << 15) // Unimplemented in gvsoc #define NEUREKA_FLAG_STREAMIN (1 << 14) #define NEUREKA_NORM_MODE_8BIT (0 << 12) #define NEUREKA_NORM_MODE_16BIT (1 << 12) // not supported @@ -87,7 +88,7 @@ #define NEUREKA_FLAG_ACTIVATION_PREFETCH (1 << 10) #define NEUREKA_FLAG_USE_WMEM (1 << 9) #define NEUREKA_FLAG_USE_TCDM (0 << 9) -#define NEUREKA_FLAG_STRIDE_2x2 (1 << 8) // not supported +#define NEUREKA_FLAG_STRIDE_2x2 (1 << 8) // not supported #define NEUREKA_FLAG_LINEAR_MODE (1 << 7) // not supported #define NEUREKA_FLAG_MODE_3x3 (0 << 5) #define NEUREKA_FLAG_MODE_3x3_DW (1 << 5) diff --git a/test/app/src/main.c b/test/app/src/main.c index db32e3f..ecc9dd4 100644 --- a/test/app/src/main.c +++ b/test/app/src/main.c @@ -20,18 +20,18 @@ #include +#include "bias.h" +#include "input.h" #include "layer_util.h" #include "nnx_layer.h" #include "output.h" -#include "input.h" -#include "bias.h" #include "scale.h" #include "weight.h" -#define NNX_MEMCPY(dst, src, size) \ -for (int i = 0; i < size; i++) { \ - dst[i] = src[i]; \ -} +#define NNX_MEMCPY(dst, src, size) \ + for (int i = 0; i < size; i++) { \ + dst[i] = src[i]; \ + } int main() { struct pi_device cl_dev; diff --git a/test/app/src/nnx_layer.c b/test/app/src/nnx_layer.c index 2ca522f..eb6f0ff 100644 --- a/test/app/src/nnx_layer.c +++ b/test/app/src/nnx_layer.c @@ -116,16 +116,16 @@ static void task_prepare(nnx_task_t *task) { STRIDE_HEIGHT); #if STRIDE_HEIGHT == 2 && STRIDE_WIDTH == 2 - nnx_task_set_dims_stride2x2( - task, INPUT_HEIGHT, INPUT_WIDTH, INPUT_CHANNEL, INPUT_WIDTH, - INPUT_CHANNEL, OUTPUT_HEIGHT, OUTPUT_WIDTH, OUTPUT_CHANNEL, - OUTPUT_WIDTH, OUTPUT_CHANNEL, WEIGHT_HEIGHT, WEIGHT_WIDTH, PADDING_TOP, - PADDING_BOTTOM, PADDING_RIGHT, PADDING_LEFT); + nnx_task_set_dims_stride2x2( + task, INPUT_HEIGHT, INPUT_WIDTH, INPUT_CHANNEL, INPUT_WIDTH, + INPUT_CHANNEL, OUTPUT_HEIGHT, OUTPUT_WIDTH, OUTPUT_CHANNEL, OUTPUT_WIDTH, + OUTPUT_CHANNEL, WEIGHT_HEIGHT, WEIGHT_WIDTH, PADDING_TOP, PADDING_BOTTOM, + PADDING_RIGHT, PADDING_LEFT); #else - nnx_task_set_dims(task, INPUT_WIDTH, INPUT_CHANNEL, INPUT_WIDTH, - INPUT_CHANNEL, OUTPUT_HEIGHT, OUTPUT_WIDTH, - OUTPUT_CHANNEL, OUTPUT_WIDTH, OUTPUT_CHANNEL, PADDING_TOP, - PADDING_BOTTOM, PADDING_RIGHT, PADDING_LEFT); + nnx_task_set_dims(task, INPUT_WIDTH, INPUT_CHANNEL, INPUT_WIDTH, + INPUT_CHANNEL, OUTPUT_HEIGHT, OUTPUT_WIDTH, OUTPUT_CHANNEL, + OUTPUT_WIDTH, OUTPUT_CHANNEL, PADDING_TOP, PADDING_BOTTOM, + PADDING_RIGHT, PADDING_LEFT); #endif nnx_task_set_ptrs(task, (uint32_t)input, INPUT_WIDTH, INPUT_CHANNEL, @@ -150,12 +150,12 @@ static void task_execute(nnx_task_t *task) { nnx_dispatch_wait(dev); #if STRIDE_HEIGHT == 2 && STRIDE_WIDTH == 2 - nnx_dispatch_stride2x2(dev, task, INPUT_WIDTH, INPUT_CHANNEL, INPUT_WIDTH, - INPUT_CHANNEL, OUTPUT_HEIGHT, OUTPUT_WIDTH, - OUTPUT_CHANNEL, OUTPUT_WIDTH, OUTPUT_CHANNEL, - WEIGHT_HEIGHT, WEIGHT_WIDTH); + nnx_dispatch_stride2x2(dev, task, INPUT_WIDTH, INPUT_CHANNEL, INPUT_WIDTH, + INPUT_CHANNEL, OUTPUT_HEIGHT, OUTPUT_WIDTH, + OUTPUT_CHANNEL, OUTPUT_WIDTH, OUTPUT_CHANNEL, + WEIGHT_HEIGHT, WEIGHT_WIDTH); #else - nnx_dispatch(dev, task); + nnx_dispatch(dev, task); #endif nnx_resolve_wait(dev, task);