-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
svdf s8: Fix state data overwrite (#59)
Adds unit test to verify fix as well. Co-authored-by: Måns Nilsson <mans.nilsson@arm.com>
- Loading branch information
1 parent
ac1db62
commit 61d1bb6
Showing
14 changed files
with
494 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
174 changes: 174 additions & 0 deletions
174
Tests/UnitTest/TestCases/Common/svdf_s8_weights_template.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
{ | ||
"version": 3, | ||
"operator_codes": [ | ||
{ | ||
"deprecated_builtin_code": 27, | ||
"version": 1 | ||
} | ||
], | ||
"subgraphs": [ | ||
{ | ||
"tensors": [ | ||
{ | ||
"shape": [ | ||
batches, | ||
input_size | ||
], | ||
"type": "INT8", | ||
"buffer": 0, | ||
"name": "tensor_input", | ||
"quantization": { | ||
"scale": [ | ||
input_scale | ||
], | ||
"zero_point": [ | ||
input_zp | ||
], | ||
"quantized_dimension": 0 | ||
}, | ||
"is_variable": false | ||
}, | ||
{ | ||
"shape": [ | ||
number_filters, | ||
input_size | ||
], | ||
"type": "INT8", | ||
"buffer": 1, | ||
"name": "tensor_weight_1", | ||
"quantization": { | ||
"scale": [ | ||
w_1_scale | ||
], | ||
"zero_point": [ | ||
w_1_zp | ||
], | ||
"quantized_dimension": 0 | ||
}, | ||
"is_variable": false | ||
}, | ||
{ | ||
"shape": [ | ||
number_filters, | ||
memory_size | ||
], | ||
"type": "INT8", | ||
"buffer": 2, | ||
"name": "tensor_weight_2", | ||
"quantization": { | ||
"scale": [ | ||
w_2_scale | ||
], | ||
"zero_point": [ | ||
w_2_zp | ||
], | ||
"quantized_dimension": 0 | ||
}, | ||
"is_variable": false | ||
}, | ||
{ | ||
"shape": [ | ||
number_units | ||
], | ||
"type": "INT32", | ||
"buffer": 3, | ||
"name": "tensor_bias", | ||
"quantization": { | ||
"scale": [ | ||
bias_scale | ||
], | ||
"zero_point": [ | ||
bias_zp | ||
], | ||
"quantized_dimension": 0 | ||
}, | ||
"is_variable": false | ||
}, | ||
{ | ||
"shape": [ | ||
batches, | ||
memory_sizeXnumber_filters | ||
], | ||
"type": "INT8", | ||
"buffer": 4, | ||
"name": "tensor_state", | ||
"quantization": { | ||
"scale": [ | ||
state_scale | ||
], | ||
"zero_point": [ | ||
state_zp | ||
], | ||
"quantized_dimension": 0 | ||
}, | ||
"is_variable": true | ||
}, | ||
{ | ||
"shape": [ | ||
batches, | ||
number_units | ||
], | ||
"type": "INT8", | ||
"buffer": 5, | ||
"name": "tensor_output", | ||
"quantization": { | ||
"scale": [ | ||
output_scale | ||
], | ||
"zero_point": [ | ||
output_zp | ||
], | ||
"quantized_dimension": 0 | ||
}, | ||
"is_variable": false | ||
} | ||
], | ||
"inputs": [ | ||
0 | ||
], | ||
"outputs": [ | ||
5 | ||
], | ||
"operators": [ | ||
{ | ||
"opcode_index": 0, | ||
"inputs": [ | ||
0, | ||
1, | ||
2, | ||
3, | ||
4 | ||
], | ||
"outputs": [ | ||
5 | ||
], | ||
"builtin_options_type": "SVDFOptions", | ||
"builtin_options": { | ||
"rank": rank_value, | ||
"fused_activation_function": "RELU" | ||
}, | ||
"custom_options_format": "FLEXBUFFERS" | ||
} | ||
] | ||
} | ||
], | ||
"description": "CMSIS-NN unit test model", | ||
"buffers": [ | ||
{}, | ||
{ | ||
"data": [] | ||
}, | ||
{ | ||
"data": [] | ||
}, | ||
{ | ||
"data": [] | ||
}, | ||
{ | ||
"data": [] | ||
}, | ||
{ | ||
"data": [] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// Generated by generate_test_data.py using tensorflow version 2.10.0 (Keras version 2.10.0). | ||
// Interpreter from tensorflow version 2.10.0 and revision v2.10.0-rc3-6-g359c3cdfc5f. | ||
#pragma once | ||
#include <stdint.h> | ||
|
||
const int32_t svdf_int8_biases[12] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Generated by generate_test_data.py using tensorflow version 2.10.0 (Keras version 2.10.0). | ||
// Interpreter from tensorflow version 2.10.0 and revision v2.10.0-rc3-6-g359c3cdfc5f. | ||
#pragma once | ||
#define SVDF_INT8_MULTIPLIER_IN 1717987072 | ||
#define SVDF_INT8_MULTIPLIER_OUT 1099511552 | ||
#define SVDF_INT8_SHIFT_1 -3 | ||
#define SVDF_INT8_SHIFT_2 -11 | ||
#define SVDF_INT8_IN_ACTIVATION_MIN -32768 | ||
#define SVDF_INT8_IN_ACTIVATION_MAX 32767 | ||
#define SVDF_INT8_RANK 1 | ||
#define SVDF_INT8_FEATURE_BATCHES 12 | ||
#define SVDF_INT8_TIME_BATCHES 2 | ||
#define SVDF_INT8_INPUT_SIZE 20 | ||
#define SVDF_INT8_DST_SIZE 12 | ||
#define SVDF_INT8_OUT_ACTIVATION_MIN -128 | ||
#define SVDF_INT8_OUT_ACTIVATION_MAX 127 | ||
#define SVDF_INT8_INPUT_BATCHES 1 | ||
#define SVDF_INT8_INPUT_OFFSET 0 | ||
#define SVDF_INT8_OUTPUT_OFFSET 0 |
8 changes: 8 additions & 0 deletions
8
Tests/UnitTest/TestCases/TestData/svdf_int8/input_sequence_data.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// Generated by generate_test_data.py using tensorflow version 2.10.0 (Keras version 2.10.0). | ||
// Interpreter from tensorflow version 2.10.0 and revision v2.10.0-rc3-6-g359c3cdfc5f. | ||
#pragma once | ||
#include <stdint.h> | ||
|
||
const int8_t svdf_int8_input_sequence[40] = {-23, 123, 104, 88, -47, 92, -14, -14, -90, -113, -94, -46, 121, -125, | ||
-100, -59, 69, 19, -80, 24, 86, 37, 8, 116, 113, -45, 116, 41, | ||
-1, -103, 37, 103, 88, -86, 28, 30, -121, 4, -83, -109}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// Generated by generate_test_data.py using tensorflow version 2.10.0 (Keras version 2.10.0). | ||
// Interpreter from tensorflow version 2.10.0 and revision v2.10.0-rc3-6-g359c3cdfc5f. | ||
#pragma once | ||
#include <stdint.h> | ||
|
||
const int8_t svdf_int8_state[24] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// Generated by generate_test_data.py using tensorflow version 2.10.0 (Keras version 2.10.0). | ||
// Interpreter from tensorflow version 2.10.0 and revision v2.10.0-rc3-6-g359c3cdfc5f. | ||
#include "biases_data.h" | ||
#include "config_data.h" | ||
#include "input_sequence_data.h" | ||
#include "state_data.h" | ||
#include "weights_feature_data.h" | ||
#include "weights_time_data.h" |
18 changes: 18 additions & 0 deletions
18
Tests/UnitTest/TestCases/TestData/svdf_int8/weights_feature_data.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Generated by generate_test_data.py using tensorflow version 2.10.0 (Keras version 2.10.0). | ||
// Interpreter from tensorflow version 2.10.0 and revision v2.10.0-rc3-6-g359c3cdfc5f. | ||
#pragma once | ||
#include <stdint.h> | ||
|
||
const int8_t svdf_int8_weights_feature[240] = { | ||
55, 27, 100, 94, 12, -10, 99, 108, 30, -39, 5, 56, 13, -100, -15, -81, 71, -26, 9, 56, | ||
-125, -19, -102, -2, -88, -78, -37, -4, -127, -39, -104, 45, 84, 97, -30, 109, 26, -122, 56, 46, | ||
-122, 3, 80, -53, -66, -78, 22, -81, 40, 8, 15, -44, -72, -128, -55, 34, -95, 21, -65, 80, | ||
94, -38, 33, 58, -62, 106, 111, 0, 75, -122, -116, 77, 56, 72, 113, 37, -88, 13, -6, 10, | ||
-48, 29, -62, -98, 13, 78, -86, 6, 49, 35, -70, -6, 102, 55, 31, -90, 75, -98, 104, 25, | ||
61, -95, 2, -74, 32, -93, -47, 102, -82, -48, -81, 55, -121, -63, 39, -50, 64, 46, 123, -126, | ||
50, 28, -9, -31, -87, 47, -8, -65, 98, 103, -41, 22, 14, 75, -36, -36, 28, -89, -110, 107, | ||
93, -71, 5, -54, 77, 105, 102, -115, -79, -31, -114, -47, -65, 44, -55, 61, 56, -35, -97, -12, | ||
116, 30, -28, -80, -49, 93, 108, -23, 57, 125, 56, 61, -108, 109, 2, -80, -94, -95, -67, -4, | ||
71, -64, 122, -127, 123, 86, -12, 27, 109, 93, -2, -30, -107, 117, -120, 41, -33, -7, -57, 78, | ||
6, -31, 108, 79, 86, -16, 70, -93, -47, 93, -54, 60, -85, 116, -69, -28, -120, -29, 7, -79, | ||
-89, -68, 25, 48, 19, 89, 50, 31, -105, -69, -26, -2, 116, -76, 62, -26, -9, 10, 102, 24}; |
7 changes: 7 additions & 0 deletions
7
Tests/UnitTest/TestCases/TestData/svdf_int8/weights_time_data.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// Generated by generate_test_data.py using tensorflow version 2.10.0 (Keras version 2.10.0). | ||
// Interpreter from tensorflow version 2.10.0 and revision v2.10.0-rc3-6-g359c3cdfc5f. | ||
#pragma once | ||
#include <stdint.h> | ||
|
||
const int8_t svdf_int8_weights_time[24] = {30, 32, -33, 59, -53, -32, -45, -12, -119, 87, 34, -114, | ||
-92, -45, -90, 114, -68, -116, -8, -10, 18, -55, 100, 1}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# | ||
# Copyright (C) 2023 Arm Limited or its affiliates. | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
# 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 | ||
# | ||
# 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. | ||
# | ||
|
||
add_cmsis_nn_unit_test_executable(test_arm_svdf_s8) | ||
|
||
target_sources(test_arm_svdf_s8 PRIVATE | ||
Unity/unity_test_arm_svdf_s8.c | ||
Unity/TestRunner/unity_test_arm_svdf_s8_runner.c) |
47 changes: 47 additions & 0 deletions
47
Tests/UnitTest/TestCases/test_arm_svdf_s8/Unity/unity_test_arm_svdf_s8.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* SPDX-FileCopyrightText: Copyright 2023 Arm Limited and/or its affiliates <open-source-office@arm.com> | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* 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 | ||
* | ||
* www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributd 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. | ||
*/ | ||
|
||
#include <stdbool.h> | ||
#include <stdint.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
#include "../test_arm_svdf_s8.c" | ||
#include "unity.h" | ||
|
||
#ifdef USING_FVP_CORSTONE_300 | ||
extern void uart_init(void); | ||
#endif | ||
|
||
/* This function is called from the autogenerated file. | ||
* The name must be exactly like this | ||
*/ | ||
void setUp(void) | ||
{ /* This is run before EACH TEST */ | ||
#ifdef USING_FVP_CORSTONE_300 | ||
uart_init(); | ||
#endif | ||
} | ||
|
||
/* This function is called from the autogenerated file. | ||
* The name must be exactly like this | ||
*/ | ||
void tearDown(void) {} | ||
|
||
void test_svdf_int8_arm_s8(void) { svdf_int8_arm_svdf_s8(); } |
Oops, something went wrong.