diff --git a/onert-micro/luci-interpreter/include/luci_interpreter/test_models/equal/FloatEqualKernel.h b/onert-micro/luci-interpreter/include/luci_interpreter/test_models/equal/FloatEqualKernel.h new file mode 100644 index 00000000000..1fce14f473e --- /dev/null +++ b/onert-micro/luci-interpreter/include/luci_interpreter/test_models/equal/FloatEqualKernel.h @@ -0,0 +1,281 @@ +/* + * 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_EQUAL_KERNEL_FLOAT_H +#define LUCI_INTERPRETER_TEST_MODELS_EQUAL_KERNEL_FLOAT_H + +#include "TestDataEqualBase.h" + +namespace luci_interpreter +{ +namespace test_kernel +{ + +namespace neg_equal_float_with_no_broadcasting +{ + +/* + * Equal Kernel with input type mismatch + * + * Input_1(1, 4, 4, 3)-Float32 Input_2(1, 4, 4, 3)-Int32 + * \ / + * Equal(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, 0x80, 0x01, 0x00, 0x00, 0x9c, 0x01, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x1c, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x88, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x90, 0xff, 0xff, 0xff, 0x94, 0xff, 0xff, 0xff, + 0x01, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x18, 0x00, 0x14, 0x00, + 0x10, 0x00, 0x0c, 0x00, 0x08, 0x00, 0x04, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, + 0x1c, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x6c, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x14, 0x00, 0x00, 0x00, 0x10, 0x00, 0x0c, 0x00, + 0x07, 0x00, 0x08, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x35, 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, 0x88, 0x00, 0x00, 0x00, + 0x44, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xd0, 0xff, 0xff, 0xff, 0x10, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x0c, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x6f, 0x66, 0x6d, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x0c, 0x00, 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, 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, 0x47, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x47, 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 = {}; + +const std::vector input2_data = {}; + +const std::vector reference_output_data = {}; + +} // namespace neg_equal_float_with_no_broadcasting + +namespace equal_float_with_no_broadcasting +{ + +/* + * Equal Kernel: + * + * Input_1(2, 5) Input_2(2, 5) + * \ / + * Equal(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, 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, 0x35, 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, + 0x3c, 0x00, 0x00, 0x00, 0x10, 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, 0x06, 0x0c, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x6f, 0x66, 0x6d, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0xd8, 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, 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, + 0x47, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 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.0, 33.11, -1.1, 0.0, 5.5, -2.0, 0.0, -1.0, -4.5, 1.1}; + +const std::vector input2_data = {0.0, 33.11, 1.2, 0.0, 5.5, -2.0, 0.01, -1.0, -4.5, 1.12}; + +const std::vector reference_output_data = {true, true, false, true, true, + true, false, true, true, false}; + +} // namespace equal_float_with_no_broadcasting + +namespace equal_float_with_broadcasting +{ + +/* + * Equal Kernel: + * + * Input_1(2, 5) Input_2(1, 5) + * \ / + * Equal(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, 0x35, 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, + 0x3c, 0x00, 0x00, 0x00, 0x10, 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, 0x06, 0x0c, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x6f, 0x66, 0x6d, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0xd8, 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, 0x02, 0x00, 0x00, 0x00, 0x01, 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, + 0x47, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 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.0, 0.0, -0.0, 0.0, 0.0, -0.0, 0.0, -0.0, -0.0, 0.0}; + +const std::vector input2_data = {0.0, -0.0, -0.0, 0.0, -0.0}; + +const std::vector reference_output_data = {true, true, true, true, true, + true, true, true, true, true}; + +} // namespace equal_float_with_broadcasting + +namespace neg_equal_float_with_broadcasting +{ + +/* + * Equal Kernel with input type mismatch: + * + * Input_1(2, 5)-float Input_2(1, 5)-Int32 + * \ / + * Equal(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, 0x68, 0x01, 0x00, 0x00, 0x84, 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, 0x35, 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, 0x78, 0x00, 0x00, 0x00, + 0x3c, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xd8, 0xff, 0xff, 0xff, 0x10, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x0c, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x6f, 0x66, 0x6d, 0x00, 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, + 0x01, 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, 0x47, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 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 = {}; + +const std::vector input2_data = {}; + +const std::vector reference_output_data = {}; + +} // namespace neg_equal_float_with_broadcasting + +class TestDataFloatEqual : public TestDataEqualBase +{ +public: + explicit TestDataFloatEqual(bool is_with_broadcast, bool is_neg) + : TestDataEqualBase(is_with_broadcast) + { + if (not is_with_broadcast) + { + if (is_neg) + { + _input1_data = neg_equal_float_with_no_broadcasting::input1_data; + _input2_data = neg_equal_float_with_no_broadcasting::input2_data; + _reference_output_data = neg_equal_float_with_no_broadcasting::reference_output_data; + _test_kernel_model_circle = neg_equal_float_with_no_broadcasting::test_kernel_model_circle; + } + else + { + _input1_data = equal_float_with_no_broadcasting::input1_data; + _input2_data = equal_float_with_no_broadcasting::input2_data; + _reference_output_data = equal_float_with_no_broadcasting::reference_output_data; + _test_kernel_model_circle = equal_float_with_no_broadcasting::test_kernel_model_circle; + } + } + else + { + if (is_neg) + { + _input1_data = neg_equal_float_with_broadcasting::input1_data; + _input2_data = neg_equal_float_with_broadcasting::input2_data; + _reference_output_data = neg_equal_float_with_broadcasting::reference_output_data; + _test_kernel_model_circle = neg_equal_float_with_broadcasting::test_kernel_model_circle; + } + else + { + _input1_data = equal_float_with_broadcasting::input1_data; + _input2_data = equal_float_with_broadcasting::input2_data; + _reference_output_data = equal_float_with_broadcasting::reference_output_data; + _test_kernel_model_circle = equal_float_with_broadcasting::test_kernel_model_circle; + } + } + } + + ~TestDataFloatEqual() override = default; +}; + +} // namespace test_kernel +} // namespace luci_interpreter + +#endif // LUCI_INTERPRETER_TEST_MODELS_EQUAL_KERNEL_FLOAT_H diff --git a/onert-micro/luci-interpreter/include/luci_interpreter/test_models/equal/IntEqualKernel.h b/onert-micro/luci-interpreter/include/luci_interpreter/test_models/equal/IntEqualKernel.h new file mode 100644 index 00000000000..964ad6dc2f9 --- /dev/null +++ b/onert-micro/luci-interpreter/include/luci_interpreter/test_models/equal/IntEqualKernel.h @@ -0,0 +1,278 @@ +/* + * 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_EQUAL_KERNEL_INT_H +#define LUCI_INTERPRETER_TEST_MODELS_EQUAL_KERNEL_INT_H + +#include "TestDataEqualBase.h" + +namespace luci_interpreter +{ +namespace test_kernel +{ +namespace equal_int_with_no_broadcasting +{ + +/* + * Equal Kernel: + * + * Input_1(1, 5) Input_2(1, 5) + * \ / + * Equal(no broadcast) + * | + * Output(1, 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, 0x35, 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, 0x06, 0x0c, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x6f, 0x66, 0x6d, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 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, 0x01, 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, 0x01, 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, 0x47, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x47, 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 = {22, 31, 14, 5, 3}; + +const std::vector input2_data = {3, 14, 14, 5, 5}; + +const std::vector reference_output_data = {false, false, true, true, false}; + +} // namespace equal_int_with_no_broadcasting + +namespace neg_equal_int_with_no_broadcasting +{ + +/* + * Equal Kernel with input type mismatch: + * + * Input_1(1, 5)-int Input_2(1, 5)-float + * \ / + * Equal(no broadcast) + * | + * Output(1, 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, 0x68, 0x01, 0x00, 0x00, 0x84, 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, 0x35, 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, + 0x3c, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xa4, 0xff, 0xff, 0xff, 0x10, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x0c, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x6f, 0x66, 0x6d, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 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, 0x02, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x69, 0x66, 0x6d, 0x32, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 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, 0x01, 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, 0x47, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 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 = {}; + +const std::vector input2_data = {}; + +const std::vector reference_output_data = {}; + +} // namespace neg_equal_int_with_no_broadcasting + +namespace equal_int_with_broadcasting +{ +/* + * Equal Kernel: + * + * Input_1(2, 5) Input_2(1, 5) + * \ / + * Equal(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, 0x35, 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, 0x06, 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, 0x01, 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, 0x47, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x47, 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 = {12, 0, 0, -12, 0, 0, 12, -12, 0, -12}; + +const std::vector input2_data = {0, 12, 0, 0, 0}; + +const std::vector reference_output_data = {false, false, true, false, true, + true, true, false, true, false}; + +} // namespace equal_int_with_broadcasting + +namespace neg_equal_int_with_broadcasting +{ + +/* + * Equal Kernel with input type mismatch: + * + * Input_1(2, 5) Input_2(1, 5) + * \ / + * Equal(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, 0x68, 0x01, 0x00, 0x00, 0x84, 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, 0x35, 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, + 0x3c, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xa4, 0xff, 0xff, 0xff, 0x10, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x0c, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x6f, 0x66, 0x6d, 0x00, 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, 0x02, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x69, 0x66, 0x6d, 0x32, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 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, 0x47, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 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 = {}; + +const std::vector input2_data = {}; + +const std::vector reference_output_data = {}; + +} // namespace neg_equal_int_with_broadcasting + +class TestDataIntEqual : public TestDataEqualBase +{ +public: + explicit TestDataIntEqual(bool is_with_broadcast, bool is_neg) + : TestDataEqualBase(is_with_broadcast) + { + if (is_with_broadcast) + { + if (is_neg) + { + _input1_data = neg_equal_int_with_broadcasting::input1_data; + _input2_data = neg_equal_int_with_broadcasting::input2_data; + _reference_output_data = neg_equal_int_with_broadcasting::reference_output_data; + _test_kernel_model_circle = neg_equal_int_with_broadcasting::test_kernel_model_circle; + } + else + { + _input1_data = equal_int_with_broadcasting::input1_data; + _input2_data = equal_int_with_broadcasting::input2_data; + _reference_output_data = equal_int_with_broadcasting::reference_output_data; + _test_kernel_model_circle = equal_int_with_broadcasting::test_kernel_model_circle; + } + } + else + { + if (is_neg) + { + _input1_data = neg_equal_int_with_no_broadcasting::input1_data; + _input2_data = neg_equal_int_with_no_broadcasting::input2_data; + _reference_output_data = neg_equal_int_with_no_broadcasting::reference_output_data; + _test_kernel_model_circle = neg_equal_int_with_no_broadcasting::test_kernel_model_circle; + } + else + { + _input1_data = equal_int_with_no_broadcasting::input1_data; + _input2_data = equal_int_with_no_broadcasting::input2_data; + _reference_output_data = equal_int_with_no_broadcasting::reference_output_data; + _test_kernel_model_circle = equal_int_with_no_broadcasting::test_kernel_model_circle; + } + } + } + + ~TestDataIntEqual() override = default; +}; + +} // namespace test_kernel +} // namespace luci_interpreter + +#endif // LUCI_INTERPRETER_TEST_MODELS_LESS_KERNEL_INT_H diff --git a/onert-micro/luci-interpreter/include/luci_interpreter/test_models/equal/TestDataEqualBase.h b/onert-micro/luci-interpreter/include/luci_interpreter/test_models/equal/TestDataEqualBase.h new file mode 100644 index 00000000000..c790f271dab --- /dev/null +++ b/onert-micro/luci-interpreter/include/luci_interpreter/test_models/equal/TestDataEqualBase.h @@ -0,0 +1,68 @@ +/* + * 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_EQUAL_KERNEL_BASE_H +#define LUCI_INTERPRETER_TEST_MODELS_EQUAL_KERNEL_BASE_H + +#include "luci_interpreter/test_models/TestDataBase.h" + +namespace luci_interpreter +{ +namespace test_kernel +{ + +template class TestDataEqualBase : public TestDataBase +{ +public: + explicit TestDataEqualBase(bool) + { + // Do nothing + } + + TestDataEqualBase() = 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_kernel +} // namespace luci_interpreter + +#endif // LUCI_INTERPRETER_TEST_MODELS_EQUAL_KERNEL_BASE_H diff --git a/onert-micro/luci-interpreter/include/luci_interpreter/test_models/greater/FloatGreaterKernel.h b/onert-micro/luci-interpreter/include/luci_interpreter/test_models/greater/FloatGreaterKernel.h new file mode 100644 index 00000000000..dcb7b6886b9 --- /dev/null +++ b/onert-micro/luci-interpreter/include/luci_interpreter/test_models/greater/FloatGreaterKernel.h @@ -0,0 +1,185 @@ +/* + * 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_GREATER_KERNEL_FLOAT_H +#define LUCI_INTERPRETER_TEST_MODELS_GREATER_KERNEL_FLOAT_H + +#include "TestDataGreaterBase.h" + +namespace luci_interpreter +{ +namespace test_kernel +{ +namespace greater_float +{ + +/* + * Greater Kernel: + * + * Input_1(1, 4, 4, 3) Input_2(1, 4, 4, 3) + * \ / + * Greater(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, 0x7c, 0x01, 0x00, 0x00, 0x98, 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, 0x2c, 0x10, 0x00, 0x00, 0x00, + 0x10, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x04, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x84, 0x00, 0x00, 0x00, + 0x44, 0x00, 0x00, 0x00, 0x10, 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, 0x06, 0x0c, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x6f, 0x66, 0x6d, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 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, 0x3d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3d, + 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.01787583, -0.8314556, -0.47624078, -1.9747407, -0.51676583, -0.20183715, -1.9358647, + 0.7616414, -0.0899037, 2.048367, -1.3174965, 1.5267943, 0.68707687, 1.3464743, + 0.98674047, -1.4853697, 1.9973947, 0.5170953, 0.37471953, -1.6011852, 0.32045737, + -0.6598305, -1.7946662, 1.2349467, 1.3320708, 0.5151753, 1.345111, -0.16560331, + 0.82792366, -1.734876, 0.043626763, -0.0118546495, 0.31535238, 0.1888555, -0.32523626, + -0.997665, 0.5819472, -2.3194845, -1.6897905, 0.9981752, -1.2897044, 0.75768864, + 0.56781554, -1.0565805, -1.4891449, 0.2493645, -1.1312587, 0.6837854}; + +const std::vector input2_data = { + 0.30809638, -0.28285328, -0.8437058, 1.7689779, 0.5182942, 0.571205, -0.89484423, + 0.28100377, 0.5453497, 1.3848042, -0.04359268, -1.7448778, -0.5375435, -0.85059136, + -0.77961826, -0.4916915, 1.3359088, -0.09580261, 0.6158275, -0.05056348, 0.90505254, + 0.94226706, 1.136139, -0.45077038, -0.5018571, -1.1543767, 0.85094684, -0.13731039, + -0.3298641, 0.9474698, -0.48497504, -0.14864737, -0.009302358, -1.1259161, 0.44226727, + 1.0149708, 0.36024934, 0.4969523, 0.45014778, -0.34718898, 1.2260172, 0.35304692, + -1.3037513, -0.2565706, 0.18085766, -0.7099202, -0.9203537, -1.2257448}; + +const std::vector reference_output_data = { + false, false, true, false, false, false, false, true, false, true, false, true, + true, true, true, false, true, true, false, false, false, false, false, true, + true, true, true, false, true, false, true, true, true, true, false, false, + true, false, false, true, false, true, true, false, false, true, false, true}; + +} // namespace greater_float + +namespace neg_greater_float_with_no_broadcasting +{ + +/* + * Greater Kernel with input type mismatch: + * + * Input_1(1, 4, 4, 3)-float Input_2(1, 4, 4, 3)-int + * \ / + * Greater(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, 0x80, 0x01, 0x00, 0x00, 0x9c, 0x01, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x1c, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x88, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x90, 0xff, 0xff, 0xff, 0x94, 0xff, 0xff, 0xff, + 0x01, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x18, 0x00, 0x14, 0x00, + 0x10, 0x00, 0x0c, 0x00, 0x08, 0x00, 0x04, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, + 0x1c, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x6c, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x14, 0x00, 0x00, 0x00, 0x10, 0x00, 0x0c, 0x00, + 0x07, 0x00, 0x08, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2c, 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, 0x88, 0x00, 0x00, 0x00, + 0x44, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xd0, 0xff, 0xff, 0xff, 0x10, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x0c, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x6f, 0x66, 0x6d, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x0c, 0x00, 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, 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, 0x3d, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x3d, 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 = {}; + +const std::vector input2_data = {}; + +const std::vector reference_output_data = {}; + +} // namespace neg_greater_float_with_no_broadcasting + +class TestDataFloatGreater : public TestDataGreaterBase +{ +public: + explicit TestDataFloatGreater(bool is_with_broadcast, bool is_neg) + : TestDataGreaterBase(is_with_broadcast) + { + if (is_with_broadcast) + { + assert(false && "Not impl yet"); + } + else + { + if (is_neg) + { + _input1_data = neg_greater_float_with_no_broadcasting::input1_data; + _input2_data = neg_greater_float_with_no_broadcasting::input2_data; + _reference_output_data = neg_greater_float_with_no_broadcasting::reference_output_data; + _test_kernel_model_circle = + neg_greater_float_with_no_broadcasting::test_kernel_model_circle; + } + else + { + _input1_data = greater_float::input1_data; + _input2_data = greater_float::input2_data; + _reference_output_data = greater_float::reference_output_data; + _test_kernel_model_circle = greater_float::test_kernel_model_circle; + } + } + } + + ~TestDataFloatGreater() override = default; +}; + +} // namespace test_kernel +} // namespace luci_interpreter + +#endif // LUCI_INTERPRETER_TEST_MODELS_GREATER_KERNEL_FLOAT_H diff --git a/onert-micro/luci-interpreter/include/luci_interpreter/test_models/greater/TestDataGreaterBase.h b/onert-micro/luci-interpreter/include/luci_interpreter/test_models/greater/TestDataGreaterBase.h new file mode 100644 index 00000000000..7c2005a640d --- /dev/null +++ b/onert-micro/luci-interpreter/include/luci_interpreter/test_models/greater/TestDataGreaterBase.h @@ -0,0 +1,68 @@ +/* + * 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_GREATER_KERNEL_BASE_H +#define LUCI_INTERPRETER_TEST_MODELS_GREATER_KERNEL_BASE_H + +#include "luci_interpreter/test_models/TestDataBase.h" + +namespace luci_interpreter +{ +namespace test_kernel +{ + +template class TestDataGreaterBase : public TestDataBase +{ +public: + explicit TestDataGreaterBase(bool) + { + // Do nothing + } + + TestDataGreaterBase() = 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_kernel +} // namespace luci_interpreter + +#endif // LUCI_INTERPRETER_TEST_MODELS_GREATER_KERNEL_BASE_H diff --git a/onert-micro/luci-interpreter/include/luci_interpreter/test_models/greater_equal/FloatGreaterEqualKernel.h b/onert-micro/luci-interpreter/include/luci_interpreter/test_models/greater_equal/FloatGreaterEqualKernel.h new file mode 100644 index 00000000000..14226ab40e7 --- /dev/null +++ b/onert-micro/luci-interpreter/include/luci_interpreter/test_models/greater_equal/FloatGreaterEqualKernel.h @@ -0,0 +1,158 @@ +/* + * 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_GREATER_EQUAL_KERNEL_FLOAT_H +#define LUCI_INTERPRETER_TEST_MODELS_GREATER_EQUAL_KERNEL_FLOAT_H + +#include "TestDataGreaterEqualBase.h" + +namespace luci_interpreter +{ +namespace test_kernel +{ +namespace greater_equal_float +{ + +/* + * GreaterEqual Kernel: + * + * Input_1(1, 4, 4, 3) Input_2(1, 4, 4, 3) + * \ / + * GreaterEqual(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, 0x7c, 0x01, 0x00, 0x00, 0x98, 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, 0x2d, 0x10, 0x00, 0x00, 0x00, + 0x10, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x04, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x84, 0x00, 0x00, 0x00, + 0x44, 0x00, 0x00, 0x00, 0x10, 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, 0x06, 0x0c, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x6f, 0x66, 0x6d, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 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, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, + 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.01787583, -0.8314556, -0.47624078, -1.9747407, -0.51676583, -0.20183715, -1.9358647, + 0.7616414, -0.0899037, 2.048367, -1.3174965, 1.5267943, 0.68707687, 1.3464743, + 0.98674047, -1.4853697, 1.9973947, 0.5170953, 0.37471953, -1.6011852, 0.32045737, + -0.6598305, -1.7946662, 1.2349467, 1.3320708, 0.5151753, 1.345111, -0.16560331, + 0.82792366, -1.734876, 0.043626763, -0.0118546495, 0.31535238, 0.1888555, -0.32523626, + -0.997665, 0.5819472, -2.3194845, -1.6897905, 0.9981752, -1.2897044, 0.75768864, + 0.56781554, -1.0565805, -1.4891449, 0.2493645, -1.1312587, 0.6837854}; + +const std::vector input2_data = { + 0.30809638, -0.28285328, -0.8437058, 1.7689779, 0.5182942, 0.571205, -0.89484423, + 0.28100377, 0.5453497, 1.3848042, -0.04359268, -1.7448778, -0.5375435, -0.85059136, + -0.77961826, -0.4916915, 1.3359088, -0.09580261, 0.6158275, -0.05056348, 0.90505254, + 0.94226706, 1.136139, -0.45077038, -0.5018571, -1.1543767, 0.85094684, -0.13731039, + -0.3298641, 0.9474698, -0.48497504, -0.14864737, -0.009302358, -1.1259161, 0.44226727, + 1.0149708, 0.36024934, 0.4969523, 0.45014778, -0.34718898, 1.2260172, 0.35304692, + -1.3037513, -0.2565706, 0.18085766, -0.7099202, -0.9203537, -1.2257448}; + +const std::vector reference_output_data = { + false, false, true, false, false, false, false, true, false, true, false, true, + true, true, true, false, true, true, false, false, false, false, false, true, + true, true, true, false, true, false, true, true, true, true, false, false, + true, false, false, true, false, true, true, false, false, true, false, true}; + +} // namespace greater_equal_float + +namespace neg_greater_equal_float_with_no_broadcasting +{ + +/* + * GreaterEqual Kernel with input type mismatch: + * + * Input_1(1, 4, 4, 3)-float Input_2(1, 4, 4, 3)-int + * \ / + * GreaterEqual(no broadcast) + * | + * Output(1, 4, 4, 3) + */ + +const unsigned char test_kernel_model_circle[] = { + +}; + +const std::vector input1_data = {}; + +const std::vector input2_data = {}; + +const std::vector reference_output_data = {}; + +} // namespace neg_greater_equal_float_with_no_broadcasting + +class TestDataFloatGreaterEqual : public TestDataGreaterEqualBase +{ +public: + explicit TestDataFloatGreaterEqual(bool is_with_broadcast, bool is_neg) + : TestDataGreaterEqualBase(is_with_broadcast) + { + if (is_with_broadcast) + { + assert(false && "Not impl yet"); + } + else + { + if (is_neg) + { + _input1_data = neg_greater_equal_float_with_no_broadcasting::input1_data; + _input2_data = neg_greater_equal_float_with_no_broadcasting::input2_data; + _reference_output_data = + neg_greater_equal_float_with_no_broadcasting::reference_output_data; + _test_kernel_model_circle = + neg_greater_equal_float_with_no_broadcasting::test_kernel_model_circle; + } + else + { + _input1_data = greater_equal_float::input1_data; + _input2_data = greater_equal_float::input2_data; + _reference_output_data = greater_equal_float::reference_output_data; + _test_kernel_model_circle = greater_equal_float::test_kernel_model_circle; + } + } + } + + ~TestDataFloatGreaterEqual() override = default; +}; + +} // namespace test_kernel +} // namespace luci_interpreter + +#endif // LUCI_INTERPRETER_TEST_MODELS_GREATER_KERNEL_FLOAT_H diff --git a/onert-micro/luci-interpreter/include/luci_interpreter/test_models/greater_equal/TestDataGreaterEqualBase.h b/onert-micro/luci-interpreter/include/luci_interpreter/test_models/greater_equal/TestDataGreaterEqualBase.h new file mode 100644 index 00000000000..9153c357ab5 --- /dev/null +++ b/onert-micro/luci-interpreter/include/luci_interpreter/test_models/greater_equal/TestDataGreaterEqualBase.h @@ -0,0 +1,68 @@ +/* + * 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_GREATER_EQUAL_KERNEL_BASE_H +#define LUCI_INTERPRETER_TEST_MODELS_GREATER_EQUAL_KERNEL_BASE_H + +#include "luci_interpreter/test_models/TestDataBase.h" + +namespace luci_interpreter +{ +namespace test_kernel +{ + +template class TestDataGreaterEqualBase : public TestDataBase +{ +public: + explicit TestDataGreaterEqualBase(bool) + { + // Do nothing + } + + TestDataGreaterEqualBase() = 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_kernel +} // namespace luci_interpreter + +#endif // LUCI_INTERPRETER_TEST_MODELS_GREATER_EQUAL_KERNEL_BASE_H diff --git a/onert-micro/luci-interpreter/include/luci_interpreter/test_models/less_equal/FloatLessEqualKernel.h b/onert-micro/luci-interpreter/include/luci_interpreter/test_models/less_equal/FloatLessEqualKernel.h new file mode 100644 index 00000000000..c20966d8336 --- /dev/null +++ b/onert-micro/luci-interpreter/include/luci_interpreter/test_models/less_equal/FloatLessEqualKernel.h @@ -0,0 +1,185 @@ +/* + * 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_LESS_EQUAL_KERNEL_FLOAT_H +#define LUCI_INTERPRETER_TEST_MODELS_LESS_EQUAL_KERNEL_FLOAT_H + +#include "TestDataLessEqualBase.h" + +namespace luci_interpreter +{ +namespace test_kernel +{ +namespace less_equal_float +{ + +/* + * LessEqual Kernel: + * + * Input_1(1, 4, 4, 3) Input_2(1, 4, 4, 3) + * \ / + * LessEqual(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, 0x7c, 0x01, 0x00, 0x00, 0x98, 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, 0x2e, 0x10, 0x00, 0x00, 0x00, + 0x10, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x04, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x84, 0x00, 0x00, 0x00, + 0x44, 0x00, 0x00, 0x00, 0x10, 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, 0x06, 0x0c, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x6f, 0x66, 0x6d, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 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, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, + 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.01787583, -0.8314556, -0.47624078, -1.9747407, -0.51676583, -0.20183715, -1.9358647, + 0.7616414, -0.0899037, 2.048367, -1.3174965, 1.5267943, 0.68707687, 1.3464743, + 0.98674047, -1.4853697, 1.9973947, 0.5170953, 0.37471953, -1.6011852, 0.32045737, + -0.6598305, -1.7946662, 1.2349467, 1.3320708, 0.5151753, 1.345111, -0.16560331, + 0.82792366, -1.734876, 0.043626763, -0.0118546495, 0.31535238, 0.1888555, -0.32523626, + -0.997665, 0.5819472, -2.3194845, -1.6897905, 0.9981752, -1.2897044, 0.75768864, + 0.56781554, -1.0565805, -1.4891449, 0.2493645, -1.1312587, 0.6837854}; + +const std::vector input2_data = { + 0.30809638, -0.28285328, -0.8437058, 1.7689779, 0.5182942, 0.571205, -0.89484423, + 0.28100377, 0.5453497, 1.3848042, -0.04359268, -1.7448778, -0.5375435, -0.85059136, + -0.77961826, -0.4916915, 1.3359088, -0.09580261, 0.6158275, -0.05056348, 0.90505254, + 0.94226706, 1.136139, -0.45077038, -0.5018571, -1.1543767, 0.85094684, -0.13731039, + -0.3298641, 0.9474698, -0.48497504, -0.14864737, -0.009302358, -1.1259161, 0.44226727, + 1.0149708, 0.36024934, 0.4969523, 0.45014778, -0.34718898, 1.2260172, 0.35304692, + -1.3037513, -0.2565706, 0.18085766, -0.7099202, -0.9203537, -1.2257448}; + +const std::vector reference_output_data = { + true, true, false, true, true, true, true, false, true, false, true, false, + false, false, false, true, false, false, true, true, true, true, true, false, + false, false, false, true, false, true, false, false, false, false, true, true, + false, true, true, false, true, false, false, true, true, false, true, false}; + +} // namespace less_equal_float + +namespace neg_less_equal_float_with_no_broadcasting +{ + +/* + * LessEqual Kernel with input type mismatch: + * + * Input_1(1, 4, 4, 3)-float Input_2(1, 4, 4, 3)-int + * \ / + * LessEqual(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, 0x80, 0x01, 0x00, 0x00, 0x9c, 0x01, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x1c, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x88, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x90, 0xff, 0xff, 0xff, 0x94, 0xff, 0xff, 0xff, + 0x01, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x18, 0x00, 0x14, 0x00, + 0x10, 0x00, 0x0c, 0x00, 0x08, 0x00, 0x04, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, + 0x1c, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x6c, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x14, 0x00, 0x00, 0x00, 0x10, 0x00, 0x0c, 0x00, + 0x07, 0x00, 0x08, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2e, 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, 0x88, 0x00, 0x00, 0x00, + 0x44, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xd0, 0xff, 0xff, 0xff, 0x10, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x0c, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x6f, 0x66, 0x6d, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x0c, 0x00, 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, 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, 0x3f, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x3f, 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 = {}; + +const std::vector input2_data = {}; + +const std::vector reference_output_data = {}; + +} // namespace neg_less_equal_float_with_no_broadcasting + +class TestDataFloatLessEqual : public TestDataLessEqualBase +{ +public: + explicit TestDataFloatLessEqual(bool is_with_broadcast, bool is_neg) + : TestDataLessEqualBase(is_with_broadcast) + { + if (is_with_broadcast) + { + assert(false && "Not impl yet"); + } + else + { + if (is_neg) + { + _input1_data = neg_less_equal_float_with_no_broadcasting::input1_data; + _input2_data = neg_less_equal_float_with_no_broadcasting::input2_data; + _reference_output_data = neg_less_equal_float_with_no_broadcasting::reference_output_data; + _test_kernel_model_circle = + neg_less_equal_float_with_no_broadcasting::test_kernel_model_circle; + } + else + { + _input1_data = less_equal_float::input1_data; + _input2_data = less_equal_float::input2_data; + _reference_output_data = less_equal_float::reference_output_data; + _test_kernel_model_circle = less_equal_float::test_kernel_model_circle; + } + } + } + + ~TestDataFloatLessEqual() override = default; +}; + +} // namespace test_kernel +} // namespace luci_interpreter + +#endif // LUCI_INTERPRETER_TEST_MODELS_LESS_KERNEL_FLOAT_H diff --git a/onert-micro/luci-interpreter/include/luci_interpreter/test_models/less_equal/TestDataLessEqualBase.h b/onert-micro/luci-interpreter/include/luci_interpreter/test_models/less_equal/TestDataLessEqualBase.h new file mode 100644 index 00000000000..4607737101a --- /dev/null +++ b/onert-micro/luci-interpreter/include/luci_interpreter/test_models/less_equal/TestDataLessEqualBase.h @@ -0,0 +1,68 @@ +/* + * 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_LESS_EQUAL_KERNEL_BASE_H +#define LUCI_INTERPRETER_TEST_MODELS_LESS_EQUAL_KERNEL_BASE_H + +#include "luci_interpreter/test_models/TestDataBase.h" + +namespace luci_interpreter +{ +namespace test_kernel +{ + +template class TestDataLessEqualBase : public TestDataBase +{ +public: + explicit TestDataLessEqualBase(bool) + { + // Do nothing + } + + TestDataLessEqualBase() = 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_kernel +} // namespace luci_interpreter + +#endif // LUCI_INTERPRETER_TEST_MODELS_LESS_EQUAL_KERNEL_BASE_H diff --git a/onert-micro/luci-interpreter/include/luci_interpreter/test_models/notequal/FloatNotEqualKernel.h b/onert-micro/luci-interpreter/include/luci_interpreter/test_models/notequal/FloatNotEqualKernel.h new file mode 100644 index 00000000000..51fd85d7502 --- /dev/null +++ b/onert-micro/luci-interpreter/include/luci_interpreter/test_models/notequal/FloatNotEqualKernel.h @@ -0,0 +1,184 @@ +/* + * 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_NOT_EQUAL_KERNEL_FLOAT_H +#define LUCI_INTERPRETER_TEST_MODELS_NOT_EQUAL_KERNEL_FLOAT_H + +#include "TestDataNotEqualBase.h" + +namespace luci_interpreter +{ +namespace test_kernel +{ +namespace not_equal_float +{ + +/* + * NotEqual Kernel: + * + * Input_1(1, 4, 4, 3) Input_2(1, 4, 4, 3) + * \ / + * NotEqual(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, 0x7c, 0x01, 0x00, 0x00, 0x98, 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, 0x36, 0x10, 0x00, 0x00, 0x00, + 0x10, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x04, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x84, 0x00, 0x00, 0x00, + 0x44, 0x00, 0x00, 0x00, 0x10, 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, 0x06, 0x0c, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x6f, 0x66, 0x6d, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 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, 0x48, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x48, + 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.01787583, -0.8314556, -0.47624078, -1.9747407, -0.51676583, -0.20183715, -1.9358647, + 0.7616414, -0.0899037, 2.048367, -1.3174965, 1.5267943, 0.68707687, 1.3464743, + 0.98674047, -1.4853697, 1.9973947, 0.5170953, 0.37471953, -1.6011852, 0.32045737, + -0.6598305, -1.7946662, 1.2349467, 1.3320708, 0.5151753, 1.345111, -0.16560331, + 0.82792366, -1.734876, 0.043626763, -0.0118546495, 0.31535238, 0.1888555, -0.32523626, + -0.997665, 0.5819472, -2.3194845, -1.6897905, 0.9981752, -1.2897044, 0.75768864, + 0.56781554, -1.0565805, -1.4891449, 0.2493645, -1.1312587, 0.6837854}; + +const std::vector input2_data = { + 0.30809638, -0.28285328, -0.8437058, 1.7689779, 0.5182942, 0.571205, -0.89484423, + 0.28100377, 0.5453497, 1.3848042, -0.04359268, -1.7448778, -0.5375435, -0.85059136, + -0.77961826, -0.4916915, 1.3359088, -0.09580261, 0.6158275, -0.05056348, 0.90505254, + 0.94226706, 1.136139, -0.45077038, -0.5018571, -1.1543767, 0.85094684, -0.13731039, + -0.3298641, 0.9474698, -0.48497504, -0.14864737, -0.009302358, -1.1259161, 0.44226727, + 1.0149708, 0.36024934, 0.4969523, 0.45014778, -0.34718898, 1.2260172, 0.35304692, + -1.3037513, -0.2565706, 0.18085766, -0.7099202, -0.9203537, -1.2257448}; + +const std::vector reference_output_data = { + true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, + true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, + true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true}; + +} // namespace not_equal_float + +namespace neg_not_equal_float_with_no_broadcasting +{ + +/* + * NotEqual Kernel with input type mismatch: + * + * Input_1(1, 4, 4, 3)-float Input_2(1, 4, 4, 3)-int + * \ / + * NotEqual(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, 0x80, 0x01, 0x00, 0x00, 0x9c, 0x01, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x1c, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x88, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x90, 0xff, 0xff, 0xff, 0x94, 0xff, 0xff, 0xff, + 0x01, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x18, 0x00, 0x14, 0x00, + 0x10, 0x00, 0x0c, 0x00, 0x08, 0x00, 0x04, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, + 0x1c, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x6c, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x14, 0x00, 0x00, 0x00, 0x10, 0x00, 0x0c, 0x00, + 0x07, 0x00, 0x08, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 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, 0x88, 0x00, 0x00, 0x00, + 0x44, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xd0, 0xff, 0xff, 0xff, 0x10, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x0c, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x6f, 0x66, 0x6d, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x0c, 0x00, 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, 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, 0x48, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x48, 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 = {}; + +const std::vector input2_data = {}; + +const std::vector reference_output_data = {}; + +} // namespace neg_not_equal_float_with_no_broadcasting + +class TestDataFloatNotEqual : public TestDataNotEqualBase +{ +public: + explicit TestDataFloatNotEqual(bool is_with_broadcast, bool is_neg) + : TestDataNotEqualBase(is_with_broadcast) + { + if (is_with_broadcast) + { + assert(false && "Not impl yet"); + } + else + { + if (is_neg) + { + _input1_data = neg_not_equal_float_with_no_broadcasting::input1_data; + _input2_data = neg_not_equal_float_with_no_broadcasting::input2_data; + _reference_output_data = neg_not_equal_float_with_no_broadcasting::reference_output_data; + _test_kernel_model_circle = + neg_not_equal_float_with_no_broadcasting::test_kernel_model_circle; + } + else + { + _input1_data = not_equal_float::input1_data; + _input2_data = not_equal_float::input2_data; + _reference_output_data = not_equal_float::reference_output_data; + _test_kernel_model_circle = not_equal_float::test_kernel_model_circle; + } + } + } + + ~TestDataFloatNotEqual() override = default; +}; + +} // namespace test_kernel +} // namespace luci_interpreter + +#endif // LUCI_INTERPRETER_TEST_MODELS_NOT_EQUAL_KERNEL_FLOAT_H diff --git a/onert-micro/luci-interpreter/include/luci_interpreter/test_models/notequal/TestDataNotEqualBase.h b/onert-micro/luci-interpreter/include/luci_interpreter/test_models/notequal/TestDataNotEqualBase.h new file mode 100644 index 00000000000..786be2170a9 --- /dev/null +++ b/onert-micro/luci-interpreter/include/luci_interpreter/test_models/notequal/TestDataNotEqualBase.h @@ -0,0 +1,68 @@ +/* + * 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_NOT_EQUAL_KERNEL_BASE_H +#define LUCI_INTERPRETER_TEST_MODELS_NOT_EQUAL_KERNEL_BASE_H + +#include "luci_interpreter/test_models/TestDataBase.h" + +namespace luci_interpreter +{ +namespace test_kernel +{ + +template class TestDataNotEqualBase : public TestDataBase +{ +public: + explicit TestDataNotEqualBase(bool) + { + // Do nothing + } + + TestDataNotEqualBase() = 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_kernel +} // namespace luci_interpreter + +#endif // LUCI_INTERPRETER_TEST_MODELS_NOT_EQUAL_KERNEL_BASE_H diff --git a/onert-micro/luci-interpreter/pal/common/PALComparisons.h b/onert-micro/luci-interpreter/pal/common/PALComparisons.h index 559d16acb5d..bb855a1ad3e 100644 --- a/onert-micro/luci-interpreter/pal/common/PALComparisons.h +++ b/onert-micro/luci-interpreter/pal/common/PALComparisons.h @@ -48,13 +48,16 @@ BroadcastComparison4DSlowPreprocess(const luci_interpreter::RuntimeShape &unexte } // namespace -template using ComparisonFn = bool (*)(T, T); - template inline bool LessFn(T lhs, T rhs) { return lhs < rhs; } +template inline bool LessEqualFn(T lhs, T rhs) { return lhs <= rhs; } +template inline bool EqualFn(T lhs, T rhs) { return lhs == rhs; } +template inline bool GreaterFn(T lhs, T rhs) { return lhs > rhs; } +template inline bool GreaterEqualFn(T lhs, T rhs) { return lhs >= rhs; } +template inline bool NotEqualFn(T lhs, T rhs) { return lhs != rhs; } -template F> +template inline void ComparisonNoScaling(const int64_t flat_size, const T *input1_data, const T *input2_data, - bool *output_data) + bool *output_data, bool F(T, T)) { for (int64_t i = 0; i < flat_size; ++i) { @@ -62,12 +65,12 @@ inline void ComparisonNoScaling(const int64_t flat_size, const T *input1_data, c } } -template F> +template inline void BroadcastComparison4DSlowWithScaling( const ComparisonParams &op_params, const luci_interpreter::RuntimeShape &unextended_input1_shape, const T *input1_data, const luci_interpreter::RuntimeShape &unextended_input2_shape, const T *input2_data, const luci_interpreter::RuntimeShape &unextended_output_shape, - bool *output_data) + bool *output_data, bool F(T, T)) { const BroadcastComparison4DSlowCommon dims = BroadcastComparison4DSlowPreprocess( unextended_input1_shape, unextended_input2_shape, unextended_output_shape); @@ -110,9 +113,10 @@ inline void BroadcastComparison4DSlowWithScaling( } } -template F> +template inline void ComparisonWithScaling(const ComparisonParams &op_params, const int64_t flat_size, - const T *input1_data, const T *input2_data, bool *output_data) + const T *input1_data, const T *input2_data, bool *output_data, + bool F(T, T)) { int left_shift = op_params.left_shift; int32_t input1_offset = op_params.input1_offset; @@ -136,12 +140,12 @@ inline void ComparisonWithScaling(const ComparisonParams &op_params, const int64 } } -template F> +template inline void BroadcastComparison4DSlowNoScaling( const ComparisonParams &op_params, const luci_interpreter::RuntimeShape &unextended_input1_shape, const T *input1_data, const luci_interpreter::RuntimeShape &unextended_input2_shape, const T *input2_data, const luci_interpreter::RuntimeShape &unextended_output_shape, - bool *output_data) + bool *output_data, bool F(T, T)) { const BroadcastComparison4DSlowCommon dims = BroadcastComparison4DSlowPreprocess( unextended_input1_shape, unextended_input2_shape, unextended_output_shape); diff --git a/onert-micro/luci-interpreter/pal/mcu/KernelsToBuild.lst b/onert-micro/luci-interpreter/pal/mcu/KernelsToBuild.lst index daf020f13c8..42883192ebe 100644 --- a/onert-micro/luci-interpreter/pal/mcu/KernelsToBuild.lst +++ b/onert-micro/luci-interpreter/pal/mcu/KernelsToBuild.lst @@ -10,8 +10,11 @@ REGISTER_KERNEL(CONV_2D, Conv2D) REGISTER_KERNEL(LOGISTIC, Logistic) REGISTER_KERNEL(GATHER, Gather) REGISTER_KERNEL(EXP, Exp) +REGISTER_KERNEL(GREATER, Greater) +REGISTER_KERNEL(GREATER_EQUAL, GreaterEqual) REGISTER_KERNEL(EXPAND_DIMS, ExpandDims) REGISTER_KERNEL(ELU, Elu) +REGISTER_KERNEL(EQUAL, Equal) REGISTER_KERNEL(FILL, Fill) REGISTER_KERNEL(PACK, Pack) REGISTER_KERNEL(PAD, Pad) @@ -21,6 +24,7 @@ REGISTER_KERNEL(RELU, Relu) REGISTER_KERNEL(RELU6, Relu6) REGISTER_KERNEL(REDUCE_PROD, ReduceCommon) REGISTER_KERNEL(LESS, Less) +REGISTER_KERNEL(LESS_EQUAL, LessEqual) REGISTER_KERNEL(LOGICAL_AND, LogicalAnd) REGISTER_KERNEL(LOGICAL_OR, LogicalOr) REGISTER_KERNEL(LEAKY_RELU, LeakyRelu) @@ -28,6 +32,7 @@ REGISTER_KERNEL(MUL, Mul) REGISTER_KERNEL(MAX_POOL_2D, MaxPool2D) REGISTER_KERNEL(CONCATENATION, Concatenation) REGISTER_KERNEL(SHAPE, Shape) +REGISTER_KERNEL(NOT_EQUAL, NotEqual) REGISTER_KERNEL(SLICE, Slice) REGISTER_KERNEL(SUB, Sub) REGISTER_KERNEL(SPLIT, Split) diff --git a/onert-micro/luci-interpreter/src/kernels/Equal.cpp b/onert-micro/luci-interpreter/src/kernels/Equal.cpp index b7cf8e56055..76968a3644d 100644 --- a/onert-micro/luci-interpreter/src/kernels/Equal.cpp +++ b/onert-micro/luci-interpreter/src/kernels/Equal.cpp @@ -14,128 +14,84 @@ * limitations under the License. */ -#include "kernels/Equal.h" +#include "Builders.h" #include "kernels/Utils.h" +#include "TISOKernel.h" -#include +#include "PALComparisons.h" namespace luci_interpreter { -namespace kernels +namespace { - -Equal::Equal(const Tensor *x, const Tensor *y, Tensor *output) : Kernel({x, y}, {output}) {} - -void Equal::configure() +// TODO: reduce code duplication with less +template +void evalGeneric(const circle::Tensor *x, const circle::Tensor *y, const circle::Tensor *output, + BaseRuntimeGraph *runtime_graph) { - LUCI_INTERPRETER_CHECK(x()->element_type() == y()->element_type()); - LUCI_INTERPRETER_CHECK(output()->element_type() == DataType::BOOL); + auto x_data = kernels::getTensorData(runtime_graph->getDataByTensor(x)); + if (x_data == nullptr) + x_data = kernels::getTensorData(runtime_graph->getConstDataByTensor(x)); - if (x()->element_type() == DataType::U8) - { - quantizeMultiplierSmallerThanOneExp(x()->scale(), &_x_multiplier, &_x_shift); - quantizeMultiplierSmallerThanOneExp(y()->scale(), &_y_multiplier, &_y_shift); - } - // TODO: enable it only if kernel with dynamic shapes - output()->resize(calculateShapeForBroadcast(x()->shape(), y()->shape())); -} + assert(x_data != nullptr); -void Equal::execute() const -{ - switch (x()->element_type()) - { - case DataType::FLOAT32: - evalFloat(); - break; - case DataType::S64: - evalInteger(); - break; - case DataType::S32: - evalInteger(); - break; - case DataType::U8: - evalQuantized(); - break; - default: - assert(false && "Unsupported type."); - } -} + auto y_data = kernels::getTensorData(runtime_graph->getDataByTensor(y)); + if (y_data == nullptr) + y_data = kernels::getTensorData(runtime_graph->getConstDataByTensor(y)); -void Equal::evalFloat() const -{ - const auto x_data = getTensorData(x()); - const auto y_data = getTensorData(y()); - auto output_data = getTensorData(output()); + assert(y_data != nullptr); + + auto output_data = kernels::getTensorData(runtime_graph->getDataByTensor(output)); - tflite::ComparisonParams op_params; - op_params.is_broadcast = x()->shape() != y()->shape(); + luci_interpreter_pal::ComparisonParams op_params; + op_params.is_broadcast = Tensor::num_elements(x) != Tensor::num_elements(y); if (op_params.is_broadcast) { - tflite::reference_ops::Broadcast4DSlowEqual(op_params, getTensorShape(x()), x_data, - getTensorShape(y()), y_data, - getTensorShape(output()), output_data); + luci_interpreter_pal::BroadcastComparison4DSlowNoScaling( + op_params, kernels::getTensorShape(x), x_data, kernels::getTensorShape(y), y_data, + kernels::getTensorShape(output), output_data, luci_interpreter_pal::EqualFn); } else { - tflite::reference_ops::Equal(op_params, getTensorShape(x()), x_data, getTensorShape(y()), - y_data, getTensorShape(output()), output_data); + const int64_t flat_size = kernels::getTensorShape(x).flatSize(); + luci_interpreter_pal::ComparisonNoScaling(flat_size, x_data, y_data, output_data, + luci_interpreter_pal::EqualFn); } } -template void Equal::evalInteger() const -{ - const auto x_data = getTensorData(x()); - const auto y_data = getTensorData(y()); - auto output_data = getTensorData(output()); +} // namespace - tflite::ComparisonParams op_params; - op_params.is_broadcast = x()->shape() != y()->shape(); +void configure_kernel_CircleEqual(const circle::Operator *cur_op, BaseRuntimeGraph *runtime_graph) +{ + kernels::TISOKernel kernel(cur_op, runtime_graph); - if (op_params.is_broadcast) - { - tflite::reference_ops::Broadcast4DSlowEqualNoScaling(op_params, getTensorShape(x()), x_data, - getTensorShape(y()), y_data, - getTensorShape(output()), output_data); - } - else - { - tflite::reference_ops::EqualNoScaling(op_params, getTensorShape(x()), x_data, - getTensorShape(y()), y_data, getTensorShape(output()), - output_data); - } + LUCI_INTERPRETER_CHECK(Tensor::element_type(kernel.input1()) == + Tensor::element_type(kernel.input2())); + LUCI_INTERPRETER_CHECK(Tensor::element_type(kernel.output()) == DataType::BOOL); } -void Equal::evalQuantized() const +void execute_kernel_CircleEqual(const circle::Operator *cur_op, BaseRuntimeGraph *runtime_graph) { - const auto x_data = getTensorData(x()); - const auto y_data = getTensorData(y()); - auto output_data = getTensorData(output()); - - tflite::ComparisonParams op_params; - op_params.left_shift = 8; - op_params.input1_offset = -x()->zero_point(); // Note the '-' - op_params.input1_shift = _x_shift; - op_params.input1_multiplier = _x_multiplier; - op_params.input2_offset = -y()->zero_point(); // Note the '-' - op_params.input2_shift = _y_shift; - op_params.input2_multiplier = _y_multiplier; - op_params.is_broadcast = x()->shape() != y()->shape(); + kernels::TISOKernel kernel(cur_op, runtime_graph); - if (op_params.is_broadcast) - { - tflite::reference_ops::Broadcast4DSlowEqualWithScaling(op_params, getTensorShape(x()), x_data, - getTensorShape(y()), y_data, - getTensorShape(output()), output_data); - } - else + switch (Tensor::element_type(kernel.input1())) { - tflite::reference_ops::EqualWithScaling(op_params, getTensorShape(x()), x_data, - getTensorShape(y()), y_data, getTensorShape(output()), - output_data); + case DataType::S64: + evalGeneric(kernel.input1(), kernel.input2(), kernel.output(), runtime_graph); + break; + case DataType::S32: + evalGeneric(kernel.input1(), kernel.input2(), kernel.output(), runtime_graph); + break; +#ifndef DIS_FLOAT + case DataType::FLOAT32: + evalGeneric(kernel.input1(), kernel.input2(), kernel.output(), runtime_graph); + break; +#endif // DIS_FLOAT + default: + assert(false && "Unsupported type."); } } -} // namespace kernels } // namespace luci_interpreter diff --git a/onert-micro/luci-interpreter/src/kernels/Equal.h b/onert-micro/luci-interpreter/src/kernels/Equal.h deleted file mode 100644 index c9be32cc096..00000000000 --- a/onert-micro/luci-interpreter/src/kernels/Equal.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef LUCI_INTERPRETER_KERNELS_EQUAL_H -#define LUCI_INTERPRETER_KERNELS_EQUAL_H - -#include "core/Kernel.h" - -namespace luci_interpreter -{ -namespace kernels -{ - -class Equal : public Kernel -{ -public: - Equal(const Tensor *x, const Tensor *y, Tensor *output); - - const Tensor *x() const { return _inputs[0]; } - const Tensor *y() const { return _inputs[1]; } - Tensor *output() const { return _outputs[0]; } - - void configure() override; - void execute() const override; - -private: - void evalFloat() const; - template void evalInteger() const; - void evalQuantized() const; - -private: - int32_t _x_multiplier = 0; - int _x_shift = 0; - int32_t _y_multiplier = 0; - int _y_shift = 0; -}; - -} // namespace kernels -} // namespace luci_interpreter - -#endif // LUCI_INTERPRETER_KERNELS_EQUAL_H diff --git a/onert-micro/luci-interpreter/src/kernels/Equal.test.cpp b/onert-micro/luci-interpreter/src/kernels/Equal.test.cpp index 5870e54602d..15bcd19197d 100644 --- a/onert-micro/luci-interpreter/src/kernels/Equal.test.cpp +++ b/onert-micro/luci-interpreter/src/kernels/Equal.test.cpp @@ -15,14 +15,14 @@ * limitations under the License. */ -#include "kernels/Equal.h" #include "kernels/TestUtils.h" -#include "luci_interpreter/TestMemoryManager.h" +#include "luci_interpreter/test_models/equal/FloatEqualKernel.h" +#include "luci_interpreter/test_models/equal/IntEqualKernel.h" + +#include "loader/ModuleLoader.h" namespace luci_interpreter { -namespace kernels -{ namespace { @@ -30,277 +30,106 @@ using namespace testing; class EqualTest : public ::testing::Test { -protected: - void SetUp() override { _memory_manager = std::make_unique(); } - - std::unique_ptr _memory_manager; + // Do nothing }; -TEST_F(EqualTest, FloatSimple) -{ - std::vector x_data{ - 0.5, 0.7, 0.9, // Row 1 - 1, 0, -1, // Row 2 - }; - - std::vector y_data{ - 0.9, 0.7, 0.5, // Row 1 - -1, 0, 1, // Row 2 - }; - - std::vector ref_output_data{ - false, true, false, // Row 1 - false, true, false, // Row 2 - }; - - Tensor x_tensor = makeInputTensor({2, 3}, x_data, _memory_manager.get()); - Tensor y_tensor = makeInputTensor({2, 3}, y_data, _memory_manager.get()); - Tensor output_tensor = makeOutputTensor(DataType::BOOL); - - Equal kernel(&x_tensor, &y_tensor, &output_tensor); - kernel.configure(); - _memory_manager->allocate_memory(output_tensor); - kernel.execute(); - - EXPECT_THAT(extractTensorData(output_tensor), ::testing::ElementsAreArray(ref_output_data)); - EXPECT_THAT(extractTensorShape(output_tensor), ::testing::ElementsAreArray({2, 3})); -} - -TEST_F(EqualTest, FloatBroardcast) +template +std::vector checkEqualKernel(test_kernel::TestDataBase *test_data_base) { - std::vector x_data{ - 0.5, 0.7, 0.9, // Row 1 - 1, 0, -1, // Row 2 - -1, 0, 1, // Row 3 - 0.9, 0.7, 0.5, // Row 4 - }; - - std::vector y_data{ - 0.9, 0.7, 0.5, // Row 1 - }; - - std::vector ref_output_data{ - false, true, false, // Row 1 - false, false, false, // Row 2 - false, false, false, // Row 3 - true, true, true, // Row 4 - }; - - Tensor x_tensor = makeInputTensor({4, 3}, x_data, _memory_manager.get()); - Tensor y_tensor = makeInputTensor({1, 3}, y_data, _memory_manager.get()); - Tensor output_tensor = makeOutputTensor(DataType::BOOL); - - Equal kernel(&x_tensor, &y_tensor, &output_tensor); - kernel.configure(); - _memory_manager->allocate_memory(output_tensor); - kernel.execute(); - - EXPECT_THAT(extractTensorData(output_tensor), ::testing::ElementsAreArray(ref_output_data)); - EXPECT_THAT(extractTensorShape(output_tensor), ::testing::ElementsAreArray({4, 3})); -} - -template -void checkIntegerSimple(luci_interpreter::IMemoryManager *memory_manager) -{ - using dtype = typename loco::DataTypeImpl::Type; - dtype min_value = std::numeric_limits::min(); - dtype max_value = std::numeric_limits::max(); - std::vector x_data{min_value, 2, max_value}; - - std::vector y_data{min_value, -2, max_value}; - - std::vector ref_output_data{true, false, true}; - - Tensor x_tensor = makeInputTensor({3}, x_data, memory_manager); - Tensor y_tensor = makeInputTensor({3}, y_data, memory_manager); - Tensor output_tensor = makeOutputTensor(DataType::BOOL); - - Equal kernel(&x_tensor, &y_tensor, &output_tensor); - kernel.configure(); - memory_manager->allocate_memory(output_tensor); - kernel.execute(); + MemoryManager memory_manager{}; + RuntimeModule runtime_module{}; + bool dealloc_input = true; - EXPECT_THAT(extractTensorData(output_tensor), ::testing::ElementsAreArray(ref_output_data)); - EXPECT_THAT(extractTensorShape(output_tensor), ::testing::ElementsAreArray({3})); -} + // 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); -template -void checkIntegerBroadcast(luci_interpreter::IMemoryManager *memory_manager) -{ - using dtype = typename loco::DataTypeImpl::Type; - dtype min_value = std::numeric_limits::min(); - dtype max_value = std::numeric_limits::max(); - std::vector x_data{ - min_value, 2, 3, // Row 1 - 4, 5, max_value, // Row 2 - -1, -2, -3, // Row 3 - min_value, -2, max_value, // Row 4 - }; + auto *main_runtime_graph = runtime_module.getMainGraph(); + assert(main_runtime_graph->getNumOfInputTensors() == 2); - std::vector y_data{ - min_value, -2, max_value, // Row 1 - }; + // set left input data + { + auto *input_tensor_data = reinterpret_cast(main_runtime_graph->configureGraphInput(0)); + std::copy(test_data_base->get_input_data_by_index(0).begin(), + test_data_base->get_input_data_by_index(0).end(), input_tensor_data); + } - std::vector ref_output_data{ - true, false, false, // Row 1 - false, false, true, // Row 2 - false, true, false, // Row 3 - true, true, true, // Row 4 - }; + // set right input data + { + auto *input_tensor_data = reinterpret_cast(main_runtime_graph->configureGraphInput(1)); + std::copy(test_data_base->get_input_data_by_index(1).begin(), + test_data_base->get_input_data_by_index(1).end(), input_tensor_data); + } - Tensor x_tensor = makeInputTensor({4, 3}, x_data, memory_manager); - Tensor y_tensor = makeInputTensor({3}, y_data, memory_manager); - Tensor output_tensor = makeOutputTensor(DataType::BOOL); + runtime_module.execute(); - Equal kernel(&x_tensor, &y_tensor, &output_tensor); - kernel.configure(); - memory_manager->allocate_memory(output_tensor); - kernel.execute(); + assert(main_runtime_graph->getNumOfOutputTensors() == 1); - EXPECT_THAT(extractTensorData(output_tensor), ::testing::ElementsAreArray(ref_output_data)); - EXPECT_THAT(extractTensorShape(output_tensor), ::testing::ElementsAreArray({4, 3})); + U *output_data = reinterpret_cast(main_runtime_graph->getOutputDataByIndex(0)); + const size_t num_elements = (main_runtime_graph->getOutputDataSizeByIndex(0) / sizeof(U)); + std::vector output_data_vector(output_data, output_data + num_elements); + return output_data_vector; } -TEST_F(EqualTest, Int32) +TEST_F(EqualTest, FloatNoBroadcast_P) { - checkIntegerSimple(_memory_manager.get()); - checkIntegerBroadcast(_memory_manager.get()); - SUCCEED(); + const bool is_with_broadcast = false; + test_kernel::TestDataFloatEqual test_data_kernel(is_with_broadcast, false); + std::vector output_data_vector = checkEqualKernel(&test_data_kernel); + EXPECT_THAT(output_data_vector, test_data_kernel.get_output_data_by_index(0)); } -TEST_F(EqualTest, Int64) +TEST_F(EqualTest, FloatWithBroadcast_P) { - checkIntegerSimple(_memory_manager.get()); - checkIntegerBroadcast(_memory_manager.get()); - SUCCEED(); + const bool is_with_broadcast = true; + test_kernel::TestDataFloatEqual test_data_kernel(is_with_broadcast, false); + std::vector output_data_vector = checkEqualKernel(&test_data_kernel); + EXPECT_THAT(output_data_vector, test_data_kernel.get_output_data_by_index(0)); } -// Choose min / max in such a way that there are exactly 256 units to avoid rounding errors. -const float F_MIN = -128.0 / 128.0; -const float F_MAX = 127.0 / 128.0; - -TEST_F(EqualTest, Uint8Quantized) +TEST_F(EqualTest, FloatNoBroadcast_NEG) { - std::vector x_data{ - 0.5, 0.5, 0.7, 0.9, // Row 1 - 1, 0, 0.05, -1, // Row 2 - }; - - std::vector y_data{ - 0.9, 0.5, 0.55, 0.5, // Row 1 - -1, 0, 0.05, 1, // Row 2 - }; - - std::vector ref_output_data{ - false, true, false, false, // Row 1 - false, true, true, false, // Row 2 - }; - - std::pair x_quant_param = quantizationParams(F_MIN, F_MAX); - Tensor x_tensor = makeInputTensor( - {1, 2, 4, 1}, x_quant_param.first, x_quant_param.second, x_data, _memory_manager.get()); - - std::pair y_quant_param = quantizationParams(F_MIN * 2, F_MAX * 2); - Tensor y_tensor = makeInputTensor( - {1, 2, 4, 1}, y_quant_param.first, y_quant_param.second, y_data, _memory_manager.get()); - - Tensor output_tensor = makeOutputTensor(DataType::BOOL); - - Equal kernel(&x_tensor, &y_tensor, &output_tensor); - kernel.configure(); - _memory_manager->allocate_memory(output_tensor); - kernel.execute(); - - EXPECT_THAT(extractTensorShape(output_tensor), ::testing::ElementsAreArray({1, 2, 4, 1})); - EXPECT_THAT(extractTensorData(output_tensor), ::testing::ElementsAreArray(ref_output_data)); + const bool is_with_broadcast = false; + test_kernel::TestDataFloatEqual test_data_kernel(is_with_broadcast, true); + EXPECT_DEATH(checkEqualKernel(&test_data_kernel), ""); } -TEST_F(EqualTest, Uint8QuantizedBroadcast) +TEST_F(EqualTest, FloatWithBroadcast_NEG) { - std::vector x_data{ - 0.4, -0.8, 0.7, 0.3, // Row 1 - -0.5, 0.1, 0, 0.5, // Row 2 - 1, 0, 0.05, -1, // Row 3 - -1, 0.05, 0, 1, // Row 4 - }; - - std::vector y_data{ - -1, 0.05, 0, 1, // Row 1 - }; - - std::vector ref_output_data{ - false, false, false, false, // Row 1 - false, false, true, false, // Row 2 - false, false, false, false, // Row 3 - true, true, true, true, // Row 4 - }; - - std::pair quant_param = quantizationParams(F_MIN, F_MAX); - Tensor x_tensor = makeInputTensor( - {1, 4, 4, 1}, quant_param.first, quant_param.second, x_data, _memory_manager.get()); - Tensor y_tensor = makeInputTensor( - {1, 1, 4, 1}, quant_param.first, quant_param.second, y_data, _memory_manager.get()); - Tensor output_tensor = makeOutputTensor(DataType::BOOL); - - Equal kernel(&x_tensor, &y_tensor, &output_tensor); - kernel.configure(); - _memory_manager->allocate_memory(output_tensor); - kernel.execute(); - - EXPECT_THAT(extractTensorShape(output_tensor), ::testing::ElementsAreArray({1, 4, 4, 1})); - EXPECT_THAT(extractTensorData(output_tensor), ::testing::ElementsAreArray(ref_output_data)); + const bool is_with_broadcast = true; + test_kernel::TestDataFloatEqual test_data_kernel(is_with_broadcast, true); + EXPECT_DEATH(checkEqualKernel(&test_data_kernel), ""); } -TEST_F(EqualTest, Input_Type_Mismatch_NEG) +TEST_F(EqualTest, IntWithBroadcast_P) { - Tensor x_tensor = makeInputTensor({1}, {1.f}, _memory_manager.get()); - Tensor y_tensor = makeInputTensor({1}, {1}, _memory_manager.get()); - Tensor output_tensor = makeOutputTensor(DataType::BOOL); - - Equal kernel(&x_tensor, &y_tensor, &output_tensor); - EXPECT_ANY_THROW(kernel.configure()); + const bool is_with_broadcast = true; + test_kernel::TestDataIntEqual test_data_kernel(is_with_broadcast, false); + std::vector output_data_vector = checkEqualKernel(&test_data_kernel); + EXPECT_THAT(output_data_vector, test_data_kernel.get_output_data_by_index(0)); } -TEST_F(EqualTest, Input_Output_Type_NEG) +TEST_F(EqualTest, IntNoBroadcast_P) { - Tensor x_tensor = makeInputTensor({1}, {1.f}, _memory_manager.get()); - Tensor y_tensor = makeInputTensor({1}, {1.f}, _memory_manager.get()); - Tensor output_tensor = makeOutputTensor(DataType::FLOAT32); - - Equal kernel(&x_tensor, &y_tensor, &output_tensor); - EXPECT_ANY_THROW(kernel.configure()); + const bool is_with_broadcast = false; + test_kernel::TestDataIntEqual test_data_kernel(is_with_broadcast, false); + std::vector output_data_vector = checkEqualKernel(&test_data_kernel); + EXPECT_THAT(output_data_vector, test_data_kernel.get_output_data_by_index(0)); } -TEST_F(EqualTest, Float_Broadcast_NEG) +TEST_F(EqualTest, IntWithBroadcast_NEG) { - Tensor x_tensor = makeInputTensor({2}, {1.f, 2.f}, _memory_manager.get()); - Tensor y_tensor = makeInputTensor({3}, {1.f, 2.f, 3.f}, _memory_manager.get()); - Tensor output_tensor = makeOutputTensor(DataType::BOOL); - - Equal kernel(&x_tensor, &y_tensor, &output_tensor); - ASSERT_ANY_THROW(kernel.configure()); + const bool is_with_broadcast = true; + test_kernel::TestDataIntEqual test_data_kernel(is_with_broadcast, true); + EXPECT_DEATH(checkEqualKernel(&test_data_kernel), ""); } -TEST_F(EqualTest, Int32_Broadcast_NEG) +TEST_F(EqualTest, IntNoBroadcast_NEG) { - Tensor x_tensor = makeInputTensor({2}, {1, 2}, _memory_manager.get()); - Tensor y_tensor = makeInputTensor({3}, {1, 2, 3}, _memory_manager.get()); - Tensor output_tensor = makeOutputTensor(DataType::BOOL); - - Equal kernel(&x_tensor, &y_tensor, &output_tensor); - ASSERT_ANY_THROW(kernel.configure()); -} - -TEST_F(EqualTest, Int64_Broadcast_NEG) -{ - Tensor x_tensor = makeInputTensor({2}, {1, 2}, _memory_manager.get()); - Tensor y_tensor = makeInputTensor({3}, {1, 2, 3}, _memory_manager.get()); - Tensor output_tensor = makeOutputTensor(DataType::BOOL); - - Equal kernel(&x_tensor, &y_tensor, &output_tensor); - ASSERT_ANY_THROW(kernel.configure()); + const bool is_with_broadcast = false; + test_kernel::TestDataIntEqual test_data_kernel(is_with_broadcast, true); + EXPECT_DEATH(checkEqualKernel(&test_data_kernel), ""); } } // namespace -} // namespace kernels } // namespace luci_interpreter diff --git a/onert-micro/luci-interpreter/src/kernels/Greater.cpp b/onert-micro/luci-interpreter/src/kernels/Greater.cpp index 9d777805981..b073a4a67cd 100644 --- a/onert-micro/luci-interpreter/src/kernels/Greater.cpp +++ b/onert-micro/luci-interpreter/src/kernels/Greater.cpp @@ -14,128 +14,75 @@ * limitations under the License. */ -#include "kernels/Greater.h" +#include "Builders.h" #include "kernels/Utils.h" +#include "TISOKernel.h" -#include +#include "PALComparisons.h" namespace luci_interpreter { -namespace kernels +namespace { +// TODO: reduce code duplication with less +template +void evalGeneric(const circle::Tensor *x, const circle::Tensor *y, const circle::Tensor *output, + BaseRuntimeGraph *runtime_graph) +{ + auto x_data = kernels::getTensorData(runtime_graph->getDataByTensor(x)); + if (x_data == nullptr) + x_data = kernels::getTensorData(runtime_graph->getConstDataByTensor(x)); + + assert(x_data != nullptr); + + auto y_data = kernels::getTensorData(runtime_graph->getDataByTensor(y)); + if (y_data == nullptr) + y_data = kernels::getTensorData(runtime_graph->getConstDataByTensor(y)); + + assert(y_data != nullptr); + + auto output_data = kernels::getTensorData(runtime_graph->getDataByTensor(output)); -Greater::Greater(const Tensor *x, const Tensor *y, Tensor *output) : Kernel({x, y}, {output}) {} + luci_interpreter_pal::ComparisonParams op_params; + op_params.is_broadcast = Tensor::num_elements(x) != Tensor::num_elements(y); -void Greater::configure() + const int64_t flat_size = kernels::getTensorShape(x).flatSize(); + luci_interpreter_pal::ComparisonNoScaling(flat_size, x_data, y_data, output_data, + luci_interpreter_pal::GreaterFn); +} + +} // namespace + +void configure_kernel_CircleGreater(const circle::Operator *cur_op, BaseRuntimeGraph *runtime_graph) { - LUCI_INTERPRETER_CHECK(x()->element_type() == y()->element_type()); - LUCI_INTERPRETER_CHECK(output()->element_type() == DataType::BOOL); + kernels::TISOKernel kernel(cur_op, runtime_graph); - if (x()->element_type() == DataType::U8) - { - quantizeMultiplierSmallerThanOneExp(x()->scale(), &_x_multiplier, &_x_shift); - quantizeMultiplierSmallerThanOneExp(y()->scale(), &_y_multiplier, &_y_shift); - } - // TODO: enable it only if kernel with dynamic shapes - output()->resize(calculateShapeForBroadcast(x()->shape(), y()->shape())); + LUCI_INTERPRETER_CHECK(Tensor::element_type(kernel.input1()) == + Tensor::element_type(kernel.input2())); + LUCI_INTERPRETER_CHECK(Tensor::element_type(kernel.output()) == DataType::BOOL); } -void Greater::execute() const +void execute_kernel_CircleGreater(const circle::Operator *cur_op, BaseRuntimeGraph *runtime_graph) { - switch (x()->element_type()) + kernels::TISOKernel kernel(cur_op, runtime_graph); + + switch (Tensor::element_type(kernel.input1())) { - case DataType::FLOAT32: - evalFloat(); - break; case DataType::S64: - evalInteger(); + evalGeneric(kernel.input1(), kernel.input2(), kernel.output(), runtime_graph); break; case DataType::S32: - evalInteger(); + evalGeneric(kernel.input1(), kernel.input2(), kernel.output(), runtime_graph); break; - case DataType::U8: - evalQuantized(); +#ifndef DIS_FLOAT + case DataType::FLOAT32: + evalGeneric(kernel.input1(), kernel.input2(), kernel.output(), runtime_graph); break; +#endif // DIS_FLOAT default: assert(false && "Unsupported type."); } } -void Greater::evalFloat() const -{ - const auto x_data = getTensorData(x()); - const auto y_data = getTensorData(y()); - auto output_data = getTensorData(output()); - - tflite::ComparisonParams op_params; - op_params.is_broadcast = x()->shape() != y()->shape(); - - if (op_params.is_broadcast) - { - tflite::reference_ops::Broadcast4DSlowGreater(op_params, getTensorShape(x()), x_data, - getTensorShape(y()), y_data, - getTensorShape(output()), output_data); - } - else - { - tflite::reference_ops::Greater(op_params, getTensorShape(x()), x_data, getTensorShape(y()), - y_data, getTensorShape(output()), output_data); - } -} - -template void Greater::evalInteger() const -{ - const auto x_data = getTensorData(x()); - const auto y_data = getTensorData(y()); - auto output_data = getTensorData(output()); - - tflite::ComparisonParams op_params; - op_params.is_broadcast = x()->shape() != y()->shape(); - - if (op_params.is_broadcast) - { - tflite::reference_ops::Broadcast4DSlowGreaterNoScaling(op_params, getTensorShape(x()), x_data, - getTensorShape(y()), y_data, - getTensorShape(output()), output_data); - } - else - { - tflite::reference_ops::GreaterNoScaling(op_params, getTensorShape(x()), x_data, - getTensorShape(y()), y_data, getTensorShape(output()), - output_data); - } -} - -void Greater::evalQuantized() const -{ - const auto x_data = getTensorData(x()); - const auto y_data = getTensorData(y()); - auto output_data = getTensorData(output()); - - tflite::ComparisonParams op_params; - op_params.left_shift = 8; - op_params.input1_offset = -x()->zero_point(); // Note the '-' - op_params.input1_shift = _x_shift; - op_params.input1_multiplier = _x_multiplier; - op_params.input2_offset = -y()->zero_point(); // Note the '-' - op_params.input2_shift = _y_shift; - op_params.input2_multiplier = _y_multiplier; - op_params.is_broadcast = x()->shape() != y()->shape(); - - if (op_params.is_broadcast) - { - tflite::reference_ops::Broadcast4DSlowGreaterWithScaling(op_params, getTensorShape(x()), x_data, - getTensorShape(y()), y_data, - getTensorShape(output()), output_data); - } - else - { - tflite::reference_ops::GreaterWithScaling(op_params, getTensorShape(x()), x_data, - getTensorShape(y()), y_data, getTensorShape(output()), - output_data); - } -} - -} // namespace kernels } // namespace luci_interpreter diff --git a/onert-micro/luci-interpreter/src/kernels/Greater.h b/onert-micro/luci-interpreter/src/kernels/Greater.h deleted file mode 100644 index 065f76d7b8f..00000000000 --- a/onert-micro/luci-interpreter/src/kernels/Greater.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef LUCI_INTERPRETER_KERNELS_GREATER_H -#define LUCI_INTERPRETER_KERNELS_GREATER_H - -#include "core/Kernel.h" - -namespace luci_interpreter -{ -namespace kernels -{ - -class Greater : public Kernel -{ -public: - Greater(const Tensor *x, const Tensor *y, Tensor *output); - - const Tensor *x() const { return _inputs[0]; } - const Tensor *y() const { return _inputs[1]; } - Tensor *output() const { return _outputs[0]; } - - void configure() override; - void execute() const override; - -private: - void evalFloat() const; - template void evalInteger() const; - void evalQuantized() const; - -private: - int32_t _x_multiplier = 0; - int _x_shift = 0; - int32_t _y_multiplier = 0; - int _y_shift = 0; -}; - -} // namespace kernels -} // namespace luci_interpreter - -#endif // LUCI_INTERPRETER_KERNELS_GREATER_H diff --git a/onert-micro/luci-interpreter/src/kernels/Greater.test.cpp b/onert-micro/luci-interpreter/src/kernels/Greater.test.cpp index a48080124ef..cd938f00d9b 100644 --- a/onert-micro/luci-interpreter/src/kernels/Greater.test.cpp +++ b/onert-micro/luci-interpreter/src/kernels/Greater.test.cpp @@ -15,14 +15,13 @@ * limitations under the License. */ -#include "kernels/Greater.h" #include "kernels/TestUtils.h" -#include "luci_interpreter/TestMemoryManager.h" +#include "luci_interpreter/test_models/greater/FloatGreaterKernel.h" + +#include "loader/ModuleLoader.h" namespace luci_interpreter { -namespace kernels -{ namespace { @@ -30,305 +29,61 @@ using namespace testing; class GreaterTest : public ::testing::Test { -protected: - void SetUp() override { _memory_manager = std::make_unique(); } - - std::unique_ptr _memory_manager; + // Do nothing }; -TEST_F(GreaterTest, FloatSimple) -{ - std::vector x_data{ - 0.5, 0.7, 0.9, // Row 1 - 1, 0, -1, // Row 2 - }; - - std::vector y_data{ - 0.9, 0.7, 0.5, // Row 1 - -1, 0, 1, // Row 2 - }; - - std::vector ref_output_data{ - false, false, true, // Row 1 - true, false, false, // Row 2 - }; - - Tensor x_tensor = makeInputTensor({2, 3}, x_data, _memory_manager.get()); - Tensor y_tensor = makeInputTensor({2, 3}, y_data, _memory_manager.get()); - Tensor output_tensor = makeOutputTensor(DataType::BOOL); - - Greater kernel(&x_tensor, &y_tensor, &output_tensor); - kernel.configure(); - _memory_manager->allocate_memory(output_tensor); - kernel.execute(); - - EXPECT_THAT(extractTensorData(output_tensor), ::testing::ElementsAreArray(ref_output_data)); - EXPECT_THAT(extractTensorShape(output_tensor), ::testing::ElementsAreArray({2, 3})); -} - -TEST_F(GreaterTest, FloatBroardcast) -{ - std::vector x_data{ - 0.5, 0.7, 0.9, // Row 1 - 1, 0, -1, // Row 2 - -1, 0, 1, // Row 3 - }; - - std::vector y_data{ - 0.9, 0.7, 0.5, // Row 1 - }; - - std::vector ref_output_data{ - false, false, true, // Row 1 - true, false, false, // Row 2 - false, false, true, // Row 3 - }; - - Tensor x_tensor = makeInputTensor({3, 3}, x_data, _memory_manager.get()); - Tensor y_tensor = makeInputTensor({1, 3}, y_data, _memory_manager.get()); - Tensor output_tensor = makeOutputTensor(DataType::BOOL); - - Greater kernel(&x_tensor, &y_tensor, &output_tensor); - kernel.configure(); - _memory_manager->allocate_memory(output_tensor); - kernel.execute(); - - EXPECT_THAT(extractTensorData(output_tensor), ::testing::ElementsAreArray(ref_output_data)); - EXPECT_THAT(extractTensorShape(output_tensor), ::testing::ElementsAreArray({3, 3})); -} - -template -void checkIntegerSimple(luci_interpreter::IMemoryManager *memory_manager) +template +std::vector checkGreaterKernel(test_kernel::TestDataBase *test_data_base) { - using dtype = typename loco::DataTypeImpl::Type; - dtype min_value = std::numeric_limits::min(); - dtype max_value = std::numeric_limits::max(); - std::vector x_data{min_value, 2, max_value}; - - std::vector y_data{min_value + 1, -2, max_value}; + MemoryManager memory_manager{}; + RuntimeModule runtime_module{}; + bool dealloc_input = true; - std::vector ref_output_data{false, true, false}; + // 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); - Tensor x_tensor = makeInputTensor({3}, x_data, memory_manager); - Tensor y_tensor = makeInputTensor({3}, y_data, memory_manager); - Tensor output_tensor = makeOutputTensor(DataType::BOOL); + auto *main_runtime_graph = runtime_module.getMainGraph(); + assert(main_runtime_graph->getNumOfInputTensors() == 2); - Greater kernel(&x_tensor, &y_tensor, &output_tensor); - kernel.configure(); - memory_manager->allocate_memory(output_tensor); - kernel.execute(); + // set left input data + { + auto *input_tensor_data = reinterpret_cast(main_runtime_graph->configureGraphInput(0)); + std::copy(test_data_base->get_input_data_by_index(0).begin(), + test_data_base->get_input_data_by_index(0).end(), input_tensor_data); + } - EXPECT_THAT(extractTensorData(output_tensor), ::testing::ElementsAreArray(ref_output_data)); - EXPECT_THAT(extractTensorShape(output_tensor), ::testing::ElementsAreArray({3})); -} - -template -void checkIntegerBroadcast(luci_interpreter::IMemoryManager *memory_manager) -{ - using dtype = typename loco::DataTypeImpl::Type; - dtype min_value = std::numeric_limits::min(); - dtype max_value = std::numeric_limits::max(); - std::vector x_data{ - min_value, 2, 3, // Row 1 - 4, 5, max_value, // Row 2 - -1, -4, -3, // Row 3 - min_value, -2, max_value, // Row 4 - }; + // set right input data + { + auto *input_tensor_data = reinterpret_cast(main_runtime_graph->configureGraphInput(1)); + std::copy(test_data_base->get_input_data_by_index(1).begin(), + test_data_base->get_input_data_by_index(1).end(), input_tensor_data); + } - std::vector y_data{ - min_value + 1, -2, max_value - 1, // Row 1 - }; + runtime_module.execute(); - std::vector ref_output_data{ - false, true, false, // Row 1 - true, true, true, // Row 2 - true, false, false, // Row 3 - false, false, true, // Row 4 - }; - - Tensor x_tensor = makeInputTensor({4, 3}, x_data, memory_manager); - Tensor y_tensor = makeInputTensor({3}, y_data, memory_manager); - Tensor output_tensor = makeOutputTensor(DataType::BOOL); - - Greater kernel(&x_tensor, &y_tensor, &output_tensor); - kernel.configure(); - memory_manager->allocate_memory(output_tensor); - kernel.execute(); - - EXPECT_THAT(extractTensorData(output_tensor), ::testing::ElementsAreArray(ref_output_data)); - EXPECT_THAT(extractTensorShape(output_tensor), ::testing::ElementsAreArray({4, 3})); -} + assert(main_runtime_graph->getNumOfOutputTensors() == 1); -TEST_F(GreaterTest, Int32) -{ - checkIntegerSimple(_memory_manager.get()); - checkIntegerBroadcast(_memory_manager.get()); - SUCCEED(); + U *output_data = reinterpret_cast(main_runtime_graph->getOutputDataByIndex(0)); + const size_t num_elements = (main_runtime_graph->getOutputDataSizeByIndex(0) / sizeof(U)); + std::vector output_data_vector(output_data, output_data + num_elements); + return output_data_vector; } -TEST_F(GreaterTest, Int64) +TEST_F(GreaterTest, FloatNoBroadcast_P) { - checkIntegerSimple(_memory_manager.get()); - checkIntegerBroadcast(_memory_manager.get()); - SUCCEED(); + const bool is_with_broadcast = false; + test_kernel::TestDataFloatGreater test_data_kernel(is_with_broadcast, false); + std::vector output_data_vector = checkGreaterKernel(&test_data_kernel); + EXPECT_THAT(output_data_vector, test_data_kernel.get_output_data_by_index(0)); } -// Choose min / max in such a way that there are exactly 256 units to avoid rounding errors. -const float F_MIN = -128.0 / 128.0; -const float F_MAX = 127.0 / 128.0; - -TEST_F(GreaterTest, Uint8Quantized) +TEST_F(GreaterTest, FloatNoBroadcast_NEG) { - std::vector x_data{ - 0.5, 0.6, 0.7, 0.9, // Row 1 - 1, 0, 0.05, -1, // Row 2 - }; - - std::vector y_data{ - 0.9, 0.6, 0.6, 0.5, // Row 1 - -1, 0.05, 0, 1, // Row 2 - }; - - std::vector ref_output_data{ - false, false, true, true, // Row 1 - true, false, true, false, // Row 2 - }; - - std::pair quant_param = quantizationParams(F_MIN, F_MAX); - Tensor x_tensor = makeInputTensor( - {1, 2, 4, 1}, quant_param.first, quant_param.second, x_data, _memory_manager.get()); - Tensor y_tensor = makeInputTensor( - {1, 2, 4, 1}, quant_param.first, quant_param.second, y_data, _memory_manager.get()); - Tensor output_tensor = makeOutputTensor(DataType::BOOL); - - Greater kernel(&x_tensor, &y_tensor, &output_tensor); - kernel.configure(); - _memory_manager->allocate_memory(output_tensor); - kernel.execute(); - - EXPECT_THAT(extractTensorShape(output_tensor), ::testing::ElementsAreArray({1, 2, 4, 1})); - EXPECT_THAT(extractTensorData(output_tensor), ::testing::ElementsAreArray(ref_output_data)); -} - -TEST_F(GreaterTest, Uint8QuantizedRescale) -{ - std::vector x_data{ - 0.5, 0.6, 0.7, 0.9, // Row 1 - 1, 0, 0.05, -1, // Row 2 - }; - - std::vector y_data{ - 0.9, 0.6, 0.6, 0.5, // Row 1 - -1, 0.05, 0, 1, // Row 2 - }; - - std::vector ref_output_data{ - false, false, true, true, // Row 1 - true, false, true, false, // Row 2 - }; - - std::pair x_quant_param = quantizationParams(F_MIN, F_MAX); - std::pair y_quant_param = quantizationParams(F_MIN * 2, F_MAX * 3); - - Tensor x_tensor = makeInputTensor( - {1, 2, 4, 1}, x_quant_param.first, x_quant_param.second, x_data, _memory_manager.get()); - Tensor y_tensor = makeInputTensor( - {1, 2, 4, 1}, y_quant_param.first, y_quant_param.second, y_data, _memory_manager.get()); - Tensor output_tensor = makeOutputTensor(DataType::BOOL); - - Greater kernel(&x_tensor, &y_tensor, &output_tensor); - kernel.configure(); - _memory_manager->allocate_memory(output_tensor); - kernel.execute(); - - EXPECT_THAT(extractTensorShape(output_tensor), ::testing::ElementsAreArray({1, 2, 4, 1})); - EXPECT_THAT(extractTensorData(output_tensor), ::testing::ElementsAreArray(ref_output_data)); -} - -TEST_F(GreaterTest, Uint8QuantizedBroadcast) -{ - std::vector x_data{ - 0.4, -0.8, 0.7, 0.3, // Row 1 - -0.5, 0.1, 0, 0.5, // Row 2 - 1, 0, 0.05, -1, // Row 3 - }; - - std::vector y_data{ - -1, 0.05, 0, 1, // Row 1 - }; - - std::vector ref_output_data{ - true, false, true, false, // Row 1 - true, true, false, false, // Row 2 - true, false, true, false, // Row 3 - }; - - std::pair quant_param = quantizationParams(F_MIN, F_MAX); - Tensor x_tensor = makeInputTensor( - {1, 3, 4, 1}, quant_param.first, quant_param.second, x_data, _memory_manager.get()); - Tensor y_tensor = makeInputTensor( - {1, 1, 4, 1}, quant_param.first, quant_param.second, y_data, _memory_manager.get()); - Tensor output_tensor = makeOutputTensor(DataType::BOOL); - - Greater kernel(&x_tensor, &y_tensor, &output_tensor); - kernel.configure(); - _memory_manager->allocate_memory(output_tensor); - kernel.execute(); - - EXPECT_THAT(extractTensorShape(output_tensor), ::testing::ElementsAreArray({1, 3, 4, 1})); - EXPECT_THAT(extractTensorData(output_tensor), ::testing::ElementsAreArray(ref_output_data)); -} - -TEST_F(GreaterTest, Input_Type_Mismatch_NEG) -{ - Tensor x_tensor = makeInputTensor({1}, {1.f}, _memory_manager.get()); - Tensor y_tensor = makeInputTensor({1}, {1}, _memory_manager.get()); - Tensor output_tensor = makeOutputTensor(DataType::BOOL); - - Greater kernel(&x_tensor, &y_tensor, &output_tensor); - EXPECT_ANY_THROW(kernel.configure()); -} - -TEST_F(GreaterTest, Input_Output_Type_NEG) -{ - Tensor x_tensor = makeInputTensor({1}, {1.f}, _memory_manager.get()); - Tensor y_tensor = makeInputTensor({1}, {1.f}, _memory_manager.get()); - Tensor output_tensor = makeOutputTensor(DataType::FLOAT32); - - Greater kernel(&x_tensor, &y_tensor, &output_tensor); - EXPECT_ANY_THROW(kernel.configure()); -} - -TEST_F(GreaterTest, Float_Broadcast_NEG) -{ - Tensor x_tensor = makeInputTensor({2}, {1.f, 2.f}, _memory_manager.get()); - Tensor y_tensor = makeInputTensor({3}, {1.f, 2.f, 3.f}, _memory_manager.get()); - Tensor output_tensor = makeOutputTensor(DataType::BOOL); - - Greater kernel(&x_tensor, &y_tensor, &output_tensor); - EXPECT_ANY_THROW(kernel.configure()); -} - -TEST_F(GreaterTest, Int32_Broadcast_NEG) -{ - Tensor x_tensor = makeInputTensor({2}, {1, 2}, _memory_manager.get()); - Tensor y_tensor = makeInputTensor({3}, {1, 2, 3}, _memory_manager.get()); - Tensor output_tensor = makeOutputTensor(DataType::BOOL); - - Greater kernel(&x_tensor, &y_tensor, &output_tensor); - EXPECT_ANY_THROW(kernel.configure()); -} - -TEST_F(GreaterTest, Int64_Broadcast_NEG) -{ - Tensor x_tensor = makeInputTensor({2}, {1, 2}, _memory_manager.get()); - Tensor y_tensor = makeInputTensor({3}, {1, 2, 3}, _memory_manager.get()); - Tensor output_tensor = makeOutputTensor(DataType::BOOL); - - Greater kernel(&x_tensor, &y_tensor, &output_tensor); - EXPECT_ANY_THROW(kernel.configure()); + const bool is_with_broadcast = false; + test_kernel::TestDataFloatGreater test_data_kernel(is_with_broadcast, true); + EXPECT_DEATH(checkGreaterKernel(&test_data_kernel), ""); } } // namespace -} // namespace kernels } // namespace luci_interpreter diff --git a/onert-micro/luci-interpreter/src/kernels/GreaterEqual.cpp b/onert-micro/luci-interpreter/src/kernels/GreaterEqual.cpp index 8f37160eaa5..dfb585d5abb 100644 --- a/onert-micro/luci-interpreter/src/kernels/GreaterEqual.cpp +++ b/onert-micro/luci-interpreter/src/kernels/GreaterEqual.cpp @@ -14,131 +14,77 @@ * limitations under the License. */ -#include "kernels/GreaterEqual.h" +#include "Builders.h" #include "kernels/Utils.h" +#include "TISOKernel.h" -#include +#include "PALComparisons.h" namespace luci_interpreter { -namespace kernels +namespace { - -GreaterEqual::GreaterEqual(const Tensor *x, const Tensor *y, Tensor *output) - : Kernel({x, y}, {output}) +// TODO: reduce code duplication with less +template +void evalGeneric(const circle::Tensor *x, const circle::Tensor *y, const circle::Tensor *output, + BaseRuntimeGraph *runtime_graph) { + auto x_data = kernels::getTensorData(runtime_graph->getDataByTensor(x)); + if (x_data == nullptr) + x_data = kernels::getTensorData(runtime_graph->getConstDataByTensor(x)); + + assert(x_data != nullptr); + + auto y_data = kernels::getTensorData(runtime_graph->getDataByTensor(y)); + if (y_data == nullptr) + y_data = kernels::getTensorData(runtime_graph->getConstDataByTensor(y)); + + assert(y_data != nullptr); + + auto output_data = kernels::getTensorData(runtime_graph->getDataByTensor(output)); + + luci_interpreter_pal::ComparisonParams op_params; + op_params.is_broadcast = Tensor::num_elements(x) != Tensor::num_elements(y); + + const int64_t flat_size = kernels::getTensorShape(x).flatSize(); + luci_interpreter_pal::ComparisonNoScaling(flat_size, x_data, y_data, output_data, + luci_interpreter_pal::GreaterEqualFn); } -void GreaterEqual::configure() +} // namespace + +void configure_kernel_CircleGreaterEqual(const circle::Operator *cur_op, + BaseRuntimeGraph *runtime_graph) { - LUCI_INTERPRETER_CHECK(x()->element_type() == y()->element_type()); - LUCI_INTERPRETER_CHECK(output()->element_type() == DataType::BOOL); + kernels::TISOKernel kernel(cur_op, runtime_graph); - if (x()->element_type() == DataType::U8) - { - quantizeMultiplierSmallerThanOneExp(x()->scale(), &_x_multiplier, &_x_shift); - quantizeMultiplierSmallerThanOneExp(y()->scale(), &_y_multiplier, &_y_shift); - } - // TODO: enable it only if kernel with dynamic shapes - output()->resize(calculateShapeForBroadcast(x()->shape(), y()->shape())); + LUCI_INTERPRETER_CHECK(Tensor::element_type(kernel.input1()) == + Tensor::element_type(kernel.input2())); + LUCI_INTERPRETER_CHECK(Tensor::element_type(kernel.output()) == DataType::BOOL); } -void GreaterEqual::execute() const +void execute_kernel_CircleGreaterEqual(const circle::Operator *cur_op, + BaseRuntimeGraph *runtime_graph) { - switch (x()->element_type()) + kernels::TISOKernel kernel(cur_op, runtime_graph); + + switch (Tensor::element_type(kernel.input1())) { - case DataType::FLOAT32: - evalFloat(); - break; case DataType::S64: - evalInteger(); + evalGeneric(kernel.input1(), kernel.input2(), kernel.output(), runtime_graph); break; case DataType::S32: - evalInteger(); + evalGeneric(kernel.input1(), kernel.input2(), kernel.output(), runtime_graph); break; - case DataType::U8: - evalQuantized(); +#ifndef DIS_FLOAT + case DataType::FLOAT32: + evalGeneric(kernel.input1(), kernel.input2(), kernel.output(), runtime_graph); break; +#endif // DIS_FLOAT default: assert(false && "Unsupported type."); } } -void GreaterEqual::evalFloat() const -{ - const auto x_data = getTensorData(x()); - const auto y_data = getTensorData(y()); - auto output_data = getTensorData(output()); - - tflite::ComparisonParams op_params; - op_params.is_broadcast = x()->shape() != y()->shape(); - - if (op_params.is_broadcast) - { - tflite::reference_ops::Broadcast4DSlowGreaterEqual(op_params, getTensorShape(x()), x_data, - getTensorShape(y()), y_data, - getTensorShape(output()), output_data); - } - else - { - tflite::reference_ops::GreaterEqual(op_params, getTensorShape(x()), x_data, getTensorShape(y()), - y_data, getTensorShape(output()), output_data); - } -} - -template void GreaterEqual::evalInteger() const -{ - const auto x_data = getTensorData(x()); - const auto y_data = getTensorData(y()); - auto output_data = getTensorData(output()); - - tflite::ComparisonParams op_params; - op_params.is_broadcast = x()->shape() != y()->shape(); - - if (op_params.is_broadcast) - { - tflite::reference_ops::Broadcast4DSlowGreaterEqualNoScaling( - op_params, getTensorShape(x()), x_data, getTensorShape(y()), y_data, getTensorShape(output()), - output_data); - } - else - { - tflite::reference_ops::GreaterEqualNoScaling(op_params, getTensorShape(x()), x_data, - getTensorShape(y()), y_data, - getTensorShape(output()), output_data); - } -} - -void GreaterEqual::evalQuantized() const -{ - const auto x_data = getTensorData(x()); - const auto y_data = getTensorData(y()); - auto output_data = getTensorData(output()); - - tflite::ComparisonParams op_params; - op_params.left_shift = 8; - op_params.input1_offset = -x()->zero_point(); // Note the '-' - op_params.input1_shift = _x_shift; - op_params.input1_multiplier = _x_multiplier; - op_params.input2_offset = -y()->zero_point(); // Note the '-' - op_params.input2_shift = _y_shift; - op_params.input2_multiplier = _y_multiplier; - op_params.is_broadcast = x()->shape() != y()->shape(); - - if (op_params.is_broadcast) - { - tflite::reference_ops::Broadcast4DSlowGreaterEqualWithScaling( - op_params, getTensorShape(x()), x_data, getTensorShape(y()), y_data, getTensorShape(output()), - output_data); - } - else - { - tflite::reference_ops::GreaterEqualWithScaling(op_params, getTensorShape(x()), x_data, - getTensorShape(y()), y_data, - getTensorShape(output()), output_data); - } -} - -} // namespace kernels } // namespace luci_interpreter diff --git a/onert-micro/luci-interpreter/src/kernels/GreaterEqual.h b/onert-micro/luci-interpreter/src/kernels/GreaterEqual.h deleted file mode 100644 index e333c30a6be..00000000000 --- a/onert-micro/luci-interpreter/src/kernels/GreaterEqual.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef LUCI_INTERPRETER_KERNELS_GREATER_EQUAL_H -#define LUCI_INTERPRETER_KERNELS_GREATER_EQUAL_H - -#include "core/Kernel.h" - -namespace luci_interpreter -{ -namespace kernels -{ - -class GreaterEqual : public Kernel -{ -public: - GreaterEqual(const Tensor *x, const Tensor *y, Tensor *output); - - const Tensor *x() const { return _inputs[0]; } - const Tensor *y() const { return _inputs[1]; } - Tensor *output() const { return _outputs[0]; } - - void configure() override; - void execute() const override; - -private: - void evalFloat() const; - template void evalInteger() const; - void evalQuantized() const; - -private: - int32_t _x_multiplier = 0; - int _x_shift = 0; - int32_t _y_multiplier = 0; - int _y_shift = 0; -}; - -} // namespace kernels -} // namespace luci_interpreter - -#endif // LUCI_INTERPRETER_KERNELS_GREATER_EQUAL_H diff --git a/onert-micro/luci-interpreter/src/kernels/GreaterEqual.test.cpp b/onert-micro/luci-interpreter/src/kernels/GreaterEqual.test.cpp index 35bf88eab33..4bc2e2b3618 100644 --- a/onert-micro/luci-interpreter/src/kernels/GreaterEqual.test.cpp +++ b/onert-micro/luci-interpreter/src/kernels/GreaterEqual.test.cpp @@ -15,14 +15,13 @@ * limitations under the License. */ -#include "kernels/GreaterEqual.h" #include "kernels/TestUtils.h" -#include "luci_interpreter/TestMemoryManager.h" +#include "luci_interpreter/test_models/greater_equal/FloatGreaterEqualKernel.h" + +#include "loader/ModuleLoader.h" namespace luci_interpreter { -namespace kernels -{ namespace { @@ -30,304 +29,61 @@ using namespace testing; class GreaterEqualTest : public ::testing::Test { -protected: - void SetUp() override { _memory_manager = std::make_unique(); } - - std::unique_ptr _memory_manager; + // Do nothing }; -TEST_F(GreaterEqualTest, FloatSimple) -{ - std::vector x_data{ - 0.5, 0.7, 0.9, // Row 1 - 1, 0, -1, // Row 2 - }; - - std::vector y_data{ - 0.9, 0.7, 0.5, // Row 1 - -1, 0, 1, // Row 2 - }; - - std::vector ref_output_data{ - false, true, true, // Row 1 - true, true, false, // Row 2 - }; - - Tensor x_tensor = makeInputTensor({2, 3}, x_data, _memory_manager.get()); - Tensor y_tensor = makeInputTensor({2, 3}, y_data, _memory_manager.get()); - Tensor output_tensor = makeOutputTensor(DataType::BOOL); - - GreaterEqual kernel(&x_tensor, &y_tensor, &output_tensor); - kernel.configure(); - _memory_manager->allocate_memory(output_tensor); - kernel.execute(); - - EXPECT_THAT(extractTensorData(output_tensor), ::testing::ElementsAreArray(ref_output_data)); - EXPECT_THAT(extractTensorShape(output_tensor), ::testing::ElementsAreArray({2, 3})); -} - -TEST_F(GreaterEqualTest, FloatBroardcast) -{ - std::vector x_data{ - 0.5, 0.7, 0.9, // Row 1 - 1, 0, -1, // Row 2 - -1, 0, 1, // Row 3 - }; - - std::vector y_data{ - 0.9, 0.7, 0.5, // Row 1 - }; - - std::vector ref_output_data{ - false, true, true, // Row 1 - true, false, false, // Row 2 - false, false, true, // Row 3 - }; - - Tensor x_tensor = makeInputTensor({3, 3}, x_data, _memory_manager.get()); - Tensor y_tensor = makeInputTensor({1, 3}, y_data, _memory_manager.get()); - Tensor output_tensor = makeOutputTensor(DataType::BOOL); - - GreaterEqual kernel(&x_tensor, &y_tensor, &output_tensor); - kernel.configure(); - _memory_manager->allocate_memory(output_tensor); - kernel.execute(); - - EXPECT_THAT(extractTensorData(output_tensor), ::testing::ElementsAreArray(ref_output_data)); - EXPECT_THAT(extractTensorShape(output_tensor), ::testing::ElementsAreArray({3, 3})); -} -template -void checkIntegerSimple(luci_interpreter::IMemoryManager *memory_manager) -{ - using dtype = typename loco::DataTypeImpl::Type; - dtype min_value = std::numeric_limits::min(); - dtype max_value = std::numeric_limits::max(); - std::vector x_data{min_value, 2, max_value}; - - std::vector y_data{min_value + 1, -2, max_value}; - - std::vector ref_output_data{false, true, true}; - - Tensor x_tensor = makeInputTensor({3}, x_data, memory_manager); - Tensor y_tensor = makeInputTensor({3}, y_data, memory_manager); - Tensor output_tensor = makeOutputTensor(DataType::BOOL); - - GreaterEqual kernel(&x_tensor, &y_tensor, &output_tensor); - kernel.configure(); - memory_manager->allocate_memory(output_tensor); - kernel.execute(); - - EXPECT_THAT(extractTensorData(output_tensor), ::testing::ElementsAreArray(ref_output_data)); - EXPECT_THAT(extractTensorShape(output_tensor), ::testing::ElementsAreArray({3})); -} - -template -void checkIntegerBroadcast(luci_interpreter::IMemoryManager *memory_manager) -{ - using dtype = typename loco::DataTypeImpl::Type; - dtype min_value = std::numeric_limits::min(); - dtype max_value = std::numeric_limits::max(); - std::vector x_data{ - min_value, 2, 3, // Row 1 - 4, 5, max_value, // Row 2 - -1, -4, -3, // Row 3 - min_value, -2, max_value - 1, // Row 4 - }; - - std::vector y_data{ - min_value + 1, -2, max_value - 1, // Row 1 - }; - - std::vector ref_output_data{ - false, true, false, // Row 1 - true, true, true, // Row 2 - true, false, false, // Row 3 - false, true, true, // Row 4 - }; - - Tensor x_tensor = makeInputTensor({4, 3}, x_data, memory_manager); - Tensor y_tensor = makeInputTensor({3}, y_data, memory_manager); - Tensor output_tensor = makeOutputTensor(DataType::BOOL); - - GreaterEqual kernel(&x_tensor, &y_tensor, &output_tensor); - kernel.configure(); - memory_manager->allocate_memory(output_tensor); - kernel.execute(); - - EXPECT_THAT(extractTensorData(output_tensor), ::testing::ElementsAreArray(ref_output_data)); - EXPECT_THAT(extractTensorShape(output_tensor), ::testing::ElementsAreArray({4, 3})); -} - -TEST_F(GreaterEqualTest, Int32) -{ - checkIntegerSimple(_memory_manager.get()); - checkIntegerBroadcast(_memory_manager.get()); - SUCCEED(); -} - -TEST_F(GreaterEqualTest, Int64) +template +std::vector checkGreaterEqualKernel(test_kernel::TestDataBase *test_data_base) { - checkIntegerSimple(_memory_manager.get()); - checkIntegerBroadcast(_memory_manager.get()); - SUCCEED(); -} - -// Choose min / max in such a way that there are exactly 256 units to avoid rounding errors. -const float F_MIN = -128.0 / 128.0; -const float F_MAX = 127.0 / 128.0; - -TEST_F(GreaterEqualTest, Uint8Quantized) -{ - std::vector x_data{ - 0.5, 0.6, 0.7, 0.9, // Row 1 - 1, 0, 0.05, -1, // Row 2 - }; - - std::vector y_data{ - 0.9, 0.6, 0.55, 0.5, // Row 1 - -1, 0.05, 0, 1, // Row 2 - }; - - std::vector ref_output_data{ - false, true, true, true, // Row 1 - true, false, true, false, // Row 2 - }; - - std::pair quant_param = quantizationParams(F_MIN, F_MAX); - Tensor x_tensor = makeInputTensor( - {1, 2, 4, 1}, quant_param.first, quant_param.second, x_data, _memory_manager.get()); - Tensor y_tensor = makeInputTensor( - {1, 2, 4, 1}, quant_param.first, quant_param.second, y_data, _memory_manager.get()); - Tensor output_tensor = makeOutputTensor(DataType::BOOL); + MemoryManager memory_manager{}; + RuntimeModule runtime_module{}; + bool dealloc_input = true; - GreaterEqual kernel(&x_tensor, &y_tensor, &output_tensor); - kernel.configure(); - _memory_manager->allocate_memory(output_tensor); - kernel.execute(); + // 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); - EXPECT_THAT(extractTensorShape(output_tensor), ::testing::ElementsAreArray({1, 2, 4, 1})); - EXPECT_THAT(extractTensorData(output_tensor), ::testing::ElementsAreArray(ref_output_data)); -} - -TEST_F(GreaterEqualTest, Uint8QuantizedRescale) -{ - std::vector x_data{ - 0.5, 0.5, 0.7, 0.9, // Row 1 - 1, 0, 0.05, -1, // Row 2 - }; + auto *main_runtime_graph = runtime_module.getMainGraph(); + assert(main_runtime_graph->getNumOfInputTensors() == 2); - std::vector y_data{ - 0.9, 0.5, 0.6, 0.5, // Row 1 - -1, 0.05, 0, 1, // Row 2 - }; + // set left input data + { + auto *input_tensor_data = reinterpret_cast(main_runtime_graph->configureGraphInput(0)); + std::copy(test_data_base->get_input_data_by_index(0).begin(), + test_data_base->get_input_data_by_index(0).end(), input_tensor_data); + } - std::vector ref_output_data{ - false, true, true, true, // Row 1 - true, false, true, false, // Row 2 - }; + // set right input data + { + auto *input_tensor_data = reinterpret_cast(main_runtime_graph->configureGraphInput(1)); + std::copy(test_data_base->get_input_data_by_index(1).begin(), + test_data_base->get_input_data_by_index(1).end(), input_tensor_data); + } - std::pair x_quant_param = quantizationParams(F_MIN, F_MAX); - std::pair y_quant_param = quantizationParams(F_MIN * 1.2, F_MAX * 1.5); + runtime_module.execute(); - Tensor x_tensor = makeInputTensor( - {1, 2, 4, 1}, x_quant_param.first, x_quant_param.second, x_data, _memory_manager.get()); - Tensor y_tensor = makeInputTensor( - {1, 2, 4, 1}, y_quant_param.first, y_quant_param.second, y_data, _memory_manager.get()); - Tensor output_tensor = makeOutputTensor(DataType::BOOL); + assert(main_runtime_graph->getNumOfOutputTensors() == 1); - GreaterEqual kernel(&x_tensor, &y_tensor, &output_tensor); - kernel.configure(); - _memory_manager->allocate_memory(output_tensor); - kernel.execute(); - - EXPECT_THAT(extractTensorShape(output_tensor), ::testing::ElementsAreArray({1, 2, 4, 1})); - EXPECT_THAT(extractTensorData(output_tensor), ::testing::ElementsAreArray(ref_output_data)); + U *output_data = reinterpret_cast(main_runtime_graph->getOutputDataByIndex(0)); + const size_t num_elements = (main_runtime_graph->getOutputDataSizeByIndex(0) / sizeof(U)); + std::vector output_data_vector(output_data, output_data + num_elements); + return output_data_vector; } -TEST_F(GreaterEqualTest, Uint8QuantizedBroadcast) +TEST_F(GreaterEqualTest, FloatNoBroadcast_P) { - std::vector x_data{ - 0.4, -0.8, 0.7, 0.3, // Row 1 - -0.5, 0.1, 0, 0.5, // Row 2 - 1, 0, 0.05, -1, // Row 3 - }; - - std::vector y_data{ - -1, 0.05, 0, 1, // Row 1 - }; - - std::vector ref_output_data{ - true, false, true, false, // Row 1 - true, true, true, false, // Row 2 - true, false, true, false, // Row 3 - }; - - std::pair quant_param = quantizationParams(F_MIN, F_MAX); - Tensor x_tensor = makeInputTensor( - {1, 3, 4, 1}, quant_param.first, quant_param.second, x_data, _memory_manager.get()); - Tensor y_tensor = makeInputTensor( - {1, 1, 4, 1}, quant_param.first, quant_param.second, y_data, _memory_manager.get()); - Tensor output_tensor = makeOutputTensor(DataType::BOOL); - - GreaterEqual kernel(&x_tensor, &y_tensor, &output_tensor); - kernel.configure(); - _memory_manager->allocate_memory(output_tensor); - kernel.execute(); - - EXPECT_THAT(extractTensorShape(output_tensor), ::testing::ElementsAreArray({1, 3, 4, 1})); - EXPECT_THAT(extractTensorData(output_tensor), ::testing::ElementsAreArray(ref_output_data)); + const bool is_with_broadcast = false; + test_kernel::TestDataFloatGreaterEqual test_data_kernel(is_with_broadcast, false); + std::vector output_data_vector = checkGreaterEqualKernel(&test_data_kernel); + EXPECT_THAT(output_data_vector, test_data_kernel.get_output_data_by_index(0)); } -TEST_F(GreaterEqualTest, Input_Type_Mismatch_NEG) +TEST_F(GreaterEqualTest, FloatNoBroadcast_NEG) { - Tensor x_tensor = makeInputTensor({1}, {1.f}, _memory_manager.get()); - Tensor y_tensor = makeInputTensor({1}, {1}, _memory_manager.get()); - Tensor output_tensor = makeOutputTensor(DataType::BOOL); - - GreaterEqual kernel(&x_tensor, &y_tensor, &output_tensor); - EXPECT_ANY_THROW(kernel.configure()); -} - -TEST_F(GreaterEqualTest, Input_Output_Type_NEG) -{ - Tensor x_tensor = makeInputTensor({1}, {1.f}, _memory_manager.get()); - Tensor y_tensor = makeInputTensor({1}, {1.f}, _memory_manager.get()); - Tensor output_tensor = makeOutputTensor(DataType::FLOAT32); - - GreaterEqual kernel(&x_tensor, &y_tensor, &output_tensor); - EXPECT_ANY_THROW(kernel.configure()); -} - -TEST_F(GreaterEqualTest, Float_Broadcast_NEG) -{ - Tensor x_tensor = makeInputTensor({2}, {1.f, 2.f}, _memory_manager.get()); - Tensor y_tensor = makeInputTensor({3}, {1.f, 2.f, 3.f}, _memory_manager.get()); - Tensor output_tensor = makeOutputTensor(DataType::BOOL); - - GreaterEqual kernel(&x_tensor, &y_tensor, &output_tensor); - EXPECT_ANY_THROW(kernel.configure()); -} - -TEST_F(GreaterEqualTest, Int32_Broadcast_NEG) -{ - Tensor x_tensor = makeInputTensor({2}, {1, 2}, _memory_manager.get()); - Tensor y_tensor = makeInputTensor({3}, {1, 2, 3}, _memory_manager.get()); - Tensor output_tensor = makeOutputTensor(DataType::BOOL); - - GreaterEqual kernel(&x_tensor, &y_tensor, &output_tensor); - EXPECT_ANY_THROW(kernel.configure()); -} - -TEST_F(GreaterEqualTest, Int64_Broadcast_NEG) -{ - Tensor x_tensor = makeInputTensor({2}, {1, 2}, _memory_manager.get()); - Tensor y_tensor = makeInputTensor({3}, {1, 2, 3}, _memory_manager.get()); - Tensor output_tensor = makeOutputTensor(DataType::BOOL); - - GreaterEqual kernel(&x_tensor, &y_tensor, &output_tensor); - EXPECT_ANY_THROW(kernel.configure()); + const bool is_with_broadcast = false; + test_kernel::TestDataFloatGreaterEqual test_data_kernel(is_with_broadcast, true); + EXPECT_DEATH(checkGreaterEqualKernel(&test_data_kernel), ""); } } // namespace -} // namespace kernels } // namespace luci_interpreter diff --git a/onert-micro/luci-interpreter/src/kernels/Less.cpp b/onert-micro/luci-interpreter/src/kernels/Less.cpp index b0459e2e490..4a688e463b9 100644 --- a/onert-micro/luci-interpreter/src/kernels/Less.cpp +++ b/onert-micro/luci-interpreter/src/kernels/Less.cpp @@ -64,16 +64,15 @@ void evalQuantized(const circle::Tensor *x, const circle::Tensor *y, const circl if (op_params.is_broadcast) { - luci_interpreter_pal::BroadcastComparison4DSlowWithScaling( + luci_interpreter_pal::BroadcastComparison4DSlowWithScaling( op_params, kernels::getTensorShape(x), x_data, kernels::getTensorShape(y), y_data, - kernels::getTensorShape(output), output_data); + kernels::getTensorShape(output), output_data, luci_interpreter_pal::LessFn); } else { const int64_t flat_size = kernels::getTensorShape(x).flatSize(); - luci_interpreter_pal::ComparisonWithScaling( - op_params, flat_size, x_data, y_data, output_data); + luci_interpreter_pal::ComparisonWithScaling(op_params, flat_size, x_data, y_data, + output_data, luci_interpreter_pal::LessFn); } } #endif // DIS_QUANT @@ -101,15 +100,15 @@ void evalGeneric(const circle::Tensor *x, const circle::Tensor *y, const circle: if (op_params.is_broadcast) { - luci_interpreter_pal::BroadcastComparison4DSlowNoScaling( + luci_interpreter_pal::BroadcastComparison4DSlowNoScaling( op_params, kernels::getTensorShape(x), x_data, kernels::getTensorShape(y), y_data, - kernels::getTensorShape(output), output_data); + kernels::getTensorShape(output), output_data, luci_interpreter_pal::LessFn); } else { const int64_t flat_size = kernels::getTensorShape(x).flatSize(); - luci_interpreter_pal::ComparisonNoScaling(flat_size, x_data, - y_data, output_data); + luci_interpreter_pal::ComparisonNoScaling(flat_size, x_data, y_data, output_data, + luci_interpreter_pal::LessFn); } } diff --git a/onert-micro/luci-interpreter/src/kernels/LessEqual.cpp b/onert-micro/luci-interpreter/src/kernels/LessEqual.cpp index d7508936d47..8928ba4e1a7 100644 --- a/onert-micro/luci-interpreter/src/kernels/LessEqual.cpp +++ b/onert-micro/luci-interpreter/src/kernels/LessEqual.cpp @@ -14,128 +14,76 @@ * limitations under the License. */ -#include "kernels/LessEqual.h" +#include "Builders.h" #include "kernels/Utils.h" +#include "TISOKernel.h" -#include +#include "PALComparisons.h" namespace luci_interpreter { -namespace kernels +namespace { +// TODO: reduce code duplication with less +template +void evalGeneric(const circle::Tensor *x, const circle::Tensor *y, const circle::Tensor *output, + BaseRuntimeGraph *runtime_graph) +{ + auto x_data = kernels::getTensorData(runtime_graph->getDataByTensor(x)); + if (x_data == nullptr) + x_data = kernels::getTensorData(runtime_graph->getConstDataByTensor(x)); + + assert(x_data != nullptr); + + auto y_data = kernels::getTensorData(runtime_graph->getDataByTensor(y)); + if (y_data == nullptr) + y_data = kernels::getTensorData(runtime_graph->getConstDataByTensor(y)); + + assert(y_data != nullptr); + + auto output_data = kernels::getTensorData(runtime_graph->getDataByTensor(output)); -LessEqual::LessEqual(const Tensor *x, const Tensor *y, Tensor *output) : Kernel({x, y}, {output}) {} + luci_interpreter_pal::ComparisonParams op_params; + op_params.is_broadcast = Tensor::num_elements(x) != Tensor::num_elements(y); -void LessEqual::configure() + const int64_t flat_size = kernels::getTensorShape(x).flatSize(); + luci_interpreter_pal::ComparisonNoScaling(flat_size, x_data, y_data, output_data, + luci_interpreter_pal::LessEqualFn); +} + +} // namespace + +void configure_kernel_CircleLessEqual(const circle::Operator *cur_op, + BaseRuntimeGraph *runtime_graph) { - LUCI_INTERPRETER_CHECK(x()->element_type() == y()->element_type()); - LUCI_INTERPRETER_CHECK(output()->element_type() == DataType::BOOL); + kernels::TISOKernel kernel(cur_op, runtime_graph); - if (x()->element_type() == DataType::U8) - { - quantizeMultiplierSmallerThanOneExp(x()->scale(), &_x_multiplier, &_x_shift); - quantizeMultiplierSmallerThanOneExp(y()->scale(), &_y_multiplier, &_y_shift); - } - // TODO: enable it only if kernel with dynamic shapes - output()->resize(calculateShapeForBroadcast(x()->shape(), y()->shape())); + LUCI_INTERPRETER_CHECK(Tensor::element_type(kernel.input1()) == + Tensor::element_type(kernel.input2())); + LUCI_INTERPRETER_CHECK(Tensor::element_type(kernel.output()) == DataType::BOOL); } -void LessEqual::execute() const +void execute_kernel_CircleLessEqual(const circle::Operator *cur_op, BaseRuntimeGraph *runtime_graph) { - switch (x()->element_type()) + kernels::TISOKernel kernel(cur_op, runtime_graph); + + switch (Tensor::element_type(kernel.input1())) { - case DataType::FLOAT32: - evalFloat(); - break; case DataType::S64: - evalInteger(); + evalGeneric(kernel.input1(), kernel.input2(), kernel.output(), runtime_graph); break; case DataType::S32: - evalInteger(); + evalGeneric(kernel.input1(), kernel.input2(), kernel.output(), runtime_graph); break; - case DataType::U8: - evalQuantized(); +#ifndef DIS_FLOAT + case DataType::FLOAT32: + evalGeneric(kernel.input1(), kernel.input2(), kernel.output(), runtime_graph); break; +#endif // DIS_FLOAT default: assert(false && "Unsupported type."); } } -void LessEqual::evalFloat() const -{ - const auto x_data = getTensorData(x()); - const auto y_data = getTensorData(y()); - auto output_data = getTensorData(output()); - - tflite::ComparisonParams op_params; - op_params.is_broadcast = x()->shape() != y()->shape(); - - if (op_params.is_broadcast) - { - tflite::reference_ops::Broadcast4DSlowLessEqual(op_params, getTensorShape(x()), x_data, - getTensorShape(y()), y_data, - getTensorShape(output()), output_data); - } - else - { - tflite::reference_ops::LessEqual(op_params, getTensorShape(x()), x_data, getTensorShape(y()), - y_data, getTensorShape(output()), output_data); - } -} - -template void LessEqual::evalInteger() const -{ - const auto x_data = getTensorData(x()); - const auto y_data = getTensorData(y()); - auto output_data = getTensorData(output()); - - tflite::ComparisonParams op_params; - op_params.is_broadcast = x()->shape() != y()->shape(); - - if (op_params.is_broadcast) - { - tflite::reference_ops::Broadcast4DSlowLessEqualNoScaling(op_params, getTensorShape(x()), x_data, - getTensorShape(y()), y_data, - getTensorShape(output()), output_data); - } - else - { - tflite::reference_ops::LessEqualNoScaling(op_params, getTensorShape(x()), x_data, - getTensorShape(y()), y_data, getTensorShape(output()), - output_data); - } -} - -void LessEqual::evalQuantized() const -{ - const auto x_data = getTensorData(x()); - const auto y_data = getTensorData(y()); - auto output_data = getTensorData(output()); - - tflite::ComparisonParams op_params; - op_params.left_shift = 8; - op_params.input1_offset = -x()->zero_point(); // Note the '-' - op_params.input1_shift = _x_shift; - op_params.input1_multiplier = _x_multiplier; - op_params.input2_offset = -y()->zero_point(); // Note the '-' - op_params.input2_shift = _y_shift; - op_params.input2_multiplier = _y_multiplier; - op_params.is_broadcast = x()->shape() != y()->shape(); - - if (op_params.is_broadcast) - { - tflite::reference_ops::Broadcast4DSlowLessEqualWithScaling( - op_params, getTensorShape(x()), x_data, getTensorShape(y()), y_data, getTensorShape(output()), - output_data); - } - else - { - tflite::reference_ops::LessEqualWithScaling(op_params, getTensorShape(x()), x_data, - getTensorShape(y()), y_data, - getTensorShape(output()), output_data); - } -} - -} // namespace kernels } // namespace luci_interpreter diff --git a/onert-micro/luci-interpreter/src/kernels/LessEqual.h b/onert-micro/luci-interpreter/src/kernels/LessEqual.h deleted file mode 100644 index f82ea90d4f2..00000000000 --- a/onert-micro/luci-interpreter/src/kernels/LessEqual.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef LUCI_INTERPRETER_KERNELS_LESS_EQUAL_H -#define LUCI_INTERPRETER_KERNELS_LESS_EQUAL_H - -#include "core/Kernel.h" - -namespace luci_interpreter -{ -namespace kernels -{ - -class LessEqual : public Kernel -{ -public: - LessEqual(const Tensor *x, const Tensor *y, Tensor *output); - - const Tensor *x() const { return _inputs[0]; } - const Tensor *y() const { return _inputs[1]; } - Tensor *output() const { return _outputs[0]; } - - void configure() override; - void execute() const override; - -private: - void evalFloat() const; - template void evalInteger() const; - void evalQuantized() const; - -private: - int32_t _x_multiplier = 0; - int _x_shift = 0; - int32_t _y_multiplier = 0; - int _y_shift = 0; -}; - -} // namespace kernels -} // namespace luci_interpreter - -#endif // LUCI_INTERPRETER_KERNELS_LESS_EQUAL_H diff --git a/onert-micro/luci-interpreter/src/kernels/LessEqual.test.cpp b/onert-micro/luci-interpreter/src/kernels/LessEqual.test.cpp index b2e2fa7a1dc..e53dc05a42a 100644 --- a/onert-micro/luci-interpreter/src/kernels/LessEqual.test.cpp +++ b/onert-micro/luci-interpreter/src/kernels/LessEqual.test.cpp @@ -15,14 +15,13 @@ * limitations under the License. */ -#include "kernels/LessEqual.h" #include "kernels/TestUtils.h" -#include "luci_interpreter/TestMemoryManager.h" +#include "luci_interpreter/test_models/less_equal/FloatLessEqualKernel.h" + +#include "loader/ModuleLoader.h" namespace luci_interpreter { -namespace kernels -{ namespace { @@ -30,305 +29,61 @@ using namespace testing; class LessEqualTest : public ::testing::Test { -protected: - void SetUp() override { _memory_manager = std::make_unique(); } - - std::unique_ptr _memory_manager; + // Do nothing }; -TEST_F(LessEqualTest, FloatSimple) -{ - std::vector x_data{ - 0.5, 0.7, 0.9, // Row 1 - 1, 0, -1, // Row 2 - }; - - std::vector y_data{ - 0.9, 0.7, 0.5, // Row 1 - -1, 0, 1, // Row 2 - }; - - std::vector ref_output_data{ - true, true, false, // Row 1 - false, true, true, // Row 2 - }; - - Tensor x_tensor = makeInputTensor({2, 3}, x_data, _memory_manager.get()); - Tensor y_tensor = makeInputTensor({2, 3}, y_data, _memory_manager.get()); - Tensor output_tensor = makeOutputTensor(DataType::BOOL); - - LessEqual kernel(&x_tensor, &y_tensor, &output_tensor); - kernel.configure(); - _memory_manager->allocate_memory(output_tensor); - kernel.execute(); - - EXPECT_THAT(extractTensorData(output_tensor), ::testing::ElementsAreArray(ref_output_data)); - EXPECT_THAT(extractTensorShape(output_tensor), ::testing::ElementsAreArray({2, 3})); -} - -TEST_F(LessEqualTest, FloatBroardcast) -{ - std::vector x_data{ - 0.5, 0.7, 0.9, // Row 1 - 1, 0, -1, // Row 2 - -1, 0, 1, // Row 3 - }; - - std::vector y_data{ - 0.9, 0.7, 0.5, // Row 1 - }; - - std::vector ref_output_data{ - true, true, false, // Row 1 - false, true, true, // Row 2 - true, true, false, // Row 3 - }; - - Tensor x_tensor = makeInputTensor({3, 3}, x_data, _memory_manager.get()); - Tensor y_tensor = makeInputTensor({1, 3}, y_data, _memory_manager.get()); - Tensor output_tensor = makeOutputTensor(DataType::BOOL); - - LessEqual kernel(&x_tensor, &y_tensor, &output_tensor); - kernel.configure(); - _memory_manager->allocate_memory(output_tensor); - kernel.execute(); - - EXPECT_THAT(extractTensorData(output_tensor), ::testing::ElementsAreArray(ref_output_data)); - EXPECT_THAT(extractTensorShape(output_tensor), ::testing::ElementsAreArray({3, 3})); -} - -template -void checkIntegerSimple(luci_interpreter::IMemoryManager *memory_manager) +template +std::vector checkLessEqualKernel(test_kernel::TestDataBase *test_data_base) { - using dtype = typename loco::DataTypeImpl::Type; - dtype min_value = std::numeric_limits::min(); - dtype max_value = std::numeric_limits::max(); - std::vector x_data{min_value, 2, max_value}; - - std::vector y_data{min_value + 1, -2, max_value}; + MemoryManager memory_manager{}; + RuntimeModule runtime_module{}; + bool dealloc_input = true; - std::vector ref_output_data{true, false, 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); - Tensor x_tensor = makeInputTensor({3}, x_data, memory_manager); - Tensor y_tensor = makeInputTensor({3}, y_data, memory_manager); - Tensor output_tensor = makeOutputTensor(DataType::BOOL); + auto *main_runtime_graph = runtime_module.getMainGraph(); + assert(main_runtime_graph->getNumOfInputTensors() == 2); - LessEqual kernel(&x_tensor, &y_tensor, &output_tensor); - kernel.configure(); - memory_manager->allocate_memory(output_tensor); - kernel.execute(); + // set left input data + { + auto *input_tensor_data = reinterpret_cast(main_runtime_graph->configureGraphInput(0)); + std::copy(test_data_base->get_input_data_by_index(0).begin(), + test_data_base->get_input_data_by_index(0).end(), input_tensor_data); + } - EXPECT_THAT(extractTensorData(output_tensor), ::testing::ElementsAreArray(ref_output_data)); - EXPECT_THAT(extractTensorShape(output_tensor), ::testing::ElementsAreArray({3})); -} - -template -void checkIntegerBroadcast(luci_interpreter::IMemoryManager *memory_manager) -{ - using dtype = typename loco::DataTypeImpl::Type; - dtype min_value = std::numeric_limits::min(); - dtype max_value = std::numeric_limits::max(); - std::vector x_data{ - min_value, 2, 3, // Row 1 - 4, 5, max_value, // Row 2 - -1, -4, -3, // Row 3 - min_value, -2, max_value, // Row 4 - }; + // set right input data + { + auto *input_tensor_data = reinterpret_cast(main_runtime_graph->configureGraphInput(1)); + std::copy(test_data_base->get_input_data_by_index(1).begin(), + test_data_base->get_input_data_by_index(1).end(), input_tensor_data); + } - std::vector y_data{ - min_value + 1, -2, max_value - 1, // Row 1 - }; + runtime_module.execute(); - std::vector ref_output_data{ - true, false, true, // Row 1 - false, false, false, // Row 2 - false, true, true, // Row 3 - true, true, false, // Row 4 - }; - - Tensor x_tensor = makeInputTensor({4, 3}, x_data, memory_manager); - Tensor y_tensor = makeInputTensor({3}, y_data, memory_manager); - Tensor output_tensor = makeOutputTensor(DataType::BOOL); - - LessEqual kernel(&x_tensor, &y_tensor, &output_tensor); - kernel.configure(); - memory_manager->allocate_memory(output_tensor); - kernel.execute(); - - EXPECT_THAT(extractTensorData(output_tensor), ::testing::ElementsAreArray(ref_output_data)); - EXPECT_THAT(extractTensorShape(output_tensor), ::testing::ElementsAreArray({4, 3})); -} + assert(main_runtime_graph->getNumOfOutputTensors() == 1); -TEST_F(LessEqualTest, Int32) -{ - checkIntegerSimple(_memory_manager.get()); - checkIntegerBroadcast(_memory_manager.get()); - SUCCEED(); + U *output_data = reinterpret_cast(main_runtime_graph->getOutputDataByIndex(0)); + const size_t num_elements = (main_runtime_graph->getOutputDataSizeByIndex(0) / sizeof(U)); + std::vector output_data_vector(output_data, output_data + num_elements); + return output_data_vector; } -TEST_F(LessEqualTest, Int64) +TEST_F(LessEqualTest, FloatNoBroadcast_P) { - checkIntegerSimple(_memory_manager.get()); - checkIntegerBroadcast(_memory_manager.get()); - SUCCEED(); + const bool is_with_broadcast = false; + test_kernel::TestDataFloatLessEqual test_data_kernel(is_with_broadcast, false); + std::vector output_data_vector = checkLessEqualKernel(&test_data_kernel); + EXPECT_THAT(output_data_vector, test_data_kernel.get_output_data_by_index(0)); } -// Choose min / max in such a way that there are exactly 256 units to avoid rounding errors. -const float F_MIN = -128.0 / 128.0; -const float F_MAX = 127.0 / 128.0; - -TEST_F(LessEqualTest, Uint8Quantized) +TEST_F(LessEqualTest, FloatNoBroadcast_NEG) { - std::vector x_data{ - 0.5, 0.6, 0.7, 0.9, // Row 1 - 1, 0, 0.05, -1, // Row 2 - }; - - std::vector y_data{ - 0.9, 0.6, 0.55, 0.5, // Row 1 - -1, 0.05, 0, 1, // Row 2 - }; - - std::vector ref_output_data{ - true, true, false, false, // Row 1 - false, true, false, true, // Row 2 - }; - - std::pair quant_param = quantizationParams(F_MIN, F_MAX); - Tensor x_tensor = makeInputTensor( - {1, 2, 4, 1}, quant_param.first, quant_param.second, x_data, _memory_manager.get()); - Tensor y_tensor = makeInputTensor( - {1, 2, 4, 1}, quant_param.first, quant_param.second, y_data, _memory_manager.get()); - Tensor output_tensor = makeOutputTensor(DataType::BOOL); - - LessEqual kernel(&x_tensor, &y_tensor, &output_tensor); - kernel.configure(); - _memory_manager->allocate_memory(output_tensor); - kernel.execute(); - - EXPECT_THAT(extractTensorShape(output_tensor), ::testing::ElementsAreArray({1, 2, 4, 1})); - EXPECT_THAT(extractTensorData(output_tensor), ::testing::ElementsAreArray(ref_output_data)); -} - -TEST_F(LessEqualTest, Uint8QuantizedRescale) -{ - std::vector x_data{ - 0.5, 0.6, 0.7, 0.9, // Row 1 - 1, 0, 0.05, -1, // Row 2 - }; - - std::vector y_data{ - 0.9, 0.6, 0.6, 0.5, // Row 1 - -1, 0.05, 0, 1, // Row 2 - }; - - std::vector ref_output_data{ - true, true, false, false, // Row 1 - false, true, false, true, // Row 2 - }; - - std::pair x_quant_param = quantizationParams(F_MIN, F_MAX); - std::pair y_quant_param = quantizationParams(F_MIN * 1.2, F_MAX * 1.5); - - Tensor x_tensor = makeInputTensor( - {1, 2, 4, 1}, x_quant_param.first, x_quant_param.second, x_data, _memory_manager.get()); - Tensor y_tensor = makeInputTensor( - {1, 2, 4, 1}, y_quant_param.first, y_quant_param.second, y_data, _memory_manager.get()); - Tensor output_tensor = makeOutputTensor(DataType::BOOL); - - LessEqual kernel(&x_tensor, &y_tensor, &output_tensor); - kernel.configure(); - _memory_manager->allocate_memory(output_tensor); - kernel.execute(); - - EXPECT_THAT(extractTensorShape(output_tensor), ::testing::ElementsAreArray({1, 2, 4, 1})); - EXPECT_THAT(extractTensorData(output_tensor), ::testing::ElementsAreArray(ref_output_data)); -} - -TEST_F(LessEqualTest, Uint8QuantizedBroadcast) -{ - std::vector x_data{ - 0.4, -0.8, 0.7, 0.3, // Row 1 - -0.5, 0.1, 0, 0.5, // Row 2 - 1, 0, 0.05, -1, // Row 3 - }; - - std::vector y_data{ - -1, 0.05, 0, 1, // Row 1 - }; - - std::vector ref_output_data{ - false, true, false, true, // Row 1 - false, false, true, true, // Row 2 - false, true, false, true, // Row 3 - }; - - std::pair quant_param = quantizationParams(F_MIN, F_MAX); - Tensor x_tensor = makeInputTensor( - {1, 3, 4, 1}, quant_param.first, quant_param.second, x_data, _memory_manager.get()); - Tensor y_tensor = makeInputTensor( - {1, 1, 4, 1}, quant_param.first, quant_param.second, y_data, _memory_manager.get()); - Tensor output_tensor = makeOutputTensor(DataType::BOOL); - - LessEqual kernel(&x_tensor, &y_tensor, &output_tensor); - kernel.configure(); - _memory_manager->allocate_memory(output_tensor); - kernel.execute(); - - EXPECT_THAT(extractTensorShape(output_tensor), ::testing::ElementsAreArray({1, 3, 4, 1})); - EXPECT_THAT(extractTensorData(output_tensor), ::testing::ElementsAreArray(ref_output_data)); -} - -TEST_F(LessEqualTest, Input_Type_Mismatch_NEG) -{ - Tensor x_tensor = makeInputTensor({1}, {1.f}, _memory_manager.get()); - Tensor y_tensor = makeInputTensor({1}, {1}, _memory_manager.get()); - Tensor output_tensor = makeOutputTensor(DataType::BOOL); - - LessEqual kernel(&x_tensor, &y_tensor, &output_tensor); - EXPECT_ANY_THROW(kernel.configure()); -} - -TEST_F(LessEqualTest, Input_Output_Type_NEG) -{ - Tensor x_tensor = makeInputTensor({1}, {1.f}, _memory_manager.get()); - Tensor y_tensor = makeInputTensor({1}, {1.f}, _memory_manager.get()); - Tensor output_tensor = makeOutputTensor(DataType::FLOAT32); - - LessEqual kernel(&x_tensor, &y_tensor, &output_tensor); - EXPECT_ANY_THROW(kernel.configure()); -} - -TEST_F(LessEqualTest, Float_Broadcast_NEG) -{ - Tensor x_tensor = makeInputTensor({2}, {1.f, 2.f}, _memory_manager.get()); - Tensor y_tensor = makeInputTensor({3}, {1.f, 2.f, 3.f}, _memory_manager.get()); - Tensor output_tensor = makeOutputTensor(DataType::BOOL); - - LessEqual kernel(&x_tensor, &y_tensor, &output_tensor); - ASSERT_ANY_THROW(kernel.configure()); -} - -TEST_F(LessEqualTest, Int32_Broadcast_NEG) -{ - Tensor x_tensor = makeInputTensor({2}, {1, 2}, _memory_manager.get()); - Tensor y_tensor = makeInputTensor({3}, {1, 2, 3}, _memory_manager.get()); - Tensor output_tensor = makeOutputTensor(DataType::BOOL); - - LessEqual kernel(&x_tensor, &y_tensor, &output_tensor); - ASSERT_ANY_THROW(kernel.configure()); -} - -TEST_F(LessEqualTest, Int64_Broadcast_NEG) -{ - Tensor x_tensor = makeInputTensor({2}, {1, 2}, _memory_manager.get()); - Tensor y_tensor = makeInputTensor({3}, {1, 2, 3}, _memory_manager.get()); - Tensor output_tensor = makeOutputTensor(DataType::BOOL); - - LessEqual kernel(&x_tensor, &y_tensor, &output_tensor); - ASSERT_ANY_THROW(kernel.configure()); + const bool is_with_broadcast = false; + test_kernel::TestDataFloatLessEqual test_data_kernel(is_with_broadcast, true); + EXPECT_DEATH(checkLessEqualKernel(&test_data_kernel), ""); } } // namespace -} // namespace kernels } // namespace luci_interpreter diff --git a/onert-micro/luci-interpreter/src/kernels/NotEqual.cpp b/onert-micro/luci-interpreter/src/kernels/NotEqual.cpp index 8c3983e47ed..92f646f95e6 100644 --- a/onert-micro/luci-interpreter/src/kernels/NotEqual.cpp +++ b/onert-micro/luci-interpreter/src/kernels/NotEqual.cpp @@ -14,128 +14,76 @@ * limitations under the License. */ -#include "kernels/NotEqual.h" +#include "Builders.h" #include "kernels/Utils.h" +#include "TISOKernel.h" -#include +#include "PALComparisons.h" namespace luci_interpreter { -namespace kernels +namespace { +// TODO: reduce code duplication with less +template +void evalGeneric(const circle::Tensor *x, const circle::Tensor *y, const circle::Tensor *output, + BaseRuntimeGraph *runtime_graph) +{ + auto x_data = kernels::getTensorData(runtime_graph->getDataByTensor(x)); + if (x_data == nullptr) + x_data = kernels::getTensorData(runtime_graph->getConstDataByTensor(x)); + + assert(x_data != nullptr); + + auto y_data = kernels::getTensorData(runtime_graph->getDataByTensor(y)); + if (y_data == nullptr) + y_data = kernels::getTensorData(runtime_graph->getConstDataByTensor(y)); + + assert(y_data != nullptr); + + auto output_data = kernels::getTensorData(runtime_graph->getDataByTensor(output)); -NotEqual::NotEqual(const Tensor *x, const Tensor *y, Tensor *output) : Kernel({x, y}, {output}) {} + luci_interpreter_pal::ComparisonParams op_params; + op_params.is_broadcast = Tensor::num_elements(x) != Tensor::num_elements(y); -void NotEqual::configure() + const int64_t flat_size = kernels::getTensorShape(x).flatSize(); + luci_interpreter_pal::ComparisonNoScaling(flat_size, x_data, y_data, output_data, + luci_interpreter_pal::NotEqualFn); +} + +} // namespace + +void configure_kernel_CircleNotEqual(const circle::Operator *cur_op, + BaseRuntimeGraph *runtime_graph) { - LUCI_INTERPRETER_CHECK(x()->element_type() == y()->element_type()); - LUCI_INTERPRETER_CHECK(output()->element_type() == DataType::BOOL); + kernels::TISOKernel kernel(cur_op, runtime_graph); - if (x()->element_type() == DataType::U8) - { - quantizeMultiplierSmallerThanOneExp(x()->scale(), &_x_multiplier, &_x_shift); - quantizeMultiplierSmallerThanOneExp(y()->scale(), &_y_multiplier, &_y_shift); - } - // TODO: enable it only if kernel with dynamic shapes - output()->resize(calculateShapeForBroadcast(x()->shape(), y()->shape())); + LUCI_INTERPRETER_CHECK(Tensor::element_type(kernel.input1()) == + Tensor::element_type(kernel.input2())); + LUCI_INTERPRETER_CHECK(Tensor::element_type(kernel.output()) == DataType::BOOL); } -void NotEqual::execute() const +void execute_kernel_CircleNotEqual(const circle::Operator *cur_op, BaseRuntimeGraph *runtime_graph) { - switch (x()->element_type()) + kernels::TISOKernel kernel(cur_op, runtime_graph); + + switch (Tensor::element_type(kernel.input1())) { - case DataType::FLOAT32: - evalFloat(); - break; case DataType::S64: - evalInteger(); + evalGeneric(kernel.input1(), kernel.input2(), kernel.output(), runtime_graph); break; case DataType::S32: - evalInteger(); + evalGeneric(kernel.input1(), kernel.input2(), kernel.output(), runtime_graph); break; - case DataType::U8: - evalQuantized(); +#ifndef DIS_FLOAT + case DataType::FLOAT32: + evalGeneric(kernel.input1(), kernel.input2(), kernel.output(), runtime_graph); break; +#endif // DIS_FLOAT default: assert(false && "Unsupported type."); } } -void NotEqual::evalFloat() const -{ - const auto x_data = getTensorData(x()); - const auto y_data = getTensorData(y()); - auto output_data = getTensorData(output()); - - tflite::ComparisonParams op_params; - op_params.is_broadcast = x()->shape() != y()->shape(); - - if (op_params.is_broadcast) - { - tflite::reference_ops::Broadcast4DSlowNotEqual(op_params, getTensorShape(x()), x_data, - getTensorShape(y()), y_data, - getTensorShape(output()), output_data); - } - else - { - tflite::reference_ops::NotEqual(op_params, getTensorShape(x()), x_data, getTensorShape(y()), - y_data, getTensorShape(output()), output_data); - } -} - -template void NotEqual::evalInteger() const -{ - const auto x_data = getTensorData(x()); - const auto y_data = getTensorData(y()); - auto output_data = getTensorData(output()); - - tflite::ComparisonParams op_params; - op_params.is_broadcast = x()->shape() != y()->shape(); - - if (op_params.is_broadcast) - { - tflite::reference_ops::Broadcast4DSlowNotEqualNoScaling(op_params, getTensorShape(x()), x_data, - getTensorShape(y()), y_data, - getTensorShape(output()), output_data); - } - else - { - tflite::reference_ops::NotEqualNoScaling(op_params, getTensorShape(x()), x_data, - getTensorShape(y()), y_data, getTensorShape(output()), - output_data); - } -} - -void NotEqual::evalQuantized() const -{ - const auto x_data = getTensorData(x()); - const auto y_data = getTensorData(y()); - auto output_data = getTensorData(output()); - - tflite::ComparisonParams op_params; - op_params.left_shift = 8; - op_params.input1_offset = -x()->zero_point(); // Note the '-' - op_params.input1_shift = _x_shift; - op_params.input1_multiplier = _x_multiplier; - op_params.input2_offset = -y()->zero_point(); // Note the '-' - op_params.input2_shift = _y_shift; - op_params.input2_multiplier = _y_multiplier; - op_params.is_broadcast = x()->shape() != y()->shape(); - - if (op_params.is_broadcast) - { - tflite::reference_ops::Broadcast4DSlowNotEqualWithScaling( - op_params, getTensorShape(x()), x_data, getTensorShape(y()), y_data, getTensorShape(output()), - output_data); - } - else - { - tflite::reference_ops::NotEqualWithScaling(op_params, getTensorShape(x()), x_data, - getTensorShape(y()), y_data, - getTensorShape(output()), output_data); - } -} - -} // namespace kernels } // namespace luci_interpreter diff --git a/onert-micro/luci-interpreter/src/kernels/NotEqual.h b/onert-micro/luci-interpreter/src/kernels/NotEqual.h deleted file mode 100644 index d2aafe8933e..00000000000 --- a/onert-micro/luci-interpreter/src/kernels/NotEqual.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef LUCI_INTERPRETER_KERNELS_NOT_EQUAL_H -#define LUCI_INTERPRETER_KERNELS_NOT_EQUAL_H - -#include "core/Kernel.h" - -namespace luci_interpreter -{ -namespace kernels -{ - -class NotEqual : public Kernel -{ -public: - NotEqual(const Tensor *x, const Tensor *y, Tensor *output); - - const Tensor *x() const { return _inputs[0]; } - const Tensor *y() const { return _inputs[1]; } - Tensor *output() const { return _outputs[0]; } - - void configure() override; - void execute() const override; - -private: - void evalFloat() const; - template void evalInteger() const; - void evalQuantized() const; - -private: - int32_t _x_multiplier = 0; - int _x_shift = 0; - int32_t _y_multiplier = 0; - int _y_shift = 0; -}; - -} // namespace kernels -} // namespace luci_interpreter - -#endif // LUCI_INTERPRETER_KERNELS_NOT_EQUAL_H diff --git a/onert-micro/luci-interpreter/src/kernels/NotEqual.test.cpp b/onert-micro/luci-interpreter/src/kernels/NotEqual.test.cpp index 45bf4022af2..520a02ea5f8 100644 --- a/onert-micro/luci-interpreter/src/kernels/NotEqual.test.cpp +++ b/onert-micro/luci-interpreter/src/kernels/NotEqual.test.cpp @@ -15,14 +15,13 @@ * limitations under the License. */ -#include "kernels/NotEqual.h" #include "kernels/TestUtils.h" -#include "luci_interpreter/TestMemoryManager.h" +#include "luci_interpreter/test_models/notequal/FloatNotEqualKernel.h" + +#include "loader/ModuleLoader.h" namespace luci_interpreter { -namespace kernels -{ namespace { @@ -30,277 +29,61 @@ using namespace testing; class NotEqualTest : public ::testing::Test { -protected: - void SetUp() override { _memory_manager = std::make_unique(); } - - std::unique_ptr _memory_manager; + // Do nothing }; -TEST_F(NotEqualTest, FloatSimple) -{ - std::vector x_data{ - 0.5, 0.7, 0.9, // Row 1 - 1, 0, -1, // Row 2 - }; - - std::vector y_data{ - 0.9, 0.7, 0.5, // Row 1 - -1, 0, 1, // Row 2 - }; - - std::vector ref_output_data{ - true, false, true, // Row 1 - true, false, true, // Row 2 - }; - - Tensor x_tensor = makeInputTensor({2, 3}, x_data, _memory_manager.get()); - Tensor y_tensor = makeInputTensor({2, 3}, y_data, _memory_manager.get()); - Tensor output_tensor = makeOutputTensor(DataType::BOOL); - - NotEqual kernel(&x_tensor, &y_tensor, &output_tensor); - kernel.configure(); - _memory_manager->allocate_memory(output_tensor); - kernel.execute(); - - EXPECT_THAT(extractTensorData(output_tensor), ::testing::ElementsAreArray(ref_output_data)); - EXPECT_THAT(extractTensorShape(output_tensor), ::testing::ElementsAreArray({2, 3})); -} - -TEST_F(NotEqualTest, FloatBroardcast) -{ - std::vector x_data{ - 0.5, 0.7, 0.9, // Row 1 - 1, 0, -1, // Row 2 - -1, 0, 1, // Row 3 - 0.9, 0.7, 0.5, // Row 4 - }; - - std::vector y_data{ - 0.9, 0.7, 0.5, // Row 1 - }; - - std::vector ref_output_data{ - true, false, true, // Row 1 - true, true, true, // Row 2 - true, true, true, // Row 3 - false, false, false, // Row 4 - }; - - Tensor x_tensor = makeInputTensor({4, 3}, x_data, _memory_manager.get()); - Tensor y_tensor = makeInputTensor({1, 3}, y_data, _memory_manager.get()); - Tensor output_tensor = makeOutputTensor(DataType::BOOL); - - NotEqual kernel(&x_tensor, &y_tensor, &output_tensor); - kernel.configure(); - _memory_manager->allocate_memory(output_tensor); - kernel.execute(); - - EXPECT_THAT(extractTensorData(output_tensor), ::testing::ElementsAreArray(ref_output_data)); - EXPECT_THAT(extractTensorShape(output_tensor), ::testing::ElementsAreArray({4, 3})); -} - -template -void checkIntegerSimple(luci_interpreter::IMemoryManager *memory_manager) -{ - using dtype = typename loco::DataTypeImpl::Type; - dtype min_value = std::numeric_limits::min(); - dtype max_value = std::numeric_limits::max(); - std::vector x_data{min_value, 2, max_value}; - - std::vector y_data{min_value, -2, max_value}; - - std::vector ref_output_data{false, true, false}; - - Tensor x_tensor = makeInputTensor({3}, x_data, memory_manager); - Tensor y_tensor = makeInputTensor({3}, y_data, memory_manager); - Tensor output_tensor = makeOutputTensor(DataType::BOOL); - - NotEqual kernel(&x_tensor, &y_tensor, &output_tensor); - kernel.configure(); - memory_manager->allocate_memory(output_tensor); - kernel.execute(); - - EXPECT_THAT(extractTensorData(output_tensor), ::testing::ElementsAreArray(ref_output_data)); - EXPECT_THAT(extractTensorShape(output_tensor), ::testing::ElementsAreArray({3})); -} - -template -void checkIntegerBroadcast(luci_interpreter::IMemoryManager *memory_manager) -{ - using dtype = typename loco::DataTypeImpl::Type; - dtype min_value = std::numeric_limits::min(); - dtype max_value = std::numeric_limits::max(); - std::vector x_data{ - min_value, 2, 3, // Row 1 - 4, 5, max_value, // Row 2 - -1, -2, -3, // Row 3 - min_value, -2, max_value, // Row 4 - }; - - std::vector y_data{ - min_value, -2, max_value, // Row 1 - }; - - std::vector ref_output_data{ - false, true, true, // Row 1 - true, true, false, // Row 2 - true, false, true, // Row 3 - false, false, false, // Row 4 - }; - - Tensor x_tensor = makeInputTensor({4, 3}, x_data, memory_manager); - Tensor y_tensor = makeInputTensor({3}, y_data, memory_manager); - Tensor output_tensor = makeOutputTensor(DataType::BOOL); - - NotEqual kernel(&x_tensor, &y_tensor, &output_tensor); - kernel.configure(); - memory_manager->allocate_memory(output_tensor); - kernel.execute(); - - EXPECT_THAT(extractTensorData(output_tensor), ::testing::ElementsAreArray(ref_output_data)); - EXPECT_THAT(extractTensorShape(output_tensor), ::testing::ElementsAreArray({4, 3})); -} - -TEST_F(NotEqualTest, Int32) -{ - checkIntegerSimple(_memory_manager.get()); - checkIntegerBroadcast(_memory_manager.get()); - SUCCEED(); -} - -TEST_F(NotEqualTest, Int64) -{ - checkIntegerSimple(_memory_manager.get()); - checkIntegerBroadcast(_memory_manager.get()); - SUCCEED(); -} - -// Choose min / max in such a way that there are exactly 256 units to avoid rounding errors. -const float F_MIN = -128.0 / 128.0; -const float F_MAX = 127.0 / 128.0; - -TEST_F(NotEqualTest, Uint8Quantized) -{ - std::vector x_data{ - 0.5, 0.5, 0.7, 0.9, // Row 1 - 1, 0, 0.05, -1, // Row 2 - }; - - std::vector y_data{ - 0.9, 0.5, 0.55, 0.5, // Row 1 - -1, 0, 0.05, 1, // Row 2 - }; - - std::vector ref_output_data{ - true, false, true, true, // Row 1 - true, false, false, true, // Row 2 - }; - - std::pair x_quant_param = quantizationParams(F_MIN, F_MAX); - Tensor x_tensor = makeInputTensor( - {1, 2, 4, 1}, x_quant_param.first, x_quant_param.second, x_data, _memory_manager.get()); - - std::pair y_quant_param = quantizationParams(F_MIN * 2, F_MAX * 2); - Tensor y_tensor = makeInputTensor( - {1, 2, 4, 1}, y_quant_param.first, y_quant_param.second, y_data, _memory_manager.get()); - - Tensor output_tensor = makeOutputTensor(DataType::BOOL); - - NotEqual kernel(&x_tensor, &y_tensor, &output_tensor); - kernel.configure(); - _memory_manager->allocate_memory(output_tensor); - kernel.execute(); - - EXPECT_THAT(extractTensorShape(output_tensor), ::testing::ElementsAreArray({1, 2, 4, 1})); - EXPECT_THAT(extractTensorData(output_tensor), ::testing::ElementsAreArray(ref_output_data)); -} - -TEST_F(NotEqualTest, Uint8QuantizedBroadcast) +template +std::vector checkNotEqualKernel(test_kernel::TestDataBase *test_data_base) { - std::vector x_data{ - 0.4, -0.8, 0.7, 0.3, // Row 1 - -0.5, 0.1, 0, 0.5, // Row 2 - 1, 0, 0.05, -1, // Row 3 - -1, 0.05, 0, 1, // Row 4 - }; - - std::vector y_data{ - -1, 0.05, 0, 1, // Row 1 - }; - - std::vector ref_output_data{ - true, true, true, true, // Row 1 - true, true, false, true, // Row 2 - true, true, true, true, // Row 3 - false, false, false, false, // Row 4 - }; - - std::pair quant_param = quantizationParams(F_MIN, F_MAX); - Tensor x_tensor = makeInputTensor( - {1, 4, 4, 1}, quant_param.first, quant_param.second, x_data, _memory_manager.get()); - Tensor y_tensor = makeInputTensor( - {1, 1, 4, 1}, quant_param.first, quant_param.second, y_data, _memory_manager.get()); - Tensor output_tensor = makeOutputTensor(DataType::BOOL); - - NotEqual kernel(&x_tensor, &y_tensor, &output_tensor); - kernel.configure(); - _memory_manager->allocate_memory(output_tensor); - kernel.execute(); + MemoryManager memory_manager{}; + RuntimeModule runtime_module{}; + bool dealloc_input = true; - EXPECT_THAT(extractTensorShape(output_tensor), ::testing::ElementsAreArray({1, 4, 4, 1})); - EXPECT_THAT(extractTensorData(output_tensor), ::testing::ElementsAreArray(ref_output_data)); -} + // 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); -TEST_F(NotEqualTest, Input_Type_Mismatch_NEG) -{ - Tensor x_tensor = makeInputTensor({1}, {1.f}, _memory_manager.get()); - Tensor y_tensor = makeInputTensor({1}, {1}, _memory_manager.get()); - Tensor output_tensor = makeOutputTensor(DataType::BOOL); + auto *main_runtime_graph = runtime_module.getMainGraph(); + assert(main_runtime_graph->getNumOfInputTensors() == 2); - NotEqual kernel(&x_tensor, &y_tensor, &output_tensor); - EXPECT_ANY_THROW(kernel.configure()); -} + // set left input data + { + auto *input_tensor_data = reinterpret_cast(main_runtime_graph->configureGraphInput(0)); + std::copy(test_data_base->get_input_data_by_index(0).begin(), + test_data_base->get_input_data_by_index(0).end(), input_tensor_data); + } -TEST_F(NotEqualTest, Input_Output_Type_NEG) -{ - Tensor x_tensor = makeInputTensor({1}, {1.f}, _memory_manager.get()); - Tensor y_tensor = makeInputTensor({1}, {1.f}, _memory_manager.get()); - Tensor output_tensor = makeOutputTensor(DataType::FLOAT32); + // set right input data + { + auto *input_tensor_data = reinterpret_cast(main_runtime_graph->configureGraphInput(1)); + std::copy(test_data_base->get_input_data_by_index(1).begin(), + test_data_base->get_input_data_by_index(1).end(), input_tensor_data); + } - NotEqual kernel(&x_tensor, &y_tensor, &output_tensor); - EXPECT_ANY_THROW(kernel.configure()); -} + runtime_module.execute(); -TEST_F(NotEqualTest, Float_Broadcast_NEG) -{ - Tensor x_tensor = makeInputTensor({2}, {1.f, 2.f}, _memory_manager.get()); - Tensor y_tensor = makeInputTensor({3}, {1.f, 2.f, 3.f}, _memory_manager.get()); - Tensor output_tensor = makeOutputTensor(DataType::BOOL); + assert(main_runtime_graph->getNumOfOutputTensors() == 1); - NotEqual kernel(&x_tensor, &y_tensor, &output_tensor); - ASSERT_ANY_THROW(kernel.configure()); + U *output_data = reinterpret_cast(main_runtime_graph->getOutputDataByIndex(0)); + const size_t num_elements = (main_runtime_graph->getOutputDataSizeByIndex(0) / sizeof(U)); + std::vector output_data_vector(output_data, output_data + num_elements); + return output_data_vector; } -TEST_F(NotEqualTest, Int32_Broadcast_NEG) +TEST_F(NotEqualTest, FloatNoBroadcast_P) { - Tensor x_tensor = makeInputTensor({2}, {1, 2}, _memory_manager.get()); - Tensor y_tensor = makeInputTensor({3}, {1, 2, 3}, _memory_manager.get()); - Tensor output_tensor = makeOutputTensor(DataType::BOOL); - - NotEqual kernel(&x_tensor, &y_tensor, &output_tensor); - ASSERT_ANY_THROW(kernel.configure()); + const bool is_with_broadcast = false; + test_kernel::TestDataFloatNotEqual test_data_kernel(is_with_broadcast, false); + std::vector output_data_vector = checkNotEqualKernel(&test_data_kernel); + EXPECT_THAT(output_data_vector, test_data_kernel.get_output_data_by_index(0)); } -TEST_F(NotEqualTest, Int64_Broadcast_NEG) +TEST_F(NotEqualTest, FloatNoBroadcast_NEG) { - Tensor x_tensor = makeInputTensor({2}, {1, 2}, _memory_manager.get()); - Tensor y_tensor = makeInputTensor({3}, {1, 2, 3}, _memory_manager.get()); - Tensor output_tensor = makeOutputTensor(DataType::BOOL); - - NotEqual kernel(&x_tensor, &y_tensor, &output_tensor); - ASSERT_ANY_THROW(kernel.configure()); + const bool is_with_broadcast = false; + test_kernel::TestDataFloatNotEqual test_data_kernel(is_with_broadcast, true); + EXPECT_DEATH(checkNotEqualKernel(&test_data_kernel), ""); } } // namespace -} // namespace kernels } // namespace luci_interpreter