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_TRANSPOSE_H_ 18 #define NNACL_KERNEL_TRANSPOSE_H_ 19 20 #include "nnacl/op_base.h" 21 #include "nnacl/kernel.h" 22 #include "nnacl/transpose_parameter.h" 23 24 typedef struct TransposeStruct { 25 KernelBase base_; 26 bool is_valid_; 27 int num_axes_; 28 int data_num_; 29 int perm_[MAX_TRANSPOSE_DIM_SIZE]; 30 int perm_size_; 31 int in_shape_[MAX_TRANSPOSE_DIM_SIZE]; /* after shape optimize */ 32 int in_shape_size_; 33 int out_shape_[MAX_TRANSPOSE_DIM_SIZE]; 34 int strides_[MAX_TRANSPOSE_DIM_SIZE]; 35 int out_strides_[MAX_TRANSPOSE_DIM_SIZE]; 36 37 int opt_perm_[PERM_NUM_THREE]; // only valid when opt_run_ is true 38 bool opt_run_; // only true when perm is [1, 0] or [0, 2, 1] 39 40 int (*compute_)(const void *src, void *dst, const int *out_shape, int *perm, int *strides, int *out_strides, 41 int data_size, int num_axes); 42 void (*nhwc2nchw_)(const void *src, void *dst, int b, int hw, int c, int task_id, int thread); 43 void (*optimize_)(const void *src, void *dst, const int *out_shape, int *perm, int *strides, int *out_strides, 44 int num_axes, int task_id, int thread); 45 } TransposeStruct; 46 47 KernelBase *CreateTranspose(OpParameter *param, int data_type); 48 49 #endif // NNACL_KERNEL_TRANSPOSE_H_ 50