From 4f7ae9b712050c252d880e5e514eb38c45e97fcd Mon Sep 17 00:00:00 2001 From: Evgenii Maltsev Date: Tue, 10 Oct 2023 18:31:59 +0300 Subject: [PATCH] [onert-micro] This PR adds support for the Squeeze kernel. Supporting kernels. Support for the Squeeze kernel for the [issue](https://github.com/Samsung/ONE/issues/10933) ONE-DCO-1.0-Signed-off-by: Evgenii Maltsev e.maltsev@samsung.com --- .../test_models/squeeze/FloatSqueezeKernel.h | 144 +++++++++++++++++ .../test_models/squeeze/NegSqueezeKernel.h | 148 ++++++++++++++++++ .../test_models/squeeze/TestDataSqueezeBase.h | 60 +++++++ .../pal/mcu/KernelsToBuild.lst | 1 + .../luci-interpreter/src/kernels/Squeeze.cpp | 80 ++++++---- .../src/kernels/Squeeze.test.cpp | 99 ++++++++---- 6 files changed, 468 insertions(+), 64 deletions(-) create mode 100644 onert-micro/luci-interpreter/include/luci_interpreter/test_models/squeeze/FloatSqueezeKernel.h create mode 100644 onert-micro/luci-interpreter/include/luci_interpreter/test_models/squeeze/NegSqueezeKernel.h create mode 100644 onert-micro/luci-interpreter/include/luci_interpreter/test_models/squeeze/TestDataSqueezeBase.h diff --git a/onert-micro/luci-interpreter/include/luci_interpreter/test_models/squeeze/FloatSqueezeKernel.h b/onert-micro/luci-interpreter/include/luci_interpreter/test_models/squeeze/FloatSqueezeKernel.h new file mode 100644 index 00000000000..021b6855ab0 --- /dev/null +++ b/onert-micro/luci-interpreter/include/luci_interpreter/test_models/squeeze/FloatSqueezeKernel.h @@ -0,0 +1,144 @@ +/* + * 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 LUCI_INTERPRETER_TEST_MODELS_FLOAT_SQUEEZE_KERNEL_H +#define LUCI_INTERPRETER_TEST_MODELS_FLOAT_SQUEEZE_KERNEL_H + +#include "TestDataSqueezeBase.h" + +namespace luci_interpreter +{ +namespace test_kernel +{ + +namespace squeeze_float +{ +/* + * Squeeze Kernel: parameters - squeeze_dims [0,3] + * + * Input(1, 4, 5, 1) + * | + * Squeeze + * | + * Output(4, 5) + */ +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, + 0x2c, 0x00, 0x00, 0x00, 0x34, 0x01, 0x00, 0x00, 0x50, 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x18, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x04, 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, + 0x70, 0x00, 0x00, 0x00, 0x74, 0x00, 0x00, 0x00, 0x78, 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, 0x1e, 0x14, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, + 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x08, 0x00, 0x04, 0x00, 0x06, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xdc, 0xff, 0xff, 0xff, + 0x0c, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x6f, 0x66, 0x6d, 0x00, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x05, 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, 0x04, 0x00, 0x00, 0x00, + 0x05, 0x00, 0x00, 0x00, 0x01, 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, + 0x2b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2b, 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 input_data = {-1, -2, -3, -4, -5, -6, -7, -8, -9, -10, + 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}; + +const std::vector reference_output_data = {-1, -2, -3, -4, -5, -6, -7, -8, -9, -10, + 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}; + +} // namespace squeeze_float + +namespace squeeze_float_no_param +{ +/* + * Squeeze Kernel: no parameters + * + * Input(1, 4, 5, 1) + * | + * Squeeze + * | + * Output(4, 5) + */ +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, + 0x2c, 0x00, 0x00, 0x00, 0x2c, 0x01, 0x00, 0x00, 0x48, 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x18, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x04, 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, 0x1e, 0x14, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, + 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x08, 0x00, 0x04, 0x00, 0x06, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0xdc, 0xff, 0xff, 0xff, 0x0c, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x0c, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x6f, 0x66, 0x6d, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x05, 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, 0x04, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x01, 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, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2b, + 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 input_data = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, + 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}; + +const std::vector reference_output_data = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, + 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}; + +} // namespace squeeze_float_no_param + +class TestDataFloatSqueeze : public TestDataSqueezeBase +{ +public: + TestDataFloatSqueeze(bool no_param = false) + { + if (no_param) + { + _input_data = squeeze_float_no_param::input_data; + _reference_output_data = squeeze_float_no_param::reference_output_data; + _test_kernel_model_circle = squeeze_float_no_param::test_kernel_model_circle; + } + else + { + _input_data = squeeze_float_no_param::input_data; + _reference_output_data = squeeze_float_no_param::reference_output_data; + _test_kernel_model_circle = squeeze_float_no_param::test_kernel_model_circle; + } + } + + ~TestDataFloatSqueeze() override = default; +}; + +} // namespace test_kernel +} // namespace luci_interpreter + +#endif // LUCI_INTERPRETER_TEST_MODELS_FLOAT_SQUEEZE_KERNEL_H diff --git a/onert-micro/luci-interpreter/include/luci_interpreter/test_models/squeeze/NegSqueezeKernel.h b/onert-micro/luci-interpreter/include/luci_interpreter/test_models/squeeze/NegSqueezeKernel.h new file mode 100644 index 00000000000..8d05fe74076 --- /dev/null +++ b/onert-micro/luci-interpreter/include/luci_interpreter/test_models/squeeze/NegSqueezeKernel.h @@ -0,0 +1,148 @@ +/* + * 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 LUCI_INTERPRETER_TEST_MODELS_NEG_FLOAT_SQUEEZE_KERNEL_H +#define LUCI_INTERPRETER_TEST_MODELS_NEG_FLOAT_SQUEEZE_KERNEL_H + +#include "TestDataSqueezeBase.h" + +namespace luci_interpreter +{ +namespace test_kernel +{ + +namespace neg_wrong_parameters_squeeze_float +{ +/* + * Squeeze Kernel: parameters - squeeze_dims [0,1,3] + * + * Input(1, 4, 5, 1) + * | + * Squeeze + * | + * Output(4, 5) + */ +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, + 0x2c, 0x00, 0x00, 0x00, 0x38, 0x01, 0x00, 0x00, 0x54, 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x18, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x04, 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, + 0x74, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, 0x00, 0x7c, 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, 0x1e, 0x14, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, + 0x2c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x08, 0x00, 0x04, 0x00, 0x06, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0xdc, 0xff, 0xff, 0xff, 0x0c, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x6f, 0x66, 0x6d, 0x00, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x05, 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, + 0x04, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x01, 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, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2b, 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_wrong_parameters_squeeze_float + +namespace neg_input_otput_mismatch_squeeze_float +{ +/* + * Squeeze Kernel: parameters - squeeze_dims [0,3] + * + * Input(1, 4, 5, 1) + * | + * Squeeze + * | + * Output(4, 4) + */ +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, 0x2c, 0x00, 0x00, 0x00, 0x34, 0x01, 0x00, 0x00, 0x50, 0x01, 0x00, 0x00, 0x03, + 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x04, 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, 0x70, 0x00, 0x00, 0x00, 0x74, 0x00, 0x00, 0x00, + 0x78, 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, 0x1e, 0x14, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x06, 0x00, 0x08, 0x00, 0x04, 0x00, 0x06, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, + 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, + 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, + 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xdc, 0xff, 0xff, + 0xff, 0x0c, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x03, 0x00, + 0x00, 0x00, 0x6f, 0x66, 0x6d, 0x00, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, + 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, 0x04, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x01, 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, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x2b, 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_otput_mismatch_squeeze_float + +class NegTestDataWrongParamFloatSqueeze : public NegTestDataBase +{ +public: + NegTestDataWrongParamFloatSqueeze() + { + + _test_kernel_model_circle = neg_wrong_parameters_squeeze_float::test_kernel_model_circle; + } + + ~NegTestDataWrongParamFloatSqueeze() override = default; + + const unsigned char *get_model_ptr() override final { return _test_kernel_model_circle; } + +protected: + const unsigned char *_test_kernel_model_circle; +}; + +class NegTestIOMismatchParamFloatSqueeze : public NegTestDataBase +{ +public: + NegTestIOMismatchParamFloatSqueeze() + { + _test_kernel_model_circle = neg_input_otput_mismatch_squeeze_float::test_kernel_model_circle; + } + + ~NegTestIOMismatchParamFloatSqueeze() 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_kernel +} // namespace luci_interpreter + +#endif // LUCI_INTERPRETER_TEST_MODELS_NEG_FLOAT_SQUEEZE_KERNEL_H diff --git a/onert-micro/luci-interpreter/include/luci_interpreter/test_models/squeeze/TestDataSqueezeBase.h b/onert-micro/luci-interpreter/include/luci_interpreter/test_models/squeeze/TestDataSqueezeBase.h new file mode 100644 index 00000000000..70e9bde1489 --- /dev/null +++ b/onert-micro/luci-interpreter/include/luci_interpreter/test_models/squeeze/TestDataSqueezeBase.h @@ -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 LUCI_INTERPRETER_TEST_MODELS_SQUEEZE_KERNEL_BASE_H +#define LUCI_INTERPRETER_TEST_MODELS_SQUEEZE_KERNEL_BASE_H + +#include "luci_interpreter/test_models/TestDataBase.h" + +namespace luci_interpreter +{ +namespace test_kernel +{ + +template class TestDataSqueezeBase : public TestDataBase +{ +public: + TestDataSqueezeBase() = default; + + const unsigned char *get_model_ptr() override final { return _test_kernel_model_circle; } + + const std::vector &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 &get_output_data_by_index(int i) override final + { + assert(i == 0); + return _reference_output_data; + } + +protected: + std::vector _input_data; + std::vector _reference_output_data; + const unsigned char *_test_kernel_model_circle; +}; + +} // namespace test_kernel +} // namespace luci_interpreter + +#endif // LUCI_INTERPRETER_TEST_MODELS_SQUEEZE_KERNEL_BASE_H diff --git a/onert-micro/luci-interpreter/pal/mcu/KernelsToBuild.lst b/onert-micro/luci-interpreter/pal/mcu/KernelsToBuild.lst index 2ab702fefa1..8045e717891 100644 --- a/onert-micro/luci-interpreter/pal/mcu/KernelsToBuild.lst +++ b/onert-micro/luci-interpreter/pal/mcu/KernelsToBuild.lst @@ -81,3 +81,4 @@ REGISTER_KERNEL(RESIZE_BILINEAR, ResizeBilinear) REGISTER_KERNEL(RSQRT, Rsqrt) REGISTER_KERNEL(NEG, Neg) REGISTER_KERNEL(ZEROS_LIKE, ZerosLike) +REGISTER_KERNEL(SQUEEZE, Squeeze) diff --git a/onert-micro/luci-interpreter/src/kernels/Squeeze.cpp b/onert-micro/luci-interpreter/src/kernels/Squeeze.cpp index 9736dce3aaa..581b5874382 100644 --- a/onert-micro/luci-interpreter/src/kernels/Squeeze.cpp +++ b/onert-micro/luci-interpreter/src/kernels/Squeeze.cpp @@ -1,6 +1,5 @@ /* - * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved - * Copyright 2018 The TensorFlow Authors. All Rights Reserved. + * 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. @@ -15,24 +14,36 @@ * limitations under the License. */ -#include "kernels/Squeeze.h" - +#include "Builders.h" #include "kernels/Utils.h" +#include "SISOKernel.h" + +#include namespace luci_interpreter { -namespace kernels -{ -Squeeze::Squeeze(const Tensor *input, Tensor *output, const SqueezeParams ¶ms) - : KernelWithParams({input}, {output}, params) +void configure_kernel_CircleSqueeze(const circle::Operator *cur_op, BaseRuntimeGraph *runtime_graph) { -} + kernels::SISOKernel kernel(cur_op, runtime_graph); -void Squeeze::configure() -{ - int input_num_dims = input()->shape().num_dims(); - int num_squeeze_dims = params().squeeze_dims.size(); + assert(cur_op->inputs()->size() == 1); + + const circle::Tensor *input = kernel.input(); + const circle::Tensor *output = kernel.output(); + + assert(Tensor::num_elements(input) == Tensor::num_elements(output)); + + const uint8_t *input_data = runtime_graph->getDataByTensor(input); + uint8_t *output_data = runtime_graph->getDataByTensor(output); + + int input_num_dims = kernels::getTensorShape(input).dimensionsCount(); + + // Get parameters + const circle::SqueezeOptions *op_params = cur_op->builtin_options_as_SqueezeOptions(); + + // Verification of the Squeeze parameters + int num_squeeze_dims = op_params->squeeze_dims()->size(); assert(input_num_dims <= 8); bool should_squeeze[8] = {false}; int num_squeezed_dims = 0; @@ -40,7 +51,8 @@ void Squeeze::configure() { for (int idx = 0; idx < input_num_dims; ++idx) { - if (input()->shape().dim(idx) == 1) + + if (kernels::getTensorShape(input).dims(idx) == 1) { should_squeeze[idx] = true; ++num_squeezed_dims; @@ -51,35 +63,37 @@ void Squeeze::configure() { for (int idx = 0; idx < num_squeeze_dims; ++idx) { - int current = params().squeeze_dims[idx] < 0 ? params().squeeze_dims[idx] + input_num_dims - : params().squeeze_dims[idx]; - assert(current >= 0 && current < input_num_dims && input()->shape().dim(current) == 1); + int current = (*op_params->squeeze_dims())[idx] < 0 + ? (*op_params->squeeze_dims())[idx] + input_num_dims + : (*op_params->squeeze_dims())[idx]; + assert(current >= 0 && current < input_num_dims && + kernels::getTensorShape(input).dims(current) == 1); if (!should_squeeze[current]) ++num_squeezed_dims; should_squeeze[current] = true; } } - // TODO: enable it only if kernel with dynamic shapes - Shape output_shape(input_num_dims - num_squeezed_dims); - for (int in_idx = 0, out_idx = 0; in_idx < input_num_dims; ++in_idx) - { - if (!should_squeeze[in_idx]) - { - output_shape.dim(out_idx++) = input()->shape().dim(in_idx); - } - } - output()->resize(output_shape); } -void Squeeze::execute() const +void execute_kernel_CircleSqueeze(const circle::Operator *cur_op, BaseRuntimeGraph *runtime_graph) { - assert(input()->shape().num_elements() == output()->shape().num_elements()); + kernels::SISOKernel kernel(cur_op, runtime_graph); + + assert(cur_op->inputs()->size() == 1); + + const circle::Tensor *input = kernel.input(); + const circle::Tensor *output = kernel.output(); + + const uint8_t *input_data = runtime_graph->getDataByTensor(input); + uint8_t *output_data = runtime_graph->getDataByTensor(output); + + assert(input_data != nullptr); + assert(output_data != nullptr); + + assert(Tensor::num_elements(input) == Tensor::num_elements(output)); - const auto *input_data = input()->data(); - auto *output_data = output()->data(); std::memcpy(output_data, input_data, - getDataTypeSize(input()->element_type()) * input()->shape().num_elements()); + getDataTypeSize(Tensor::element_type(input)) * Tensor::num_elements(input)); } -} // namespace kernels } // namespace luci_interpreter diff --git a/onert-micro/luci-interpreter/src/kernels/Squeeze.test.cpp b/onert-micro/luci-interpreter/src/kernels/Squeeze.test.cpp index 1bc0b6459e2..8aff882c14a 100644 --- a/onert-micro/luci-interpreter/src/kernels/Squeeze.test.cpp +++ b/onert-micro/luci-interpreter/src/kernels/Squeeze.test.cpp @@ -14,9 +14,10 @@ * limitations under the License. */ -#include "kernels/Squeeze.h" #include "kernels/TestUtils.h" -#include "luci_interpreter/TestMemoryManager.h" +#include "loader/ModuleLoader.h" +#include "luci_interpreter/test_models/squeeze/FloatSqueezeKernel.h" +#include "luci_interpreter/test_models/squeeze/NegSqueezeKernel.h" namespace luci_interpreter { @@ -27,46 +28,82 @@ namespace using namespace testing; -template -void Check(std::initializer_list input_shape, std::initializer_list output_shape, - std::initializer_list input_data, std::initializer_list output_data, - std::initializer_list squeeze_dims) +class SqueezeTest : public ::testing::Test { - std::unique_ptr memory_manager = std::make_unique(); + // Do nothing +}; + +template std::vector checkKernel(test_kernel::TestDataBase *test_data_base) +{ + MemoryManager memory_manager{}; + RuntimeModule runtime_module{}; + bool dealloc_input = true; + + // Load model with single op + auto *model_data_raw = reinterpret_cast(test_data_base->get_model_ptr()); + ModuleLoader::load(&runtime_module, &memory_manager, model_data_raw, dealloc_input); - constexpr DataType element_type = getElementType(); - Tensor input_tensor = - makeInputTensor(input_shape, input_data, memory_manager.get()); - Tensor output_tensor = makeOutputTensor(element_type); + auto *main_runtime_graph = runtime_module.getMainGraph(); + assert(main_runtime_graph->getNumOfInputTensors() == 1); - SqueezeParams params{}; - params.squeeze_dims = squeeze_dims; + // Set input data + { + auto *input_tensor_data = reinterpret_cast(main_runtime_graph->configureGraphInput(0)); + std::copy(test_data_base->get_input_data_by_index(0).begin(), + test_data_base->get_input_data_by_index(0).end(), input_tensor_data); + } - Squeeze kernel(&input_tensor, &output_tensor, params); - kernel.configure(); - memory_manager->allocate_memory(output_tensor); - kernel.execute(); + runtime_module.execute(); - EXPECT_THAT(extractTensorData(output_tensor), ::testing::ElementsAreArray(output_data)); - EXPECT_THAT(extractTensorShape(output_tensor), ::testing::ElementsAreArray(output_shape)); + assert(main_runtime_graph->getNumOfOutputTensors() == 1); + + T *output_data = reinterpret_cast(main_runtime_graph->getOutputDataByIndex(0)); + const size_t num_elements = (main_runtime_graph->getOutputDataSizeByIndex(0) / sizeof(T)); + std::vector output_data_vector(output_data, output_data + num_elements); + return output_data_vector; } -template class SqueezeTest : public ::testing::Test +TEST_F(SqueezeTest, Float_P) { -}; + test_kernel::TestDataFloatSqueeze test_data_kernel(false); + std::vector output_data_vector = checkKernel(&test_data_kernel); -using DataTypes = ::testing::Types; -TYPED_TEST_SUITE(SqueezeTest, DataTypes); + EXPECT_THAT(output_data_vector, + FloatArrayNear(test_data_kernel.get_output_data_by_index(0), 0.0001f)); +} -TYPED_TEST(SqueezeTest, TotalTest) +TEST_F(SqueezeTest, Float_No_Param_P) { - Check( - /*input_shape=*/{1, 24, 1}, /*output_shape=*/{24}, - /*input_data=*/{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, - 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24}, - /*output_data=*/{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, - 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24}, - {-1, 0}); + test_kernel::TestDataFloatSqueeze test_data_kernel(true); + std::vector output_data_vector = checkKernel(&test_data_kernel); + + EXPECT_THAT(output_data_vector, + FloatArrayNear(test_data_kernel.get_output_data_by_index(0), 0.0001f)); +} + +TEST_F(SqueezeTest, Input_output_type_mismatch_NEG) +{ + test_kernel::NegTestIOMismatchParamFloatSqueeze test_data_kernel; + MemoryManager memory_manager{}; + RuntimeModule runtime_module{}; + bool dealloc_input = true; + // Load model with single op + auto *model_data_raw = reinterpret_cast(test_data_kernel.get_model_ptr()); + EXPECT_DEATH(ModuleLoader::load(&runtime_module, &memory_manager, model_data_raw, dealloc_input), + ""); +} + +TEST_F(SqueezeTest, Wrong_Param_NEG) +{ + test_kernel::NegTestDataWrongParamFloatSqueeze test_data_kernel; + MemoryManager memory_manager{}; + RuntimeModule runtime_module{}; + bool dealloc_input = true; + // Load model with single op + auto *model_data_raw = reinterpret_cast(test_data_kernel.get_model_ptr()); + + EXPECT_DEATH(ModuleLoader::load(&runtime_module, &memory_manager, model_data_raw, dealloc_input), + ""); } } // namespace