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 = 0, output_activation_max = 0;
33 CalculateActivationRange(_activation, &output_activation_min, &output_activation_max);
34 nnfw::cker::BinaryArithmeticOpParam op_params;
35 op_params.float_activation_max = output_activation_max;
36 op_params.float_activation_min = output_activation_min;
38 const bool requires_broadcast = !HaveSameShapes(_lhs, _rhs);
39 if (requires_broadcast)
41 nnfw::cker::BroadcastBinaryArithmeticOp<nnfw::cker::BinaryArithmeticOpType::DIV>(
42 op_params, getTensorShape(_lhs), reinterpret_cast<const float *>(_lhs->buffer()),
43 getTensorShape(_rhs), reinterpret_cast<const float *>(_rhs->buffer()),
44 getTensorShape(_output), reinterpret_cast<float *>(_output->buffer()));
48 nnfw::cker::BinaryArithmeticOp<nnfw::cker::BinaryArithmeticOpType::DIV>(
49 op_params, getTensorShape(_lhs), reinterpret_cast<const float *>(_lhs->buffer()),
50 getTensorShape(_rhs), reinterpret_cast<const float *>(_rhs->buffer()),
51 getTensorShape(_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 // op_params.quantized_activation_max = output_activation_max;
61 // op_params.quantized_activation_min = output_activation_min;
63 // cker quant8 div is not implemented yet
64 throw std::runtime_error{"Div NYI for quantized"};
67 void DivLayer::configure(const IPortableTensor *lhs, const IPortableTensor *rhs,
68 const ir::Activation activation, IPortableTensor *output)
72 _activation = activation;
78 if (_output->data_type() == OperandType::FLOAT32)
82 else if (_output->data_type() == OperandType::QUANT_UINT8_ASYMM)
88 throw std::runtime_error{"Div: unsupported data type"};
94 } // namespace backend