diff --git a/onert-micro/onert-micro/include/pal/cmsisnn/KernelsToBuild.lst b/onert-micro/onert-micro/include/pal/cmsisnn/KernelsToBuild.lst index 56c7822d564..f3fba6542af 100644 --- a/onert-micro/onert-micro/include/pal/cmsisnn/KernelsToBuild.lst +++ b/onert-micro/onert-micro/include/pal/cmsisnn/KernelsToBuild.lst @@ -85,3 +85,5 @@ REGISTER_KERNEL(SOFTMAX, Softmax) #/*REGISTER_KERNEL(ZEROS_LIKE, ZerosLike)*/ #/*REGISTER_KERNEL(SQUEEZE, Squeeze)*/ #/*REGISTER_KERNEL(UNPACK, Unpack)*/ +REGISTER_KERNEL(RELU, Relu) +REGISTER_KERNEL(RELU6, Relu6) diff --git a/onert-micro/onert-micro/include/pal/cmsisnn/PALRelu.h b/onert-micro/onert-micro/include/pal/cmsisnn/PALRelu.h new file mode 100644 index 00000000000..b20a5d8586a --- /dev/null +++ b/onert-micro/onert-micro/include/pal/cmsisnn/PALRelu.h @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2024 Samsung Electronics Co., Ltd. All Rights Reserved + * Copyright 2017 The TensorFlow Authors. 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_EXECUTE_PAL_RELU_H +#define ONERT_MICRO_EXECUTE_PAL_RELU_H + +#include "PALReluCommon.h" + +#include + +namespace onert_micro +{ +namespace execute +{ +namespace pal +{ + +template <> +OMStatus ReLUCommon(const int flat_size, const int8_t *input_data, int8_t *output_data, + const float alpha, const bool is_relu_6) +{ + // 1. Relu + if (is_relu_6 == false && alpha == 0) + { + memcpy(output_data, input_data, flat_size); + arm_relu_q7(output_data, flat_size); + } + // 2. Relu6 + else if (is_relu_6 && alpha == 0) + { + memcpy(output_data, input_data, flat_size); + arm_relu6_s8(output_data, flat_size); + } + // 3. Leaky_Relu not supported by cmsis_nn + else if (alpha != 0) + { + for (int i = 0; i < flat_size; i++) + { + const int8_t val = input_data[i]; + int8_t result = val > 0 ? val : val * alpha; + output_data[i] = result; + } + } + + return Ok; +} + +} // namespace pal +} // namespace execute +} // namespace onert_micro +#endif // ONERT_MICRO_EXECUTE_PAL_RELU_H diff --git a/onert-micro/onert-micro/include/pal/common/PALReluCommon.h b/onert-micro/onert-micro/include/pal/common/PALReluCommon.h index 6490824d3f9..c454513a5ce 100644 --- a/onert-micro/onert-micro/include/pal/common/PALReluCommon.h +++ b/onert-micro/onert-micro/include/pal/common/PALReluCommon.h @@ -29,14 +29,15 @@ namespace execute namespace pal { -inline OMStatus ReLUCommon(const int flat_size, const float *input_data, float *output_data, - const float alpha, const bool is_relu_6) +template +OMStatus ReLUCommon(const int flat_size, const Type *input_data, Type *output_data, + const float alpha, const bool is_relu_6) { - const float relu_6_value = 6.0f; + const Type relu_6_value = 6.0f; for (int i = 0; i < flat_size; i++) { - const float val = input_data[i]; - float result = val > 0 ? val : val * alpha; + const Type val = input_data[i]; + Type result = val > 0 ? val : val * alpha; result = is_relu_6 ? (result > relu_6_value ? relu_6_value : result) : result; output_data[i] = result; } diff --git a/onert-micro/onert-micro/include/pal/mcu/PALRelu.h b/onert-micro/onert-micro/include/pal/mcu/PALRelu.h new file mode 100644 index 00000000000..8a405aedce5 --- /dev/null +++ b/onert-micro/onert-micro/include/pal/mcu/PALRelu.h @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 Samsung Electronics Co., Ltd. All Rights Reserved + * Copyright 2017 The TensorFlow Authors. 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_EXECUTE_PAL_RELU_H +#define ONERT_MICRO_EXECUTE_PAL_RELU_H + +#include "PALReluCommon.h" +#include "PALUtils.h" + +#endif // ONERT_MICRO_EXECUTE_PAL_RELU_H diff --git a/onert-micro/onert-micro/include/test_models/relu/Int8ReLUKernel.h b/onert-micro/onert-micro/include/test_models/relu/Int8ReLUKernel.h new file mode 100644 index 00000000000..0f671ea9911 --- /dev/null +++ b/onert-micro/onert-micro/include/test_models/relu/Int8ReLUKernel.h @@ -0,0 +1,94 @@ +/* + * 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_INT8_RELU_KERNEL_H +#define ONERT_MICRO_TEST_MODELS_INT8_RELU_KERNEL_H + +#include "TestDataReLUBase.h" + +namespace onert_micro +{ +namespace test_model +{ +namespace relu_s8 +{ +/* + * ReLU Kernel: + * + * Input(1, 3, 3, 2) + * | + * ReLU + * | + * Output(1, 3, 3, 2) + */ +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, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x42, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc3, 0x03, 0x00, 0x00, 0x00, 0x6f, 0x66, 0x6d, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 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, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x80, 0x3f, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x42, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xc3, 0x03, 0x00, 0x00, 0x00, 0x69, 0x66, 0x6d, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 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, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x15, + 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 = {4, 11, -10, 9, -4, -20, 18, 7, -9, + 6, -4, 10, 8, 3, -21, -7, 1, 7}; +const std::vector reference_output_data = {4, 6, 0, 6, 0, 0, 6, 6, 0, + 6, 0, 6, 6, 3, 0, 0, 1, 6}; + +} // namespace relu_s8 + +class TestDataS8ReLU : public TestDataReLUBase +{ +public: + TestDataS8ReLU() + { + _input_data = relu_s8::input_data; + _reference_output_data = relu_s8::reference_output_data; + _test_kernel_model_circle = relu_s8::test_kernel_model_circle; + } + + ~TestDataS8ReLU() override = default; +}; + +} // namespace test_model +} // namespace onert_micro + +#endif // ONERT_MICRO_TEST_MODELS_INT8_RELU_KERNEL_H diff --git a/onert-micro/onert-micro/include/test_models/relu/NegReLUKernel.h b/onert-micro/onert-micro/include/test_models/relu/NegReLUKernel.h index 26b03538f2d..74bdbbb3b70 100644 --- a/onert-micro/onert-micro/include/test_models/relu/NegReLUKernel.h +++ b/onert-micro/onert-micro/include/test_models/relu/NegReLUKernel.h @@ -77,6 +77,59 @@ class NegTestDataInputOutputTypeMismatchReLUKernel : public NegTestDataBase const unsigned char *_test_kernel_model_circle; }; +namespace neg_input_output_shape_mismatch_kernel +{ +/* + * ReLU Kernel with input output type mismatch: + * + * Input(1, 3, 3, 2) - Int8 + * | + * ReLU + * | + * Output(1, 3, 3, 1) - Int8 + */ +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, 0x14, 0x01, 0x00, 0x00, 0x30, 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, 0x40, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0xd4, 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, 0x03, 0x00, 0x00, 0x00, 0x03, 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, 0x03, 0x00, 0x00, 0x00, + 0x03, 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, + 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x13, 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_shape_mismatch_kernel + +class NegTestDataInputOutputShapeMismatchReLUKernel : public NegTestDataBase +{ +public: + NegTestDataInputOutputShapeMismatchReLUKernel() + { + _test_kernel_model_circle = neg_input_output_shape_mismatch_kernel::test_kernel_model_circle; + } + + ~NegTestDataInputOutputShapeMismatchReLUKernel() 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 diff --git a/onert-micro/onert-micro/include/test_models/relu6/Int8ReLU6Kernel.h b/onert-micro/onert-micro/include/test_models/relu6/Int8ReLU6Kernel.h new file mode 100644 index 00000000000..b998bae030c --- /dev/null +++ b/onert-micro/onert-micro/include/test_models/relu6/Int8ReLU6Kernel.h @@ -0,0 +1,94 @@ +/* + * 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_INT8_RELU6_KERNEL_H +#define ONERT_MICRO_TEST_MODELS_INT8_RELU6_KERNEL_H + +#include "TestDataReLU6Base.h" + +namespace onert_micro +{ +namespace test_model +{ +namespace relu6_s8 +{ +/* + * ReLU6 Kernel: + * + * Input(1, 3, 3, 2) + * | + * ReLU6 + * | + * Output(1, 3, 3, 2) + */ +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, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x42, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc3, 0x03, 0x00, 0x00, 0x00, 0x6f, 0x66, 0x6d, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 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, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x80, 0x3f, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x42, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xc3, 0x03, 0x00, 0x00, 0x00, 0x69, 0x66, 0x6d, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 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, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x15, + 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 = {4, 11, -10, 9, -4, -20, 18, 7, -9, + 6, -4, 10, 8, 3, -21, -7, 1, 7}; +const std::vector reference_output_data = {4, 6, 0, 6, 0, 0, 6, 6, 0, + 6, 0, 6, 6, 3, 0, 0, 1, 6}; + +} // namespace relu6_s8 + +class TestDataS8ReLU6 : public TestDataReLU6Base +{ +public: + TestDataS8ReLU6() + { + _input_data = relu6_s8::input_data; + _reference_output_data = relu6_s8::reference_output_data; + _test_kernel_model_circle = relu6_s8::test_kernel_model_circle; + } + + ~TestDataS8ReLU6() override = default; +}; + +} // namespace test_model +} // namespace onert_micro + +#endif // ONERT_MICRO_TEST_MODELS_INT8_RELU6_KERNEL_H diff --git a/onert-micro/onert-micro/include/test_models/relu6/NegReLU6Kernel.h b/onert-micro/onert-micro/include/test_models/relu6/NegReLU6Kernel.h index d048e247cb5..595a3fabb37 100644 --- a/onert-micro/onert-micro/include/test_models/relu6/NegReLU6Kernel.h +++ b/onert-micro/onert-micro/include/test_models/relu6/NegReLU6Kernel.h @@ -77,6 +77,62 @@ class NegTestDataInputOutputTypeMismatchReLU6Kernel : public NegTestDataBase const unsigned char *_test_kernel_model_circle; }; +namespace neg_input_output_shape_mismatch_kernel +{ +/* + * ReLU6 Kernel with input output shape mismatch: + * + * Input(1, 3, 3, 2) + * | + * ReLU6 + * | + * Output(1, 3, 3, 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, + 0x2c, 0x00, 0x00, 0x00, 0x1c, 0x01, 0x00, 0x00, 0x38, 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, 0x44, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0xd0, 0xff, 0xff, 0xff, 0x10, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x09, 0x0c, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x6f, 0x66, 0x6d, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 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, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, + 0x0c, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x69, 0x66, 0x6d, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 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, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x15, + 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_shape_mismatch_kernel + +class NegTestDataInputOutputShapeMismatchReLU6Kernel : public NegTestDataBase +{ +public: + NegTestDataInputOutputShapeMismatchReLU6Kernel() + { + _test_kernel_model_circle = neg_input_output_shape_mismatch_kernel::test_kernel_model_circle; + } + + ~NegTestDataInputOutputShapeMismatchReLU6Kernel() 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 diff --git a/onert-micro/onert-micro/src/execute/kernels/ReluCommon.cpp b/onert-micro/onert-micro/src/execute/kernels/ReluCommon.cpp index ae464bffef9..3393c72e5c9 100644 --- a/onert-micro/onert-micro/src/execute/kernels/ReluCommon.cpp +++ b/onert-micro/onert-micro/src/execute/kernels/ReluCommon.cpp @@ -15,7 +15,7 @@ */ #include "execute/kernels/ReluCommon.h" -#include "PALReluCommon.h" +#include "PALRelu.h" using namespace onert_micro; using namespace onert_micro::execute; @@ -86,6 +86,23 @@ OMStatus onert_micro::execute::execute_relu_common(const OMExecuteArgs &execute_ } break; #endif // DIS_FLOAT +#ifndef DIS_QUANT + case circle::TensorType_INT8: + { + core::OMRuntimeShape input_shape(input); + core::OMRuntimeShape output_shape(output); + + const auto *input_data_int8 = core::utils::castInputData(input_data); + auto *output_data_int8 = core::utils::castOutputData(output_data); + + assert(output_data_int8); + const int flat_size = input_shape.flatSize(); + + status = pal::ReLUCommon(flat_size, input_data_int8, output_data_int8, alpha, is_relu_6); + } + break; +#endif // DIS_QUANT + default: { status = UnsupportedType; diff --git a/onert-micro/onert-micro/src/execute/kernels/tests/Relu.test.cpp b/onert-micro/onert-micro/src/execute/kernels/tests/Relu.test.cpp index 280e512a2ac..0390f01af44 100644 --- a/onert-micro/onert-micro/src/execute/kernels/tests/Relu.test.cpp +++ b/onert-micro/onert-micro/src/execute/kernels/tests/Relu.test.cpp @@ -16,6 +16,7 @@ #include "execute/OMTestUtils.h" #include "test_models/relu/FloatReLUKernel.h" +#include "test_models/relu/Int8ReLUKernel.h" #include "test_models/relu/NegReLUKernel.h" namespace onert_micro @@ -41,6 +42,14 @@ TEST_F(ReLUTest, Float_P) FloatArrayNear(test_data_kernel.get_output_data_by_index(0), 0.0001f)); } +TEST_F(ReLUTest, S8_P) +{ + onert_micro::test_model::TestDataS8ReLU 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(ReLUTest, Input_output_type_mismatch_NEG) { onert_micro::test_model::NegTestDataInputOutputTypeMismatchReLUKernel test_data_kernel; @@ -48,6 +57,13 @@ TEST_F(ReLUTest, Input_output_type_mismatch_NEG) EXPECT_DEATH(checkNEGSISOKernel(&test_data_kernel), ""); } +TEST_F(ReLUTest, Input_output_shape_mismatch_NEG) +{ + onert_micro::test_model::NegTestDataInputOutputShapeMismatchReLUKernel test_data_kernel; + + EXPECT_DEATH(checkNEGSISOKernel(&test_data_kernel), ""); +} + } // namespace testing } // namespace execute } // namespace onert_micro diff --git a/onert-micro/onert-micro/src/execute/kernels/tests/Relu6.test.cpp b/onert-micro/onert-micro/src/execute/kernels/tests/Relu6.test.cpp index 0279c0d2728..68d35934a0a 100644 --- a/onert-micro/onert-micro/src/execute/kernels/tests/Relu6.test.cpp +++ b/onert-micro/onert-micro/src/execute/kernels/tests/Relu6.test.cpp @@ -17,6 +17,7 @@ #include "execute/OMTestUtils.h" #include "test_models/relu6/FloatReLU6Kernel.h" #include "test_models/relu6/NegReLU6Kernel.h" +#include "test_models/relu6/Int8ReLU6Kernel.h" namespace onert_micro { @@ -41,6 +42,14 @@ TEST_F(ReLU6Test, Float_P) FloatArrayNear(test_data_kernel.get_output_data_by_index(0), 0.0001f)); } +TEST_F(ReLU6Test, S8_P) +{ + onert_micro::test_model::TestDataS8ReLU6 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(ReLU6Test, Input_output_type_mismatch_NEG) { onert_micro::test_model::NegTestDataInputOutputTypeMismatchReLU6Kernel test_data_kernel; @@ -48,6 +57,13 @@ TEST_F(ReLU6Test, Input_output_type_mismatch_NEG) EXPECT_DEATH(checkNEGSISOKernel(&test_data_kernel), ""); } +TEST_F(ReLU6Test, Input_output_shape_mismatch_NEG) +{ + onert_micro::test_model::NegTestDataInputOutputShapeMismatchReLU6Kernel test_data_kernel; + + EXPECT_DEATH(checkNEGSISOKernel(&test_data_kernel), ""); +} + } // namespace testing } // namespace execute } // namespace onert_micro