From 5ccb39dac87264e8aae05a52d71a4650128e2bd5 Mon Sep 17 00:00:00 2001 From: Seungho Henry Park <136296779+shs-park@users.noreply.github.com> Date: Mon, 31 Jul 2023 07:21:53 +0900 Subject: [PATCH 01/11] [luci/import] Support HardSwish operation (#11181) Support HardSwish operation in luci/import Signed-off-by: Seungho Henry Park --- .../luci/import/include/luci/Import/Nodes.h | 1 + .../luci/Import/Nodes/CircleHardSwish.h | 37 +++++++++++++++++ .../luci/import/src/GraphBuilderRegistry.cpp | 1 + .../luci/import/src/Nodes/CircleHardSwish.cpp | 41 +++++++++++++++++++ 4 files changed, 80 insertions(+) create mode 100644 compiler/luci/import/include/luci/Import/Nodes/CircleHardSwish.h create mode 100644 compiler/luci/import/src/Nodes/CircleHardSwish.cpp diff --git a/compiler/luci/import/include/luci/Import/Nodes.h b/compiler/luci/import/include/luci/Import/Nodes.h index 02a1e50c5d3..e8c8d0aaee9 100644 --- a/compiler/luci/import/include/luci/Import/Nodes.h +++ b/compiler/luci/import/include/luci/Import/Nodes.h @@ -55,6 +55,7 @@ #include "Nodes/CircleGelu.h" #include "Nodes/CircleGreater.h" #include "Nodes/CircleGreaterEqual.h" +#include "Nodes/CircleHardSwish.h" #include "Nodes/CircleIf.h" #include "Nodes/CircleInstanceNorm.h" #include "Nodes/CircleL2Normalize.h" diff --git a/compiler/luci/import/include/luci/Import/Nodes/CircleHardSwish.h b/compiler/luci/import/include/luci/Import/Nodes/CircleHardSwish.h new file mode 100644 index 00000000000..7aeb0299bb6 --- /dev/null +++ b/compiler/luci/import/include/luci/Import/Nodes/CircleHardSwish.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __LUCI_IMPORT_OP_CIRCLE_HARDSWISH_H__ +#define __LUCI_IMPORT_OP_CIRCLE_HARDSWISH_H__ + +#include "luci/Import/GraphBuilder.h" + +namespace luci +{ + +class CircleHardSwishGraphBuilder : public GraphBuilder +{ +public: + bool validate(const ValidateArgs &args) const final; + +private: + CircleNode *build_node(const circle::OperatorT &op, const std::vector &inputs, + loco::Graph *graph) const final; +}; + +} // namespace luci + +#endif // __LUCI_IMPORT_OP_CIRCLE_HARDSWISH_H__ diff --git a/compiler/luci/import/src/GraphBuilderRegistry.cpp b/compiler/luci/import/src/GraphBuilderRegistry.cpp index 9f9bcb462ef..301e418a7b3 100644 --- a/compiler/luci/import/src/GraphBuilderRegistry.cpp +++ b/compiler/luci/import/src/GraphBuilderRegistry.cpp @@ -64,6 +64,7 @@ GraphBuilderRegistry::GraphBuilderRegistry() CIRCLE_NODE(GELU, CircleGeluGraphBuilder); // 150 CIRCLE_NODE(GREATER, CircleGreaterGraphBuilder); // 61 CIRCLE_NODE(GREATER_EQUAL, CircleGreaterEqualGraphBuilder); // 62 + CIRCLE_NODE(HARD_SWISH, CircleHardSwishGraphBuilder); // 117 CIRCLE_NODE(IF, CircleIfGraphBuilder); // 118 CIRCLE_NODE(INSTANCE_NORM, CircleInstanceNormGraphBuilder); // 254 CIRCLE_NODE(L2_NORMALIZATION, CircleL2NormalizeGraphBuilder); // 11 diff --git a/compiler/luci/import/src/Nodes/CircleHardSwish.cpp b/compiler/luci/import/src/Nodes/CircleHardSwish.cpp new file mode 100644 index 00000000000..47fc1c92cfe --- /dev/null +++ b/compiler/luci/import/src/Nodes/CircleHardSwish.cpp @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "luci/Import/Nodes/CircleHardSwish.h" + +#include + +#include + +namespace luci +{ + +bool CircleHardSwishGraphBuilder::validate(const ValidateArgs &args) const +{ + return GraphBuilder::validate(args, 1); +} + +CircleNode *CircleHardSwishGraphBuilder::build_node(const circle::OperatorT &, + const std::vector &inputs, + loco::Graph *graph) const +{ + auto *node = graph->nodes()->create(); + node->features(inputs.at(0)); + + return node; +} + +} // namespace luci From 6287c44491d049927c9a44bda752a0fe699c02b3 Mon Sep 17 00:00:00 2001 From: Seungho Henry Park <136296779+shs-park@users.noreply.github.com> Date: Mon, 31 Jul 2023 18:08:23 +0900 Subject: [PATCH 02/11] [luci/service] Support HardSwish operation (#11185) Support HardSwish operation in luci/service Signed-off-by: Seungho Henry Park --- .../luci/Service/CircleShapeInference.h | 1 + .../luci/Service/CircleTypeInference.h | 1 + compiler/luci/service/src/CircleCloneNode.h | 1 + .../service/src/CircleShapeInferenceRule.cpp | 7 ++ .../service/src/CircleTypeInferenceRule.cpp | 5 ++ .../service/src/Nodes/CircleHardSwish.cpp | 27 +++++++ .../src/Nodes/CircleHardSwish.test.cpp | 74 +++++++++++++++++++ 7 files changed, 116 insertions(+) create mode 100644 compiler/luci/service/src/Nodes/CircleHardSwish.cpp create mode 100644 compiler/luci/service/src/Nodes/CircleHardSwish.test.cpp diff --git a/compiler/luci/service/include/luci/Service/CircleShapeInference.h b/compiler/luci/service/include/luci/Service/CircleShapeInference.h index 2c112094116..92c5fb04cce 100644 --- a/compiler/luci/service/include/luci/Service/CircleShapeInference.h +++ b/compiler/luci/service/include/luci/Service/CircleShapeInference.h @@ -79,6 +79,7 @@ class Algorithm final : public luci::CircleNodeVisitor // loco::TensorShape visit(const luci::CircleGatherNd *node) final; // loco::TensorShape visit(const luci::CircleGreater *node) final; // loco::TensorShape visit(const luci::CircleGreaterEqual *node) final; + // loco::TensorShape visit(const luci::CircleHardSwish *node) final; // loco::TensorShape visit(const luci::CircleIf *node) final; // loco::TensorShape visit(const luci::CircleL2Normalize *node) final; // loco::TensorShape visit(const luci::CircleL2Pool2D *node) final; diff --git a/compiler/luci/service/include/luci/Service/CircleTypeInference.h b/compiler/luci/service/include/luci/Service/CircleTypeInference.h index e0ceabeac86..4f4ab0f34ab 100644 --- a/compiler/luci/service/include/luci/Service/CircleTypeInference.h +++ b/compiler/luci/service/include/luci/Service/CircleTypeInference.h @@ -78,6 +78,7 @@ class Algorithm final : public luci::CircleNodeVisitor // loco::DataType visit(const luci::CircleGatherNd *node) final; // loco::DataType visit(const luci::CircleGreater *node) final; // loco::DataType visit(const luci::CircleGreaterEqual *node) final; + // loco::DataType visit(const luci::CircleHardSwish *node) final; // loco::DataType visit(const luci::CircleIf *node) final; // loco::DataType visit(const luci::CircleL2Normalize *node) final; // loco::DataType visit(const luci::CircleL2Pool2D *node) final; diff --git a/compiler/luci/service/src/CircleCloneNode.h b/compiler/luci/service/src/CircleCloneNode.h index 3133bd476a8..e0b4dbc41bb 100644 --- a/compiler/luci/service/src/CircleCloneNode.h +++ b/compiler/luci/service/src/CircleCloneNode.h @@ -105,6 +105,7 @@ template <> class CloneNodeLet final : public luci::CircleNodeVisitor< luci::CircleNode *visit(const luci::CircleGelu *) final; luci::CircleNode *visit(const luci::CircleGreater *) final; luci::CircleNode *visit(const luci::CircleGreaterEqual *) final; + luci::CircleNode *visit(const luci::CircleHardSwish *) final; luci::CircleNode *visit(const luci::CircleIf *) final; luci::CircleNode *visit(const luci::CircleNode *) final { return nullptr; } diff --git a/compiler/luci/service/src/CircleShapeInferenceRule.cpp b/compiler/luci/service/src/CircleShapeInferenceRule.cpp index 5a272a6a97f..d56886c9731 100644 --- a/compiler/luci/service/src/CircleShapeInferenceRule.cpp +++ b/compiler/luci/service/src/CircleShapeInferenceRule.cpp @@ -2098,6 +2098,13 @@ class ShapeInferenceAlgorithm final : public luci::CircleNodeVisitorfeatures()).as(); + + return loco::NodeShape{input_shape}; + } + loco::NodeShape visit(const luci::CircleIf *node) final { // Shape of CircleIf is not used. Just use input 0 diff --git a/compiler/luci/service/src/CircleTypeInferenceRule.cpp b/compiler/luci/service/src/CircleTypeInferenceRule.cpp index f38bdd81f01..bd3feb977ed 100644 --- a/compiler/luci/service/src/CircleTypeInferenceRule.cpp +++ b/compiler/luci/service/src/CircleTypeInferenceRule.cpp @@ -181,6 +181,11 @@ struct TypeInferenceAlgorithm final : public luci::CircleNodeVisitorfeatures()); + } + loco::DataType visit(const luci::CircleIf *node) final { // Type of If is not used. Just use input 0 diff --git a/compiler/luci/service/src/Nodes/CircleHardSwish.cpp b/compiler/luci/service/src/Nodes/CircleHardSwish.cpp new file mode 100644 index 00000000000..bbc466e3f7f --- /dev/null +++ b/compiler/luci/service/src/Nodes/CircleHardSwish.cpp @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "CircleCloneNode.h" + +namespace luci +{ + +luci::CircleNode *CloneNodeLet::visit(const luci::CircleHardSwish *) +{ + return _graph->nodes()->create(); +} + +} // namespace luci diff --git a/compiler/luci/service/src/Nodes/CircleHardSwish.test.cpp b/compiler/luci/service/src/Nodes/CircleHardSwish.test.cpp new file mode 100644 index 00000000000..b79386bea90 --- /dev/null +++ b/compiler/luci/service/src/Nodes/CircleHardSwish.test.cpp @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "luci/Service/CircleNodeClone.h" + +#include +#include +#include + +#include + +#include + +TEST(ShapeRuleTest, simple_hardswish) +{ + luci::CircleInput input; + luci::CircleHardSwish hard_swish; + + input.shape({3, 4}); + input.shape_status(luci::ShapeStatus::VALID); + + hard_swish.features(&input); + + loco::TensorShape shape; + luci::sinf::Rule shape_inf_rule; + + ASSERT_TRUE(shape_inf_rule.infer(&hard_swish, shape)); + ASSERT_EQ(2, shape.rank()); + ASSERT_EQ(3, shape.dim(0).value()); + ASSERT_EQ(4, shape.dim(1).value()); +} + +TEST(DataTypeRuleTest, simple_hardswish) +{ + luci::CircleInput input; + luci::CircleHardSwish hard_swish; + + input.dtype(loco::DataType::S32); + + hard_swish.features(&input); + + loco::DataType dtype; + luci::tinf::Rule type_inf_rule; + + ASSERT_TRUE(type_inf_rule.infer(&hard_swish, dtype)); + ASSERT_EQ(loco::DataType::S32, dtype); +} + +TEST(CloneNodeTest, clone_HardSwish) +{ + auto g = loco::make_graph(); + auto node_hardswish = g->nodes()->create(); + + auto gc = loco::make_graph(); + auto cloned = luci::clone_node(node_hardswish, gc.get()); + ASSERT_NE(nullptr, cloned); + ASSERT_EQ(gc.get(), cloned->graph()); + + auto cloned_hardswish = dynamic_cast(cloned); + ASSERT_NE(nullptr, cloned_hardswish); +} From 3a1ba89635527eec323e7800252a830a9ccd7c0e Mon Sep 17 00:00:00 2001 From: batcheu Date: Mon, 31 Jul 2023 18:09:05 +0900 Subject: [PATCH 03/11] [moco-tf] Fix typo in header macro (#11186) This PR fixes typo in HEADER guard. ONE-DCO-1.0-Signed-off-by: Jonghwa Lee --- compiler/moco-tf/src/Canonicalization/SoftmaxCanonicalizer.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/moco-tf/src/Canonicalization/SoftmaxCanonicalizer.h b/compiler/moco-tf/src/Canonicalization/SoftmaxCanonicalizer.h index 0dd31503f52..33fc14a6d0b 100644 --- a/compiler/moco-tf/src/Canonicalization/SoftmaxCanonicalizer.h +++ b/compiler/moco-tf/src/Canonicalization/SoftmaxCanonicalizer.h @@ -15,7 +15,7 @@ */ #ifndef __MOCO_TF_SOFTMAX_CANONICALIZER_H__ -#define __MOCO_TF_SOFTMAx_CANONICALIZER_H__ +#define __MOCO_TF_SOFTMAX_CANONICALIZER_H__ #include "Transform.h" #include "SimpleNodeTransform.h" From b52bb16878d3eabddfd7595370b6163421361cff Mon Sep 17 00:00:00 2001 From: Evgenii Maltsev Date: Mon, 31 Jul 2023 16:02:54 +0300 Subject: [PATCH 04/11] [onert-micro] Support Resize Bilinear kernel (#11149) * [onert-micro] This commit adds support for the Resize Bilinear kernel. Supporting kernels. This commit adds support for the Resize Bilinear kernel. ONE-DCO-1.0-Signed-off-by: Evgenii Maltsev e.maltsev@samsung.com * [onert-micro] This commit fixes of the nnas format for the Resize Bilinear kernel support. --------- Co-authored-by: Evgenii Maltsev --- .../FloatResizeBilinearKernel.h | 190 ++++++++ .../resize_bilinear/NegResizeBilinearKernel.h | 461 ++++++++++++++++++ .../TestDataResizeBilinearBase.h | 61 +++ .../resize_bilinear/U8ResizeBilinearKernel.h | 208 ++++++++ .../luci-interpreter/pal/common/PALUtils.h | 8 + .../pal/mcu/KernelsToBuild.lst | 1 + .../pal/mcu/PALResizeBilinear.h | 116 ++++- .../src/kernels/ResizeBilinear.cpp | 109 +++-- .../src/kernels/ResizeBilinear.test.cpp | 323 +++++------- 9 files changed, 1241 insertions(+), 236 deletions(-) create mode 100644 onert-micro/luci-interpreter/include/luci_interpreter/test_models/resize_bilinear/FloatResizeBilinearKernel.h create mode 100644 onert-micro/luci-interpreter/include/luci_interpreter/test_models/resize_bilinear/NegResizeBilinearKernel.h create mode 100644 onert-micro/luci-interpreter/include/luci_interpreter/test_models/resize_bilinear/TestDataResizeBilinearBase.h create mode 100644 onert-micro/luci-interpreter/include/luci_interpreter/test_models/resize_bilinear/U8ResizeBilinearKernel.h diff --git a/onert-micro/luci-interpreter/include/luci_interpreter/test_models/resize_bilinear/FloatResizeBilinearKernel.h b/onert-micro/luci-interpreter/include/luci_interpreter/test_models/resize_bilinear/FloatResizeBilinearKernel.h new file mode 100644 index 00000000000..0ada18eaeb7 --- /dev/null +++ b/onert-micro/luci-interpreter/include/luci_interpreter/test_models/resize_bilinear/FloatResizeBilinearKernel.h @@ -0,0 +1,190 @@ +/* + * Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef LUCI_INTERPRETER_TEST_MODELS_FLOAT_RESIZE_BILINEAR_KERNEL_H +#define LUCI_INTERPRETER_TEST_MODELS_FLOAT_RESIZE_BILINEAR_KERNEL_H + +#include "TestDataResizeBilinearBase.h" + +namespace luci_interpreter +{ +namespace test_kernel +{ +namespace resize_bilinear_float +{ +/* + * ResizeBilinear Kernel: + * + * align_corners = false; half_pixel_centers = false; + * + * Input(2, 2, 2, 1) FLOAT + * | + * | Constant Input(2) [3,3] INT32 + * | / + * ResizeBilinear + * | + * Output(2, 3, 3, 1) FLOAT + */ +const unsigned char test_kernel_model_circle[] = { + 0x18, 0x00, 0x00, 0x00, 0x43, 0x49, 0x52, 0x30, 0x00, 0x00, 0x0e, 0x00, 0x14, 0x00, + 0x00, 0x00, 0x0c, 0x00, 0x08, 0x00, 0x10, 0x00, 0x04, 0x00, 0x0e, 0x00, 0x00, 0x00, + 0x10, 0x00, 0x00, 0x00, 0x48, 0x00, 0x00, 0x00, 0x84, 0x01, 0x00, 0x00, 0xa0, 0x01, + 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, + 0x24, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x08, 0x00, + 0x04, 0x00, 0x06, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x03, 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, + 0x60, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x68, 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, 0x0f, + 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, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x04, 0x00, + 0x00, 0x00, 0xa0, 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, 0x02, 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, 0x03, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x02, 0x10, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x73, 0x69, + 0x7a, 0x65, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 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, 0x10, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x69, 0x66, 0x6d, 0x31, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, + 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x0c, 0x00, + 0x0c, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x0c, 0x00, 0x00, 0x00, + 0x17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x17, 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 = { + 3, 6, // + 9, 12, // + 4, 10, // + 10, 16 // +}; + +const std::vector reference_output_data = { + 3, 5, 6, // + 7, 9, 10, // + 9, 11, 12, // + 4, 8, 10, // + 8, 12, 14, // + 10, 14, 16, // +}; + +} // namespace resize_bilinear_float + +namespace resize_bilinear_float_half_pixel_centers +{ +/* + * ResizeBilinear Kernel: + * + * align_corners = false; half_pixel_centers = true; + * + * Input(2, 2, 2, 1) FLOAT + * | + * | Constant Input(2) [3,3] INT32 + * | / + * ResizeBilinear + * | + * Output(2, 3, 3, 1) FLOAT + */ +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, + 0x4c, 0x00, 0x00, 0x00, 0x94, 0x01, 0x00, 0x00, 0xb0, 0x01, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x38, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x06, 0x00, 0x08, 0x00, 0x04, 0x00, 0x06, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x08, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0xf8, 0xff, 0xff, 0xff, + 0xfc, 0xff, 0xff, 0xff, 0x04, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x18, 0x00, 0x14, 0x00, 0x10, 0x00, 0x0c, 0x00, + 0x08, 0x00, 0x04, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, + 0x6c, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x74, 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, 0x0f, 0x18, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, + 0x20, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, + 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x78, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xa0, 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, 0x02, 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, 0x03, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x02, 0x10, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x73, 0x69, 0x7a, 0x65, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 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, 0x10, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x69, 0x66, 0x6d, 0x31, + 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x0c, 0x00, 0x0c, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x0c, 0x00, 0x00, 0x00, + 0x17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x17, 0x11, 0x00, 0x00, 0x00, 0x4f, 0x4e, 0x45, 0x2d, + 0x74, 0x66, 0x6c, 0x69, 0x74, 0x65, 0x32, 0x63, 0x69, 0x72, 0x63, 0x6c, 0x65, 0x00, 0x00, 0x00}; + +const std::vector input_data = { + 1, 2, // + 3, 4, // + 1, 2, // + 3, 4 // +}; + +const std::vector reference_output_data = { + 1, 1.5, 2, // + 2, 2.5, 3, // + 3, 3.5, 4, // + 1, 1.5, 2, // + 2, 2.5, 3, // + 3, 3.5, 4, // +}; + +} // namespace resize_bilinear_float_half_pixel_centers + +class TestDataFloatResizeBilinear : public TestDataResizeBilinearBase +{ +public: + TestDataFloatResizeBilinear(bool half_pixel_centers) + { + if (!half_pixel_centers) + { + _input_data = resize_bilinear_float::input_data; + _reference_output_data = resize_bilinear_float::reference_output_data; + _test_kernel_model_circle = resize_bilinear_float::test_kernel_model_circle; + } + else + { + _input_data = resize_bilinear_float_half_pixel_centers::input_data; + _reference_output_data = resize_bilinear_float_half_pixel_centers::reference_output_data; + _test_kernel_model_circle = + resize_bilinear_float_half_pixel_centers::test_kernel_model_circle; + } + } + + ~TestDataFloatResizeBilinear() override = default; +}; + +} // namespace test_kernel +} // namespace luci_interpreter + +#endif // LUCI_INTERPRETER_TEST_MODELS_FLOAT_RESIZE_BILINEAR_KERNEL_H diff --git a/onert-micro/luci-interpreter/include/luci_interpreter/test_models/resize_bilinear/NegResizeBilinearKernel.h b/onert-micro/luci-interpreter/include/luci_interpreter/test_models/resize_bilinear/NegResizeBilinearKernel.h new file mode 100644 index 00000000000..70133dcdbae --- /dev/null +++ b/onert-micro/luci-interpreter/include/luci_interpreter/test_models/resize_bilinear/NegResizeBilinearKernel.h @@ -0,0 +1,461 @@ +/* + * Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef LUCI_INTERPRETER_TEST_MODELS_NEG_RESIZE_BILINEAR_KERNEL_H +#define LUCI_INTERPRETER_TEST_MODELS_NEG_RESIZE_BILINEAR_KERNEL_H + +#include "TestDataResizeBilinearBase.h" + +namespace luci_interpreter +{ +namespace test_kernel +{ +namespace neg_invalid_input_shape_float_resize_bilinear_kernel +{ +/* + * ResizeBilinear Kernel (invalid_input_shape, dimensions should be 4): + * + * align_corners = false; half_pixel_centers = true; + * + * Input(2, 2, 2) FLOAT + * | + * | Constant Input(2) [3,3] INT32 + * | / + * ResizeBilinear + * | + * Output(2, 3, 3, 1) FLOAT + */ +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, + 0x4c, 0x00, 0x00, 0x00, 0x90, 0x01, 0x00, 0x00, 0xac, 0x01, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x38, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x06, 0x00, 0x08, 0x00, 0x04, 0x00, 0x06, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x08, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0xf8, 0xff, 0xff, 0xff, + 0xfc, 0xff, 0xff, 0xff, 0x04, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x18, 0x00, 0x14, 0x00, 0x10, 0x00, 0x0c, 0x00, + 0x08, 0x00, 0x04, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, + 0x6c, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x74, 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, 0x0f, 0x18, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, + 0x20, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, + 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x78, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xa0, 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, 0x02, 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, 0x03, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x02, 0x10, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x73, 0x69, 0x7a, 0x65, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 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, 0x10, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x69, 0x66, 0x6d, 0x31, + 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 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, 0x17, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x17, 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_invalid_input_shape_float_resize_bilinear_kernel + +namespace neg_invalid_param_float_resize_bilinear_kernel +{ +/* + * ResizeBilinear Kernel (invalid params: should be only param true "align_corners" or + * "half_pixel_centers" ): + * + * align_corners = true; half_pixel_centers = true; + * + * Input(2, 2, 2, 1) FLOAT + * | + * | Constant Input(2) [3,3] INT32 + * | / + * ResizeBilinear + * | + * Output(2, 3, 3, 1) FLOAT + */ +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, 0x4c, 0x00, 0x00, 0x00, 0x94, 0x01, 0x00, 0x00, 0xb0, 0x01, 0x00, 0x00, 0x04, + 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, + 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x08, 0x00, 0x04, 0x00, 0x06, 0x00, 0x00, + 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 0x00, + 0x00, 0x00, 0xf8, 0xff, 0xff, 0xff, 0xfc, 0xff, 0xff, 0xff, 0x04, 0x00, 0x04, 0x00, 0x04, + 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, + 0x18, 0x00, 0x14, 0x00, 0x10, 0x00, 0x0c, 0x00, 0x08, 0x00, 0x04, 0x00, 0x0e, 0x00, 0x00, + 0x00, 0x14, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x6c, 0x00, 0x00, 0x00, 0x70, 0x00, + 0x00, 0x00, 0x74, 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, 0x0f, 0x18, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x20, 0x00, + 0x00, 0x00, 0x0c, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x06, 0x00, 0x0c, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, + 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, + 0x00, 0x00, 0x78, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xa0, + 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, 0x02, 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, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x10, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x73, 0x69, 0x7a, 0x65, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, + 0x00, 0x02, 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, 0x10, + 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x69, 0x66, 0x6d, 0x31, 0x00, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, + 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x0c, 0x00, + 0x0c, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x17, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x17, 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_invalid_param_float_resize_bilinear_kernel + +namespace neg_invalid_size_shape_dimensions_float_resize_bilinear_kernel +{ +/* + * ResizeBilinear Kernel (invalid dimensions of the size shape ): + * + * align_corners = false; half_pixel_centers = false; + * + * Input(2, 2, 2, 1) FLOAT + * | + * | Constant Input(1) [3] INT32 + * | / + * ResizeBilinear + * | + * Output(2, 3, 3, 1) FLOAT + */ +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, + 0x44, 0x00, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x9c, 0x01, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x30, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x06, 0x00, 0x08, 0x00, 0x04, 0x00, 0x06, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 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, + 0x68, 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, 0x0f, + 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, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, 0x00, + 0x40, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xa0, 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, 0x02, 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, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, + 0x10, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x73, 0x69, 0x7a, 0x65, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, + 0x08, 0x00, 0x04, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x10, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x69, 0x66, 0x6d, 0x31, 0x00, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x0c, 0x00, + 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x17, 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_invalid_size_shape_dimensions_float_resize_bilinear_kernel + +namespace neg_invalid_input_shape_uint8_resize_bilinear_kernel +{ +/* + * ResizeBilinear Kernel (invalid_input_shape, dimensions should be 4): + * + * align_corners = false; half_pixel_centers = true; + * + * Input(2, 2, 2) UINT8 + * | + * | Constant Input(2) [3,3] INT32 + * | / + * ResizeBilinear + * | + * Output(2, 3, 3, 1) UINT8 + */ +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, 0x48, 0x00, 0x00, 0x00, 0x20, 0x02, 0x00, 0x00, 0x3c, 0x02, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, + 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x08, 0x00, 0x04, 0x00, 0x06, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 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, + 0x60, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x68, 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, 0x0f, 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, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x84, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x5a, 0xff, 0xff, 0xff, 0x14, 0x00, 0x00, 0x00, 0x48, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x03, 0x44, 0x00, 0x00, 0x00, 0x4c, 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, 0x7f, 0x43, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x6f, 0x66, 0x6d, 0x00, 0x05, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x0c, 0x00, 0x14, 0x00, 0x10, 0x00, 0x0f, 0x00, 0x08, 0x00, 0x04, 0x00, 0x0c, 0x00, 0x00, 0x00, + 0x10, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x10, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x73, 0x69, 0x7a, 0x65, 0x00, 0x00, 0x00, 0x00, 0x01, 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, 0x03, 0x58, 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, 0x7f, 0x43, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x69, 0x66, 0x6d, 0x31, 0x00, 0x00, 0x00, 0x00, + 0x05, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x0c, 0x00, 0x0c, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x0c, 0x00, 0x00, 0x00, + 0x17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x17, 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_invalid_input_shape_uint8_resize_bilinear_kernel + +namespace neg_invalid_param_uint8_resize_bilinear_kernel +{ +/* + * ResizeBilinear Kernel (invalid params: should be only param true "align_corners" or + * "half_pixel_centers" ): + * + * align_corners = true; half_pixel_centers = true; + * + * Input(2, 2, 2, 1) UINT8 + * | + * | Constant Input(2) [3,3] INT32 + * | / + * ResizeBilinear + * | + * Output(2, 3, 3, 1) UINT8 + */ +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, 0x48, 0x00, 0x00, 0x00, 0x20, 0x02, 0x00, 0x00, 0x3c, + 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, + 0x24, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x08, 0x00, 0x04, + 0x00, 0x06, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x03, 0x00, + 0x00, 0x00, 0x03, 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, 0x60, 0x00, 0x00, 0x00, 0x64, 0x00, + 0x00, 0x00, 0x68, 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, 0x0f, 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, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x03, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x84, 0x00, 0x00, 0x00, 0x04, 0x00, + 0x00, 0x00, 0x5a, 0xff, 0xff, 0xff, 0x14, 0x00, 0x00, 0x00, 0x48, 0x00, 0x00, 0x00, 0x02, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x44, 0x00, 0x00, 0x00, 0x4c, 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, 0x7f, 0x43, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x6f, 0x66, 0x6d, 0x00, + 0x05, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, + 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x14, 0x00, 0x10, 0x00, + 0x0f, 0x00, 0x08, 0x00, 0x04, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x03, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x10, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x73, 0x69, 0x7a, 0x65, 0x00, 0x00, 0x00, 0x00, 0x01, 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, 0x03, 0x58, 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, 0x7f, 0x43, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x69, 0x66, 0x6d, + 0x31, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, + 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, + 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x0c, 0x00, 0x0b, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x04, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x17, 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_invalid_param_uint8_resize_bilinear_kernel + +namespace neg_invalid_size_shape_dimensions_uint8_resize_bilinear_kernel +{ +/* + * ResizeBilinear Kernel (invalid dimensions of the size shape ): + * + * align_corners = false; half_pixel_centers = false; + * + * Input(2, 2, 2, 1) UINT8 + * | + * | Constant Input(1) [3] INT32 + * | / + * ResizeBilinear + * | + * Output(2, 3, 3, 1) UINT8 + */ +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, + 0x44, 0x00, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x9c, 0x01, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x30, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x06, 0x00, 0x08, 0x00, 0x04, 0x00, 0x06, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 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, + 0x68, 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, 0x0f, + 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, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, 0x00, + 0x40, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xa0, 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, 0x02, 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, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, + 0x10, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x73, 0x69, 0x7a, 0x65, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, + 0x08, 0x00, 0x04, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x10, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x69, 0x66, 0x6d, 0x31, 0x00, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x0c, 0x00, + 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x17, 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_invalid_size_shape_dimensions_uint8_resize_bilinear_kernel + +class NegTestDataInvalidInputShapeFloatResizeBilinearKernel : public NegTestDataBase +{ +public: + NegTestDataInvalidInputShapeFloatResizeBilinearKernel() + { + _test_kernel_model_circle = + neg_invalid_input_shape_float_resize_bilinear_kernel::test_kernel_model_circle; + } + + ~NegTestDataInvalidInputShapeFloatResizeBilinearKernel() override = default; + + const unsigned char *get_model_ptr() override final { return _test_kernel_model_circle; } + +protected: + const unsigned char *_test_kernel_model_circle; +}; + +class NegTestDataInvalidParamFloatResizeBilinearKernel : public NegTestDataBase +{ +public: + NegTestDataInvalidParamFloatResizeBilinearKernel() + { + _test_kernel_model_circle = + neg_invalid_param_float_resize_bilinear_kernel::test_kernel_model_circle; + } + + ~NegTestDataInvalidParamFloatResizeBilinearKernel() override = default; + + const unsigned char *get_model_ptr() override final { return _test_kernel_model_circle; } + +protected: + const unsigned char *_test_kernel_model_circle; +}; + +class NegTestDataInvalidSizeShapeDimensionsFloatResizeBilinearKernel : public NegTestDataBase +{ +public: + NegTestDataInvalidSizeShapeDimensionsFloatResizeBilinearKernel() + { + _test_kernel_model_circle = + neg_invalid_size_shape_dimensions_float_resize_bilinear_kernel::test_kernel_model_circle; + } + + ~NegTestDataInvalidSizeShapeDimensionsFloatResizeBilinearKernel() override = default; + + const unsigned char *get_model_ptr() override final { return _test_kernel_model_circle; } + +protected: + const unsigned char *_test_kernel_model_circle; +}; + +class NegTestDataInvalidInputShapeUint8ResizeBilinearKernel : public NegTestDataBase +{ +public: + NegTestDataInvalidInputShapeUint8ResizeBilinearKernel() + { + _test_kernel_model_circle = + neg_invalid_input_shape_uint8_resize_bilinear_kernel::test_kernel_model_circle; + } + + ~NegTestDataInvalidInputShapeUint8ResizeBilinearKernel() override = default; + + const unsigned char *get_model_ptr() override final { return _test_kernel_model_circle; } + +protected: + const unsigned char *_test_kernel_model_circle; +}; + +class NegTestDataInvalidParamUint8ResizeBilinearKernel : public NegTestDataBase +{ +public: + NegTestDataInvalidParamUint8ResizeBilinearKernel() + { + _test_kernel_model_circle = + neg_invalid_param_uint8_resize_bilinear_kernel::test_kernel_model_circle; + } + + ~NegTestDataInvalidParamUint8ResizeBilinearKernel() override = default; + + const unsigned char *get_model_ptr() override final { return _test_kernel_model_circle; } + +protected: + const unsigned char *_test_kernel_model_circle; +}; + +class NegTestDataInvalidSizeShapeDimensionsUint8ResizeBilinearKernel : public NegTestDataBase +{ +public: + NegTestDataInvalidSizeShapeDimensionsUint8ResizeBilinearKernel() + { + _test_kernel_model_circle = + neg_invalid_size_shape_dimensions_uint8_resize_bilinear_kernel::test_kernel_model_circle; + } + + ~NegTestDataInvalidSizeShapeDimensionsUint8ResizeBilinearKernel() override = default; + + const unsigned char *get_model_ptr() override final { return _test_kernel_model_circle; } + +protected: + const unsigned char *_test_kernel_model_circle; +}; + +} // namespace test_kernel +} // namespace luci_interpreter + +#endif // LUCI_INTERPRETER_TEST_MODELS_NEG_RESIZE_BILINEAR_KERNEL_H diff --git a/onert-micro/luci-interpreter/include/luci_interpreter/test_models/resize_bilinear/TestDataResizeBilinearBase.h b/onert-micro/luci-interpreter/include/luci_interpreter/test_models/resize_bilinear/TestDataResizeBilinearBase.h new file mode 100644 index 00000000000..21808511110 --- /dev/null +++ b/onert-micro/luci-interpreter/include/luci_interpreter/test_models/resize_bilinear/TestDataResizeBilinearBase.h @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef LUCI_INTERPRETER_TEST_MODELS_RESIZE_BILINEAR_KERNEL_BASE_H +#define LUCI_INTERPRETER_TEST_MODELS_RESIZE_BILINEAR_KERNEL_BASE_H + +#include "luci_interpreter/test_models/TestDataBase.h" + +namespace luci_interpreter +{ +namespace test_kernel +{ + +template class TestDataResizeBilinearBase : public TestDataBase +{ +public: + TestDataResizeBilinearBase() = default; + + const unsigned char *get_model_ptr() override final { return _test_kernel_model_circle; } + + const std::vector &get_input_data_by_index(int i) override final + { + switch (i) + { + case 0: + return _input_data; + default: + assert(false && "Wrong input index"); + } + } + + const std::vector &get_output_data_by_index(int i) override final + { + assert(i == 0); + return _reference_output_data; + } + +protected: + std::vector _input_data; + std::vector _reference_output_data; + + const unsigned char *_test_kernel_model_circle; +}; + +} // namespace test_kernel +} // namespace luci_interpreter + +#endif // LUCI_INTERPRETER_TEST_MODELS_RESIZE_BILINEAR_KERNEL_BASE_H diff --git a/onert-micro/luci-interpreter/include/luci_interpreter/test_models/resize_bilinear/U8ResizeBilinearKernel.h b/onert-micro/luci-interpreter/include/luci_interpreter/test_models/resize_bilinear/U8ResizeBilinearKernel.h new file mode 100644 index 00000000000..7c422b1e443 --- /dev/null +++ b/onert-micro/luci-interpreter/include/luci_interpreter/test_models/resize_bilinear/U8ResizeBilinearKernel.h @@ -0,0 +1,208 @@ +/* + * Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef LUCI_INTERPRETER_TEST_MODELS_UINT8_RESIZE_BILINEAR_KERNEL_H +#define LUCI_INTERPRETER_TEST_MODELS_UINT8_RESIZE_BILINEAR_KERNEL_H + +#include "TestDataResizeBilinearBase.h" + +namespace luci_interpreter +{ +namespace test_kernel +{ + +namespace resize_bilinear_uint8 +{ +/* + * ResizeBilinear Kernel: + * + * align_corners = false; half_pixel_centers = false; + * + * Input(2, 2, 2, 1) UINT8 + * | + * | Constant Input(2) [3,3] INT32 + * | / + * ResizeBilinear + * | + * Output(2, 3, 3, 1) UINT8 + */ +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, 0x48, 0x00, 0x00, 0x00, 0x18, 0x02, 0x00, 0x00, 0x34, 0x02, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, + 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x08, 0x00, 0x04, 0x00, 0x06, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 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, + 0x60, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x68, 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, 0x0f, 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, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x84, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x5a, 0xff, 0xff, 0xff, 0x14, 0x00, 0x00, 0x00, 0x4c, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x03, 0x48, 0x00, 0x00, 0x00, 0x4c, 0xff, 0xff, 0xff, 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, 0x7f, 0x43, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x6f, 0x66, 0x6d, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x02, 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, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x10, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x73, 0x69, 0x7a, 0x65, 0x00, 0x00, 0x00, 0x00, 0x01, 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, 0x54, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x54, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x14, 0x00, + 0x04, 0x00, 0x08, 0x00, 0x0c, 0x00, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 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, 0x7f, 0x43, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x69, 0x66, 0x6d, 0x31, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x0c, 0x00, 0x0b, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x04, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x17, + 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 = { + 3, 6, // + 9, 12, // + 4, 10, // + 10, 16 // +}; + +const std::vector reference_output_data = { + 3, 5, 6, // + 7, 9, 10, // + 9, 11, 12, // + 4, 8, 10, // + 8, 12, 14, // + 10, 14, 16, // +}; + +} // namespace resize_bilinear_uint8 + +namespace resize_bilinear_uint8_half_pixel_centers +{ +/* + * ResizeBilinear Kernel: + * + * align_corners = false; half_pixel_centers = true; + * + * Input(2, 2, 2, 1) UINT8 + * | + * | Constant Input(2) [3,3] INT32 + * | / + * ResizeBilinear + * | + * Output(2, 3, 3, 1) UINT8 + */ +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, 0x4c, 0x00, 0x00, 0x00, 0x28, 0x02, 0x00, 0x00, 0x44, 0x02, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, + 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x08, 0x00, 0x04, 0x00, 0x06, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0xf8, 0xff, 0xff, 0xff, 0xfc, 0xff, 0xff, 0xff, 0x04, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x18, 0x00, 0x14, 0x00, + 0x10, 0x00, 0x0c, 0x00, 0x08, 0x00, 0x04, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, + 0x1c, 0x00, 0x00, 0x00, 0x6c, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x74, 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, 0x0f, 0x18, 0x00, 0x00, 0x00, + 0x1c, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x07, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x84, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x5a, 0xff, 0xff, 0xff, 0x14, 0x00, 0x00, 0x00, 0x4c, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x03, 0x48, 0x00, 0x00, 0x00, 0x4c, 0xff, 0xff, 0xff, 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, 0x7f, 0x43, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x6f, 0x66, 0x6d, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x02, 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, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x10, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x73, 0x69, 0x7a, 0x65, 0x00, 0x00, 0x00, 0x00, 0x01, 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, 0x54, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x54, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x14, 0x00, + 0x04, 0x00, 0x08, 0x00, 0x0c, 0x00, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 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, 0x7f, 0x43, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x69, 0x66, 0x6d, 0x31, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x0c, 0x00, 0x0b, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x04, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x17, + 0x11, 0x00, 0x00, 0x00, 0x4f, 0x4e, 0x45, 0x2d, 0x74, 0x66, 0x6c, 0x69, 0x74, 0x65, 0x32, 0x63, + 0x69, 0x72, 0x63, 0x6c, 0x65, 0x00, 0x00, 0x00 + +}; + +const std::vector input_data = { + 1, 2, // + 3, 4, // + 1, 2, // + 3, 4 // +}; + +const std::vector reference_output_data = { + 1, 2, 2, // + 2, 3, 3, // + 3, 4, 4, // + 1, 2, 2, // + 2, 3, 3, // + 3, 4, 4, // +}; + +} // namespace resize_bilinear_uint8_half_pixel_centers + +class TestDataUint8ResizeBilinear : public TestDataResizeBilinearBase +{ +public: + TestDataUint8ResizeBilinear(bool half_pixel_centers) + { + if (!half_pixel_centers) + { + _input_data = resize_bilinear_uint8::input_data; + _reference_output_data = resize_bilinear_uint8::reference_output_data; + _test_kernel_model_circle = resize_bilinear_uint8::test_kernel_model_circle; + } + else + { + _input_data = resize_bilinear_uint8_half_pixel_centers::input_data; + _reference_output_data = resize_bilinear_uint8_half_pixel_centers::reference_output_data; + _test_kernel_model_circle = + resize_bilinear_uint8_half_pixel_centers::test_kernel_model_circle; + } + } + + ~TestDataUint8ResizeBilinear() override = default; +}; + +} // namespace test_kernel +} // namespace luci_interpreter + +#endif // LUCI_INTERPRETER_TEST_MODELS_UINT8_RESIZE_BILINEAR_KERNEL_H diff --git a/onert-micro/luci-interpreter/pal/common/PALUtils.h b/onert-micro/luci-interpreter/pal/common/PALUtils.h index 7578dfde637..1e05bfc7b06 100644 --- a/onert-micro/luci-interpreter/pal/common/PALUtils.h +++ b/onert-micro/luci-interpreter/pal/common/PALUtils.h @@ -169,6 +169,14 @@ inline bool nextIndex(const int num_dims, const int *dims, int *current) return (carry == 0); } +// Get common shape dim, assert that they all agree. +inline int MatchingDim(const luci_interpreter::RuntimeShape &shape1, int index1, + const luci_interpreter::RuntimeShape &shape2, int index2) +{ + assert(shape1.dims(index1) == shape2.dims(index2)); + return shape1.dims(index1); +} + } // namespace luci_interpreter_pal #endif // LUCI_INTERPRETER_PAL_UTILS_H diff --git a/onert-micro/luci-interpreter/pal/mcu/KernelsToBuild.lst b/onert-micro/luci-interpreter/pal/mcu/KernelsToBuild.lst index 9da97cce133..0ee376cb3e9 100644 --- a/onert-micro/luci-interpreter/pal/mcu/KernelsToBuild.lst +++ b/onert-micro/luci-interpreter/pal/mcu/KernelsToBuild.lst @@ -36,4 +36,5 @@ REGISTER_KERNEL(TRANSPOSE, Transpose) REGISTER_KERNEL(SOFTMAX, Softmax) REGISTER_KERNEL(WHILE, While) REGISTER_KERNEL(UNIDIRECTIONAL_SEQUENCE_LSTM, UnidirectionalSequenceLSTM) +REGISTER_KERNEL(RESIZE_BILINEAR, ResizeBilinear) REGISTER_KERNEL(NEG, Neg) diff --git a/onert-micro/luci-interpreter/pal/mcu/PALResizeBilinear.h b/onert-micro/luci-interpreter/pal/mcu/PALResizeBilinear.h index 4db7fa8e749..b2808b2d024 100644 --- a/onert-micro/luci-interpreter/pal/mcu/PALResizeBilinear.h +++ b/onert-micro/luci-interpreter/pal/mcu/PALResizeBilinear.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. All Rights Reserved + * Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,21 +17,119 @@ #ifndef LUCI_INTERPRETER_PAL_RESIZEBILINEAR_H #define LUCI_INTERPRETER_PAL_RESIZEBILINEAR_H -#include +#include "PALUtils.h" namespace luci_interpreter_pal { + +// Offset function for positining corresponding index in input data +// int i0 - batches, int i1 - height, int i2 - width, int i3 - depth +inline int Offset(const luci_interpreter::RuntimeShape &shape, int i0, int i1, int i2, int i3) +{ + assert(shape.dimensionsCount() == 4); + + const int32_t *dims_data = reinterpret_cast(shape.dimsData()); + LUCI_INTERPRETER_CHECK(i0 >= 0 && i0 < dims_data[0]); + LUCI_INTERPRETER_CHECK(i1 >= 0 && i1 < dims_data[1]); + LUCI_INTERPRETER_CHECK(i2 >= 0 && i2 < dims_data[2]); + LUCI_INTERPRETER_CHECK(i3 >= 0 && i3 < dims_data[3]); + return ((i0 * dims_data[1] + i1) * dims_data[2] + i2) * dims_data[3] + i3; +} + +inline void ComputeInterpolationValues(const float value, const float scale, + const bool half_pixel_centers, int32_t input_size, + float *scaled_value, int32_t *lower_bound, + int32_t *upper_bound) +{ + if (half_pixel_centers) + { + *scaled_value = (value + 0.5f) * scale - 0.5f; + } + else + { + *scaled_value = value * scale; + } + float scaled_value_floor = std::floor(*scaled_value); + *lower_bound = std::max(static_cast(scaled_value_floor), static_cast(0)); + *upper_bound = std::min(static_cast(std::ceil(*scaled_value)), input_size - 1); +} + template static inline void -ResizeBilinear(const tflite::ResizeBilinearParams &op_params, - const tflite::RuntimeShape &unextended_input_shape, const T *input_data, - const tflite::RuntimeShape &output_size_shape, const int32_t *output_size_data, - const tflite::RuntimeShape &unextended_output_shape, T *output_data) +ResizeBilinear(const circle::ResizeBilinearOptions *op_params, + const luci_interpreter::RuntimeShape &unextended_input_shape, const T *input_data, + const luci_interpreter::RuntimeShape &unextended_output_size_shape, + const int32_t *output_size_data, + const luci_interpreter::RuntimeShape &unextended_output_shape, T *output_data) { - tflite::reference_ops::ResizeBilinear(op_params, unextended_input_shape, input_data, - output_size_shape, output_size_data, - unextended_output_shape, output_data); + // If half_pixel_centers is True, align_corners must be False. + LUCI_INTERPRETER_CHECK(!op_params->half_pixel_centers() || !op_params->align_corners()); + + assert(unextended_input_shape.dimensionsCount() >= 4); + assert(unextended_output_size_shape.dimensionsCount() >= 1); + assert(unextended_output_shape.dimensionsCount() >= 4); + const luci_interpreter::RuntimeShape input_shape = + luci_interpreter::RuntimeShape::extendedShape(4, unextended_input_shape); + const luci_interpreter::RuntimeShape output_size_shape = + luci_interpreter::RuntimeShape::extendedShape(4, unextended_output_size_shape); + const luci_interpreter::RuntimeShape output_shape = + luci_interpreter::RuntimeShape::extendedShape(4, unextended_output_shape); + + int32_t batches = MatchingDim(input_shape, 0, output_shape, 0); + int32_t input_height = input_shape.dims(1); + int32_t input_width = input_shape.dims(2); + int32_t depth = MatchingDim(input_shape, 3, output_shape, 3); + + assert(output_size_shape.dims(0) == 1); + assert(output_size_shape.dims(1) == 1); + assert(output_size_shape.dims(2) == 1); + assert(output_size_shape.dims(3) == 2); + + int32_t output_height = output_size_data[Offset(output_size_shape, 0, 0, 0, 0)]; + int32_t output_width = output_size_data[Offset(output_size_shape, 0, 0, 0, 1)]; + + float height_scale = static_cast(input_height) / output_height; + float width_scale = static_cast(input_width) / output_width; + if (op_params->align_corners() && output_height > 1) + { + height_scale = static_cast(input_height - 1) / (output_height - 1); + } + if (op_params->align_corners() && output_width > 1) + { + width_scale = static_cast(input_width - 1) / (output_width - 1); + } + const float rounding_offset = std::numeric_limits::is_integer ? .5f : .0f; + + for (int b = 0; b < batches; ++b) + { + for (int y = 0; y < output_height; ++y) + { + float input_y; + int32_t y0, y1; + ComputeInterpolationValues(y, height_scale, op_params->half_pixel_centers(), input_height, + &input_y, &y0, &y1); + for (int x = 0; x < output_width; ++x) + { + float input_x; + int32_t x0, x1; + ComputeInterpolationValues(x, width_scale, op_params->half_pixel_centers(), input_width, + &input_x, &x0, &x1); + for (int c = 0; c < depth; ++c) + { + T interpolation = static_cast( + input_data[Offset(input_shape, b, y0, x0, c)] * (1 - (input_y - y0)) * + (1 - (input_x - x0)) + + input_data[Offset(input_shape, b, y1, x0, c)] * (input_y - y0) * (1 - (input_x - x0)) + + input_data[Offset(input_shape, b, y0, x1, c)] * (1 - (input_y - y0)) * (input_x - x0) + + input_data[Offset(input_shape, b, y1, x1, c)] * (input_y - y0) * (input_x - x0) + + rounding_offset); + output_data[Offset(output_shape, b, y, x, c)] = interpolation; + } + } + } + } } + } // namespace luci_interpreter_pal #endif // LUCI_INTERPRETER_PAL_RESIZEBILINEAR_H diff --git a/onert-micro/luci-interpreter/src/kernels/ResizeBilinear.cpp b/onert-micro/luci-interpreter/src/kernels/ResizeBilinear.cpp index 8d07ea70e31..7ce3833b359 100644 --- a/onert-micro/luci-interpreter/src/kernels/ResizeBilinear.cpp +++ b/onert-micro/luci-interpreter/src/kernels/ResizeBilinear.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved + * Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved * Copyright 2019 The TensorFlow Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,61 +15,104 @@ * limitations under the License. */ -#include "kernels/ResizeBilinear.h" - +#include "Builders.h" #include "kernels/Utils.h" +#include "kernels/BinaryOpCommon.h" + #include "PALResizeBilinear.h" namespace luci_interpreter { -namespace kernels -{ -ResizeBilinear::ResizeBilinear(const Tensor *input, const Tensor *size, Tensor *output, - const ResizeBilinearParams ¶ms) - : KernelWithParams({input, size}, {output}, params) -{ -} +/* + * ResizeBilinear Kernel: + * Description: resizing input Tensor by input constants using Bilinear Interpolation + * 2 Inputs: Input tensor ( Shape dimensions count = 4); Input constant (Shape dimensions count = 1, + * Num elements =2) Parameters: align_corners; half_pixel_centers; + * + * Example: + * Input(2, 2, 2, 1) + * | + * | Constant Input(2) [3,3] INT32 + * | / + * ResizeBilinear + * | + * Output(2, 3, 3, 1) UINT8 + */ -void ResizeBilinear::configure() +void configure_kernel_CircleResizeBilinear(const circle::Operator *cur_op, + BaseRuntimeGraph *runtime_graph) { - LUCI_INTERPRETER_CHECK(input()->shape().num_dims() == 4); - LUCI_INTERPRETER_CHECK(size()->shape().num_dims() == 1); - LUCI_INTERPRETER_CHECK(size()->element_type() == DataType::S32); - if (params().half_pixel_centers && params().align_corners) + // Check of the size of input. Should be 2 + assert(cur_op->inputs()->size() == 2); + const auto input_index = cur_op->inputs()->operator[](0); + const auto size_index = cur_op->inputs()->operator[](1); + const auto output_index = cur_op->outputs()->operator[](0); + + assert(input_index != -1); + assert(size_index != -1); + assert(output_index != -1); + // Get tensors + const auto input = runtime_graph->getCircleTensorByIndex(input_index); + const auto size = runtime_graph->getCircleTensorByIndex(size_index); + const auto output = runtime_graph->getCircleTensorByIndex(output_index); + // Check of the Input shape + assert(kernels::getTensorShape(input).dimensionsCount() == 4); + // Check of the Const input size shape + assert(kernels::getTensorShape(size).dimensionsCount() == 1); + assert(Tensor::element_type(size) == DataType::S32); + assert(kernels::getTensorShape(size).dims(0) == 2); + + const auto *params = cur_op->builtin_options_as_ResizeBilinearOptions(); + if (params->half_pixel_centers() && params->align_corners()) assert(false && "If half_pixel_centers is True, align_corners must be False."); - LUCI_INTERPRETER_CHECK(size()->shape().dim(0) == 2); - Shape output_shape(4); - output_shape.dim(0) = input()->shape().dim(0); - output_shape.dim(1) = getTensorData(size())[0]; - output_shape.dim(2) = getTensorData(size())[1]; - output_shape.dim(3) = input()->shape().dim(3); - // TODO: enable it only if kernel with dynamic shapes - output()->resize(output_shape); } -void ResizeBilinear::execute() const +void execute_kernel_CircleResizeBilinear(const circle::Operator *cur_op, + BaseRuntimeGraph *runtime_graph) { - tflite::ResizeBilinearParams op_params{}; - op_params.align_corners = params().align_corners; - op_params.half_pixel_centers = params().half_pixel_centers; - switch (output()->element_type()) + assert(cur_op->inputs()->size() == 2); + const auto input_index = cur_op->inputs()->operator[](0); + const auto size_index = cur_op->inputs()->operator[](1); + const auto output_index = cur_op->outputs()->operator[](0); + + assert(input_index != -1); + assert(size_index != -1); + assert(output_index != -1); + + const auto input = runtime_graph->getCircleTensorByIndex(input_index); + const auto size = runtime_graph->getCircleTensorByIndex(size_index); + const auto output = runtime_graph->getCircleTensorByIndex(output_index); + + const uint8_t *input_data = runtime_graph->getDataByTensor(input); + const uint8_t *size_data = runtime_graph->getConstDataByTensor(size); + uint8_t *output_data = runtime_graph->getDataByTensor(output); + + assert(input_data != nullptr); + assert(size_data != nullptr); + assert(output_data != nullptr); + + // Get parameters + const auto *op_params = cur_op->builtin_options_as_ResizeBilinearOptions(); + + switch (Tensor::element_type(output)) { case DataType::FLOAT32: luci_interpreter_pal::ResizeBilinear( - op_params, getTensorShape(input()), getTensorData(input()), getTensorShape(size()), - getTensorData(size()), getTensorShape(output()), getTensorData(output())); + op_params, kernels::getTensorShape(input), kernels::getTensorData(input_data), + kernels::getTensorShape(size), kernels::getTensorData(size_data), + kernels::getTensorShape(output), kernels::getTensorData(output_data)); break; case DataType::U8: luci_interpreter_pal::ResizeBilinear( - op_params, getTensorShape(input()), getTensorData(input()), getTensorShape(size()), - getTensorData(size()), getTensorShape(output()), getTensorData(output())); + op_params, kernels::getTensorShape(input), kernels::getTensorData(input_data), + kernels::getTensorShape(size), kernels::getTensorData(size_data), + kernels::getTensorShape(output), kernels::getTensorData(output_data)); break; default: assert(false && "Unsupported type."); } } -} // namespace kernels } // namespace luci_interpreter diff --git a/onert-micro/luci-interpreter/src/kernels/ResizeBilinear.test.cpp b/onert-micro/luci-interpreter/src/kernels/ResizeBilinear.test.cpp index 933a1128c6f..d8ecae5a0f4 100644 --- a/onert-micro/luci-interpreter/src/kernels/ResizeBilinear.test.cpp +++ b/onert-micro/luci-interpreter/src/kernels/ResizeBilinear.test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved + * Copyright (c) 2023 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"); @@ -15,9 +15,11 @@ * limitations under the License. */ -#include "kernels/ResizeBilinear.h" #include "kernels/TestUtils.h" -#include "luci_interpreter/TestMemoryManager.h" +#include "loader/ModuleLoader.h" +#include "luci_interpreter/test_models/resize_bilinear/FloatResizeBilinearKernel.h" +#include "luci_interpreter/test_models/resize_bilinear/U8ResizeBilinearKernel.h" +#include "luci_interpreter/test_models/resize_bilinear/NegResizeBilinearKernel.h" namespace luci_interpreter { @@ -28,226 +30,159 @@ namespace using namespace testing; +class ResizeBilinearTest : public ::testing::Test +{ + // Do nothing +}; + template -void Check(std::initializer_list input_shape, std::initializer_list size_shape, - std::initializer_list output_shape, std::initializer_list input_data, - std::initializer_list size_data, std::initializer_list output_data, - bool align_corners, bool half_pixel_centers) +std::vector checkResizeBilinearKernel(test_kernel::TestDataBase *test_data_base) { - std::unique_ptr memory_manager = std::make_unique(); - Tensor input_tensor = - makeInputTensor(input_shape, input_data, memory_manager.get()); - Tensor size_tensor = makeInputTensor(size_shape, size_data, memory_manager.get()); - Tensor output_tensor = makeOutputTensor(DataType::FLOAT32); - - ResizeBilinearParams params{}; - params.align_corners = align_corners; - params.half_pixel_centers = half_pixel_centers; - - ResizeBilinear kernel(&input_tensor, &size_tensor, &output_tensor, params); - kernel.configure(); - memory_manager->allocate_memory(output_tensor); - kernel.execute(); - - EXPECT_THAT(extractTensorShape(output_tensor), ::testing::ElementsAreArray(output_shape)); - EXPECT_THAT(extractTensorData(output_tensor), FloatArrayNear(output_data)); + MemoryManager memory_manager{}; + RuntimeModule runtime_module{}; + bool dealloc_input = true; + + // Load model with single op + auto *model_data_raw = reinterpret_cast(test_data_base->get_model_ptr()); + ModuleLoader::load(&runtime_module, &memory_manager, model_data_raw, dealloc_input); + + auto *main_runtime_graph = runtime_module.getMainGraph(); + assert(main_runtime_graph->getNumOfInputTensors() == 1); + + // Set input data + { + auto *input_tensor_data = reinterpret_cast(main_runtime_graph->configureGraphInput(0)); + std::copy(test_data_base->get_input_data_by_index(0).begin(), + test_data_base->get_input_data_by_index(0).end(), input_tensor_data); + } + + runtime_module.execute(); + + assert(main_runtime_graph->getNumOfOutputTensors() == 1); + + T *output_data = reinterpret_cast(main_runtime_graph->getOutputDataByIndex(0)); + const size_t num_elements = (main_runtime_graph->getOutputDataSizeByIndex(0) / sizeof(T)); + std::vector output_data_vector(output_data, output_data + num_elements); + return output_data_vector; } -template <> -void Check(std::initializer_list input_shape, - std::initializer_list size_shape, - std::initializer_list output_shape, - std::initializer_list input_data, - std::initializer_list size_data, - std::initializer_list output_data, bool align_corners, - bool half_pixel_centers) +TEST_F(ResizeBilinearTest, Float_P) { - // On TFlite example use Uint8 value it self, so this means quant param scale 1.0f and zero - // point 0. - std::unique_ptr memory_manager = std::make_unique(); - - Tensor input_tensor = - makeInputTensor(input_shape, 1.0, 0, input_data, memory_manager.get()); - Tensor size_tensor = makeInputTensor(size_shape, size_data, memory_manager.get()); - Tensor output_tensor = makeOutputTensor(DataType::U8, 1.0, 0); - - ResizeBilinearParams params{}; - params.align_corners = align_corners; - params.half_pixel_centers = half_pixel_centers; - - ResizeBilinear kernel(&input_tensor, &size_tensor, &output_tensor, params); - kernel.configure(); - memory_manager->allocate_memory(output_tensor); - kernel.execute(); - - EXPECT_THAT(extractTensorShape(output_tensor), ::testing::ElementsAreArray(output_shape)); - EXPECT_THAT(dequantizeTensorData(output_tensor), - FloatArrayNear(output_data, output_tensor.scale())); + test_kernel::TestDataFloatResizeBilinear test_data_kernel(false); + std::vector output_data_vector = checkResizeBilinearKernel(&test_data_kernel); + + EXPECT_THAT(output_data_vector, + FloatArrayNear(test_data_kernel.get_output_data_by_index(0), 0.0001f)); } -template class ResizeBilinearTest : public ::testing::Test +TEST_F(ResizeBilinearTest, HalfPixelCenter_Float_P) { -}; -using DataTypes = ::testing::Types; -TYPED_TEST_SUITE(ResizeBilinearTest, DataTypes); + test_kernel::TestDataFloatResizeBilinear test_data_kernel(true); + std::vector output_data_vector = checkResizeBilinearKernel(&test_data_kernel); + + EXPECT_THAT(output_data_vector, + FloatArrayNear(test_data_kernel.get_output_data_by_index(0), 0.0001f)); +} + +TEST_F(ResizeBilinearTest, Uint8_P) +{ + test_kernel::TestDataUint8ResizeBilinear test_data_kernel(false); + std::vector output_data_vector = checkResizeBilinearKernel(&test_data_kernel); + + EXPECT_THAT(output_data_vector, test_data_kernel.get_output_data_by_index(0)); +} -TYPED_TEST(ResizeBilinearTest, SimpleTest) +TEST_F(ResizeBilinearTest, HalfPixelCenter_Uint8_P) { - Check({2, 2, 2, 1}, {2}, {2, 3, 3, 1}, - { - 3, 6, // - 9, 12, // - 4, 10, // - 10, 16 // - }, - {3, 3}, - { - 3, 5, 6, // - 7, 9, 10, // - 9, 11, 12, // - 4, 8, 10, // - 8, 12, 14, // - 10, 14, 16, // - }, - false, false); - SUCCEED(); + test_kernel::TestDataUint8ResizeBilinear test_data_kernel(true); + std::vector output_data_vector = checkResizeBilinearKernel(&test_data_kernel); + + EXPECT_THAT(output_data_vector, test_data_kernel.get_output_data_by_index(0)); } -TEST(ResizeBilinearTest, HalfPixelCenterFloatTest) +TEST_F(ResizeBilinearTest, InvalidInputShape_Float_NEG) { - Check({2, 2, 2, 1}, {2}, {2, 3, 3, 1}, - { - 1, 2, // - 3, 4, // - 1, 2, // - 3, 4 // - }, - {3, 3}, - { - 1, 1.5, 2, // - 2, 2.5, 3, // - 3, 3.5, 4, // - 1, 1.5, 2, // - 2, 2.5, 3, // - 3, 3.5, 4, // - }, - false, true); - SUCCEED(); + + test_kernel::NegTestDataInvalidInputShapeFloatResizeBilinearKernel test_data_kernel; + + MemoryManager memory_manager{}; + RuntimeModule runtime_module{}; + bool dealloc_input = true; + // Load model with single op + auto *model_data_raw = reinterpret_cast(test_data_kernel.get_model_ptr()); + EXPECT_DEATH(ModuleLoader::load(&runtime_module, &memory_manager, model_data_raw, dealloc_input), + ""); } -TEST(ResizeBilinearTest, HalfPixelCenterUint8Test) +TEST_F(ResizeBilinearTest, InvalidParams_Float_NEG) { - Check({2, 2, 2, 1}, {2}, {2, 3, 3, 1}, - { - 3, 6, // - 9, 12, // - 4, 10, // - 12, 16 // - }, - {3, 3}, - { - 2, 4, 6, // - 6, 7, 9, // - 9, 10, 12, // - 4, 7, 10, // - 8, 10, 13, // - 12, 14, 16, // - }, - false, true); - SUCCEED(); + + test_kernel::NegTestDataInvalidParamFloatResizeBilinearKernel test_data_kernel; + + MemoryManager memory_manager{}; + RuntimeModule runtime_module{}; + bool dealloc_input = true; + // Load model with single op + auto *model_data_raw = reinterpret_cast(test_data_kernel.get_model_ptr()); + EXPECT_DEATH(ModuleLoader::load(&runtime_module, &memory_manager, model_data_raw, dealloc_input), + ""); } -TEST(ResizeBilinearTest, InputShapeInvalid_NEG) +TEST_F(ResizeBilinearTest, InvalidSizeShape_Float_NEG) { - std::unique_ptr memory_manager = std::make_unique(); - - Tensor input_tensor = makeInputTensor({2, 2, 2}, - { - 3, 6, // - 9, 12, // - 4, 10, // - 10, 16 // - }, - memory_manager.get()); - Tensor size_tensor = makeInputTensor({2}, {3, 3}, memory_manager.get()); - Tensor output_tensor = makeOutputTensor(DataType::FLOAT32); - - ResizeBilinearParams params{}; - params.align_corners = false; - params.half_pixel_centers = false; - - ResizeBilinear kernel(&input_tensor, &size_tensor, &output_tensor, params); - EXPECT_ANY_THROW(kernel.configure()); + + test_kernel::NegTestDataInvalidSizeShapeDimensionsFloatResizeBilinearKernel test_data_kernel; + + MemoryManager memory_manager{}; + RuntimeModule runtime_module{}; + bool dealloc_input = true; + // Load model with single op + auto *model_data_raw = reinterpret_cast(test_data_kernel.get_model_ptr()); + EXPECT_DEATH(ModuleLoader::load(&runtime_module, &memory_manager, model_data_raw, dealloc_input), + ""); } -TEST(ResizeBilinearTest, SizeShapeInvalid_NEG) +TEST_F(ResizeBilinearTest, InvalidInputShape_uint8_NEG) { - std::unique_ptr memory_manager = std::make_unique(); - - Tensor input_tensor = makeInputTensor({2, 2, 2, 1}, - { - 3, 6, // - 9, 12, // - 4, 10, // - 10, 16 // - }, - memory_manager.get()); - Tensor size_tensor = makeInputTensor({2, 1}, {3, 3}, memory_manager.get()); - Tensor output_tensor = makeOutputTensor(DataType::FLOAT32); - - ResizeBilinearParams params{}; - params.align_corners = false; - params.half_pixel_centers = false; - - ResizeBilinear kernel(&input_tensor, &size_tensor, &output_tensor, params); - EXPECT_ANY_THROW(kernel.configure()); + + test_kernel::NegTestDataInvalidInputShapeUint8ResizeBilinearKernel test_data_kernel; + + MemoryManager memory_manager{}; + RuntimeModule runtime_module{}; + bool dealloc_input = true; + // Load model with single op + auto *model_data_raw = reinterpret_cast(test_data_kernel.get_model_ptr()); + EXPECT_DEATH(ModuleLoader::load(&runtime_module, &memory_manager, model_data_raw, dealloc_input), + ""); } -TEST(ResizeBilinearTest, SizeDimInvalid_NEG) +TEST_F(ResizeBilinearTest, InvalidParams_uint8_NEG) { - std::unique_ptr memory_manager = std::make_unique(); - - Tensor input_tensor = makeInputTensor({2, 2, 2, 1}, - { - 3, 6, // - 9, 12, // - 4, 10, // - 10, 16 // - }, - memory_manager.get()); - Tensor size_tensor = makeInputTensor({3}, {3, 3, 1}, memory_manager.get()); - Tensor output_tensor = makeOutputTensor(DataType::FLOAT32); - - ResizeBilinearParams params{}; - params.align_corners = false; - params.half_pixel_centers = false; - - ResizeBilinear kernel(&input_tensor, &size_tensor, &output_tensor, params); - EXPECT_ANY_THROW(kernel.configure()); + + test_kernel::NegTestDataInvalidParamUint8ResizeBilinearKernel test_data_kernel; + + MemoryManager memory_manager{}; + RuntimeModule runtime_module{}; + bool dealloc_input = true; + // Load model with single op + auto *model_data_raw = reinterpret_cast(test_data_kernel.get_model_ptr()); + EXPECT_DEATH(ModuleLoader::load(&runtime_module, &memory_manager, model_data_raw, dealloc_input), + ""); } -TEST(ResizeBilinearTest, InvalidParams_NEG) +TEST_F(ResizeBilinearTest, InvalidSizeShape_uint8_NEG) { - std::unique_ptr memory_manager = std::make_unique(); - - Tensor input_tensor = makeInputTensor({2, 2, 2, 1}, - { - 3, 6, // - 9, 12, // - 4, 10, // - 10, 16 // - }, - memory_manager.get()); - Tensor size_tensor = makeInputTensor({2}, {3, 3}, memory_manager.get()); - Tensor output_tensor = makeOutputTensor(DataType::FLOAT32); - - ResizeBilinearParams params{}; - params.align_corners = true; - params.half_pixel_centers = true; - - ResizeBilinear kernel(&input_tensor, &size_tensor, &output_tensor, params); - EXPECT_ANY_THROW(kernel.configure()); + + test_kernel::NegTestDataInvalidSizeShapeDimensionsUint8ResizeBilinearKernel test_data_kernel; + + MemoryManager memory_manager{}; + RuntimeModule runtime_module{}; + bool dealloc_input = true; + // Load model with single op + auto *model_data_raw = reinterpret_cast(test_data_kernel.get_model_ptr()); + EXPECT_DEATH(ModuleLoader::load(&runtime_module, &memory_manager, model_data_raw, dealloc_input), + ""); } } // namespace From 7f405f7b2e93b5a70319d3b4218668150501b5c5 Mon Sep 17 00:00:00 2001 From: Seungho Henry Park <136296779+shs-park@users.noreply.github.com> Date: Tue, 1 Aug 2023 13:12:17 +0900 Subject: [PATCH 05/11] [luci/import] Clean up some comments (#11194) Some of comments have been cleaned up - Commas deleted - Unnecessary comments deleted ONE-DCO-1.0-Signed-off-by: Seungho Henry Park --- compiler/luci/import/src/GraphBuilderRegistry.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/compiler/luci/import/src/GraphBuilderRegistry.cpp b/compiler/luci/import/src/GraphBuilderRegistry.cpp index 301e418a7b3..9c868320ddf 100644 --- a/compiler/luci/import/src/GraphBuilderRegistry.cpp +++ b/compiler/luci/import/src/GraphBuilderRegistry.cpp @@ -69,7 +69,7 @@ GraphBuilderRegistry::GraphBuilderRegistry() CIRCLE_NODE(INSTANCE_NORM, CircleInstanceNormGraphBuilder); // 254 CIRCLE_NODE(L2_NORMALIZATION, CircleL2NormalizeGraphBuilder); // 11 CIRCLE_NODE(L2_POOL_2D, CircleL2Pool2DGraphBuilder); // 12 - CIRCLE_NODE(LEAKY_RELU, CircleLeakyReluGraphBuilder); // 98, + CIRCLE_NODE(LEAKY_RELU, CircleLeakyReluGraphBuilder); // 98 CIRCLE_NODE(LESS, CircleLessGraphBuilder); // 58 CIRCLE_NODE(LESS_EQUAL, CircleLessEqualGraphBuilder); // 63 CIRCLE_NODE(LOCAL_RESPONSE_NORMALIZATION, CircleLocalResponseNormalizationGraphBuilder); // 13 @@ -88,16 +88,16 @@ GraphBuilderRegistry::GraphBuilderRegistry() CIRCLE_NODE(MIRROR_PAD, CircleMirrorPadGraphBuilder); // 100 CIRCLE_NODE(MUL, CircleMulGraphBuilder); // 18 CIRCLE_NODE(NEG, CircleNegGraphBuilder); // 59 - CIRCLE_NODE(NON_MAX_SUPPRESSION_V4, CircleNonMaxSuppressionV4GraphBuilder); // 120, - CIRCLE_NODE(NON_MAX_SUPPRESSION_V5, CircleNonMaxSuppressionV5GraphBuilder); // 121, + CIRCLE_NODE(NON_MAX_SUPPRESSION_V4, CircleNonMaxSuppressionV4GraphBuilder); // 120 + CIRCLE_NODE(NON_MAX_SUPPRESSION_V5, CircleNonMaxSuppressionV5GraphBuilder); // 121 CIRCLE_NODE(NOT_EQUAL, CircleNotEqualGraphBuilder); // 72 CIRCLE_NODE(ONE_HOT, CircleOneHotGraphBuilder); // 85 CIRCLE_NODE(PACK, CirclePackGraphBuilder); // 83 CIRCLE_NODE(PAD, CirclePadGraphBuilder); // 34 CIRCLE_NODE(PADV2, CirclePadV2GraphBuilder); // 60 CIRCLE_NODE(POW, CirclePowGraphBuilder); // 78 - CIRCLE_NODE(PRELU, CirclePReluGraphBuilder); // 54, - CIRCLE_NODE(QUANTIZE, CircleQuantizeGraphBuilder); // 114, + CIRCLE_NODE(PRELU, CirclePReluGraphBuilder); // 54 + CIRCLE_NODE(QUANTIZE, CircleQuantizeGraphBuilder); // 114 CIRCLE_NODE(RANGE, CircleRangeGraphBuilder); // 96 CIRCLE_NODE(RANK, CircleRankGraphBuilder); // 110 CIRCLE_NODE(REDUCE_ANY, CircleReduceAnyGraphBuilder); // 91 @@ -162,7 +162,6 @@ GraphBuilderRegistry::GraphBuilderRegistry() // BuiltinOperator_BIDIRECTIONAL_SEQUENCE_RNN = 46, // BuiltinOperator_DELEGATE = 51, // BuiltinOperator_ARG_MAX = 56, - // BuiltinOperator_HARD_SWISH = 117, // Register builders for nodes which not handles in builders registered above. #define CIRCLE_NODE(CLASS) add(std::make_unique()) From 3b27895104f6924ec78e73095c7532056e068463 Mon Sep 17 00:00:00 2001 From: Seungho Henry Park <136296779+shs-park@users.noreply.github.com> Date: Tue, 1 Aug 2023 13:12:28 +0900 Subject: [PATCH 06/11] [luci/partition] Support HardSwish operation (#11193) Support HardSwish operation in luci/partition ONE-DCO-1.0-Signed-off-by: Seungho Henry Park --- .../luci/partition/include/luci/ConnectNode.h | 1 + .../partition/src/Nodes/CircleHardSwish.cpp | 38 ++++++++ .../src/Nodes/CircleHardSwish.test.cpp | 90 +++++++++++++++++++ 3 files changed, 129 insertions(+) create mode 100644 compiler/luci/partition/src/Nodes/CircleHardSwish.cpp create mode 100644 compiler/luci/partition/src/Nodes/CircleHardSwish.test.cpp diff --git a/compiler/luci/partition/include/luci/ConnectNode.h b/compiler/luci/partition/include/luci/ConnectNode.h index 95444a37806..d8cbfc6c46f 100644 --- a/compiler/luci/partition/include/luci/ConnectNode.h +++ b/compiler/luci/partition/include/luci/ConnectNode.h @@ -97,6 +97,7 @@ class ConnectNode final : public luci::CircleNodeVisitor void visit(const luci::CircleGelu *) final; void visit(const luci::CircleGreater *) final; void visit(const luci::CircleGreaterEqual *) final; + void visit(const luci::CircleHardSwish *) final; void visit(const luci::CircleIf *) final; void visit(const luci::CircleL2Normalize *) final; void visit(const luci::CircleL2Pool2D *) final; diff --git a/compiler/luci/partition/src/Nodes/CircleHardSwish.cpp b/compiler/luci/partition/src/Nodes/CircleHardSwish.cpp new file mode 100644 index 00000000000..d6903f30581 --- /dev/null +++ b/compiler/luci/partition/src/Nodes/CircleHardSwish.cpp @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "luci/ConnectNode.h" + +namespace +{ + +void connect(luci::ConnectNode *cn, const luci::CircleHardSwish *node) +{ + auto *cloned = loco::must_cast(cn->find_clone(node)); + + luci::CircleNode *features = loco::must_cast(node->features()); + + cloned->features(cn->find_clone(features)); +} + +} // namespace + +namespace luci +{ + +void ConnectNode::visit(const luci::CircleHardSwish *node) { connect(this, node); } + +} // namespace luci diff --git a/compiler/luci/partition/src/Nodes/CircleHardSwish.test.cpp b/compiler/luci/partition/src/Nodes/CircleHardSwish.test.cpp new file mode 100644 index 00000000000..770597313fa --- /dev/null +++ b/compiler/luci/partition/src/Nodes/CircleHardSwish.test.cpp @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "luci/ConnectNode.h" + +#include "ConnectNode.test.h" + +#include + +#include + +namespace +{ + +using namespace luci::test; + +class NodeGraphlet : public NodeGraphletT +{ +public: + NodeGraphlet() = default; +}; + +class TestNodeGraph : public TestIOGraph, public NodeGraphlet +{ +public: + TestNodeGraph() = default; + +public: + void init(const ShapeU32 shape) + { + TestIOGraph::init(shape, shape); + NodeGraphlet::init(g()); + + node()->features(input()); + + output()->from(node()); + } +}; + +} // namespace + +TEST(ConnectNodeTest, connect_HardSwish) +{ + TestNodeGraph tng; + tng.init({2, 3}); + + ConnectionTestHelper cth; + cth.prepare_inputs(&tng); + + auto *node = tng.node(); + ASSERT_NO_THROW(loco::must_cast(node)); + + auto *clone = luci::clone_node(node, cth.graph_clone()); + ASSERT_NO_THROW(loco::must_cast(clone)); + + cth.clone_connect(node, clone); + + ASSERT_EQ(1, clone->arity()); + ASSERT_EQ(cth.inputs(0), clone->arg(0)); +} + +TEST(ConnectNodeTest, connect_HardSwish_NEG) +{ + TestNodeGraph tng; + tng.init({2, 3}); + + ConnectionTestHelper cth; + cth.prepare_inputs_miss(&tng); + + auto *node = tng.node(); + ASSERT_NO_THROW(loco::must_cast(node)); + + auto *clone = luci::clone_node(node, cth.graph_clone()); + ASSERT_NO_THROW(loco::must_cast(clone)); + + EXPECT_ANY_THROW(cth.clone_connect(node, clone)); +} From 6bc49315063426d0131ff2e7c11e6a9ad52cd5ca Mon Sep 17 00:00:00 2001 From: Hyeongseok Oh Date: Tue, 1 Aug 2023 13:30:53 +0900 Subject: [PATCH 07/11] [infra/docker] Install android sdk (#11187) This commit installs android sdk in ubuntu focal image. It is installed in ubuntu bionic but we will be end to support ubuntu bionic image. ONE-DCO-1.0-Signed-off-by: Hyeongseok Oh --- infra/docker/focal/Dockerfile | 43 +++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/infra/docker/focal/Dockerfile b/infra/docker/focal/Dockerfile index 99097b0a944..0c6c582e973 100644 --- a/infra/docker/focal/Dockerfile +++ b/infra/docker/focal/Dockerfile @@ -51,6 +51,49 @@ RUN cp tmp/data/tools/sdb /usr/bin/. && rm -rf tmp/* # ARM none eabi build tool RUN apt-get update && apt-get -qqy install gcc-arm-none-eabi +# Install java +RUN apt-get install -y --no-install-recommends openjdk-8-jdk + +# download and install Gradle +# https://services.gradle.org/distributions/ +ARG GRADLE_VERSION=6.4.1 +ARG GRADLE_DIST=bin +RUN cd /opt && \ + wget -q https://services.gradle.org/distributions/gradle-${GRADLE_VERSION}-${GRADLE_DIST}.zip && \ + unzip gradle*.zip && \ + ls -d */ | sed 's/\/*$//g' | xargs -I{} mv {} gradle && \ + rm gradle*.zip + +# download and install Android SDK +# https://developer.android.com/studio#command-tools +ARG ANDROID_SDK_VERSION=6514223 +ENV ANDROID_SDK_ROOT /opt/android-sdk +RUN mkdir -p ${ANDROID_SDK_ROOT}/cmdline-tools && \ + wget -q https://dl.google.com/android/repository/commandlinetools-linux-${ANDROID_SDK_VERSION}_latest.zip && \ + unzip *tools*linux*.zip -d ${ANDROID_SDK_ROOT}/cmdline-tools && \ + rm *tools*linux*.zip + +# accept the license agreements of the SDK components +RUN mkdir -p ${ANDROID_SDK_ROOT}/licenses +RUN echo 24333f8a63b6825ea9c5514f83c2829b004d1fee > ${ANDROID_SDK_ROOT}/licenses/android-sdk-license +RUN echo d56f5187479451eabf01fb78af6dfcb131a6481e >> ${ANDROID_SDK_ROOT}/licenses/android-sdk-license + +# Env variable for gradle build +ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64 +ENV GRADLE_HOME /opt/gradle +ENV PATH ${PATH}:${GRADLE_HOME}/bin:${ANDROID_SDK_ROOT}/cmdline-tools/tools/bin:${ANDROID_SDK_ROOT}/platform-tools +ENV ANDROID_HOME ${ANDROID_SDK_ROOT} + +# Install NDK +RUN sdkmanager --install "ndk;20.0.5594570" +RUN sdkmanager "platform-tools" + +# Env for ko encoding build +ENV LC_ALL "C.UTF-8" + +# setup adb server +EXPOSE 5037 + # Setup user to match host user, and give superuser permissions ARG USER_ID=1000 ARG GROUP_ID=${USER_ID} From 70889f10f75425146e3b89064731e922c2b16cfe Mon Sep 17 00:00:00 2001 From: Seungho Henry Park <136296779+shs-park@users.noreply.github.com> Date: Tue, 1 Aug 2023 13:39:00 +0900 Subject: [PATCH 08/11] [luci-interpreter] Support HardSwish operation (#11195) Support HardSwish operation in luci-interpreter ONE-DCO-1.0-Signed-off-by: Seungho Henry Park --- .../pal/linux/KernelsToBuild.lst | 1 + .../luci-interpreter/pal/linux/PALHardSwish.h | 31 +++++++ .../src/kernels/HardSwish.cpp | 52 ++++++++++++ .../luci-interpreter/src/kernels/HardSwish.h | 43 ++++++++++ .../src/kernels/HardSwish.test.cpp | 81 +++++++++++++++++++ .../src/loader/nodes/HardSwish.cpp | 35 ++++++++ 6 files changed, 243 insertions(+) create mode 100644 compiler/luci-interpreter/pal/linux/PALHardSwish.h create mode 100644 compiler/luci-interpreter/src/kernels/HardSwish.cpp create mode 100644 compiler/luci-interpreter/src/kernels/HardSwish.h create mode 100644 compiler/luci-interpreter/src/kernels/HardSwish.test.cpp create mode 100644 compiler/luci-interpreter/src/loader/nodes/HardSwish.cpp diff --git a/compiler/luci-interpreter/pal/linux/KernelsToBuild.lst b/compiler/luci-interpreter/pal/linux/KernelsToBuild.lst index 193ac72e4e1..e4d42de339e 100644 --- a/compiler/luci-interpreter/pal/linux/KernelsToBuild.lst +++ b/compiler/luci-interpreter/pal/linux/KernelsToBuild.lst @@ -24,6 +24,7 @@ REGISTER_KERNEL(Gather) REGISTER_KERNEL(Gelu) REGISTER_KERNEL(Greater) REGISTER_KERNEL(GreaterEqual) +REGISTER_KERNEL(HardSwish) REGISTER_KERNEL(If) REGISTER_KERNEL(InstanceNorm) REGISTER_KERNEL(L2Normalize) diff --git a/compiler/luci-interpreter/pal/linux/PALHardSwish.h b/compiler/luci-interpreter/pal/linux/PALHardSwish.h new file mode 100644 index 00000000000..2ce7cb3a1f5 --- /dev/null +++ b/compiler/luci-interpreter/pal/linux/PALHardSwish.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef LUCI_INTERPRETER_PAL_HARDSWISH_H +#define LUCI_INTERPRETER_PAL_HARDSWISH_H + +#include + +namespace luci_interpreter_pal +{ +static inline void HardSwish(const tflite::RuntimeShape &input_shape, const float *input_data, + const tflite::RuntimeShape &output_shape, float *output_data) +{ + tflite::optimized_ops::HardSwish(input_shape, input_data, output_shape, output_data); +} +} // namespace luci_interpreter_pal + +#endif // LUCI_INTERPRETER_PAL_HARDSWISH_H diff --git a/compiler/luci-interpreter/src/kernels/HardSwish.cpp b/compiler/luci-interpreter/src/kernels/HardSwish.cpp new file mode 100644 index 00000000000..b1008459ad5 --- /dev/null +++ b/compiler/luci-interpreter/src/kernels/HardSwish.cpp @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "kernels/HardSwish.h" +#include "kernels/Utils.h" + +#include "PALHardSwish.h" + +#include + +namespace luci_interpreter +{ + +namespace kernels +{ + +HardSwish::HardSwish(const Tensor *input, Tensor *output) : Kernel({input}, {output}) {} + +void HardSwish::configure() +{ + LUCI_INTERPRETER_CHECK(input()->element_type() == output()->element_type()); + output()->resize(input()->shape()); +} + +void HardSwish::execute() const +{ + switch (input()->element_type()) + { + case DataType::FLOAT32: + luci_interpreter_pal::HardSwish(getTensorShape(input()), getTensorData(input()), + getTensorShape(output()), getTensorData(output())); + break; + default: + throw std::runtime_error("Unsupported type."); + } +} + +} // namespace kernels +} // namespace luci_interpreter diff --git a/compiler/luci-interpreter/src/kernels/HardSwish.h b/compiler/luci-interpreter/src/kernels/HardSwish.h new file mode 100644 index 00000000000..bb9e9b65305 --- /dev/null +++ b/compiler/luci-interpreter/src/kernels/HardSwish.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef LUCI_INTERPRETER_KERNELS_HARDSWISH_H +#define LUCI_INTERPRETER_KERNELS_HARDSWISH_H + +#include "core/Kernel.h" +#include "core/KernelParams.h" + +namespace luci_interpreter +{ +namespace kernels +{ + +class HardSwish : public Kernel +{ +public: + HardSwish(const Tensor *input, Tensor *output); + + const Tensor *input() const { return _inputs[0]; } + Tensor *output() const { return _outputs[0]; } + + void configure() override; + void execute() const override; +}; + +} // namespace kernels +} // namespace luci_interpreter + +#endif // LUCI_INTERPRETER_KERNELS_HARDSWISH_H diff --git a/compiler/luci-interpreter/src/kernels/HardSwish.test.cpp b/compiler/luci-interpreter/src/kernels/HardSwish.test.cpp new file mode 100644 index 00000000000..c055fee0e18 --- /dev/null +++ b/compiler/luci-interpreter/src/kernels/HardSwish.test.cpp @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "kernels/HardSwish.h" +#include "kernels/TestUtils.h" +#include "luci_interpreter/TestMemoryManager.h" + +namespace luci_interpreter +{ +namespace kernels +{ +namespace +{ + +using namespace testing; + +void Check(std::initializer_list input_shape, std::initializer_list output_shape, + std::initializer_list input_data, std::initializer_list output_data) +{ + std::unique_ptr memory_manager = std::make_unique(); + Tensor input_tensor = + makeInputTensor(input_shape, input_data, memory_manager.get()); + Tensor output_tensor = makeOutputTensor(DataType::FLOAT32); + + HardSwish kernel(&input_tensor, &output_tensor); + kernel.configure(); + memory_manager->allocate_memory(output_tensor); + kernel.execute(); + + (void)output_shape; + EXPECT_THAT(extractTensorData(output_tensor), FloatArrayNear(output_data)); +} + +TEST(HardSwishTest, SimpleHardSwish) +{ + Check( + /*input_shape=*/{1, 2, 4, 1}, /*output_shape=*/{1, 2, 4, 1}, + /*input_data=*/ + { + 0, -6, 2, -4, // + 3, -2, 10, -0.1, // + }, + /*output_data=*/ + { + 0, -0, 1.66667, -0, // + 3, -0.333333, 10, -0.0483333, // + }); +} + +TEST(HardSwishTest, InOutTypeMismatch_NEG) +{ + std::unique_ptr memory_manager = std::make_unique(); + Shape input_shape{1, 2, 4, 1}; + std::vector input_data{ + 0, -6, 2, -4, // + 3, -2, 10, -0.1, // + }; + Tensor input_tensor = + makeInputTensor(input_shape, input_data, memory_manager.get()); + Tensor output_tensor = makeOutputTensor(DataType::U8); + + HardSwish kernel(&input_tensor, &output_tensor); + EXPECT_ANY_THROW(kernel.configure()); +} + +} // namespace +} // namespace kernels +} // namespace luci_interpreter diff --git a/compiler/luci-interpreter/src/loader/nodes/HardSwish.cpp b/compiler/luci-interpreter/src/loader/nodes/HardSwish.cpp new file mode 100644 index 00000000000..2e62f24022b --- /dev/null +++ b/compiler/luci-interpreter/src/loader/nodes/HardSwish.cpp @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "Builders.h" + +#include "kernels/HardSwish.h" + +namespace luci_interpreter +{ + +std::unique_ptr build_kernel_CircleHardSwish(const luci::CircleNode *circle_node, + KernelBuilderHelper &helper) +{ + const auto *node = loco::must_cast(circle_node); + assert(node->arity() == 1); + + const Tensor *input = helper.getInputTensor(node->features()); + Tensor *output = helper.getOutputTensor(node); + + return std::make_unique(input, output); +} +} // namespace luci_interpreter From 2b7313aff83b73e287f530c2d9fc3792c30ffda8 Mon Sep 17 00:00:00 2001 From: Jang Jiseob Date: Tue, 1 Aug 2023 13:42:27 +0900 Subject: [PATCH 09/11] [onert] Restore IOTensors for outputs of graph (#11191) This commit restores IOTensors for outputs of graph. ONE-DCO-1.0-Signed-off-by: ragmani --- .../core/src/compiler/ExecutorFactory.cc | 10 ++--- .../core/src/exec/train/TrainableExecutor.cc | 45 +++++-------------- 2 files changed, 16 insertions(+), 39 deletions(-) diff --git a/runtime/onert/core/src/compiler/ExecutorFactory.cc b/runtime/onert/core/src/compiler/ExecutorFactory.cc index 42be636e54a..4554c0e9d12 100644 --- a/runtime/onert/core/src/compiler/ExecutorFactory.cc +++ b/runtime/onert/core/src/compiler/ExecutorFactory.cc @@ -731,10 +731,10 @@ exec::IExecutor *ExecutorFactory::createTrainableExecutor( train::TensorRegistries tensor_regs{tbackend_contexts, true}; - // NOTE Outputs of trainable graph cannot be IOTensor. They will be built by the owned backend. - initializeSubgraphIOTensors(*lowered_graph, tbackend_contexts, - lowered_graph->graph().getInputs() | ir::Remove::DUPLICATED | - ir::Remove::UNDEFINED); + initializeSubgraphIOTensors( + *lowered_graph, tbackend_contexts, + (lowered_graph->graph().getInputs() + lowered_graph->graph().getOutputs()) | + ir::Remove::DUPLICATED | ir::Remove::UNDEFINED); // linearize auto order = Linear::linearize(*lowered_graph); @@ -839,7 +839,7 @@ exec::IExecutor *ExecutorFactory::createTrainableExecutor( assert(std::all_of(lowered_graph->trainable_graph().getOutputs().begin(), lowered_graph->trainable_graph().getOutputs().end(), [&](const auto &output_idx) { - return tensor_regs.getDerivativeITensor(output_idx) != nullptr; + return tensor_regs.getDerivativeITensor(output_idx) == nullptr; })); } diff --git a/runtime/onert/core/src/exec/train/TrainableExecutor.cc b/runtime/onert/core/src/exec/train/TrainableExecutor.cc index 24d0e2d6924..5e358920b2c 100644 --- a/runtime/onert/core/src/exec/train/TrainableExecutor.cc +++ b/runtime/onert/core/src/exec/train/TrainableExecutor.cc @@ -83,15 +83,18 @@ void TrainableExecutor::forward(const IODescription &desc, bool training) desc.inputs[i]->size); } - // Set output(s) - assert(_output_tensors.size() == desc.outputs.size()); - for (uint32_t i = 0; i < _output_tensors.size(); ++i) + if (!training) { - auto tensor = _output_tensors[i]; + // Set output(s) + assert(_output_tensors.size() == desc.outputs.size()); + for (uint32_t i = 0; i < _output_tensors.size(); ++i) + { + auto tensor = _output_tensors[i]; - if (desc.outputs[i] == nullptr) - throw std::runtime_error{"Output " + std::to_string(i) + "'s buffer is not set."}; - tensor->setUserTensor(static_cast(desc.outputs[i]->buffer), desc.outputs[i]->size); + if (desc.outputs[i] == nullptr) + throw std::runtime_error{"Output " + std::to_string(i) + "'s buffer is not set."}; + tensor->setUserTensor(static_cast(desc.outputs[i]->buffer), desc.outputs[i]->size); + } } forwardImpl(training); @@ -136,40 +139,14 @@ void TrainableExecutor::forwardImpl(bool training) } } -void TrainableExecutor::backward(const IODescription &desc, uint32_t training_step) +void TrainableExecutor::backward(const IODescription &, uint32_t training_step) { // For thread-safe, use mutex // TODO: if all used backends on this executor are thread-safe, // do not need to use mutex (otherwise, use mutex) std::lock_guard lock(_mutex); - // TODO Update IO tensors if desc has dynamic input - // Set input(s) - assert(_input_tensors.size() == desc.inputs.size()); - for (uint32_t i = 0; i < _input_tensors.size(); ++i) - { - auto tensor = _input_tensors[i]; - - // TODO Check if (desc.inputs[i] == nullptr) - // TODO Better design for ITensor? (we need const_cast as ITensor is writable) - tensor->setUserTensor(static_cast(const_cast(desc.inputs[i]->buffer)), - desc.inputs[i]->size); - } - - // Set output(s) - assert(_output_tensors.size() == desc.outputs.size()); - for (uint32_t i = 0; i < _output_tensors.size(); ++i) - { - auto tensor = _output_tensors[i]; - - if (desc.outputs[i] == nullptr) - throw std::runtime_error{"Output " + std::to_string(i) + "'s buffer is not set."}; - tensor->setUserTensor(static_cast(desc.outputs[i]->buffer), desc.outputs[i]->size); - } - backwardImpl(training_step); - - // TODO Update output(s) desc if desc has dynamic input } void TrainableExecutor::backwardImpl(uint32_t training_step) From 9656b8ead905444b20d39693603dae05a5350d61 Mon Sep 17 00:00:00 2001 From: Seungho Henry Park <136296779+shs-park@users.noreply.github.com> Date: Tue, 1 Aug 2023 15:21:18 +0900 Subject: [PATCH 10/11] [res] Support HardSwish operation (#11196) Support HardSwish operation in res ONE-DCO-1.0-Signed-off-by: Seungho Henry Park --- .../HardSwish_000/test.recipe | 17 +++++++++++++++++ .../HardSwish_000/test.reverse | 0 2 files changed, 17 insertions(+) create mode 100644 res/TensorFlowLiteRecipes/HardSwish_000/test.recipe create mode 100644 res/TensorFlowLiteRecipes/HardSwish_000/test.reverse diff --git a/res/TensorFlowLiteRecipes/HardSwish_000/test.recipe b/res/TensorFlowLiteRecipes/HardSwish_000/test.recipe new file mode 100644 index 00000000000..9dab36e2094 --- /dev/null +++ b/res/TensorFlowLiteRecipes/HardSwish_000/test.recipe @@ -0,0 +1,17 @@ +operand { + name: "ifm" + type: FLOAT32 + shape { dim: 1 dim: 3 dim: 3 dim: 2 } +} +operand { + name: "ofm" + type: FLOAT32 + shape { dim: 1 dim: 3 dim: 3 dim: 2 } +} +operation { + type: "HardSwish" + input: "ifm" + output: "ofm" +} +input: "ifm" +output: "ofm" diff --git a/res/TensorFlowLiteRecipes/HardSwish_000/test.reverse b/res/TensorFlowLiteRecipes/HardSwish_000/test.reverse new file mode 100644 index 00000000000..e69de29bb2d From 88ea00fbc341563acc002a7d1514f9093640a44b Mon Sep 17 00:00:00 2001 From: Balyshev Artem <43214667+BalyshevArtem@users.noreply.github.com> Date: Tue, 1 Aug 2023 10:06:18 +0300 Subject: [PATCH 11/11] [onert-micro] Support LogicalAnd, LogicalOr kernels (#10998) This PR adds supporting of LogicalAnd, LogicalOr kernel. ONE-DCO-1.0-Signed-off-by: Artem Balyshev Co-authored-by: Artem Balyshev Co-authored-by: chunseoklee --- .../logical_and/BoolLogicalAndKernel.h | 104 ++++++++++++++++ .../logical_and/NegLogicalAndKernel.h | 90 ++++++++++++++ .../logical_and/TestDataLogicalAndBase.h | 63 ++++++++++ .../logical_or/BoolLogicalOrKernel.h | 105 ++++++++++++++++ .../logical_or/NegLogicalOrKernel.h | 90 ++++++++++++++ .../logical_or/TestDataLogicalOrBase.h | 63 ++++++++++ .../pal/common/PALLogicalCommon.h | 35 ++++++ .../pal/mcu/KernelsToBuild.lst | 2 + .../src/kernels/LogicalAnd.cpp | 70 ++++++----- .../luci-interpreter/src/kernels/LogicalAnd.h | 47 ------- .../src/kernels/LogicalAnd.test.cpp | 114 ++++++++--------- .../luci-interpreter/src/kernels/LogicalNot.h | 46 ------- .../src/kernels/LogicalOr.cpp | 61 ++++++--- .../luci-interpreter/src/kernels/LogicalOr.h | 44 ------- .../src/kernels/LogicalOr.test.cpp | 117 ++++++++---------- 15 files changed, 740 insertions(+), 311 deletions(-) create mode 100644 onert-micro/luci-interpreter/include/luci_interpreter/test_models/logical_and/BoolLogicalAndKernel.h create mode 100644 onert-micro/luci-interpreter/include/luci_interpreter/test_models/logical_and/NegLogicalAndKernel.h create mode 100644 onert-micro/luci-interpreter/include/luci_interpreter/test_models/logical_and/TestDataLogicalAndBase.h create mode 100644 onert-micro/luci-interpreter/include/luci_interpreter/test_models/logical_or/BoolLogicalOrKernel.h create mode 100644 onert-micro/luci-interpreter/include/luci_interpreter/test_models/logical_or/NegLogicalOrKernel.h create mode 100644 onert-micro/luci-interpreter/include/luci_interpreter/test_models/logical_or/TestDataLogicalOrBase.h create mode 100644 onert-micro/luci-interpreter/pal/common/PALLogicalCommon.h delete mode 100644 onert-micro/luci-interpreter/src/kernels/LogicalAnd.h delete mode 100644 onert-micro/luci-interpreter/src/kernels/LogicalNot.h delete mode 100644 onert-micro/luci-interpreter/src/kernels/LogicalOr.h diff --git a/onert-micro/luci-interpreter/include/luci_interpreter/test_models/logical_and/BoolLogicalAndKernel.h b/onert-micro/luci-interpreter/include/luci_interpreter/test_models/logical_and/BoolLogicalAndKernel.h new file mode 100644 index 00000000000..8b87fa28e5f --- /dev/null +++ b/onert-micro/luci-interpreter/include/luci_interpreter/test_models/logical_and/BoolLogicalAndKernel.h @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef LUCI_INTERPRETER_TEST_MODELS_BOOL_LOGICAL_AND_KERNEL_H +#define LUCI_INTERPRETER_TEST_MODELS_BOOL_LOGICAL_AND_KERNEL_H + +#include "TestDataLogicalAndBase.h" + +namespace luci_interpreter +{ +namespace test_kernel +{ +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 test_kernel +} // namespace luci_interpreter + +#endif // LUCI_INTERPRETER_TEST_MODELS_FLOAT_LOGICAL_AND_KERNEL_H diff --git a/onert-micro/luci-interpreter/include/luci_interpreter/test_models/logical_and/NegLogicalAndKernel.h b/onert-micro/luci-interpreter/include/luci_interpreter/test_models/logical_and/NegLogicalAndKernel.h new file mode 100644 index 00000000000..6624fe2a22e --- /dev/null +++ b/onert-micro/luci-interpreter/include/luci_interpreter/test_models/logical_and/NegLogicalAndKernel.h @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef LUCI_INTERPRETER_TEST_MODELS_NEG_LOGICAL_AND_KERNEL_H +#define LUCI_INTERPRETER_TEST_MODELS_NEG_LOGICAL_AND_KERNEL_H + +#include "TestDataLogicalAndBase.h" + +namespace luci_interpreter +{ +namespace test_kernel +{ +namespace neg_logical_and_inputs_type_mismatch +{ +/* + * LogicalAnd Kernel with input types 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 NegTestDataInputTypeMismatchLogicalAndKernel : public NegTestDataBase +{ +public: + NegTestDataInputTypeMismatchLogicalAndKernel() + { + _test_kernel_model_circle = neg_logical_and_inputs_type_mismatch::test_kernel_model_circle; + } + + ~NegTestDataInputTypeMismatchLogicalAndKernel() override = default; + + const unsigned char *get_model_ptr() override final { return _test_kernel_model_circle; } + +protected: + const unsigned char *_test_kernel_model_circle; +}; + +} // namespace test_kernel +} // namespace luci_interpreter + +#endif // LUCI_INTERPRETER_TEST_MODELS_NEG_LOGICAL_AND_KERNEL_H diff --git a/onert-micro/luci-interpreter/include/luci_interpreter/test_models/logical_and/TestDataLogicalAndBase.h b/onert-micro/luci-interpreter/include/luci_interpreter/test_models/logical_and/TestDataLogicalAndBase.h new file mode 100644 index 00000000000..c2842a3334d --- /dev/null +++ b/onert-micro/luci-interpreter/include/luci_interpreter/test_models/logical_and/TestDataLogicalAndBase.h @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef LUCI_INTERPRETER_TEST_MODELS_LOGICAL_AND_KERNEL_BASE_H +#define LUCI_INTERPRETER_TEST_MODELS_LOGICAL_AND_KERNEL_BASE_H + +#include "luci_interpreter/test_models/TestDataBase.h" + +namespace luci_interpreter +{ +namespace test_kernel +{ + +template class TestDataLogicalAndBase : public TestDataBase +{ +public: + TestDataLogicalAndBase() = 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 test_kernel +} // namespace luci_interpreter + +#endif // LUCI_INTERPRETER_TEST_MODELS_LOGICAL_AND_KERNEL_BASE_H diff --git a/onert-micro/luci-interpreter/include/luci_interpreter/test_models/logical_or/BoolLogicalOrKernel.h b/onert-micro/luci-interpreter/include/luci_interpreter/test_models/logical_or/BoolLogicalOrKernel.h new file mode 100644 index 00000000000..90b7511db0d --- /dev/null +++ b/onert-micro/luci-interpreter/include/luci_interpreter/test_models/logical_or/BoolLogicalOrKernel.h @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef LUCI_INTERPRETER_TEST_MODELS_BOOL_LOGICAL_OR_KERNEL_H +#define LUCI_INTERPRETER_TEST_MODELS_BOOL_LOGICAL_OR_KERNEL_H + +#include "TestDataLogicalOrBase.h" + +namespace luci_interpreter +{ +namespace test_kernel +{ +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, 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, 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, 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}; + +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, false, 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, true, true, true, true, true, true, true, true, true, + true, true, true, true, true, true, true, true, true, false, false, false}; + +const std::vector reference_output_data = { + 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, true, true, true, true, false, false}; + +} // namespace logical_or_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 test_kernel +} // namespace luci_interpreter + +#endif // LUCI_INTERPRETER_TEST_MODELS_FLOAT_LOGICAL_OR_KERNEL_H diff --git a/onert-micro/luci-interpreter/include/luci_interpreter/test_models/logical_or/NegLogicalOrKernel.h b/onert-micro/luci-interpreter/include/luci_interpreter/test_models/logical_or/NegLogicalOrKernel.h new file mode 100644 index 00000000000..1225d98fb36 --- /dev/null +++ b/onert-micro/luci-interpreter/include/luci_interpreter/test_models/logical_or/NegLogicalOrKernel.h @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef LUCI_INTERPRETER_TEST_MODELS_NEG_LOGICAL_OR_KERNEL_H +#define LUCI_INTERPRETER_TEST_MODELS_NEG_LOGICAL_OR_KERNEL_H + +#include "TestDataLogicalOrBase.h" + +namespace luci_interpreter +{ +namespace test_kernel +{ +namespace neg_logical_or_inputs_type_mismatch +{ +/* + * LogicalOr Kernel with input types 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_or_inputs_type_mismatch + +class NegTestDataInputTypeMismatchLogicalOrKernel : public NegTestDataBase +{ +public: + NegTestDataInputTypeMismatchLogicalOrKernel() + { + _test_kernel_model_circle = neg_logical_or_inputs_type_mismatch::test_kernel_model_circle; + } + + ~NegTestDataInputTypeMismatchLogicalOrKernel() override = default; + + const unsigned char *get_model_ptr() override final { return _test_kernel_model_circle; } + +protected: + const unsigned char *_test_kernel_model_circle; +}; + +} // namespace test_kernel +} // namespace luci_interpreter + +#endif // LUCI_INTERPRETER_TEST_MODELS_NEG_LOGICAL_OR_KERNEL_H diff --git a/onert-micro/luci-interpreter/include/luci_interpreter/test_models/logical_or/TestDataLogicalOrBase.h b/onert-micro/luci-interpreter/include/luci_interpreter/test_models/logical_or/TestDataLogicalOrBase.h new file mode 100644 index 00000000000..af9fee2adcd --- /dev/null +++ b/onert-micro/luci-interpreter/include/luci_interpreter/test_models/logical_or/TestDataLogicalOrBase.h @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef LUCI_INTERPRETER_TEST_MODELS_LOGICAL_OR_KERNEL_BASE_H +#define LUCI_INTERPRETER_TEST_MODELS_LOGICAL_OR_KERNEL_BASE_H + +#include "luci_interpreter/test_models/TestDataBase.h" + +namespace luci_interpreter +{ +namespace test_kernel +{ + +template class TestDataLogicalOrBase : public TestDataBase +{ +public: + TestDataLogicalOrBase() = 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 test_kernel +} // namespace luci_interpreter + +#endif // LUCI_INTERPRETER_TEST_MODELS_LOGICAL_OR_KERNEL_BASE_H diff --git a/onert-micro/luci-interpreter/pal/common/PALLogicalCommon.h b/onert-micro/luci-interpreter/pal/common/PALLogicalCommon.h new file mode 100644 index 00000000000..18173f583ac --- /dev/null +++ b/onert-micro/luci-interpreter/pal/common/PALLogicalCommon.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved + * Copyright 2020 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 LUCI_INTERPRETER_PAL_LOGICAL_COMMON_H +#define LUCI_INTERPRETER_PAL_LOGICAL_COMMON_H + +namespace luci_interpreter_pal +{ + +inline void LogicalCommon(const int flat_size, const bool *input1_data, const bool *input2_data, + bool *output_data, bool (*f)(bool, bool)) +{ + for (int i = 0; i < flat_size; ++i) + { + output_data[i] = f(input1_data[i], input2_data[i]); + } +} + +} // namespace luci_interpreter_pal + +#endif // LUCI_INTERPRETER_PAL_LOGICAL_COMMON_H diff --git a/onert-micro/luci-interpreter/pal/mcu/KernelsToBuild.lst b/onert-micro/luci-interpreter/pal/mcu/KernelsToBuild.lst index 0ee376cb3e9..daf020f13c8 100644 --- a/onert-micro/luci-interpreter/pal/mcu/KernelsToBuild.lst +++ b/onert-micro/luci-interpreter/pal/mcu/KernelsToBuild.lst @@ -21,6 +21,8 @@ REGISTER_KERNEL(RELU, Relu) REGISTER_KERNEL(RELU6, Relu6) REGISTER_KERNEL(REDUCE_PROD, ReduceCommon) REGISTER_KERNEL(LESS, Less) +REGISTER_KERNEL(LOGICAL_AND, LogicalAnd) +REGISTER_KERNEL(LOGICAL_OR, LogicalOr) REGISTER_KERNEL(LEAKY_RELU, LeakyRelu) REGISTER_KERNEL(MUL, Mul) REGISTER_KERNEL(MAX_POOL_2D, MaxPool2D) diff --git a/onert-micro/luci-interpreter/src/kernels/LogicalAnd.cpp b/onert-micro/luci-interpreter/src/kernels/LogicalAnd.cpp index 65e0b50537e..7e440cca4f7 100644 --- a/onert-micro/luci-interpreter/src/kernels/LogicalAnd.cpp +++ b/onert-micro/luci-interpreter/src/kernels/LogicalAnd.cpp @@ -14,50 +14,58 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -#include "kernels/LogicalAnd.h" - +#include "Builders.h" #include "kernels/Utils.h" +#include "TISOKernel.h" -#include "kernels/BinaryOpCommon.h" +#include "PALLogicalCommon.h" namespace luci_interpreter { -namespace kernels +namespace { +bool LogicalAnd(bool x, bool y) { return x && y; } +} // namespace -LogicalAnd::LogicalAnd(const Tensor *input1, const Tensor *input2, Tensor *output) - : Kernel({input1, input2}, {output}) +void configure_kernel_CircleLogicalAnd(const circle::Operator *cur_op, + BaseRuntimeGraph *runtime_graph) { -} + kernels::TISOKernel kernel(cur_op, runtime_graph); -void LogicalAnd::configure() -{ - LUCI_INTERPRETER_CHECK(input1()->element_type() == input2()->element_type()); - LUCI_INTERPRETER_CHECK(input1()->element_type() == output()->element_type()); - // TODO: enable it only if kernel with dynamic shapes - output()->resize(calculateShapeForBroadcast(input1()->shape(), input2()->shape())); -} + LUCI_INTERPRETER_CHECK(Tensor::element_type(kernel.input1()) == + Tensor::element_type(kernel.input2())); + LUCI_INTERPRETER_CHECK(Tensor::element_type(kernel.input1()) == DataType::BOOL); + LUCI_INTERPRETER_CHECK(Tensor::element_type(kernel.output()) == DataType::BOOL); -void LogicalAnd::execute() const -{ - switch (input1()->element_type()) - { - case DataType::BOOL: - evalLogicalAnd(); - break; - default: - assert(false && "Unsupported type."); - } + // TODO support broadcast + LUCI_INTERPRETER_CHECK(Tensor::num_elements(kernel.input1()) == + Tensor::num_elements(kernel.input2())); + LUCI_INTERPRETER_CHECK(Tensor::num_dims(kernel.input1()) == Tensor::num_dims(kernel.input2())); } -inline void LogicalAnd::evalLogicalAnd() const +// TODO: add inplace +// TODO: reduce code duplication with LogicalOr +void execute_kernel_CircleLogicalAnd(const circle::Operator *cur_op, + BaseRuntimeGraph *runtime_graph) { - BinaryOpBroadcastSlow(getTensorShape(input1()), getTensorData(input1()), - getTensorShape(input2()), getTensorData(input2()), - getTensorShape(output()), getTensorData(output()), - [](bool x, bool y) { return x && y; }); + kernels::TISOKernel kernel(cur_op, runtime_graph); + + auto x_data = kernels::getTensorData(runtime_graph->getDataByTensor(kernel.input1())); + if (x_data == nullptr) + x_data = kernels::getTensorData(runtime_graph->getConstDataByTensor(kernel.input1())); + + assert(x_data != nullptr); + + auto y_data = kernels::getTensorData(runtime_graph->getDataByTensor(kernel.input2())); + if (y_data == nullptr) + y_data = kernels::getTensorData(runtime_graph->getConstDataByTensor(kernel.input2())); + + assert(y_data != nullptr); + + auto output_data = kernels::getTensorData(runtime_graph->getDataByTensor(kernel.output())); + + const int64_t flat_size = kernels::getTensorShape(kernel.input1()).flatSize(); + luci_interpreter_pal::LogicalCommon(flat_size, x_data, y_data, output_data, LogicalAnd); } -} // namespace kernels } // namespace luci_interpreter diff --git a/onert-micro/luci-interpreter/src/kernels/LogicalAnd.h b/onert-micro/luci-interpreter/src/kernels/LogicalAnd.h deleted file mode 100644 index 46b889986f9..00000000000 --- a/onert-micro/luci-interpreter/src/kernels/LogicalAnd.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef LUCI_INTERPRETER_KERNELS_LOGICALAND_H -#define LUCI_INTERPRETER_KERNELS_LOGICALAND_H - -#include "core/Kernel.h" -#include "core/KernelParams.h" - -namespace luci_interpreter -{ -namespace kernels -{ - -class LogicalAnd : public Kernel -{ -public: - LogicalAnd(const Tensor *input1, const Tensor *input2, Tensor *output); - - const Tensor *input1() const { return _inputs[0]; } - const Tensor *input2() const { return _inputs[1]; } - Tensor *output() const { return _outputs[0]; } - - void configure() override; - void execute() const override; - -private: - inline void evalLogicalAnd() const; -}; - -} // namespace kernels -} // namespace luci_interpreter - -#endif // LUCI_INTERPRETER_KERNELS_LOGICALAND_H diff --git a/onert-micro/luci-interpreter/src/kernels/LogicalAnd.test.cpp b/onert-micro/luci-interpreter/src/kernels/LogicalAnd.test.cpp index 21b7951e023..2f72c083268 100644 --- a/onert-micro/luci-interpreter/src/kernels/LogicalAnd.test.cpp +++ b/onert-micro/luci-interpreter/src/kernels/LogicalAnd.test.cpp @@ -15,14 +15,14 @@ * limitations under the License. */ -#include "kernels/LogicalAnd.h" #include "kernels/TestUtils.h" -#include "luci_interpreter/TestMemoryManager.h" +#include "luci_interpreter/test_models/logical_and/BoolLogicalAndKernel.h" +#include "luci_interpreter/test_models/logical_and/NegLogicalAndKernel.h" + +#include "loader/ModuleLoader.h" namespace luci_interpreter { -namespace kernels -{ namespace { @@ -30,72 +30,66 @@ using namespace testing; class LogicalAndTest : public ::testing::Test { -protected: - void SetUp() override { _memory_manager = std::make_unique(); } - - std::unique_ptr _memory_manager; + // Do nothing }; -TEST_F(LogicalAndTest, Basic) +template +std::vector checkLogicalAndKernel(test_kernel::TestDataBase *test_data_base) { - Shape input_shape{1, 1, 1, 4}; - Tensor input_tensor1 = - makeInputTensor(input_shape, {true, false, false, true}, _memory_manager.get()); - Tensor input_tensor2 = - makeInputTensor(input_shape, {true, false, true, false}, _memory_manager.get()); - Tensor output_tensor = makeOutputTensor(DataType::BOOL); - - LogicalAnd kernel(&input_tensor1, &input_tensor2, &output_tensor); - kernel.configure(); - _memory_manager->allocate_memory(output_tensor); - kernel.execute(); - - EXPECT_THAT(extractTensorData(output_tensor), - ::testing::ElementsAre(true, false, false, false)); - EXPECT_THAT(extractTensorShape(output_tensor), ::testing::ElementsAre(1, 1, 1, 4)); + MemoryManager memory_manager{}; + RuntimeModule runtime_module{}; + bool dealloc_input = true; + + // Load model with single op + auto *model_data_raw = reinterpret_cast(test_data_base->get_model_ptr()); + ModuleLoader::load(&runtime_module, &memory_manager, model_data_raw, dealloc_input); + + auto *main_runtime_graph = runtime_module.getMainGraph(); + assert(main_runtime_graph->getNumOfInputTensors() == 2); + + // set left input data + { + auto *input_tensor_data = reinterpret_cast(main_runtime_graph->configureGraphInput(0)); + std::copy(test_data_base->get_input_data_by_index(0).begin(), + test_data_base->get_input_data_by_index(0).end(), input_tensor_data); + } + + // set right input data + { + auto *input_tensor_data = reinterpret_cast(main_runtime_graph->configureGraphInput(1)); + std::copy(test_data_base->get_input_data_by_index(1).begin(), + test_data_base->get_input_data_by_index(1).end(), input_tensor_data); + } + + runtime_module.execute(); + + assert(main_runtime_graph->getNumOfOutputTensors() == 1); + + T *output_data = reinterpret_cast(main_runtime_graph->getOutputDataByIndex(0)); + const size_t num_elements = (main_runtime_graph->getOutputDataSizeByIndex(0) / sizeof(T)); + std::vector output_data_vector(output_data, output_data + num_elements); + return output_data_vector; } -TEST_F(LogicalAndTest, Broadcast) +TEST_F(LogicalAndTest, Bool_P) { - Tensor input_tensor1 = makeInputTensor({1, 1, 1, 4}, {true, false, false, true}, - _memory_manager.get()); - Tensor input_tensor2 = - makeInputTensor({1, 1, 1, 1}, {true}, _memory_manager.get()); - Tensor output_tensor = makeOutputTensor(DataType::BOOL); - - LogicalAnd kernel(&input_tensor1, &input_tensor2, &output_tensor); - kernel.configure(); - _memory_manager->allocate_memory(output_tensor); - kernel.execute(); - - EXPECT_THAT(extractTensorData(output_tensor), - ::testing::ElementsAre(true, false, false, true)); - EXPECT_THAT(extractTensorShape(output_tensor), ::testing::ElementsAre(1, 1, 1, 4)); + test_kernel::TestDataBoolLogicalAnd test_data_kernel; + std::vector output_data_vector = checkLogicalAndKernel(&test_data_kernel); + EXPECT_THAT(output_data_vector, test_data_kernel.get_output_data_by_index(0)); } -TEST_F(LogicalAndTest, MismatchInputType_NEG) +TEST_F(LogicalAndTest, Input_type_mismatch_NEG) { - Tensor input1_tensor = - makeInputTensor({1, 1, 1, 4}, {1, 0, 0, 1}, _memory_manager.get()); - Tensor input2_tensor = - makeInputTensor({1, 1, 1, 1}, {false}, _memory_manager.get()); - Tensor output_tensor = makeOutputTensor(DataType::S32); - - LogicalAnd kernel(&input1_tensor, &input2_tensor, &output_tensor); - EXPECT_ANY_THROW(kernel.configure()); -} - -TEST_F(LogicalAndTest, InputTypeInvalid_NEG) -{ - Tensor input1_tensor = - makeInputTensor({1, 1, 1, 4}, {1, 0, 0, 1}, _memory_manager.get()); - Tensor input2_tensor = makeInputTensor({1, 1, 1, 1}, {0}, _memory_manager.get()); - Tensor output_tensor = makeOutputTensor(DataType::BOOL); - - LogicalAnd kernel(&input1_tensor, &input2_tensor, &output_tensor); - EXPECT_ANY_THROW(kernel.configure()); + test_kernel::NegTestDataInputTypeMismatchLogicalAndKernel test_data_kernel; + + MemoryManager memory_manager{}; + RuntimeModule runtime_module{}; + bool dealloc_input = true; + // Load model with single op + auto *model_data_raw = reinterpret_cast(test_data_kernel.get_model_ptr()); + EXPECT_DEATH(ModuleLoader::load(&runtime_module, &memory_manager, model_data_raw, dealloc_input), + ""); } } // namespace -} // namespace kernels } // namespace luci_interpreter diff --git a/onert-micro/luci-interpreter/src/kernels/LogicalNot.h b/onert-micro/luci-interpreter/src/kernels/LogicalNot.h deleted file mode 100644 index 1608fafa54e..00000000000 --- a/onert-micro/luci-interpreter/src/kernels/LogicalNot.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef LUCI_INTERPRETER_KERNELS_LOGICALNOT_H -#define LUCI_INTERPRETER_KERNELS_LOGICALNOT_H - -#include "core/Kernel.h" -#include "core/KernelParams.h" - -namespace luci_interpreter -{ -namespace kernels -{ - -class LogicalNot : public Kernel -{ -public: - LogicalNot(const Tensor *input, Tensor *output); - - const Tensor *input() const { return _inputs[0]; } - Tensor *output() const { return _outputs[0]; } - - void configure() override; - void execute() const override; - -private: - inline void evalLogicalNot() const; -}; - -} // namespace kernels -} // namespace luci_interpreter - -#endif // LUCI_INTERPRETER_KERNELS_LOGICALNOT_H diff --git a/onert-micro/luci-interpreter/src/kernels/LogicalOr.cpp b/onert-micro/luci-interpreter/src/kernels/LogicalOr.cpp index ecb8ee49b04..207c739642e 100644 --- a/onert-micro/luci-interpreter/src/kernels/LogicalOr.cpp +++ b/onert-micro/luci-interpreter/src/kernels/LogicalOr.cpp @@ -14,37 +14,58 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -#include "kernels/LogicalOr.h" - +#include "Builders.h" #include "kernels/Utils.h" -#include "kernels/BinaryOpCommon.h" +#include "TISOKernel.h" + +#include "PALLogicalCommon.h" namespace luci_interpreter { -namespace kernels -{ -LogicalOr::LogicalOr(const Tensor *input1, const Tensor *input2, Tensor *output) - : Kernel({input1, input2}, {output}) +namespace { -} +bool LogicalOr(bool x, bool y) { return x || y; } +} // namespace -void LogicalOr::configure() +void configure_kernel_CircleLogicalOr(const circle::Operator *cur_op, + BaseRuntimeGraph *runtime_graph) { - LUCI_INTERPRETER_CHECK(input1()->element_type() == input2()->element_type()); - LUCI_INTERPRETER_CHECK(input1()->element_type() == DataType::BOOL); - // TODO: enable it only if kernel with dynamic shapes - output()->resize(calculateShapeForBroadcast(input1()->shape(), input2()->shape())); + kernels::TISOKernel kernel(cur_op, runtime_graph); + + LUCI_INTERPRETER_CHECK(Tensor::element_type(kernel.input1()) == + Tensor::element_type(kernel.input2())); + LUCI_INTERPRETER_CHECK(Tensor::element_type(kernel.input1()) == DataType::BOOL); + LUCI_INTERPRETER_CHECK(Tensor::element_type(kernel.output()) == DataType::BOOL); + + // TODO support broadcast + LUCI_INTERPRETER_CHECK(Tensor::num_elements(kernel.input1()) == + Tensor::num_elements(kernel.input2())); + LUCI_INTERPRETER_CHECK(Tensor::num_dims(kernel.input1()) == Tensor::num_dims(kernel.input2())); } -void LogicalOr::execute() const +// TODO: add inplace +// TODO: reduce code duplication with LogicalAnd +void execute_kernel_CircleLogicalOr(const circle::Operator *cur_op, BaseRuntimeGraph *runtime_graph) { - BinaryOpBroadcastSlow(getTensorShape(input1()), getTensorData(input1()), - getTensorShape(input2()), getTensorData(input2()), - getTensorShape(output()), getTensorData(output()), - [](bool x, bool y) { return x || y; }); + kernels::TISOKernel kernel(cur_op, runtime_graph); + + auto x_data = kernels::getTensorData(runtime_graph->getDataByTensor(kernel.input1())); + if (x_data == nullptr) + x_data = kernels::getTensorData(runtime_graph->getConstDataByTensor(kernel.input1())); + + assert(x_data != nullptr); + + auto y_data = kernels::getTensorData(runtime_graph->getDataByTensor(kernel.input2())); + if (y_data == nullptr) + y_data = kernels::getTensorData(runtime_graph->getConstDataByTensor(kernel.input2())); + + assert(y_data != nullptr); + + auto output_data = kernels::getTensorData(runtime_graph->getDataByTensor(kernel.output())); + + const int64_t flat_size = kernels::getTensorShape(kernel.input1()).flatSize(); + luci_interpreter_pal::LogicalCommon(flat_size, x_data, y_data, output_data, LogicalOr); } -} // namespace kernels } // namespace luci_interpreter diff --git a/onert-micro/luci-interpreter/src/kernels/LogicalOr.h b/onert-micro/luci-interpreter/src/kernels/LogicalOr.h deleted file mode 100644 index 88606483f3c..00000000000 --- a/onert-micro/luci-interpreter/src/kernels/LogicalOr.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved - * Copyright 2019 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 LUCI_INTERPRETER_KERNELS_LOGICALOR_H -#define LUCI_INTERPRETER_KERNELS_LOGICALOR_H - -#include "core/Kernel.h" - -namespace luci_interpreter -{ -namespace kernels -{ - -class LogicalOr : public Kernel -{ -public: - LogicalOr(const Tensor *input1, const Tensor *input2, Tensor *output); - - const Tensor *input1() const { return _inputs[0]; } - const Tensor *input2() const { return _inputs[1]; } - Tensor *output() const { return _outputs[0]; } - - void configure() override; - void execute() const override; -}; - -} // namespace kernels -} // namespace luci_interpreter - -#endif // LUCI_INTERPRETER_KERNELS_LOGICALOR_H diff --git a/onert-micro/luci-interpreter/src/kernels/LogicalOr.test.cpp b/onert-micro/luci-interpreter/src/kernels/LogicalOr.test.cpp index d65a69a5e36..baa338d5a35 100644 --- a/onert-micro/luci-interpreter/src/kernels/LogicalOr.test.cpp +++ b/onert-micro/luci-interpreter/src/kernels/LogicalOr.test.cpp @@ -15,14 +15,14 @@ * limitations under the License. */ -#include "kernels/LogicalOr.h" #include "kernels/TestUtils.h" -#include "luci_interpreter/TestMemoryManager.h" +#include "luci_interpreter/test_models/logical_or/BoolLogicalOrKernel.h" +#include "luci_interpreter/test_models/logical_or/NegLogicalOrKernel.h" + +#include "loader/ModuleLoader.h" namespace luci_interpreter { -namespace kernels -{ namespace { @@ -30,75 +30,66 @@ using namespace testing; class LogicalOrTest : public ::testing::Test { -protected: - void SetUp() override { _memory_manager = std::make_unique(); } - - std::unique_ptr _memory_manager; + // Do nothing }; -TEST_F(LogicalOrTest, Basic) -{ - Tensor input1_tensor = makeInputTensor({1, 1, 1, 4}, {true, false, false, true}, - _memory_manager.get()); - Tensor input2_tensor = makeInputTensor({1, 1, 1, 4}, {true, false, true, false}, - _memory_manager.get()); - - Tensor output_tensor = makeOutputTensor(DataType::BOOL); - - LogicalOr kernel(&input1_tensor, &input2_tensor, &output_tensor); - kernel.configure(); - _memory_manager->allocate_memory(output_tensor); - kernel.execute(); - - EXPECT_THAT(extractTensorData(output_tensor), - ::testing::ElementsAre(true, false, true, true)); - EXPECT_THAT(extractTensorShape(output_tensor), ::testing::ElementsAre(1, 1, 1, 4)); -} - -TEST_F(LogicalOrTest, Broadcast) +template +std::vector checkLogicalOrKernel(test_kernel::TestDataBase *test_data_base) { - Tensor input1_tensor = makeInputTensor({1, 1, 1, 4}, {true, false, false, true}, - _memory_manager.get()); - Tensor input2_tensor = - makeInputTensor({1, 1, 1, 1}, {false}, _memory_manager.get()); - - Tensor output_tensor = makeOutputTensor(DataType::BOOL); - - LogicalOr kernel(&input1_tensor, &input2_tensor, &output_tensor); - kernel.configure(); - _memory_manager->allocate_memory(output_tensor); - kernel.execute(); - - EXPECT_THAT(extractTensorData(output_tensor), - ::testing::ElementsAre(true, false, false, true)); - EXPECT_THAT(extractTensorShape(output_tensor), ::testing::ElementsAre(1, 1, 1, 4)); + MemoryManager memory_manager{}; + RuntimeModule runtime_module{}; + bool dealloc_input = true; + + // Load model with single op + auto *model_data_raw = reinterpret_cast(test_data_base->get_model_ptr()); + ModuleLoader::load(&runtime_module, &memory_manager, model_data_raw, dealloc_input); + + auto *main_runtime_graph = runtime_module.getMainGraph(); + assert(main_runtime_graph->getNumOfInputTensors() == 2); + + // set left input data + { + auto *input_tensor_data = reinterpret_cast(main_runtime_graph->configureGraphInput(0)); + std::copy(test_data_base->get_input_data_by_index(0).begin(), + test_data_base->get_input_data_by_index(0).end(), input_tensor_data); + } + + // set right input data + { + auto *input_tensor_data = reinterpret_cast(main_runtime_graph->configureGraphInput(1)); + std::copy(test_data_base->get_input_data_by_index(1).begin(), + test_data_base->get_input_data_by_index(1).end(), input_tensor_data); + } + + runtime_module.execute(); + + assert(main_runtime_graph->getNumOfOutputTensors() == 1); + + T *output_data = reinterpret_cast(main_runtime_graph->getOutputDataByIndex(0)); + const size_t num_elements = (main_runtime_graph->getOutputDataSizeByIndex(0) / sizeof(T)); + std::vector output_data_vector(output_data, output_data + num_elements); + return output_data_vector; } -TEST_F(LogicalOrTest, MismatchInputType_NEG) +TEST_F(LogicalOrTest, Bool_P) { - Tensor input1_tensor = - makeInputTensor({1, 1, 1, 4}, {1, 0, 0, 1}, _memory_manager.get()); - Tensor input2_tensor = - makeInputTensor({1, 1, 1, 1}, {false}, _memory_manager.get()); - - Tensor output_tensor = makeOutputTensor(DataType::S32); - - LogicalOr kernel(&input1_tensor, &input2_tensor, &output_tensor); - EXPECT_ANY_THROW(kernel.configure()); + test_kernel::TestDataBoolLogicalOr test_data_kernel; + std::vector output_data_vector = checkLogicalOrKernel(&test_data_kernel); + EXPECT_THAT(output_data_vector, test_data_kernel.get_output_data_by_index(0)); } -TEST_F(LogicalOrTest, InputTypeInvalid_NEG) +TEST_F(LogicalOrTest, Input_type_mismatch_NEG) { - Tensor input1_tensor = - makeInputTensor({1, 1, 1, 4}, {1, 0, 0, 1}, _memory_manager.get()); - Tensor input2_tensor = makeInputTensor({1, 1, 1, 1}, {0}, _memory_manager.get()); - - Tensor output_tensor = makeOutputTensor(DataType::BOOL); - - LogicalOr kernel(&input1_tensor, &input2_tensor, &output_tensor); - EXPECT_ANY_THROW(kernel.configure()); + test_kernel::NegTestDataInputTypeMismatchLogicalOrKernel test_data_kernel; + + MemoryManager memory_manager{}; + RuntimeModule runtime_module{}; + bool dealloc_input = true; + // Load model with single op + auto *model_data_raw = reinterpret_cast(test_data_kernel.get_model_ptr()); + EXPECT_DEATH(ModuleLoader::load(&runtime_module, &memory_manager, model_data_raw, dealloc_input), + ""); } } // namespace -} // namespace kernels } // namespace luci_interpreter