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.
19 #include "kernels/Utils.h"
21 #include "kernels/BinaryOpCommon.h"
25 namespace luci_interpreter
28 void configure_kernel_CircleMul(const circle::Operator *cur_op, BaseRuntimeGraph *runtime_graph)
30 kernels::TISOKernel kernel(cur_op, runtime_graph);
32 LUCI_INTERPRETER_CHECK(Tensor::element_type(kernel.input1()) ==
33 Tensor::element_type(kernel.input2()));
34 LUCI_INTERPRETER_CHECK(Tensor::element_type(kernel.input1()) ==
35 Tensor::element_type(kernel.input2()));
37 if (Tensor::element_type(kernel.input1()) == DataType::S16)
39 LUCI_INTERPRETER_CHECK(Tensor::zero_points(kernel.input1()).size() == 1 &&
40 Tensor::zero_points(kernel.input2()).size() == 1);
41 LUCI_INTERPRETER_CHECK(Tensor::zero_point(kernel.input1()) == 0 &&
42 Tensor::zero_point(kernel.input2()) == 0 &&
43 Tensor::zero_point(kernel.output()) == 0);
48 void execute_kernel_CircleMul(const circle::Operator *cur_op, BaseRuntimeGraph *runtime_graph)
50 kernels::TISOKernel kernel(cur_op, runtime_graph);
52 const auto *options = cur_op->builtin_options_as_MulOptions();
54 luci_interpreter::RuntimeShape input_shape1 =
55 kernels::getTensorRuntimeShape(kernel.input1(), runtime_graph);
56 luci_interpreter::RuntimeShape input_shape2 =
57 kernels::getTensorRuntimeShape(kernel.input2(), runtime_graph);
59 bool is_inplace = runtime_graph->is_inplace_op(cur_op);
61 switch (Tensor::element_type(kernel.input1()))
64 case DataType::FLOAT32:
66 auto tiso_func = luci_interpreter_pal::Mul<float>;
67 auto broadcast_tiso_func = luci_interpreter_pal::BroadcastMul4DSlow<float>;
70 kernels::evalTISOInplaceKernel<float>(tiso_func, broadcast_tiso_func, &kernel, options,
71 std::move(input_shape1), std::move(input_shape2));
75 kernels::TISOData kernel_data = kernel.readData();
76 kernels::evalTISOKernel<float>(tiso_func, broadcast_tiso_func, &kernel, &kernel_data,
77 options, std::move(input_shape1), std::move(input_shape2));
84 auto tiso_func = luci_interpreter_pal::Mul<int64_t>;
85 auto broadcast_tiso_func = luci_interpreter_pal::BroadcastMul4DSlow<int64_t>;
88 kernels::evalTISOInplaceKernel<int64_t>(tiso_func, broadcast_tiso_func, &kernel, options,
89 std::move(input_shape1), std::move(input_shape2));
93 kernels::TISOData kernel_data = kernel.readData();
94 kernels::evalTISOKernel<int64_t>(tiso_func, broadcast_tiso_func, &kernel, &kernel_data,
95 options, std::move(input_shape1), std::move(input_shape2));
101 auto tiso_func = luci_interpreter_pal::Mul<int32_t>;
102 auto broadcast_tiso_func = luci_interpreter_pal::BroadcastMul4DSlow<int32_t>;
105 kernels::evalTISOInplaceKernel<int32_t>(tiso_func, broadcast_tiso_func, &kernel, options,
106 std::move(input_shape1), std::move(input_shape2));
110 kernels::TISOData kernel_data = kernel.readData();
111 kernels::evalTISOKernel<int32_t>(tiso_func, broadcast_tiso_func, &kernel, &kernel_data,
112 options, std::move(input_shape1), std::move(input_shape2));
118 // TODO: check quantize Mul
121 auto tiso_func = [](const luci_interpreter_pal::ArithmeticParams ¶ms,
122 const luci_interpreter::RuntimeShape &input1_shape, const uint8_t *input1_data,
123 const luci_interpreter::RuntimeShape &input2_shape, const uint8_t *input2_data,
124 const luci_interpreter::RuntimeShape &output_shape, uint8_t *output_data) {
125 luci_interpreter_pal::Mul(params, input1_shape, input1_data, input2_shape, input2_data,
126 output_shape, output_data);
128 auto broadcast_tiso_func =
129 [](const luci_interpreter_pal::ArithmeticParams ¶ms, const luci_interpreter::RuntimeShape &input1_shape,
130 const uint8_t *input1_data, const luci_interpreter::RuntimeShape &input2_shape,
131 const uint8_t *input2_data, const luci_interpreter::RuntimeShape &output_shape,
132 uint8_t *output_data) {
133 luci_interpreter_pal::BroadcastMul4DSlow(params, input1_shape, input1_data, input2_shape,
134 input2_data, output_shape, output_data);
138 kernels::evalTISOInplaceQuantizedKernel<uint8_t>(tiso_func, broadcast_tiso_func, &kernel,
143 kernels::TISOData kernel_data = kernel.readData();
144 kernels::evalTISOQuantizedKernel<uint8_t>(tiso_func, broadcast_tiso_func, &kernel,
145 &kernel_data, options);
152 assert(false && "Unsupported type.");
156 } // namespace luci_interpreter