2 * Copyright (c) 2019 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.
17 #include <cker/operation/Logistic.h>
19 #include "OperationUtil.h"
21 #include "interp/Registration.h"
22 #include "ir/operation/Logistic.h"
31 void prepareLogistic(ExecEnv *env, const ir::Operation &node)
33 const auto input_index = node.getInputs().at(0);
34 const auto output_index = node.getOutputs().at(0);
36 const auto input_tensor = env->tensorAt(input_index);
38 const auto output_info = env->graph().operands().at(output_index).info();
40 // Check shape and type lhs is same with rhs
41 // TODO Util function to compare TensorInfo
42 if (output_info.total_size() == 0)
44 throw std::runtime_error{"Interp(TConv): NYI unspecified output shape"};
48 env->allocateIfNeeded(output_index, output_info);
51 const auto output_tensor = env->tensorAt(output_index);
52 if (input_tensor->data_type() != output_tensor->data_type())
54 throw std::runtime_error{"Interp(Logistic): Invalid output type"};
58 void invoke(const ITensor *input_tensor, const ITensor *output_tensor)
60 const auto input_buffer = input_tensor->bufferRO();
61 auto output_buffer = output_tensor->buffer();
63 const auto cker_input_shape = convertShape(input_tensor->tensorInfo().shape());
64 const auto cker_output_shape = convertShape(output_tensor->tensorInfo().shape());
65 const float *input_ptr = reinterpret_cast<const float *>(input_buffer);
66 float *output_ptr = reinterpret_cast<float *>(output_buffer);
68 nnfw::cker::Logistic(cker_input_shape, input_ptr, cker_output_shape, output_ptr);
71 void invokeLogistic(const ExecEnv *env, const ir::Operation &node)
73 const auto input_index = node.getInputs().at(0);
74 const auto output_index = node.getOutputs().at(0);
76 const auto input_tensor = env->tensorAt(input_index);
77 const auto output_tensor = env->tensorAt(output_index);
79 const auto data_type = input_tensor->data_type();
81 if (data_type == ir::DataType::FLOAT32)
83 invoke(input_tensor, output_tensor);
87 throw std::runtime_error{"Interp(Logistic): NYI - Unsupported data type"};
92 OpKernel *getLogistic()
94 static OpKernel kernel = {prepareLogistic, invokeLogistic};