diff --git a/onert-micro/onert-micro/include/pal/mcu/KernelsToBuild.lst b/onert-micro/onert-micro/include/pal/mcu/KernelsToBuild.lst index db570313880..109fb1448a9 100644 --- a/onert-micro/onert-micro/include/pal/mcu/KernelsToBuild.lst +++ b/onert-micro/onert-micro/include/pal/mcu/KernelsToBuild.lst @@ -18,7 +18,7 @@ REGISTER_KERNEL(FULLY_CONNECTED, FullyConnected) REGISTER_KERNEL(CONV_2D, Conv2D) REGISTER_KERNEL(LOGISTIC, Logistic) REGISTER_KERNEL(LOG, Log) -#/*REGISTER_KERNEL(GATHER, Gather)*/ +REGISTER_KERNEL(GATHER, Gather) REGISTER_KERNEL(GATHER_ND, GatherND) REGISTER_KERNEL(EXP, Exp) REGISTER_KERNEL(GREATER, Greater) @@ -63,7 +63,7 @@ REGISTER_KERNEL(SQUARED_DIFFERENCE, SquaredDifference) REGISTER_KERNEL(SUB, Sub) #/*REGISTER_KERNEL(SPLIT, Split)*/ REGISTER_KERNEL(SPACE_TO_BATCH_ND, SpaceToBatchND) -#/*REGISTER_KERNEL(STRIDED_SLICE, StridedSlice)*/ +REGISTER_KERNEL(STRIDED_SLICE, StridedSlice) #/*REGISTER_KERNEL(SPLIT_V, SplitV)*/ REGISTER_KERNEL(SQUARE, Square) REGISTER_KERNEL(SQRT, Sqrt) @@ -76,7 +76,7 @@ REGISTER_KERNEL(SOFTMAX, Softmax) #/*REGISTER_KERNEL(SUM, Sum)*/ #/*REGISTER_KERNEL(SELECT_V2, SelectV2)*/ #/*REGISTER_KERNEL(SVDF, SVDF)*/ -#/*REGISTER_KERNEL(WHILE, While)*/ +REGISTER_KERNEL(WHILE, While) #/*REGISTER_KERNEL(UNIDIRECTIONAL_SEQUENCE_LSTM, UnidirectionalSequenceLSTM)*/ #/*REGISTER_KERNEL(RESIZE_BILINEAR, ResizeBilinear)*/ #/*REGISTER_KERNEL(RESIZE_NEAREST_NEIGHBOR, ResizeNearestNeighbor)*/ diff --git a/onert-micro/onert-micro/include/test_models/while/NegWhileKernel.h b/onert-micro/onert-micro/include/test_models/while/NegWhileKernel.h new file mode 100644 index 00000000000..ae775cbb99b --- /dev/null +++ b/onert-micro/onert-micro/include/test_models/while/NegWhileKernel.h @@ -0,0 +1,137 @@ +/* + * Copyright (c) 2024 Samsung Electronics Co., Ltd. All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ONERT_MICRO_TEST_MODELS_NEG_WHILE_KERNEL_H +#define ONERT_MICRO_TEST_MODELS_NEG_WHILE_KERNEL_H + +#include "test_models/TestDataBase.h" + +namespace onert_micro +{ +namespace test_model +{ + +namespace neg_while_kernel +{ +/* + * While Kernel with wrong output type for Cond Graph (should be boolean but using int32): + * Main graph: + * Input(1) + * | + * While + * | + * Output(1) + * + * Cond graph: + * CInput(1) + * | + * Less (Const = 10) + * | + * COutput(1) - int32, but should be bool + * + * Body Graph: + * BInput(1) + * | + * Add (Const = 1) + * | + * BOutput(1) + */ +const unsigned char test_kernel_model_circle[] = { + 0x18, 0x00, 0x00, 0x00, 0x43, 0x49, 0x52, 0x30, 0x00, 0x00, 0x0e, 0x00, 0x14, 0x00, 0x00, 0x00, + 0x0c, 0x00, 0x08, 0x00, 0x10, 0x00, 0x04, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x7c, 0x00, 0x00, 0x00, 0x78, 0x03, 0x00, 0x00, 0xb0, 0x03, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, + 0x68, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x58, 0x00, 0x00, 0x00, 0x50, 0x00, 0x00, 0x00, + 0x48, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0xe2, 0xff, 0xff, 0xff, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x94, 0xfc, 0xff, 0xff, 0x04, 0x00, 0x06, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x06, 0x00, 0x08, 0x00, 0x04, 0x00, 0x06, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0xb8, 0xfc, 0xff, 0xff, 0xbc, 0xfc, 0xff, 0xff, + 0xc0, 0xfc, 0xff, 0xff, 0xc4, 0xfc, 0xff, 0xff, 0xc8, 0xfc, 0xff, 0xff, 0x03, 0x00, 0x00, 0x00, + 0x10, 0x02, 0x00, 0x00, 0x08, 0x01, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x0a, 0xfe, 0xff, 0xff, + 0x14, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, + 0x68, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x57, 0x48, 0x49, 0x4c, 0x45, 0x5f, 0x42, 0x4f, + 0x44, 0x59, 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, 0x0b, 0x0c, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x30, 0xfd, 0xff, 0xff, 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, 0x58, 0x00, 0x00, 0x00, + 0x30, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xd0, 0xfd, 0xff, 0xff, 0x10, 0x00, 0x00, 0x00, + 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x10, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x62, 0x6f, 0x66, 0x6d, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0xf8, 0xfd, 0xff, 0xff, 0x10, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, + 0x10, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x62, 0x69, 0x66, 0x6d, 0x33, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x1c, 0xfe, 0xff, 0xff, 0x10, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x02, 0x10, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x62, 0x69, 0x66, 0x6d, + 0x31, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0a, 0xff, 0xff, 0xff, + 0x14, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x54, 0x00, 0x00, 0x00, 0x58, 0x00, 0x00, 0x00, + 0x5c, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x57, 0x48, 0x49, 0x4c, 0x45, 0x5f, 0x43, 0x4f, + 0x4e, 0x44, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xfe, 0xfe, 0xff, 0xff, + 0x00, 0x00, 0x00, 0x29, 0x10, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x24, 0xfe, 0xff, 0xff, 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, + 0x58, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xc4, 0xfe, 0xff, 0xff, + 0x10, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x10, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x63, 0x6f, 0x66, 0x6d, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0xec, 0xfe, 0xff, 0xff, 0x10, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x02, 0x10, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x63, 0x69, 0x66, 0x6d, + 0x32, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0xff, 0xff, 0xff, 0x10, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x10, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, + 0x63, 0x69, 0x66, 0x6d, 0x31, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 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, 0x4d, 0x61, 0x69, 0x6e, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, + 0x18, 0x00, 0x14, 0x00, 0x10, 0x00, 0x0c, 0x00, 0x07, 0x00, 0x08, 0x00, 0x0e, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x5d, 0x18, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x08, 0x00, 0x0c, 0x00, 0x08, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0xdc, 0xff, 0xff, 0xff, 0x10, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x02, 0x0c, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x6f, 0x66, 0x6d, 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, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x02, 0x10, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x69, 0x66, 0x6d, 0x31, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x34, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xf4, 0xff, 0xff, 0xff, + 0x77, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x0c, 0x00, 0x0c, 0x00, 0x0b, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x04, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x3a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3a, + 0x04, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00, 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_while_kernel + +class NegTestDataWhileKernel : public NegTestDataBase +{ +public: + NegTestDataWhileKernel() + { + _test_kernel_model_circle = neg_while_kernel::test_kernel_model_circle; + } + + ~NegTestDataWhileKernel() override = default; + + const unsigned char *get_model_ptr() override final { return _test_kernel_model_circle; } + +protected: + const unsigned char *_test_kernel_model_circle; +}; + +} // namespace test_model +} // namespace onert_micro + +#endif // ONERT_MICRO_TEST_MODELS_NEG_WHILE_KERNEL_H diff --git a/onert-micro/onert-micro/include/test_models/while/WhileKernel.h b/onert-micro/onert-micro/include/test_models/while/WhileKernel.h new file mode 100644 index 00000000000..3809381ec1f --- /dev/null +++ b/onert-micro/onert-micro/include/test_models/while/WhileKernel.h @@ -0,0 +1,163 @@ +/* + * Copyright (c) 2024 Samsung Electronics Co., Ltd. All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ONERT_MICRO_TEST_MODELS_WHILE_KERNEL_H +#define ONERT_MICRO_TEST_MODELS_WHILE_KERNEL_H + +#include "test_models/TestDataBase.h" +#include + +namespace onert_micro +{ +namespace test_model +{ + +namespace while_kernel +{ +/* + * While Kernel: + * Main graph: + * Input(1) + * | + * While + * | + * Output(1) + * + * Cond graph: + * CInput(1) + * | + * Less (Const = 10) + * | + * COutput(1) + * + * Body Graph: + * BInput(1) + * | + * Add (Const = 1) + * | + * BOutput(1) + */ +const unsigned char test_kernel_model_circle[] = { + 0x18, 0x00, 0x00, 0x00, 0x43, 0x49, 0x52, 0x30, 0x00, 0x00, 0x0e, 0x00, 0x14, 0x00, 0x00, 0x00, + 0x0c, 0x00, 0x08, 0x00, 0x10, 0x00, 0x04, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x7c, 0x00, 0x00, 0x00, 0x78, 0x03, 0x00, 0x00, 0xb0, 0x03, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, + 0x68, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x58, 0x00, 0x00, 0x00, 0x50, 0x00, 0x00, 0x00, + 0x48, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0xe2, 0xff, 0xff, 0xff, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x94, 0xfc, 0xff, 0xff, 0x04, 0x00, 0x06, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x06, 0x00, 0x08, 0x00, 0x04, 0x00, 0x06, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0xb8, 0xfc, 0xff, 0xff, 0xbc, 0xfc, 0xff, 0xff, + 0xc0, 0xfc, 0xff, 0xff, 0xc4, 0xfc, 0xff, 0xff, 0xc8, 0xfc, 0xff, 0xff, 0x03, 0x00, 0x00, 0x00, + 0x10, 0x02, 0x00, 0x00, 0x08, 0x01, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x0a, 0xfe, 0xff, 0xff, + 0x14, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, + 0x68, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x57, 0x48, 0x49, 0x4c, 0x45, 0x5f, 0x42, 0x4f, + 0x44, 0x59, 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, 0x0b, 0x0c, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x30, 0xfd, 0xff, 0xff, 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, 0x58, 0x00, 0x00, 0x00, + 0x30, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xd0, 0xfd, 0xff, 0xff, 0x10, 0x00, 0x00, 0x00, + 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x10, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x62, 0x6f, 0x66, 0x6d, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0xf8, 0xfd, 0xff, 0xff, 0x10, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, + 0x10, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x62, 0x69, 0x66, 0x6d, 0x33, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x1c, 0xfe, 0xff, 0xff, 0x10, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x02, 0x10, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x62, 0x69, 0x66, 0x6d, + 0x31, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0a, 0xff, 0xff, 0xff, + 0x14, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x54, 0x00, 0x00, 0x00, 0x58, 0x00, 0x00, 0x00, + 0x5c, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x57, 0x48, 0x49, 0x4c, 0x45, 0x5f, 0x43, 0x4f, + 0x4e, 0x44, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xfe, 0xfe, 0xff, 0xff, + 0x00, 0x00, 0x00, 0x29, 0x10, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x24, 0xfe, 0xff, 0xff, 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, + 0x58, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xc4, 0xfe, 0xff, 0xff, + 0x10, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x10, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x63, 0x6f, 0x66, 0x6d, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0xec, 0xfe, 0xff, 0xff, 0x10, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x02, 0x10, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x63, 0x69, 0x66, 0x6d, + 0x32, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0xff, 0xff, 0xff, 0x10, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x10, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, + 0x63, 0x69, 0x66, 0x6d, 0x31, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 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, 0x4d, 0x61, 0x69, 0x6e, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, + 0x18, 0x00, 0x14, 0x00, 0x10, 0x00, 0x0c, 0x00, 0x07, 0x00, 0x08, 0x00, 0x0e, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x5d, 0x18, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x08, 0x00, 0x0c, 0x00, 0x08, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0xdc, 0xff, 0xff, 0xff, 0x10, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x02, 0x0c, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x6f, 0x66, 0x6d, 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, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x02, 0x10, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x69, 0x66, 0x6d, 0x31, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x34, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xf4, 0xff, 0xff, 0xff, + 0x77, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x0c, 0x00, 0x0c, 0x00, 0x0b, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x04, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x3a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3a, + 0x04, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00, 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 = {35}; + +const std::vector reference_output_data = {35}; +} // namespace while_kernel + +template class TestDataWhileKernel : public TestDataBase +{ +public: + TestDataWhileKernel() + { + _input_data = while_kernel::input_data; + _reference_output_data = while_kernel::reference_output_data; + _test_kernel_model_circle = while_kernel::test_kernel_model_circle; + } + + ~TestDataWhileKernel() override = default; + + const unsigned char *get_model_ptr() override final { return _test_kernel_model_circle; } + + const std::vector &get_input_data_by_index(int i) override final + { + switch (i) + { + case 0: + return _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_model +} // namespace onert_micro + +#endif // ONERT_MICRO_TEST_MODELS_WHILE_KERNEL_H diff --git a/onert-micro/onert-micro/src/core/OMRuntimeModule.cpp b/onert-micro/onert-micro/src/core/OMRuntimeModule.cpp index 44e819029c8..00555f59567 100644 --- a/onert-micro/onert-micro/src/core/OMRuntimeModule.cpp +++ b/onert-micro/onert-micro/src/core/OMRuntimeModule.cpp @@ -104,16 +104,23 @@ OMStatus OMRuntimeModule::importModel(const char *model_ptr, const OMConfig &con runtime_allocator, config); if (status != Ok) return status; + } + for (uint32_t i = 0; i < num_subgraph; ++i) + { + // Second - load default graph + OMRuntimeGraph &graph = _graphs.at(i); + OMRuntimeContext &runtime_context = graph.getRuntimeContext(); + OMRuntimeStorage &runtime_storage = graph.getRuntimeStorage(); + memory::OMRuntimeAllocator &runtime_allocator = graph.getRuntimeAllocator(); // 5 - KernelConfigure import::OMConfigureArgs configure_args = {runtime_storage, runtime_context, 0, config, *this}; status = import::OMKernelConfiguration::configureKernels(configure_args); if (status != Ok) return status; - - // Done! } + // Done! return Ok; } diff --git a/onert-micro/onert-micro/src/execute/OMRuntimeKernel.cpp b/onert-micro/onert-micro/src/execute/OMRuntimeKernel.cpp index 0eaf3f8b38e..11b3e0437a7 100644 --- a/onert-micro/onert-micro/src/execute/OMRuntimeKernel.cpp +++ b/onert-micro/onert-micro/src/execute/OMRuntimeKernel.cpp @@ -26,15 +26,15 @@ OMStatus onert_micro::execute::OMRuntimeKernel::readKernel(uint16_t op_index, const circle::Operator *last_operator = runtime_context.getCircleOperatorAt(op_index); inputs_num = first_operator->inputs()->size(); - assert(inputs_num < maxInputSize); + assert(inputs_num <= maxInputSize); - if (inputs_num >= maxInputSize) + if (inputs_num > maxInputSize) return UnknownError; outputs_num = last_operator->outputs()->size(); - assert(outputs_num < maxOutputSize); + assert(outputs_num <= maxOutputSize); - if (outputs_num >= maxOutputSize) + if (outputs_num > maxOutputSize) return UnknownError; assert(inputs_num > 0 and outputs_num > 0); diff --git a/onert-micro/onert-micro/src/execute/kernels/While.cpp b/onert-micro/onert-micro/src/execute/kernels/While.cpp new file mode 100644 index 00000000000..d59fa82383d --- /dev/null +++ b/onert-micro/onert-micro/src/execute/kernels/While.cpp @@ -0,0 +1,146 @@ +/* + * Copyright (c) 2024 Samsung Electronics Co., Ltd. All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "execute/OMKernelExecutionBuilder.h" +#include "OMStatus.h" +#include "execute/OMRuntimeKernel.h" +#include "core/OMUtils.h" +#include "core/OMDataType.h" +#include "execute/OMKernelExecute.h" + +using namespace onert_micro; +using namespace onert_micro::execute; + +// NOTE: doesnt currently support dynamic shapes +OMStatus onert_micro::execute::execute_kernel_CircleWhile(const OMExecuteArgs &execute_args) +{ + core::OMRuntimeModule &runtime_module = execute_args.runtime_module; + core::OMRuntimeContext &runtime_context = execute_args.runtime_context; + core::OMRuntimeStorage &runtime_storage = execute_args.runtime_storage; + uint16_t op_index = execute_args.kernel_index; + + OMRuntimeKernel runtime_kernel; + runtime_kernel.readKernel(op_index, runtime_context); + auto options = runtime_kernel.first_operator->builtin_options_as_WhileOptions(); + + // Obtain conditional and body runtime subgraphs + const auto body_subgraph_index = options->body_subgraph_index(); + const auto cond_subgraph_index = options->cond_subgraph_index(); + core::OMRuntimeGraph *cond_runtime_graph = nullptr; + core::OMRuntimeGraph *body_runtime_graph = nullptr; + runtime_module.getRuntimeGraphAt(cond_subgraph_index, &cond_runtime_graph); + runtime_module.getRuntimeGraphAt(body_subgraph_index, &body_runtime_graph); + + core::OMRuntimeContext &cond_runtime_context = cond_runtime_graph->getRuntimeContext(); + core::OMRuntimeStorage &cond_runtime_storage = cond_runtime_graph->getRuntimeStorage(); + core::memory::OMRuntimeAllocator &cond_runtime_allocator = + cond_runtime_graph->getRuntimeAllocator(); + + core::OMRuntimeContext &body_runtime_context = body_runtime_graph->getRuntimeContext(); + core::OMRuntimeStorage &body_runtime_storage = body_runtime_graph->getRuntimeStorage(); + core::memory::OMRuntimeAllocator &body_runtime_allocator = + body_runtime_graph->getRuntimeAllocator(); + + OMStatus status = runtime_kernel.getDataFromStorage(op_index, runtime_storage, runtime_context); + if (status != Ok) + return status; + + // Copy input data to the output + assert(runtime_kernel.inputs_num == runtime_kernel.outputs_num); + for (uint32_t i = 0; i < runtime_kernel.inputs_num; ++i) + { + const auto cur_input_tensor = runtime_kernel.inputs[i]; + const auto input_data_size = sizeof(core::OMDataType(cur_input_tensor->type())) * + core::OMRuntimeShape(cur_input_tensor).flatSize(); + std::memcpy(runtime_kernel.outputs_data[i], runtime_kernel.inputs_data[i], input_data_size); + } + + do + { + // Handle conditional graph + { + // Allocate cond graph inputs + cond_runtime_graph->allocateGraphInputs(); + auto cond_graphs_inputs = cond_runtime_graph->getNumberOfInputs(); + for (uint32_t i = 0; i < cond_graphs_inputs; ++i) + { + auto *cur_cond_input_data = + reinterpret_cast(cond_runtime_graph->getInputDataAt(i)); + uint8_t *cur_main_input_data = runtime_kernel.outputs_data[i]; + assert(cur_main_input_data != nullptr); + assert(cur_cond_input_data != nullptr); + const auto cur_input_tensor = runtime_kernel.inputs[i]; + const auto input_data_size = sizeof(core::OMDataType(cur_input_tensor->type())) * + core::OMRuntimeShape(cur_input_tensor).flatSize(); + std::memcpy(cur_cond_input_data, cur_main_input_data, input_data_size); + } + // Run cond graph + execute::OMExecuteArgs cond_execute_args = {cond_runtime_storage, cond_runtime_context, 0, + runtime_module}; + status = execute::OMKernelExecute::runForward(cond_execute_args, cond_runtime_allocator); + if (status != Ok) + return status; + + // Check cond graph result + bool cond_result_value = reinterpret_cast(cond_runtime_graph->getOutputDataAt(0))[0]; + // Reset cond graph values + cond_runtime_graph->reset(); + // If false - then finish while loop + if (cond_result_value == false) + break; + } + + // Handle body graph + { + // Allocate body graph inputs + body_runtime_graph->allocateGraphInputs(); + // Copy data + auto body_graphs_inputs = body_runtime_graph->getNumberOfInputs(); + for (uint32_t i = 0; i < body_graphs_inputs; ++i) + { + auto *cur_body_input_data = + reinterpret_cast(body_runtime_graph->getInputDataAt(i)); + uint8_t *cur_main_input_data = runtime_kernel.outputs_data[i]; + assert(cur_main_input_data != nullptr); + assert(cur_body_input_data != nullptr); + const auto cur_input_tensor = runtime_kernel.inputs[i]; + const auto input_data_size = sizeof(core::OMDataType(cur_input_tensor->type())) * + core::OMRuntimeShape(cur_input_tensor).flatSize(); + std::memcpy(cur_body_input_data, cur_main_input_data, input_data_size); + } + // Run body graph + execute::OMExecuteArgs body_execute_args = {body_runtime_storage, body_runtime_context, 0, + runtime_module}; + status = execute::OMKernelExecute::runForward(body_execute_args, body_runtime_allocator); + if (status != Ok) + return status; + + // Copy body calculated data to the main output + for (uint32_t i = 0; i < runtime_kernel.inputs_num; ++i) + { + auto cur_calculated_data = body_runtime_graph->getOutputDataAt(i); + const auto cur_tensor = runtime_kernel.outputs[i]; + const auto data_size = sizeof(core::OMDataType(cur_tensor->type())) * + core::OMRuntimeShape(cur_tensor).flatSize(); + std::memcpy(runtime_kernel.outputs_data[i], cur_calculated_data, data_size); + } + + body_runtime_graph->reset(); + } + } while (true); + + return status; +} diff --git a/onert-micro/onert-micro/src/execute/kernels/tests/While.test.cpp b/onert-micro/onert-micro/src/execute/kernels/tests/While.test.cpp new file mode 100644 index 00000000000..97f91bbae2c --- /dev/null +++ b/onert-micro/onert-micro/src/execute/kernels/tests/While.test.cpp @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2024 Samsung Electronics Co., Ltd. All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "execute/OMTestUtils.h" +#include "test_models/while/WhileKernel.h" +#include "test_models/while/NegWhileKernel.h" + +namespace onert_micro +{ +namespace execute +{ +namespace testing +{ + +using namespace testing; + +class WhileTest : public ::testing::Test +{ + // Do nothing +}; + +TEST_F(WhileTest, Main_P) +{ + onert_micro::test_model::TestDataWhileKernel test_data_kernel; + std::vector output_data_vector = + onert_micro::execute::testing::checkKernel(1, &test_data_kernel); + EXPECT_THAT(output_data_vector, test_data_kernel.get_output_data_by_index(0)); +} + +TEST_F(WhileTest, Input_output_type_mismatch_NEG) +{ + onert_micro::test_model::NegTestDataWhileKernel test_data_kernel; + + EXPECT_DEATH(checkNEGSISOKernel(&test_data_kernel), ""); +} + +} // namespace testing +} // namespace execute +} // namespace onert_micro diff --git a/onert-micro/onert-micro/src/import/kernels/While.cpp b/onert-micro/onert-micro/src/import/kernels/While.cpp new file mode 100644 index 00000000000..65752818b3c --- /dev/null +++ b/onert-micro/onert-micro/src/import/kernels/While.cpp @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2024 Samsung Electronics Co., Ltd. All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "import/OMKernelConfigureBuilder.h" +#include "core/OMUtils.h" +#include "OMStatus.h" +#include "execute/OMRuntimeKernel.h" + +using namespace onert_micro; +using namespace onert_micro::core; + +OMStatus onert_micro::import::configure_kernel_CircleWhile( + const onert_micro::import::OMConfigureArgs &config_args) +{ + OMRuntimeModule &runtime_module = config_args.runtime_module; + OMRuntimeContext &runtime_context = config_args.runtime_context; + uint16_t op_index = config_args.kernel_index; + + onert_micro::execute::OMRuntimeKernel runtime_kernel; + + OMStatus status = runtime_kernel.readKernel(op_index, runtime_context); + if (status != Ok) + return status; + + auto options = runtime_kernel.first_operator->builtin_options_as_WhileOptions(); + status = utils::checkCondition(options != nullptr); + if (status != Ok) + return status; + + // Num of inputs equals to num of outputs + status = utils::checkCondition(runtime_kernel.inputs_num == runtime_kernel.outputs_num); + if (status != Ok) + return status; + + // Obtain conditional and body runtime subgraphs + const auto body_subgraph_index = options->body_subgraph_index(); + const auto cond_subgraph_index = options->cond_subgraph_index(); + OMRuntimeGraph *cond_runtime_graph = nullptr; + OMRuntimeGraph *body_runtime_graph = nullptr; + status = runtime_module.getRuntimeGraphAt(cond_subgraph_index, &cond_runtime_graph); + if (status != Ok) + return status; + status = runtime_module.getRuntimeGraphAt(body_subgraph_index, &body_runtime_graph); + if (status != Ok) + return status; + + OMRuntimeContext &cond_runtime_context = cond_runtime_graph->getRuntimeContext(); + OMRuntimeContext &body_runtime_context = body_runtime_graph->getRuntimeContext(); + + // Check cond runtime graph + status = + utils::checkCondition(cond_runtime_graph->getNumberOfInputs() == runtime_kernel.inputs_num and + cond_runtime_graph->getNumberOfOutputs() == 1); + if (status != Ok) + return status; + + const auto cond_output_index = cond_runtime_context.getGraphOutputTensorIndex(0); + const auto cond_output_tensor = + cond_runtime_context.getTensorByIndex(static_cast(cond_output_index)); + status = utils::checkCondition(cond_output_tensor->type() == circle::TensorType_BOOL); + + // Check body runtime graph + status = + utils::checkCondition(body_runtime_graph->getNumberOfInputs() == runtime_kernel.inputs_num and + body_runtime_graph->getNumberOfOutputs() == runtime_kernel.outputs_num); + return status; +} diff --git a/onert-micro/onert-micro/src/optimize/pass/FindInplaceOpPass.cpp b/onert-micro/onert-micro/src/optimize/pass/FindInplaceOpPass.cpp index e02ebce60ea..9239320fba9 100644 --- a/onert-micro/onert-micro/src/optimize/pass/FindInplaceOpPass.cpp +++ b/onert-micro/onert-micro/src/optimize/pass/FindInplaceOpPass.cpp @@ -56,7 +56,6 @@ OMStatus isInplaceOperation(const circle::Operator *op, core::OMRuntimeContext & case circle::BuiltinOperator_ADD: case circle::BuiltinOperator_MUL: case circle::BuiltinOperator_SUB: - case circle::BuiltinOperator_WHILE: case circle::BuiltinOperator_ZEROS_LIKE: { is_inplace = true;