ONE - On-device Neural Engine
Loading...
Searching...
No Matches
BroadcastTo.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 "Builders.h"
18#include "kernels/Utils.h"
19#include "TISOKernel.h"
20
21#include "PALBroadcastTo.h"
22
23namespace luci_interpreter
24{
25namespace
26{
27constexpr int kMaxDims = 5;
28} // namespace
29
30void configure_kernel_CircleBroadcastTo(const circle::Operator *cur_op,
31 BaseRuntimeGraph *runtime_graph)
32{
33 kernels::TISOKernel kernel(cur_op, runtime_graph);
34
35 LUCI_INTERPRETER_CHECK(Tensor::element_type(kernel.input1()) ==
36 Tensor::element_type(kernel.output()));
37 LUCI_INTERPRETER_CHECK(Tensor::element_type(kernel.input2()) == DataType::S32 or
38 Tensor::element_type(kernel.input2()) == DataType::S64);
39
40 // Ensure output dims is not less than input dims.
41 int input_num_dims = Tensor::num_dims(kernel.input1());
42 int output_num_dims = Tensor::num_dims(kernel.output());
43 int shape_num_dims = Tensor::dim(kernel.input2(), 0);
44
45 LUCI_INTERPRETER_CHECK(output_num_dims == shape_num_dims);
46 LUCI_INTERPRETER_CHECK(input_num_dims <= output_num_dims);
47 LUCI_INTERPRETER_CHECK(output_num_dims <= kMaxDims);
48}
49
50void execute_kernel_CircleBroadcastTo(const circle::Operator *cur_op,
51 BaseRuntimeGraph *runtime_graph)
52{
53 kernels::TISOKernel kernel(cur_op, runtime_graph);
54
55 const auto *input_data = runtime_graph->getDataByTensor(kernel.input1());
56 assert(input_data);
57
58 auto *output_data = runtime_graph->getDataByTensor(kernel.output());
59
60 luci_interpreter_pal::BroadcastTo<kMaxDims>(
61 kernels::getTensorRuntimeShape(kernel.input1(), runtime_graph), input_data,
62 kernels::getTensorRuntimeShape(kernel.output(), runtime_graph), output_data,
63 Tensor::element_type(kernel.input1()));
64}
65} // namespace luci_interpreter
uint8_t * getDataByTensor(const circle::Tensor *raw_tensor)
const circle::Tensor * output() const
Definition TISOKernel.h:62
const circle::Tensor * input2() const
Definition TISOKernel.h:61
const circle::Tensor * input1() const
Definition TISOKernel.h:60
#define LUCI_INTERPRETER_CHECK(cond)
Definition Utils.h:36
luci_interpreter::RuntimeShape getTensorRuntimeShape(const circle::Tensor *circle_tensor, BaseRuntimeGraph *runtime_graph)
Definition Utils.cpp:29
void configure_kernel_CircleBroadcastTo(const circle::Operator *cur_op, BaseRuntimeGraph *runtime_graph)
void execute_kernel_CircleBroadcastTo(const circle::Operator *cur_op, BaseRuntimeGraph *runtime_graph)
const loco::Dimension & dim(uint32_t axis) const
Definition Tensor.h:44