From d96113544a7c1c47d5e3f3f19c49dea5fdc12576 Mon Sep 17 00:00:00 2001 From: Chunseok Lee Date: Mon, 19 Aug 2024 11:35:28 +0900 Subject: [PATCH] [onert-micro] S8 Test for Logisitic - Add test for S8 Logistic - Fix logistic kernel by syncing with tflite DCO-1.0-Signed-off-by: Chunseok Lee --- .../include/pal/common/PALLogistic.h | 2 +- .../test_models/logistic/S8LogisticKernel.h | 93 +++++++++++++++++++ .../execute/kernels/tests/Logistic.test.cpp | 9 ++ 3 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 onert-micro/onert-micro/include/test_models/logistic/S8LogisticKernel.h diff --git a/onert-micro/onert-micro/include/pal/common/PALLogistic.h b/onert-micro/onert-micro/include/pal/common/PALLogistic.h index de0f4f94fdd..298515531bc 100644 --- a/onert-micro/onert-micro/include/pal/common/PALLogistic.h +++ b/onert-micro/onert-micro/include/pal/common/PALLogistic.h @@ -96,7 +96,7 @@ OMStatus inline Logistic(const int flat_size, const int8_t *input_data, float in result = 1.f / (1.f + std::exp(-val)); } // Requantize - int8_t output = static_cast(result / output_scale + output_zero_point); + int8_t output = static_cast(std::round(result / output_scale) + output_zero_point); output_data[i] = output; } return Ok; diff --git a/onert-micro/onert-micro/include/test_models/logistic/S8LogisticKernel.h b/onert-micro/onert-micro/include/test_models/logistic/S8LogisticKernel.h new file mode 100644 index 00000000000..333fe228ab9 --- /dev/null +++ b/onert-micro/onert-micro/include/test_models/logistic/S8LogisticKernel.h @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2024 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_S8_LOGISTIC_KERNEL_H +#define ONERT_MICRO_TEST_MODELS_S8_LOGISTIC_KERNEL_H + +#include "TestDataLogisticBase.h" + +namespace onert_micro +{ +namespace test_model +{ +namespace logistic_s8 +{ +/* + * Logistic Kernel: + * + * Input(1, 1, 2, 2) : zp = -128, scale 1/256.0 by tflite quant spec + * | + * Logistic + * | + * Output(1, 1, 2, 2) zp = -128, scale 1/256.0 by tflite quant spec + */ +const unsigned char test_kernel_model_circle[] = { + 0x1c, 0x00, 0x00, 0x00, 0x43, 0x49, 0x52, 0x30, 0x00, 0x00, 0x00, 0x00, 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, 0xa8, 0x01, 0x00, 0x00, 0xc4, 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, 0x48, 0x00, 0x00, 0x00, 0x4c, 0x00, 0x00, 0x00, 0x50, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x08, 0x00, 0x04, 0x00, + 0x0a, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x0c, 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, + 0x84, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x92, 0xff, 0xff, 0xff, 0x14, 0x00, 0x00, 0x00, + 0x48, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x44, 0x00, 0x00, 0x00, + 0x84, 0xff, 0xff, 0xff, 0x2c, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3b, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x6f, 0x66, 0x6d, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x18, 0x00, 0x14, 0x00, 0x13, 0x00, 0x0c, 0x00, + 0x08, 0x00, 0x04, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x58, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x54, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x14, 0x00, + 0x04, 0x00, 0x08, 0x00, 0x0c, 0x00, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, + 0x24, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x80, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x80, 0x3b, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x69, 0x66, 0x6d, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 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, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, + 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 = {-10, -5, 8, 99}; +const std::vector reference_output_data = {29, 30, 33, 53}; + +} // namespace logistic_s8 + +class TestDataS8Logistic : public TestDataLogisticBase +{ +public: + TestDataS8Logistic() + { + _input_data = logistic_s8::input_data; + _reference_output_data = logistic_s8::reference_output_data; + _test_kernel_model_circle = logistic_s8::test_kernel_model_circle; + } + + ~TestDataS8Logistic() override = default; +}; + +} // namespace test_model +} // namespace onert_micro + +#endif // ONERT_MICRO_TEST_MODELS_S8_LOGISTIC_KERNEL_H diff --git a/onert-micro/onert-micro/src/execute/kernels/tests/Logistic.test.cpp b/onert-micro/onert-micro/src/execute/kernels/tests/Logistic.test.cpp index 9b82cadae50..60d2efca403 100644 --- a/onert-micro/onert-micro/src/execute/kernels/tests/Logistic.test.cpp +++ b/onert-micro/onert-micro/src/execute/kernels/tests/Logistic.test.cpp @@ -16,6 +16,7 @@ #include "execute/OMTestUtils.h" #include "test_models/logistic/FloatLogisticKernel.h" +#include "test_models/logistic/S8LogisticKernel.h" #include "test_models/logistic/NegLogisticKernel.h" namespace onert_micro @@ -40,6 +41,14 @@ TEST_F(LogisticTest, Float_P) EXPECT_THAT(output_data_vector, test_data_kernel.get_output_data_by_index(0)); } +TEST_F(LogisticTest, S8_P) +{ + onert_micro::test_model::TestDataS8Logistic test_data_kernel; + std::vector output_data_vector = + onert_micro::execute::testing::checkKernel(1, &test_data_kernel); + EXPECT_THAT(output_data_vector, test_data_kernel.get_output_data_by_index(0)); +} + TEST_F(LogisticTest, Input_output_type_mismatch_NEG) { onert_micro::test_model::NegTestDataInputOutputTypeMismatchLogisticKernel test_data_kernel;