Skip to content
Draft
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
6 changes: 6 additions & 0 deletions onert-micro/onert-micro/include/core/OMKernelData.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ struct ConcatenationParams
uint32_t axis;
};

struct CumSumParams
{
bool exclusive;
bool reverse;
};

struct SoftmaxParams
{
float beta;
Expand Down
99 changes: 99 additions & 0 deletions onert-micro/onert-micro/include/pal/common/PALCumSum.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
* Copyright (c) 2024 Samsung Electronics Co., Ltd. All Rights Reserved
* Copyright 2021 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_PAL_CUM_SUM_COMMON_H
#define ONERT_MICRO_PAL_CUM_SUM_COMMON_H

#include "core/OMKernelData.h"
#include "core/OMRuntimeShape.h"

using namespace onert_micro::core;

namespace onert_micro::execute::pal
{

template <typename T>
OMStatus CumSum(const CumSumParams &params, const OMRuntimeShape &input_shape, const T *input_data,
int32_t axis, T *output_data)
{
const int32_t rank = input_shape.dimensionsCount();

int32_t inner_size = 1;
int32_t outer_size = 1;
int32_t depth_size = 1;

for (int32_t i = 0; i < rank; ++i)
{
if (i < axis)
inner_size *= input_shape.dims(i);

else if (i > axis)
outer_size *= input_shape.dims(i);

else
depth_size *= input_shape.dims(i);
}

// clang-format off

auto get_adj_index_fn = [reverse = params.reverse](int32_t index, int32_t dims)
{
if (!reverse)
return index;

return (dims - 1) - index;
};

// clang-format on

for (int32_t outer = 0; outer < outer_size; ++outer)
{
int32_t outer_adj = get_adj_index_fn(outer, outer_size);

for (int32_t inner = 0; inner < inner_size; ++inner)
{
T accumulator = 0;
int32_t inner_adj = get_adj_index_fn(inner, inner_size);

for (int32_t depth = 0; depth < depth_size; ++depth)
{
int32_t depth_adj = get_adj_index_fn(depth, depth_size);
int32_t index = outer_adj;

index += inner_adj * depth_size * outer_size;
index += depth_adj * outer_size;

if (params.exclusive)
{
output_data[index] = accumulator;
accumulator += input_data[index];

continue;
}

accumulator += input_data[index];
output_data[index] = accumulator;
}
}
}

return Ok;
}

} // namespace onert_micro::execute::pal

#endif // ONERT_MICRO_PAL_CUM_SUM_COMMON_H
1 change: 1 addition & 0 deletions onert-micro/onert-micro/include/pal/mcu/KernelsToBuild.lst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ REGISTER_KERNEL(AVERAGE_POOL_2D, AveragePool2D)
REGISTER_KERNEL(ARG_MAX, ArgMax)
REGISTER_KERNEL(ARG_MIN, ArgMin)
REGISTER_KERNEL(CONCATENATION, Concatenation)
REGISTER_KERNEL(CUMSUM, CumSum)
#/*REGISTER_KERNEL(CUSTOM, BroadcastTo)*/
REGISTER_KERNEL(BATCH_TO_SPACE_ND, BatchToSpaceND)
REGISTER_KERNEL(CEIL, Ceil)
Expand Down
19 changes: 14 additions & 5 deletions onert-micro/onert-micro/include/test_models/TestDataBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
#define ONERT_MICRO_TEST_MODELS_TEST_DATA_BASE_H

#include <vector>
#include <cstdint>
#include <cassert>

namespace onert_micro
{
namespace test_model
namespace onert_micro::test_model
{

template <typename T, typename U = T> class TestDataBase
Expand All @@ -32,7 +32,17 @@ template <typename T, typename U = T> class TestDataBase
virtual const unsigned char *get_model_ptr() = 0;

virtual const std::vector<T> &get_input_data_by_index(int i) = 0;

virtual const std::vector<U> &get_output_data_by_index(int i) = 0;

// clang-format off

virtual const uint8_t *get_input_data_ptr_by_index(int i, int32_t &size)
{
return nullptr;
}

// clang-format on
};

class NegTestDataBase
Expand All @@ -42,7 +52,6 @@ class NegTestDataBase
virtual const unsigned char *get_model_ptr() = 0;
};

} // namespace test_model
} // namespace onert_micro
} // namespace onert_micro::test_model

#endif // ONERT_MICRO_TEST_MODELS_TEST_DATA_BASE_H
Loading