18#ifndef LUCI_INTERPRETER_PAL_REFERENCE_OPS_H
19#define LUCI_INTERPRETER_PAL_REFERENCE_OPS_H
32#include "third_party/eigen3/Eigen/Core"
33#include "fixedpoint/fixedpoint.h"
34#include "ruy/profiler/instrumentation.h"
35#include "tensorflow/lite/c/common.h"
36#include "tensorflow/lite/kernels/internal/common.h"
37#include "tensorflow/lite/kernels/internal/quantization_util.h"
38#include "tensorflow/lite/kernels/internal/reference/add.h"
39#include "tensorflow/lite/kernels/internal/reference/add_n.h"
40#include "tensorflow/lite/kernels/internal/reference/arg_min_max.h"
41#include "tensorflow/lite/kernels/internal/reference/batch_matmul.h"
42#include "tensorflow/lite/kernels/internal/reference/batch_to_space_nd.h"
43#include "tensorflow/lite/kernels/internal/reference/binary_function.h"
44#include "tensorflow/lite/kernels/internal/reference/cast.h"
45#include "tensorflow/lite/kernels/internal/reference/ceil.h"
46#include "tensorflow/lite/kernels/internal/reference/comparisons.h"
47#include "tensorflow/lite/kernels/internal/reference/concatenation.h"
48#include "tensorflow/lite/kernels/internal/reference/conv.h"
49#include "tensorflow/lite/kernels/internal/reference/depth_to_space.h"
50#include "tensorflow/lite/kernels/internal/reference/dequantize.h"
51#include "tensorflow/lite/kernels/internal/reference/div.h"
52#include "tensorflow/lite/kernels/internal/reference/elu.h"
53#include "tensorflow/lite/kernels/internal/reference/exp.h"
54#include "tensorflow/lite/kernels/internal/reference/fill.h"
55#include "tensorflow/lite/kernels/internal/reference/floor.h"
56#include "tensorflow/lite/kernels/internal/reference/floor_div.h"
57#include "tensorflow/lite/kernels/internal/reference/floor_mod.h"
58#include "tensorflow/lite/kernels/internal/reference/fully_connected.h"
59#include "tensorflow/lite/kernels/internal/reference/gather.h"
60#include "tensorflow/lite/kernels/internal/reference/hard_swish.h"
61#include "tensorflow/lite/kernels/internal/reference/l2normalization.h"
62#include "tensorflow/lite/kernels/internal/reference/leaky_relu.h"
63#include "tensorflow/lite/kernels/internal/reference/log_softmax.h"
64#include "tensorflow/lite/kernels/internal/reference/logistic.h"
65#include "tensorflow/lite/kernels/internal/reference/maximum_minimum.h"
66#include "tensorflow/lite/kernels/internal/reference/mul.h"
67#include "tensorflow/lite/kernels/internal/reference/neg.h"
68#include "tensorflow/lite/kernels/internal/reference/pad.h"
69#include "tensorflow/lite/kernels/internal/reference/pooling.h"
70#include "tensorflow/lite/kernels/internal/reference/prelu.h"
71#include "tensorflow/lite/kernels/internal/reference/process_broadcast_shapes.h"
72#include "tensorflow/lite/kernels/internal/reference/quantize.h"
73#include "tensorflow/lite/kernels/internal/reference/reduce.h"
74#include "tensorflow/lite/kernels/internal/reference/requantize.h"
75#include "tensorflow/lite/kernels/internal/reference/resize_bilinear.h"
76#include "tensorflow/lite/kernels/internal/reference/resize_nearest_neighbor.h"
77#include "tensorflow/lite/kernels/internal/reference/round.h"
78#include "tensorflow/lite/kernels/internal/reference/softmax.h"
79#include "tensorflow/lite/kernels/internal/reference/space_to_batch_nd.h"
80#include "tensorflow/lite/kernels/internal/reference/space_to_depth.h"
81#include "tensorflow/lite/kernels/internal/reference/strided_slice.h"
82#include "tensorflow/lite/kernels/internal/reference/string_comparisons.h"
83#include "tensorflow/lite/kernels/internal/reference/sub.h"
84#include "tensorflow/lite/kernels/internal/reference/tanh.h"
85#include "tensorflow/lite/kernels/internal/reference/transpose.h"
86#include "tensorflow/lite/kernels/internal/reference/transpose_conv.h"
87#include "tensorflow/lite/kernels/internal/strided_slice_logic.h"
88#include "tensorflow/lite/kernels/internal/tensor.h"
89#include "tensorflow/lite/kernels/internal/types.h"
93namespace reference_ops
97inline void Relu(
const RuntimeShape &input_shape,
const T *input_data,
101 for (
int i = 0; i < flat_size; ++i)
105 const T clamped = val < lower ? lower : val;
111inline void Relu1(
const RuntimeShape &input_shape,
const T *input_data,
114 ruy::profiler::ScopeLabel label(
"Relu1 (not fused)");
116 for (
int i = 0; i < flat_size; ++i)
121 const T clamped = val > upper ? upper : val < lower ? lower : val;
126inline void Relu6(
const RuntimeShape &input_shape,
const float *input_data,
129 ruy::profiler::ScopeLabel label(
"Relu6 (not fused)");
131 for (
int i = 0; i < flat_size; ++i)
134 const float upper = 6;
135 const float lower = 0;
136 const float clamped = val > upper ? upper : val < lower ? lower : val;
142inline void ReluX(
const tflite::ReluParams ¶ms,
const RuntimeShape &input_shape,
143 const T *input_data,
const RuntimeShape &
output_shape, T *output_data)
145 ruy::profiler::ScopeLabel label(
"Quantized ReluX (not fused)");
147 for (
int i = 0; i < flat_size; ++i)
151 params.output_multiplier,
152 params.output_shift);
153 clamped = std::max(params.quantized_activation_min, clamped);
154 clamped = std::min(params.quantized_activation_max, clamped);
160inline void ReluX(
const tflite::ActivationParams ¶ms,
const RuntimeShape &input_shape,
161 const T *input_data,
const RuntimeShape &
output_shape, T *output_data)
163 ruy::profiler::ScopeLabel label(
"Quantized ReluX (not fused)");
165 const T max_value = params.quantized_activation_max;
166 const T min_value = params.quantized_activation_min;
167 for (
int i = 0; i < flat_size; ++i)
170 const T clamped = val > max_value ? max_value : val < min_value ? min_value : val;
180 const RuntimeShape &unswitched_input1_shape,
181 const uint8 *unswitched_input1_data,
182 const RuntimeShape &unswitched_input2_shape,
183 const uint8 *unswitched_input2_data,
186 ArithmeticParams switched_params = unswitched_params;
187 switched_params.input1_offset = unswitched_params.input2_offset;
188 switched_params.input2_offset = unswitched_params.input1_offset;
190 const bool use_unswitched = unswitched_params.broadcast_category ==
191 tflite::BroadcastableOpCategory::kFirstInputBroadcastsFast;
193 const ArithmeticParams ¶ms = use_unswitched ? unswitched_params : switched_params;
194 const uint8 *
input1_data = use_unswitched ? unswitched_input1_data : unswitched_input2_data;
195 const uint8 *
input2_data = use_unswitched ? unswitched_input2_data : unswitched_input1_data;
204 int y0 = params.broadcast_shape[0];
205 int y1 = params.broadcast_shape[1];
206 int y2 = params.broadcast_shape[2];
207 int y3 = params.broadcast_shape[3];
208 int y4 = params.broadcast_shape[4];
209 for (
int i0 = 0; i0 < y0; ++i0)
211 const uint8 *input2_data_ptr;
212 for (
int i1 = 0; i1 < y1; ++i1)
214 input2_data_ptr = input2_data_reset;
215 for (
int i2 = 0; i2 < y2; ++i2)
217 for (
int i3 = 0; i3 < y3; ++i3)
219 MulElementwise(y4, params, input1_data_ptr, input2_data_ptr, output_data_ptr);
220 input2_data_ptr += y4;
221 output_data_ptr += y4;
223 input1_data_ptr += y4;
226 input2_data_reset = input2_data_ptr;
230inline void Mul(
const ArithmeticParams ¶ms,
const RuntimeShape &input1_shape,
231 const int16 *input1_data,
const RuntimeShape &input2_shape,
234 ruy::profiler::ScopeLabel label(
"Mul/Int16");
238 for (
int i = 0; i < flat_size; i++)
241 using F0 = gemmlowp::FixedPoint<std::int16_t, 0>;
243 F0 unclamped_result = F0::FromRaw(input1_data[i]) * F0::FromRaw(input2_data[i]);
248inline void Mul(
const ArithmeticParams ¶ms,
const RuntimeShape &input1_shape,
249 const int16 *input1_data,
const RuntimeShape &input2_shape,
252 ruy::profiler::ScopeLabel label(
"Mul/Int16Uint8");
253 int32 output_offset = params.output_offset;
254 int32 output_activation_min = params.quantized_activation_min;
255 int32 output_activation_max = params.quantized_activation_max;
256 TFLITE_DCHECK_LE(output_activation_min, output_activation_max);
260 for (
int i = 0; i < flat_size; i++)
263 using F0 = gemmlowp::FixedPoint<std::int16_t, 0>;
265 F0 unclamped_result = F0::FromRaw(input1_data[i]) * F0::FromRaw(input2_data[i]);
266 int16 rescaled_result = gemmlowp::RoundingDivideByPOT(unclamped_result.raw(), 8);
267 int16 clamped_result = std::min<int16>(output_activation_max - output_offset, rescaled_result);
268 clamped_result = std::max<int16>(output_activation_min - output_offset, clamped_result);
273inline void Sub16(
const ArithmeticParams ¶ms,
const RuntimeShape &input1_shape,
274 const int16_t *input1_data,
const RuntimeShape &input2_shape,
275 const int16_t *input2_data,
const RuntimeShape &
output_shape,
276 int16_t *output_data)
278 ruy::profiler::ScopeLabel label(
"Sub/Int16");
279 const int input1_shift = params.input1_shift;
281 const int16 output_activation_min = params.quantized_activation_min;
282 const int16 output_activation_max = params.quantized_activation_max;
284 TFLITE_DCHECK(input1_shift == 0 || params.input2_shift == 0);
285 TFLITE_DCHECK_LE(input1_shift, 0);
286 TFLITE_DCHECK_LE(params.input2_shift, 0);
289 const int input_right_shift = input1_shift == 0 ? -params.input2_shift : -input1_shift;
291 if (input1_shift == 0)
294 using F0 = gemmlowp::FixedPoint<std::int16_t, 0>;
295 for (
int i = 0; i < flat_size; ++i)
297 F0 input_ready_scaled = F0::FromRaw(not_shift_input[i]);
299 F0::FromRaw(gemmlowp::RoundingDivideByPOT(shift_input[i], input_right_shift));
300 F0
result = SaturatingSub(input_ready_scaled, scaled_input);
302 const int16 clamped_output =
303 std::min(output_activation_max, std::max(output_activation_min, raw_output));
310 using F0 = gemmlowp::FixedPoint<std::int16_t, 0>;
311 for (
int i = 0; i < flat_size; ++i)
313 F0 input_ready_scaled = F0::FromRaw(not_shift_input[i]);
315 F0::FromRaw(gemmlowp::RoundingDivideByPOT(shift_input[i], input_right_shift));
316 F0
result = SaturatingSub(scaled_input, input_ready_scaled);
318 const int16 clamped_output =
319 std::min(output_activation_max, std::max(output_activation_min, raw_output));
325template <
typename Scalar>
326void Pack(
const PackParams ¶ms,
const RuntimeShape *
const *input_shapes,
327 const Scalar *
const *input_data,
const RuntimeShape &
output_shape, Scalar *output_data)
329 ruy::profiler::ScopeLabel label(
"Pack");
331 int axis = params.axis;
332 int inputs_count = params.inputs_count;
335 for (
int i = 0; i < axis; i++)
340 for (
int i = params.axis + 1; i < dimensions; i++)
344 TFLITE_DCHECK_EQ((**input_shapes).FlatSize(), copy_size * outer_size);
346 for (
int i = 0; i < inputs_count; ++i)
348 for (
int k = 0; k < outer_size; k++)
350 const Scalar *input_ptr =
input_data[i] + copy_size * k;
351 int loc = k * inputs_count * copy_size + i * copy_size;
352 memcpy(output_data + loc, input_ptr, copy_size *
sizeof(Scalar));
357template <
typename Scalar>
358void Unpack(
const UnpackParams ¶ms,
const RuntimeShape &input_shape,
const Scalar *input_data,
359 const RuntimeShape &
output_shape, Scalar *
const *output_datas)
361 ruy::profiler::ScopeLabel label(
"Unpack");
362 const int dimensions = input_shape.DimensionsCount();
363 const int outputs_count = params.num_split;
366 int axis = params.axis;
371 TFLITE_DCHECK_GE(axis, 0);
372 TFLITE_DCHECK_LT(axis, dimensions);
373 for (
int i = 0; i < axis; ++i)
375 outer_size *= input_shape.Dims(i);
378 for (
int i = axis + 1; i < dimensions; ++i)
380 copy_size *= input_shape.Dims(i);
382 TFLITE_DCHECK_EQ(
output_shape.FlatSize(), copy_size * outer_size);
384 for (
int i = 0; i < outputs_count; ++i)
386 for (
int k = 0; k < outer_size; k++)
388 Scalar *output_ptr = output_datas[i] + copy_size * k;
389 int loc = k * outputs_count * copy_size + i * copy_size;
390 memcpy(output_ptr, input_data + loc, copy_size *
sizeof(Scalar));
395template <
typename Scalar>
396void PackWithScaling(
const PackParams ¶ms,
const RuntimeShape *
const *input_shapes,
400 ruy::profiler::ScopeLabel label(
"PackWithScaling");
402 int axis = params.axis;
403 const int32 *input_zeropoint = params.input_zeropoint;
404 const float *input_scale = params.input_scale;
405 int inputs_count = params.inputs_count;
406 const int32 output_zeropoint = params.output_zeropoint;
407 const float output_scale = params.output_scale;
410 for (
int i = 0; i < axis; i++)
415 for (
int i = axis + 1; i < dimensions; i++)
419 TFLITE_DCHECK_EQ((**input_shapes).FlatSize(), copy_size * outer_size);
422 const float inverse_output_scale = 1.f / output_scale;
423 for (
int k = 0; k < outer_size; k++)
425 for (
int i = 0; i < inputs_count; ++i)
427 if (input_zeropoint[i] == output_zeropoint && input_scale[i] == output_scale)
429 memcpy(output_ptr, input_data[i] + k * copy_size, copy_size *
sizeof(Scalar));
434 const float scale = input_scale[i] * inverse_output_scale;
435 const float bias = -input_zeropoint[i] *
scale;
437 for (
int j = 0; j < copy_size; ++j)
440 static_cast<int32_t
>(std::round(input_ptr[j] * scale + bias)) + output_zeropoint;
441 output_ptr[j] =
static_cast<uint8_t
>(std::max(std::min(255, value), 0));
444 output_ptr += copy_size;
449template <
typename Scalar>
450void DepthConcatenation(
const ConcatenationParams ¶ms,
const RuntimeShape *
const *input_shapes,
451 const Scalar *
const *input_data,
const RuntimeShape &
output_shape,
454 ruy::profiler::ScopeLabel label(
"DepthConcatenation");
455 auto params_copy = params;
456 params_copy.axis = 3;
460inline void LstmCell(
const LstmCellParams ¶ms,
const RuntimeShape &unextended_input_shape,
461 const float *input_data,
const RuntimeShape &unextended_prev_activ_shape,
462 const float *prev_activ_data,
const RuntimeShape &weights_shape,
463 const float *weights_data,
const RuntimeShape &unextended_bias_shape,
464 const float *bias_data,
const RuntimeShape &unextended_prev_state_shape,
465 const float *prev_state_data,
466 const RuntimeShape &unextended_output_state_shape,
float *output_state_data,
467 const RuntimeShape &unextended_output_activ_shape,
float *output_activ_data,
468 const RuntimeShape &unextended_concat_temp_shape,
float *concat_temp_data,
469 const RuntimeShape &unextended_activ_temp_shape,
float *activ_temp_data)
471 TFLITE_DCHECK_LE(unextended_input_shape.DimensionsCount(), 4);
472 TFLITE_DCHECK_LE(unextended_prev_activ_shape.DimensionsCount(), 4);
473 TFLITE_DCHECK_LE(unextended_bias_shape.DimensionsCount(), 4);
474 TFLITE_DCHECK_LE(unextended_prev_state_shape.DimensionsCount(), 4);
475 TFLITE_DCHECK_LE(unextended_output_state_shape.DimensionsCount(), 4);
476 TFLITE_DCHECK_LE(unextended_output_activ_shape.DimensionsCount(), 4);
477 TFLITE_DCHECK_LE(unextended_concat_temp_shape.DimensionsCount(), 4);
478 TFLITE_DCHECK_LE(unextended_activ_temp_shape.DimensionsCount(), 4);
479 const RuntimeShape input_shape = RuntimeShape::ExtendedShape(4, unextended_input_shape);
480 const RuntimeShape prev_activ_shape = RuntimeShape::ExtendedShape(4, unextended_prev_activ_shape);
481 const RuntimeShape bias_shape = RuntimeShape::ExtendedShape(4, unextended_bias_shape);
482 const RuntimeShape prev_state_shape = RuntimeShape::ExtendedShape(4, unextended_prev_state_shape);
483 const RuntimeShape output_state_shape =
484 RuntimeShape::ExtendedShape(4, unextended_output_state_shape);
485 const RuntimeShape output_activ_shape =
486 RuntimeShape::ExtendedShape(4, unextended_output_activ_shape);
487 const RuntimeShape concat_temp_shape =
488 RuntimeShape::ExtendedShape(4, unextended_concat_temp_shape);
489 const RuntimeShape activ_temp_shape = RuntimeShape::ExtendedShape(4, unextended_activ_temp_shape);
490 TFLITE_DCHECK_GE(weights_shape.DimensionsCount(), 2);
492 const int weights_dim_count = weights_shape.DimensionsCount();
493 const int batches =
MatchingDim(input_shape, 0, prev_activ_shape, 0, prev_state_shape, 0,
494 output_state_shape, 0, output_activ_shape, 0);
495 const int height =
MatchingDim(input_shape, 1, prev_activ_shape, 1, prev_state_shape, 1,
496 output_state_shape, 1, output_activ_shape, 1);
497 const int width =
MatchingDim(input_shape, 2, prev_activ_shape, 2, prev_state_shape, 2,
498 output_state_shape, 2, output_activ_shape, 2);
499 const int input_depth = input_shape.Dims(3);
500 const int prev_activ_depth = prev_activ_shape.Dims(3);
501 const int total_input_depth = prev_activ_depth + input_depth;
502 TFLITE_DCHECK_EQ(weights_shape.Dims(weights_dim_count - 1), total_input_depth);
504 const int intern_activ_depth =
MatchingDim(weights_shape, weights_dim_count - 2, bias_shape, 3);
505 TFLITE_DCHECK_EQ(weights_shape.FlatSize(), intern_activ_depth * total_input_depth);
506 TFLITE_DCHECK_EQ(intern_activ_depth % 4, 0);
507 const int output_depth =
MatchingDim(prev_state_shape, 3, prev_activ_shape, 3, output_state_shape,
508 3, output_activ_shape, 3);
509 TFLITE_DCHECK_EQ(output_depth, intern_activ_depth / 4);
512 std::vector<float const *> concat_input_arrays_data;
513 std::vector<RuntimeShape const *> concat_input_arrays_shapes;
514 concat_input_arrays_data.push_back(input_data);
515 concat_input_arrays_data.push_back(prev_activ_data);
516 concat_input_arrays_shapes.push_back(&input_shape);
517 concat_input_arrays_shapes.push_back(&prev_activ_shape);
518 tflite::ConcatenationParams concat_params;
519 concat_params.axis = 3;
520 concat_params.inputs_count = concat_input_arrays_data.size();
521 Concatenation(concat_params, &(concat_input_arrays_shapes[0]), &(concat_input_arrays_data[0]),
522 concat_temp_shape, concat_temp_data);
525 tflite::FullyConnectedParams fc_params;
526 fc_params.float_activation_min = std::numeric_limits<float>::lowest();
527 fc_params.float_activation_max = std::numeric_limits<float>::max();
528 FullyConnected(fc_params, concat_temp_shape, concat_temp_data, weights_shape, weights_data,
529 bias_shape, bias_data, activ_temp_shape, activ_temp_data);
532 for (
int b = 0;
b < batches; ++
b)
534 for (
int w = 0;
w < width; ++
w)
536 for (
int h = 0;
h < height; ++
h)
538 for (
int c = 0; c < output_depth; ++c)
540 const float input_gate =
543 std::exp(-activ_temp_data[
Offset(activ_temp_shape, b, h, w, 0 * output_depth + c)]));
544 const float new_input =
545 std::tanh(activ_temp_data[
Offset(activ_temp_shape, b, h, w, 1 * output_depth + c)]);
546 const float forget_gate =
549 std::exp(-activ_temp_data[
Offset(activ_temp_shape, b, h, w, 2 * output_depth + c)]));
550 const float output_gate =
553 std::exp(-activ_temp_data[
Offset(activ_temp_shape, b, h, w, 3 * output_depth + c)]));
554 const float new_state =
555 input_gate * new_input +
556 forget_gate * prev_state_data[
Offset(prev_state_shape, b, h, w, c)];
557 output_state_data[
Offset(output_state_shape, b, h, w, c)] = new_state;
558 output_activ_data[
Offset(output_activ_shape, b, h, w, c)] =
559 output_gate * std::tanh(new_state);
650template <
int StateIntegerBits>
652LstmCell(
const LstmCellParams ¶ms,
const RuntimeShape &unextended_input_shape,
653 const uint8 *input_data_uint8,
const RuntimeShape &unextended_prev_activ_shape,
654 const uint8 *prev_activ_data_uint8,
const RuntimeShape &weights_shape,
655 const uint8 *weights_data_uint8,
const RuntimeShape &unextended_bias_shape,
656 const int32 *bias_data_int32,
const RuntimeShape &unextended_prev_state_shape,
657 const int16 *prev_state_data_int16,
const RuntimeShape &unextended_output_state_shape,
658 int16 *output_state_data_int16,
const RuntimeShape &unextended_output_activ_shape,
659 uint8 *output_activ_data_uint8,
const RuntimeShape &unextended_concat_temp_shape,
660 uint8 *concat_temp_data_uint8,
const RuntimeShape &unextended_activ_temp_shape,
661 int16 *activ_temp_data_int16,
void *gemmlowp_context)
663 (void)gemmlowp_context;
664 int32 weights_zero_point = params.weights_zero_point;
665 int32 accum_multiplier = params.accum_multiplier;
666 int accum_shift = params.accum_shift;
667 TFLITE_DCHECK_LE(unextended_input_shape.DimensionsCount(), 4);
668 TFLITE_DCHECK_LE(unextended_prev_activ_shape.DimensionsCount(), 4);
669 TFLITE_DCHECK_LE(unextended_bias_shape.DimensionsCount(), 4);
670 TFLITE_DCHECK_LE(unextended_prev_state_shape.DimensionsCount(), 4);
671 TFLITE_DCHECK_LE(unextended_output_state_shape.DimensionsCount(), 4);
672 TFLITE_DCHECK_LE(unextended_output_activ_shape.DimensionsCount(), 4);
673 TFLITE_DCHECK_LE(unextended_concat_temp_shape.DimensionsCount(), 4);
674 TFLITE_DCHECK_LE(unextended_activ_temp_shape.DimensionsCount(), 4);
675 const RuntimeShape input_shape = RuntimeShape::ExtendedShape(4, unextended_input_shape);
676 const RuntimeShape prev_activ_shape = RuntimeShape::ExtendedShape(4, unextended_prev_activ_shape);
677 const RuntimeShape bias_shape = RuntimeShape::ExtendedShape(4, unextended_bias_shape);
678 const RuntimeShape prev_state_shape = RuntimeShape::ExtendedShape(4, unextended_prev_state_shape);
679 const RuntimeShape output_state_shape =
680 RuntimeShape::ExtendedShape(4, unextended_output_state_shape);
681 const RuntimeShape output_activ_shape =
682 RuntimeShape::ExtendedShape(4, unextended_output_activ_shape);
683 const RuntimeShape concat_temp_shape =
684 RuntimeShape::ExtendedShape(4, unextended_concat_temp_shape);
685 const RuntimeShape activ_temp_shape = RuntimeShape::ExtendedShape(4, unextended_activ_temp_shape);
686 TFLITE_DCHECK_GE(weights_shape.DimensionsCount(), 2);
689 const int weights_dim_count = weights_shape.DimensionsCount();
691 output_state_shape, output_activ_shape);
692 const int input_depth = input_shape.Dims(3);
693 const int prev_activ_depth = prev_activ_shape.Dims(3);
694 const int total_input_depth = prev_activ_depth + input_depth;
695 TFLITE_DCHECK_EQ(weights_shape.Dims(weights_dim_count - 1), total_input_depth);
696 const int intern_activ_depth =
MatchingDim(weights_shape, weights_dim_count - 2, bias_shape, 3);
697 TFLITE_DCHECK_EQ(weights_shape.FlatSize(), intern_activ_depth * total_input_depth);
699 TFLITE_DCHECK_EQ(intern_activ_depth % 4, 0);
700 const int output_depth =
MatchingDim(prev_state_shape, 3, prev_activ_shape, 3, output_state_shape,
701 3, output_activ_shape, 3);
702 TFLITE_DCHECK_EQ(output_depth, intern_activ_depth / 4);
704 const int fc_output_depth =
705 MatchingDim(weights_shape, weights_dim_count - 2, activ_temp_shape, 3);
706 const int fc_accum_depth = total_input_depth;
707 TFLITE_DCHECK_EQ(fc_output_depth, 4 * output_depth);
710 uint8 const *concat_input_arrays_data[2] = {input_data_uint8, prev_activ_data_uint8};
711 const RuntimeShape *concat_input_arrays_shapes[2] = {&input_shape, &prev_activ_shape};
712 tflite::ConcatenationParams concat_params;
713 concat_params.axis = 3;
714 concat_params.inputs_count = 2;
715 Concatenation(concat_params, concat_input_arrays_shapes, concat_input_arrays_data,
716 concat_temp_shape, concat_temp_data_uint8);
723 for (
int b = 0;
b < fc_batches; ++
b)
725 for (
int out_c = 0; out_c < fc_output_depth; ++out_c)
729 int32 accum = bias_data_int32[out_c];
731 for (
int d = 0; d < fc_accum_depth; ++d)
733 int16 input_val = concat_temp_data_uint8[
b * fc_accum_depth + d] - 128;
734 int16 weights_val = weights_data_uint8[out_c * fc_accum_depth + d] - weights_zero_point;
735 accum += input_val * weights_val;
743 accum = std::max(-32768, std::min(32767,
static_cast<int>(accum)));
744 activ_temp_data_int16[out_c + fc_output_depth *
b] = accum;
750 for (
int b = 0;
b < outer_size; ++
b)
752 for (
int c = 0; c < output_depth; ++c)
762 using F0 = gemmlowp::FixedPoint<std::int16_t, 0>;
766 using F3 = gemmlowp::FixedPoint<std::int16_t, 3>;
771 using FS = gemmlowp::FixedPoint<std::int16_t, StateIntegerBits>;
773 F3 input_gate_input =
774 F3::FromRaw(activ_temp_data_int16[b * fc_output_depth + 0 * output_depth + c]);
775 F0 input_gate_output = gemmlowp::logistic(input_gate_input);
778 F3 input_modulation_gate_input =
779 F3::FromRaw(activ_temp_data_int16[b * fc_output_depth + 1 * output_depth + c]);
780 F0 input_modulation_gate_output = gemmlowp::tanh(input_modulation_gate_input);
782 F3 forget_gate_input =
783 F3::FromRaw(activ_temp_data_int16[b * fc_output_depth + 2 * output_depth + c]);
784 F0 forget_gate_output = gemmlowp::logistic(forget_gate_input);
786 F3 output_gate_input =
787 F3::FromRaw(activ_temp_data_int16[b * fc_output_depth + 3 * output_depth + c]);
788 F0 output_gate_output = gemmlowp::logistic(output_gate_input);
790 F0 input_times_input_modulation = input_gate_output * input_modulation_gate_output;
791 FS prev_state = FS::FromRaw(prev_state_data_int16[b * output_depth + c]);
792 FS prev_state_times_forget_state = forget_gate_output * prev_state;
795 gemmlowp::SaturatingAdd(gemmlowp::Rescale<StateIntegerBits>(input_times_input_modulation),
796 prev_state_times_forget_state);
805 F3 new_state_f3 = gemmlowp::Rescale<3>(new_state);
806 F0 output_activ_int16 = output_gate_output * gemmlowp::tanh(new_state_f3);
810 output_state_data_int16[
b * output_depth + c] = new_state.raw();
813 int16 rescaled_output_activ = gemmlowp::RoundingDivideByPOT(output_activ_int16.raw(), 8);
814 int16 clamped_output_activ =
815 std::max<int16>(-128, std::min<int16>(127, rescaled_output_activ));
816 output_activ_data_uint8[
b * output_depth + c] = 128 + clamped_output_activ;
821template <
typename Scalar>
822void Split(
const SplitParams ¶ms,
const RuntimeShape &input_shape,
const Scalar *input_data,
823 const RuntimeShape *
const *output_shapes, Scalar *
const *output_data)
825 ruy::profiler::ScopeLabel label(
"Split");
826 const int split_dimensions = input_shape.DimensionsCount();
827 int axis = params.axis < 0 ? params.axis + split_dimensions : params.axis;
828 int outputs_count = params.num_split;
829 TFLITE_DCHECK_LT(axis, split_dimensions);
831 int64_t split_size = 0;
832 for (
int i = 0; i < outputs_count; i++)
834 TFLITE_DCHECK_EQ(output_shapes[i]->DimensionsCount(), split_dimensions);
835 for (
int j = 0; j < split_dimensions; j++)
842 split_size += output_shapes[i]->Dims(axis);
844 TFLITE_DCHECK_EQ(split_size, input_shape.Dims(axis));
845 int64_t outer_size = 1;
846 for (
int i = 0; i < axis; ++i)
848 outer_size *= input_shape.Dims(i);
852 int64_t base_inner_size = 1;
853 for (
int i = axis + 1; i < split_dimensions; ++i)
855 base_inner_size *= input_shape.Dims(i);
859 for (
int k = 0; k < outer_size; k++)
861 for (
int i = 0; i < outputs_count; ++i)
863 const int copy_size = output_shapes[i]->Dims(axis) * base_inner_size;
864 memcpy(output_data[i] + k * copy_size, input_ptr, copy_size *
sizeof(Scalar));
865 input_ptr += copy_size;
870inline int NodeOffset(
int b,
int h,
int w,
int height,
int width)
872 return (b * height + h) * width +
w;
876 const RuntimeShape &input_shape,
const float *input_data,
879 const int trailing_dim = input_shape.DimensionsCount() - 1;
883 for (
int i = 0; i < outer_size; ++i)
885 for (
int c = 0; c < depth; ++c)
887 const int begin_input_c = std::max(0,
static_cast<int>(c - op_params.range));
888 const int end_input_c = std::min(depth,
static_cast<int>(c + op_params.range));
890 for (
int input_c = begin_input_c; input_c < end_input_c; ++input_c)
892 const float input_val =
input_data[i * depth + input_c];
893 accum += input_val * input_val;
895 const float multiplier = std::pow(op_params.bias + op_params.alpha * accum, -op_params.beta);
901inline void Dequantize(
const RuntimeShape &input_shape,
const Eigen::half *input_data,
905 for (
int i = 0; i < flat_size; i++)
911inline void FakeQuant(
const tflite::FakeQuantParams &op_params,
const RuntimeShape &input_shape,
912 const float *input_data,
const RuntimeShape &
output_shape,
float *output_data)
914 ruy::profiler::ScopeLabel label(
"FakeQuant");
915 float rmin = op_params.minmax.min;
916 float rmax = op_params.minmax.max;
917 int num_bits = op_params.num_bits;
920 TFLITE_DCHECK_LE(rmin, 0.0f);
921 TFLITE_DCHECK_GE(rmax, 0.0f);
922 TFLITE_DCHECK_LT(rmin, rmax);
926 int quant_max = (1 << num_bits) - 1;
927 float nudged_min, nudged_max, nudged_scale;
928 NudgeQuantizationRange(rmin, rmax, quant_min, quant_max, &nudged_min, &nudged_max, &nudged_scale);
930 FakeQuantizeArray(nudged_scale, nudged_min, nudged_max, input_data, output_data, flat_size);
934struct GatherNdHelperResult
943inline GatherNdHelperResult
GatherNdHelper(
const RuntimeShape ¶ms_shape,
944 const RuntimeShape &indices_shape)
946 GatherNdHelperResult ret;
949 const int indices_dims = indices_shape.DimensionsCount();
950 ret.indices_nd = indices_shape.Dims(indices_dims - 1);
951 const int params_dims = params_shape.DimensionsCount();
952 for (
int i = 0; i < indices_dims - 1; ++i)
954 ret.n_slices *= indices_shape.Dims(i);
956 for (
int i = ret.indices_nd; i < params_dims; ++i)
958 ret.slice_size *= params_shape.Dims(i);
961 int remain_flat_size = params_shape.FlatSize();
962 ret.dims_to_count = std::vector<int>(ret.indices_nd, 0);
963 for (
int i = 0; i < ret.indices_nd; ++i)
965 ret.dims_to_count[i] = remain_flat_size / params_shape.Dims(i);
966 remain_flat_size = ret.dims_to_count[i];
972template <
typename ParamsT,
typename IndicesT =
int32>
973inline void GatherNd(
const RuntimeShape ¶ms_shape,
const ParamsT *params_data,
974 const RuntimeShape &indices_shape,
const IndicesT *indices_data,
977 ruy::profiler::ScopeLabel label(
"GatherNd");
979 const GatherNdHelperResult res =
GatherNdHelper(params_shape, indices_shape);
980 for (
int i = 0; i < res.n_slices; ++i)
983 for (
int j = 0; j < res.indices_nd; ++j)
985 from_pos += indices_data[i * res.indices_nd + j] * res.dims_to_count[j];
987 std::memcpy(output_data + i * res.slice_size, params_data + from_pos,
988 sizeof(ParamsT) * res.slice_size);
992#ifndef TF_LITE_STATIC_MEMORY
993template <
typename IndicesT =
int32>
994inline void GatherNdString(
const RuntimeShape ¶ms_shape,
const TfLiteTensor *params_data,
995 const RuntimeShape &indices_shape,
const IndicesT *indices_data,
996 const RuntimeShape &
output_shape, TfLiteTensor *output_data)
998 ruy::profiler::ScopeLabel label(
"GatherNdString");
1000 const GatherNdHelperResult res =
GatherNdHelper(params_shape, indices_shape);
1001 DynamicBuffer buffer;
1002 for (
int i = 0; i < res.n_slices; ++i)
1005 for (
int j = 0; j < res.indices_nd; ++j)
1007 from_pos += indices_data[i * res.indices_nd + j] * res.dims_to_count[j];
1009 for (
int j = 0; j < res.slice_size; ++j)
1011 buffer.AddString(GetString(params_data, from_pos + j));
1014 buffer.WriteToTensor(output_data,
nullptr);
1018template <
typename IndicesT,
typename UpdatesT>
1019inline void ScatterNd(
const RuntimeShape &indices_shape,
const IndicesT *indices_data,
1020 const RuntimeShape &updates_shape,
const UpdatesT *updates_data,
1021 const RuntimeShape &
output_shape, UpdatesT *output_data)
1023 ruy::profiler::ScopeLabel label(
"ScatterNd");
1027 const int outer_dims = indices_shape.DimensionsCount() - 1;
1028 const int indices_nd = indices_shape.Dims(outer_dims);
1029 const int updates_dims = updates_shape.DimensionsCount();
1030 for (
int i = 0; i < outer_dims; ++i)
1032 n_slices *= indices_shape.Dims(i);
1034 for (
int i = outer_dims; i < updates_dims; ++i)
1036 slice_size *= updates_shape.Dims(i);
1040 int remain_flat_size = output_flat_size;
1041 std::vector<int> dims_to_count(indices_nd, 0);
1042 for (
int i = 0; i < indices_nd; ++i)
1044 dims_to_count[i] = remain_flat_size /
output_shape.Dims(i);
1045 remain_flat_size = dims_to_count[i];
1048 memset(output_data, 0,
sizeof(UpdatesT) * output_flat_size);
1049 for (
int i = 0; i < n_slices; ++i)
1052 for (
int j = 0; j < indices_nd; ++j)
1054 IndicesT idx = indices_data[i * indices_nd + j];
1056 to_pos += idx * dims_to_count[j];
1058 for (
int j = 0; j < slice_size; j++)
1060 output_data[to_pos + j] += updates_data[i * slice_size + j];
1065template <
typename T>
1066inline void Slice(
const tflite::SliceParams &op_params,
const RuntimeShape &input_shape,
1067 const RuntimeShape &
output_shape, SequentialTensorWriter<T> *writer)
1069 const RuntimeShape ext_shape = RuntimeShape::ExtendedShape(5, input_shape);
1070 TFLITE_DCHECK_LE(op_params.begin_count, 5);
1071 TFLITE_DCHECK_LE(op_params.size_count, 5);
1075 std::array<int, 5> start;
1076 std::array<int, 5> stop;
1077 for (
int i = 0; i < 5; ++i)
1079 int padded_i = 5 - i;
1083 : start[i] + op_params.size[
size_count - padded_i];
1086 for (
int i0 = start[0]; i0 < stop[0]; ++i0)
1088 for (
int i1 = start[1]; i1 < stop[1]; ++i1)
1090 for (
int i2 = start[2]; i2 < stop[2]; ++i2)
1092 for (
int i3 = start[3]; i3 < stop[3]; ++i3)
1094 for (
int i4 = start[4]; i4 < stop[4]; ++i4)
1096 writer->Write(
Offset(ext_shape, i0, i1, i2, i3, i4));
1104template <
typename T>
1105inline void Slice(
const tflite::SliceParams &op_params,
const RuntimeShape &input_shape,
1106 const T *input_data,
const RuntimeShape &
output_shape, T *output_data)
1108 SequentialTensorWriter<T> writer(input_data, output_data);
1112template <
typename T>
1113inline void Slice(
const tflite::SliceParams &op_params,
const RuntimeShape &input_shape,
1114 const TfLiteTensor *input,
const RuntimeShape &
output_shape, TfLiteTensor *output)
1116 SequentialTensorWriter<T> writer(input, output);
1120template <
typename T>
1121void Minimum(
const RuntimeShape &input1_shape,
const T *input1_data,
const T *input2_data,
1127 for (
int i = 0; i < flat_size; i++)
1135template <
typename T>
1136inline void Minimum(
const RuntimeShape &input1_shape,
const T *input1_data,
const RuntimeShape &,
1137 const T *input2_data,
const RuntimeShape &
output_shape, T *output_data)
1143template <
typename T>
1144void Maximum(
const RuntimeShape &input1_shape,
const T *input1_data,
const T *input2_data,
1150 for (
int i = 0; i < flat_size; i++)
1158template <
typename T>
1159inline void Maximum(
const RuntimeShape &input1_shape,
const T *input1_data,
const RuntimeShape &,
1160 const T *input2_data,
const RuntimeShape &
output_shape, T *output_data)
1166template <
typename T1,
typename T2,
typename T3>
1167void ArgMax(
const RuntimeShape &input1_shape,
const T1 *input1_data,
const T3 *input2_data,
1175template <
typename T1,
typename T2,
typename T3>
1176inline void ArgMax(
const RuntimeShape &input1_shape,
const T1 *input1_data,
1177 const RuntimeShape &input2_shape,
const T3 *input2_data,
1184template <
typename D,
typename T>
1185void Select(
const RuntimeShape &input_condition_shape,
const D *input_condition_data,
1186 const RuntimeShape &input_x_shape,
const T *input_x_data,
1187 const RuntimeShape &input_y_shape,
const T *input_y_data,
1193 if (input_condition_shape.FlatSize() == 1 && input_x_shape.FlatSize() == 1 &&
1194 input_y_shape.FlatSize() == 1 &&
output_shape.FlatSize() == 1)
1202 for (int64_t i = 0; i < flatsize; ++i)
1204 output_data[i] = input_condition_data[i] ? input_x_data[i] : input_y_data[i];
1208template <
typename D,
typename T>
1209void RankOneSelect(
const RuntimeShape &input_condition_shape,
const D *input_condition_data,
1210 const RuntimeShape &input_x_shape,
const T *input_x_data,
1211 const RuntimeShape &input_y_shape,
const T *input_y_data,
1214 const int64_t outer_size = input_condition_shape.FlatSize();
1216 if (input_condition_shape.DimensionsCount() == 0)
1227 for (int64_t i = 0; i < outer_size; i++)
1229 const T *
input_data = input_condition_data[i] ? input_x_data : input_y_data;
1230 memcpy(output_data +
offset, input_data +
offset, inner_size *
sizeof(T));
1235template <
typename D,
typename T>
1237 const RuntimeShape &input_x_shape,
const T *input_x_data,
1238 const RuntimeShape &input_y_shape,
const T *input_y_data,
1241 TFLITE_DCHECK_LE(input_condition_shape.DimensionsCount(), 4);
1242 TFLITE_DCHECK_LE(input_x_shape.DimensionsCount(), 4);
1243 TFLITE_DCHECK_LE(input_y_shape.DimensionsCount(), 4);
1246 const RuntimeShape extended_output_shape = RuntimeShape::ExtendedShape(4,
output_shape);
1252 &desc_condition, &desc_x, &desc_y);
1265 for (
int b = 0;
b < extended_output_shape.Dims(0); ++
b)
1267 for (
int y = 0; y < extended_output_shape.Dims(1); ++y)
1269 for (
int x = 0; x < extended_output_shape.Dims(2); ++x)
1271 for (
int c = 0; c < extended_output_shape.Dims(3); ++c)
1277 input_condition_data[condition_index] ? input_x_data[x_index] : input_y_data[y_index];
1284template <
typename D,
typename T>
1285void SelectTrueCoords(
const RuntimeShape &input_condition_shape,
const D *input_condition_data,
1288 const size_t size = input_condition_shape.FlatSize();
1294 const size_t cond_rank = input_condition_shape.DimensionsCount();
1296 std::vector<int> dims_to_count(cond_rank, 0);
1297 int cur_flat_size =
size;
1298 for (
int i = 0; i < cond_rank; ++i)
1300 dims_to_count[i] = cur_flat_size / input_condition_shape.Dims(i);
1301 cur_flat_size = dims_to_count[i];
1304 int output_index = 0;
1305 for (
int i = 0; i <
size; ++i)
1307 if (input_condition_data[i])
1311 for (
int j = 0; j < cond_rank; ++j)
1313 int coord_j = flat_index / dims_to_count[j];
1314 output_data[output_index * cond_rank + j] = coord_j;
1315 flat_index %= dims_to_count[j];
1323template <
typename T,
typename TI>
1324inline void SparseToDense(
const std::vector<std::vector<TI>> &indices,
const T *values,
1325 T default_value,
bool value_is_scalar,
1326 const RuntimeShape &unextended_output_shape, T *output_data)
1328 TFLITE_DCHECK_LE(unextended_output_shape.DimensionsCount(), 4);
1329 const RuntimeShape
output_shape = RuntimeShape::ExtendedShape(4, unextended_output_shape);
1330 const int value_count = indices.size();
1341 if (value_is_scalar)
1343 for (
int i = 0; i < value_count; ++i)
1345 const std::vector<TI> &
index = indices[i];
1346 TFLITE_DCHECK_EQ(
index.size(), 4);
1347 const T value = *values;
1354 for (
int i = 0; i < value_count; ++i)
1356 const std::vector<TI> &
index = indices[i];
1357 TFLITE_DCHECK_EQ(
index.size(), 4);
1358 const T value = values[i];
1363template <
typename T>
1364inline void Pow(
const RuntimeShape &input1_shape,
const T *input1_data,
1365 const RuntimeShape &input2_shape,
const T *input2_data,
1369 for (
int i = 0; i < flat_size; ++i)
1371 output_data[i] = std::pow(input1_data[i], input2_data[i]);
1375template <
typename T>
1376inline void BroadcastPow4DSlow(
const RuntimeShape &unextended_input1_shape,
const T *input1_data,
1377 const RuntimeShape &unextended_input2_shape,
const T *input2_data,
1378 const RuntimeShape &unextended_output_shape, T *output_data)
1380 TFLITE_DCHECK_LE(unextended_input1_shape.DimensionsCount(), 4);
1381 TFLITE_DCHECK_LE(unextended_input2_shape.DimensionsCount(), 4);
1382 TFLITE_DCHECK_LE(unextended_output_shape.DimensionsCount(), 4);
1383 const RuntimeShape
output_shape = RuntimeShape::ExtendedShape(4, unextended_output_shape);
1403 output_data[out_idx] = std::pow(in1_val, in2_val);
1410template <
typename Scalar>
1411void Reverse(
int axis,
const RuntimeShape &input_shape,
const Scalar *input_data,
1414 ruy::profiler::ScopeLabel label(
"Reverse");
1417 for (
int i = 0; i < axis; ++i)
1419 outer_size *= input_shape.Dims(i);
1423 for (
int i = axis + 1; i < input_shape.DimensionsCount(); ++i)
1425 copy_size *= input_shape.Dims(i);
1428 const int dims_at_axis = input_shape.Dims(axis);
1429 for (
int i = 0; i < outer_size; ++i)
1431 for (
int j = 0; j < dims_at_axis; ++j)
1433 const int start_pos = (i * dims_at_axis + j) * copy_size;
1435 int loc = (i * dims_at_axis + dims_at_axis - j - 1) * copy_size;
1436 memcpy(output_ptr, input_data + loc, copy_size *
sizeof(Scalar));
1441template <
typename Scalar,
typename TS>
1442void ReverseSequence(
const TS *seq_lengths,
const int seq_dim,
const int batch_dim,
1443 const RuntimeShape &input_shape,
const Scalar *input_data,
1446 ruy::profiler::ScopeLabel label(
"ReverseSequence");
1449 int outer_dim = std::min(batch_dim, seq_dim);
1450 int medium_dim = std::max(batch_dim, seq_dim);
1451 for (
int i = 0; i < outer_dim; ++i)
1453 outer_size *= input_shape.Dims(i);
1456 int medium_size = 1;
1457 for (
int i = outer_dim + 1; i < medium_dim; ++i)
1459 medium_size *= input_shape.Dims(i);
1463 for (
int i = medium_dim + 1; i < input_shape.DimensionsCount(); ++i)
1465 copy_size *= input_shape.Dims(i);
1468 const int dims_at_outer_dim = input_shape.Dims(outer_dim);
1469 const int dims_at_medium_dim = input_shape.Dims(medium_dim);
1472 if (batch_dim > seq_dim)
1474 for (
int i = 0; i < outer_size; ++i)
1476 for (
int j = 0; j < dims_at_outer_dim; ++j)
1478 const int in_pos_base = (i * dims_at_outer_dim + j) * medium_size;
1479 for (
int p = 0; p < medium_size; ++p)
1481 for (
int q = 0; q < dims_at_medium_dim; ++q)
1483 const int in_pos = ((in_pos_base + p) * dims_at_medium_dim + q) * copy_size;
1485 int sl = seq_lengths[q] - 1;
1492 const int out_pos_base = (i * dims_at_outer_dim + sl - j) * medium_size;
1493 const int out_pos = ((out_pos_base + p) * dims_at_medium_dim + q) * copy_size;
1496 memcpy(output_ptr, in_ptr, copy_size *
sizeof(Scalar));
1502 else if (batch_dim < seq_dim)
1504 for (
int i = 0; i < outer_size; ++i)
1506 for (
int j = 0; j < dims_at_outer_dim; ++j)
1508 const int in_pos_base = (i * dims_at_outer_dim + j) * medium_size;
1509 int sl = seq_lengths[j] - 1;
1510 const int out_pos_base = (i * dims_at_outer_dim + j) * medium_size;
1511 for (
int p = 0; p < medium_size; ++p)
1513 for (
int q = 0; q < dims_at_medium_dim; ++q)
1515 const int in_pos = ((in_pos_base + p) * dims_at_medium_dim + q) * copy_size;
1523 const int out_pos = ((out_pos_base + p) * dims_at_medium_dim + sl - q) * copy_size;
1526 memcpy(output_ptr, in_ptr, copy_size *
sizeof(Scalar));
1534template <
typename T>
1535inline void SegmentSum(
const RuntimeShape &input_shape,
const T *input_data,
1536 const RuntimeShape &segment_ids_shape,
const int32_t *segment_ids_data,
1541 memset(output_data, 0,
sizeof(T) *
output_shape.FlatSize());
1543 for (
int i = 0; i < input_shape.Dims(0); i++)
1545 int output_index = segment_ids_data[i];
1546 for (
int j = 0; j < segment_flat_size; ++j)
void Concatenation(int concat_dim, const Scalar *const *input_data, const Dims< 4 > *const *input_dims, int inputs_count, Scalar *output_data, const Dims< 4 > &output_dims)
void FullyConnected(const float *input_data, const Dims< 4 > &input_dims, const float *weights_data, const Dims< 4 > &weights_dims, const float *bias_data, const Dims< 4 > &bias_dims, float *output_data, const Dims< 4 > &output_dims)
void NdArrayDescsForElementwiseBroadcast(const Dims< N > &input0_dims, const Dims< N > &input1_dims, NdArrayDesc< N > *desc0_out, NdArrayDesc< N > *desc1_out)
int SubscriptToIndex(const NdArrayDesc< 4 > &desc, int i0, int i1, int i2, int i3)
int Offset(const Dims< 4 > &dims, int i0, int i1, int i2, int i3)
int MatchingFlatSize(const Dims< N > &dims, const Dims< N > &check_dims_0)
__global uchar * offset(const Image *img, int x, int y)
const luci_interpreter::RuntimeShape output_shape
const std::vector< float > input1_data
const std::vector< float > input2_data
loco::GraphInputIndex index(const TFPlaceholder *node)
uint32_t num_elements(const Shape &shape)
The number of elements of a feature map of a given shape.
void MulElementwise(int size, const BinaryArithmeticOpParam ¶ms, const uint8_t *input1_data, const uint8_t *input2_data, uint8_t *output_data)
int MatchingDim(const Shape &shape1, int index1, const Shape &shape2, int index2)
int FlatSizeSkipDim(const Shape &shape, int skip_dim)
void ArgMinMax(const Shape &input1_shape, const T1 *input1_data, const Shape &output_shape, T2 *output_data, int32_t axis, const Cmp &cmp)
int MatchingFlatSizeSkipDim(const Shape &shape, int skip_dim, const Shape &check_shape_0)
int MatchingElementsSize(const Shape &shape, const Shape &check_shape_0, const Shape &check_shape_1)
int32_t MultiplyByQuantizedMultiplier(int32_t x, int32_t quantized_multiplier, int shift)
void GatherNd(const RuntimeShape ¶ms_shape, const ParamsT *params_data, const RuntimeShape &indices_shape, const IndicesT *indices_data, const RuntimeShape &output_shape, ParamsT *output_data)
void LocalResponseNormalization(const tflite::LocalResponseNormalizationParams &op_params, const RuntimeShape &input_shape, const float *input_data, const RuntimeShape &output_shape, float *output_data)
void FakeQuant(const tflite::FakeQuantParams &op_params, const RuntimeShape &input_shape, const float *input_data, const RuntimeShape &output_shape, float *output_data)
void Sub16(const ArithmeticParams ¶ms, const RuntimeShape &input1_shape, const int16_t *input1_data, const RuntimeShape &input2_shape, const int16_t *input2_data, const RuntimeShape &output_shape, int16_t *output_data)
void LstmCell(const LstmCellParams ¶ms, const RuntimeShape &unextended_input_shape, const float *input_data, const RuntimeShape &unextended_prev_activ_shape, const float *prev_activ_data, const RuntimeShape &weights_shape, const float *weights_data, const RuntimeShape &unextended_bias_shape, const float *bias_data, const RuntimeShape &unextended_prev_state_shape, const float *prev_state_data, const RuntimeShape &unextended_output_state_shape, float *output_state_data, const RuntimeShape &unextended_output_activ_shape, float *output_activ_data, const RuntimeShape &unextended_concat_temp_shape, float *concat_temp_data, const RuntimeShape &unextended_activ_temp_shape, float *activ_temp_data)
void Relu1(const RuntimeShape &input_shape, const T *input_data, const RuntimeShape &output_shape, T *output_data)
void Dequantize(const RuntimeShape &input_shape, const Eigen::half *input_data, const RuntimeShape &output_shape, float *output_data)
GatherNdHelperResult GatherNdHelper(const RuntimeShape ¶ms_shape, const RuntimeShape &indices_shape)
void GatherNdString(const RuntimeShape ¶ms_shape, const TfLiteTensor *params_data, const RuntimeShape &indices_shape, const IndicesT *indices_data, const RuntimeShape &output_shape, TfLiteTensor *output_data)
void SparseToDense(const std::vector< std::vector< TI > > &indices, const T *values, T default_value, bool value_is_scalar, const RuntimeShape &unextended_output_shape, T *output_data)
void ArgMax(const RuntimeShape &input1_shape, const T1 *input1_data, const T3 *input2_data, const RuntimeShape &output_shape, T2 *output_data)
void ReluX(const tflite::ReluParams ¶ms, const RuntimeShape &input_shape, const T *input_data, const RuntimeShape &output_shape, T *output_data)
void Select(const RuntimeShape &input_condition_shape, const D *input_condition_data, const RuntimeShape &input_x_shape, const T *input_x_data, const RuntimeShape &input_y_shape, const T *input_y_data, const RuntimeShape &output_shape, T *output_data)
void BroadcastPow4DSlow(const RuntimeShape &unextended_input1_shape, const T *input1_data, const RuntimeShape &unextended_input2_shape, const T *input2_data, const RuntimeShape &unextended_output_shape, T *output_data)
void ReverseSequence(const TS *seq_lengths, const int seq_dim, const int batch_dim, const RuntimeShape &input_shape, const Scalar *input_data, const RuntimeShape &output_shape, Scalar *output_data)
void BroadcastSelect4DSlow(const RuntimeShape &input_condition_shape, const D *input_condition_data, const RuntimeShape &input_x_shape, const T *input_x_data, const RuntimeShape &input_y_shape, const T *input_y_data, const RuntimeShape &output_shape, T *output_data)
void Minimum(const RuntimeShape &input1_shape, const T *input1_data, const T *input2_data, const RuntimeShape &output_shape, T *output_data)
void RankOneSelect(const RuntimeShape &input_condition_shape, const D *input_condition_data, const RuntimeShape &input_x_shape, const T *input_x_data, const RuntimeShape &input_y_shape, const T *input_y_data, const RuntimeShape &output_shape, T *output_data)
void Pow(const RuntimeShape &input1_shape, const T *input1_data, const RuntimeShape &input2_shape, const T *input2_data, const RuntimeShape &output_shape, T *output_data)
void Mul(const ArithmeticParams ¶ms, const RuntimeShape &input1_shape, const int16 *input1_data, const RuntimeShape &input2_shape, const int16 *input2_data, const RuntimeShape &output_shape, int16 *output_data)
void SelectTrueCoords(const RuntimeShape &input_condition_shape, const D *input_condition_data, T *output_data)
void Slice(const tflite::SliceParams &op_params, const RuntimeShape &input_shape, const RuntimeShape &output_shape, SequentialTensorWriter< T > *writer)
void SegmentSum(const RuntimeShape &input_shape, const T *input_data, const RuntimeShape &segment_ids_shape, const int32_t *segment_ids_data, const RuntimeShape &output_shape, T *output_data)
void DepthConcatenation(const ConcatenationParams ¶ms, const RuntimeShape *const *input_shapes, const Scalar *const *input_data, const RuntimeShape &output_shape, Scalar *output_data)
void PackWithScaling(const PackParams ¶ms, const RuntimeShape *const *input_shapes, const uint8 *const *input_data, const RuntimeShape &output_shape, uint8 *output_data)
void Pack(const PackParams ¶ms, const RuntimeShape *const *input_shapes, const Scalar *const *input_data, const RuntimeShape &output_shape, Scalar *output_data)
void BroadcastMulFivefold(const ArithmeticParams &unswitched_params, const RuntimeShape &unswitched_input1_shape, const uint8 *unswitched_input1_data, const RuntimeShape &unswitched_input2_shape, const uint8 *unswitched_input2_data, const RuntimeShape &output_shape, uint8 *output_data)
int NodeOffset(int b, int h, int w, int height, int width)
void Reverse(int axis, const RuntimeShape &input_shape, const Scalar *input_data, const RuntimeShape &output_shape, Scalar *output_data)
void Relu6(const RuntimeShape &input_shape, const float *input_data, const RuntimeShape &output_shape, float *output_data)
void Unpack(const UnpackParams ¶ms, const RuntimeShape &input_shape, const Scalar *input_data, const RuntimeShape &output_shape, Scalar *const *output_datas)
void Split(const SplitParams ¶ms, const RuntimeShape &input_shape, const Scalar *input_data, const RuntimeShape *const *output_shapes, Scalar *const *output_data)
void Maximum(const RuntimeShape &input1_shape, const T *input1_data, const T *input2_data, const RuntimeShape &output_shape, T *output_data)
void ScatterNd(const RuntimeShape &indices_shape, const IndicesT *indices_data, const RuntimeShape &updates_shape, const UpdatesT *updates_data, const RuntimeShape &output_shape, UpdatesT *output_data)
std::vector< int > dims_to_count