1 /*
2  * SPDX-FileCopyrightText: Copyright 2010-2022 Arm Limited and/or its affiliates <open-source-office@arm.com>
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Licensed under the Apache License, Version 2.0 (the License); you may
7  * not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an AS IS BASIS, WITHOUT
14  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
19 #include "unity.h"
20 #include <arm_nnfunctions.h>
21 
22 #include "../TestData/softmax/test_data.h"
23 #include "../Utils/validate.h"
24 
25 #define REPEAT_NUM (2)
26 
softmax_arm_softmax_s8(void)27 void softmax_arm_softmax_s8(void)
28 {
29     const int32_t num_rows = SOFTMAX_NUM_ROWS;
30     const int32_t row_size = SOFTMAX_ROW_SIZE;
31     const int32_t mult = SOFTMAX_INPUT_MULT;
32     const int32_t shift = SOFTMAX_INPUT_LEFT_SHIFT;
33     const int32_t diff_min = SOFTMAX_DIFF_MIN;
34     const int8_t *input_data = softmax_input;
35     int8_t output[SOFTMAX_DST_SIZE];
36 
37     for (int i = 0; i < REPEAT_NUM; i++)
38     {
39         arm_softmax_s8(input_data, num_rows, row_size, mult, shift, diff_min, output);
40         TEST_ASSERT_TRUE(validate(output, softmax_output_ref, SOFTMAX_DST_SIZE));
41     }
42 }
43 
softmax_invalid_diff_min_arm_softmax_s8(void)44 void softmax_invalid_diff_min_arm_softmax_s8(void)
45 {
46     const int32_t num_rows = SOFTMAX_NUM_ROWS;
47     const int32_t row_size = SOFTMAX_ROW_SIZE;
48     const int32_t mult = SOFTMAX_INPUT_MULT;
49     const int32_t shift = SOFTMAX_INPUT_LEFT_SHIFT;
50     const int32_t diff_min = 0x7FFFFFFF;
51     const int8_t *input_data = softmax_input;
52     int8_t output[SOFTMAX_DST_SIZE];
53 
54     int8_t *softmax_expect_invalid_output = malloc(SOFTMAX_DST_SIZE);
55     for (int i = 0; i < SOFTMAX_DST_SIZE; i++)
56     {
57         softmax_expect_invalid_output[i] = -128;
58     }
59 
60     for (int i = 0; i < REPEAT_NUM; i++)
61     {
62         arm_softmax_s8(input_data, num_rows, row_size, mult, shift, diff_min, output);
63         TEST_ASSERT_TRUE(validate(output, softmax_expect_invalid_output, SOFTMAX_DST_SIZE));
64     }
65     free(softmax_expect_invalid_output);
66 }
67