Skip to content

Commit

Permalink
Fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
lukamac committed Jan 18, 2024
1 parent 27664cd commit ccc835b
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 42 deletions.
44 changes: 24 additions & 20 deletions neureka/hal/neureka_task.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand All @@ -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),
Expand Down
5 changes: 3 additions & 2 deletions neureka/hal/neureka_task_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions test/app/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@

#include <pmsis.h>

#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;
Expand Down
28 changes: 14 additions & 14 deletions test/app/src/nnx_layer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
Expand Down

0 comments on commit ccc835b

Please sign in to comment.