2 * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include "kernels/Utils.h"
19 #include "SISOKernel.h"
21 #include "PALSoftmax.h"
23 namespace luci_interpreter
30 void evalFloat(const circle::Tensor *input, const circle::Tensor *output,
31 const circle::SoftmaxOptions *options, BaseRuntimeGraph *runtime_graph)
33 const auto *input_data = runtime_graph->getDataByTensor(input);
34 auto *output_data = runtime_graph->getDataByTensor(output);
36 luci_interpreter_pal::Softmax(options->beta(), kernels::getTensorShape(input),
37 kernels::getTensorData<float>(input_data),
38 kernels::getTensorData<float>(output_data));
44 void configure_kernel_CircleSoftmax(const circle::Operator *cur_op, BaseRuntimeGraph *runtime_graph)
46 kernels::SISOKernel kernel(cur_op, runtime_graph);
48 LUCI_INTERPRETER_CHECK(Tensor::element_type(kernel.input()) ==
49 Tensor::element_type(kernel.output()));
50 LUCI_INTERPRETER_CHECK(Tensor::num_dims(kernel.input()) >= 1);
53 if (Tensor::element_type(kernel.input()) == DataType::U8 ||
54 Tensor::element_type(kernel.input()) == DataType::S8)
56 LUCI_INTERPRETER_CHECK(Tensor::element_type(kernel.input()) == DataType::S8 ||
57 Tensor::zero_point(kernel.output()) == 0);
58 LUCI_INTERPRETER_CHECK(Tensor::element_type(kernel.input()) == DataType::U8 ||
59 Tensor::zero_point(kernel.output()) ==
60 std::numeric_limits<int8_t>::min());
65 void execute_kernel_CircleSoftmax(const circle::Operator *cur_op, BaseRuntimeGraph *runtime_graph)
67 kernels::SISOKernel kernel(cur_op, runtime_graph);
69 const auto *options = cur_op->builtin_options_as_SoftmaxOptions();
71 switch (Tensor::element_type(kernel.input()))
74 case DataType::FLOAT32:
75 evalFloat(kernel.input(), kernel.output(), options, runtime_graph);
79 assert(false && "Unsupported type.");
83 } // namespace luci_interpreter