From 1bcb09a5a6f932009f6aff71f24e5cbf851d0c75 Mon Sep 17 00:00:00 2001 From: Denis Tarasenko Date: Thu, 10 Apr 2025 15:55:29 +0300 Subject: [PATCH] [onert-micro/onert-micro] Add kernels for logical operations (And/Or/Not) This will add kernels for logical operations with corresponding tests. ONE-DCO-1.0-Signed-off-by: Denis Tarasenko monoamind@outlook.com --- .../include/pal/common/PALLogicalCommon.h | 53 ++++++ .../include/pal/common/PALLogicalNotCommon.h | 37 ++++ .../include/pal/mcu/KernelsToBuild.lst | 6 +- .../logical_and/BoolLogicalAndKernel.h | 110 ++++++++++++ .../logical_and/NegLogicalAndKernel.h | 94 +++++++++++ .../logical_and/TestDataLogicalAndBase.h | 68 ++++++++ .../logical_not/BoolLogicalNotKernel.h | 96 +++++++++++ .../logical_not/NegLogicalNotKernel.h | 158 ++++++++++++++++++ .../logical_not/TestDataLogicalNotBase.h | 65 +++++++ .../logical_or/BoolLogicalOrKernel.h | 110 ++++++++++++ .../logical_or/NegLogicalOrKernel.h | 97 +++++++++++ .../logical_or/TestDataLogicalOrBase.h | 67 ++++++++ .../src/execute/kernels/LogicalAnd.cpp | 46 +++++ .../src/execute/kernels/LogicalNot.cpp | 45 +++++ .../src/execute/kernels/LogicalOr.cpp | 46 +++++ .../execute/kernels/tests/LogicalAnd.test.cpp | 50 ++++++ .../execute/kernels/tests/LogicalNot.test.cpp | 57 +++++++ .../execute/kernels/tests/LogicalOr.test.cpp | 50 ++++++ .../src/import/kernels/LogicalAnd.cpp | 60 +++++++ .../src/import/kernels/LogicalNot.cpp | 45 +++++ .../src/import/kernels/LogicalOr.cpp | 60 +++++++ 21 files changed, 1417 insertions(+), 3 deletions(-) create mode 100644 onert-micro/onert-micro/include/pal/common/PALLogicalCommon.h create mode 100644 onert-micro/onert-micro/include/pal/common/PALLogicalNotCommon.h create mode 100644 onert-micro/onert-micro/include/test_models/logical_and/BoolLogicalAndKernel.h create mode 100644 onert-micro/onert-micro/include/test_models/logical_and/NegLogicalAndKernel.h create mode 100644 onert-micro/onert-micro/include/test_models/logical_and/TestDataLogicalAndBase.h create mode 100644 onert-micro/onert-micro/include/test_models/logical_not/BoolLogicalNotKernel.h create mode 100644 onert-micro/onert-micro/include/test_models/logical_not/NegLogicalNotKernel.h create mode 100644 onert-micro/onert-micro/include/test_models/logical_not/TestDataLogicalNotBase.h create mode 100644 onert-micro/onert-micro/include/test_models/logical_or/BoolLogicalOrKernel.h create mode 100644 onert-micro/onert-micro/include/test_models/logical_or/NegLogicalOrKernel.h create mode 100644 onert-micro/onert-micro/include/test_models/logical_or/TestDataLogicalOrBase.h create mode 100644 onert-micro/onert-micro/src/execute/kernels/LogicalAnd.cpp create mode 100644 onert-micro/onert-micro/src/execute/kernels/LogicalNot.cpp create mode 100644 onert-micro/onert-micro/src/execute/kernels/LogicalOr.cpp create mode 100644 onert-micro/onert-micro/src/execute/kernels/tests/LogicalAnd.test.cpp create mode 100644 onert-micro/onert-micro/src/execute/kernels/tests/LogicalNot.test.cpp create mode 100644 onert-micro/onert-micro/src/execute/kernels/tests/LogicalOr.test.cpp create mode 100644 onert-micro/onert-micro/src/import/kernels/LogicalAnd.cpp create mode 100644 onert-micro/onert-micro/src/import/kernels/LogicalNot.cpp create mode 100644 onert-micro/onert-micro/src/import/kernels/LogicalOr.cpp diff --git a/onert-micro/onert-micro/include/pal/common/PALLogicalCommon.h b/onert-micro/onert-micro/include/pal/common/PALLogicalCommon.h new file mode 100644 index 00000000000..04ac11a1e9f --- /dev/null +++ b/onert-micro/onert-micro/include/pal/common/PALLogicalCommon.h @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2025 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_EXECUTE_PAL_LOGICAL_COMMON_H +#define ONERT_MICRO_EXECUTE_PAL_LOGICAL_COMMON_H + +#include "OMStatus.h" + +namespace onert_micro::execute::pal +{ + +struct LogicalAndFn +{ + bool operator()(bool lhs, bool rhs) { return lhs && rhs; } +}; + +struct LogicalOrFn +{ + bool operator()(bool lhs, bool rhs) { return lhs || rhs; } +}; + +// ------------------------------------------------------------------------------------------------ + +template +OMStatus LogicalCommon(const int flat_size, const bool *input1_data, const bool *input2_data, + bool *output_data) +{ + Fn func; + + for (int i = 0; i < flat_size; ++i) + { + output_data[i] = func(input1_data[i], input2_data[i]); + } + + return Ok; +} + +} // namespace onert_micro::execute::pal + +#endif // ONERT_MICRO_EXECUTE_PAL_LOGICAL_COMMON_H diff --git a/onert-micro/onert-micro/include/pal/common/PALLogicalNotCommon.h b/onert-micro/onert-micro/include/pal/common/PALLogicalNotCommon.h new file mode 100644 index 00000000000..ca1ac3b267f --- /dev/null +++ b/onert-micro/onert-micro/include/pal/common/PALLogicalNotCommon.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2025 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_EXECUTE_PAL_LOGICAL_NOT_COMMON_H +#define ONERT_MICRO_EXECUTE_PAL_LOGICAL_NOT_COMMON_H + +#include "OMStatus.h" + +namespace onert_micro::execute::pal +{ + +OMStatus LogicalNot(const int flat_size, const bool *input_data, bool *output_data) +{ + for (int i = 0; i < flat_size; ++i) + { + output_data[i] = !(input_data[i]); + } + + return Ok; +} + +} // namespace onert_micro::execute::pal + +#endif // ONERT_MICRO_EXECUTE_PAL_LOGICAL_NOT_COMMON_H diff --git a/onert-micro/onert-micro/include/pal/mcu/KernelsToBuild.lst b/onert-micro/onert-micro/include/pal/mcu/KernelsToBuild.lst index 23c59c6a2ff..cdd9340a411 100644 --- a/onert-micro/onert-micro/include/pal/mcu/KernelsToBuild.lst +++ b/onert-micro/onert-micro/include/pal/mcu/KernelsToBuild.lst @@ -45,9 +45,9 @@ REGISTER_KERNEL(LESS, Less) REGISTER_KERNEL(L2_NORMALIZATION, L2Normalize) REGISTER_KERNEL(L2_POOL_2D, L2Pool2D) REGISTER_KERNEL(LESS_EQUAL, LessEqual) -#/*REGISTER_KERNEL(LOGICAL_AND, LogicalAnd)*/ -#/*REGISTER_KERNEL(LOGICAL_NOT, LogicalNot)*/ -#/*REGISTER_KERNEL(LOGICAL_OR, LogicalOr)*/ +REGISTER_KERNEL(LOGICAL_AND, LogicalAnd) +REGISTER_KERNEL(LOGICAL_NOT, LogicalNot) +REGISTER_KERNEL(LOGICAL_OR, LogicalOr) REGISTER_KERNEL(LEAKY_RELU, LeakyRelu) REGISTER_KERNEL(LOG_SOFTMAX, LogSoftmax) REGISTER_KERNEL(MUL, Mul) diff --git a/onert-micro/onert-micro/include/test_models/logical_and/BoolLogicalAndKernel.h b/onert-micro/onert-micro/include/test_models/logical_and/BoolLogicalAndKernel.h new file mode 100644 index 00000000000..38f2226ff00 --- /dev/null +++ b/onert-micro/onert-micro/include/test_models/logical_and/BoolLogicalAndKernel.h @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2025 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_BOOL_LOGICAL_AND_KERNEL_H +#define ONERT_MICRO_TEST_MODELS_BOOL_LOGICAL_AND_KERNEL_H + +#include "TestDataLogicalAndBase.h" + +// clang-format off + +namespace onert_micro::test_model +{ +namespace logical_and_bool +{ + +/* + * LogicalAnd Kernel: + * + * Input(1, 4, 4, 3) Input(1, 4, 4, 3) + * | | + * -----LogicalAnd----- + * | + * Output(1, 4, 4, 3) + */ + +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, + 0x30, 0x00, 0x00, 0x00, 0x78, 0x01, 0x00, 0x00, 0x94, 0x01, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x1c, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x88, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x90, 0xff, 0xff, 0xff, 0x94, 0xff, 0xff, 0xff, + 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, 0x60, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x6c, 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, 0x14, 0x00, 0x00, 0x00, 0x10, 0x00, 0x0c, 0x00, + 0x07, 0x00, 0x08, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x10, 0x00, 0x00, 0x00, + 0x10, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x04, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00, + 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, 0x02, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x7c, 0x00, 0x00, 0x00, + 0x38, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x9c, 0xff, 0xff, 0xff, 0x10, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x0c, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x6f, 0x66, 0x6d, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0xcc, 0xff, 0xff, 0xff, 0x10, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x10, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x69, 0x66, 0x6d, 0x32, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x03, 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, 0x06, 0x10, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x69, 0x66, 0x6d, 0x31, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x03, 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, 0x56, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x56, 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 input1_data = { + true, false, true, true, true, false, true, true, true, true, true, true, true, true, true, true, + true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, + true, true, true, true, true, true, true, true, true, true, true, true, true, true, false, false +}; + +const std::vector input2_data = { + true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, + true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, + true, true, true, true, true, true, true, true, true, true, true, true, true, false, true, false +}; + +const std::vector reference_output_data = { + true, false, true, true, true, false, true, true, true, true, true, true, true, true, true, true, + true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, + true, true, true, true, true, true, true, true, true, true, true, true, true, false, false, false +}; + +} // namespace logical_and_bool + +// ------------------------------------------------------------------------------------------------ + +class TestDataBoolLogicalAnd : public TestDataLogicalAndBase +{ +public: + TestDataBoolLogicalAnd() + { + _input1_data = logical_and_bool::input1_data; + _input2_data = logical_and_bool::input2_data; + _reference_output_data = logical_and_bool::reference_output_data; + _test_kernel_model_circle = logical_and_bool::test_kernel_model_circle; + } + + ~TestDataBoolLogicalAnd() override = default; +}; + +} // namespace onert_micro::test_model + +#endif // ONERT_MICRO_TEST_MODELS_BOOL_LOGICAL_AND_KERNEL_H diff --git a/onert-micro/onert-micro/include/test_models/logical_and/NegLogicalAndKernel.h b/onert-micro/onert-micro/include/test_models/logical_and/NegLogicalAndKernel.h new file mode 100644 index 00000000000..c89ef6b2080 --- /dev/null +++ b/onert-micro/onert-micro/include/test_models/logical_and/NegLogicalAndKernel.h @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2025 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_LOGICAL_AND_KERNEL_H +#define ONERT_MICRO_TEST_MODELS_NEG_LOGICAL_AND_KERNEL_H + +#include "TestDataLogicalAndBase.h" + +// clang-format off + +namespace onert_micro::test_model +{ +namespace neg_logical_and_inputs_type_mismatch +{ + +/* + * LogicalAnd Kernel with inputs type mismatch: + * + * Input(1, 4, 4, 3)-Bool Input(1, 4, 4, 3)-Float32 + * | | + * -------LogicalAnd-------- + * | + * Output(1, 4, 4, 3) + */ + +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, + 0x30, 0x00, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x9c, 0x01, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x1c, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x88, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x90, 0xff, 0xff, 0xff, 0x94, 0xff, 0xff, 0xff, + 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, 0x60, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x6c, 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, 0x14, 0x00, 0x00, 0x00, 0x10, 0x00, 0x0c, 0x00, + 0x07, 0x00, 0x08, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x10, 0x00, 0x00, 0x00, + 0x10, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x04, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00, + 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, 0x02, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x84, 0x00, 0x00, 0x00, + 0x44, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x94, 0xff, 0xff, 0xff, 0x10, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x0c, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x6f, 0x66, 0x6d, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, + 0x08, 0x00, 0x04, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x10, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x69, 0x66, 0x6d, 0x32, 0x00, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x03, 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, 0x06, + 0x10, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x69, 0x66, 0x6d, 0x31, 0x00, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x03, 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, 0x56, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x56, 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_logical_and_inputs_type_mismatch + +// ------------------------------------------------------------------------------------------------ + +class NegTestDataLogicalAndInputsTypeMismatch : public NegTestDataBase +{ +public: + NegTestDataLogicalAndInputsTypeMismatch() + { + _test_kernel_model_circle = neg_logical_and_inputs_type_mismatch::test_kernel_model_circle; + } + + ~NegTestDataLogicalAndInputsTypeMismatch() override = default; + + const unsigned char *get_model_ptr() override final { return _test_kernel_model_circle; } + +protected: + const unsigned char *_test_kernel_model_circle; +}; + +} // namespace onert_micro::test_model + +#endif // ONERT_MICRO_TEST_MODELS_NEG_LOGICAL_AND_KERNEL_H diff --git a/onert-micro/onert-micro/include/test_models/logical_and/TestDataLogicalAndBase.h b/onert-micro/onert-micro/include/test_models/logical_and/TestDataLogicalAndBase.h new file mode 100644 index 00000000000..415652b4d8c --- /dev/null +++ b/onert-micro/onert-micro/include/test_models/logical_and/TestDataLogicalAndBase.h @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2025 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_LOGICAL_AND_KERNEL_BASE_H +#define ONERT_MICRO_TEST_MODELS_LOGICAL_AND_KERNEL_BASE_H + +#include "test_models/TestDataBase.h" + +namespace onert_micro::test_model +{ + +template class TestDataLogicalAndBase : public TestDataBase +{ +public: + TestDataLogicalAndBase() = default; + ~TestDataLogicalAndBase() override = default; + + // clang-format off + + const unsigned char *get_model_ptr() override final + { + return _test_kernel_model_circle; + } + + // clang-format on + + const std::vector &get_input_data_by_index(int i) override final + { + switch (i) + { + case 0: + return _input1_data; + case 1: + return _input2_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 _input1_data; + std::vector _input2_data; + std::vector _reference_output_data; + const unsigned char *_test_kernel_model_circle; +}; + +} // namespace onert_micro::test_model + +#endif // ONERT_MICRO_TEST_MODELS_LOGICAL_AND_KERNEL_BASE_H diff --git a/onert-micro/onert-micro/include/test_models/logical_not/BoolLogicalNotKernel.h b/onert-micro/onert-micro/include/test_models/logical_not/BoolLogicalNotKernel.h new file mode 100644 index 00000000000..2df62a9202a --- /dev/null +++ b/onert-micro/onert-micro/include/test_models/logical_not/BoolLogicalNotKernel.h @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2025 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_BOOL_LOGICAL_NOT_KERNEL_H +#define ONERT_MICRO_TEST_MODELS_BOOL_LOGICAL_NOT_KERNEL_H + +#include "TestDataLogicalNotBase.h" + +// clang-format off + +namespace onert_micro::test_model +{ +namespace logical_not_bool +{ + +/* + * LogicalNot Kernel: + * + * Input(1, 4, 4, 3) + * | + * LogicalNot + * | + * Output(1, 4, 4, 3) + */ + +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, + 0x28, 0x00, 0x00, 0x00, 0x2c, 0x01, 0x00, 0x00, 0x48, 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x14, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x8c, 0xff, 0xff, 0xff, + 0x90, 0xff, 0xff, 0xff, 0x94, 0xff, 0xff, 0xff, 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, 0x5c, 0x00, 0x00, 0x00, + 0x60, 0x00, 0x00, 0x00, 0x64, 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, + 0x14, 0x00, 0x00, 0x00, 0x10, 0x00, 0x0c, 0x00, 0x07, 0x00, 0x08, 0x00, 0x0e, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x3f, 0x10, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x04, 0x00, 0x04, 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, 0x06, 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, + 0x02, 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, 0x06, + 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, 0x57, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x57, + 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 = { + false, true, false, false, true, true, false, false, false, + false, false, true, false, true, true, true, true, true +}; + +const std::vector reference_output_data = { + true, false, true, true, false, false, true, true, true, + true, true, false, true, false, false, false, false, false +}; + +} // namespace logical_not_bool + +// ------------------------------------------------------------------------------------------------ + +class TestDataBoolLogicalNot : public TestDataLogicalNotBase +{ +public: + TestDataBoolLogicalNot() + { + _input_data = logical_not_bool::input_data; + _reference_output_data = logical_not_bool::reference_output_data; + _test_kernel_model_circle = logical_not_bool::test_kernel_model_circle; + } + + ~TestDataBoolLogicalNot() override = default; +}; + +} // namespace onert_micro::test_model + +#endif // ONERT_MICRO_TEST_MODELS_BOOL_LOGICAL_NOT_KERNEL_H diff --git a/onert-micro/onert-micro/include/test_models/logical_not/NegLogicalNotKernel.h b/onert-micro/onert-micro/include/test_models/logical_not/NegLogicalNotKernel.h new file mode 100644 index 00000000000..9f95f42552f --- /dev/null +++ b/onert-micro/onert-micro/include/test_models/logical_not/NegLogicalNotKernel.h @@ -0,0 +1,158 @@ +/* + * Copyright (c) 2025 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_LOGICAL_NOT_KERNEL_H +#define ONERT_MICRO_TEST_MODELS_NEG_LOGICAL_NOT_KERNEL_H + +#include "TestDataLogicalNotBase.h" + +// clang-format off + +namespace onert_micro::test_model +{ +namespace neg_logical_not_output_type_mismatch +{ + +/* + * LogicalNot Kernel with wrong output type (should be bool): + * + * Input(1, 3, 3, 2) - Bool + * | + * LogicalNot + * | + * Output(1, 3, 3, 2) - Int + */ + +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, + 0x28, 0x00, 0x00, 0x00, 0x2c, 0x01, 0x00, 0x00, 0x48, 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x14, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x8c, 0xff, 0xff, 0xff, + 0x90, 0xff, 0xff, 0xff, 0x94, 0xff, 0xff, 0xff, 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, 0x5c, 0x00, 0x00, 0x00, + 0x60, 0x00, 0x00, 0x00, 0x64, 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, + 0x14, 0x00, 0x00, 0x00, 0x10, 0x00, 0x0c, 0x00, 0x07, 0x00, 0x08, 0x00, 0x0e, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x3f, 0x10, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x04, 0x00, 0x04, 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, 0x02, 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, + 0x02, 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, 0x06, + 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, 0x57, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x57, + 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_logical_not_output_type_mismatch + +// ------------------------------------------------------------------------------------------------ + +namespace neg_logical_not_output_shape_mismatch +{ + +/* + * LogicalNot Kernel with input and output shapes mismatch (should be equal): + * + * Input(1, 3, 3, 2) - Bool + * | + * LogicalNot + * | + * Output(1, 3, 3) - Bool + */ + + 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, + 0x28, 0x00, 0x00, 0x00, 0x2c, 0x01, 0x00, 0x00, 0x48, 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x14, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x8c, 0xff, 0xff, 0xff, + 0x90, 0xff, 0xff, 0xff, 0x94, 0xff, 0xff, 0xff, 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, 0x5c, 0x00, 0x00, 0x00, + 0x60, 0x00, 0x00, 0x00, 0x64, 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, + 0x14, 0x00, 0x00, 0x00, 0x10, 0x00, 0x0c, 0x00, 0x07, 0x00, 0x08, 0x00, 0x0e, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x3f, 0x10, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x04, 0x00, 0x04, 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, 0x02, 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, + 0x02, 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, 0x06, + 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, 0x57, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x57, + 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_logical_not_output_shape_mismatch + +// ------------------------------------------------------------------------------------------------ + +class NegTestDataLogicalNotOutputTypeMismatch : public NegTestDataBase +{ +public: + NegTestDataLogicalNotOutputTypeMismatch() + { + _test_kernel_model_circle = neg_logical_not_output_type_mismatch::test_kernel_model_circle; + } + + ~NegTestDataLogicalNotOutputTypeMismatch() override = default; + + const unsigned char *get_model_ptr() override final + { + return _test_kernel_model_circle; + } + +protected: + const unsigned char *_test_kernel_model_circle; +}; + +// ------------------------------------------------------------------------------------------------ + +class NegTestDataLogicalNotOutputShapeMismatch : public NegTestDataBase +{ +public: + NegTestDataLogicalNotOutputShapeMismatch() + { + _test_kernel_model_circle = neg_logical_not_output_shape_mismatch::test_kernel_model_circle; + } + + ~NegTestDataLogicalNotOutputShapeMismatch() override = default; + + const unsigned char *get_model_ptr() override final + { + return _test_kernel_model_circle; + } + +protected: + const unsigned char *_test_kernel_model_circle; +}; + +} // namespace onert_micro::test_model + +#endif // ONERT_MICRO_TEST_MODELS_NEG_LOGICAL_NOT_KERNEL_H diff --git a/onert-micro/onert-micro/include/test_models/logical_not/TestDataLogicalNotBase.h b/onert-micro/onert-micro/include/test_models/logical_not/TestDataLogicalNotBase.h new file mode 100644 index 00000000000..5269485b698 --- /dev/null +++ b/onert-micro/onert-micro/include/test_models/logical_not/TestDataLogicalNotBase.h @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2025 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_LOGICAL_NOT_KERNEL_BASE_H +#define ONERT_MICRO_TEST_MODELS_LOGICAL_NOT_KERNEL_BASE_H + +#include "test_models/TestDataBase.h" + +namespace onert_micro::test_model +{ + +template class TestDataLogicalNotBase : public TestDataBase +{ +public: + TestDataLogicalNotBase() = default; + ~TestDataLogicalNotBase() override = default; + + // clang-format off + + const unsigned char *get_model_ptr() override final + { + return _test_kernel_model_circle; + } + + // clang-format on + + 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 onert_micro::test_model + +#endif // ONERT_MICRO_TEST_MODELS_LOGICAL_NOT_KERNEL_BASE_H diff --git a/onert-micro/onert-micro/include/test_models/logical_or/BoolLogicalOrKernel.h b/onert-micro/onert-micro/include/test_models/logical_or/BoolLogicalOrKernel.h new file mode 100644 index 00000000000..d5404dca1b7 --- /dev/null +++ b/onert-micro/onert-micro/include/test_models/logical_or/BoolLogicalOrKernel.h @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2025 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_BOOL_LOGICAL_OR_KERNEL_H +#define ONERT_MICRO_TEST_MODELS_BOOL_LOGICAL_OR_KERNEL_H + +#include "TestDataLogicalOrBase.h" + +// clang-format off + +namespace onert_micro::test_model +{ +namespace logical_or_bool +{ + +/* + * LogicalOr Kernel: + * + * Input(1, 4, 4, 3) Input(1, 4, 4, 3) + * | | + * -----LogicalOr------ + * | + * Output(1, 4, 4, 3) + */ + +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, + 0x30, 0x00, 0x00, 0x00, 0x78, 0x01, 0x00, 0x00, 0x94, 0x01, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x1c, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x88, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x90, 0xff, 0xff, 0xff, 0x94, 0xff, 0xff, 0xff, + 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, 0x60, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x6c, 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, 0x14, 0x00, 0x00, 0x00, 0x10, 0x00, 0x0c, 0x00, + 0x07, 0x00, 0x08, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x10, 0x00, 0x00, 0x00, + 0x10, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x04, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00, + 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, 0x02, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x7c, 0x00, 0x00, 0x00, + 0x38, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x9c, 0xff, 0xff, 0xff, 0x10, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x0c, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x6f, 0x66, 0x6d, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0xcc, 0xff, 0xff, 0xff, 0x10, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x10, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x69, 0x66, 0x6d, 0x32, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x03, 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, 0x06, 0x10, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x69, 0x66, 0x6d, 0x31, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x03, 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, 0x56, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x56, 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 input1_data = { + true, false, true, true, true, false, true, true, true, true, true, true, true, true, true, true, + true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, + true, true, true, true, true, true, true, true, true, true, true, true, true, true, false, false +}; + +const std::vector input2_data = { + true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, + true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, + true, true, true, true, true, true, true, true, true, true, true, true, true, false, true, false +}; + +const std::vector reference_output_data = { + true, false, true, true, true, false, true, true, true, true, true, true, true, true, true, true, + true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, + true, true, true, true, true, true, true, true, true, true, true, true, true, false, false, false +}; + +} // namespace logical_and_bool + +// ------------------------------------------------------------------------------------------------ + +class TestDataBoolLogicalOr : public TestDataLogicalOrBase +{ +public: + TestDataBoolLogicalOr() + { + _input1_data = logical_or_bool::input1_data; + _input2_data = logical_or_bool::input2_data; + _reference_output_data = logical_or_bool::reference_output_data; + _test_kernel_model_circle = logical_or_bool::test_kernel_model_circle; + } + + ~TestDataBoolLogicalOr() override = default; +}; + +} // namespace onert_micro::test_model + +#endif // ONERT_MICRO_TEST_MODELS_BOOL_LOGICAL_OR_KERNEL_H diff --git a/onert-micro/onert-micro/include/test_models/logical_or/NegLogicalOrKernel.h b/onert-micro/onert-micro/include/test_models/logical_or/NegLogicalOrKernel.h new file mode 100644 index 00000000000..ae0d9594b39 --- /dev/null +++ b/onert-micro/onert-micro/include/test_models/logical_or/NegLogicalOrKernel.h @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2025 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_LOGICAL_OR_KERNEL_H +#define ONERT_MICRO_TEST_MODELS_NEG_LOGICAL_OR_KERNEL_H + +#include "TestDataLogicalOrBase.h" + +// clang-format off + +namespace onert_micro::test_model +{ +namespace neg_logical_or_inputs_type_mismatch +{ + +/* + * LogicalOr Kernel with inputs type mismatch: + * + * Input(1, 4, 4, 3)-Bool Input(1, 4, 4, 3)-Float32 + * | | + * -------LogicalOr-------- + * | + * Output(1, 4, 4, 3) + */ + +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, + 0x30, 0x00, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x9c, 0x01, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x1c, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x88, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x90, 0xff, 0xff, 0xff, 0x94, 0xff, 0xff, 0xff, + 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, 0x60, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x6c, 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, 0x14, 0x00, 0x00, 0x00, 0x10, 0x00, 0x0c, 0x00, + 0x07, 0x00, 0x08, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x10, 0x00, 0x00, 0x00, + 0x10, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x04, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00, + 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, 0x02, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x84, 0x00, 0x00, 0x00, + 0x44, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x94, 0xff, 0xff, 0xff, 0x10, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x0c, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x6f, 0x66, 0x6d, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, + 0x08, 0x00, 0x04, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x10, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x69, 0x66, 0x6d, 0x32, 0x00, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x03, 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, 0x06, + 0x10, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x69, 0x66, 0x6d, 0x31, 0x00, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x03, 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, 0x54, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x54, 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_logical_and_inputs_type_mismatch + +// ------------------------------------------------------------------------------------------------ + +class NegTestDataLogicalOrInputsTypeMismatch : public NegTestDataBase +{ +public: + NegTestDataLogicalOrInputsTypeMismatch() + { + _test_kernel_model_circle = neg_logical_or_inputs_type_mismatch::test_kernel_model_circle; + } + + ~NegTestDataLogicalOrInputsTypeMismatch() override = default; + + const unsigned char *get_model_ptr() override final + { + return _test_kernel_model_circle; + } + +protected: + const unsigned char *_test_kernel_model_circle; +}; + +} // namespace onert_micro::test_model + +#endif // ONERT_MICRO_TEST_MODELS_NEG_LOGICAL_OR_KERNEL_H diff --git a/onert-micro/onert-micro/include/test_models/logical_or/TestDataLogicalOrBase.h b/onert-micro/onert-micro/include/test_models/logical_or/TestDataLogicalOrBase.h new file mode 100644 index 00000000000..bb0806e5799 --- /dev/null +++ b/onert-micro/onert-micro/include/test_models/logical_or/TestDataLogicalOrBase.h @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2025 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_LOGICAL_OR_KERNEL_BASE_H +#define ONERT_MICRO_TEST_MODELS_LOGICAL_OR_KERNEL_BASE_H + +#include "test_models/TestDataBase.h" + +#include + +namespace onert_micro::test_model +{ + +template +class TestDataLogicalOrBase : public TestDataBase +{ +public: + TestDataLogicalOrBase() = default; + ~TestDataLogicalOrBase() override = 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 _input1_data; + case 1: + return _input2_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 _input1_data; + std::vector _input2_data; + std::vector _reference_output_data; + const unsigned char *_test_kernel_model_circle; +}; + +} // namespace onert_micro::test_model + +#endif // ONERT_MICRO_TEST_MODELS_LOGICAL_OR_KERNEL_BASE_H diff --git a/onert-micro/onert-micro/src/execute/kernels/LogicalAnd.cpp b/onert-micro/onert-micro/src/execute/kernels/LogicalAnd.cpp new file mode 100644 index 00000000000..5e9a2c3dd8b --- /dev/null +++ b/onert-micro/onert-micro/src/execute/kernels/LogicalAnd.cpp @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2025 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. + */ + +#include "core/OMUtils.h" +#include "execute/OMUtils.h" + +#include "PALLogicalCommon.h" + +using namespace onert_micro::core; + +namespace onert_micro::execute +{ + +OMStatus execute_kernel_CircleLogicalAnd(const OMExecuteArgs &execute_args) +{ + const circle::Tensor *input1; + const circle::Tensor *input2; + const circle::Tensor *output; + + OMRuntimeKernel rt_kernel; + + TISOHeader(execute_args, &input1, &input2, &output, &rt_kernel); + + auto input1_data = utils::castInputData(rt_kernel.inputs_data[0]); + auto input2_data = utils::castInputData(rt_kernel.inputs_data[1]); + auto output_data = utils::castOutputData(rt_kernel.outputs_data[0]); + + const int flat_size = OMRuntimeShape(input1).flatSize(); + + return pal::LogicalCommon(flat_size, input1_data, input2_data, output_data); +} + +} // namespace onert_micro::execute diff --git a/onert-micro/onert-micro/src/execute/kernels/LogicalNot.cpp b/onert-micro/onert-micro/src/execute/kernels/LogicalNot.cpp new file mode 100644 index 00000000000..f89805b73a7 --- /dev/null +++ b/onert-micro/onert-micro/src/execute/kernels/LogicalNot.cpp @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2025 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. + */ + +#include "core/OMUtils.h" +#include "execute/OMUtils.h" + +#include "PALLogicalNotCommon.h" + +using namespace onert_micro::core; + +namespace onert_micro::execute +{ + +OMStatus execute_kernel_CircleLogicalNot(const OMExecuteArgs &execute_args) +{ + const circle::Tensor *input; + const circle::Tensor *output; + + uint8_t *input_data; + uint8_t *output_data; + + SISOHeader(execute_args, &input, &output, &input_data, &output_data); + + auto bool_input_data = utils::castInputData(input_data); + auto bool_output_data = utils::castOutputData(output_data); + + const int flat_size = OMRuntimeShape(input).flatSize(); + + return pal::LogicalNot(flat_size, bool_input_data, bool_output_data); +} + +} // namespace onert_micro::execute diff --git a/onert-micro/onert-micro/src/execute/kernels/LogicalOr.cpp b/onert-micro/onert-micro/src/execute/kernels/LogicalOr.cpp new file mode 100644 index 00000000000..721a98e9aea --- /dev/null +++ b/onert-micro/onert-micro/src/execute/kernels/LogicalOr.cpp @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2025 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. + */ + +#include "core/OMUtils.h" +#include "execute/OMUtils.h" + +#include "PALLogicalCommon.h" + +using namespace onert_micro::core; + +namespace onert_micro::execute +{ + +OMStatus execute_kernel_CircleLogicalOr(const OMExecuteArgs &execute_args) +{ + const circle::Tensor *input1; + const circle::Tensor *input2; + const circle::Tensor *output; + + OMRuntimeKernel rt_kernel; + + TISOHeader(execute_args, &input1, &input2, &output, &rt_kernel); + + auto input1_data = utils::castInputData(rt_kernel.inputs_data[0]); + auto input2_data = utils::castInputData(rt_kernel.inputs_data[1]); + auto output_data = utils::castOutputData(rt_kernel.outputs_data[0]); + + const int flat_size = OMRuntimeShape(input1).flatSize(); + + return pal::LogicalCommon(flat_size, input1_data, input2_data, output_data); +} + +} // namespace onert_micro::execute diff --git a/onert-micro/onert-micro/src/execute/kernels/tests/LogicalAnd.test.cpp b/onert-micro/onert-micro/src/execute/kernels/tests/LogicalAnd.test.cpp new file mode 100644 index 00000000000..a34ecddd0fe --- /dev/null +++ b/onert-micro/onert-micro/src/execute/kernels/tests/LogicalAnd.test.cpp @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2025 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. + */ + +#include "execute/OMTestUtils.h" + +#include "test_models/logical_and/BoolLogicalAndKernel.h" +#include "test_models/logical_and/NegLogicalAndKernel.h" + +namespace onert_micro::execute::testing +{ + +// ------------------------------------------------------------------------------------------------ + +class LogicalAndTest : public ::testing::Test +{ +}; + +// ------------------------------------------------------------------------------------------------ + +TEST_F(LogicalAndTest, Bool_P) +{ + test_model::TestDataBoolLogicalAnd test_data_bool_logical_and; + auto output_data_vector = checkKernel(2, &test_data_bool_logical_and); + + EXPECT_TRUE(output_data_vector == test_data_bool_logical_and.get_output_data_by_index(0)); +} + +TEST_F(LogicalAndTest, InputTypeMismatch_NEG) +{ + test_model::NegTestDataLogicalAndInputsTypeMismatch neg_test_data; + + EXPECT_DEATH(checkNEGSISOKernel(&neg_test_data), ""); +} + +// ------------------------------------------------------------------------------------------------ + +} // namespace onert_micro::execute::testing diff --git a/onert-micro/onert-micro/src/execute/kernels/tests/LogicalNot.test.cpp b/onert-micro/onert-micro/src/execute/kernels/tests/LogicalNot.test.cpp new file mode 100644 index 00000000000..ab2acae0d11 --- /dev/null +++ b/onert-micro/onert-micro/src/execute/kernels/tests/LogicalNot.test.cpp @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2025 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. + */ + +#include "execute/OMTestUtils.h" + +#include "test_models/logical_not/BoolLogicalNotKernel.h" +#include "test_models/logical_not/NegLogicalNotKernel.h" + +namespace onert_micro::execute::testing +{ + +// ------------------------------------------------------------------------------------------------ + +class LogicalNotTest : public ::testing::Test +{ +}; + +// ------------------------------------------------------------------------------------------------ + +TEST_F(LogicalNotTest, Bool_P) +{ + test_model::TestDataBoolLogicalNot test_data_bool_logical_not; + auto output_data_vector = checkKernel(1, &test_data_bool_logical_not); + + EXPECT_TRUE(output_data_vector == test_data_bool_logical_not.get_output_data_by_index(0)); +} + +TEST_F(LogicalNotTest, OutputTypeMismatch_NEG) +{ + test_model::NegTestDataLogicalNotOutputTypeMismatch neg_test_data; + + EXPECT_DEATH(checkNEGSISOKernel(&neg_test_data), ""); +} + +TEST_F(LogicalNotTest, OutputShapeMismatch_NEG) +{ + test_model::NegTestDataLogicalNotOutputShapeMismatch neg_test_data; + + EXPECT_DEATH(checkNEGSISOKernel(&neg_test_data), ""); +} + +// ------------------------------------------------------------------------------------------------ + +} // namespace onert_micro::execute::testing diff --git a/onert-micro/onert-micro/src/execute/kernels/tests/LogicalOr.test.cpp b/onert-micro/onert-micro/src/execute/kernels/tests/LogicalOr.test.cpp new file mode 100644 index 00000000000..772a300da34 --- /dev/null +++ b/onert-micro/onert-micro/src/execute/kernels/tests/LogicalOr.test.cpp @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2025 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. + */ + +#include "execute/OMTestUtils.h" + +#include "test_models/logical_or/BoolLogicalOrKernel.h" +#include "test_models/logical_or/NegLogicalOrKernel.h" + +namespace onert_micro::execute::testing +{ + +// ------------------------------------------------------------------------------------------------ + +class LogicalOrTest : public ::testing::Test +{ +}; + +// ------------------------------------------------------------------------------------------------ + +TEST_F(LogicalOrTest, Bool_P) +{ + test_model::TestDataBoolLogicalOr test_data_bool_logical_or; + auto output_data_vector = checkKernel(2, &test_data_bool_logical_or); + + EXPECT_TRUE(output_data_vector == test_data_bool_logical_or.get_output_data_by_index(0)); +} + +TEST_F(LogicalOrTest, InputTypeMismatch_NEG) +{ + test_model::NegTestDataLogicalOrInputsTypeMismatch neg_test_data; + + EXPECT_DEATH(checkNEGSISOKernel(&neg_test_data), ""); +} + +// ------------------------------------------------------------------------------------------------ + +} // namespace onert_micro::execute::testing diff --git a/onert-micro/onert-micro/src/import/kernels/LogicalAnd.cpp b/onert-micro/onert-micro/src/import/kernels/LogicalAnd.cpp new file mode 100644 index 00000000000..f44a0391348 --- /dev/null +++ b/onert-micro/onert-micro/src/import/kernels/LogicalAnd.cpp @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2025 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. + */ + +#include "core/OMUtils.h" +#include "import/OMUtils.h" + +using namespace onert_micro::core; + +namespace onert_micro::import +{ + +OMStatus configure_kernel_CircleLogicalAnd(const OMConfigureArgs &config_args) +{ + const circle::Tensor *input1; + const circle::Tensor *input2; + const circle::Tensor *output; + + TISOHeader(config_args, &input1, &input2, &output); + + std::array types = {input1->type(), input2->type(), output->type()}; + + // clang-format off + + bool type_check = std::all_of(types.cbegin(), types.cend(), [](const auto& type) + { + return type == circle::TensorType_BOOL; + }); + + // clang-format on + + OMStatus status = utils::checkCondition(type_check); + + if (status != Ok) + return status; + + const OMRuntimeShape input_shape1(input1); + const OMRuntimeShape input_shape2(input2); + + status = utils::checkCondition(input_shape1.flatSize() == input_shape2.flatSize()); + + if (status != Ok) + return status; + + return utils::checkCondition(input_shape1.dimensionsCount() == input_shape2.dimensionsCount()); +} + +} // namespace onert_micro::import diff --git a/onert-micro/onert-micro/src/import/kernels/LogicalNot.cpp b/onert-micro/onert-micro/src/import/kernels/LogicalNot.cpp new file mode 100644 index 00000000000..ff6c5998456 --- /dev/null +++ b/onert-micro/onert-micro/src/import/kernels/LogicalNot.cpp @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2025 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. + */ + +#include "core/OMUtils.h" +#include "import/OMUtils.h" + +using namespace onert_micro::core; + +namespace onert_micro::import +{ + +OMStatus configure_kernel_CircleLogicalNot(const OMConfigureArgs &config_args) +{ + const circle::Tensor *input; + const circle::Tensor *output; + + SISOHeader(config_args, &input, &output); + + bool type_check = (input->type() == circle::TensorType_BOOL && input->type() == output->type()); + + OMStatus status = utils::checkCondition(type_check); + + if (status != Ok) + return status; + + const OMRuntimeShape input_shape(input); + const OMRuntimeShape output_shape(output); + + return utils::checkCondition(input_shape == output_shape); +} + +} // namespace onert_micro::import diff --git a/onert-micro/onert-micro/src/import/kernels/LogicalOr.cpp b/onert-micro/onert-micro/src/import/kernels/LogicalOr.cpp new file mode 100644 index 00000000000..34abe3edf32 --- /dev/null +++ b/onert-micro/onert-micro/src/import/kernels/LogicalOr.cpp @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2025 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. + */ + +#include "core/OMUtils.h" +#include "import/OMUtils.h" + +using namespace onert_micro::core; + +namespace onert_micro::import +{ + +OMStatus configure_kernel_CircleLogicalOr(const OMConfigureArgs &config_args) +{ + const circle::Tensor *input1; + const circle::Tensor *input2; + const circle::Tensor *output; + + TISOHeader(config_args, &input1, &input2, &output); + + std::array types = {input1->type(), input2->type(), output->type()}; + + // clang-format off + + bool type_check = std::all_of(types.cbegin(), types.cend(), [](const auto &type) + { + return type == circle::TensorType_BOOL; + }); + + // clang-format on + + OMStatus status = utils::checkCondition(type_check); + + if (status != Ok) + return status; + + const OMRuntimeShape input_shape1(input1); + const OMRuntimeShape input_shape2(input2); + + status = utils::checkCondition(input_shape1.flatSize() == input_shape2.flatSize()); + + if (status != Ok) + return status; + + return utils::checkCondition(input_shape1.dimensionsCount() == input_shape2.dimensionsCount()); +} + +} // namespace onert_micro::import