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

[onert-micro] Enable Reduce(Sum) #14521

Merged
merged 1 commit into from
Feb 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion onert-micro/onert-micro/include/pal/mcu/KernelsToBuild.lst
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ REGISTER_KERNEL(TANH, Tanh)
REGISTER_KERNEL(TRANSPOSE, Transpose)
REGISTER_KERNEL(TRANSPOSE_CONV, TransposeConv)
REGISTER_KERNEL(SOFTMAX, Softmax)
#/*REGISTER_KERNEL(SUM, Sum)*/
REGISTER_KERNEL(SUM, Sum)
REGISTER_KERNEL(SELECT_V2, SelectV2)
REGISTER_KERNEL(SVDF, SVDF)
REGISTER_KERNEL(WHILE, While)
Expand Down
132 changes: 132 additions & 0 deletions onert-micro/onert-micro/include/test_models/sum/FloatSumKernel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/*
* Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved
*
* 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.
*/

#ifndef ONERT_MICRO_TEST_MODELS_FLOAT_SUM_KERNEL_H
#define ONERT_MICRO_TEST_MODELS_FLOAT_SUM_KERNEL_H

#include "TestDataSumBase.h"

namespace onert_micro
{
namespace test_model
{
namespace sum_float
{
/*
* Sum Kernel:
*
* Input(1, 8, 8, 4)
* |
* Sum
* |
* Output(1, 8, 8, 1)
*/
const unsigned char test_kernel_model_circle[] = {
0x18, 0x00, 0x00, 0x00, 0x43, 0x49, 0x52, 0x30, 0x00, 0x00, 0x0e, 0x00, 0x14, 0x00, 0x00, 0x00,
0x0c, 0x00, 0x08, 0x00, 0x10, 0x00, 0x04, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,
0x48, 0x00, 0x00, 0x00, 0x94, 0x01, 0x00, 0x00, 0xb0, 0x01, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
0x34, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00,
0x00, 0x00, 0x06, 0x00, 0x08, 0x00, 0x04, 0x00, 0x06, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
0x04, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0xf8, 0xff, 0xff, 0xff, 0xfc, 0xff, 0xff, 0xff,
0x04, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00,
0x00, 0x00, 0x0e, 0x00, 0x18, 0x00, 0x14, 0x00, 0x10, 0x00, 0x0c, 0x00, 0x08, 0x00, 0x04, 0x00,
0x0e, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x68, 0x00, 0x00, 0x00,
0x6c, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x6d, 0x61, 0x69, 0x6e,
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00,
0x16, 0x00, 0x00, 0x00, 0x10, 0x00, 0x0c, 0x00, 0x07, 0x00, 0x08, 0x00, 0x0e, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x1b, 0x14, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00,
0x00, 0x00, 0x06, 0x00, 0x08, 0x00, 0x07, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x84, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00,
0x04, 0x00, 0x00, 0x00, 0x94, 0xff, 0xff, 0xff, 0x0c, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
0x0c, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x6f, 0x66, 0x6d, 0x00, 0x04, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x0c, 0x00, 0x14, 0x00, 0x10, 0x00, 0x0f, 0x00, 0x08, 0x00, 0x04, 0x00, 0x0c, 0x00, 0x00, 0x00,
0x10, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x1c, 0x00, 0x00, 0x00,
0x11, 0x00, 0x00, 0x00, 0x72, 0x65, 0x64, 0x75, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x69, 0x6e,
0x64, 0x69, 0x63, 0x65, 0x73, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x0c, 0x00, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x08, 0x00, 0x04, 0x00, 0x0c, 0x00, 0x00, 0x00,
0x0c, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
0x69, 0x66, 0x6d, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00,
0x08, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,
0x0c, 0x00, 0x0c, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x0c, 0x00, 0x00, 0x00,
0x4a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4a, 0x11, 0x00, 0x00, 0x00, 0x4f, 0x4e, 0x45, 0x2d,
0x74, 0x66, 0x6c, 0x69, 0x74, 0x65, 0x32, 0x63, 0x69, 0x72, 0x63, 0x6c, 0x65, 0x00, 0x00, 0x00};

const std::vector<float> input_data = {
-73.19745, -62.66789, -15.868883, -69.99245, -86.77558, -47.07158, -59.42521, 5.4639907,
-15.482954, 58.430527, 30.962307, -8.479264, 64.87171, 67.23879, 54.92413, -75.001656,
4.095402, -11.012883, 1.7135352, -13.673498, 87.62411, 88.27154, 86.84994, 61.68961,
-67.81691, -36.073383, 54.346165, -83.79197, 35.099308, -23.05919, 26.401726, 20.99549,
-68.63421, -93.027596, 20.0895, -16.020033, 57.642673, 8.66057, 39.191364, 29.198711,
-5.9334397, 11.010835, 82.77485, -34.213863, -38.869553, 16.539444, 51.105484, 25.632273,
-55.436813, -26.42026, 77.96095, -59.019154, -82.52756, -94.416176, -83.77591, 46.43875,
0.7686069, 57.346397, -89.24597, -8.594538, -98.168755, -33.18969, -41.993664, 13.660449,
50.10378, 9.801906, -4.2520585, 27.210102, 48.8715, -19.44194, 38.652195, 23.77053,
-82.0674, -93.96652, 99.148094, 22.794533, 0.5715625, 0.84766275, 87.92019, 37.35077,
-32.265865, 67.46462, -24.098558, 87.36311, 90.409134, 33.023712, -15.923093, 40.05901,
-12.006578, 31.039108, -63.882004, -73.78517, -24.940235, 30.9098, 31.745, -89.77378,
-46.777866, 58.79768, -24.669464, 96.29413, 61.62126, 45.743416, 38.30191, 71.805405,
-31.20969, 33.56755, -1.926614, 72.13441, -22.292011, -16.355177, 21.689945, 87.95895,
-98.04168, 93.35264, -12.684541, -18.105795, 30.574284, 42.890903, -94.390366, -47.013157,
-98.465126, 28.63009, -83.54015, 86.82799, 0.6768988, 6.070787, 43.308678, 1.8557712,
-73.0521, -90.86948, 43.77232, 68.301056, 66.867775, 97.34002, -59.342876, -51.359367,
17.27793, 52.223003, -3.9915564, 29.598532, 34.474148, -80.920456, -30.45005, -17.469683,
-67.02992, -34.23075, -35.53944, 61.557327, -66.91338, -94.03176, -45.88021, 97.36409,
96.45681, -32.885677, 72.40823, -62.28857, 20.948895, 1.259363, -84.97583, 60.83626,
-94.692535, -15.315798, -99.92936, 40.56625, -8.6356325, -7.3984733, 56.255993, -31.700819,
62.08311, 52.800938, 32.27374, -99.46793, -40.924038, 24.67266, -58.954403, 42.263252,
-72.13501, -58.40316, 14.619292, -43.400642, -82.13468, -47.54976, -42.642033, -8.409653,
74.90983, 97.76474, -71.152916, 83.61312, -37.22972, 21.405357, -56.848846, 90.63024,
-70.21143, -29.522697, 94.9647, 74.74478, 37.564766, -40.22343, -63.337795, -65.86191,
-48.546135, -58.20052, 36.73888, 67.78194, -43.096832, 94.7046, 9.798892, -79.97487,
-15.868657, -84.753975, 4.8745494, -18.346195, 54.9818, 75.854, 41.797707, -5.673281,
-36.31264, -73.4931, -41.090492, 6.3805137, -73.66098, 85.20992, 91.28027, -73.26658,
-92.18044, 41.29011, 5.5041995, -73.70062, -16.678818, 30.614132, 92.100555, 11.274231,
-37.915485, 34.91591, 36.32971, -37.70164, -23.708878, 19.026278, -41.71216, 67.325356,
78.23511, -43.154037, 22.667723, 30.742237, -6.086414, 17.191307, 65.828896, -40.83338,
-18.61725, 23.976517, 80.2347, -92.53064, 71.6477, -38.28841, -60.853157, 24.402542};

const std::vector<float> reference_output_data = {
-221.72667, -187.80838, 65.43062, 112.03298, -18.877445, 324.43518, -133.33609, 59.437332,
-157.59233, 134.69333, 53.63838, 54.407646, -62.91527, -214.28088, -39.725502, -159.69167,
82.86372, 91.85229, -54.091293, 126.690186, 98.46331, 147.56876, -118.63464, -52.059216,
83.64448, 217.472, 72.56565, 71.00171, -35.479378, -67.93834, -66.547195, 51.912132,
-51.84819, 53.505547, 95.10791, -94.36604, -75.24278, -109.46126, 73.690796, -1.9313087,
-169.37143, 8.521067, 47.689857, -32.942528, -159.31952, -180.73613, 185.13477, 17.957031,
69.97535, -131.85837, -2.2258453, -18.56821, -114.094284, 166.96024, -144.51573, 29.562637,
-119.086754, 117.310104, -4.3715096, 20.930595, 88.49103, 36.10041, -6.9366684, -3.0913277};

} // namespace sum_float

class TestDataFloatSum : public TestDataSumBase<float>
{
public:
TestDataFloatSum()
{
_input_data = sum_float::input_data;
_reference_output_data = sum_float::reference_output_data;
_test_kernel_model_circle = sum_float::test_kernel_model_circle;
}

~TestDataFloatSum() override = default;
};

} // namespace test_model
} // namespace onert_micro

#endif // ONERT_MICRO_TEST_MODELS_FLOAT_SUM_KERNEL_H
91 changes: 91 additions & 0 deletions onert-micro/onert-micro/include/test_models/sum/NegSumKernel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved
*
* 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.
*/

#ifndef ONERT_MICRO_TEST_MODELS_NEG_SUM_KERNEL_H
#define ONERT_MICRO_TEST_MODELS_NEG_SUM_KERNEL_H

#include "TestDataSumBase.h"

namespace onert_micro
{
namespace test_model
{
namespace neg_input_output_type_mismatch_sum_kernel
{
/*
* Sum Kernel with input output type mismatch:
*
* Input(1, 8, 8, 4) - Float32
* |
* Sum
* |
* Output(1, 8, 8, 1) - Int32
*/
const unsigned char test_kernel_model_circle[] = {
0x18, 0x00, 0x00, 0x00, 0x43, 0x49, 0x52, 0x30, 0x00, 0x00, 0x0e, 0x00, 0x14, 0x00, 0x00, 0x00,
0x0c, 0x00, 0x08, 0x00, 0x10, 0x00, 0x04, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,
0x48, 0x00, 0x00, 0x00, 0x98, 0x01, 0x00, 0x00, 0xb4, 0x01, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
0x34, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00,
0x00, 0x00, 0x06, 0x00, 0x08, 0x00, 0x04, 0x00, 0x06, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
0x04, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xf8, 0xff, 0xff, 0xff, 0xfc, 0xff, 0xff, 0xff,
0x04, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00,
0x00, 0x00, 0x0e, 0x00, 0x18, 0x00, 0x14, 0x00, 0x10, 0x00, 0x0c, 0x00, 0x08, 0x00, 0x04, 0x00,
0x0e, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x68, 0x00, 0x00, 0x00,
0x6c, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x6d, 0x61, 0x69, 0x6e,
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00,
0x16, 0x00, 0x00, 0x00, 0x10, 0x00, 0x0c, 0x00, 0x07, 0x00, 0x08, 0x00, 0x0e, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x1b, 0x14, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00,
0x00, 0x00, 0x06, 0x00, 0x08, 0x00, 0x07, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x88, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00,
0x04, 0x00, 0x00, 0x00, 0xd0, 0xff, 0xff, 0xff, 0x10, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x02, 0x0c, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x6f, 0x66, 0x6d, 0x00,
0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x14, 0x00, 0x10, 0x00, 0x0f, 0x00, 0x08, 0x00, 0x04, 0x00,
0x0c, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
0x1c, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x72, 0x65, 0x64, 0x75, 0x63, 0x74, 0x69, 0x6f,
0x6e, 0x5f, 0x69, 0x6e, 0x64, 0x69, 0x63, 0x65, 0x73, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x08, 0x00, 0x04, 0x00,
0x0c, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00,
0x03, 0x00, 0x00, 0x00, 0x69, 0x66, 0x6d, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x08, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x10, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x0c, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00,
0x0c, 0x00, 0x00, 0x00, 0x4a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4a, 0x11, 0x00, 0x00, 0x00,
0x4f, 0x4e, 0x45, 0x2d, 0x74, 0x66, 0x6c, 0x69, 0x74, 0x65, 0x32, 0x63, 0x69, 0x72, 0x63, 0x6c,
0x65, 0x00, 0x00, 0x00};
} // namespace neg_input_output_type_mismatch_sum_kernel

class NegTestDataInputOutputTypeMismatchSumKernel : public NegTestDataBase
{
public:
NegTestDataInputOutputTypeMismatchSumKernel()
{
_test_kernel_model_circle = neg_input_output_type_mismatch_sum_kernel::test_kernel_model_circle;
}

~NegTestDataInputOutputTypeMismatchSumKernel() override = default;

const unsigned char *get_model_ptr() override final { return _test_kernel_model_circle; }

protected:
const unsigned char *_test_kernel_model_circle;
};

} // namespace test_model
} // namespace onert_micro

#endif // ONERT_MICRO_TEST_MODELS_NEG_TANH_KERNEL_H
60 changes: 60 additions & 0 deletions onert-micro/onert-micro/include/test_models/sum/TestDataSumBase.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved
*
* 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.
*/

#ifndef ONERT_MICRO_TEST_MODELS_SUM_KERNEL_BASE_H
#define ONERT_MICRO_TEST_MODELS_SUM_KERNEL_BASE_H

#include "test_models/TestDataBase.h"

namespace onert_micro
{
namespace test_model
{

template <typename T> class TestDataSumBase : public TestDataBase<T>
{
public:
TestDataSumBase() = default;

const unsigned char *get_model_ptr() override final { return _test_kernel_model_circle; }

const std::vector<T> &get_input_data_by_index(int i) override final
{
switch (i)
{
case 0:
return _input_data;
default:
assert(false && "Wrong input index");
}
}

const std::vector<T> &get_output_data_by_index(int i) override final
{
assert(i == 0);
return _reference_output_data;
}

protected:
std::vector<T> _input_data;
std::vector<T> _reference_output_data;
const unsigned char *_test_kernel_model_circle;
};

} // namespace test_model
} // namespace onert_micro

#endif // ONERT_MICRO_TEST_MODELS_SUM_KERNEL_BASE_H
Loading