From c038bb0594b580f3ca9ea1d072ea8da09b239713 Mon Sep 17 00:00:00 2001 From: Balyshev Artem <43214667+BalyshevArtem@users.noreply.github.com> Date: Wed, 27 Sep 2023 12:29:36 +0300 Subject: [PATCH] [onert-micro] Add float Log kernels (#11602) This commit adds float Log kernels for onert-micro. ONE-DCO-1.0-Signed-off-by: Artem Balyshev Co-authored-by: Artem Balyshev --- .../test_models/log/FloatLogKernel.h | 88 +++++++++++++++++++ .../test_models/log/NegLogKernel.h | 83 +++++++++++++++++ .../test_models/log/TestDataLogBase.h | 60 +++++++++++++ .../pal/cmsisnn/KernelsToBuild.lst | 1 + .../luci-interpreter/pal/common/PALLog.h | 38 ++++++++ .../pal/mcu/KernelsToBuild.lst | 1 + .../luci-interpreter/src/kernels/Log.cpp | 77 ++++++++++++++++ .../luci-interpreter/src/kernels/Log.test.cpp | 86 ++++++++++++++++++ .../src/loader/GraphLoader.cpp | 1 + 9 files changed, 435 insertions(+) create mode 100644 onert-micro/luci-interpreter/include/luci_interpreter/test_models/log/FloatLogKernel.h create mode 100644 onert-micro/luci-interpreter/include/luci_interpreter/test_models/log/NegLogKernel.h create mode 100644 onert-micro/luci-interpreter/include/luci_interpreter/test_models/log/TestDataLogBase.h create mode 100644 onert-micro/luci-interpreter/pal/common/PALLog.h create mode 100644 onert-micro/luci-interpreter/src/kernels/Log.cpp create mode 100644 onert-micro/luci-interpreter/src/kernels/Log.test.cpp diff --git a/onert-micro/luci-interpreter/include/luci_interpreter/test_models/log/FloatLogKernel.h b/onert-micro/luci-interpreter/include/luci_interpreter/test_models/log/FloatLogKernel.h new file mode 100644 index 00000000000..c6ede70a382 --- /dev/null +++ b/onert-micro/luci-interpreter/include/luci_interpreter/test_models/log/FloatLogKernel.h @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef LUCI_INTERPRETER_TEST_MODELS_FLOAT_LOG_KERNEL_H +#define LUCI_INTERPRETER_TEST_MODELS_FLOAT_LOG_KERNEL_H + +#include "TestDataLogBase.h" + +namespace luci_interpreter +{ +namespace test_kernel +{ +namespace log_float +{ +/* + * Log Kernel: + * + * Input(1, 3, 3, 2) + * | + * Log + * | + * Output(1, 3, 3, 2) + */ +const unsigned char test_kernel_model_circle[] = { + 0x18, 0x00, 0x00, 0x00, 0x43, 0x49, 0x52, 0x30, 0x00, 0x00, 0x0e, 0x00, 0x14, 0x00, 0x00, 0x00, + 0x0c, 0x00, 0x08, 0x00, 0x10, 0x00, 0x04, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x2c, 0x00, 0x00, 0x00, 0x14, 0x01, 0x00, 0x00, 0x30, 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x18, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xf8, 0xff, 0xff, 0xff, + 0xfc, 0xff, 0xff, 0xff, 0x04, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x18, 0x00, 0x14, 0x00, 0x10, 0x00, 0x0c, 0x00, + 0x08, 0x00, 0x04, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, + 0x48, 0x00, 0x00, 0x00, 0x4c, 0x00, 0x00, 0x00, 0x50, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x0a, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x08, 0x00, 0x04, 0x00, 0x0a, 0x00, 0x00, 0x00, + 0x08, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0xd4, 0xff, 0xff, 0xff, 0x0c, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x0c, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x6f, 0x66, 0x6d, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x0c, 0x00, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x08, 0x00, 0x04, 0x00, 0x0c, 0x00, 0x00, 0x00, + 0x0c, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x69, 0x66, 0x6d, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x0c, 0x00, 0x0c, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x0c, 0x00, 0x00, 0x00, + 0x49, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x49, 0x11, 0x00, 0x00, 0x00, 0x4f, 0x4e, 0x45, 0x2d, + 0x74, 0x66, 0x6c, 0x69, 0x74, 0x65, 0x32, 0x63, 0x69, 0x72, 0x63, 0x6c, 0x65, 0x00, 0x00, 0x00}; + +const std::vector input_data = { + 2.9393284, 12.591625, 14.310633, 4.178408, 9.743034, 7.6983232, 10.804855, 2.9712732, 13.964229, + 8.660442, 12.715771, 12.287443, 11.55983, 6.143016, 1.032474, 10.3692465, 13.885086, 12.157783}; +const std::vector reference_output_data = { + 1.0781811, 2.533032, 2.6610029, 1.4299303, 2.2765527, 2.0410025, + 2.3799956, 1.0889906, 2.636499, 2.1587658, 2.542843, 2.5085778, + 2.4475362, 1.8153158, 0.031957902, 2.3388443, 2.6308153, 2.4979694}; + +} // namespace log_float + +class TestDataFloatLog : public TestDataLogBase +{ +public: + TestDataFloatLog() + { + _input_data = log_float::input_data; + _reference_output_data = log_float::reference_output_data; + _test_kernel_model_circle = log_float::test_kernel_model_circle; + } + + ~TestDataFloatLog() override = default; +}; + +} // namespace test_kernel +} // namespace luci_interpreter + +#endif // LUCI_INTERPRETER_TEST_MODELS_FLOAT_LOG_KERNEL_H diff --git a/onert-micro/luci-interpreter/include/luci_interpreter/test_models/log/NegLogKernel.h b/onert-micro/luci-interpreter/include/luci_interpreter/test_models/log/NegLogKernel.h new file mode 100644 index 00000000000..27cfd38676e --- /dev/null +++ b/onert-micro/luci-interpreter/include/luci_interpreter/test_models/log/NegLogKernel.h @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef LUCI_INTERPRETER_TEST_MODELS_NEG_LOG_KERNEL_H +#define LUCI_INTERPRETER_TEST_MODELS_NEG_LOG_KERNEL_H + +#include "luci_interpreter/test_models/TestDataBase.h" + +namespace luci_interpreter +{ +namespace test_kernel +{ +namespace neg_input_output_type_mismatch_kernel +{ +/* + * Log Kernel with input output type mismatch: + * + * Input(1, 3, 3, 2) - Float32 + * | + * Log + * | + * Output(1, 3, 3, 2) - Int32 + */ +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, + 0x2c, 0x00, 0x00, 0x00, 0x24, 0x01, 0x00, 0x00, 0x40, 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x18, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xf8, 0xff, 0xff, 0xff, + 0xfc, 0xff, 0xff, 0xff, 0x04, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x18, 0x00, 0x14, 0x00, 0x10, 0x00, 0x0c, 0x00, + 0x08, 0x00, 0x04, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, + 0x48, 0x00, 0x00, 0x00, 0x4c, 0x00, 0x00, 0x00, 0x50, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x0a, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x08, 0x00, 0x04, 0x00, 0x0a, 0x00, 0x00, 0x00, + 0x08, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x50, 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, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, + 0x0c, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x6f, 0x66, 0x6d, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x0c, 0x00, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x08, 0x00, 0x04, 0x00, 0x0c, 0x00, 0x00, 0x00, + 0x0c, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x69, 0x66, 0x6d, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x0c, 0x00, 0x0c, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x0c, 0x00, 0x00, 0x00, + 0x49, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x49, 0x11, 0x00, 0x00, 0x00, 0x4f, 0x4e, 0x45, 0x2d, + 0x74, 0x66, 0x6c, 0x69, 0x74, 0x65, 0x32, 0x63, 0x69, 0x72, 0x63, 0x6c, 0x65, 0x00, 0x00, 0x00}; +} // namespace neg_input_output_type_mismatch_kernel + +class NegTestDataInputOutputTypeMismatchLogKernel : public NegTestDataBase +{ +public: + NegTestDataInputOutputTypeMismatchLogKernel() + { + _test_kernel_model_circle = neg_input_output_type_mismatch_kernel::test_kernel_model_circle; + } + + ~NegTestDataInputOutputTypeMismatchLogKernel() override = default; + + const unsigned char *get_model_ptr() override final { return _test_kernel_model_circle; } + +protected: + const unsigned char *_test_kernel_model_circle; +}; + +} // namespace test_kernel +} // namespace luci_interpreter + +#endif // LUCI_INTERPRETER_TEST_MODELS_NEG_LOG_KERNEL_H diff --git a/onert-micro/luci-interpreter/include/luci_interpreter/test_models/log/TestDataLogBase.h b/onert-micro/luci-interpreter/include/luci_interpreter/test_models/log/TestDataLogBase.h new file mode 100644 index 00000000000..83f22eec483 --- /dev/null +++ b/onert-micro/luci-interpreter/include/luci_interpreter/test_models/log/TestDataLogBase.h @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef LUCI_INTERPRETER_TEST_MODELS_LOG_KERNEL_BASE_H +#define LUCI_INTERPRETER_TEST_MODELS_LOG_KERNEL_BASE_H + +#include "luci_interpreter/test_models/TestDataBase.h" + +namespace luci_interpreter +{ +namespace test_kernel +{ + +template class TestDataLogBase : public TestDataBase +{ +public: + TestDataLogBase() = default; + + const unsigned char *get_model_ptr() override final { return _test_kernel_model_circle; } + + const std::vector &get_input_data_by_index(int i) override final + { + switch (i) + { + case 0: + return _input_data; + default: + assert(false && "Wrong input index"); + } + } + + const std::vector &get_output_data_by_index(int i) override final + { + assert(i == 0); + return _reference_output_data; + } + +protected: + std::vector _input_data; + std::vector _reference_output_data; + const unsigned char *_test_kernel_model_circle; +}; + +} // namespace test_kernel +} // namespace luci_interpreter + +#endif // LUCI_INTERPRETER_TEST_MODELS_LOG_KERNEL_BASE_H diff --git a/onert-micro/luci-interpreter/pal/cmsisnn/KernelsToBuild.lst b/onert-micro/luci-interpreter/pal/cmsisnn/KernelsToBuild.lst index 505a586597e..b7a670b50dd 100644 --- a/onert-micro/luci-interpreter/pal/cmsisnn/KernelsToBuild.lst +++ b/onert-micro/luci-interpreter/pal/cmsisnn/KernelsToBuild.lst @@ -7,6 +7,7 @@ REGISTER_KERNEL(DIV, Div) REGISTER_KERNEL(ADD_N, AddN) REGISTER_KERNEL(CONV_2D, Conv2D) REGISTER_KERNEL(LOGISTIC, Logistic) +REGISTER_KERNEL(LOG, Log) REGISTER_KERNEL(GATHER, Gather) REGISTER_KERNEL(EXP, Exp) REGISTER_KERNEL(FULLY_CONNECTED, FullyConnected) diff --git a/onert-micro/luci-interpreter/pal/common/PALLog.h b/onert-micro/luci-interpreter/pal/common/PALLog.h new file mode 100644 index 00000000000..30870389850 --- /dev/null +++ b/onert-micro/luci-interpreter/pal/common/PALLog.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef LUCI_INTERPRETER_PAL_EXP_H +#define LUCI_INTERPRETER_PAL_EXP_H + +#include "PALUtils.h" +#include + +namespace luci_interpreter_pal +{ + +inline void Log(const int flat_size, const float *input_data, float *output_data) +{ + for (int i = 0; i < flat_size; i++) + { + const float val = input_data[i]; + const float result = std::log(val); + output_data[i] = result; + } +} + +} // namespace luci_interpreter_pal + +#endif // LUCI_INTERPRETER_PAL_EXP_H diff --git a/onert-micro/luci-interpreter/pal/mcu/KernelsToBuild.lst b/onert-micro/luci-interpreter/pal/mcu/KernelsToBuild.lst index f76d1b88a4f..9d5617339ac 100644 --- a/onert-micro/luci-interpreter/pal/mcu/KernelsToBuild.lst +++ b/onert-micro/luci-interpreter/pal/mcu/KernelsToBuild.lst @@ -9,6 +9,7 @@ REGISTER_KERNEL(ADD_N, AddN) REGISTER_KERNEL(FULLY_CONNECTED, FullyConnected) REGISTER_KERNEL(CONV_2D, Conv2D) REGISTER_KERNEL(LOGISTIC, Logistic) +REGISTER_KERNEL(LOG, Log) REGISTER_KERNEL(GATHER, Gather) REGISTER_KERNEL(EXP, Exp) REGISTER_KERNEL(GREATER, Greater) diff --git a/onert-micro/luci-interpreter/src/kernels/Log.cpp b/onert-micro/luci-interpreter/src/kernels/Log.cpp new file mode 100644 index 00000000000..4650c4031b3 --- /dev/null +++ b/onert-micro/luci-interpreter/src/kernels/Log.cpp @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "Builders.h" +#include "kernels/Utils.h" +#include "SISOKernel.h" + +#include "PALLog.h" + +namespace luci_interpreter +{ + +void configure_kernel_CircleLog(const circle::Operator *cur_op, BaseRuntimeGraph *runtime_graph) +{ + kernels::SISOKernel kernel(cur_op, runtime_graph); + + LUCI_INTERPRETER_CHECK(Tensor::element_type(kernel.input()) == + Tensor::element_type(kernel.output())); + LUCI_INTERPRETER_CHECK(Tensor::num_elements(kernel.input()) == + Tensor::num_elements(kernel.output())); + LUCI_INTERPRETER_CHECK(Tensor::num_dims(kernel.input()) == Tensor::num_dims(kernel.output())); +} + +void execute_kernel_CircleLog(const circle::Operator *cur_op, BaseRuntimeGraph *runtime_graph) +{ + kernels::SISOKernel kernel(cur_op, runtime_graph); + + const auto *input_data = runtime_graph->getDataByTensor(kernel.input()); + assert(input_data); + + auto *output_data = runtime_graph->getDataByTensor(kernel.output()); + + bool is_inplace = runtime_graph->is_inplace_op(cur_op); + + switch (Tensor::element_type(kernel.input())) + { +#ifndef DIS_FLOAT + case DataType::FLOAT32: + { + const float *input_data_float = kernels::getTensorData(input_data); + float *output_data_float = kernels::getTensorData(output_data); + if (is_inplace) + { + output_data_float = const_cast(input_data_float); + } + + assert(output_data_float); + + const int flat_size = + kernels::getTensorRuntimeShape(kernel.input(), runtime_graph).flatSize(); + + luci_interpreter_pal::Log(flat_size, input_data_float, output_data_float); + break; + } +#endif // DIS_FLOAT + default: + assert(false && "Unsupported type"); + } + + if (is_inplace) + runtime_graph->makeInplaceOperation(kernel.input(), kernel.output()); +} + +} // namespace luci_interpreter diff --git a/onert-micro/luci-interpreter/src/kernels/Log.test.cpp b/onert-micro/luci-interpreter/src/kernels/Log.test.cpp new file mode 100644 index 00000000000..b055b0a8df1 --- /dev/null +++ b/onert-micro/luci-interpreter/src/kernels/Log.test.cpp @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "kernels/TestUtils.h" +#include "luci_interpreter/test_models/log/FloatLogKernel.h" +#include "luci_interpreter/test_models/log/NegLogKernel.h" + +#include "loader/ModuleLoader.h" + +namespace luci_interpreter +{ +namespace +{ + +using namespace testing; + +class LogTest : public ::testing::Test +{ + // Do nothing +}; + +template std::vector checkLogKernel(test_kernel::TestDataBase *test_data_base) +{ + MemoryManager memory_manager{}; + RuntimeModule runtime_module{}; + bool dealloc_input = true; + + // Load model with single op + auto *model_data_raw = reinterpret_cast(test_data_base->get_model_ptr()); + ModuleLoader::load(&runtime_module, &memory_manager, model_data_raw, dealloc_input); + + auto *main_runtime_graph = runtime_module.getMainGraph(); + assert(main_runtime_graph->getNumOfInputTensors() == 1); + + // Set input data + { + auto *input_tensor_data = reinterpret_cast(main_runtime_graph->configureGraphInput(0)); + std::copy(test_data_base->get_input_data_by_index(0).begin(), + test_data_base->get_input_data_by_index(0).end(), input_tensor_data); + } + + runtime_module.execute(); + + assert(main_runtime_graph->getNumOfOutputTensors() == 1); + + T *output_data = reinterpret_cast(main_runtime_graph->getOutputDataByIndex(0)); + const size_t num_elements = (main_runtime_graph->getOutputDataSizeByIndex(0) / sizeof(T)); + std::vector output_data_vector(output_data, output_data + num_elements); + return output_data_vector; +} + +TEST_F(LogTest, Float_P) +{ + test_kernel::TestDataFloatLog test_data_kernel; + std::vector output_data_vector = checkLogKernel(&test_data_kernel); + EXPECT_THAT(output_data_vector, kernels::testing::FloatArrayNear( + test_data_kernel.get_output_data_by_index(0), 0.0001f)); +} + +TEST_F(LogTest, Input_output_type_mismatch_NEG) +{ + test_kernel::NegTestDataInputOutputTypeMismatchLogKernel test_data_kernel; + MemoryManager memory_manager{}; + RuntimeModule runtime_module{}; + bool dealloc_input = true; + // Load model with single op + auto *model_data_raw = reinterpret_cast(test_data_kernel.get_model_ptr()); + EXPECT_DEATH(ModuleLoader::load(&runtime_module, &memory_manager, model_data_raw, dealloc_input), + ""); +} + +} // namespace +} // namespace luci_interpreter diff --git a/onert-micro/luci-interpreter/src/loader/GraphLoader.cpp b/onert-micro/luci-interpreter/src/loader/GraphLoader.cpp index 26e207ac02f..aaea3c12660 100644 --- a/onert-micro/luci-interpreter/src/loader/GraphLoader.cpp +++ b/onert-micro/luci-interpreter/src/loader/GraphLoader.cpp @@ -33,6 +33,7 @@ bool isInplaceOperation(const circle::BuiltinOperator &op) case circle::BuiltinOperator_EXP: case circle::BuiltinOperator_TANH: case circle::BuiltinOperator_LEAKY_RELU: + case circle::BuiltinOperator_LOG: case circle::BuiltinOperator_RELU: case circle::BuiltinOperator_RELU6: case circle::BuiltinOperator_ADD: