Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[onert-micro] Add Div kernel #13245

Merged
merged 2 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions onert-micro/onert-micro/include/pal/common/PALDivCommon.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright (c) 2024 Samsung Electronics Co., Ltd. All Rights Reserved
* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef ONERT_MICRO_EXECUTE_PAL_DIV_COMMON_H
#define ONERT_MICRO_EXECUTE_PAL_DIV_COMMON_H

#include "PALArithmeticOpCommon.h"

namespace onert_micro
{
namespace execute
{
namespace pal
{

template <typename T>
OMStatus Div(const core::BinaryArithmeticBroadcastParams &params, const int flat_size,
const T *input1_data, const T *input2_data, T *output_data)
{
ArithmeticOp<T, DivFn<T>>(params, flat_size, input1_data, input2_data, output_data);
return Ok;
}

template <typename T>
OMStatus BroadcastDiv4DSlow(const core::BinaryArithmeticBroadcastParams &params,
const core::OMRuntimeShape &input1_shape, const T *input1_data,
const core::OMRuntimeShape &input2_shape, const T *input2_data,
const core::OMRuntimeShape &output_shape, T *output_data)
{
BroadcastArithmeticOp4DSlow<T, DivFn<T>>(params, input1_shape, input1_data, input2_shape,
input2_data, output_shape, output_data);
return Ok;
}

} // namespace pal
} // namespace execute
} // namespace onert_micro

#endif // ONERT_MICRO_EXECUTE_PAL_MUL_COMMON_H
2 changes: 1 addition & 1 deletion onert-micro/onert-micro/include/pal/mcu/KernelsToBuild.lst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ REGISTER_KERNEL(BATCH_TO_SPACE_ND, BatchToSpaceND)
#/*REGISTER_KERNEL(CEIL, Ceil)*/
REGISTER_KERNEL(COS, Cos)
#/*REGISTER_KERNEL(CAST, Cast)*/
#/*REGISTER_KERNEL(DIV, Div)*/
REGISTER_KERNEL(DIV, Div)
REGISTER_KERNEL(DEPTHWISE_CONV_2D, DepthwiseConv2D)
#/*REGISTER_KERNEL(DEPTH_TO_SPACE, DepthToSpace)*/
#/*REGISTER_KERNEL(DEQUANTIZE, Dequantize)*/
Expand Down
23 changes: 23 additions & 0 deletions onert-micro/onert-micro/include/pal/mcu/PALDiv.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright (c) 2021 Samsung Electronics Co., Ltd. All Rights Reserved
* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef ONERT_MICRO_EXECUTE_PAL_DIV_H
#define ONERT_MICRO_EXECUTE_PAL_DIV_H

#include "PALDivCommon.h"

#endif // ONERT_MICRO_EXECUTE_PAL_MUL_H
184 changes: 184 additions & 0 deletions onert-micro/onert-micro/include/test_models/div/FloatDivKernel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
/*
* Copyright (c) 2024 Samsung Electronics Co., Ltd. All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef ONERT_MICRO_TEST_MODELS_DIV_KERNEL_FLOAT_H
#define ONERT_MICRO_TEST_MODELS_DIV_KERNEL_FLOAT_H

#include "TestDataDivBase.h"

namespace onert_micro
{
namespace test_model
{
namespace div_float_with_broadcasting
{

/*
* div Kernel:
*
* Input_1(1, 4, 4, 3) Input_2(1, 4, 4, 1)
* \ /
* Div(with broadcast)
* |
* Output(1, 4, 4, 3)
*/
const unsigned char test_kernel_model_circle[] = {
0x18, 0x00, 0x00, 0x00, 0x43, 0x49, 0x52, 0x30, 0x00, 0x00, 0x0e, 0x00, 0x14, 0x00, 0x00, 0x00,
0x0c, 0x00, 0x08, 0x00, 0x10, 0x00, 0x04, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,
0x30, 0x00, 0x00, 0x00, 0x6c, 0x01, 0x00, 0x00, 0x88, 0x01, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
0x1c, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
0x88, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x90, 0xff, 0xff, 0xff, 0x94, 0xff, 0xff, 0xff,
0x01, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x18, 0x00, 0x14, 0x00,
0x10, 0x00, 0x0c, 0x00, 0x08, 0x00, 0x04, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00,
0x1c, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x6c, 0x00, 0x00, 0x00,
0x04, 0x00, 0x00, 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x14, 0x00, 0x00, 0x00, 0x10, 0x00, 0x0c, 0x00,
0x07, 0x00, 0x08, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1d, 0x10, 0x00, 0x00, 0x00,
0x10, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x04, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x74, 0x00, 0x00, 0x00,
0x34, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xa4, 0xff, 0xff, 0xff, 0x0c, 0x00, 0x00, 0x00,
0x03, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x6f, 0x66, 0x6d, 0x00,
0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
0x03, 0x00, 0x00, 0x00, 0xd0, 0xff, 0xff, 0xff, 0x0c, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
0x10, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x69, 0x66, 0x6d, 0x32, 0x00, 0x00, 0x00, 0x00,
0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x08, 0x00, 0x04, 0x00,
0x0c, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,
0x04, 0x00, 0x00, 0x00, 0x69, 0x66, 0x6d, 0x31, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x0c, 0x00, 0x0b, 0x00, 0x00, 0x00,
0x00, 0x00, 0x04, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x2a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2a,
0x11, 0x00, 0x00, 0x00, 0x4f, 0x4e, 0x45, 0x2d, 0x74, 0x66, 0x6c, 0x69, 0x74, 0x65, 0x32, 0x63,
0x69, 0x72, 0x63, 0x6c, 0x65, 0x00, 0x00, 0x00};

const std::vector<float> input1_data = {
0.53560877, -1.8867658, -8.832248, 5.859678, -5.1357374, -7.014421, 2.8209867, -4.6921616,
8.162995, -2.6120718, -0.8869447, -2.3489552, -6.208182, -2.2264383, 6.55287, -5.3615203,
-2.7882025, 1.1029396, -9.950372, 0.1670622, 3.533298, 2.606648, 7.126593, -3.6454842,
2.637641, -6.7670174, 5.8970585, 8.792766, -6.63798, -1.1457828, 9.122211, -3.2186837,
-8.038172, 3.3369763, 0.89376354, -7.979661, -4.241393, -3.4046402, 6.1339216, 7.767886,
5.7856345, 8.147999, 9.79144, 8.312661, -4.9722652, 3.0038614, -5.3218126, -6.5680394};
const std::vector<float> input2_data = {
-8.79469, -0.2644837, -1.6307421, 2.0497515, -1.5460981, 1.3044068, 7.1843495, 1.1402534,
0.2102437, 4.253287, 7.076496, 1.3749583, 6.6056423, 4.4962177, 3.9589605, -1.8852876};
const std::vector<float> reference_output_data = {
-0.06090138, 0.21453466, 1.0042704, -22.155157, 19.417974, 26.521185, -1.7298791,
2.8773167, -5.005694, -1.2743359, -0.4327084, -1.1459707, 4.0153866, 1.4400369,
-4.2383275, -4.110313, -2.1375253, 0.8455488, -1.3850067, 0.023253629, 0.49180487,
2.286025, 6.250008, -3.1970825, 12.545636, -32.18654, 28.048681, 2.0672872,
-1.5606706, -0.26938763, 1.2890859, -0.45484143, -1.1358972, 2.4269655, 0.6500296,
-5.803566, -0.6420864, -0.51541394, 0.9285882, 1.727649, 1.2867781, 1.8121896,
2.4732351, 2.099708, -1.2559522, -1.5933173, 2.822812, 3.4838395};

} // namespace div_float_with_broadcasting

namespace div_float_no_broadcasting
{
/*
* div Kernel:
*
* Input_1(1, 4, 4, 3) Input_2(1, 4, 4, 3)
* \ /
* Div(no broadcast)
* |
* Output(1, 4, 4, 3)
*/
const unsigned char test_kernel_model_circle[] = {
0x18, 0x00, 0x00, 0x00, 0x43, 0x49, 0x52, 0x30, 0x00, 0x00, 0x0e, 0x00, 0x14, 0x00, 0x00, 0x00,
0x0c, 0x00, 0x08, 0x00, 0x10, 0x00, 0x04, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,
0x30, 0x00, 0x00, 0x00, 0x6c, 0x01, 0x00, 0x00, 0x88, 0x01, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
0x1c, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
0x88, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x90, 0xff, 0xff, 0xff, 0x94, 0xff, 0xff, 0xff,
0x01, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x18, 0x00, 0x14, 0x00,
0x10, 0x00, 0x0c, 0x00, 0x08, 0x00, 0x04, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00,
0x1c, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x6c, 0x00, 0x00, 0x00,
0x04, 0x00, 0x00, 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x14, 0x00, 0x00, 0x00, 0x10, 0x00, 0x0c, 0x00,
0x07, 0x00, 0x08, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1d, 0x10, 0x00, 0x00, 0x00,
0x10, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x04, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x74, 0x00, 0x00, 0x00,
0x34, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xa4, 0xff, 0xff, 0xff, 0x0c, 0x00, 0x00, 0x00,
0x03, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x6f, 0x66, 0x6d, 0x00,
0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
0x03, 0x00, 0x00, 0x00, 0xd0, 0xff, 0xff, 0xff, 0x0c, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
0x10, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x69, 0x66, 0x6d, 0x32, 0x00, 0x00, 0x00, 0x00,
0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
0x03, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x08, 0x00, 0x04, 0x00,
0x0c, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,
0x04, 0x00, 0x00, 0x00, 0x69, 0x66, 0x6d, 0x31, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x0c, 0x00, 0x0b, 0x00, 0x00, 0x00,
0x00, 0x00, 0x04, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x2a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2a,
0x11, 0x00, 0x00, 0x00, 0x4f, 0x4e, 0x45, 0x2d, 0x74, 0x66, 0x6c, 0x69, 0x74, 0x65, 0x32, 0x63,
0x69, 0x72, 0x63, 0x6c, 0x65, 0x00, 0x00, 0x00};

std::vector<float> input1_data = {
-0.45486993, 7.7920837, 2.458276, -9.338201, 2.132607, 7.5134172, -7.3420544, -6.390925,
1.456884, -1.8421048, 2.4459255, -3.930421, 5.439674, -0.3640652, -4.5039334, -8.457781,
3.8367634, -6.271797, -3.6314914, 7.7209616, 0.7935352, -6.561332, 0.77153474, 8.639922,
0.15612718, 5.9307566, 0.71869296, 5.4473047, -7.4552007, -2.4453044, -5.7700257, 7.9675865,
4.7339244, 1.3709338, 6.940702, 2.7984607, 9.185996, 8.848705, -4.7602606, -3.887096,
4.807505, 2.9972825, 5.416388, 5.6682634, -5.875255, -0.29188222, 7.522483, -6.873605};
std::vector<float> input2_data = {
1.5015899, 9.9904785, -5.368375, -3.0589666, 1.4541256, 3.0067844, -1.0564902, 3.4706006,
4.3666296, 9.586457, -4.497033, -9.208905, -6.8920064, 6.2652717, -0.60215276, 7.8108196,
-7.7110577, -4.182856, 6.8893385, 9.817479, -9.451469, -2.0223913, 5.1733356, 5.4378557,
4.1402535, -4.4087567, 0.16630036, -8.007953, 4.7895074, -3.2770896, 4.013145, 2.2894316,
5.74741, -9.481342, 3.194859, 9.471764, -7.8339133, -8.103412, -3.8862576, 9.901491,
5.358148, -2.7227716, -5.84558, 9.881574, 3.5261114, 3.4573863, 8.221204, -3.6716719};
std::vector<float> reference_output_data = {
-0.30292553, 0.779951, -0.4579181, 3.0527303, 1.4665906, 2.4988215, 6.949477,
-1.8414464, 0.3336404, -0.19215699, -0.54389757, 0.42680657, -0.7892729, -0.058108445,
7.4797187, -1.0828289, -0.49756643, 1.4994054, -0.52711755, 0.7864505, -0.083958924,
3.2443435, 0.14913681, 1.5888473, 0.03770957, -1.345222, 4.321656, -0.6802369,
-1.5565695, 0.7461817, -1.4377816, 3.4801593, 0.8236622, -0.14459279, 2.1724596,
0.29545298, -1.1725935, -1.0919728, 1.2248958, -0.3925768, 0.8972326, -1.1008204,
-0.92657834, 0.5736195, -1.6662138, -0.0844228, 0.9150099, 1.872064};

} // namespace div_float_no_broadcasting

class TestDataFloatDiv : public TestDataDivBase<float>
{
public:
explicit TestDataFloatDiv(bool is_with_broadcast) : TestDataDivBase<float>(is_with_broadcast)
{
if (is_with_broadcast)
{
_input1_data = div_float_with_broadcasting::input1_data;
_input2_data = div_float_with_broadcasting::input2_data;
_reference_output_data = div_float_with_broadcasting::reference_output_data;
_test_kernel_model_circle = div_float_with_broadcasting::test_kernel_model_circle;
}
else
{
_input1_data = div_float_no_broadcasting::input1_data;
_input2_data = div_float_no_broadcasting::input2_data;
_reference_output_data = div_float_no_broadcasting::reference_output_data;
_test_kernel_model_circle = div_float_no_broadcasting::test_kernel_model_circle;
}
}

~TestDataFloatDiv() override = default;
};

} // namespace test_model
} // namespace onert_micro

#endif // ONERT_MICRO_TEST_MODELS_MUL_KERNEL_FLOAT_H
Loading
Loading