1 /** 2 * Copyright 2023 Huawei Technologies Co., Ltd 3 * 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 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 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. 15 */ 16 17 #ifndef NNACL_KERNEL_REDUCE_H_ 18 #define NNACL_KERNEL_REDUCE_H_ 19 20 #include "nnacl/op_base.h" 21 #include "nnacl/tensor_c.h" 22 #include "nnacl/kernel.h" 23 24 typedef struct ReduceKernelList { 25 int type_; 26 int (*float_function_)(const int outer_size, const int inner_size, const int axis_size, const float *src_data, 27 float *dst_data, const int tid, const int thread_num); 28 int (*int_function_)(const int outer_size, const int inner_size, const int axis_size, const int *src_data, 29 int *dst_data, const int tid, const int thread_num); 30 int (*bool_function_)(const int outer_size, const int inner_size, const int axis_size, const bool *src_data, 31 bool *dst_data, const int tid, const int thread_num); 32 int (*float_last_axis_func_)(const int outer_size, const int inner_size, const int axis_size, const float *src_data, 33 float *dst_data, const int tid, const int thread_num); 34 } ReduceKernelList; 35 36 typedef struct ReduceStruct { 37 KernelBase base_; 38 bool only_copy_; 39 int num_axes_; 40 TypeIdC data_type_; 41 int axes_[MAX_SHAPE_SIZE]; 42 43 void *data_buffers_[MAX_SHAPE_SIZE]; 44 size_t data_buffer_sizes_[MAX_SHAPE_SIZE]; 45 int data_buffers_size_; 46 ReduceModeC mode_; 47 48 int outer_sizes_[MAX_SHAPE_SIZE]; 49 int inner_sizes_[MAX_SHAPE_SIZE]; 50 int axis_sizes_[MAX_SHAPE_SIZE]; 51 int offset_size_; 52 53 int outer_size_; 54 int inner_size_; 55 int axis_size_; 56 57 void *src_data_; 58 void *dst_data_; 59 ReduceKernelList compute_; 60 61 void (*handle_sum_square_)(KernelBase *base); 62 void (*init_kernel_list_)(KernelBase *base); 63 int (*calculate_coeff_)(KernelBase *base); 64 int (*call_uint_)(KernelBase *base, int task_id); 65 } ReduceStruct; 66 67 KernelBase *CreateReduce(OpParameter *param, int data_type); 68 int ReducePrepare(KernelBase *self); 69 int ReduceResize(KernelBase *self); 70 int ReduceCompute(KernelBase *self); 71 72 #endif // NNACL_KERNEL_RESHAPE_H_ 73