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.
19 #include <cker/operation/BinaryArithmeticOps.h>
30 void DivLayer::divFloat32()
32 float output_activation_min, output_activation_max;
33 CalculateActivationRangeFloat(_activation, &output_activation_min, &output_activation_max);
34 nnfw::cker::BinaryArithmeticOpParam op_params;
35 op_params.type = nnfw::cker::BinaryArithmeticOpType::DIV;
36 op_params.float_activation_max = output_activation_max;
37 op_params.float_activation_min = output_activation_min;
39 if (!HaveSameShapes(_lhs, _rhs))
41 nnfw::cker::BroadcastBinaryArithmeticOpSlow(
42 op_params, convertToExtendedCkerShape(_lhs),
43 reinterpret_cast<const float *>(_lhs->buffer()), convertToExtendedCkerShape(_rhs),
44 reinterpret_cast<const float *>(_rhs->buffer()), convertToExtendedCkerShape(_output),
45 reinterpret_cast<float *>(_output->buffer()));
49 nnfw::cker::BinaryArithmeticOp(
50 op_params, convertTensorToCkerShape(_lhs), reinterpret_cast<const float *>(_lhs->buffer()),
51 convertTensorToCkerShape(_rhs), reinterpret_cast<const float *>(_rhs->buffer()),
52 convertTensorToCkerShape(_output), reinterpret_cast<float *>(_output->buffer()));
55 void DivLayer::divQuant8()
57 int32_t output_activation_min, output_activation_max;
58 CalculateActivationRangeUint8(_activation, _output, &output_activation_min,
59 &output_activation_max);
60 // nnfw::cker::BinaryArithmeticOpParam op_params;
61 // op_params.quantized_activation_max = output_activation_max;
62 // op_params.quantized_activation_min = output_activation_min;
64 // cker quant8 div is not implemented yet
65 throw std::runtime_error{"Div NYI for quantized"};
68 void DivLayer::configure(const operand::Tensor *lhs, const operand::Tensor *rhs,
69 const ir::Activation activation, operand::Tensor *output)
73 _activation = activation;
79 if (_output->data_type() == OperandType::FLOAT32)
83 else if (_output->data_type() == OperandType::QUANT8_ASYMM)
91 } // namespace backend