diff --git a/onert-micro/luci-interpreter/include/luci_interpreter/test_models/pad/FloatPadKernel.h b/onert-micro/luci-interpreter/include/luci_interpreter/test_models/pad/FloatPadKernel.h new file mode 100644 index 00000000000..ddfd3cf981c --- /dev/null +++ b/onert-micro/luci-interpreter/include/luci_interpreter/test_models/pad/FloatPadKernel.h @@ -0,0 +1,106 @@ +/* + * 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_PAD_KERNEL_H +#define LUCI_INTERPRETER_TEST_MODELS_FLOAT_PAD_KERNEL_H + +#include "TestDataPadBase.h" + +namespace luci_interpreter +{ +namespace test_kernel +{ +namespace pad_float +{ +/* + * Pad Kernel: + * + * Input(1, 3, 3, 2) + * | + * Pad + * | + * Output(1, 3, 3, 2) + */ +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, + 0x60, 0x00, 0x00, 0x00, 0x9c, 0x01, 0x00, 0x00, 0xb8, 0x01, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x4c, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x06, 0x00, 0x08, 0x00, 0x04, 0x00, 0x06, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x20, 0x00, 0x00, 0x00, 0x00, 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, + 0x00, 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, 0x16, 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, 0x7c, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x9c, 0xff, 0xff, 0xff, 0x0c, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x0c, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x6f, 0x66, 0x6d, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x0c, 0x00, 0x14, 0x00, 0x10, 0x00, 0x0f, 0x00, 0x08, 0x00, 0x04, 0x00, 0x0c, 0x00, 0x00, 0x00, + 0x10, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x10, 0x00, 0x00, 0x00, + 0x07, 0x00, 0x00, 0x00, 0x70, 0x61, 0x64, 0x64, 0x69, 0x6e, 0x67, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x04, 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, + 0x0c, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x69, 0x66, 0x6d, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x0c, 0x00, 0x0b, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x04, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x22, + 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 = { + -0.7942257, -1.3318212, -0.7918672, -1.0024637, -0.23364098, 0.49224994, + -0.23747201, -0.14768714, 1.4870708, -0.79761434, -0.27848604, 1.1856802, + 1.1039438, -0.34465268, -1.5857629, 3.0654314, 0.13304773, 0.067413524}; + +const std::vector reference_output_data = { + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0, 0.0, -0.7942257, -1.3318212, -0.7918672, + -1.0024637, -0.23364098, 0.49224994, 0.0, 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0, 0.0, -0.23747201, -0.14768714, 1.4870708, + -0.79761434, -0.27848604, 1.1856802, 0.0, 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0, 0.0, 1.1039438, -0.34465268, -1.5857629, + 3.0654314, 0.13304773, 0.067413524, 0.0, 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; + +} // namespace pad_float + +class TestDataFloatPad : public TestDataPadBase +{ +public: + TestDataFloatPad() + { + _input_data = pad_float::input_data; + _reference_output_data = pad_float::reference_output_data; + _test_kernel_model_circle = pad_float::test_kernel_model_circle; + } + + ~TestDataFloatPad() override = default; +}; + +} // namespace test_kernel +} // namespace luci_interpreter + +#endif // LUCI_INTERPRETER_TEST_MODELS_FLOAT_PAD_KERNEL_H diff --git a/onert-micro/luci-interpreter/include/luci_interpreter/test_models/pad/NegPadKernel.h b/onert-micro/luci-interpreter/include/luci_interpreter/test_models/pad/NegPadKernel.h new file mode 100644 index 00000000000..15936e449ba --- /dev/null +++ b/onert-micro/luci-interpreter/include/luci_interpreter/test_models/pad/NegPadKernel.h @@ -0,0 +1,92 @@ +/* + * 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_PAD_KERNEL_H +#define LUCI_INTERPRETER_TEST_MODELS_NEG_PAD_KERNEL_H + +#include "TestDataPadBase.h" + +namespace luci_interpreter +{ +namespace test_kernel +{ +namespace neg_pad_input_output_type_mismatch +{ +/* + * Pad Kernel with input output type mismatch (should be equal): + * + * Input(1, 3, 3, 2) - Float + * | + * Pad + * | + * Output(1, 3, 3, 2) - Int + */ +const unsigned char test_kernel_model_circle[] = { + 0x18, 0x00, 0x00, 0x00, 0x43, 0x49, 0x52, 0x30, 0x00, 0x00, 0x0e, 0x00, 0x14, 0x00, 0x00, 0x00, + 0x0c, 0x00, 0x08, 0x00, 0x10, 0x00, 0x04, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x60, 0x00, 0x00, 0x00, 0xa0, 0x01, 0x00, 0x00, 0xbc, 0x01, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x4c, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x06, 0x00, 0x08, 0x00, 0x04, 0x00, 0x06, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x20, 0x00, 0x00, 0x00, 0x00, 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, + 0x00, 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, 0x16, 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, 0x80, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0xd0, 0xff, 0xff, 0xff, 0x10, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x02, 0x0c, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x6f, 0x66, 0x6d, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x14, 0x00, 0x10, 0x00, 0x0f, 0x00, 0x08, 0x00, 0x04, 0x00, + 0x0c, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, + 0x10, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x70, 0x61, 0x64, 0x64, 0x69, 0x6e, 0x67, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x04, 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, 0x0c, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x69, 0x66, 0x6d, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x0c, 0x00, + 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x22, 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_pad_input_output_type_mismatch + +class NegTestDataInputOutputTypeMismatchPadKernel : public NegTestDataBase +{ +public: + NegTestDataInputOutputTypeMismatchPadKernel() + { + _test_kernel_model_circle = neg_pad_input_output_type_mismatch::test_kernel_model_circle; + } + + ~NegTestDataInputOutputTypeMismatchPadKernel() 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_PAD_KERNEL_H diff --git a/onert-micro/luci-interpreter/include/luci_interpreter/test_models/pad/TestDataPadBase.h b/onert-micro/luci-interpreter/include/luci_interpreter/test_models/pad/TestDataPadBase.h new file mode 100644 index 00000000000..e5c72def0e1 --- /dev/null +++ b/onert-micro/luci-interpreter/include/luci_interpreter/test_models/pad/TestDataPadBase.h @@ -0,0 +1,60 @@ +/* + * 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_PAD_KERNEL_BASE_H +#define LUCI_INTERPRETER_TEST_MODELS_PAD_KERNEL_BASE_H + +#include "luci_interpreter/test_models/TestDataBase.h" + +namespace luci_interpreter +{ +namespace test_kernel +{ + +template class TestDataPadBase : public TestDataBase +{ +public: + TestDataPadBase() = 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_PAD_KERNEL_BASE_H diff --git a/onert-micro/luci-interpreter/include/luci_interpreter/test_models/pad_v2/FloatPadV2Kernel.h b/onert-micro/luci-interpreter/include/luci_interpreter/test_models/pad_v2/FloatPadV2Kernel.h new file mode 100644 index 00000000000..0aa00f88445 --- /dev/null +++ b/onert-micro/luci-interpreter/include/luci_interpreter/test_models/pad_v2/FloatPadV2Kernel.h @@ -0,0 +1,110 @@ +/* + * 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_PADV2_KERNEL_H +#define LUCI_INTERPRETER_TEST_MODELS_FLOAT_PADV2_KERNEL_H + +#include "TestDataPadV2Base.h" + +namespace luci_interpreter +{ +namespace test_kernel +{ +namespace padV2_float +{ +/* + * PadV2 Kernel: + * + * Input(1, 3, 3, 2) + * | + * PadV2 + * | + * Output(1, 3, 3, 2) + */ +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, + 0x74, 0x00, 0x00, 0x00, 0xe4, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, + 0x60, 0x00, 0x00, 0x00, 0x58, 0x00, 0x00, 0x00, 0x50, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0xee, 0xff, 0xff, 0xff, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x06, 0x00, 0x08, 0x00, 0x04, 0x00, 0x06, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 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, 0x00, 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, 0x64, 0x00, 0x00, 0x00, 0x68, 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, 0x2b, + 0x10, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x04, 0x00, 0x04, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0xac, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x70, 0xff, 0xff, 0xff, 0x0c, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x6f, 0x66, 0x6d, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x05, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x9c, 0xff, 0xff, 0xff, + 0x0c, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, + 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x74, 0x5f, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x73, 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, 0x07, 0x00, 0x00, 0x00, 0x70, 0x61, 0x64, 0x64, + 0x69, 0x6e, 0x67, 0x00, 0x02, 0x00, 0x00, 0x00, 0x04, 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, 0x0c, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x69, 0x66, 0x6d, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x0c, 0x00, 0x0c, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x0c, 0x00, 0x00, 0x00, + 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 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 = { + -0.7942257, -1.3318212, -0.7918672, -1.0024637, -0.23364098, 0.49224994, + -0.23747201, -0.14768714, 1.4870708, -0.79761434, -0.27848604, 1.1856802, + 1.1039438, -0.34465268, -1.5857629, 3.0654314, 0.13304773, 0.067413524}; + +const std::vector reference_output_data = { + 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, + 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, + 1.0, 1.0, 1.0, 1.0, -0.7942257, -1.3318212, -0.7918672, + -1.0024637, -0.23364098, 0.49224994, 1.0, 1.0, 1.0, 1.0, + 1.0, 1.0, 1.0, 1.0, -0.23747201, -0.14768714, 1.4870708, + -0.79761434, -0.27848604, 1.1856802, 1.0, 1.0, 1.0, 1.0, + 1.0, 1.0, 1.0, 1.0, 1.1039438, -0.34465268, -1.5857629, + 3.0654314, 0.13304773, 0.067413524, 1.0, 1.0, 1.0, 1.0, + 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, + 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0}; + +} // namespace padV2_float + +class TestDataFloatPadV2 : public TestDataPadV2Base +{ +public: + TestDataFloatPadV2() + { + _input_data = padV2_float::input_data; + _reference_output_data = padV2_float::reference_output_data; + _test_kernel_model_circle = padV2_float::test_kernel_model_circle; + } + + ~TestDataFloatPadV2() override = default; +}; + +} // namespace test_kernel +} // namespace luci_interpreter + +#endif // LUCI_INTERPRETER_TEST_MODELS_FLOAT_PADV2_KERNEL_H diff --git a/onert-micro/luci-interpreter/include/luci_interpreter/test_models/pad_v2/NegPadV2Kernel.h b/onert-micro/luci-interpreter/include/luci_interpreter/test_models/pad_v2/NegPadV2Kernel.h new file mode 100644 index 00000000000..2591a601695 --- /dev/null +++ b/onert-micro/luci-interpreter/include/luci_interpreter/test_models/pad_v2/NegPadV2Kernel.h @@ -0,0 +1,97 @@ +/* + * 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_PADV2_KERNEL_H +#define LUCI_INTERPRETER_TEST_MODELS_NEG_PADV2_KERNEL_H + +#include "TestDataPadV2Base.h" + +namespace luci_interpreter +{ +namespace test_kernel +{ +namespace neg_padV2_input_output_type_mismatch +{ +/* + * PadV2 Kernel with input output type mismatch (should be equal): + * + * Input(1, 3, 3, 2) - Float + * | + * PadV2 + * | + * Output(1, 3, 3, 2) - Int + */ +const unsigned char test_kernel_model_circle[] = { + 0x18, 0x00, 0x00, 0x00, 0x43, 0x49, 0x52, 0x30, 0x00, 0x00, 0x0e, 0x00, 0x14, 0x00, 0x00, 0x00, + 0x0c, 0x00, 0x08, 0x00, 0x10, 0x00, 0x04, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x74, 0x00, 0x00, 0x00, 0xe8, 0x01, 0x00, 0x00, 0x04, 0x02, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, + 0x60, 0x00, 0x00, 0x00, 0x58, 0x00, 0x00, 0x00, 0x50, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0xee, 0xff, 0xff, 0xff, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x06, 0x00, 0x08, 0x00, 0x04, 0x00, 0x06, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 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, 0x00, 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, 0x64, 0x00, 0x00, 0x00, 0x68, 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, 0x2b, + 0x10, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x04, 0x00, 0x04, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0xb0, 0x00, 0x00, 0x00, 0x74, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0xa4, 0xff, 0xff, 0xff, 0x10, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, + 0x0c, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x6f, 0x66, 0x6d, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x9c, 0xff, 0xff, 0xff, 0x0c, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, + 0x0f, 0x00, 0x00, 0x00, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x74, 0x5f, 0x76, 0x61, 0x6c, + 0x75, 0x65, 0x73, 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, 0x07, 0x00, 0x00, 0x00, + 0x70, 0x61, 0x64, 0x64, 0x69, 0x6e, 0x67, 0x00, 0x02, 0x00, 0x00, 0x00, 0x04, 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, 0x0c, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x69, 0x66, 0x6d, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x10, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x0c, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, + 0x0c, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 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_padV2_input_output_type_mismatch + +class NegTestDataInputOutputTypeMismatchPadV2Kernel : public NegTestDataBase +{ +public: + NegTestDataInputOutputTypeMismatchPadV2Kernel() + { + _test_kernel_model_circle = neg_padV2_input_output_type_mismatch::test_kernel_model_circle; + } + + ~NegTestDataInputOutputTypeMismatchPadV2Kernel() 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_PADV2_KERNEL_H diff --git a/onert-micro/luci-interpreter/include/luci_interpreter/test_models/pad_v2/TestDataPadV2Base.h b/onert-micro/luci-interpreter/include/luci_interpreter/test_models/pad_v2/TestDataPadV2Base.h new file mode 100644 index 00000000000..b94eb3cfa20 --- /dev/null +++ b/onert-micro/luci-interpreter/include/luci_interpreter/test_models/pad_v2/TestDataPadV2Base.h @@ -0,0 +1,60 @@ +/* + * 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_PADV2_KERNEL_BASE_H +#define LUCI_INTERPRETER_TEST_MODELS_PADV2_KERNEL_BASE_H + +#include "luci_interpreter/test_models/TestDataBase.h" + +namespace luci_interpreter +{ +namespace test_kernel +{ + +template class TestDataPadV2Base : public TestDataBase +{ +public: + TestDataPadV2Base() = 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_PADV2_KERNEL_BASE_H diff --git a/onert-micro/luci-interpreter/pal/common/PALPad.h b/onert-micro/luci-interpreter/pal/common/PALPad.h new file mode 100644 index 00000000000..f9dd73f1bcc --- /dev/null +++ b/onert-micro/luci-interpreter/pal/common/PALPad.h @@ -0,0 +1,109 @@ +/* + * 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"); + * 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_PAD_H +#define LUCI_INTERPRETER_PAL_PAD_H + +#include "PALUtils.h" + +namespace luci_interpreter_pal +{ + +constexpr int PadKernelMaxDimensionCount() { return 5; } + +void Pad(const PadParams &op_params, const luci_interpreter::RuntimeShape &input_shape, + const float *input_data, const float *pad_value_ptr, + const luci_interpreter::RuntimeShape &output_shape, float *output_data) +{ + // Runtime calls are currently fixed at 5 dimensions. Copy inputs so we can + // pad them to 5 dims (yes, we are "padding the padding"). + int left_padding_copy[PadKernelMaxDimensionCount()]; + for (int i = 0; i < PadKernelMaxDimensionCount(); i++) + { + left_padding_copy[i] = 0; + } + for (int i = 0; i < op_params.left_padding_count; ++i) + { + left_padding_copy[i + PadKernelMaxDimensionCount() - op_params.left_padding_count] = + op_params.left_padding[i]; + } + int right_padding_copy[PadKernelMaxDimensionCount()]; + for (int i = 0; i < PadKernelMaxDimensionCount(); i++) + { + right_padding_copy[i] = 0; + } + for (int i = 0; i < op_params.right_padding_count; ++i) + { + right_padding_copy[i + PadKernelMaxDimensionCount() - op_params.right_padding_count] = + op_params.right_padding[i]; + } + const auto extended_output = + luci_interpreter::RuntimeShape::extendedShape(PadKernelMaxDimensionCount(), output_shape); + const int output_batch = extended_output.dims(0); + const int output_plane = extended_output.dims(1); + const int output_height = extended_output.dims(2); + const int output_width = extended_output.dims(3); + const int output_depth = extended_output.dims(4); + + const int left_b_padding = left_padding_copy[0]; + const int left_p_padding = left_padding_copy[1]; + const int left_h_padding = left_padding_copy[2]; + const int left_w_padding = left_padding_copy[3]; + const int left_d_padding = left_padding_copy[4]; + + const int right_b_padding = right_padding_copy[0]; + const int right_p_padding = right_padding_copy[1]; + const int right_h_padding = right_padding_copy[2]; + const int right_w_padding = right_padding_copy[3]; + const int right_d_padding = right_padding_copy[4]; + + const float pad_value = *pad_value_ptr; + + const float *in_ptr = input_data; + float *out_ptr = output_data; + for (int out_b = 0; out_b < output_batch; ++out_b) + { + for (int out_p = 0; out_p < output_plane; ++out_p) + { + for (int out_h = 0; out_h < output_height; ++out_h) + { + for (int out_w = 0; out_w < output_width; ++out_w) + { + for (int out_d = 0; out_d < output_depth; ++out_d) + { + if (out_b < left_b_padding || out_b >= output_batch - right_b_padding || + out_p < left_p_padding || out_p >= output_plane - right_p_padding || + out_h < left_h_padding || out_h >= output_height - right_h_padding || + out_w < left_w_padding || out_w >= output_width - right_w_padding || + out_d < left_d_padding || out_d >= output_depth - right_d_padding) + { + *out_ptr++ = pad_value; + } + else + { + *out_ptr++ = *in_ptr++; + } + } + } + } + } + } +} + +} // namespace luci_interpreter_pal + +#endif // LUCI_INTERPRETER_PAL_PAD_H diff --git a/onert-micro/luci-interpreter/pal/common/Params.h b/onert-micro/luci-interpreter/pal/common/Params.h index 8517a25b190..0dea29432cb 100644 --- a/onert-micro/luci-interpreter/pal/common/Params.h +++ b/onert-micro/luci-interpreter/pal/common/Params.h @@ -21,6 +21,14 @@ namespace luci_interpreter_pal { +struct PadParams +{ + int8_t left_padding_count; + int32_t left_padding[5]; + int8_t right_padding_count; + int32_t right_padding[5]; +}; + struct FullyConnectedParams { int32_t input_offset; diff --git a/onert-micro/luci-interpreter/pal/mcu/KernelsToBuild.lst b/onert-micro/luci-interpreter/pal/mcu/KernelsToBuild.lst index bfa3457b113..5981887657c 100644 --- a/onert-micro/luci-interpreter/pal/mcu/KernelsToBuild.lst +++ b/onert-micro/luci-interpreter/pal/mcu/KernelsToBuild.lst @@ -10,6 +10,8 @@ REGISTER_KERNEL(EXPAND_DIMS, ExpandDims) REGISTER_KERNEL(ELU, Elu) REGISTER_KERNEL(FILL, Fill) REGISTER_KERNEL(PACK, Pack) +REGISTER_KERNEL(PAD, Pad) +REGISTER_KERNEL(PADV2, PadV2) REGISTER_KERNEL(RESHAPE, Reshape) REGISTER_KERNEL(REDUCE_PROD, ReduceCommon) REGISTER_KERNEL(LESS, Less) diff --git a/onert-micro/luci-interpreter/src/kernels/CMakeLists.txt b/onert-micro/luci-interpreter/src/kernels/CMakeLists.txt index c60b97e5114..66c0a9e9d47 100644 --- a/onert-micro/luci-interpreter/src/kernels/CMakeLists.txt +++ b/onert-micro/luci-interpreter/src/kernels/CMakeLists.txt @@ -7,7 +7,8 @@ set(SOURCES KernelBuilder.cpp SISOKernel.h TISOKernel.h - MISOKernel.h) + MISOKernel.h + PadCommon.cpp) macro(REGISTER_KERNEL OPERATOR, NODE) list(APPEND SOURCES "${NODE}.cpp") diff --git a/onert-micro/luci-interpreter/src/kernels/Pad.cpp b/onert-micro/luci-interpreter/src/kernels/Pad.cpp index 6b452654c16..18af756a6f3 100644 --- a/onert-micro/luci-interpreter/src/kernels/Pad.cpp +++ b/onert-micro/luci-interpreter/src/kernels/Pad.cpp @@ -14,101 +14,19 @@ * limitations under the License. */ -#include "kernels/Pad.h" - -#include "kernels/Utils.h" - -#include - -#include +#include "Builders.h" +#include "PadCommon.h" namespace luci_interpreter { -namespace kernels -{ - -Pad::Pad(const Tensor *input, const Tensor *paddings, Tensor *output) - : Kernel({input, paddings}, {output}) -{ -} - -void Pad::configure() +void configure_kernel_CirclePad(const circle::Operator *cur_op, BaseRuntimeGraph *runtime_graph) { - const Shape &input_shape = input()->shape(); - const int num_dims = input_shape.num_dims(); - - if (num_dims > 4) - assert(false && "Unsupported number of dimensions."); - - assert(output()->element_type() == input()->element_type()); - assert(paddings()->element_type() == DataType::S32); - // Paddings shape should be [N, 2]. - assert(paddings()->shape().num_dims() == 2); - assert(paddings()->shape().dim(0) == num_dims); - assert(paddings()->shape().dim(1) == 2); - - Shape output_shape(num_dims); - const auto *paddings_data = getTensorData(paddings()); - for (int i = 0; i < num_dims; ++i) - { - const int32_t padding_before = paddings_data[i * 2]; - const int32_t padding_after = paddings_data[i * 2 + 1]; - assert(padding_before >= 0 && padding_after >= 0); - output_shape.dim(i) = input_shape.dim(i) + padding_before + padding_after; - } - // TODO: enable it only if kernel with dynamic shapes - output()->resize(output_shape); + configure_kernel_CirclePadCommon(cur_op, runtime_graph); } -void Pad::execute() const +void execute_kernel_CirclePad(const circle::Operator *cur_op, BaseRuntimeGraph *runtime_graph) { - const int num_dims = input()->shape().num_dims(); - - tflite::PadParams params{}; - params.left_padding_count = num_dims; - params.right_padding_count = num_dims; - - const auto *paddings_data = getTensorData(paddings()); - for (int i = num_dims - 1; i >= 0; --i) - { - params.left_padding[i] = paddings_data[i * 2]; - params.right_padding[i] = paddings_data[i * 2 + 1]; - } - - switch (input()->element_type()) - { - case DataType::FLOAT32: - { - const float pad_value = 0.0f; - tflite::reference_ops::Pad(params, getTensorShape(input()), getTensorData(input()), - &pad_value, getTensorShape(output()), - getTensorData(output())); - break; - } - case DataType::U8: - { - assert(output()->zero_point() >= std::numeric_limits::min()); - assert(output()->zero_point() <= std::numeric_limits::max()); - const auto pad_value = static_cast(output()->zero_point()); - tflite::reference_ops::Pad(params, getTensorShape(input()), getTensorData(input()), - &pad_value, getTensorShape(output()), - getTensorData(output())); - break; - } - case DataType::S8: - { - assert(output()->zero_point() >= std::numeric_limits::min()); - assert(output()->zero_point() <= std::numeric_limits::max()); - const auto pad_value = static_cast(output()->zero_point()); - tflite::reference_ops::Pad(params, getTensorShape(input()), getTensorData(input()), - &pad_value, getTensorShape(output()), - getTensorData(output())); - break; - } - default: - assert(false && "Unsupported type."); - } + execute_kernel_CirclePadCommon(cur_op, runtime_graph); } -} // namespace kernels } // namespace luci_interpreter diff --git a/onert-micro/luci-interpreter/src/kernels/Pad.test.cpp b/onert-micro/luci-interpreter/src/kernels/Pad.test.cpp index dd3ce947c0e..3c835cbc0f0 100644 --- a/onert-micro/luci-interpreter/src/kernels/Pad.test.cpp +++ b/onert-micro/luci-interpreter/src/kernels/Pad.test.cpp @@ -14,96 +14,73 @@ * limitations under the License. */ -#include "kernels/Pad.h" #include "kernels/TestUtils.h" -#include "luci_interpreter/TestMemoryManager.h" +#include "luci_interpreter/test_models/pad/FloatPadKernel.h" +#include "luci_interpreter/test_models/pad/NegPadKernel.h" + +#include "loader/ModuleLoader.h" namespace luci_interpreter { -namespace kernels -{ namespace { using namespace testing; -float GetTolerance(float min, float max) { return (max - min) / 255.0; } +class PadTest : public ::testing::Test +{ + // Do nothing +}; -TEST(Pad, Uint8) +template std::vector checkPadKernel(test_kernel::TestDataBase *test_data_base) { - std::unique_ptr memory_manager = std::make_unique(); - float kQuantizedTolerance = GetTolerance(-1.0, 1.0); - std::pair quant_param = quantizationParams(-1.0f, 1.0f); - std::vector input_data{-0.8, 0.2, 0.9, 0.7, 0.1, -0.3}; - std::vector paddings_data{0, 0, 0, 2, 1, 3, 0, 0}; - Tensor input_tensor = makeInputTensor( - {1, 2, 3, 1}, quant_param.first, quant_param.second, input_data, memory_manager.get()); - Tensor paddings_tensor = - makeInputTensor({4, 2}, paddings_data, memory_manager.get()); - Tensor output_tensor = makeOutputTensor(DataType::U8, quant_param.first, quant_param.second); - - Pad kernel(&input_tensor, &paddings_tensor, &output_tensor); - kernel.configure(); - memory_manager->allocate_memory(output_tensor); - kernel.execute(); - - std::vector ref_output_data{0, -0.8, 0.2, 0.9, 0, 0, 0, 0, 0.7, 0.1, -0.3, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; - EXPECT_THAT(dequantizeTensorData(output_tensor), - FloatArrayNear(ref_output_data, kQuantizedTolerance)); - EXPECT_THAT(extractTensorShape(output_tensor), ::testing::ElementsAreArray({1, 4, 7, 1})); + 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; } -TEST(Pad, Int8) +TEST_F(PadTest, Float_P) { - std::unique_ptr memory_manager = std::make_unique(); - float kQuantizedTolerance = GetTolerance(-1.0, 1.0); - std::pair quant_param = quantizationParams(-1.0f, 1.0f); - std::vector input_data{-0.2, 0.4, 0.5, -0.7, -0.1, -0.9, 0.7, 0.1, 0.2}; - std::vector paddings_data{0, 0, 1, 2, 2, 1, 0, 0}; - Tensor input_tensor = makeInputTensor( - {1, 3, 3, 1}, quant_param.first, quant_param.second, input_data, memory_manager.get()); - Tensor paddings_tensor = - makeInputTensor({4, 2}, paddings_data, memory_manager.get()); - Tensor output_tensor = makeOutputTensor(DataType::S8, quant_param.first, quant_param.second); - - Pad kernel(&input_tensor, &paddings_tensor, &output_tensor); - kernel.configure(); - memory_manager->allocate_memory(output_tensor); - kernel.execute(); - - std::vector ref_output_data{0, 0, 0, 0, 0, 0, 0, 0, -0.2, 0.4, 0.5, 0, - 0, 0, -0.7, -0.1, -0.9, 0, 0, 0, 0.7, 0.1, 0.2, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; - EXPECT_THAT(dequantizeTensorData(output_tensor), - FloatArrayNear(ref_output_data, kQuantizedTolerance)); - EXPECT_THAT(extractTensorShape(output_tensor), ::testing::ElementsAreArray({1, 6, 6, 1})); + test_kernel::TestDataFloatPad test_data_kernel; + std::vector output_data_vector = checkPadKernel(&test_data_kernel); + EXPECT_THAT(output_data_vector, test_data_kernel.get_output_data_by_index(0)); } -TEST(Pad, Float) +TEST_F(PadTest, Input_output_type_mismatch_NEG) { - std::unique_ptr memory_manager = std::make_unique(); - std::vector input_data{1, 2, 3, 4, 5, 6}; - std::vector paddings_data{1, 0, 0, 2, 0, 3, 0, 0}; - Tensor input_tensor = - makeInputTensor({1, 2, 3, 1}, input_data, memory_manager.get()); - Tensor paddings_tensor = - makeInputTensor({4, 2}, paddings_data, memory_manager.get()); - Tensor output_tensor = makeOutputTensor(DataType::FLOAT32); - - Pad kernel(&input_tensor, &paddings_tensor, &output_tensor); - kernel.configure(); - memory_manager->allocate_memory(output_tensor); - kernel.execute(); - - std::vector ref_output_data{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 0, 0, 0, 4, 5, - 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; - std::initializer_list ref_output_shape{2, 4, 6, 1}; - EXPECT_THAT(extractTensorData(output_tensor), FloatArrayNear(ref_output_data)); - EXPECT_THAT(extractTensorShape(output_tensor), ::testing::ElementsAreArray(ref_output_shape)); + test_kernel::NegTestDataInputOutputTypeMismatchPadKernel 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/PadCommon.cpp b/onert-micro/luci-interpreter/src/kernels/PadCommon.cpp new file mode 100644 index 00000000000..92cd11758f1 --- /dev/null +++ b/onert-micro/luci-interpreter/src/kernels/PadCommon.cpp @@ -0,0 +1,144 @@ +/* + * 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/Utils.h" + +#include "PadCommon.h" +#include "PALPad.h" + +namespace luci_interpreter +{ +void configure_kernel_CirclePadCommon(const circle::Operator *cur_op, + BaseRuntimeGraph *runtime_graph) +{ + const auto num_inputs = cur_op->inputs()->size(); + + const auto input1_index = cur_op->inputs()->operator[](0); + const auto input2_index = cur_op->inputs()->operator[](1); + const auto input3_index = num_inputs == 3 ? cur_op->inputs()->operator[](2) : -1; + const auto output_index = cur_op->outputs()->operator[](0); + + assert(input1_index != -1); + assert(input2_index != -1); + assert(input3_index != -1 or num_inputs == 2); + assert(output_index != -1); + + const auto input1_tensor = runtime_graph->getCircleTensorByIndex(input1_index); + const auto input2_tensor = runtime_graph->getCircleTensorByIndex(input2_index); + const auto input3_tensor = + num_inputs == 3 ? runtime_graph->getCircleTensorByIndex(input3_index) : nullptr; + const auto output_tensor = runtime_graph->getCircleTensorByIndex(output_index); + + assert(input1_tensor != nullptr); + assert(input2_tensor != nullptr); + assert(input3_tensor != nullptr or num_inputs == 2); + assert(output_tensor != nullptr); + + LUCI_INTERPRETER_CHECK(Tensor::element_type(input2_tensor) == DataType::S32); + LUCI_INTERPRETER_CHECK(Tensor::element_type(input1_tensor) == + Tensor::element_type(output_tensor)); + if (input3_tensor != nullptr) + { + LUCI_INTERPRETER_CHECK(Tensor::element_type(input3_tensor) == + Tensor::element_type(input1_tensor)); + // Value is scalar + LUCI_INTERPRETER_CHECK(Tensor::num_elements(input3_tensor) == 1); + } + + // Check shapes + const int32_t *paddings_data = + kernels::getTensorData(runtime_graph->getConstDataByTensor(input2_tensor)); + for (int i = 0; i < Tensor::num_dims(output_tensor); i++) + { + int output_dim = Tensor::dim(output_tensor, i); + int expected_dim = + Tensor::dim(input1_tensor, i) + paddings_data[i * 2] + paddings_data[i * 2 + 1]; + LUCI_INTERPRETER_CHECK(output_dim == expected_dim); + } +} + +void execute_kernel_CirclePadCommon(const circle::Operator *cur_op, BaseRuntimeGraph *runtime_graph) +{ + const auto num_inputs = cur_op->inputs()->size(); + + const auto input1_index = cur_op->inputs()->operator[](0); + const auto input2_index = cur_op->inputs()->operator[](1); + const auto input3_index = num_inputs == 3 ? cur_op->inputs()->operator[](2) : -1; + const auto output_index = cur_op->outputs()->operator[](0); + + assert(input1_index != -1); + assert(input2_index != -1); + assert(input3_index != -1 or num_inputs == 2); + assert(output_index != -1); + + const auto input1_tensor = runtime_graph->getCircleTensorByIndex(input1_index); + const auto input2_tensor = runtime_graph->getCircleTensorByIndex(input2_index); + const auto input3_tensor = + num_inputs == 3 ? runtime_graph->getCircleTensorByIndex(input3_index) : nullptr; + const auto output_tensor = runtime_graph->getCircleTensorByIndex(output_index); + + assert(input1_tensor != nullptr); + assert(input2_tensor != nullptr); + assert(input3_tensor != nullptr or num_inputs == 2); + assert(output_tensor != nullptr); + + luci_interpreter_pal::PadParams pad_params; + const int num_input_dimensions = Tensor::num_dims(input1_tensor); + pad_params.left_padding_count = num_input_dimensions; + pad_params.right_padding_count = num_input_dimensions; + + const int32_t *paddings_data = + kernels::getTensorData(runtime_graph->getConstDataByTensor(input2_tensor)); + for (int idx = num_input_dimensions - 1; idx >= 0; --idx) + { + pad_params.left_padding[idx] = paddings_data[idx * 2]; + pad_params.right_padding[idx] = paddings_data[idx * 2 + 1]; + } + + auto *input1_data = runtime_graph->getDataByTensor(input1_tensor); + if (input1_data == nullptr) + input1_data = runtime_graph->getConstDataByTensor(input1_tensor); + assert(input1_data); + + auto *input2_data = runtime_graph->getConstDataByTensor(input2_tensor); + assert(input2_data); + + auto *output_data = runtime_graph->getDataByTensor(output_tensor); + assert(output_data); + + switch (Tensor::element_type(input1_tensor)) + { +#ifndef DIS_FLOAT + case DataType::FLOAT32: + { + float pad_value = + input3_tensor == nullptr + ? 0.f + : *kernels::getTensorData(runtime_graph->getConstDataByTensor(input3_tensor)); + luci_interpreter_pal::Pad(pad_params, kernels::getTensorShape(input1_tensor), + kernels::getTensorData(input1_data), &pad_value, + kernels::getTensorShape(output_tensor), + kernels::getTensorData(output_data)); + } + break; +#endif // DIS_FLOAT + default: + assert(false && "Unsupported type"); + } +} + +} // namespace luci_interpreter diff --git a/onert-micro/luci-interpreter/src/kernels/Pad.h b/onert-micro/luci-interpreter/src/kernels/PadCommon.h similarity index 52% rename from onert-micro/luci-interpreter/src/kernels/Pad.h rename to onert-micro/luci-interpreter/src/kernels/PadCommon.h index e05b47f2929..d8fa4bed31e 100644 --- a/onert-micro/luci-interpreter/src/kernels/Pad.h +++ b/onert-micro/luci-interpreter/src/kernels/PadCommon.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 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. @@ -14,30 +14,20 @@ * limitations under the License. */ -#ifndef LUCI_INTERPRETER_KERNELS_PAD_H -#define LUCI_INTERPRETER_KERNELS_PAD_H +#ifndef LUCI_INTERPRETER_KERNELS_PAD_COMMON_H +#define LUCI_INTERPRETER_KERNELS_PAD_COMMON_H -#include "core/Kernel.h" +#include "Builders.h" +#include "kernels/Utils.h" namespace luci_interpreter { -namespace kernels -{ - -class Pad : public Kernel -{ -public: - Pad(const Tensor *input, const Tensor *paddings, Tensor *output); - - const Tensor *input() const { return _inputs[0]; } - const Tensor *paddings() const { return _inputs[1]; } - Tensor *output() const { return _outputs[0]; } +void configure_kernel_CirclePadCommon(const circle::Operator *cur_op, + BaseRuntimeGraph *runtime_graph); - void configure() override; - void execute() const override; -}; +void execute_kernel_CirclePadCommon(const circle::Operator *cur_op, + BaseRuntimeGraph *runtime_graph); -} // namespace kernels } // namespace luci_interpreter -#endif // LUCI_INTERPRETER_KERNELS_PAD_H +#endif // LUCI_INTERPRETER_KERNELS_PAD_COMMON_H diff --git a/onert-micro/luci-interpreter/src/kernels/PadV2.cpp b/onert-micro/luci-interpreter/src/kernels/PadV2.cpp index c141e3d1688..7e0f61b8d30 100644 --- a/onert-micro/luci-interpreter/src/kernels/PadV2.cpp +++ b/onert-micro/luci-interpreter/src/kernels/PadV2.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. All Rights Reserved + * 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. @@ -14,95 +14,19 @@ * limitations under the License. */ -#include "kernels/PadV2.h" - -#include "kernels/Utils.h" - -#include - -#include +#include "Builders.h" +#include "PadCommon.h" namespace luci_interpreter { -namespace kernels -{ - -PadV2::PadV2(const Tensor *input, const Tensor *paddings, const Tensor *constant_values, - Tensor *output) - : Kernel({input, paddings, constant_values}, {output}) -{ -} - -void PadV2::configure() +void configure_kernel_CirclePadV2(const circle::Operator *cur_op, BaseRuntimeGraph *runtime_graph) { - const Shape &input_shape = input()->shape(); - const int num_dims = input_shape.num_dims(); - - if (num_dims > 4) - assert(false && "Unsupported number of dimensions."); - - assert(output()->element_type() == input()->element_type()); - assert(paddings()->element_type() == DataType::S32); - assert(constant_values()->element_type() == output()->element_type()); - // Paddings shape should be [N, 2]. - assert(paddings()->shape().num_dims() == 2); - assert(paddings()->shape().dim(0) == num_dims); - assert(paddings()->shape().dim(1) == 2); - // Constant values elements number should be 1. - assert(constant_values()->shape().num_elements() == 1); - - Shape output_shape(num_dims); - const auto *paddings_data = getTensorData(paddings()); - for (int i = 0; i < num_dims; ++i) - { - const int32_t padding_before = paddings_data[i * 2]; - const int32_t padding_after = paddings_data[i * 2 + 1]; - assert(padding_before >= 0 && padding_after >= 0); - output_shape.dim(i) = input_shape.dim(i) + padding_before + padding_after; - } - // TODO: enable it only if kernel with dynamic shapes - output()->resize(output_shape); + configure_kernel_CirclePadCommon(cur_op, runtime_graph); } -void PadV2::execute() const +void execute_kernel_CirclePadV2(const circle::Operator *cur_op, BaseRuntimeGraph *runtime_graph) { - const int num_dims = input()->shape().num_dims(); - - tflite::PadParams params{}; - params.left_padding_count = num_dims; - params.right_padding_count = num_dims; - - const auto *paddings_data = getTensorData(paddings()); - for (int i = num_dims - 1; i >= 0; --i) - { - params.left_padding[i] = paddings_data[i * 2]; - params.right_padding[i] = paddings_data[i * 2 + 1]; - } - - switch (input()->element_type()) - { - case DataType::FLOAT32: - { - const auto pad_value = getTensorData(constant_values())[0]; - tflite::reference_ops::Pad(params, getTensorShape(input()), getTensorData(input()), - &pad_value, getTensorShape(output()), - getTensorData(output())); - break; - } - case DataType::U8: - { - assert(output()->zero_point() >= std::numeric_limits::min()); - assert(output()->zero_point() <= std::numeric_limits::max()); - const auto pad_value = getTensorData(constant_values())[0]; - tflite::reference_ops::Pad(params, getTensorShape(input()), getTensorData(input()), - &pad_value, getTensorShape(output()), - getTensorData(output())); - break; - } - default: - assert(false && "Unsupported type."); - } + execute_kernel_CirclePadCommon(cur_op, runtime_graph); } -} // namespace kernels } // namespace luci_interpreter diff --git a/onert-micro/luci-interpreter/src/kernels/PadV2.h b/onert-micro/luci-interpreter/src/kernels/PadV2.h deleted file mode 100644 index 48a31f584f7..00000000000 --- a/onert-micro/luci-interpreter/src/kernels/PadV2.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2021 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_PAD_V2_H -#define LUCI_INTERPRETER_KERNELS_PAD_V2_H - -#include "core/Kernel.h" - -namespace luci_interpreter -{ -namespace kernels -{ - -class PadV2 : public Kernel -{ -public: - PadV2(const Tensor *input, const Tensor *paddings, const Tensor *constant_values, Tensor *output); - - const Tensor *input() const { return _inputs[0]; } - const Tensor *paddings() const { return _inputs[1]; } - const Tensor *constant_values() const { return _inputs[2]; } - Tensor *output() const { return _outputs[0]; } - - void configure() override; - void execute() const override; -}; - -} // namespace kernels -} // namespace luci_interpreter - -#endif // LUCI_INTERPRETER_KERNELS_PAD_V2_H diff --git a/onert-micro/luci-interpreter/src/kernels/PadV2.test.cpp b/onert-micro/luci-interpreter/src/kernels/PadV2.test.cpp index 41efaff060b..8be5b025252 100644 --- a/onert-micro/luci-interpreter/src/kernels/PadV2.test.cpp +++ b/onert-micro/luci-interpreter/src/kernels/PadV2.test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. All Rights Reserved + * 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. @@ -14,77 +14,73 @@ * limitations under the License. */ -#include "kernels/PadV2.h" #include "kernels/TestUtils.h" -#include "luci_interpreter/TestMemoryManager.h" +#include "luci_interpreter/test_models/pad_v2/FloatPadV2Kernel.h" +#include "luci_interpreter/test_models/pad_v2/NegPadV2Kernel.h" + +#include "loader/ModuleLoader.h" namespace luci_interpreter { -namespace kernels -{ namespace { using namespace testing; -float GetTolerance(float min, float max) { return (max - min) / 255.0; } +class PadV2Test : public ::testing::Test +{ + // Do nothing +}; -TEST(PadV2, Uint8) +template std::vector checkPadV2Kernel(test_kernel::TestDataBase *test_data_base) { - std::unique_ptr memory_manager = std::make_unique(); - float kQuantizedTolerance = GetTolerance(-1.0, 1.0); - std::pair quant_param = quantizationParams(-1.0f, 1.0f); - std::vector input_data{-0.8, 0.2, 0.9, 0.7, 0.1, -0.3}; - std::vector paddings_data{0, 0, 0, 2, 1, 3, 0, 0}; - std::vector constant_values_data{0.5}; - Tensor input_tensor = makeInputTensor( - {1, 2, 3, 1}, quant_param.first, quant_param.second, input_data, memory_manager.get()); - Tensor paddings_tensor = - makeInputTensor({4, 2}, paddings_data, memory_manager.get()); - Tensor constant_values = makeInputTensor( - {1}, quant_param.first, quant_param.second, constant_values_data, memory_manager.get()); - Tensor output_tensor = makeOutputTensor(DataType::U8, quant_param.first, quant_param.second); - - PadV2 kernel(&input_tensor, &paddings_tensor, &constant_values, &output_tensor); - kernel.configure(); - memory_manager->allocate_memory(output_tensor); - kernel.execute(); - - std::vector ref_output_data = { - 0.5, -0.8, 0.2, 0.9, 0.5, 0.5, 0.5, 0.5, 0.7, 0.1, -0.3, 0.5, 0.5, 0.5, // - 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5}; // - EXPECT_THAT(dequantizeTensorData(output_tensor), - FloatArrayNear(ref_output_data, kQuantizedTolerance)); - EXPECT_THAT(extractTensorShape(output_tensor), ::testing::ElementsAreArray({1, 4, 7, 1})); + 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; +} + +TEST_F(PadV2Test, Float_P) +{ + test_kernel::TestDataFloatPadV2 test_data_kernel; + std::vector output_data_vector = checkPadV2Kernel(&test_data_kernel); + EXPECT_THAT(output_data_vector, test_data_kernel.get_output_data_by_index(0)); } -TEST(PadV2, Float) +TEST_F(PadV2Test, Input_output_type_mismatch_NEG) { - std::unique_ptr memory_manager = std::make_unique(); - std::vector input_data{1, 2, 3, 4, 5, 6}; - std::vector paddings_data{1, 0, 0, 2, 0, 3, 0, 0}; - std::vector constant_values_data{7}; - Tensor input_tensor = - makeInputTensor({1, 2, 3, 1}, input_data, memory_manager.get()); - Tensor paddings_tensor = - makeInputTensor({4, 2}, paddings_data, memory_manager.get()); - Tensor constant_values = - makeInputTensor({1}, constant_values_data, memory_manager.get()); - Tensor output_tensor = makeOutputTensor(DataType::FLOAT32); - - PadV2 kernel(&input_tensor, &paddings_tensor, &constant_values, &output_tensor); - kernel.configure(); - memory_manager->allocate_memory(output_tensor); - kernel.execute(); - - std::vector ref_output_data{7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, - 7, 7, 7, 7, 7, 7, 7, 7, 1, 2, 3, 7, 7, 7, 4, 5, - 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7}; - std::initializer_list ref_output_shape{2, 4, 6, 1}; - EXPECT_THAT(extractTensorData(output_tensor), FloatArrayNear(ref_output_data)); - EXPECT_THAT(extractTensorShape(output_tensor), ::testing::ElementsAreArray(ref_output_shape)); + test_kernel::NegTestDataInputOutputTypeMismatchPadV2Kernel 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