ONE - On-device Neural Engine
Loading...
Searching...
No Matches
DynamicUpdateSlice.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2025 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 "DynamicUpdateSlice.h"
18#include "OperationUtils.h"
19
21
23{
24
26 : _operand(nullptr), _update(nullptr), _indices(nullptr), _output(nullptr)
27{
28 // DO NOTHING
29}
30
32
34 const IPortableTensor *update,
35 const IPortableTensor *indices, IPortableTensor *output)
36{
37 assert(operand != nullptr);
38 assert(update != nullptr);
39 assert(indices != nullptr);
40 assert(output != nullptr);
41
42 _operand = operand;
43 _update = update;
44 _indices = indices;
45 _output = output;
46}
47
49{
50 // Get indices data as int64 type vector
51 std::vector<int64_t> indices_data(_indices->getShape().num_elements());
52 for (size_t i = 0; i < indices_data.size(); ++i)
53 {
54 if (_indices->data_type() == OperandType::INT32)
55 {
56 indices_data[i] = static_cast<int64_t>(getBuffer<int32_t>(_indices)[i]);
57 }
58 else
59 {
60 assert(_indices->data_type() == OperandType::INT64);
61 indices_data[i] = getBuffer<int64_t>(_indices)[i];
62 }
63 }
64
65 switch (_operand->data_type())
66 {
67 case OperandType::FLOAT32:
68 nnfw::cker::DynamicUpdateSlice()(getShape(_operand), getBuffer<float>(_operand),
69 getShape(_update), getBuffer<float>(_update), indices_data,
70 getBuffer<float>(_output));
71 break;
72 case OperandType::QUANT_UINT8_ASYMM:
73 nnfw::cker::DynamicUpdateSlice()(getShape(_operand), getBuffer<uint8_t>(_operand),
74 getShape(_update), getBuffer<uint8_t>(_update), indices_data,
75 getBuffer<uint8_t>(_output));
76 break;
77 case OperandType::QUANT_INT16_SYMM:
78 nnfw::cker::DynamicUpdateSlice()(getShape(_operand), getBuffer<int8_t>(_operand),
79 getShape(_update), getBuffer<int8_t>(_update), indices_data,
80 getBuffer<int8_t>(_output));
81 break;
82 default:
83 throw std::runtime_error{"DynamicUpdateSlice: NYI - unsupported data type"};
84 break;
85 }
86}
87
88} // namespace onert::backend::cpu::ops
A tensor class that is portable for other backends.
ir::DataType data_type() const override final
ir::Shape getShape() const override final
Get ir::Shape of tensor.
void configure(const IPortableTensor *operand, const IPortableTensor *update, const IPortableTensor *indices, IPortableTensor *output)
nnfw::cker::Shape getShape(const IPortableTensor *tensor)