Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add neureka support #2

Merged
merged 72 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from 43 commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
8cd7965
Add neureka support similar to ne16
lukamac Jan 14, 2024
e096415
add neureka support to test app
lukamac Jan 14, 2024
c480025
Add weight mem source flag
lukamac Jan 14, 2024
953db1e
Fix formatting
lukamac Jan 15, 2024
a114acd
Fix strides and counters, remove stride2x2 and flag16 mode
lukamac Jan 16, 2024
94bbe08
Fix uninitialized L1 data
lukamac Jan 16, 2024
6341d0e
Fixup nnx_quant_t nnx_norm_t
lukamac Jan 16, 2024
eddf389
Add Neureka weight roll/unroll script
lukamac Jan 17, 2024
e281f4d
Fix Ne16 weight rolling was unpacking to bits instead of 8
lukamac Jan 17, 2024
d6008b6
Fix generated arrays initialization
lukamac Jan 18, 2024
56afb5f
Fix Neureka weight unroll for 1x1 mode
lukamac Jan 18, 2024
925aa41
Fix Arpan's name in the contributors
lukamac Jan 18, 2024
0140665
Remove WIEGHT_D0_STRIDE_MODE_1x1
lukamac Jan 18, 2024
741b5d7
Add multi-accelerator support and neureka as a target
lukamac Jan 18, 2024
27664cd
Remove stride2x2 for neureka
lukamac Jan 18, 2024
ccc835b
Fix formatting
lukamac Jan 18, 2024
df0eb6b
Skip invalid tests
lukamac Jan 18, 2024
31dc36e
Change invalid tes tskip to explicit pytest skip with reason
lukamac Jan 18, 2024
7bae33c
Add neureka test to the CI
lukamac Jan 18, 2024
a0080c6
Fix formatting
lukamac Jan 18, 2024
be50522
Add --print-tensors flag
lukamac Jan 19, 2024
2c07dbd
Remove memcpys since it was a linker script bug
lukamac Jan 19, 2024
6a82ff5
Add Application section to test's readme
lukamac Jan 19, 2024
295ce90
Fix formatting
lukamac Jan 19, 2024
dc2409c
Fix accelerator name printing
lukamac Jan 19, 2024
d6ba620
Add input_signed to neureka
lukamac Jan 19, 2024
0934172
Add readme per accelerator
lukamac Jan 19, 2024
2947229
Remove ne16 input dim 2 stride calculation
lukamac Jan 19, 2024
b7442ee
Move common validators to NnxTest
lukamac Jan 19, 2024
91effde
Fix xored relu with unsigned instead of signed
lukamac Jan 22, 2024
0187793
Change gvsoc functions have a body only when running in gvsoc
lukamac Jan 22, 2024
4fab480
Change remove %s from main strings
lukamac Jan 22, 2024
3906e7a
Fix output checking should be done before cluster close since data is…
lukamac Jan 22, 2024
774cfd3
Remove L2 copies of tensors
lukamac Jan 22, 2024
4358ed5
Replace pointer arithmetic with array indexing
lukamac Jan 22, 2024
668c045
Fix formatting
lukamac Jan 22, 2024
cf70c78
Fix Neureka name in readme
lukamac Jan 22, 2024
b02e018
Align names with Neureka.py
lukamac Jan 24, 2024
5e61e39
Pad cin
lukamac Jan 24, 2024
8345b1d
Rename <acc>.py to <acc>MemoryLayout.py
lukamac Jan 25, 2024
a623ccf
Extract functional model from test gen
lukamac Jan 25, 2024
b743930
Remove conf from NeuralEngineFunctionalModel
lukamac Jan 25, 2024
f425ea5
Add isort
lukamac Jan 26, 2024
932847d
Remove neureka siracusa clock gating
lukamac Jan 26, 2024
7ff3fcb
Remove inline from hal
lukamac Jan 26, 2024
772fd95
Removed xor, python has xor
lukamac Jan 26, 2024
2223af9
WIP: Add without norm_quant
lukamac Jan 26, 2024
8232527
Remove -flto
lukamac Jan 26, 2024
df3f5dd
Add -std=c11
lukamac Jan 26, 2024
24ebd9e
Move stride shift to stride2x2 function
lukamac Jan 26, 2024
f1ed5f6
Fix flag clear before setting
lukamac Jan 26, 2024
c47b2c5
Fix normMode hardcoded to 32bit
lukamac Jan 26, 2024
27ab3a5
Set quantMode in *_set_bits function
lukamac Jan 26, 2024
23009cc
Fix output d0 stride and rename defs
lukamac Jan 27, 2024
e78dd80
Fixes to strides and stride2x2
lukamac Jan 27, 2024
a6f142a
Add no norm_quant to neureka and all the fixes too
lukamac Jan 27, 2024
c436ea4
Fix stride2x2 validity check for out channel to check stride evenness
lukamac Jan 27, 2024
eda8b51
Fix formatting
lukamac Jan 27, 2024
8b37485
Remove TODO's cause neureka clearly needs these functions
lukamac Jan 27, 2024
d9c45ef
Remove equal 0 check because that can never be the case due to the re…
lukamac Jan 27, 2024
29ee483
Remove TODOs, checked padding
lukamac Jan 27, 2024
d9c7723
Rename divnceil and remainder, and add nnx_ prefix
lukamac Jan 27, 2024
37ba86c
Add citation
lukamac Jan 29, 2024
9e0b211
Add sdk and compiler commit hashes
lukamac Jan 29, 2024
1a4f873
Change task size to a define
lukamac Jan 29, 2024
0412759
Update supported acc supported features
lukamac Jan 29, 2024
b9f3de4
Update changelog
lukamac Jan 29, 2024
5990d83
Update pulp-sdk commit hash
lukamac Jan 29, 2024
07f47d9
Remove -std=c11 flag
lukamac Jan 29, 2024
0791162
Fix readme collapsable verbatim
lukamac Jan 29, 2024
9145445
Remove __PLATFORM__ check from the library since it's pulp-sdk specific
lukamac Jan 29, 2024
6d24dd8
Change channel and bits with w_in_stride for set_ptrs
lukamac Jan 30, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,41 @@ stages:
- lint
- test

format_python:
python_format:
stage: lint
tags:
- python-lint
script:
- black --check .

static_check_python:
python_sort_imports:
stage: lint
tags:
- python-lint
script:
- isort --check test

python_static_check:
stage: lint
tags:
- python-lint
script:
- pyright .

run_test0:
run_ne16_test:
stage: test
tags:
- gap9-sdk
artifacts:
untracked: true
script:
- cd test && pytest test.py --test-dir tests --recursive
- cd test && pytest test.py --test-dir tests --recursive -A ne16

run_neureka_test:
stage: test
tags:
- siracusa-sdk
artifacts:
untracked: true
script:
- cd test && pytest test.py --test-dir tests --recursive -A neureka
44 changes: 3 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,46 +39,8 @@ _Note: The accelerator can provide additional helper functions if needed._

## Accelerators

### NE16

Github repo [link](https://github.com/pulp-platform/ne16).

#### Implemented features

- [x] Convolution w/ kernel shape 1x1
- [x] Convolution w/ kernel shape 3x3
- [x] Depthwise convolution w/ kernel shape 3x3
- [x] Stride 1x1
- [x] Stride 2x2
- [ ] Normalization and quantization
- [x] With
- [ ] Without
- [x] Relu (w/ and w/o)
- [x] Bias (w/ and w/o)
- [ ] Per-channel shift
- [x] Per-layer shift
- [ ] Rounding
- [ ] Input type
- [x] uint8
- [ ] uint16
- [ ] Output type
- [x] int8
- [x] uint8 (only w/ Relu)
- [ ] int32
- [ ] uint32 (only w/ Relu)
- [ ] Scale type
- [x] uint8
- [ ] uint16
- [ ] uint32
- [x] Bias type
- [x] int32
- [ ] Weight type
- [x] int8
- [ ] int2-7

### Neureka

**Untested and considered broken.**
- [NE16](ne16/README.md)
- [Neureka](neureka/README.md)

## Testing

Expand All @@ -101,7 +63,7 @@ The library will follow the [Semantic Versioning](https://semver.org/).

* Luka Macan <[[email protected]](mailto:[email protected])>
* Francesco Conti <[[email protected]](mailto:[email protected])>
* Arpan Prasad <[[email protected]](mailto:[email protected])>
* Arpan Suravi Prasad <[[email protected]](mailto:[email protected])>

## License

Expand Down
8 changes: 4 additions & 4 deletions inc/pulp_nnx_ne16.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ void ne16_nnx_dispatch_wait(ne16_dev_t *dev);
/** ne16_nnx_dispatch
*
* Dispatch a task to the accelerator.
* Fails with return code 1 if the task cannot be dispatched. Otherwise returns 0.
* Fails with return code 1 if the task cannot be dispatched. Otherwise returns
* 0.
*/
int ne16_nnx_dispatch(ne16_dev_t *dev, ne16_task_t *task);

Expand All @@ -59,7 +60,6 @@ int ne16_nnx_resolve_check(ne16_dev_t *dev, ne16_task_t *task);
*/
void ne16_nnx_resolve_wait(ne16_dev_t *dev, ne16_task_t *task);


/* Additional helper functions */

/** ne16_nnx_dispatch_stride2x2
Expand All @@ -70,8 +70,8 @@ void ne16_nnx_resolve_wait(ne16_dev_t *dev, ne16_task_t *task);
* Works only if the k_out is divisible by 2.
*/
void ne16_nnx_dispatch_stride2x2(
ne16_dev_t *dev, ne16_task_t *task, const uint32_t w_in, const uint32_t k_in,
const uint32_t w_in_stride, const uint32_t k_in_stride,
ne16_dev_t *dev, ne16_task_t *task, const uint32_t w_in,
const uint32_t k_in, const uint32_t w_in_stride, const uint32_t k_in_stride,
const uint32_t h_out, const uint32_t w_out, const uint32_t k_out,
const uint32_t w_out_stride, const uint32_t k_out_stride,
const uint8_t h_ker, const uint8_t w_ker);
61 changes: 61 additions & 0 deletions inc/pulp_nnx_neureka.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Luka Macan <[email protected]>
*
* Copyright 2023 ETH Zurich and University of Bologna
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/

#include "neureka.h"
#include "neureka_siracusa_bsp.h"
#include "neureka_task.h"
#include <stdint.h>

/* PULP-NNX interface */

void neureka_nnx_init(neureka_dev_t *dev, neureka_siracusa_conf_t *conf);
void neureka_nnx_term(neureka_dev_t *dev);

/** neureka_nnx_dispatch_check
*
* Check whether you can dispatch to the accelerator.
*/
int neureka_nnx_dispatch_check(neureka_dev_t *dev);

/** neureka_nnx_dispatch_wait
*
* Block until you can dispatch to the accelerator.
*/
void neureka_nnx_dispatch_wait(neureka_dev_t *dev);

/** neureka_nnx_dispatch
*
* Dispatch a task to the accelerator.
* Fails with return code 1 if the task cannot be dispatched. Otherwise returns
* 0.
*/
int neureka_nnx_dispatch(neureka_dev_t *dev, neureka_task_t *task);

/** neureka_nnx_resolve_check
*
* Check whether the task has been resolved.
*/
int neureka_nnx_resolve_check(neureka_dev_t *dev, neureka_task_t *task);

/** neureka_nnx_resolve_wait
*
* Block until you can resolve the task.
*/
void neureka_nnx_resolve_wait(neureka_dev_t *dev, neureka_task_t *task);
37 changes: 37 additions & 0 deletions ne16/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# NE16

## Docs

- Github repo [link](https://github.com/pulp-platform/ne16).

## Implemented features

- [x] Convolution w/ kernel shape 1x1
- [x] Convolution w/ kernel shape 3x3
- [x] Depthwise convolution w/ kernel shape 3x3
- [x] Stride 2x2
- [ ] Normalization and quantization
- [x] With
- [ ] Without
- [x] Relu (w/ and w/o)
- [x] Bias (w/ and w/o)
- [ ] Per-channel shift
- [x] Per-layer shift
- [ ] Rounding
- [ ] Input type
- [x] uint8
- [ ] uint16
lukamac marked this conversation as resolved.
Show resolved Hide resolved
- [ ] Output type
- [x] int8
- [x] uint8 (only w/ Relu)
- [ ] int32
- [ ] uint32 (only w/ Relu)
- [ ] Scale type
- [x] uint8
- [ ] uint16
- [ ] uint32
- [x] Bias type
- [x] int32
- [ ] Weight type
- [x] int8
- [ ] int2-7
4 changes: 4 additions & 0 deletions ne16/gvsoc/ne16_gvsoc.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,17 @@ typedef enum ne16_gvsoc_log_level_e {
static void ne16_gvsoc_log_activate(ne16_dev_t *dev,
ne16_gvsoc_log_level_e log_level,
ne16_gvsoc_log_format_e format) {
#if __PLATFORM__ == ARCHI_PLATFORM_GVSOC
lukamac marked this conversation as resolved.
Show resolved Hide resolved
hwpe_task_reg_write(&dev->hwpe_dev, NE16_REG_GVSOC_LOG_LEVEL, log_level);
hwpe_task_reg_write(&dev->hwpe_dev, NE16_REG_GVSOC_LOG_FORMAT, format);
#endif
}

static void ne16_gvsoc_log_deactivate(ne16_dev_t *dev) {
#if __PLATFORM__ == ARCHI_PLATFORM_GVSOC
hwpe_task_reg_write(&dev->hwpe_dev, NE16_REG_GVSOC_LOG_LEVEL,
NE16_GVSOC_LOG_LEVEL_CONFIG);
#endif
}

#endif // __NE16_GVSOC_H__
18 changes: 7 additions & 11 deletions ne16/hal/ne16_task.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,7 @@ void ne16_task_set_strides(ne16_task_t *task, const uint32_t k_in,
const uint32_t num_k_in = divnceil(k_in, NE16_INPUT_CHANNEL_THROUGHPUT);

const ne16_stride_t input_stride = {
.d0 = k_in_stride,
.d1 = k_in_stride * w_in_stride,
.d2 = task->depthwise ? 0
: k_in_stride * NE16_FILTER_BUFFER_SIZE *
NE16_FILTER_BUFFER_SIZE};
.d0 = k_in_stride, .d1 = k_in_stride * w_in_stride, .d2 = 0};
task->data.cfg.input_stride = input_stride;

// WARNING: Stride works only for even output channel sizes (divisible by 2)
Expand All @@ -133,20 +129,18 @@ void ne16_task_set_strides(ne16_task_t *task, const uint32_t k_in,
task->data.cfg.weights_stride.d0 = task->weight_d0_stride * task->qw;
task->data.cfg.weights_stride.d1 =
task->weight_d0_stride * task->qw * num_k_in;
task->data.cfg.weights_stride.d2 = 0;
} else if (!task->depthwise) {
task->data.cfg.weights_stride.d0 =
NE16_FILTER_SIZE * NE16_FILTER_SIZE * task->weight_d0_stride;
task->data.cfg.weights_stride.d1 = NE16_FILTER_SIZE * NE16_FILTER_SIZE *
task->weight_d0_stride * task->qw *
num_k_in;
task->data.cfg.weights_stride.d2 = 0;
} else {
task->data.cfg.weights_stride.d0 =
NE16_FILTER_SIZE * NE16_FILTER_SIZE * task->weight_d0_stride;
task->data.cfg.weights_stride.d1 = 0;
task->data.cfg.weights_stride.d2 = 0;
}
task->data.cfg.weights_stride.d2 = 0;
}

void ne16_task_set_counters(ne16_task_t *task, const uint32_t k_in,
Expand Down Expand Up @@ -195,8 +189,9 @@ void ne16_task_set_dims(ne16_task_t *task, const uint32_t w_in,
const uint32_t k_in, const uint32_t w_in_stride,
const uint32_t k_in_stride, const uint32_t h_out,
const uint32_t w_out, const uint32_t k_out,
const uint32_t w_out_stride, const uint32_t k_out_stride,
const uint8_t padding_top, const uint8_t padding_bottom,
const uint32_t w_out_stride,
const uint32_t k_out_stride, const uint8_t padding_top,
const uint8_t padding_bottom,
const uint8_t padding_right,
const uint8_t padding_left) {
ne16_task_set_strides(task, k_in, w_in_stride, k_in_stride, w_out_stride,
Expand All @@ -220,7 +215,8 @@ void ne16_task_set_dims_stride2x2(
ne16_task_set_strides(task, k_in, w_in_stride, k_in_stride, w_out_stride,
k_out_stride);
ne16_task_set_counters(task, k_in, h_out > 1 ? 3 : 1, w_out > 1 ? 3 : 1,
k_out, h_in + padding_top >= 5 ? 0 : padding_bottom, 0);
k_out, h_in + padding_top >= 5 ? 0 : padding_bottom,
0);

const uint8_t padding_bottom_new =
(h_in + padding_top - h_ker) % stride == 0 ? 0 : padding_bottom;
Expand Down
5 changes: 3 additions & 2 deletions ne16/hal/ne16_task.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,9 @@ void ne16_task_set_dims(ne16_task_t *task, const uint32_t w_in,
const uint32_t k_in, const uint32_t w_in_stride,
const uint32_t k_in_stride, const uint32_t h_out,
const uint32_t w_out, const uint32_t k_out,
const uint32_t w_out_stride, const uint32_t k_out_stride,
const uint8_t padding_top, const uint8_t padding_bottom,
const uint32_t w_out_stride,
const uint32_t k_out_stride, const uint8_t padding_top,
const uint8_t padding_bottom,
const uint8_t padding_right,
const uint8_t padding_left);
void ne16_task_set_dims_stride2x2(
Expand Down
35 changes: 35 additions & 0 deletions neureka/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Neureka

## Docs

Github repo [link](https://github.com/siracusa-soc/ne).

## Implemented features

- [x] Convolution w/ kernel shape 1x1
- [x] Convolution w/ kernel shape 3x3
- [x] Depthwise convolution w/ kernel shape 3x3
- [ ] Normalization and quantization
- [x] With
- [ ] Without
- [x] Relu (w/ and w/o)
- [x] Bias (w/ and w/o)
- [ ] Per-channel shift
- [x] Per-layer shift
- [ ] Rounding
- [ ] Input type
- [x] uint8
- [x] int8
- [ ] Output type
- [x] int8
- [x] uint8 (only w/ Relu)
- [ ] int32
- [ ] uint32 (only w/ Relu)
- [ ] Scale type
- [x] uint8
- [ ] uint32
- [x] Bias type
- [x] int32
- [ ] Weight type
- [x] int8
- [ ] int2-7
Loading
Loading