ONE - On-device Neural Engine
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Exp.cpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
3 * Copyright 2018 The TensorFlow Authors. All Rights Reserved.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#include "Builders.h"
19#include "kernels/Utils.h"
20#include "SISOKernel.h"
21
22#include "PALExp.h"
23
24namespace luci_interpreter
25{
26
27void configure_kernel_CircleExp(const circle::Operator *cur_op, BaseRuntimeGraph *runtime_graph)
28{
29 kernels::SISOKernel kernel(cur_op, runtime_graph);
30
31 LUCI_INTERPRETER_CHECK(Tensor::element_type(kernel.input()) ==
32 Tensor::element_type(kernel.output()));
33 LUCI_INTERPRETER_CHECK(Tensor::num_elements(kernel.input()) ==
34 Tensor::num_elements(kernel.output()));
35 LUCI_INTERPRETER_CHECK(Tensor::num_dims(kernel.input()) == Tensor::num_dims(kernel.output()));
36}
37
38void execute_kernel_CircleExp(const circle::Operator *cur_op, BaseRuntimeGraph *runtime_graph)
39{
40 kernels::SISOKernel kernel(cur_op, runtime_graph);
41
42 const auto *input_data = runtime_graph->getDataByTensor(kernel.input());
43 assert(input_data);
44
45 auto *output_data = runtime_graph->getDataByTensor(kernel.output());
46
47 bool is_inplace = runtime_graph->is_inplace_op(cur_op);
48
49 switch (Tensor::element_type(kernel.input()))
50 {
51#ifndef DIS_FLOAT
52 case DataType::FLOAT32:
53 {
54 const float *input_data_float = kernels::getTensorData<float>(input_data);
55 float *output_data_float = kernels::getTensorData<float>(output_data);
56 if (is_inplace)
57 {
58 output_data_float = const_cast<float *>(input_data_float);
59 }
60
61 assert(output_data_float);
62
63 const int flat_size =
64 kernels::getTensorRuntimeShape(kernel.input(), runtime_graph).flatSize();
65
66 luci_interpreter_pal::Exp(flat_size, input_data_float, output_data_float);
67 break;
68 }
69#endif // DIS_FLOAT
70 default:
71 assert(false && "Unsupported type");
72 }
73
74 if (is_inplace)
75 runtime_graph->makeInplaceOperation(kernel.input(), kernel.output());
76}
77
78} // namespace luci_interpreter
void makeInplaceOperation(const circle::Tensor *src_tensor, const circle::Tensor *dst_tensor)
bool is_inplace_op(const circle::Operator *op)
uint8_t * getDataByTensor(const circle::Tensor *raw_tensor)
const circle::Tensor * output() const
Definition SISOKernel.h:47
const circle::Tensor * input() const
Definition SISOKernel.h:46
#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 Exp(const int flat_size, const float *input_data, float *output_data)
Definition PALExp.h:26
void execute_kernel_CircleExp(const circle::Operator *cur_op, BaseRuntimeGraph *runtime_graph)
Definition Exp.cpp:38
void configure_kernel_CircleExp(const circle::Operator *cur_op, BaseRuntimeGraph *runtime_graph)
Definition Exp.cpp:27