diff --git a/mindspore/lite/nnacl/arg_min_max_parameter.h b/mindspore/lite/nnacl/arg_min_max_parameter.h index afedab08c5..949923d052 100644 --- a/mindspore/lite/nnacl/arg_min_max_parameter.h +++ b/mindspore/lite/nnacl/arg_min_max_parameter.h @@ -38,8 +38,8 @@ typedef struct ArgMinMaxParameter { int32_t axis_type_; int32_t dims_size_; int32_t data_type_; // equals to type_id - int32_t in_strides_[DIMENSION_4D]; - int32_t out_strides_[DIMENSION_4D]; + int32_t in_strides_[COMM_SHAPE_SIZE]; + int32_t out_strides_[COMM_SHAPE_SIZE]; ArgElement *arg_elements_; } ArgMinMaxParameter; diff --git a/mindspore/lite/nnacl/batch_to_space.h b/mindspore/lite/nnacl/batch_to_space.h index c42463970b..7a8a76003b 100644 --- a/mindspore/lite/nnacl/batch_to_space.h +++ b/mindspore/lite/nnacl/batch_to_space.h @@ -20,12 +20,11 @@ #include "nnacl/op_base.h" #define BATCH_TO_SPACE_BLOCK_SHAPE_SIZE 2 -#define BATCH_TO_SPACE_CROPS_SIZE 4 typedef struct BatchToSpaceParameter { OpParameter op_parameter_; int32_t block_shape_[BATCH_TO_SPACE_BLOCK_SHAPE_SIZE]; - int32_t crops_[BATCH_TO_SPACE_CROPS_SIZE]; + int32_t crops_[COMM_SHAPE_SIZE]; bool no_crop_; } BatchToSpaceParameter; diff --git a/mindspore/lite/nnacl/broadcast_to_parameter.h b/mindspore/lite/nnacl/broadcast_to_parameter.h index 8cdce592e7..dd9823729b 100644 --- a/mindspore/lite/nnacl/broadcast_to_parameter.h +++ b/mindspore/lite/nnacl/broadcast_to_parameter.h @@ -18,18 +18,16 @@ #include "nnacl/op_base.h" -#define BROADCAST_TO_SHAPE_MAX_SIZE 4 - typedef struct BroadcastToParameter { OpParameter op_parameter_; - int shape_[BROADCAST_TO_SHAPE_MAX_SIZE]; + int shape_[COMM_SHAPE_SIZE]; size_t shape_size_; } BroadcastToParameter; typedef struct BroadcastShapeInfo { - int input_shape_[BROADCAST_TO_SHAPE_MAX_SIZE]; + int input_shape_[COMM_SHAPE_SIZE]; int input_shape_size_; - int output_shape_[BROADCAST_TO_SHAPE_MAX_SIZE]; + int output_shape_[COMM_SHAPE_SIZE]; int output_shape_size_; } BroadcastShapeInfo; diff --git a/mindspore/lite/nnacl/crop_parameter.h b/mindspore/lite/nnacl/crop_parameter.h index c3c94224a3..4ab5c58303 100644 --- a/mindspore/lite/nnacl/crop_parameter.h +++ b/mindspore/lite/nnacl/crop_parameter.h @@ -20,15 +20,13 @@ #include "nnacl/op_base.h" #include "mindspore/lite/nnacl/int8/quantize.h" -#define CROP_OFFSET_MAX_SIZE 4 - typedef struct CropParameter { OpParameter op_parameter_; CropQuantArg quant_arg; int thread_count_; int offset_size_; - int64_t offset_[CROP_OFFSET_MAX_SIZE]; - int64_t in_offset_[CROP_OFFSET_MAX_SIZE]; + int64_t offset_[COMM_SHAPE_SIZE]; + int64_t in_offset_[COMM_SHAPE_SIZE]; int64_t axis_; int *in_shape_; int *out_shape_; diff --git a/mindspore/lite/nnacl/fill_parameter.h b/mindspore/lite/nnacl/fill_parameter.h index dc87516d7a..dbde073817 100644 --- a/mindspore/lite/nnacl/fill_parameter.h +++ b/mindspore/lite/nnacl/fill_parameter.h @@ -18,12 +18,10 @@ #include "nnacl/op_base.h" -#define FILL_DIMS_MAX_SIZE 4 - typedef struct FillParameter { // Primitive parameter OpParameter op_parameter_; - int dims_[FILL_DIMS_MAX_SIZE]; + int dims_[COMM_SHAPE_SIZE]; int num_dims_; } FillParameter; diff --git a/mindspore/lite/nnacl/fp32/pad_fp32.c b/mindspore/lite/nnacl/fp32/pad_fp32.c index b776f729be..7552d3ed7d 100644 --- a/mindspore/lite/nnacl/fp32/pad_fp32.c +++ b/mindspore/lite/nnacl/fp32/pad_fp32.c @@ -53,7 +53,7 @@ int TransOut2InputDimIndex(int out_dim_index, int left_pad, int in_dim, int offs int GetInputFlattenIndex(int out_flatten_index, const int *input_shape, const PadParameter *pad_param) { int in_flatten_index = 0; int i; - for (i = 0; i < DEFAULT_PAD_NDIMS; ++i) { + for (i = 0; i < COMM_SHAPE_SIZE; ++i) { int left_pad = pad_param->paddings_[i * 2]; int out_dim_index = out_flatten_index / pad_param->out_strides[i]; out_flatten_index %= pad_param->out_strides[i]; diff --git a/mindspore/lite/nnacl/int8/pad_int8.c b/mindspore/lite/nnacl/int8/pad_int8.c index 5239212553..10f648882a 100644 --- a/mindspore/lite/nnacl/int8/pad_int8.c +++ b/mindspore/lite/nnacl/int8/pad_int8.c @@ -52,7 +52,7 @@ int TransOut2InputDimIndexInt8(int out_dim_index, int left_pad, int in_dim, int int GetInputFlattenIndexInt8(int out_flatten_index, const int *input_shape, const PadParameter *pad_param) { int in_flatten_index = 0; int i; - for (i = 0; i < DEFAULT_PAD_NDIMS; ++i) { + for (i = 0; i < COMM_SHAPE_SIZE; ++i) { int left_pad = pad_param->paddings_[i * 2]; int out_dim_index = out_flatten_index / pad_param->out_strides[i]; out_flatten_index %= pad_param->out_strides[i]; diff --git a/mindspore/lite/nnacl/int8/unsqueeze_int8.c b/mindspore/lite/nnacl/int8/unsqueeze_int8.c index acf2bb9f58..0be441c2b6 100644 --- a/mindspore/lite/nnacl/int8/unsqueeze_int8.c +++ b/mindspore/lite/nnacl/int8/unsqueeze_int8.c @@ -14,8 +14,8 @@ * limitations under the License. */ -#include "nnacl/unsqueeze_parameter.h" #include "nnacl/int8/unsqueeze_int8.h" +#include "nnacl/unsqueeze_parameter.h" int Int8Unsqueeze(int8_t *input_ptr, int8_t *output_ptr, UnSqueezeParameter *para_, size_t data_size, int task_id) { float output_scale = para_->quant_arg.out_quant_args_.scale_; diff --git a/mindspore/lite/nnacl/int8/unsqueeze_int8.h b/mindspore/lite/nnacl/int8/unsqueeze_int8.h index ad6e40aa62..b6fbce9cd2 100644 --- a/mindspore/lite/nnacl/int8/unsqueeze_int8.h +++ b/mindspore/lite/nnacl/int8/unsqueeze_int8.h @@ -17,6 +17,7 @@ #ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_OPCLIB_INT8_UNSQUEEZE_INT8_H_ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_OPCLIB_INT8_UNSQUEEZE_INT8_H_ +#include #include "nnacl/op_base.h" #include "nnacl/unsqueeze_parameter.h" diff --git a/mindspore/lite/nnacl/l2_norm_parameter.h b/mindspore/lite/nnacl/l2_norm_parameter.h index f9bf06bb6d..615f8273d9 100644 --- a/mindspore/lite/nnacl/l2_norm_parameter.h +++ b/mindspore/lite/nnacl/l2_norm_parameter.h @@ -23,7 +23,7 @@ typedef struct L2NormParameter { // Primitive parameter OpParameter op_parameter_; float epsilon_; - int axis_[8]; + int axis_[MAX_SHAPE_SIZE]; // shape correlative size_t axis_num_; int data_num_; diff --git a/mindspore/lite/nnacl/layer_norm_parameter.h b/mindspore/lite/nnacl/layer_norm_parameter.h index 69c7dd7614..4b8b077e9d 100644 --- a/mindspore/lite/nnacl/layer_norm_parameter.h +++ b/mindspore/lite/nnacl/layer_norm_parameter.h @@ -32,7 +32,7 @@ typedef struct LayerNormParameter { int params_inner_size_; int params_outer_size_; int normalized_dims_; - int normalized_shape_[8]; + int normalized_shape_[MAX_SHAPE_SIZE]; // other parameter int thread_count_; int thread_outsize_; diff --git a/mindspore/lite/nnacl/op_base.h b/mindspore/lite/nnacl/op_base.h index 82105f8e97..d83743778e 100644 --- a/mindspore/lite/nnacl/op_base.h +++ b/mindspore/lite/nnacl/op_base.h @@ -48,6 +48,9 @@ #define MSVALID(left, x, right) (MSMIN((MSMAX(left, x)), right)) +#define COMM_SHAPE_SIZE 4 +#define MAX_SHAPE_SIZE 8 + #define DIMENSION_4D 4 #define DIMENSION_6D 6 #define kInputIndex 0 diff --git a/mindspore/lite/nnacl/pad_parameter.h b/mindspore/lite/nnacl/pad_parameter.h index ff2629d536..fb9c7ae136 100644 --- a/mindspore/lite/nnacl/pad_parameter.h +++ b/mindspore/lite/nnacl/pad_parameter.h @@ -30,13 +30,13 @@ typedef struct PadQuantArg { typedef struct PadParameter { // Primitive parameter OpParameter op_parameter_; - int paddings_[MAX_PAD_SIZE]; + int paddings_[MAX_SHAPE_SIZE]; int pad_mode_; float constant_value_; // shape correlative int padding_length; // other parameter - int in_strides[DEFAULT_PAD_NDIMS]; + int in_strides[COMM_SHAPE_SIZE]; int out_strides[DEFAULT_PAD_NDIMS]; int mirror_offset_; PadQuantArg pad_quant_arg_; diff --git a/mindspore/lite/nnacl/reduce_parameter.h b/mindspore/lite/nnacl/reduce_parameter.h index ed36f1b9c7..1e7ace4156 100644 --- a/mindspore/lite/nnacl/reduce_parameter.h +++ b/mindspore/lite/nnacl/reduce_parameter.h @@ -17,12 +17,11 @@ #ifndef MINDSPORE_LITE_NNACL_REDUCE_PARAMETER_H_ #define MINDSPORE_LITE_NNACL_REDUCE_PARAMETER_H_ #include "nnacl/op_base.h" -#define REDUCE_MAX_AXES_NUM 8 typedef struct ReduceParameter { // primitive parameter OpParameter op_parameter_; - int axes_[REDUCE_MAX_AXES_NUM]; + int axes_[MAX_SHAPE_SIZE]; bool keep_dims_; int mode_; bool reduce_to_end_; diff --git a/mindspore/lite/nnacl/sigmoid_parameter.h b/mindspore/lite/nnacl/sigmoid_parameter.h index 09abf2e7f6..f5cade2fb8 100644 --- a/mindspore/lite/nnacl/sigmoid_parameter.h +++ b/mindspore/lite/nnacl/sigmoid_parameter.h @@ -18,7 +18,6 @@ #define MINDSPORE_LITE_NNACL_SIGMOID_PARAMETER_H_ #include "nnacl/op_base.h" -#define SIGMOID_OFFSET_MAX_SIZE 4 typedef struct SigmoidParameter { // primitive parameter @@ -32,8 +31,8 @@ typedef struct SigmoidParameter { SigmoidQuantArg quant_arg; double alpha_; int thread_count_; - int64_t offset_[PRELU_OFFSET_MAX_SIZE]; - int64_t in_offset_[PRELU_OFFSET_MAX_SIZE]; + int64_t offset_[MAX_SHAPE_SIZE]; + int64_t in_offset_[MAX_SHAPE_SIZE]; int64_t axis_; int input_dim_; int element_num; diff --git a/mindspore/lite/nnacl/slice_parameter.h b/mindspore/lite/nnacl/slice_parameter.h index 5ebad62965..e535ed6371 100644 --- a/mindspore/lite/nnacl/slice_parameter.h +++ b/mindspore/lite/nnacl/slice_parameter.h @@ -19,8 +19,6 @@ #include "nnacl/op_base.h" -#define SLICE_SHAPE_MAX_SIZE 4 - typedef struct SliceQuantArg { QuantArg in_args_; QuantArg out_args_; @@ -33,10 +31,10 @@ typedef struct SliceParameter { OpParameter op_parameter_; // shape correlative - int32_t shape_[SLICE_SHAPE_MAX_SIZE]; - int32_t begin_[SLICE_SHAPE_MAX_SIZE]; - int32_t end_[SLICE_SHAPE_MAX_SIZE]; - int32_t size_[SLICE_SHAPE_MAX_SIZE]; + int32_t shape_[COMM_SHAPE_SIZE]; + int32_t begin_[COMM_SHAPE_SIZE]; + int32_t end_[COMM_SHAPE_SIZE]; + int32_t size_[COMM_SHAPE_SIZE]; // other parameter SliceQuantArg quant_arg_; diff --git a/mindspore/lite/nnacl/strided_slice.h b/mindspore/lite/nnacl/strided_slice.h index 2e0ff78a4f..ea4547b138 100644 --- a/mindspore/lite/nnacl/strided_slice.h +++ b/mindspore/lite/nnacl/strided_slice.h @@ -21,14 +21,14 @@ typedef struct StridedSliceParameter { // primitive parameter OpParameter op_parameter_; - int begins_[8]; - int ends_[8]; - int strides_[8]; + int begins_[MAX_SHAPE_SIZE]; + int ends_[MAX_SHAPE_SIZE]; + int strides_[MAX_SHAPE_SIZE]; int isScale; // shape correlative int in_shape_length_; - int in_shape_[8]; + int in_shape_[MAX_SHAPE_SIZE]; // other parameter int num_axes_; diff --git a/mindspore/lite/nnacl/transpose.h b/mindspore/lite/nnacl/transpose.h index e34dbb18a2..06087526b2 100644 --- a/mindspore/lite/nnacl/transpose.h +++ b/mindspore/lite/nnacl/transpose.h @@ -24,12 +24,12 @@ typedef struct TransposeParameter { // primitive parameter OpParameter op_parameter_; - int perm_[8]; + int perm_[MAX_SHAPE_SIZE]; bool conjugate_; // shape correlative - int strides_[8]; - int out_strides_[8]; + int strides_[MAX_SHAPE_SIZE]; + int out_strides_[MAX_SHAPE_SIZE]; // other parameter int num_axes_; diff --git a/mindspore/lite/nnacl/unsqueeze_parameter.h b/mindspore/lite/nnacl/unsqueeze_parameter.h index cf6e6b0058..137dc2ac51 100644 --- a/mindspore/lite/nnacl/unsqueeze_parameter.h +++ b/mindspore/lite/nnacl/unsqueeze_parameter.h @@ -17,12 +17,8 @@ #ifndef MINDSPORE_LITE_NNACL_UNSQUEEZE_PARAMETER_H_ #define MINDSPORE_LITE_NNACL_UNSQUEEZE_PARAMETER_H_ -#include -#include #include "nnacl/op_base.h" -#define UNSQUEEZE_MAX_SIZE 4 - typedef struct UnSqueezeQuantArg { int *output_shape_; float alpha; @@ -35,12 +31,12 @@ typedef struct UnSqueezeQuantArg { typedef struct UnSqueezeParameter { // primitive parameter OpParameter op_parameter_; - int dims_[UNSQUEEZE_MAX_SIZE]; + int dims_[COMM_SHAPE_SIZE]; // shape correlative const int *in_shape_; const int *out_shape_; - int64_t offset_[UNSQUEEZE_MAX_SIZE]; + int64_t offset_[COMM_SHAPE_SIZE]; int64_t axis_; // other parameter diff --git a/mindspore/lite/src/ops/populate/batch_to_space_populate.cc b/mindspore/lite/src/ops/populate/batch_to_space_populate.cc index 4a89dbdba2..5332e0cfd6 100644 --- a/mindspore/lite/src/ops/populate/batch_to_space_populate.cc +++ b/mindspore/lite/src/ops/populate/batch_to_space_populate.cc @@ -41,8 +41,8 @@ OpParameter *PopulateBatchToSpaceParameter(const mindspore::lite::PrimitiveC *pr } auto crops = param->GetCrops(); - if (crops.size() != BATCH_TO_SPACE_CROPS_SIZE) { - MS_LOG(ERROR) << "batch_to_space crops size should be " << BATCH_TO_SPACE_CROPS_SIZE; + if (crops.size() != COMM_SHAPE_SIZE) { + MS_LOG(ERROR) << "batch_to_space crops size should be " << COMM_SHAPE_SIZE; free(batch_space_param); return nullptr; } @@ -52,7 +52,7 @@ OpParameter *PopulateBatchToSpaceParameter(const mindspore::lite::PrimitiveC *pr } batch_space_param->no_crop_ = true; - for (int i = 0; i < BATCH_TO_SPACE_CROPS_SIZE; ++i) { + for (int i = 0; i < COMM_SHAPE_SIZE; ++i) { batch_space_param->crops_[i] = crops[i]; if (batch_space_param->crops_[i] != 0) { batch_space_param->no_crop_ = false; diff --git a/mindspore/lite/src/ops/populate/crop_populate.cc b/mindspore/lite/src/ops/populate/crop_populate.cc index a59ba5a2d6..0898fa283f 100644 --- a/mindspore/lite/src/ops/populate/crop_populate.cc +++ b/mindspore/lite/src/ops/populate/crop_populate.cc @@ -25,8 +25,8 @@ namespace lite { OpParameter *PopulateCropParameter(const mindspore::lite::PrimitiveC *primitive) { auto param = reinterpret_cast(const_cast(primitive)); auto param_offset = param->GetOffsets(); - if (param_offset.size() > CROP_OFFSET_MAX_SIZE) { - MS_LOG(ERROR) << "crop_param offset size(" << param_offset.size() << ") should <= " << CROP_OFFSET_MAX_SIZE; + if (param_offset.size() > COMM_SHAPE_SIZE) { + MS_LOG(ERROR) << "crop_param offset size(" << param_offset.size() << ") should <= " << COMM_SHAPE_SIZE; return nullptr; } CropParameter *crop_param = reinterpret_cast(malloc(sizeof(CropParameter))); diff --git a/mindspore/lite/src/ops/populate/reduce_populate.cc b/mindspore/lite/src/ops/populate/reduce_populate.cc index c35b18d875..b881fbd479 100644 --- a/mindspore/lite/src/ops/populate/reduce_populate.cc +++ b/mindspore/lite/src/ops/populate/reduce_populate.cc @@ -36,8 +36,8 @@ OpParameter *PopulateReduceParameter(const mindspore::lite::PrimitiveC *primitiv reduce_param->reduce_to_end_ = reduce->GetReduceToEnd(); reduce_param->coeff = reduce->GetCoeff(); auto axisVector = reduce->GetAxes(); - if (axisVector.size() > REDUCE_MAX_AXES_NUM) { - MS_LOG(ERROR) << "Reduce axes size " << axisVector.size() << " exceed limit " << REDUCE_MAX_AXES_NUM; + if (axisVector.size() > MAX_SHAPE_SIZE) { + MS_LOG(ERROR) << "Reduce axes size " << axisVector.size() << " exceed limit " << MAX_SHAPE_SIZE; free(reduce_param); return nullptr; } diff --git a/mindspore/lite/src/runtime/kernel/arm/base/reduce_base.cc b/mindspore/lite/src/runtime/kernel/arm/base/reduce_base.cc index ceb311f830..afc2c83a16 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/reduce_base.cc +++ b/mindspore/lite/src/runtime/kernel/arm/base/reduce_base.cc @@ -100,7 +100,7 @@ int ReduceBaseCPUKernel::Init() { if (in_tensors_.size() > 1) { auto axes_ptr = in_tensors_.at(1); num_axes_ = axes_ptr->ElementsNum(); - if (axes_ptr->ElementsNum() > REDUCE_MAX_AXES_NUM) { + if (axes_ptr->ElementsNum() > MAX_SHAPE_SIZE) { MS_LOG(ERROR) << "input axes invalid."; return RET_ERROR; } diff --git a/mindspore/lite/src/runtime/kernel/arm/base/reduce_base.h b/mindspore/lite/src/runtime/kernel/arm/base/reduce_base.h index 3ec9738763..27fcbc8b33 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/reduce_base.h +++ b/mindspore/lite/src/runtime/kernel/arm/base/reduce_base.h @@ -39,7 +39,7 @@ class ReduceBaseCPUKernel : public LiteKernel { int CheckParameters(); protected: - int axes_[REDUCE_MAX_AXES_NUM]; + int axes_[MAX_SHAPE_SIZE]; int num_axes_; int mode_; bool reduce_to_end_; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/pad_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/pad_fp32.cc index 159c93a54a..924884bdfc 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/pad_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/pad_fp32.cc @@ -41,30 +41,30 @@ int PadCPUKernel::Init() { int PadCPUKernel::ReSize() { auto input = in_tensors_.at(0); auto rank = input->shape().size(); - if (rank > DEFAULT_PAD_NDIMS) { - MS_LOG(ERROR) << "Pad input rank should <= " << DEFAULT_PAD_NDIMS << ", got " << rank; + if (rank > COMM_SHAPE_SIZE) { + MS_LOG(ERROR) << "Pad input rank should <= " << COMM_SHAPE_SIZE << ", got " << rank; return RET_ERROR; } auto output = out_tensors_.at(0); if (pad_param_->pad_mode_ == static_cast(schema::PaddingMode_CONSTANT)) { - auto ret = ExtendShape(in_, DEFAULT_PAD_NDIMS, input->shape().data(), rank); + auto ret = ExtendShape(in_, COMM_SHAPE_SIZE, input->shape().data(), rank); if (ret != RET_OK) { return ret; } - ret = ExtendShape(out_, DEFAULT_PAD_NDIMS, output->shape().data(), rank); + ret = ExtendShape(out_, COMM_SHAPE_SIZE, output->shape().data(), rank); if (ret != RET_OK) { return ret; } - if (pad_param_->padding_length < MAX_PAD_SIZE) { - int ori_paddings[MAX_PAD_SIZE]; + if (pad_param_->padding_length < MAX_SHAPE_SIZE) { + int ori_paddings[MAX_SHAPE_SIZE]; for (auto i = 0; i < pad_param_->padding_length; ++i) { ori_paddings[i] = pad_param_->paddings_[i]; } - ret = ExtendPaddings(pad_param_->paddings_, MAX_PAD_SIZE, ori_paddings, pad_param_->padding_length); + ret = ExtendPaddings(pad_param_->paddings_, MAX_SHAPE_SIZE, ori_paddings, pad_param_->padding_length); if (ret != RET_OK) { return ret; } - pad_param_->padding_length = MAX_PAD_SIZE; + pad_param_->padding_length = MAX_SHAPE_SIZE; } } return RET_OK; @@ -72,8 +72,8 @@ int PadCPUKernel::ReSize() { void PadCPUKernel::InitMirrorPadBlock() { mirror_pad_block_.clear(); - std::vector left_pads(DEFAULT_PAD_NDIMS); - for (size_t i = 0; i < DEFAULT_PAD_NDIMS; ++i) { + std::vector left_pads(COMM_SHAPE_SIZE); + for (size_t i = 0; i < COMM_SHAPE_SIZE; ++i) { left_pads[i] = pad_param_->paddings_[2 * i]; } @@ -84,7 +84,7 @@ void PadCPUKernel::InitMirrorPadBlock() { /* init separate dims */ int cur_input = 1; int cur_output = 1; - for (size_t i = 0; i < DEFAULT_PAD_NDIMS; ++i) { + for (size_t i = 0; i < COMM_SHAPE_SIZE; ++i) { if (1 < cur_input) { input_separate_dims.emplace_back(cur_input); output_separate_dims.emplace_back(cur_output); @@ -150,7 +150,7 @@ void PadCPUKernel::InitMirrorPadBlock() { } MirrorPadBlock block; - const int size_offset = DEFAULT_PAD_NDIMS - static_cast(pad_region.size()); + const int size_offset = COMM_SHAPE_SIZE - static_cast(pad_region.size()); for (size_t i = 0; i < pad_region.size(); ++i) { int di = size_offset + i; int si = remain_dim_offset + i; @@ -328,28 +328,28 @@ int PadCPUKernel::CopyPaddingFromInput() { return RET_ERROR; } - auto ret = ExtendShape(in_, DEFAULT_PAD_NDIMS, input_shape.data(), rank); + auto ret = ExtendShape(in_, COMM_SHAPE_SIZE, input_shape.data(), rank); if (ret != RET_OK) { return ret; } - ret = ExtendPaddings(pad_param_->paddings_, MAX_PAD_SIZE, paddings, padding_tensor->ElementsNum()); + ret = ExtendPaddings(pad_param_->paddings_, MAX_SHAPE_SIZE, paddings, padding_tensor->ElementsNum()); if (ret != RET_OK) { return ret; } - pad_param_->padding_length = MAX_PAD_SIZE; + pad_param_->padding_length = MAX_SHAPE_SIZE; return RET_OK; } void PadCPUKernel::CalculateStrides() { - pad_param_->in_strides[DEFAULT_PAD_NDIMS - 1] = 1; - for (auto i = DEFAULT_PAD_NDIMS - 2; i >= 0; --i) { + pad_param_->in_strides[COMM_SHAPE_SIZE - 1] = 1; + for (auto i = COMM_SHAPE_SIZE - 2; i >= 0; --i) { pad_param_->in_strides[i] = in_[i + 1] * pad_param_->in_strides[i + 1]; } - for (auto i = 0; i < DEFAULT_PAD_NDIMS; ++i) { + for (auto i = 0; i < COMM_SHAPE_SIZE; ++i) { out_[i] = in_[i] + pad_param_->paddings_[i * 2] + pad_param_->paddings_[i * 2 + 1]; } - pad_param_->out_strides[DEFAULT_PAD_NDIMS - 1] = 1; - for (auto i = DEFAULT_PAD_NDIMS - 2; i >= 0; --i) { + pad_param_->out_strides[COMM_SHAPE_SIZE - 1] = 1; + for (auto i = COMM_SHAPE_SIZE - 2; i >= 0; --i) { pad_param_->out_strides[i] = out_[i + 1] * pad_param_->out_strides[i + 1]; } } @@ -358,7 +358,7 @@ int PadCPUKernel::HandleMirrorPad() { if (in_tensors_.size() == 1) { auto input_shape = in_tensors_.at(0)->shape(); int rank = static_cast(input_shape.size()); - auto ret = ExtendShape(in_, DEFAULT_PAD_NDIMS, input_shape.data(), rank); + auto ret = ExtendShape(in_, COMM_SHAPE_SIZE, input_shape.data(), rank); if (ret != RET_OK) { return ret; } @@ -368,7 +368,7 @@ int PadCPUKernel::HandleMirrorPad() { return ret; } } - auto ret = CheckPaddings(pad_param_->paddings_, DEFAULT_PAD_NDIMS, in_, pad_param_->pad_mode_); + auto ret = CheckPaddings(pad_param_->paddings_, COMM_SHAPE_SIZE, in_, pad_param_->pad_mode_); if (ret != RET_OK) { return ret; } diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/transpose_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/transpose_fp32.cc index c32cae37d6..f5edc39d82 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/transpose_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/transpose_fp32.cc @@ -29,7 +29,6 @@ using mindspore::schema::PrimitiveType_Nhwc2Nchw; using mindspore::schema::PrimitiveType_Transpose; namespace mindspore::kernel { - int TransposeCPUKernel::Init() { if (!InferShapeDone()) { return RET_OK; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/transpose_fp32.h b/mindspore/lite/src/runtime/kernel/arm/fp32/transpose_fp32.h index 607fd5a9df..1581b8f2bb 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/transpose_fp32.h +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/transpose_fp32.h @@ -20,6 +20,7 @@ #include #include "include/errorcode.h" #include "nnacl/fp32/transpose_fp32.h" +#include "nnacl/transpose.h" #include "src/lite_kernel.h" #include "src/kernel_registry.h" diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/pad_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/pad_int8.cc index 828de0c4ac..d4d0fe1d80 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/pad_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/pad_int8.cc @@ -91,12 +91,12 @@ int PadInt8CPUKernel::InitPadParam() { int out[] = {1, 1, 1, 1}; for (int i = 0; i < ndims; i++) { - in[DEFAULT_PAD_NDIMS - ndims + i] = in_dims[i]; - out[DEFAULT_PAD_NDIMS - ndims + i] = out_dims[i]; + in[COMM_SHAPE_SIZE - ndims + i] = in_dims[i]; + out[COMM_SHAPE_SIZE - ndims + i] = out_dims[i]; } - memcpy(in_dims_, in, DEFAULT_PAD_NDIMS * sizeof(int)); - memcpy(out_dims_, out, DEFAULT_PAD_NDIMS * sizeof(int)); + memcpy(in_dims_, in, COMM_SHAPE_SIZE * sizeof(int)); + memcpy(out_dims_, out, COMM_SHAPE_SIZE * sizeof(int)); return RET_OK; } @@ -146,7 +146,7 @@ int PadInt8CPUKernel::HandleMirrorPad() { if (ret != RET_OK) { return ret; } - ret = CheckPaddings(pad_param_->paddings_, DEFAULT_PAD_NDIMS, in_dims_, pad_param_->pad_mode_); + ret = CheckPaddings(pad_param_->paddings_, COMM_SHAPE_SIZE, in_dims_, pad_param_->pad_mode_); if (ret != RET_OK) { return ret; } @@ -156,15 +156,15 @@ int PadInt8CPUKernel::HandleMirrorPad() { } void PadInt8CPUKernel::CalculateStrides() { - pad_param_->in_strides[DEFAULT_PAD_NDIMS - 1] = 1; - for (auto i = DEFAULT_PAD_NDIMS - 2; i >= 0; --i) { + pad_param_->in_strides[COMM_SHAPE_SIZE - 1] = 1; + for (auto i = COMM_SHAPE_SIZE - 2; i >= 0; --i) { pad_param_->in_strides[i] = in_dims_[i + 1] * pad_param_->in_strides[i + 1]; } - for (auto i = 0; i < DEFAULT_PAD_NDIMS; ++i) { + for (auto i = 0; i < COMM_SHAPE_SIZE; ++i) { out_dims_[i] = in_dims_[i] + pad_param_->paddings_[i * 2] + pad_param_->paddings_[i * 2 + 1]; } - pad_param_->out_strides[DEFAULT_PAD_NDIMS - 1] = 1; - for (auto i = DEFAULT_PAD_NDIMS - 2; i >= 0; --i) { + pad_param_->out_strides[COMM_SHAPE_SIZE - 1] = 1; + for (auto i = COMM_SHAPE_SIZE - 2; i >= 0; --i) { pad_param_->out_strides[i] = out_dims_[i + 1] * pad_param_->out_strides[i + 1]; } } @@ -252,11 +252,11 @@ int PadInt8CPUKernel::CopyPaddingFromInput() { return RET_ERROR; } - auto ret = ExtendPaddings(pad_param_->paddings_, MAX_PAD_SIZE, paddings, padding_tensor->ElementsNum()); + auto ret = ExtendPaddings(pad_param_->paddings_, MAX_SHAPE_SIZE, paddings, padding_tensor->ElementsNum()); if (ret != RET_OK) { return ret; } - pad_param_->padding_length = MAX_PAD_SIZE; + pad_param_->padding_length = MAX_SHAPE_SIZE; return RET_OK; } diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/pad_int8.h b/mindspore/lite/src/runtime/kernel/arm/int8/pad_int8.h index c0bf673502..ecd1f61fed 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/pad_int8.h +++ b/mindspore/lite/src/runtime/kernel/arm/int8/pad_int8.h @@ -59,8 +59,8 @@ class PadInt8CPUKernel : public LiteKernel { PadParameter *pad_param_ = nullptr; int8_t *in_data_ = nullptr; int8_t *out_data_ = nullptr; - int in_dims_[DEFAULT_PAD_NDIMS] = {0}; - int out_dims_[DEFAULT_PAD_NDIMS] = {0}; + int in_dims_[COMM_SHAPE_SIZE] = {0}; + int out_dims_[COMM_SHAPE_SIZE] = {0}; }; } // namespace mindspore::kernel #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_INT8_PAD_INT8_H_ diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/transpose_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/transpose_int8.cc index 481a9d8b1c..da2dad0069 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/transpose_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/transpose_int8.cc @@ -24,7 +24,6 @@ using mindspore::lite::RET_OP_EXECUTE_FAILURE; using mindspore::schema::PrimitiveType_Transpose; namespace mindspore::kernel { - int TransposeInt8CPUKernel::Init() { if (!InferShapeDone()) { return RET_OK; @@ -94,7 +93,7 @@ int TransposeInt8CPUKernel::ReSize() { transpose_param_->out_strides_[i] = out_shape.at(i + 1) * transpose_param_->out_strides_[i + 1]; } - extra_dims_ = out_shape.size() > MAX_TRANSPOSE_DIM_SIZE; + extra_dims_ = out_shape.size() > MAX_SHAPE_SIZE; num_unit_ = static_cast(in_shape.at(transpose_param_->perm_[kNHWC_H])); thread_h_num_ = MSMIN(thread_num_, num_unit_);