2 * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
3 * Copyright 2019 The TensorFlow Authors. All Rights Reserved.
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include "kernels/Mul.h"
20 #include "kernels/Utils.h"
22 #include <tensorflow/lite/kernels/internal/reference/reference_ops.h>
26 namespace luci_interpreter
31 Mul::Mul(const Tensor *input1, const Tensor *input2, Tensor *output, const MulParams ¶ms)
32 : KernelWithParams<MulParams>({input1, input2}, {output}, params)
38 assert(input1()->element_type() == input2()->element_type());
39 output()->resize(calculateShapeForBroadcast(input1()->shape(), input2()->shape()));
42 void Mul::execute() const
44 switch (input1()->element_type())
46 case DataType::FLOAT32:
50 throw std::runtime_error("Unsupported type.");
54 void Mul::evalFloat() const
56 float activation_min{};
57 float activation_max{};
58 calculateActivationRange(_params.activation, &activation_min, &activation_max);
60 tflite::ArithmeticParams params{};
61 params.float_activation_min = activation_min;
62 params.float_activation_max = activation_max;
64 const bool need_broadcast = tflite::reference_ops::ProcessBroadcastShapes(
65 getTensorShape(input1()), getTensorShape(input2()), ¶ms);
69 tflite::reference_ops::BroadcastMul4DSlow(
70 params, getTensorShape(input1()), getTensorData<float>(input1()), getTensorShape(input2()),
71 getTensorData<float>(input2()), getTensorShape(output()), getTensorData<float>(output()));
75 tflite::reference_ops::Mul(params, getTensorShape(input1()), getTensorData<float>(input1()),
76 getTensorShape(input2()), getTensorData<float>(input2()),
77 getTensorShape(output()), getTensorData<float>(output()));
81 } // namespace kernels
82 } // namespace luci_interpreter