From: @liuwenhao4 Reviewed-by: @HilbertDavid,@zhanghaibo5 Signed-off-by: @zhanghaibo5tags/v1.1.0
| @@ -19,7 +19,7 @@ | |||||
| #include "nnacl/fp32/arithmetic_self.h" | #include "nnacl/fp32/arithmetic_self.h" | ||||
| // abs: | // abs: | ||||
| int ElementAbs(float *input, float *output, int element_size) { | |||||
| int ElementAbs(const float *input, float *output, const int element_size) { | |||||
| for (int i = 0; i < element_size; i++) { | for (int i = 0; i < element_size; i++) { | ||||
| output[i] = fabsf(input[i]); | output[i] = fabsf(input[i]); | ||||
| } | } | ||||
| @@ -27,7 +27,7 @@ int ElementAbs(float *input, float *output, int element_size) { | |||||
| } | } | ||||
| // cos: | // cos: | ||||
| int ElementCos(float *input, float *output, int element_size) { | |||||
| int ElementCos(const float *input, float *output, const int element_size) { | |||||
| for (int i = 0; i < element_size; i++) { | for (int i = 0; i < element_size; i++) { | ||||
| output[i] = cosf(input[i]); | output[i] = cosf(input[i]); | ||||
| } | } | ||||
| @@ -35,7 +35,7 @@ int ElementCos(float *input, float *output, int element_size) { | |||||
| } | } | ||||
| // log: | // log: | ||||
| int ElementLog(float *input, float *output, int element_size) { | |||||
| int ElementLog(const float *input, float *output, const int element_size) { | |||||
| for (int i = 0; i < element_size; i++) { | for (int i = 0; i < element_size; i++) { | ||||
| if (input[i] <= 0) { | if (input[i] <= 0) { | ||||
| return NNACL_ERRCODE_LOG_NEGATIVE_OR_ZERO; | return NNACL_ERRCODE_LOG_NEGATIVE_OR_ZERO; | ||||
| @@ -46,7 +46,7 @@ int ElementLog(float *input, float *output, int element_size) { | |||||
| } | } | ||||
| // Square | // Square | ||||
| int ElementSquare(float *input, float *output, int element_size) { | |||||
| int ElementSquare(const float *input, float *output, const int element_size) { | |||||
| for (int i = 0; i < element_size; i++) { | for (int i = 0; i < element_size; i++) { | ||||
| output[i] = input[i] * input[i]; | output[i] = input[i] * input[i]; | ||||
| } | } | ||||
| @@ -54,7 +54,7 @@ int ElementSquare(float *input, float *output, int element_size) { | |||||
| } | } | ||||
| // Sqrt | // Sqrt | ||||
| int ElementSqrt(float *input, float *output, int element_size) { | |||||
| int ElementSqrt(const float *input, float *output, const int element_size) { | |||||
| for (int i = 0; i < element_size; i++) { | for (int i = 0; i < element_size; i++) { | ||||
| if (input[i] < 0) { | if (input[i] < 0) { | ||||
| return NNACL_ERRCODE_SQRT_NEGATIVE; | return NNACL_ERRCODE_SQRT_NEGATIVE; | ||||
| @@ -65,7 +65,7 @@ int ElementSqrt(float *input, float *output, int element_size) { | |||||
| } | } | ||||
| // rsqrt | // rsqrt | ||||
| int ElementRsqrt(float *input, float *output, int element_size) { | |||||
| int ElementRsqrt(const float *input, float *output, const int element_size) { | |||||
| for (int i = 0; i < element_size; i++) { | for (int i = 0; i < element_size; i++) { | ||||
| if (input[i] <= 0) { | if (input[i] <= 0) { | ||||
| return NNACL_ERRCODE_RSQRT_NEGATIVE_OR_ZERO; | return NNACL_ERRCODE_RSQRT_NEGATIVE_OR_ZERO; | ||||
| @@ -76,7 +76,7 @@ int ElementRsqrt(float *input, float *output, int element_size) { | |||||
| } | } | ||||
| // sin: | // sin: | ||||
| int ElementSin(float *input, float *output, int element_size) { | |||||
| int ElementSin(const float *input, float *output, const int element_size) { | |||||
| for (int i = 0; i < element_size; i++) { | for (int i = 0; i < element_size; i++) { | ||||
| output[i] = sinf(input[i]); | output[i] = sinf(input[i]); | ||||
| } | } | ||||
| @@ -84,7 +84,7 @@ int ElementSin(float *input, float *output, int element_size) { | |||||
| } | } | ||||
| // logical_not: | // logical_not: | ||||
| int ElementLogicalNot(float *input, float *output, int element_size) { | |||||
| int ElementLogicalNot(const float *input, float *output, const int element_size) { | |||||
| for (int i = 0; i < element_size; i++) { | for (int i = 0; i < element_size; i++) { | ||||
| output[i] = (float)(!((bool)(input[i]))); | output[i] = (float)(!((bool)(input[i]))); | ||||
| } | } | ||||
| @@ -92,7 +92,7 @@ int ElementLogicalNot(float *input, float *output, int element_size) { | |||||
| } | } | ||||
| // round: | // round: | ||||
| int ElementRound(float *input, float *output, int element_size) { | |||||
| int ElementRound(const float *input, float *output, const int element_size) { | |||||
| for (int i = 0; i < element_size; i++) { | for (int i = 0; i < element_size; i++) { | ||||
| output[i] = round(input[i]); | output[i] = round(input[i]); | ||||
| } | } | ||||
| @@ -100,21 +100,21 @@ int ElementRound(float *input, float *output, int element_size) { | |||||
| } | } | ||||
| // floor: | // floor: | ||||
| int ElementFloor(float *input, float *output, int element_size) { | |||||
| int ElementFloor(const float *input, float *output, const int element_size) { | |||||
| for (int i = 0; i < element_size; i++) { | for (int i = 0; i < element_size; i++) { | ||||
| output[i] = floorf(input[i]); | output[i] = floorf(input[i]); | ||||
| } | } | ||||
| return NNACL_OK; | return NNACL_OK; | ||||
| } | } | ||||
| int ElementCeil(float *input, float *output, int number) { | |||||
| int ElementCeil(const float *input, float *output, const int number) { | |||||
| for (int i = 0; i < number; ++i) { | for (int i = 0; i < number; ++i) { | ||||
| output[i] = ceil(input[i]); | output[i] = ceil(input[i]); | ||||
| } | } | ||||
| return NNACL_OK; | return NNACL_OK; | ||||
| } | } | ||||
| int ElementNegative(float *input, float *output, int element_size) { | |||||
| int ElementNegative(const float *input, float *output, const int element_size) { | |||||
| for (int i = 0; i < element_size; ++i) { | for (int i = 0; i < element_size; ++i) { | ||||
| output[i] = -input[i]; | output[i] = -input[i]; | ||||
| } | } | ||||
| @@ -26,29 +26,29 @@ | |||||
| #ifdef __cplusplus | #ifdef __cplusplus | ||||
| extern "C" { | extern "C" { | ||||
| #endif | #endif | ||||
| int ElementAbs(float *input, float *output, int element_size); | |||||
| int ElementAbs(const float *input, float *output, const int element_size); | |||||
| int ElementCos(float *input, float *output, int element_size); | |||||
| int ElementCos(const float *input, float *output, const int element_size); | |||||
| int ElementLog(float *input, float *output, int element_size); | |||||
| int ElementLog(const float *input, float *output, const int element_size); | |||||
| int ElementSquare(float *input, float *output, int element_size); | |||||
| int ElementSquare(const float *input, float *output, const int element_size); | |||||
| int ElementSqrt(float *input, float *output, int element_size); | |||||
| int ElementSqrt(const float *input, float *output, const int element_size); | |||||
| int ElementRsqrt(float *input, float *output, int element_size); | |||||
| int ElementRsqrt(const float *input, float *output, const int element_size); | |||||
| int ElementSin(float *input, float *output, int element_size); | |||||
| int ElementSin(const float *input, float *output, const int element_size); | |||||
| int ElementLogicalNot(float *input, float *output, int element_size); | |||||
| int ElementLogicalNot(const float *input, float *output, const int element_size); | |||||
| int ElementRound(float *input, float *output, int element_size); | |||||
| int ElementRound(const float *input, float *output, const int element_size); | |||||
| int ElementFloor(float *input, float *output, int element_size); | |||||
| int ElementFloor(const float *input, float *output, const int element_size); | |||||
| int ElementCeil(float *input, float *output, int number); | |||||
| int ElementCeil(const float *input, float *output, const int number); | |||||
| int ElementNegative(float *input, float *output, int element_size); | |||||
| int ElementNegative(const float *input, float *output, const int element_size); | |||||
| #ifdef __cplusplus | #ifdef __cplusplus | ||||
| } | } | ||||
| #endif | #endif | ||||
| @@ -340,7 +340,7 @@ void DeConvWgMerge(const float *src, float *dst, size_t src_stride, size_t dst_s | |||||
| return; | return; | ||||
| } | } | ||||
| void DeConvWgCalWgFp32(const float *tile_in, float *tile_out, float *weight_buf, float *tmp_buf, float *at_buf, | |||||
| void DeConvWgCalWgFp32(const float *tile_in, float *tile_out, float *weight_buf, float *tmp_buf, const float *at_buf, | |||||
| float *a_mid_buf, float *trans_a_buf, bool *transfered, const float *bt_buf, float *b_tmp_buf, | float *a_mid_buf, float *trans_a_buf, bool *transfered, const float *bt_buf, float *b_tmp_buf, | ||||
| int unit_size, int w_start, int h_start, ConvParameter *conv_param, DeConvParam *deconv_param) { | int unit_size, int w_start, int h_start, ConvParameter *conv_param, DeConvParam *deconv_param) { | ||||
| int winograd_plane = unit_size * unit_size; | int winograd_plane = unit_size * unit_size; | ||||
| @@ -24,9 +24,9 @@ void DoSpaceToBatchNHWCInt8(const int8_t *input, int8_t *output, const int *bloc | |||||
| int copy_num = out_shape[3]; | int copy_num = out_shape[3]; | ||||
| int block_w = block_sizes[1]; | int block_w = block_sizes[1]; | ||||
| int block_h = block_sizes[0]; | int block_h = block_sizes[0]; | ||||
| int in_strides[4]; | |||||
| int in_strides[4] = {0}; | |||||
| ComputeStrides(in_shape, in_strides, 4); | ComputeStrides(in_shape, in_strides, 4); | ||||
| int out_strides[4]; | |||||
| int out_strides[4] = {0}; | |||||
| ComputeStrides(out_shape, out_strides, 4); | ComputeStrides(out_shape, out_strides, 4); | ||||
| size_t copy_size = copy_num * sizeof(int8_t); | size_t copy_size = copy_num * sizeof(int8_t); | ||||
| size_t out_offset = 0; | size_t out_offset = 0; | ||||
| @@ -151,7 +151,7 @@ void TransposeCommInt8(const int8_t *in_data, int8_t *out_data, const int *strid | |||||
| int DoTransposeInt8(const int8_t *in_data, int8_t *out_data, int *input_shape, const int *output_shape, | int DoTransposeInt8(const int8_t *in_data, int8_t *out_data, int *input_shape, const int *output_shape, | ||||
| TransposeParameter *transpose_param, int h_start, int h_end, int *dim_size, int *position) { | TransposeParameter *transpose_param, int h_start, int h_end, int *dim_size, int *position) { | ||||
| if (in_data == NULL || out_data == NULL) { | if (in_data == NULL || out_data == NULL) { | ||||
| return NNACL_ERR; | |||||
| return NNACL_NULL_PTR; | |||||
| } | } | ||||
| int *perm = transpose_param->perm_; | int *perm = transpose_param->perm_; | ||||
| @@ -47,7 +47,7 @@ class Arithmetic : public PrimitiveC { | |||||
| protected: | protected: | ||||
| bool broadcasting_ = false; | bool broadcasting_ = false; | ||||
| int ndim_; | |||||
| int ndim_ = 0; | |||||
| std::vector<int> in_shape0_; | std::vector<int> in_shape0_; | ||||
| std::vector<int> in_shape1_; | std::vector<int> in_shape1_; | ||||
| std::vector<int> out_shape_; | std::vector<int> out_shape_; | ||||
| @@ -63,6 +63,10 @@ int Gather::UnPackAttr(const Primitive &prim, const std::vector<AnfNodePtr> &inp | |||||
| gather_attr->axis = axis; | gather_attr->axis = axis; | ||||
| } else { | } else { | ||||
| MS_LOG(ERROR) << "input axis is not value node."; | MS_LOG(ERROR) << "input axis is not value node."; | ||||
| delete this->primitive_; | |||||
| delete gather_attr; | |||||
| this->primitive_ = nullptr; | |||||
| gather_attr = nullptr; | |||||
| return RET_ERROR; | return RET_ERROR; | ||||
| } | } | ||||
| gather_attr->batchDims = 0; | gather_attr->batchDims = 0; | ||||
| @@ -70,7 +70,7 @@ class StridedSlice : public PrimitiveC { | |||||
| std::vector<int> GetStrides() { return this->strides_; } | std::vector<int> GetStrides() { return this->strides_; } | ||||
| protected: | protected: | ||||
| int ndim_; | |||||
| int ndim_ = 0; | |||||
| std::vector<int> in_shape_; | std::vector<int> in_shape_; | ||||
| std::vector<int> begins_; | std::vector<int> begins_; | ||||
| std::vector<int> ends_; | std::vector<int> ends_; | ||||
| @@ -39,9 +39,9 @@ class DetectionPostProcessBaseCPUKernel : public LiteKernel { | |||||
| int ReSize() override; | int ReSize() override; | ||||
| int Run() override; | int Run() override; | ||||
| int thread_num_; | |||||
| int num_boxes_; | |||||
| int num_classes_with_bg_; | |||||
| int thread_num_ = 1; | |||||
| int num_boxes_ = 0; | |||||
| int num_classes_with_bg_ = 0; | |||||
| float *input_boxes_ = nullptr; | float *input_boxes_ = nullptr; | ||||
| float *input_scores_ = nullptr; | float *input_scores_ = nullptr; | ||||
| DetectionPostProcessParameter *params_ = nullptr; | DetectionPostProcessParameter *params_ = nullptr; | ||||
| @@ -33,7 +33,7 @@ using mindspore::schema::PrimitiveType_Sqrt; | |||||
| using mindspore::schema::PrimitiveType_Square; | using mindspore::schema::PrimitiveType_Square; | ||||
| namespace mindspore::kernel { | namespace mindspore::kernel { | ||||
| typedef int (*ArithmeticSelfFunc)(float *input, float *output, int element_size); | |||||
| typedef int (*ArithmeticSelfFunc)(const float *input, float *output, const int element_size); | |||||
| class ArithmeticSelfCPUKernel : public LiteKernel { | class ArithmeticSelfCPUKernel : public LiteKernel { | ||||
| public: | public: | ||||
| explicit ArithmeticSelfCPUKernel(OpParameter *parameter, const std::vector<lite::Tensor *> &inputs, | explicit ArithmeticSelfCPUKernel(OpParameter *parameter, const std::vector<lite::Tensor *> &inputs, | ||||
| @@ -40,10 +40,10 @@ class QuantizedAddCPUKernel : public LiteKernel { | |||||
| private: | private: | ||||
| AddQuantParameter para_; | AddQuantParameter para_; | ||||
| ArithmeticParameter *arith_para_; | |||||
| int thread_count_; | |||||
| int thread_stride_; | |||||
| int elements_num_; | |||||
| ArithmeticParameter *arith_para_ = nullptr; | |||||
| int thread_count_ = 1; | |||||
| int thread_stride_ = 0; | |||||
| int elements_num_ = 0; | |||||
| int8_t *input0_data_ = nullptr; | int8_t *input0_data_ = nullptr; | ||||
| int8_t *input1_data_ = nullptr; | int8_t *input1_data_ = nullptr; | ||||
| int8_t *output_data_ = nullptr; | int8_t *output_data_ = nullptr; | ||||
| @@ -37,8 +37,8 @@ class DetectionPostProcessInt8CPUKernel : public DetectionPostProcessBaseCPUKern | |||||
| int8_t *data_int8_ = nullptr; | int8_t *data_int8_ = nullptr; | ||||
| float *data_fp32_ = nullptr; | float *data_fp32_ = nullptr; | ||||
| lite::QuantArg quant_param_; | lite::QuantArg quant_param_; | ||||
| int quant_size_; | |||||
| int thread_n_stride_; | |||||
| int quant_size_ = 0; | |||||
| int thread_n_stride_ = 0; | |||||
| int DequantizeInt8ToFp32(const int task_id); | int DequantizeInt8ToFp32(const int task_id); | ||||
| private: | private: | ||||
| @@ -68,9 +68,9 @@ class FullconnectionInt8CPUKernel : public FullconnectionBaseCPUKernel { | |||||
| int *input_sums_ = nullptr; | int *input_sums_ = nullptr; | ||||
| int *weight_bias_sums_ = nullptr; | int *weight_bias_sums_ = nullptr; | ||||
| int *bias_ptr_ = nullptr; | int *bias_ptr_ = nullptr; | ||||
| int r4_; | |||||
| int c4_; | |||||
| int d16_; | |||||
| int r4_ = 0; | |||||
| int c4_ = 0; | |||||
| int d16_ = 0; | |||||
| }; | }; | ||||
| } // namespace mindspore::kernel | } // namespace mindspore::kernel | ||||
| @@ -46,8 +46,8 @@ class LayerNormInt8CPUKernel : public LiteKernel { | |||||
| private: | private: | ||||
| LayerNormParameter *param_ = nullptr; | LayerNormParameter *param_ = nullptr; | ||||
| LayerNormQuantArg quant_param_; | LayerNormQuantArg quant_param_; | ||||
| int outer_size_; | |||||
| int inner_size_; | |||||
| int outer_size_ = 0; | |||||
| int inner_size_ = 0; | |||||
| int8_t *src_ptr_ = nullptr; | int8_t *src_ptr_ = nullptr; | ||||
| int8_t *dst_ptr_ = nullptr; | int8_t *dst_ptr_ = nullptr; | ||||
| int8_t *gamma_ptr_ = nullptr; | int8_t *gamma_ptr_ = nullptr; | ||||
| @@ -39,12 +39,12 @@ class MulInt8CPUKernel : public LiteKernel { | |||||
| int DoExecute(int task_id); | int DoExecute(int task_id); | ||||
| private: | private: | ||||
| const lite::InnerContext *ctx_; | |||||
| ArithmeticParameter *tile_para; | |||||
| const lite::InnerContext *ctx_ = nullptr; | |||||
| ArithmeticParameter *tile_para = nullptr; | |||||
| MulParameter para_; | MulParameter para_; | ||||
| int thread_count_; | |||||
| int64_t elements_num_; | |||||
| int64_t count_unit_; | |||||
| int thread_count_ = 1; | |||||
| int64_t elements_num_ = 0; | |||||
| int64_t count_unit_ = 0; | |||||
| int8_t *input0_data_ = nullptr; | int8_t *input0_data_ = nullptr; | ||||
| int8_t *input1_data_ = nullptr; | int8_t *input1_data_ = nullptr; | ||||
| int8_t *output_data_ = nullptr; | int8_t *output_data_ = nullptr; | ||||
| @@ -42,9 +42,11 @@ ScaleInt8CPUKernel::~ScaleInt8CPUKernel() { | |||||
| } | } | ||||
| if (input1_data_ != nullptr && malloced_scale_) { | if (input1_data_ != nullptr && malloced_scale_) { | ||||
| free(input1_data_); | free(input1_data_); | ||||
| input1_data_ = nullptr; | |||||
| } | } | ||||
| if (input2_data_ != nullptr && malloced_offset_) { | if (input2_data_ != nullptr && malloced_offset_) { | ||||
| free(input2_data_); | free(input2_data_); | ||||
| input2_data_ = nullptr; | |||||
| } | } | ||||
| } | } | ||||
| @@ -85,6 +87,7 @@ int ScaleInt8CPUKernel::InitScaleOffset() { | |||||
| if (input2_data_ == nullptr) { | if (input2_data_ == nullptr) { | ||||
| MS_LOG(ERROR) << "malloc input2_data_ failed."; | MS_LOG(ERROR) << "malloc input2_data_ failed."; | ||||
| free(input1_data_); | free(input1_data_); | ||||
| input1_data_ = nullptr; | |||||
| return RET_ERROR; | return RET_ERROR; | ||||
| } | } | ||||
| malloced_offset_ = true; | malloced_offset_ = true; | ||||
| @@ -356,6 +359,7 @@ kernel::LiteKernel *CpuScaleInt8KernelCreator(const std::vector<lite::Tensor *> | |||||
| if (kernel == nullptr) { | if (kernel == nullptr) { | ||||
| MS_LOG(ERROR) << "New kernel fails."; | MS_LOG(ERROR) << "New kernel fails."; | ||||
| free(opParameter); | free(opParameter); | ||||
| opParameter = nullptr; | |||||
| return nullptr; | return nullptr; | ||||
| } | } | ||||
| @@ -47,13 +47,13 @@ class ScaleInt8CPUKernel : public LiteKernel { | |||||
| int8_t *input1_data_ = nullptr; | int8_t *input1_data_ = nullptr; | ||||
| int8_t *input2_data_ = nullptr; | int8_t *input2_data_ = nullptr; | ||||
| int8_t *output_data_ = nullptr; | int8_t *output_data_ = nullptr; | ||||
| const lite::InnerContext *ctx_; | |||||
| ScaleParameter *scale_param_; | |||||
| const lite::InnerContext *ctx_ = nullptr; | |||||
| ScaleParameter *scale_param_ = nullptr; | |||||
| ArithmeticParameter *tile_para = nullptr; | ArithmeticParameter *tile_para = nullptr; | ||||
| std::vector<int> second_in_shape_; | std::vector<int> second_in_shape_; | ||||
| int thread_count_; | |||||
| int64_t elements_num_; | |||||
| int64_t count_unit_; | |||||
| int thread_count_ = 1; | |||||
| int64_t elements_num_ = 0; | |||||
| int64_t count_unit_ = 0; | |||||
| bool has_bias_ = false; | bool has_bias_ = false; | ||||
| bool malloced_scale_ = false; | bool malloced_scale_ = false; | ||||
| bool malloced_offset_ = false; | bool malloced_offset_ = false; | ||||