#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_OPTIMIZED_REDUCE_H_
#define TENSORFLOW_LITE_KERNELS_INTERNAL_OPTIMIZED_REDUCE_H_
#include <stdint.h>
#include <algorithm>
#include <limits>
#include <vector>
#include "ruy/profiler/instrumentation.h"
#include "tensorflow/lite/kernels/cpu_backend_threadpool.h"
#include "tensorflow/lite/kernels/internal/optimized/optimized_ops_utils.h"
#include "tensorflow/lite/kernels/internal/optimized/reduce_utils.h"
#include "tensorflow/lite/kernels/internal/reduce_common.h"
#include "tensorflow/lite/kernels/internal/reference/reduce.h"
#include "tensorflow/lite/kernels/internal/runtime_shape.h"
#include "tensorflow/lite/kernels/internal/types.h"
#include "tensorflow/lite/kernels/kernel_util.h"
namespace tflite {
namespace optimized_ops {
inline void MeanImpl(const tflite::MeanParams& op_params,
const RuntimeShape& input_shape, const uint8_t* input_data,
int32 multiplier, int32 shift, int32 bias,
const RuntimeShape& output_shape, uint8_t* output_data,
int start_depth, int end_depth) { … }
struct MeanWorkerTask : cpu_backend_threadpool::Task { … };
inline void Mean(const tflite::MeanParams& op_params,
const RuntimeShape& unextended_input_shape,
const uint8_t* input_data, int32 input_zero_point,
float input_scale, const RuntimeShape& unextended_output_shape,
uint8_t* output_data, int32 output_zero_point,
float output_scale, CpuBackendContext* cpu_backend_context) { … }
template <typename T>
struct SumOp { … };
template <typename T, typename U>
struct CastSumOp { … };
template <typename T>
struct ProdOp { … };
template <typename T>
struct MaxOp { … };
template <typename T>
struct MinOp { … };
struct AndOp { … };
struct OrOp { … };
template <typename T>
void ReduceIsCopy(const T* input_data, const int* input_dims,
const int input_num_dims, T* output_data) { … }
template <typename T, typename U, typename ReducerFirst, typename ReducerNext>
inline std::pair<const T*, U*> ReduceImpl(const T* input_data,
const int* input_dims, U* output_data,
int depth, int parity, bool next,
const ReducerFirst& reducer_first,
const ReducerNext& reducer_next) { … }
template <typename In, typename Out, typename ReducerFirst,
typename ReducerNext>
inline bool Reduce(const In* input_data, const int* input_dims,
const int input_num_dims, const int* axis,
const int num_axis, Out* output_data,
const ReducerFirst& reducer_first,
const ReducerNext& reducer_next) { … }
template <typename T, typename U>
bool QuantizedMeanOrSum(const T* input_data, int32_t input_zero_point,
float input_scale, const int* input_dims,
const int input_num_dims, T* output_data,
int32_t output_zero_point, float output_scale,
const int* output_dims, const int output_num_dims,
const int* axis, const int num_axis_dimensions,
bool keep_dims, int* normalized_dims,
int* resolved_axis, U* temp_sum, bool compute_sum) { … }
ReduceType;
template <typename T>
inline bool ReduceDispatcher(const T* input_data, const int* input_dims,
const int input_num_dims, const int* output_dims,
int output_num_dims, T* output_data,
const int* axis, const int64_t num_axis_dimensions,
ReduceType reduce_type) { … }
template <>
inline bool ReduceDispatcher<bool>(const bool* input_data,
const int* input_dims,
const int input_num_dims,
const int* output_dims, int output_num_dims,
bool* output_data, const int* axis,
const int64_t num_axis_dimensions,
ReduceType reduce_type) { … }
template <typename T>
struct ReducerFirst { … };
template <typename T>
struct ReducerNext { … };
template <typename T>
inline bool QuantizedReduceProd(
const T* input_data, int32_t input_zero_point,
const RuntimeShape& input_shape, T* output_data, int32_t output_zero_point,
const RuntimeShape& output_shape, const int* axis,
const int64_t num_axis_dimensions, int* resolved_axis, int* normalized_dims,
int32_t* temp_prod, int32_t scaling_multiplier, int scaling_shift) { … }
template <typename T>
inline void Mean(const tflite::MeanParams& op_params,
const RuntimeShape& input_shape, const T* input_data,
const RuntimeShape& output_shape, T* output_data) { … }
template <typename T, typename U>
inline bool MeanGeneral(const T* input_data, const int* input_dims,
const int input_num_dims, T* output_data,
const int* output_dims, const int output_num_dims,
const int* axis, const int num_axis_dimensions,
bool keep_dims, int* normalized_dims,
int* resolved_axis, U* temp_sum) { … }
template <typename T, typename U>
inline bool Mean(const T* input_data, const int* input_dims,
const int input_num_dims, T* output_data,
const int* output_dims, const int output_num_dims,
const int* axis, const int num_axis_dimensions, bool keep_dims,
int* normalized_dims, int* resolved_axis, U* temp_sum) { … }
template <>
inline bool Mean<float, float>(const float* input_data, const int* input_dims,
const int input_num_dims, float* output_data,
const int* output_dims,
const int output_num_dims, const int* axis,
const int num_axis_dimensions, bool keep_dims,
int* normalized_dims, int* resolved_axis,
float* temp_sum) { … }
template <typename T>
inline bool ReduceGeneric(const T* input_data, const int* input_dims,
const int input_num_dims, T* output_data,
const int* output_dims, const int output_num_dims,
const int* axis, const int64_t num_axis_dimensions,
int* resolved_axis, int* normalized_dims,
ReduceType reduce_type) { … }
}
}
#endif