Skip to content

Commit

Permalink
Add input_signed to neureka
Browse files Browse the repository at this point in the history
  • Loading branch information
lukamac committed Jan 19, 2024
1 parent dc2409c commit d6ba620
Show file tree
Hide file tree
Showing 9 changed files with 128 additions and 8 deletions.
4 changes: 2 additions & 2 deletions neureka/hal/neureka_task.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,9 @@ void neureka_task_init(neureka_task_t *task, const uint8_t kernel_shape,
const neureka_weight_offset_mode_e weights_offset_mode,
const uint32_t weights_offset_factor,
neureka_quant_t quant, neureka_norm_t norm,
const uint8_t stride) {
const uint8_t flag_input_signed) {
*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,
Expand All @@ -67,6 +66,7 @@ void neureka_task_init(neureka_task_t *task, const uint8_t kernel_shape,
: NEUREKA_FLAG_MODE_3x3;

task->data.cfg.conf0 |=
flag_input_signed << NEUREKA_SHIFT_FLAG_INPUT_SIGNED |
NEUREKA_FLAG_NORM_QUANT | quant.function | quant.mode |
(quant.shift_amount << 16) |
quant.flag_rounding << NEUREKA_SHIFT_ROUNDING | norm.mode |
Expand Down
4 changes: 1 addition & 3 deletions neureka/hal/neureka_task.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,7 @@ typedef struct neureka_task_data_t {
typedef struct neureka_task_t {
neureka_task_data_t data;
uint8_t outbytes;
uint8_t weight_d0_stride;
uint8_t qw;
uint8_t stride_shift;
uint8_t output_channel_throughput;
uint8_t input_channel_throughput;
uint8_t kernel_shape;
Expand All @@ -127,7 +125,7 @@ void neureka_task_init(neureka_task_t *task, const uint8_t kernel_shape,
const neureka_weight_offset_mode_e weights_offset_mode,
const uint32_t weights_offset_factor,
neureka_quant_t quant, neureka_norm_t norm,
const uint8_t stride);
const uint8_t flag_input_signed);
uint32_t neureka_get_tile_padding(uint32_t padding, uint32_t i_height,
uint32_t i_width, uint32_t n_height,
uint32_t n_width);
Expand Down
3 changes: 2 additions & 1 deletion neureka/hal/neureka_task_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,15 @@

/* SHIFT */

#define NEUREKA_SHIFT_FLAG_INPUT_SIGNED (26)
#define NEUREKA_SHIFT_FLAG_NORM_BIAS (25)
#define NEUREKA_SHIFT_FLAG_NORM_SHIFT (24)
#define NEUREKA_SHIFT_QUANT_SHIFT (16)
#define NEUREKA_SHIFT_ROUNDING (11)

/* CONF0 FLAGS */

#define NEUREKA_FLAG_SIGNED_ACTIVATION (1 << 26)
#define NEUREKA_FLAG_INPUT_SIGNED (1 << 26)
#define NEUREKA_FLAG_NORM_BIAS (1 << 25)
#define NEUREKA_FLAG_NORM_SHIFT (1 << 24)
#define NEUREKA_FLAG_QUANT_FUNCTION_IDENTITY (1 << 23)
Expand Down
2 changes: 1 addition & 1 deletion test/NeurekaTestConf.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def _check_type(
@field_validator("in_type")
@classmethod
def check_valid_in_type(cls, v: IntegerType) -> IntegerType:
NeurekaTestConf._check_type("in_type", v, ["uint8"])
NeurekaTestConf._check_type("in_type", v, ["uint8", "int8"])
return v

@field_validator("out_type")
Expand Down
7 changes: 6 additions & 1 deletion test/app/src/nnx_layer.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,12 @@ static void task_prepare(nnx_task_t *task) {
(nnx_norm_t){.mode = normMode8Bit,
.flag_bias = HAS_BIAS ? nnxTaskFlagTrue : nnxTaskFlagFalse,
.flag_shift = nnxTaskFlagFalse},
STRIDE_HEIGHT);
#ifdef NNX_NE16
STRIDE_HEIGHT
#elif NNX_NEUREKA
INPUT_SIGNED
#endif
);

#if STRIDE_HEIGHT == 2 && STRIDE_WIDTH == 2
nnx_task_set_dims_stride2x2(
Expand Down
29 changes: 29 additions & 0 deletions test/tests/test_102/conf.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"in_height": 4,
"in_width": 3,
"in_channel": 8,
"out_channel": 8,
"padding": {
"top": 0,
"bottom": 0,
"left": 0,
"right": 0
},
"kernel_shape": {
"height": 3,
"width": 3
},
"depthwise": false,
"stride": {
"height": 1,
"width": 1
},
"in_type": "int8",
"out_type": "uint8",
"weight_type": "int8",
"scale_type": "uint8",
"bias_type": "int32",
"has_norm_quant": true,
"has_bias": true,
"has_relu": true
}
29 changes: 29 additions & 0 deletions test/tests/test_103/conf.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"in_height": 20,
"in_width": 15,
"in_channel": 40,
"out_channel": 25,
"padding": {
"top": 0,
"bottom": 0,
"left": 0,
"right": 0
},
"kernel_shape": {
"height": 3,
"width": 3
},
"depthwise": false,
"stride": {
"height": 1,
"width": 1
},
"in_type": "int8",
"out_type": "uint8",
"weight_type": "int8",
"scale_type": "uint8",
"bias_type": "int32",
"has_norm_quant": true,
"has_bias": true,
"has_relu": true
}
29 changes: 29 additions & 0 deletions test/tests/test_104/conf.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"in_height": 20,
"in_width": 15,
"in_channel": 40,
"out_channel": 25,
"padding": {
"top": 0,
"bottom": 0,
"left": 0,
"right": 0
},
"kernel_shape": {
"height": 1,
"width": 1
},
"depthwise": false,
"stride": {
"height": 1,
"width": 1
},
"in_type": "int8",
"out_type": "uint8",
"weight_type": "int8",
"scale_type": "uint8",
"bias_type": "int32",
"has_norm_quant": true,
"has_bias": true,
"has_relu": true
}
29 changes: 29 additions & 0 deletions test/tests/test_105/conf.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"in_height": 20,
"in_width": 15,
"in_channel": 40,
"out_channel": 40,
"padding": {
"top": 0,
"bottom": 0,
"left": 0,
"right": 0
},
"kernel_shape": {
"height": 3,
"width": 3
},
"depthwise": true,
"stride": {
"height": 1,
"width": 1
},
"in_type": "int8",
"out_type": "uint8",
"weight_type": "int8",
"scale_type": "uint8",
"bias_type": "int32",
"has_norm_quant": true,
"has_bias": true,
"has_relu": true
}

0 comments on commit d6ba620

Please sign in to comment.