diff --git a/onert-micro/onert-micro/include/pal/common/PALDivCommon.h b/onert-micro/onert-micro/include/pal/common/PALDivCommon.h new file mode 100644 index 00000000000..a54b8eb8ff7 --- /dev/null +++ b/onert-micro/onert-micro/include/pal/common/PALDivCommon.h @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2024 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 ONERT_MICRO_EXECUTE_PAL_DIV_COMMON_H +#define ONERT_MICRO_EXECUTE_PAL_DIV_COMMON_H + +#include "PALArithmeticOpCommon.h" + +namespace onert_micro +{ +namespace execute +{ +namespace pal +{ + +template +OMStatus Div(const core::BinaryArithmeticBroadcastParams ¶ms, const int flat_size, + const T *input1_data, const T *input2_data, T *output_data) +{ + ArithmeticOp>(params, flat_size, input1_data, input2_data, output_data); + return Ok; +} + +template +OMStatus BroadcastDiv4DSlow(const core::BinaryArithmeticBroadcastParams ¶ms, + const core::OMRuntimeShape &input1_shape, const T *input1_data, + const core::OMRuntimeShape &input2_shape, const T *input2_data, + const core::OMRuntimeShape &output_shape, T *output_data) +{ + BroadcastArithmeticOp4DSlow>(params, input1_shape, input1_data, input2_shape, + input2_data, output_shape, output_data); + return Ok; +} + +} // namespace pal +} // namespace execute +} // namespace onert_micro + +#endif // ONERT_MICRO_EXECUTE_PAL_MUL_COMMON_H diff --git a/onert-micro/onert-micro/include/pal/mcu/KernelsToBuild.lst b/onert-micro/onert-micro/include/pal/mcu/KernelsToBuild.lst index db570313880..fb2e20b87e6 100644 --- a/onert-micro/onert-micro/include/pal/mcu/KernelsToBuild.lst +++ b/onert-micro/onert-micro/include/pal/mcu/KernelsToBuild.lst @@ -10,7 +10,7 @@ REGISTER_KERNEL(BATCH_TO_SPACE_ND, BatchToSpaceND) #/*REGISTER_KERNEL(CEIL, Ceil)*/ REGISTER_KERNEL(COS, Cos) #/*REGISTER_KERNEL(CAST, Cast)*/ -#/*REGISTER_KERNEL(DIV, Div)*/ +REGISTER_KERNEL(DIV, Div) REGISTER_KERNEL(DEPTHWISE_CONV_2D, DepthwiseConv2D) #/*REGISTER_KERNEL(DEPTH_TO_SPACE, DepthToSpace)*/ #/*REGISTER_KERNEL(DEQUANTIZE, Dequantize)*/ diff --git a/onert-micro/onert-micro/include/pal/mcu/PALDiv.h b/onert-micro/onert-micro/include/pal/mcu/PALDiv.h new file mode 100644 index 00000000000..74859c28153 --- /dev/null +++ b/onert-micro/onert-micro/include/pal/mcu/PALDiv.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2021 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 ONERT_MICRO_EXECUTE_PAL_DIV_H +#define ONERT_MICRO_EXECUTE_PAL_DIV_H + +#include "PALDivCommon.h" + +#endif // ONERT_MICRO_EXECUTE_PAL_MUL_H diff --git a/onert-micro/onert-micro/include/test_models/div/FloatDivKernel.h b/onert-micro/onert-micro/include/test_models/div/FloatDivKernel.h new file mode 100644 index 00000000000..bc76d2d73d2 --- /dev/null +++ b/onert-micro/onert-micro/include/test_models/div/FloatDivKernel.h @@ -0,0 +1,184 @@ +/* + * 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_DIV_KERNEL_FLOAT_H +#define ONERT_MICRO_TEST_MODELS_DIV_KERNEL_FLOAT_H + +#include "TestDataDivBase.h" + +namespace onert_micro +{ +namespace test_model +{ +namespace div_float_with_broadcasting +{ + +/* + * div Kernel: + * + * Input_1(1, 4, 4, 3) Input_2(1, 4, 4, 1) + * \ / + * Div(with broadcast) + * | + * Output(1, 4, 4, 3) + */ +const unsigned char test_kernel_model_circle[] = { + 0x18, 0x00, 0x00, 0x00, 0x43, 0x49, 0x52, 0x30, 0x00, 0x00, 0x0e, 0x00, 0x14, 0x00, 0x00, 0x00, + 0x0c, 0x00, 0x08, 0x00, 0x10, 0x00, 0x04, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x30, 0x00, 0x00, 0x00, 0x6c, 0x01, 0x00, 0x00, 0x88, 0x01, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x1c, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x88, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x90, 0xff, 0xff, 0xff, 0x94, 0xff, 0xff, 0xff, + 0x01, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x18, 0x00, 0x14, 0x00, + 0x10, 0x00, 0x0c, 0x00, 0x08, 0x00, 0x04, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, + 0x1c, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x6c, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x14, 0x00, 0x00, 0x00, 0x10, 0x00, 0x0c, 0x00, + 0x07, 0x00, 0x08, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1d, 0x10, 0x00, 0x00, 0x00, + 0x10, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x04, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x74, 0x00, 0x00, 0x00, + 0x34, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xa4, 0xff, 0xff, 0xff, 0x0c, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x6f, 0x66, 0x6d, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0xd0, 0xff, 0xff, 0xff, 0x0c, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x10, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x69, 0x66, 0x6d, 0x32, 0x00, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x08, 0x00, 0x04, 0x00, + 0x0c, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x69, 0x66, 0x6d, 0x31, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x0c, 0x00, 0x0b, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x04, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x2a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2a, + 0x11, 0x00, 0x00, 0x00, 0x4f, 0x4e, 0x45, 0x2d, 0x74, 0x66, 0x6c, 0x69, 0x74, 0x65, 0x32, 0x63, + 0x69, 0x72, 0x63, 0x6c, 0x65, 0x00, 0x00, 0x00}; + +const std::vector input1_data = { + 0.53560877, -1.8867658, -8.832248, 5.859678, -5.1357374, -7.014421, 2.8209867, -4.6921616, + 8.162995, -2.6120718, -0.8869447, -2.3489552, -6.208182, -2.2264383, 6.55287, -5.3615203, + -2.7882025, 1.1029396, -9.950372, 0.1670622, 3.533298, 2.606648, 7.126593, -3.6454842, + 2.637641, -6.7670174, 5.8970585, 8.792766, -6.63798, -1.1457828, 9.122211, -3.2186837, + -8.038172, 3.3369763, 0.89376354, -7.979661, -4.241393, -3.4046402, 6.1339216, 7.767886, + 5.7856345, 8.147999, 9.79144, 8.312661, -4.9722652, 3.0038614, -5.3218126, -6.5680394}; +const std::vector input2_data = { + -8.79469, -0.2644837, -1.6307421, 2.0497515, -1.5460981, 1.3044068, 7.1843495, 1.1402534, + 0.2102437, 4.253287, 7.076496, 1.3749583, 6.6056423, 4.4962177, 3.9589605, -1.8852876}; +const std::vector reference_output_data = { + -0.06090138, 0.21453466, 1.0042704, -22.155157, 19.417974, 26.521185, -1.7298791, + 2.8773167, -5.005694, -1.2743359, -0.4327084, -1.1459707, 4.0153866, 1.4400369, + -4.2383275, -4.110313, -2.1375253, 0.8455488, -1.3850067, 0.023253629, 0.49180487, + 2.286025, 6.250008, -3.1970825, 12.545636, -32.18654, 28.048681, 2.0672872, + -1.5606706, -0.26938763, 1.2890859, -0.45484143, -1.1358972, 2.4269655, 0.6500296, + -5.803566, -0.6420864, -0.51541394, 0.9285882, 1.727649, 1.2867781, 1.8121896, + 2.4732351, 2.099708, -1.2559522, -1.5933173, 2.822812, 3.4838395}; + +} // namespace div_float_with_broadcasting + +namespace div_float_no_broadcasting +{ +/* + * div Kernel: + * + * Input_1(1, 4, 4, 3) Input_2(1, 4, 4, 3) + * \ / + * Div(no broadcast) + * | + * Output(1, 4, 4, 3) + */ +const unsigned char test_kernel_model_circle[] = { + 0x18, 0x00, 0x00, 0x00, 0x43, 0x49, 0x52, 0x30, 0x00, 0x00, 0x0e, 0x00, 0x14, 0x00, 0x00, 0x00, + 0x0c, 0x00, 0x08, 0x00, 0x10, 0x00, 0x04, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x30, 0x00, 0x00, 0x00, 0x6c, 0x01, 0x00, 0x00, 0x88, 0x01, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x1c, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x88, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x90, 0xff, 0xff, 0xff, 0x94, 0xff, 0xff, 0xff, + 0x01, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x18, 0x00, 0x14, 0x00, + 0x10, 0x00, 0x0c, 0x00, 0x08, 0x00, 0x04, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, + 0x1c, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x6c, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x14, 0x00, 0x00, 0x00, 0x10, 0x00, 0x0c, 0x00, + 0x07, 0x00, 0x08, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1d, 0x10, 0x00, 0x00, 0x00, + 0x10, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x04, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x74, 0x00, 0x00, 0x00, + 0x34, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xa4, 0xff, 0xff, 0xff, 0x0c, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x6f, 0x66, 0x6d, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0xd0, 0xff, 0xff, 0xff, 0x0c, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x10, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x69, 0x66, 0x6d, 0x32, 0x00, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x08, 0x00, 0x04, 0x00, + 0x0c, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x69, 0x66, 0x6d, 0x31, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x0c, 0x00, 0x0b, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x04, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x2a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2a, + 0x11, 0x00, 0x00, 0x00, 0x4f, 0x4e, 0x45, 0x2d, 0x74, 0x66, 0x6c, 0x69, 0x74, 0x65, 0x32, 0x63, + 0x69, 0x72, 0x63, 0x6c, 0x65, 0x00, 0x00, 0x00}; + +std::vector input1_data = { + -0.45486993, 7.7920837, 2.458276, -9.338201, 2.132607, 7.5134172, -7.3420544, -6.390925, + 1.456884, -1.8421048, 2.4459255, -3.930421, 5.439674, -0.3640652, -4.5039334, -8.457781, + 3.8367634, -6.271797, -3.6314914, 7.7209616, 0.7935352, -6.561332, 0.77153474, 8.639922, + 0.15612718, 5.9307566, 0.71869296, 5.4473047, -7.4552007, -2.4453044, -5.7700257, 7.9675865, + 4.7339244, 1.3709338, 6.940702, 2.7984607, 9.185996, 8.848705, -4.7602606, -3.887096, + 4.807505, 2.9972825, 5.416388, 5.6682634, -5.875255, -0.29188222, 7.522483, -6.873605}; +std::vector input2_data = { + 1.5015899, 9.9904785, -5.368375, -3.0589666, 1.4541256, 3.0067844, -1.0564902, 3.4706006, + 4.3666296, 9.586457, -4.497033, -9.208905, -6.8920064, 6.2652717, -0.60215276, 7.8108196, + -7.7110577, -4.182856, 6.8893385, 9.817479, -9.451469, -2.0223913, 5.1733356, 5.4378557, + 4.1402535, -4.4087567, 0.16630036, -8.007953, 4.7895074, -3.2770896, 4.013145, 2.2894316, + 5.74741, -9.481342, 3.194859, 9.471764, -7.8339133, -8.103412, -3.8862576, 9.901491, + 5.358148, -2.7227716, -5.84558, 9.881574, 3.5261114, 3.4573863, 8.221204, -3.6716719}; +std::vector reference_output_data = { + -0.30292553, 0.779951, -0.4579181, 3.0527303, 1.4665906, 2.4988215, 6.949477, + -1.8414464, 0.3336404, -0.19215699, -0.54389757, 0.42680657, -0.7892729, -0.058108445, + 7.4797187, -1.0828289, -0.49756643, 1.4994054, -0.52711755, 0.7864505, -0.083958924, + 3.2443435, 0.14913681, 1.5888473, 0.03770957, -1.345222, 4.321656, -0.6802369, + -1.5565695, 0.7461817, -1.4377816, 3.4801593, 0.8236622, -0.14459279, 2.1724596, + 0.29545298, -1.1725935, -1.0919728, 1.2248958, -0.3925768, 0.8972326, -1.1008204, + -0.92657834, 0.5736195, -1.6662138, -0.0844228, 0.9150099, 1.872064}; + +} // namespace div_float_no_broadcasting + +class TestDataFloatDiv : public TestDataDivBase +{ +public: + explicit TestDataFloatDiv(bool is_with_broadcast) : TestDataDivBase(is_with_broadcast) + { + if (is_with_broadcast) + { + _input1_data = div_float_with_broadcasting::input1_data; + _input2_data = div_float_with_broadcasting::input2_data; + _reference_output_data = div_float_with_broadcasting::reference_output_data; + _test_kernel_model_circle = div_float_with_broadcasting::test_kernel_model_circle; + } + else + { + _input1_data = div_float_no_broadcasting::input1_data; + _input2_data = div_float_no_broadcasting::input2_data; + _reference_output_data = div_float_no_broadcasting::reference_output_data; + _test_kernel_model_circle = div_float_no_broadcasting::test_kernel_model_circle; + } + } + + ~TestDataFloatDiv() override = default; +}; + +} // namespace test_model +} // namespace onert_micro + +#endif // ONERT_MICRO_TEST_MODELS_MUL_KERNEL_FLOAT_H diff --git a/onert-micro/onert-micro/include/test_models/div/IntDivKernel.h b/onert-micro/onert-micro/include/test_models/div/IntDivKernel.h new file mode 100644 index 00000000000..49672157140 --- /dev/null +++ b/onert-micro/onert-micro/include/test_models/div/IntDivKernel.h @@ -0,0 +1,267 @@ +/* + * 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_DIV_KERNEL_INT_H +#define ONERT_MICRO_TEST_MODELS_DIV_KERNEL_INT_H + +#include "TestDataDivBase.h" + +namespace onert_micro +{ +namespace test_model +{ +namespace div_int_with_broadcasting +{ + +/* + * Div Kernel: + * + * Input_1(2, 5) Input_2(2, 1) + * \ / + * Div(with broadcast) + * | + * Output(2, 5) + */ +const unsigned char test_kernel_model_circle[] = { + 0x18, 0x00, 0x00, 0x00, 0x43, 0x49, 0x52, 0x30, 0x00, 0x00, 0x0e, 0x00, 0x14, 0x00, 0x00, 0x00, + 0x0c, 0x00, 0x08, 0x00, 0x10, 0x00, 0x04, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x30, 0x00, 0x00, 0x00, 0x60, 0x01, 0x00, 0x00, 0x7c, 0x01, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x1c, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x88, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x90, 0xff, 0xff, 0xff, 0x94, 0xff, 0xff, 0xff, + 0x01, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x18, 0x00, 0x14, 0x00, + 0x10, 0x00, 0x0c, 0x00, 0x08, 0x00, 0x04, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, + 0x1c, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x6c, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x14, 0x00, 0x00, 0x00, 0x10, 0x00, 0x0c, 0x00, + 0x07, 0x00, 0x08, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1d, 0x10, 0x00, 0x00, 0x00, + 0x10, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x04, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x6c, 0x00, 0x00, 0x00, + 0x30, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xac, 0xff, 0xff, 0xff, 0x10, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x0c, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x6f, 0x66, 0x6d, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, + 0xd4, 0xff, 0xff, 0xff, 0x10, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, + 0x10, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x69, 0x66, 0x6d, 0x32, 0x00, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x05, 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, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x0c, 0x00, + 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x2a, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x2a, 0x11, 0x00, 0x00, 0x00, 0x4f, 0x4e, 0x45, 0x2d, 0x74, 0x66, 0x6c, 0x69, + 0x74, 0x65, 0x32, 0x63, 0x69, 0x72, 0x63, 0x6c, 0x65, 0x00, 0x00, 0x00}; + +const std::vector input1_data = {7, -17}; +const std::vector input2_data = {12, 4, -7, -10, -10, -16, -17, 1, 15, 4}; +const std::vector reference_output_data = {0, 1, -1, 0, 0, 1, 1, -17, -1, -4}; + +} // namespace div_int_with_broadcasting + +namespace div_int_no_broadcasting +{ +/* + * Div Kernel: + * + * Input_1(2, 5) Input_2(2, 5) + * \ / + * Div(no broadcast) + * | + * Output(2, 5) + */ +const unsigned char test_kernel_model_circle[] = { + 0x18, 0x00, 0x00, 0x00, 0x43, 0x49, 0x52, 0x30, 0x00, 0x00, 0x0e, 0x00, 0x14, 0x00, 0x00, 0x00, + 0x0c, 0x00, 0x08, 0x00, 0x10, 0x00, 0x04, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x30, 0x00, 0x00, 0x00, 0x60, 0x01, 0x00, 0x00, 0x7c, 0x01, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x1c, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x88, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x90, 0xff, 0xff, 0xff, 0x94, 0xff, 0xff, 0xff, + 0x01, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x18, 0x00, 0x14, 0x00, + 0x10, 0x00, 0x0c, 0x00, 0x08, 0x00, 0x04, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, + 0x1c, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x6c, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x14, 0x00, 0x00, 0x00, 0x10, 0x00, 0x0c, 0x00, + 0x07, 0x00, 0x08, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1d, 0x10, 0x00, 0x00, 0x00, + 0x10, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x04, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x6c, 0x00, 0x00, 0x00, + 0x30, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xac, 0xff, 0xff, 0xff, 0x10, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x0c, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x6f, 0x66, 0x6d, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, + 0xd4, 0xff, 0xff, 0xff, 0x10, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, + 0x10, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x69, 0x66, 0x6d, 0x32, 0x00, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x05, 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, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x05, 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, 0x2a, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x2a, 0x11, 0x00, 0x00, 0x00, 0x4f, 0x4e, 0x45, 0x2d, 0x74, 0x66, 0x6c, 0x69, + 0x74, 0x65, 0x32, 0x63, 0x69, 0x72, 0x63, 0x6c, 0x65, 0x00, 0x00, 0x00}; + +std::vector input1_data = {-4, 19, -4, -9, 17, 12, 17, -15, -10, -14}; +std::vector input2_data = {-18, -16, -17, -9, -6, -1, 7, -2, -15, -3}; +std::vector reference_output_data = {0, -1, 0, 1, -2, -12, 2, 7, 0, 4}; + +} // namespace div_int_no_broadcasting + +namespace div_int64_with_broadcasting +{ + +/* + * Div Kernel: + * + * Input_1(2, 5) Input_2(2, 1) + * \ / + * Div(with broadcast) + * | + * Output(2, 5) + */ +const unsigned char test_kernel_model_circle[] = { + 0x18, 0x00, 0x00, 0x00, 0x43, 0x49, 0x52, 0x30, 0x00, 0x00, 0x0e, 0x00, 0x14, 0x00, 0x00, 0x00, + 0x0c, 0x00, 0x08, 0x00, 0x10, 0x00, 0x04, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x30, 0x00, 0x00, 0x00, 0x60, 0x01, 0x00, 0x00, 0x7c, 0x01, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x1c, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x88, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x90, 0xff, 0xff, 0xff, 0x94, 0xff, 0xff, 0xff, + 0x01, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x18, 0x00, 0x14, 0x00, + 0x10, 0x00, 0x0c, 0x00, 0x08, 0x00, 0x04, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, + 0x1c, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x6c, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x14, 0x00, 0x00, 0x00, 0x10, 0x00, 0x0c, 0x00, + 0x07, 0x00, 0x08, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1d, 0x10, 0x00, 0x00, 0x00, + 0x10, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x04, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x6c, 0x00, 0x00, 0x00, + 0x30, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xac, 0xff, 0xff, 0xff, 0x10, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x0c, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x6f, 0x66, 0x6d, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, + 0xd4, 0xff, 0xff, 0xff, 0x10, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, + 0x10, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x69, 0x66, 0x6d, 0x32, 0x00, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x05, 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, 0x04, 0x10, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x69, 0x66, 0x6d, 0x31, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x0c, 0x00, + 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x2a, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x2a, 0x11, 0x00, 0x00, 0x00, 0x4f, 0x4e, 0x45, 0x2d, 0x74, 0x66, 0x6c, 0x69, + 0x74, 0x65, 0x32, 0x63, 0x69, 0x72, 0x63, 0x6c, 0x65, 0x00, 0x00, 0x00}; + +const std::vector input1_data = {7, -17}; +const std::vector input2_data = {12, 4, -7, -10, -10, -16, -17, 1, 15, 4}; +const std::vector reference_output_data = {0, 1, -1, 0, 0, 1, 1, -17, -1, -4}; + +} // namespace div_int64_with_broadcasting + +namespace div_int64_no_broadcasting +{ +/* + * Div Kernel: + * + * Input_1(2, 5) Input_2(2, 5) + * \ / + * Div(no broadcast) + * | + * Output(2, 5) + */ +const unsigned char test_kernel_model_circle[] = { + 0x18, 0x00, 0x00, 0x00, 0x43, 0x49, 0x52, 0x30, 0x00, 0x00, 0x0e, 0x00, 0x14, 0x00, 0x00, 0x00, + 0x0c, 0x00, 0x08, 0x00, 0x10, 0x00, 0x04, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x30, 0x00, 0x00, 0x00, 0x60, 0x01, 0x00, 0x00, 0x7c, 0x01, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x1c, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x88, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x90, 0xff, 0xff, 0xff, 0x94, 0xff, 0xff, 0xff, + 0x01, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x18, 0x00, 0x14, 0x00, + 0x10, 0x00, 0x0c, 0x00, 0x08, 0x00, 0x04, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, + 0x1c, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x6c, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x14, 0x00, 0x00, 0x00, 0x10, 0x00, 0x0c, 0x00, + 0x07, 0x00, 0x08, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1d, 0x10, 0x00, 0x00, 0x00, + 0x10, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x04, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x6c, 0x00, 0x00, 0x00, + 0x30, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xac, 0xff, 0xff, 0xff, 0x10, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x0c, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x6f, 0x66, 0x6d, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, + 0xd4, 0xff, 0xff, 0xff, 0x10, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, + 0x10, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x69, 0x66, 0x6d, 0x32, 0x00, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x05, 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, 0x04, 0x10, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x69, 0x66, 0x6d, 0x31, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x05, 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, 0x2a, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x2a, 0x11, 0x00, 0x00, 0x00, 0x4f, 0x4e, 0x45, 0x2d, 0x74, 0x66, 0x6c, 0x69, + 0x74, 0x65, 0x32, 0x63, 0x69, 0x72, 0x63, 0x6c, 0x65, 0x00, 0x00, 0x00}; + +std::vector input1_data = {-4, 19, -4, -9, 17, 12, 17, -15, -10, -14}; +std::vector input2_data = {-18, -16, -17, -9, -6, -1, 7, -2, -15, -3}; +std::vector reference_output_data = {0, -1, 0, 1, -2, -12, 2, 7, 0, 4}; + +} // namespace div_int64_no_broadcasting + +class TestDataIntDiv : public TestDataDivBase +{ +public: + explicit TestDataIntDiv(bool is_with_broadcast) : TestDataDivBase(is_with_broadcast) + { + if (is_with_broadcast) + { + _input1_data = div_int_with_broadcasting::input1_data; + _input2_data = div_int_with_broadcasting::input2_data; + _reference_output_data = div_int_with_broadcasting::reference_output_data; + _test_kernel_model_circle = div_int_with_broadcasting::test_kernel_model_circle; + } + else + { + _input1_data = div_int_no_broadcasting::input1_data; + _input2_data = div_int_no_broadcasting::input2_data; + _reference_output_data = div_int_no_broadcasting::reference_output_data; + _test_kernel_model_circle = div_int_no_broadcasting::test_kernel_model_circle; + } + } + + ~TestDataIntDiv() override = default; +}; + +class TestDataInt64Div : public TestDataDivBase +{ +public: + explicit TestDataInt64Div(bool is_with_broadcast) : TestDataDivBase(is_with_broadcast) + { + if (is_with_broadcast) + { + _input1_data = div_int64_with_broadcasting::input1_data; + _input2_data = div_int64_with_broadcasting::input2_data; + _reference_output_data = div_int64_with_broadcasting::reference_output_data; + _test_kernel_model_circle = div_int64_with_broadcasting::test_kernel_model_circle; + } + else + { + _input1_data = div_int64_no_broadcasting::input1_data; + _input2_data = div_int64_no_broadcasting::input2_data; + _reference_output_data = div_int64_no_broadcasting::reference_output_data; + _test_kernel_model_circle = div_int64_no_broadcasting::test_kernel_model_circle; + } + } + + ~TestDataInt64Div() override = default; +}; + +} // namespace test_model +} // namespace onert_micro + +#endif // ONERT_MICRO_TEST_MODELS_DIV_KERNEL_INT_H diff --git a/onert-micro/onert-micro/include/test_models/div/NegDivKernel.h b/onert-micro/onert-micro/include/test_models/div/NegDivKernel.h new file mode 100644 index 00000000000..7170d56ae5b --- /dev/null +++ b/onert-micro/onert-micro/include/test_models/div/NegDivKernel.h @@ -0,0 +1,149 @@ +/* + * 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_DIV_KERNEL_H +#define ONERT_MICRO_TEST_MODELS_NEG_DIV_KERNEL_H + +#include "TestDataDivBase.h" + +namespace onert_micro +{ +namespace test_model +{ +namespace input_1_wrong_type_div +{ + +/* + * Div Kernel with input type mismatch: + * + * Input_1(2, 5) - Int32 Input_2(2, 1) - Float + * \ / + * Div(with broadcast) + * | + * Output(2, 5) + */ +const unsigned char test_kernel_model_circle[] = { + 0x18, 0x00, 0x00, 0x00, 0x43, 0x49, 0x52, 0x30, 0x00, 0x00, 0x0e, 0x00, 0x14, 0x00, 0x00, 0x00, + 0x0c, 0x00, 0x08, 0x00, 0x10, 0x00, 0x04, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x30, 0x00, 0x00, 0x00, 0x64, 0x01, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x1c, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x88, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x90, 0xff, 0xff, 0xff, 0x94, 0xff, 0xff, 0xff, + 0x01, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x18, 0x00, 0x14, 0x00, + 0x10, 0x00, 0x0c, 0x00, 0x08, 0x00, 0x04, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, + 0x1c, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x6c, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x14, 0x00, 0x00, 0x00, 0x10, 0x00, 0x0c, 0x00, + 0x07, 0x00, 0x08, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1d, 0x10, 0x00, 0x00, 0x00, + 0x10, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x04, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x74, 0x00, 0x00, 0x00, + 0x38, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xa4, 0xff, 0xff, 0xff, 0x0c, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x6f, 0x66, 0x6d, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x14, 0x00, + 0x10, 0x00, 0x0f, 0x00, 0x08, 0x00, 0x04, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x10, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x69, 0x66, 0x6d, 0x32, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x05, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x08, 0x00, 0x04, 0x00, + 0x0c, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x69, 0x66, 0x6d, 0x31, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x05, 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, + 0x2a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2a, 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 input_1_wrong_type_div + +namespace input_2_wrong_type_div +{ + +/* + * DIV Kernel with input type mismatch: + * + * Input_1(2, 5)- Float Input_2(2, 1) - Int32 + * \ / + * Div(with broadcast) + * | + * Output(2, 5) + */ +const unsigned char test_kernel_model_circle[] = { + 0x18, 0x00, 0x00, 0x00, 0x43, 0x49, 0x52, 0x30, 0x00, 0x00, 0x0e, 0x00, 0x14, 0x00, 0x00, 0x00, + 0x0c, 0x00, 0x08, 0x00, 0x10, 0x00, 0x04, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x30, 0x00, 0x00, 0x00, 0x64, 0x01, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x1c, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x88, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x90, 0xff, 0xff, 0xff, 0x94, 0xff, 0xff, 0xff, + 0x01, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x18, 0x00, 0x14, 0x00, + 0x10, 0x00, 0x0c, 0x00, 0x08, 0x00, 0x04, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, + 0x1c, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x6c, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x14, 0x00, 0x00, 0x00, 0x10, 0x00, 0x0c, 0x00, + 0x07, 0x00, 0x08, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1d, 0x10, 0x00, 0x00, 0x00, + 0x10, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x04, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x74, 0x00, 0x00, 0x00, + 0x38, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xa4, 0xff, 0xff, 0xff, 0x0c, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x6f, 0x66, 0x6d, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x14, 0x00, + 0x10, 0x00, 0x0f, 0x00, 0x08, 0x00, 0x04, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x10, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x69, 0x66, 0x6d, 0x32, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x05, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x08, 0x00, 0x04, 0x00, + 0x0c, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x69, 0x66, 0x6d, 0x31, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x05, 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, + 0x2a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2a, 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 input_2_wrong_type_div + +class NegTestDataInput1WrongTypeDiv : public NegTestDataBase +{ +public: + NegTestDataInput1WrongTypeDiv() + { + _test_kernel_model_circle = input_1_wrong_type_div::test_kernel_model_circle; + } + + ~NegTestDataInput1WrongTypeDiv() override = default; + + const unsigned char *get_model_ptr() override final { return _test_kernel_model_circle; } + +protected: + const unsigned char *_test_kernel_model_circle; +}; + +class NegTestDataInput2WrongTypeDiv : public NegTestDataBase +{ +public: + NegTestDataInput2WrongTypeDiv() + { + _test_kernel_model_circle = input_2_wrong_type_div::test_kernel_model_circle; + } + + ~NegTestDataInput2WrongTypeDiv() 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_DIV_KERNEL_H diff --git a/onert-micro/onert-micro/include/test_models/div/TestDataDivBase.h b/onert-micro/onert-micro/include/test_models/div/TestDataDivBase.h new file mode 100644 index 00000000000..785a37d780c --- /dev/null +++ b/onert-micro/onert-micro/include/test_models/div/TestDataDivBase.h @@ -0,0 +1,68 @@ +/* + * 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_DIV_KERNEL_BASE_H +#define ONERT_MICRO_TEST_MODELS_DIV_KERNEL_BASE_H + +#include "test_models/TestDataBase.h" + +namespace onert_micro +{ +namespace test_model +{ + +template class TestDataDivBase : public TestDataBase +{ +public: + explicit TestDataDivBase(bool) + { + // Do nothing + } + + TestDataDivBase() = delete; + + const unsigned char *get_model_ptr() override final { return _test_kernel_model_circle; } + + const std::vector &get_input_data_by_index(int i) override final + { + switch (i) + { + case 0: + return _input1_data; + case 1: + return _input2_data; + default: + assert(false && "Wrong input index"); + } + } + + const std::vector &get_output_data_by_index(int i) override final + { + assert(i == 0); + return _reference_output_data; + } + +protected: + std::vector _input1_data; + std::vector _input2_data; + std::vector _reference_output_data; + const unsigned char *_test_kernel_model_circle; +}; + +} // namespace test_model +} // namespace onert_micro + +#endif // ONERT_MICRO_TEST_MODELS_DIV_KERNEL_BASE_H diff --git a/onert-micro/onert-micro/src/execute/kernels/Div.cpp b/onert-micro/onert-micro/src/execute/kernels/Div.cpp new file mode 100644 index 00000000000..03958782a66 --- /dev/null +++ b/onert-micro/onert-micro/src/execute/kernels/Div.cpp @@ -0,0 +1,166 @@ +/* + * 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/OMUtils.h" +#include "execute/OMKernelExecutionBuilder.h" +#include "OMStatus.h" +#include "execute/OMRuntimeKernel.h" +#include "core/OMUtils.h" + +#include "core/OMRuntimeShape.h" +#include "PALDiv.h" + +using namespace onert_micro; +using namespace onert_micro::execute; + +namespace +{ + +constexpr uint32_t input1TensorIdx = 0; +constexpr uint32_t input2TensorIdx = 1; +constexpr uint32_t outputTensorIdx = 0; + +} // namespace + +// NOTE: doesnt currently support dynamic shapes +// TODO: reduce code duplication with Add, Sub +OMStatus onert_micro::execute::execute_kernel_CircleDiv(const OMExecuteArgs &execute_args) +{ + core::OMRuntimeContext &runtime_context = execute_args.runtime_context; + core::OMRuntimeStorage &runtime_storage = execute_args.runtime_storage; + uint16_t op_index = execute_args.kernel_index; + + const circle::Tensor *input1; + const circle::Tensor *input2; + const circle::Tensor *output; + + uint8_t *input1_data; + uint8_t *input2_data; + uint8_t *output_data; + + const circle::DivOptions *options; + // Read kernel + { + execute::OMRuntimeKernel runtime_kernel; + runtime_kernel.readKernel(op_index, runtime_context); + + input1 = runtime_kernel.inputs[input1TensorIdx]; + input2 = runtime_kernel.inputs[input2TensorIdx]; + output = runtime_kernel.outputs[outputTensorIdx]; + assert(input1 != nullptr); + assert(input2 != nullptr); + assert(output != nullptr); + + runtime_kernel.getDataFromStorage(op_index, runtime_storage, runtime_context); + + input1_data = runtime_kernel.inputs_data[input1TensorIdx]; + input2_data = runtime_kernel.inputs_data[input2TensorIdx]; + output_data = runtime_kernel.outputs_data[outputTensorIdx]; + assert(input1_data != nullptr); + assert(input2_data != nullptr); + assert(output_data != nullptr); + + options = runtime_kernel.first_operator->builtin_options_as_DivOptions(); + } + + OMStatus status; + + core::OMRuntimeShape input1_shape(input1); + core::OMRuntimeShape input2_shape(input2); + core::OMRuntimeShape output_shape(output); + + core::BinaryArithmeticBroadcastParams params{}; + const bool need_broadcast = pal::processBroadcastShapes(input1_shape, input2_shape, ¶ms); + + switch (input1->type()) + { +#ifndef DIS_FLOAT + case circle::TensorType_FLOAT32: + { + status = execute::calculateActivationRange(options->fused_activation_function(), + ¶ms.float_activation_min, + ¶ms.float_activation_max); + + if (need_broadcast) + { + status = pal::BroadcastDiv4DSlow( + params, input1_shape, core::utils::castInputData(input1_data), input2_shape, + core::utils::castInputData(input2_data), output_shape, + core::utils::castOutputData(output_data)); + } + else + { + status = + pal::Div(params, input1_shape.flatSize(), core::utils::castInputData(input1_data), + core::utils::castInputData(input2_data), + core::utils::castOutputData(output_data)); + } + } + break; +#endif // DIS_FLOAT + case circle::TensorType_INT64: + { + status = execute::calculateActivationRange(options->fused_activation_function(), + ¶ms.int64_activation_min, + ¶ms.int64_activation_max); + + if (need_broadcast) + { + status = pal::BroadcastDiv4DSlow( + params, input1_shape, core::utils::castInputData(input1_data), input2_shape, + core::utils::castInputData(input2_data), output_shape, + core::utils::castOutputData(output_data)); + } + else + { + status = pal::Div(params, input1_shape.flatSize(), + core::utils::castInputData(input1_data), + core::utils::castInputData(input2_data), + core::utils::castOutputData(output_data)); + } + } + break; + case circle::TensorType_INT32: + { + status = execute::calculateActivationRange(options->fused_activation_function(), + ¶ms.int32_activation_min, + ¶ms.int32_activation_max); + + if (need_broadcast) + { + status = pal::BroadcastDiv4DSlow( + params, input1_shape, core::utils::castInputData(input1_data), input2_shape, + core::utils::castInputData(input2_data), output_shape, + core::utils::castOutputData(output_data)); + } + else + { + status = pal::Div(params, input1_shape.flatSize(), + core::utils::castInputData(input1_data), + core::utils::castInputData(input2_data), + core::utils::castOutputData(output_data)); + } + } + break; + default: + { + status = UnsupportedType; + assert(false && "Unsupported type."); + } + } + + return status; +} diff --git a/onert-micro/onert-micro/src/execute/kernels/tests/Div.test.cpp b/onert-micro/onert-micro/src/execute/kernels/tests/Div.test.cpp new file mode 100644 index 00000000000..3f3465ec862 --- /dev/null +++ b/onert-micro/onert-micro/src/execute/kernels/tests/Div.test.cpp @@ -0,0 +1,116 @@ +/* + * 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/div/FloatDivKernel.h" +#include "test_models/div/NegDivKernel.h" +#include "test_models/div/IntDivKernel.h" + +namespace onert_micro +{ +namespace execute +{ +namespace testing +{ + +using namespace testing; + +class DivTest : public ::testing::Test +{ + // Do nothing +}; + +TEST_F(DivTest, INT64_P) +{ + // No broadcast + { + const bool is_with_broadcast = false; + test_model::TestDataInt64Div test_data_add_no_broadcasting(is_with_broadcast); + std::vector output_data_vector = + onert_micro::execute::testing::checkKernel(2, &test_data_add_no_broadcasting); + EXPECT_THAT(output_data_vector, test_data_add_no_broadcasting.get_output_data_by_index(0)); + } + // With broadcast + { + const bool is_with_broadcast = true; + test_model::TestDataInt64Div test_data_add_with_broadcasting(is_with_broadcast); + std::vector output_data_vector = + onert_micro::execute::testing::checkKernel(2, &test_data_add_with_broadcasting); + EXPECT_THAT(output_data_vector, test_data_add_with_broadcasting.get_output_data_by_index(0)); + } +} + +TEST_F(DivTest, INT_P) +{ + // No broadcast + { + const bool is_with_broadcast = false; + test_model::TestDataIntDiv test_data_add_no_broadcasting(is_with_broadcast); + std::vector output_data_vector = + onert_micro::execute::testing::checkKernel(2, &test_data_add_no_broadcasting); + EXPECT_THAT(output_data_vector, test_data_add_no_broadcasting.get_output_data_by_index(0)); + } + // With broadcast + { + const bool is_with_broadcast = true; + test_model::TestDataIntDiv test_data_add_with_broadcasting(is_with_broadcast); + std::vector output_data_vector = + onert_micro::execute::testing::checkKernel(2, &test_data_add_with_broadcasting); + EXPECT_THAT(output_data_vector, test_data_add_with_broadcasting.get_output_data_by_index(0)); + } +} + +TEST_F(DivTest, Float_P) +{ + // No broadcast + { + const bool is_with_broadcast = false; + test_model::TestDataFloatDiv test_data_float_add_no_broadcasting(is_with_broadcast); + std::vector output_data_vector = + onert_micro::execute::testing::checkKernel(2, &test_data_float_add_no_broadcasting); + EXPECT_THAT( + output_data_vector, + FloatArrayNear(test_data_float_add_no_broadcasting.get_output_data_by_index(0), 0.0001f)); + } + // With broadcast + { + const bool is_with_broadcast = true; + test_model::TestDataFloatDiv test_data_float_add_with_broadcasting(is_with_broadcast); + std::vector output_data_vector = + onert_micro::execute::testing::checkKernel(2, &test_data_float_add_with_broadcasting); + EXPECT_THAT( + output_data_vector, + FloatArrayNear(test_data_float_add_with_broadcasting.get_output_data_by_index(0), 0.0001f)); + } +} + +TEST_F(DivTest, Wrong_Input1_Type_NEG) +{ + onert_micro::test_model::NegTestDataInput1WrongTypeDiv test_data_kernel; + + EXPECT_DEATH(checkNEGSISOKernel(&test_data_kernel), ""); +} + +TEST_F(DivTest, Wrong_Input2_Type_NEG) +{ + onert_micro::test_model::NegTestDataInput2WrongTypeDiv 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/helpers/OMConfigureTISOKernel.cpp b/onert-micro/onert-micro/src/import/helpers/OMConfigureTISOKernel.cpp index 5f58382b4c4..93e7210bd78 100644 --- a/onert-micro/onert-micro/src/import/helpers/OMConfigureTISOKernel.cpp +++ b/onert-micro/onert-micro/src/import/helpers/OMConfigureTISOKernel.cpp @@ -68,12 +68,31 @@ OMStatus onert_micro::import::helpers::configure_TISO_kernel(const OMConfigureAr return NoQuantization; } - if (input1->quantization()->scale()->size() != 1 or - input2->quantization()->scale()->size() != 1 or output->quantization()->scale()->size() != 1) + if (input1->quantization()->scale() == nullptr or + input1->quantization()->zero_point() == nullptr or + input1->quantization()->scale()->size() != 1 or + input1->quantization()->zero_point()->size() != 1) { - return UnsupportedQuantizationType; + return NoQuantization; + } + + if (input2->quantization()->scale() == nullptr or + input2->quantization()->zero_point() == nullptr or + input2->quantization()->scale()->size() != 1 or + input2->quantization()->zero_point()->size() != 1) + { + return NoQuantization; + } + + if (output->quantization()->scale() == nullptr or + output->quantization()->zero_point() == nullptr or + output->quantization()->scale()->size() != 1 or + output->quantization()->zero_point()->size() != 1) + { + return NoQuantization; } #endif // DIS_QUANT + return status; } diff --git a/onert-micro/onert-micro/src/import/kernels/Add.cpp b/onert-micro/onert-micro/src/import/kernels/Add.cpp index 52ee337a788..90bd876d193 100644 --- a/onert-micro/onert-micro/src/import/kernels/Add.cpp +++ b/onert-micro/onert-micro/src/import/kernels/Add.cpp @@ -14,84 +14,12 @@ * limitations under the License. */ -#include "import/OMKernelConfigureBuilder.h" -#include "core/OMUtils.h" -#include "OMStatus.h" -#include "execute/OMRuntimeKernel.h" +#include "import/helpers/OMConfigureTISOKernel.h" using namespace onert_micro; using namespace onert_micro::core; -namespace -{ - -constexpr uint32_t input1TensorIdx = 0; -constexpr uint32_t input2TensorIdx = 1; -constexpr uint32_t outputTensorIdx = 0; - -} // namespace - -// TODO: reduce code duplication with Mul, Sub OMStatus onert_micro::import::configure_kernel_CircleAdd(const OMConfigureArgs &config_args) { - 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; - - const circle::Tensor *input1 = runtime_kernel.inputs[input1TensorIdx]; - const circle::Tensor *input2 = runtime_kernel.inputs[input2TensorIdx]; - const circle::Tensor *output = runtime_kernel.outputs[outputTensorIdx]; - - assert(input1 != nullptr); - assert(input2 != nullptr); - assert(output != nullptr); - - status = utils::checkCondition(input1->type() == output->type()); - if (status != Ok) - return status; - - status = utils::checkCondition(input2->type() == output->type()); - if (status != Ok) - return status; - - if (input1->type() != circle::TensorType_INT8 and input1->type() != circle::TensorType_INT16) - return status; - - // Check quantization params - if (input1->quantization() == nullptr or input2->quantization() == nullptr or - output->quantization() == nullptr) - { - return NoQuantization; - } - - if (input1->quantization()->scale() == nullptr or - input1->quantization()->zero_point() == nullptr or - input1->quantization()->scale()->size() != 1 or - input1->quantization()->zero_point()->size() != 1) - { - return NoQuantization; - } - - if (input2->quantization()->scale() == nullptr or - input2->quantization()->zero_point() == nullptr or - input2->quantization()->scale()->size() != 1 or - input2->quantization()->zero_point()->size() != 1) - { - return NoQuantization; - } - - if (output->quantization()->scale() == nullptr or - output->quantization()->zero_point() == nullptr or - output->quantization()->scale()->size() != 1 or - output->quantization()->zero_point()->size() != 1) - { - return NoQuantization; - } - - return status; + return import::helpers::configure_TISO_kernel(config_args); } diff --git a/onert-micro/onert-micro/src/import/kernels/Div.cpp b/onert-micro/onert-micro/src/import/kernels/Div.cpp new file mode 100644 index 00000000000..0ce01663200 --- /dev/null +++ b/onert-micro/onert-micro/src/import/kernels/Div.cpp @@ -0,0 +1,25 @@ +/* + * 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/helpers/OMConfigureTISOKernel.h" + +using namespace onert_micro; +using namespace onert_micro::core; + +OMStatus onert_micro::import::configure_kernel_CircleDiv(const OMConfigureArgs &config_args) +{ + return import::helpers::configure_TISO_kernel(config_args); +} diff --git a/onert-micro/onert-micro/src/import/kernels/Mul.cpp b/onert-micro/onert-micro/src/import/kernels/Mul.cpp index b40259afd07..8eb35d01a49 100644 --- a/onert-micro/onert-micro/src/import/kernels/Mul.cpp +++ b/onert-micro/onert-micro/src/import/kernels/Mul.cpp @@ -14,89 +14,12 @@ * limitations under the License. */ -#include "OMStatus.h" - -#include "core/OMUtils.h" -#include "import/OMKernelConfigureBuilder.h" -#include "execute/OMRuntimeKernel.h" +#include "import/helpers/OMConfigureTISOKernel.h" using namespace onert_micro; using namespace onert_micro::core; -namespace -{ - -constexpr uint32_t input1TensorIdx = 0; -constexpr uint32_t input2TensorIdx = 1; -constexpr uint32_t outputTensorIdx = 0; - -} // namespace - -// TODO: reduce code duplication with Add, Sub OMStatus onert_micro::import::configure_kernel_CircleMul(const OMConfigureArgs &config_args) { - 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; - - const circle::Tensor *input1 = runtime_kernel.inputs[input1TensorIdx]; - const circle::Tensor *input2 = runtime_kernel.inputs[input2TensorIdx]; - const circle::Tensor *output = runtime_kernel.outputs[outputTensorIdx]; - - assert(input1 != nullptr); - assert(input2 != nullptr); - assert(output != nullptr); - - status = utils::checkCondition(input1->type() == output->type()); - if (status != Ok) - return status; - - status = utils::checkCondition(input2->type() == output->type()); - if (status != Ok) - return status; - - if (input1->type() != circle::TensorType_INT8 and input1->type() != circle::TensorType_INT16) - return status; - -#ifndef DIS_QUANT - - // Check quantization params - if (input1->quantization() == nullptr or input2->quantization() == nullptr or - output->quantization() == nullptr) - { - return NoQuantization; - } - - if (input1->quantization()->scale() == nullptr or - input1->quantization()->zero_point() == nullptr or - input1->quantization()->scale()->size() != 1 or - input1->quantization()->zero_point()->size() != 1) - { - return NoQuantization; - } - - if (input2->quantization()->scale() == nullptr or - input2->quantization()->zero_point() == nullptr or - input2->quantization()->scale()->size() != 1 or - input2->quantization()->zero_point()->size() != 1) - { - return NoQuantization; - } - - if (output->quantization()->scale() == nullptr or - output->quantization()->zero_point() == nullptr or - output->quantization()->scale()->size() != 1 or - output->quantization()->zero_point()->size() != 1) - { - return NoQuantization; - } - -#endif // DIS_QUANT - - return status; + return import::helpers::configure_TISO_kernel(config_args); } diff --git a/onert-micro/onert-micro/src/import/kernels/Sub.cpp b/onert-micro/onert-micro/src/import/kernels/Sub.cpp index 39076daf3e7..a21201f0d1d 100644 --- a/onert-micro/onert-micro/src/import/kernels/Sub.cpp +++ b/onert-micro/onert-micro/src/import/kernels/Sub.cpp @@ -14,71 +14,12 @@ * limitations under the License. */ -#include "OMStatus.h" - -#include "core/OMUtils.h" -#include "import/OMKernelConfigureBuilder.h" -#include "execute/OMRuntimeKernel.h" +#include "import/helpers/OMConfigureTISOKernel.h" using namespace onert_micro; using namespace onert_micro::core; -namespace -{ - -constexpr uint32_t input1TensorIdx = 0; -constexpr uint32_t input2TensorIdx = 1; -constexpr uint32_t outputTensorIdx = 0; - -} // namespace - -// TODO: reduce code duplication with Add, Mul OMStatus onert_micro::import::configure_kernel_CircleSub(const OMConfigureArgs &config_args) { - 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; - - const circle::Tensor *input1 = runtime_kernel.inputs[input1TensorIdx]; - const circle::Tensor *input2 = runtime_kernel.inputs[input2TensorIdx]; - const circle::Tensor *output = runtime_kernel.outputs[outputTensorIdx]; - - assert(input1 != nullptr); - assert(input2 != nullptr); - assert(output != nullptr); - - status = utils::checkCondition(input1->type() == output->type()); - if (status != Ok) - return status; - - status = utils::checkCondition(input2->type() == output->type()); - if (status != Ok) - return status; - - if (input1->type() != circle::TensorType_INT8 and input1->type() != circle::TensorType_INT16) - return status; - -#ifndef DIS_QUANT - - // Check quantization params - if (input1->quantization() == nullptr or input2->quantization() == nullptr or - output->quantization() == nullptr) - { - return NoQuantization; - } - - if (input1->quantization()->scale()->size() != 1 or - input2->quantization()->scale()->size() != 1 or output->quantization()->scale()->size() != 1) - { - return UnsupportedQuantizationType; - } - -#endif // DIS_QUANT - - return status; + return import::helpers::configure_TISO_kernel(config_args); }