ONE - On-device Neural Engine
Loading...
Searching...
No Matches
CumSum.cpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "kernels/CumSum.h"
18
19#include <tensorflow/lite/kernels/internal/optimized/optimized_ops.h>
20
21#include "kernels/Utils.h"
22
23namespace luci_interpreter
24{
25namespace kernels
26{
27
28CumSum::CumSum(const Tensor *input, const Tensor *axis, Tensor *output, const CumSumParams &params)
29 : KernelWithParams<CumSumParams>({input, axis}, {output}, params)
30{
31}
32
34{
35 LUCI_INTERPRETER_CHECK(input()->element_type() == output()->element_type());
36 LUCI_INTERPRETER_CHECK(input()->shape().num_dims() >= 1);
37
38 LUCI_INTERPRETER_CHECK(axis()->element_type() == DataType::S32);
39 LUCI_INTERPRETER_CHECK(axis()->shape().num_dims() == 0);
40
41 output()->resize(input()->shape());
42}
43
44void CumSum::execute() const
45{
46 switch (input()->element_type())
47 {
48 case DataType::FLOAT32:
49 tflite::optimized_ops::CumSum(getTensorData<float>(input()), getTensorShape(input()),
50 *getTensorData<int32_t>(axis()), params().exclusive,
51 params().reverse, getTensorData<float>(output()));
52 break;
53 case DataType::S32:
54 tflite::optimized_ops::CumSum(getTensorData<int32_t>(input()), getTensorShape(input()),
55 *getTensorData<int32_t>(axis()), params().exclusive,
56 params().reverse, getTensorData<int32_t>(output()));
57 break;
58 case DataType::S64:
59 tflite::optimized_ops::CumSum(getTensorData<int64_t>(input()), getTensorShape(input()),
60 *getTensorData<int32_t>(axis()), params().exclusive,
61 params().reverse, getTensorData<int64_t>(output()));
62 break;
63 default:
64 throw std::runtime_error("luci-intp CumSum Unsupported type.");
65 }
66}
67
68} // namespace kernels
69} // namespace luci_interpreter
const CumSumParams & params() const
Definition Kernel.h:67
void resize(const Shape &new_shape)
Definition Tensor.cpp:56
const Tensor * axis() const
Definition CumSum.h:36
void execute() const override
Definition CumSum.cpp:44
CumSum(const Tensor *input, const Tensor *axis, Tensor *output, const CumSumParams &params)
Definition CumSum.cpp:28
const Tensor * input() const
Definition CumSum.h:35
#define LUCI_INTERPRETER_CHECK(cond)
Definition Utils.h:36
tflite::RuntimeShape getTensorShape(const Tensor *tensor)
Definition Utils.h:194