From 2219a9c80e787986f5dd5bf4475c74df2bb06cd9 Mon Sep 17 00:00:00 2001 From: zhaozhenlong Date: Thu, 15 Oct 2020 20:11:25 +0800 Subject: [PATCH] fix issue quant dtype cast not support input fp16 opParameter free in creator --- .../lite/nnacl/fp16/quant_dtype_cast_fp16.c | 48 +++++ .../lite/nnacl/fp16/quant_dtype_cast_fp16.h | 35 ++++ mindspore/lite/src/kernel_registry.cc | 1 - .../kernel/arm/base/arg_min_max_base.cc | 1 + .../kernel/arm/base/batch_to_space_base.cc | 1 + .../runtime/kernel/arm/base/concat_base.cc | 1 + .../src/runtime/kernel/arm/base/crop_base.cc | 1 + .../kernel/arm/base/depth_to_space_base.cc | 1 + .../kernel/arm/base/fullconnection_base.cc | 1 + .../kernel/arm/base/leaky_relu_base.cc | 1 + .../runtime/kernel/arm/base/matmul_base.cc | 2 + .../lite/src/runtime/kernel/arm/base/pad.cc | 2 + .../runtime/kernel/arm/base/pooling_base.cc | 2 + .../src/runtime/kernel/arm/base/power_base.cc | 2 + .../src/runtime/kernel/arm/base/prior_box.cc | 2 + .../kernel/arm/base/quant_dtype_cast.cc | 1 + .../runtime/kernel/arm/base/reduce_base.cc | 6 + .../runtime/kernel/arm/base/reshape_base.cc | 3 + .../runtime/kernel/arm/base/resize_base.cc | 2 + .../runtime/kernel/arm/base/softmax_base.cc | 2 + .../src/runtime/kernel/arm/base/split_base.cc | 3 + .../runtime/kernel/arm/base/squeeze_base.cc | 1 + .../runtime/kernel/arm/base/strided_slice.cc | 1 + .../kernel/arm/fp16/activation_fp16.cc | 1 + .../kernel/arm/fp16/arithmetic_fp16.cc | 1 + .../kernel/arm/fp16/arithmetic_self_fp16.cc | 3 + .../runtime/kernel/arm/fp16/batchnorm_fp16.cc | 1 + .../src/runtime/kernel/arm/fp16/cast_fp16.cc | 3 + .../runtime/kernel/arm/fp16/concat_fp16.cc | 1 + .../arm/fp16/convolution_depthwise_fp16.cc | 2 + .../kernel/arm/fp16/convolution_fp16.cc | 2 + .../src/runtime/kernel/arm/fp16/crop_fp16.cc | 1 + .../arm/fp16/deconvolution_depthwise_fp16.cc | 2 + .../kernel/arm/fp16/deconvolution_fp16.cc | 2 + .../kernel/arm/fp16/fullconnection_fp16.cc | 2 + .../kernel/arm/fp16/fused_batchnorm_fp16.cc | 1 + .../runtime/kernel/arm/fp16/matmul_fp16.cc | 1 + .../src/runtime/kernel/arm/fp16/pad_fp16.cc | 1 + .../runtime/kernel/arm/fp16/pooling_fp16.cc | 1 + .../kernel/arm/fp16/quant_dtype_cast_fp16.cc | 169 ++++++++++++++++++ .../kernel/arm/fp16/quant_dtype_cast_fp16.h | 49 +++++ .../runtime/kernel/arm/fp16/reduce_fp16.cc | 2 + .../runtime/kernel/arm/fp16/reshape_fp16.cc | 1 + .../src/runtime/kernel/arm/fp16/scale_fp16.cc | 1 + .../src/runtime/kernel/arm/fp16/slice_fp16.cc | 1 + .../runtime/kernel/arm/fp16/softmax_fp16.cc | 1 + .../src/runtime/kernel/arm/fp16/split_fp16.cc | 1 + .../src/runtime/kernel/arm/fp16/stack_fp16.cc | 1 + .../runtime/kernel/arm/fp16/transpose_fp16.cc | 1 + .../src/runtime/kernel/arm/fp32/activation.cc | 1 + .../lite/src/runtime/kernel/arm/fp32/addn.cc | 2 + .../src/runtime/kernel/arm/fp32/arithmetic.cc | 1 + .../kernel/arm/fp32/arithmetic_self.cc | 1 + .../src/runtime/kernel/arm/fp32/batchnorm.cc | 1 + .../lite/src/runtime/kernel/arm/fp32/bias.cc | 1 + .../runtime/kernel/arm/fp32/broadcast_to.cc | 1 + .../lite/src/runtime/kernel/arm/fp32/cast.cc | 3 + .../kernel/arm/fp32/constant_of_shape.cc | 1 + .../runtime/kernel/arm/fp32/convolution.cc | 2 + .../kernel/arm/fp32/convolution_depthwise.cc | 2 + .../runtime/kernel/arm/fp32/deconvolution.cc | 2 + .../arm/fp32/deconvolution_depthwise.cc | 2 + .../kernel/arm/fp32/detection_post_process.cc | 1 + .../lite/src/runtime/kernel/arm/fp32/elu.cc | 10 +- .../kernel/arm/fp32/embedding_lookup.cc | 10 +- .../lite/src/runtime/kernel/arm/fp32/exp.cc | 10 +- .../src/runtime/kernel/arm/fp32/expandDims.cc | 9 +- .../lite/src/runtime/kernel/arm/fp32/fill.cc | 1 + .../src/runtime/kernel/arm/fp32/flatten.cc | 1 + .../kernel/arm/fp32/fused_batchnorm.cc | 1 + .../src/runtime/kernel/arm/fp32/gather.cc | 1 + .../src/runtime/kernel/arm/fp32/gatherNd.cc | 1 + .../src/runtime/kernel/arm/fp32/l2_norm.cc | 1 + .../kernel/arm/fp32/local_response_norm.cc | 1 + .../runtime/kernel/arm/fp32/lsh_projection.cc | 2 + .../lite/src/runtime/kernel/arm/fp32/lstm.cc | 1 + .../src/runtime/kernel/arm/fp32/nchw2nhwc.cc | 1 + .../src/runtime/kernel/arm/fp32/nhwc2nchw.cc | 1 + .../src/runtime/kernel/arm/fp32/one_hot.cc | 2 + .../lite/src/runtime/kernel/arm/fp32/prelu.cc | 1 + .../lite/src/runtime/kernel/arm/fp32/range.cc | 1 + .../lite/src/runtime/kernel/arm/fp32/rank.cc | 1 + .../src/runtime/kernel/arm/fp32/reverse.cc | 1 + .../kernel/arm/fp32/reverse_sequence.cc | 1 + .../runtime/kernel/arm/fp32/roi_pooling.cc | 3 + .../lite/src/runtime/kernel/arm/fp32/scale.cc | 1 + .../src/runtime/kernel/arm/fp32/scatter_nd.cc | 1 + .../lite/src/runtime/kernel/arm/fp32/shape.cc | 1 + .../src/runtime/kernel/arm/fp32/skip_gram.cc | 10 +- .../lite/src/runtime/kernel/arm/fp32/slice.cc | 1 + .../runtime/kernel/arm/fp32/space_to_batch.cc | 1 + .../runtime/kernel/arm/fp32/space_to_depth.cc | 1 + .../kernel/arm/fp32/sparse_to_dense.cc | 1 + .../src/runtime/kernel/arm/fp32/squeeze.cc | 1 + .../lite/src/runtime/kernel/arm/fp32/stack.cc | 1 + .../lite/src/runtime/kernel/arm/fp32/tile.cc | 10 +- .../lite/src/runtime/kernel/arm/fp32/topk.cc | 1 + .../src/runtime/kernel/arm/fp32/transpose.cc | 1 + .../src/runtime/kernel/arm/fp32/unique.cc | 1 + .../src/runtime/kernel/arm/fp32/unsqueeze.cc | 1 + .../src/runtime/kernel/arm/fp32/unstack.cc | 1 + .../lite/src/runtime/kernel/arm/fp32/where.cc | 1 + .../src/runtime/kernel/arm/fp32/zeroslike.cc | 1 + .../kernel/arm/fp32_grad/activation_grad.cc | 1 + .../kernel/arm/fp32_grad/apply_momentum.cc | 6 +- .../kernel/arm/fp32_grad/arithmetic_grad.cc | 1 + .../arm/fp32_grad/arithmetic_self_grad.cc | 1 + .../runtime/kernel/arm/fp32_grad/bias_grad.cc | 1 + .../runtime/kernel/arm/fp32_grad/bn_grad.cc | 1 + .../kernel/arm/fp32_grad/convolution.cc | 6 +- .../arm/fp32_grad/convolution_grad_filter.cc | 1 + .../arm/fp32_grad/convolution_grad_input.cc | 1 + .../fp32_grad/deconvolution_grad_filter.cc | 1 + .../runtime/kernel/arm/fp32_grad/neg_grad.cc | 1 + .../kernel/arm/fp32_grad/pooling_grad.cc | 1 + .../kernel/arm/fp32_grad/power_grad.cc | 1 + .../src/runtime/kernel/arm/fp32_grad/sgd.cc | 8 +- .../softmax_cross_entropy_with_logits.cc | 6 +- .../kernel/arm/fp32_grad/softmax_grad.cc | 1 + ...parse_softmax_cross_entropy_with_logits.cc | 6 +- .../kernel/arm/fp32_grad/tuple_getitem.cc | 6 +- .../src/runtime/kernel/arm/int8/activation.cc | 1 + .../src/runtime/kernel/arm/int8/add_int8.cc | 10 +- .../kernel/arm/int8/arithmetic_int8.cc | 1 + .../kernel/arm/int8/arithmetic_self_int8.cc | 1 + .../runtime/kernel/arm/int8/batchnorm_int8.cc | 1 + .../runtime/kernel/arm/int8/bias_add_int8.cc | 10 +- .../arm/int8/convolution_depthwise_int8.cc | 1 + .../kernel/arm/int8/convolution_int8.cc | 1 + .../arm/int8/deconvolution_depthwise_int8.cc | 1 + .../kernel/arm/int8/deconvolution_int8.cc | 1 + .../src/runtime/kernel/arm/int8/div_int8.cc | 10 +- .../runtime/kernel/arm/int8/gatherNd_int8.cc | 1 + .../runtime/kernel/arm/int8/gather_int8.cc | 1 + .../src/runtime/kernel/arm/int8/mul_int8.cc | 1 + .../src/runtime/kernel/arm/int8/scale_int8.cc | 1 + .../src/runtime/kernel/arm/int8/slice_int8.cc | 1 + .../kernel/arm/int8/space_to_batch_int8.cc | 1 + .../src/runtime/kernel/arm/int8/sub_int8.cc | 10 +- .../src/runtime/kernel/arm/int8/topk_int8.cc | 1 + .../runtime/kernel/arm/int8/unsqueeze_int8.cc | 1 + .../kernel/arm/string/extract_feature.cc | 1 + .../kernel/arm/string/hashtable_lookup.cc | 1 + .../runtime/kernel/arm/string/normalize.cc | 1 + .../src/runtime/kernel/arm/string/predict.cc | 1 + .../kernel/opencl/kernel/activation.cc | 2 + .../kernel/opencl/kernel/arithmetic.cc | 1 + .../kernel/opencl/kernel/arithmetic_self.cc | 1 + .../kernel/opencl/kernel/batch_to_space_nd.cc | 1 + .../runtime/kernel/opencl/kernel/batchnorm.cc | 1 + .../runtime/kernel/opencl/kernel/biasadd.cc | 3 + .../src/runtime/kernel/opencl/kernel/cast.cc | 1 + .../runtime/kernel/opencl/kernel/concat.cc | 1 + .../kernel/opencl/kernel/conv2d_transpose.cc | 1 + .../kernel/opencl/kernel/convolution.cc | 1 + .../kernel/opencl/kernel/depthwise_conv2d.cc | 1 + .../kernel/opencl/kernel/fullconnection.cc | 1 + .../runtime/kernel/opencl/kernel/gather.cc | 1 + .../runtime/kernel/opencl/kernel/matmul.cc | 1 + .../src/runtime/kernel/opencl/kernel/pad.cc | 1 + .../runtime/kernel/opencl/kernel/pooling2d.cc | 1 + .../src/runtime/kernel/opencl/kernel/prelu.cc | 2 + .../runtime/kernel/opencl/kernel/reduce.cc | 1 + .../runtime/kernel/opencl/kernel/reshape.cc | 1 + .../runtime/kernel/opencl/kernel/resize.cc | 1 + .../src/runtime/kernel/opencl/kernel/scale.cc | 1 + .../src/runtime/kernel/opencl/kernel/slice.cc | 1 + .../runtime/kernel/opencl/kernel/softmax.cc | 1 + .../kernel/opencl/kernel/space_to_batch_nd.cc | 1 + .../runtime/kernel/opencl/kernel/to_format.cc | 1 + .../runtime/kernel/opencl/kernel/transpose.cc | 1 + 171 files changed, 600 insertions(+), 30 deletions(-) create mode 100644 mindspore/lite/nnacl/fp16/quant_dtype_cast_fp16.c create mode 100644 mindspore/lite/nnacl/fp16/quant_dtype_cast_fp16.h create mode 100644 mindspore/lite/src/runtime/kernel/arm/fp16/quant_dtype_cast_fp16.cc create mode 100644 mindspore/lite/src/runtime/kernel/arm/fp16/quant_dtype_cast_fp16.h diff --git a/mindspore/lite/nnacl/fp16/quant_dtype_cast_fp16.c b/mindspore/lite/nnacl/fp16/quant_dtype_cast_fp16.c new file mode 100644 index 0000000000..9abc836424 --- /dev/null +++ b/mindspore/lite/nnacl/fp16/quant_dtype_cast_fp16.c @@ -0,0 +1,48 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "nnacl/fp16/quant_dtype_cast_fp16.h" +#include "nnacl/errorcode.h" + +int DoDequantizeInt8ToFp16(int8_t *quant_values, float16_t *real_values, float scale, int32_t zp, int size) { + if (quant_values == NULL || real_values == NULL) { + return NNACL_PARAM_INVALID; + } + + for (int i = 0; i < size; ++i) { + real_values[i] = (quant_values[i] - zp) * scale; + } + return NNACL_OK; +} + +int DoQuantizeToInt8FromFp16(float16_t *real_values, int8_t *quant_values, float scale, int32_t zp, int size) { + if (quant_values == NULL || real_values == NULL) { + return NNACL_PARAM_INVALID; + } + + for (int i = 0; i < size; ++i) { + float temp = round((float)real_values[i] / scale + zp); + if (temp > 127) { + quant_values[i] = 127; + } else if (temp < -128) { + quant_values[i] = -128; + } else { + quant_values[i] = (int8_t)temp; + } + } + return NNACL_OK; +} diff --git a/mindspore/lite/nnacl/fp16/quant_dtype_cast_fp16.h b/mindspore/lite/nnacl/fp16/quant_dtype_cast_fp16.h new file mode 100644 index 0000000000..6442355ba6 --- /dev/null +++ b/mindspore/lite/nnacl/fp16/quant_dtype_cast_fp16.h @@ -0,0 +1,35 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef MINDSPORE_LITE_NNACL_FP16_QUANTDTYPECAST_FP16_H_ +#define MINDSPORE_LITE_NNACL_FP16_QUANTDTYPECAST_FP16_H_ + +#include "nnacl/op_base.h" + +#ifdef ENABLE_NEON +#include +#endif + +#ifdef __cplusplus +extern "C" { +#endif +int DoDequantizeInt8ToFp16(int8_t *quant_values, float16_t *real_values, float scale, int32_t zp, int size); +int DoQuantizeToInt8FromFp16(float16_t *real_values, int8_t *quant_values, float scale, int32_t zp, int size); +#ifdef __cplusplus +} +#endif + +#endif // MINDSPORE_LITE_NNACL_INT8_QUANTDTYPECAST_H_ diff --git a/mindspore/lite/src/kernel_registry.cc b/mindspore/lite/src/kernel_registry.cc index bda5dbedd5..44fa6c35d7 100644 --- a/mindspore/lite/src/kernel_registry.cc +++ b/mindspore/lite/src/kernel_registry.cc @@ -120,7 +120,6 @@ kernel::LiteKernel *KernelRegistry::GetKernel(const std::vector &in_te return kernel; } } - free(parameter); return nullptr; } diff --git a/mindspore/lite/src/runtime/kernel/arm/base/arg_min_max_base.cc b/mindspore/lite/src/runtime/kernel/arm/base/arg_min_max_base.cc index 64f96eb1c7..7ecfe950a7 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/arg_min_max_base.cc +++ b/mindspore/lite/src/runtime/kernel/arm/base/arg_min_max_base.cc @@ -124,6 +124,7 @@ kernel::LiteKernel *CpuArgMinMaxFp32KernelCreator(const std::vectorInit(); diff --git a/mindspore/lite/src/runtime/kernel/arm/base/batch_to_space_base.cc b/mindspore/lite/src/runtime/kernel/arm/base/batch_to_space_base.cc index 979c7dc3a3..ff04a3947b 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/batch_to_space_base.cc +++ b/mindspore/lite/src/runtime/kernel/arm/base/batch_to_space_base.cc @@ -90,6 +90,7 @@ kernel::LiteKernel *CpuBatchToSpaceFp32KernelCreator(const std::vector auto *kernel = new (std::nothrow) ConcatCPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "new ConcatCPUKernel fail!"; + free(opParameter); return nullptr; } auto ret = kernel->Init(); diff --git a/mindspore/lite/src/runtime/kernel/arm/base/crop_base.cc b/mindspore/lite/src/runtime/kernel/arm/base/crop_base.cc index 7274fade1a..289f2d4d67 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/crop_base.cc +++ b/mindspore/lite/src/runtime/kernel/arm/base/crop_base.cc @@ -142,6 +142,7 @@ kernel::LiteKernel *CpuCropFp32KernelCreator(const std::vector & auto *kernel = new (std::nothrow) CropCPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "new CropCPUKernel fail!"; + free(opParameter); return nullptr; } auto ret = kernel->Init(); diff --git a/mindspore/lite/src/runtime/kernel/arm/base/depth_to_space_base.cc b/mindspore/lite/src/runtime/kernel/arm/base/depth_to_space_base.cc index 78805a96fc..b8fd69e2e7 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/depth_to_space_base.cc +++ b/mindspore/lite/src/runtime/kernel/arm/base/depth_to_space_base.cc @@ -100,6 +100,7 @@ kernel::LiteKernel *CpuDepthToSpaceFp32KernelCreator(const std::vectorFreeData(); weight_tensor->SetData(restore_data); } + free(opParameter); return nullptr; } auto ret = kernel->Init(); diff --git a/mindspore/lite/src/runtime/kernel/arm/base/leaky_relu_base.cc b/mindspore/lite/src/runtime/kernel/arm/base/leaky_relu_base.cc index 84477245f4..c8dc43ec05 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/leaky_relu_base.cc +++ b/mindspore/lite/src/runtime/kernel/arm/base/leaky_relu_base.cc @@ -41,6 +41,7 @@ kernel::LiteKernel *CpuLeakyReluInt8KernelCreator(const std::vectorInit(); diff --git a/mindspore/lite/src/runtime/kernel/arm/base/matmul_base.cc b/mindspore/lite/src/runtime/kernel/arm/base/matmul_base.cc index dbcbecd3e4..e3ea4ca1a4 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/matmul_base.cc +++ b/mindspore/lite/src/runtime/kernel/arm/base/matmul_base.cc @@ -40,6 +40,7 @@ kernel::LiteKernel *CpuMatmulKernelCreator(const std::vector &in auto *dequant_weight = kernel::LiteKernelUtil::DequantWeight(weight_tensor); if (dequant_weight == nullptr) { MS_LOG(ERROR) << "dequant data is nullptr."; + free(opParameter); return nullptr; } weight_tensor->SetData(dequant_weight); @@ -59,6 +60,7 @@ kernel::LiteKernel *CpuMatmulKernelCreator(const std::vector &in weight_tensor->FreeData(); weight_tensor->SetData(restore_data); } + free(opParameter); return nullptr; } auto ret = kernel->Init(); diff --git a/mindspore/lite/src/runtime/kernel/arm/base/pad.cc b/mindspore/lite/src/runtime/kernel/arm/base/pad.cc index aeffa3126b..4a7de87661 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/pad.cc +++ b/mindspore/lite/src/runtime/kernel/arm/base/pad.cc @@ -37,6 +37,7 @@ kernel::LiteKernel *CpuPadInt8KernelCreator(const std::vector &i auto *kernel = new (std::nothrow) PadInt8CPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "new PadCPUKernel failed."; + free(opParameter); return nullptr; } auto ret = kernel->Init(); @@ -58,6 +59,7 @@ kernel::LiteKernel *CpuPadFp32KernelCreator(const std::vector &i auto *kernel = new (std::nothrow) PadCPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "new PadCPUKernel failed."; + free(opParameter); return nullptr; } auto ret = kernel->Init(); diff --git a/mindspore/lite/src/runtime/kernel/arm/base/pooling_base.cc b/mindspore/lite/src/runtime/kernel/arm/base/pooling_base.cc index 8e520139a6..83d426e81b 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/pooling_base.cc +++ b/mindspore/lite/src/runtime/kernel/arm/base/pooling_base.cc @@ -115,6 +115,7 @@ kernel::LiteKernel *CpuPoolingInt8KernelCreator(const std::vectorInit(); @@ -139,6 +140,7 @@ kernel::LiteKernel *CpuPoolingFp32KernelCreator(const std::vectorInit(); diff --git a/mindspore/lite/src/runtime/kernel/arm/base/power_base.cc b/mindspore/lite/src/runtime/kernel/arm/base/power_base.cc index e1949b8b53..4a0a0792e3 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/power_base.cc +++ b/mindspore/lite/src/runtime/kernel/arm/base/power_base.cc @@ -43,6 +43,7 @@ kernel::LiteKernel *CpuPowerInt8KernelCreator(const std::vector auto *kernel = new (std::nothrow) PowerInt8CPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "new PowerInt8CPUKernel fail!"; + free(opParameter); return nullptr; } auto ret = kernel->Init(); @@ -64,6 +65,7 @@ kernel::LiteKernel *CpuPowerFp32KernelCreator(const std::vector PowerCPUKernel *kernel = new (std::nothrow) PowerCPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "new PowerCPUKernel fail!"; + free(opParameter); return nullptr; } auto ret = kernel->Init(); diff --git a/mindspore/lite/src/runtime/kernel/arm/base/prior_box.cc b/mindspore/lite/src/runtime/kernel/arm/base/prior_box.cc index f4052e9440..a7e97d8e6b 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/prior_box.cc +++ b/mindspore/lite/src/runtime/kernel/arm/base/prior_box.cc @@ -186,11 +186,13 @@ kernel::LiteKernel *CpuPriorBoxKernelCreator(const std::vector & } if (desc.type != schema::PrimitiveType_PriorBox) { MS_LOG(ERROR) << "PriorBox invalid desc type " << desc.type; + free(op_parameter); return nullptr; } auto *kernel = new (std::nothrow) PriorBoxCPUKernel(op_parameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "new PriorBoxCPUKernel fail!"; + free(op_parameter); return nullptr; } auto ret = kernel->Init(); diff --git a/mindspore/lite/src/runtime/kernel/arm/base/quant_dtype_cast.cc b/mindspore/lite/src/runtime/kernel/arm/base/quant_dtype_cast.cc index 97b8cc2597..b9b809bc41 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/quant_dtype_cast.cc +++ b/mindspore/lite/src/runtime/kernel/arm/base/quant_dtype_cast.cc @@ -177,6 +177,7 @@ kernel::LiteKernel *CpuQuantDTypeCastFp32KernelCreator(const std::vectorInit(); 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 ecf3bf6b0d..05bff4db17 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/reduce_base.cc +++ b/mindspore/lite/src/runtime/kernel/arm/base/reduce_base.cc @@ -181,11 +181,13 @@ kernel::LiteKernel *CpuReduceFp32KernelCreator(const std::vector } if (desc.type != schema::PrimitiveType_Reduce) { MS_LOG(ERROR) << "Reduce op desc.type should be PrimitiveType_Reduce, got " << desc.type; + free(opParameter); return nullptr; } auto *kernel = new (std::nothrow) ReduceCPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "Reduce new ReduceCPUKernel failed."; + free(opParameter); return nullptr; } auto ret = kernel->Init(); @@ -210,11 +212,13 @@ kernel::LiteKernel *CpuMeanFp32KernelCreator(const std::vector & } if (desc.type != schema::PrimitiveType_Mean) { MS_LOG(ERROR) << "Reduce op desc.type should be PrimitiveType_Mean, got " << desc.type; + free(opParameter); return nullptr; } auto *kernel = new (std::nothrow) ReduceCPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "Reduce new ReduceCPUKernel failed."; + free(opParameter); return nullptr; } auto ret = kernel->Init(); @@ -239,11 +243,13 @@ kernel::LiteKernel *CpuReduceInt8KernelCreator(const std::vector } if (desc.type != schema::PrimitiveType_Reduce) { MS_LOG(ERROR) << "Reduce op desc.type should be PrimitiveType_Reduce, got " << desc.type; + free(opParameter); return nullptr; } auto *kernel = new (std::nothrow) ReduceInt8CPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "Reduce new ReduceCPUKernel failed."; + free(opParameter); return nullptr; } auto ret = kernel->Init(); diff --git a/mindspore/lite/src/runtime/kernel/arm/base/reshape_base.cc b/mindspore/lite/src/runtime/kernel/arm/base/reshape_base.cc index 01448f9331..a6e5feb310 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/reshape_base.cc +++ b/mindspore/lite/src/runtime/kernel/arm/base/reshape_base.cc @@ -42,6 +42,7 @@ kernel::LiteKernel *CpuReshapeInt8KernelCreator(const std::vectorInit(); @@ -66,6 +67,7 @@ kernel::LiteKernel *CpuReshapeInt32KernelCreator(const std::vectorInit(); @@ -90,6 +92,7 @@ kernel::LiteKernel *CpuReshapeFp32KernelCreator(const std::vectorInit(); diff --git a/mindspore/lite/src/runtime/kernel/arm/base/resize_base.cc b/mindspore/lite/src/runtime/kernel/arm/base/resize_base.cc index 8e0b8c0f45..954d7897f2 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/resize_base.cc +++ b/mindspore/lite/src/runtime/kernel/arm/base/resize_base.cc @@ -140,6 +140,7 @@ kernel::LiteKernel *CpuResizeFp32KernelCreator(const std::vector auto *kernel = new (std::nothrow) ResizeCPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "new ResizeCPUKernel fail!"; + free(opParameter); return nullptr; } auto ret = kernel->Init(); @@ -165,6 +166,7 @@ kernel::LiteKernel *CpuResizeInt8KernelCreator(const std::vector auto *kernel = new (std::nothrow) ResizeInt8CPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "new ResizeCPUKernel fail!"; + free(opParameter); return nullptr; } auto ret = kernel->Init(); diff --git a/mindspore/lite/src/runtime/kernel/arm/base/softmax_base.cc b/mindspore/lite/src/runtime/kernel/arm/base/softmax_base.cc index 465f1f7b65..edf8e4a9b0 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/softmax_base.cc +++ b/mindspore/lite/src/runtime/kernel/arm/base/softmax_base.cc @@ -68,6 +68,7 @@ kernel::LiteKernel *CpuSoftmaxInt8KernelCreator(const std::vectorInit(); @@ -92,6 +93,7 @@ kernel::LiteKernel *CpuSoftmaxFp32KernelCreator(const std::vectorInit(); diff --git a/mindspore/lite/src/runtime/kernel/arm/base/split_base.cc b/mindspore/lite/src/runtime/kernel/arm/base/split_base.cc index 89d9558bc8..b1be331d5f 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/split_base.cc +++ b/mindspore/lite/src/runtime/kernel/arm/base/split_base.cc @@ -84,6 +84,7 @@ kernel::LiteKernel *CpuSplitInt8KernelCreator(const std::vector auto *kernel = new (std::nothrow) SplitInt8CPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "new SplitCPUKernel fail!"; + free(opParameter); return nullptr; } auto ret = kernel->Init(); @@ -108,6 +109,7 @@ kernel::LiteKernel *CpuSplitInt32KernelCreator(const std::vector auto *kernel = new (std::nothrow) SplitCPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "new SplitCPUKernel fail!"; + free(opParameter); return nullptr; } auto ret = kernel->Init(); @@ -132,6 +134,7 @@ kernel::LiteKernel *CpuSplitFp32KernelCreator(const std::vector auto *kernel = new (std::nothrow) SplitCPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "new SplitCPUKernel fail!"; + free(opParameter); return nullptr; } auto ret = kernel->Init(); diff --git a/mindspore/lite/src/runtime/kernel/arm/base/squeeze_base.cc b/mindspore/lite/src/runtime/kernel/arm/base/squeeze_base.cc index c29efde98e..d743aae570 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/squeeze_base.cc +++ b/mindspore/lite/src/runtime/kernel/arm/base/squeeze_base.cc @@ -41,6 +41,7 @@ kernel::LiteKernel *CpuSqueezeInt8KernelCreator(const std::vectorInit(); diff --git a/mindspore/lite/src/runtime/kernel/arm/base/strided_slice.cc b/mindspore/lite/src/runtime/kernel/arm/base/strided_slice.cc index c96dbc9447..f7193ca268 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/strided_slice.cc +++ b/mindspore/lite/src/runtime/kernel/arm/base/strided_slice.cc @@ -128,6 +128,7 @@ kernel::LiteKernel *CpuStridedSliceKernelCreator(const std::vectorInit(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/arithmetic_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/arithmetic_fp16.cc index 4cb0c0c36d..aa8cd3b656 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/arithmetic_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/arithmetic_fp16.cc @@ -241,6 +241,7 @@ kernel::LiteKernel *CpuArithmeticFp16KernelCreator(const std::vectorname_; + free(parameter); return nullptr; } auto ret = kernel->Init(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/arithmetic_self_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/arithmetic_self_fp16.cc index 6140e18b04..f6de91b42c 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/arithmetic_self_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/arithmetic_self_fp16.cc @@ -115,6 +115,9 @@ kernel::LiteKernel *CpuArithmeticSelfFp16KernelCreator(const std::vectorInit(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/batchnorm_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/batchnorm_fp16.cc index b0b59ac223..9b91cf3794 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/batchnorm_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/batchnorm_fp16.cc @@ -97,6 +97,7 @@ kernel::LiteKernel *CpuBatchnormFp16KernelCreator(const std::vectorInit(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/cast_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/cast_fp16.cc index 56edbaa340..0280f75141 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/cast_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/cast_fp16.cc @@ -104,15 +104,18 @@ kernel::LiteKernel *CpuCastFp16KernelCreator(const std::vector & } if (ctx == nullptr) { MS_LOG(ERROR) << "Input context is nullptr!"; + free(opParameter); return nullptr; } if (ctx->thread_num_ == 0) { MS_LOG(ERROR) << "context thread num is 0!"; + free(opParameter); return nullptr; } auto *kernel = new (std::nothrow) CastFp16CPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "new CastFp16CPUKernel fail!"; + free(opParameter); return nullptr; } auto ret = kernel->Init(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/concat_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/concat_fp16.cc index 70eb457562..5fa547e828 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/concat_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/concat_fp16.cc @@ -151,6 +151,7 @@ kernel::LiteKernel *CpuConcatFp16KernelCreator(const std::vector kernel::LiteKernel *kernel = new (std::nothrow) ConcatFp16CPUKernel(parameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "new ConcatCPUKernel fail!"; + free(parameter); return nullptr; } auto ret = kernel->Init(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_depthwise_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_depthwise_fp16.cc index cb8273fa8b..c96efcc5f3 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_depthwise_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_depthwise_fp16.cc @@ -150,6 +150,7 @@ kernel::LiteKernel *CpuConvDwFp16KernelCreator(const std::vector auto *dequant_weight = kernel::LiteKernelUtil::DequantWeight(weight_tensor); if (dequant_weight == nullptr) { MS_LOG(ERROR) << "dequant data is nullptr."; + free(opParameter); return nullptr; } weight_tensor->set_data_type(kNumberTypeFloat32); @@ -171,6 +172,7 @@ kernel::LiteKernel *CpuConvDwFp16KernelCreator(const std::vector weight_tensor->set_data_type(kNumberTypeInt8); weight_tensor->SetData(restore_data); } + free(opParameter); return nullptr; } auto ret = kernel->Init(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_fp16.cc index fafd1caf1e..84bfe991e3 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_fp16.cc @@ -188,6 +188,7 @@ kernel::LiteKernel *CpuConvFp16KernelCreator(const std::vector & auto *dequant_weight = kernel::LiteKernelUtil::DequantWeight(weight_tensor); if (dequant_weight == nullptr) { MS_LOG(ERROR) << "dequant data is nullptr."; + free(opParameter); return nullptr; } weight_tensor->set_data_type(kNumberTypeFloat32); @@ -226,6 +227,7 @@ kernel::LiteKernel *CpuConvFp16KernelCreator(const std::vector & weight_tensor->set_data_type(kNumberTypeInt8); weight_tensor->SetData(restore_data); } + free(opParameter); return nullptr; } auto ret = kernel->Init(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/crop_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/crop_fp16.cc index 9f722ddbe0..64cb351350 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/crop_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/crop_fp16.cc @@ -115,6 +115,7 @@ kernel::LiteKernel *CpuCropFp16KernelCreator(const std::vector & auto *kernel = new (std::nothrow) CropFp16CPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "new CropFp16CPUKernel fail!"; + free(opParameter); return nullptr; } auto ret = kernel->Init(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/deconvolution_depthwise_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/deconvolution_depthwise_fp16.cc index ceae86d0b0..fdf64b6b4a 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/deconvolution_depthwise_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/deconvolution_depthwise_fp16.cc @@ -213,6 +213,7 @@ kernel::LiteKernel *CpuDeconvDwFp16KernelCreator(const std::vectorset_data_type(kNumberTypeFloat32); @@ -227,6 +228,7 @@ kernel::LiteKernel *CpuDeconvDwFp16KernelCreator(const std::vectorset_data_type(kNumberTypeInt8); weight_tensor->SetData(restore_data); } + free(opParameter); return nullptr; } auto ret = kernel->Init(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/deconvolution_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/deconvolution_fp16.cc index 81577e245d..963f929f91 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/deconvolution_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/deconvolution_fp16.cc @@ -220,6 +220,7 @@ kernel::LiteKernel *CpuDeConvFp16KernelCreator(const std::vector auto *dequant_weight = kernel::LiteKernelUtil::DequantWeight(weight_tensor); if (dequant_weight == nullptr) { MS_LOG(ERROR) << "dequant data is nullptr."; + free(opParameter); return nullptr; } weight_tensor->set_data_type(kNumberTypeFloat32); @@ -234,6 +235,7 @@ kernel::LiteKernel *CpuDeConvFp16KernelCreator(const std::vector weight_tensor->set_data_type(kNumberTypeInt8); weight_tensor->SetData(restore_data); } + free(opParameter); return nullptr; } auto ret = kernel->Init(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/fullconnection_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/fullconnection_fp16.cc index 0a53a76faf..75e8b13904 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/fullconnection_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/fullconnection_fp16.cc @@ -196,6 +196,7 @@ kernel::LiteKernel *CpuFullConnectionFp16KernelCreator(const std::vectorset_data_type(kNumberTypeFloat32); @@ -209,6 +210,7 @@ kernel::LiteKernel *CpuFullConnectionFp16KernelCreator(const std::vectorset_data_type(kNumberTypeInt8); weight_tensor->SetData(restore_data); } + free(opParameter); return nullptr; } auto ret = kernel->Init(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/fused_batchnorm_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/fused_batchnorm_fp16.cc index 7cad6bd4f7..a977e1fe89 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/fused_batchnorm_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/fused_batchnorm_fp16.cc @@ -86,6 +86,7 @@ kernel::LiteKernel *CpuFusedBatchnormFp16KernelCreator(const std::vectorInit(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/matmul_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/matmul_fp16.cc index c2a5a0d235..01527376f1 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/matmul_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/matmul_fp16.cc @@ -272,6 +272,7 @@ kernel::LiteKernel *CpuMatmulFp16KernelCreator(const std::vector weight_tensor->set_data_type(kNumberTypeInt8); weight_tensor->SetData(restore_data); } + free(opParameter); return nullptr; } auto ret = kernel->Init(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/pad_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/pad_fp16.cc index 32aeb8cb21..68135d8ccc 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/pad_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/pad_fp16.cc @@ -87,6 +87,7 @@ kernel::LiteKernel *CpuPadFp16KernelCreator(const std::vector &i auto *kernel = new (std::nothrow) PadFp16CPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "new PadFp16CPUKernel fail!"; + free(opParameter); return nullptr; } auto ret = kernel->Init(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/pooling_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/pooling_fp16.cc index 7834f8f4d4..79d436f507 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/pooling_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/pooling_fp16.cc @@ -130,6 +130,7 @@ kernel::LiteKernel *CpuPoolingFp16KernelCreator(const std::vectorInit(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/quant_dtype_cast_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/quant_dtype_cast_fp16.cc new file mode 100644 index 0000000000..0df73c6ffa --- /dev/null +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/quant_dtype_cast_fp16.cc @@ -0,0 +1,169 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "src/runtime/kernel/arm/fp16/quant_dtype_cast_fp16.h" +#include +#include "nnacl/int8/quant_dtype_cast.h" +#include "nnacl/fp16/quant_dtype_cast_fp16.h" +#include "src/runtime/runtime_api.h" +#include "src/kernel_registry.h" +#include "schema/model_generated.h" +#include "include/errorcode.h" + +using mindspore::kernel::KERNEL_ARCH::kCPU; +using mindspore::lite::KernelRegistrar; +using mindspore::lite::RET_ERROR; +using mindspore::lite::RET_OK; +using mindspore::lite::RET_PARAM_INVALID; +using mindspore::schema::PrimitiveType_QuantDTypeCast; + +namespace mindspore::kernel { +int QuantDTypeCastFp16CPUKernel::Init() { + if (in_tensors_.size() != 1) { + MS_LOG(ERROR) << "inputs number should be 1, but " << in_tensors_.size() << " is given."; + return RET_PARAM_INVALID; + } + if (out_tensors_.size() != 1) { + MS_LOG(ERROR) << "outputs number should be 1, but " << out_tensors_.size() << " is given."; + return RET_PARAM_INVALID; + } + auto in_tensor = in_tensors_.front(); + auto out_tensor = out_tensors_.front(); + auto param = reinterpret_cast(op_parameter_); + if (param->dstT == kNumberTypeInt8) { + if (in_tensor->data_type() != kNumberTypeFloat16 || out_tensor->data_type() != kNumberTypeInt8) { + MS_LOG(ERROR) << "param data type and tensor data type do not match."; + return RET_ERROR; + } + inverse_ = false; + } else if (param->srcT == kNumberTypeInt8) { + if (in_tensor->data_type() != kNumberTypeInt8 || out_tensor->data_type() != kNumberTypeFloat16) { + MS_LOG(ERROR) << "param data type and tensor data type do not match."; + return RET_ERROR; + } + inverse_ = true; + } else { + MS_LOG(ERROR) << "param data type not supported:" + << " src: " << param->srcT << " dst: " << param->dstT; + return RET_PARAM_INVALID; + } + + if (!InferShapeDone()) { + return RET_OK; + } + return ReSize(); +} + +int QuantDTypeCastFp16CPUKernel::ReSize() { + auto in_tensor = in_tensors_.front(); + num_unit_ = static_cast(in_tensor->ElementsNum()); + thread_n_num_ = MSMIN(thread_num_, num_unit_); + thread_n_stride_ = UP_DIV(num_unit_, thread_n_num_); + return RET_OK; +} + +int QuantDTypeCastFp16CPUKernel::QuantDTypeCast(int task_id) { + int num_unit_thread = MSMIN(thread_n_stride_, num_unit_ - task_id * thread_n_stride_); + if (num_unit_thread <= 0) { + return RET_OK; + } + int thread_offset = task_id * thread_n_stride_; + if (in_tensors_.front()->GetQuantParams().empty() && out_tensors_.front()->GetQuantParams().empty()) { + MS_LOG(ERROR) << "QuantDTypeCast need quantization parameters which is not found."; + return RET_ERROR; + } + auto quant_arg = !out_tensors_.front()->GetQuantParams().empty() ? out_tensors_.front()->GetQuantParams().front() + : in_tensors_.front()->GetQuantParams().front(); + int ret; + if (inverse_) { + ret = DoDequantizeInt8ToFp16(int8_ptr_ + thread_offset, float16_ptr_ + thread_offset, quant_arg.scale, + quant_arg.zeroPoint, num_unit_thread); + } else { + ret = DoQuantizeToInt8FromFp16(float16_ptr_ + thread_offset, int8_ptr_ + thread_offset, quant_arg.scale, + quant_arg.zeroPoint, num_unit_thread); + } + + if (ret != RET_OK) { + MS_LOG(ERROR) << "QuantDTypeCastFp16 error task_id[" << task_id << "] error_code[" << ret << "]"; + return RET_ERROR; + } + return RET_OK; +} + +int QuantDTypeCastRun(void *cdata, int task_id) { + auto g_kernel = reinterpret_cast(cdata); + auto ret = g_kernel->QuantDTypeCast(task_id); + if (ret != RET_OK) { + MS_LOG(ERROR) << "QuantDTypeCastRun error task_id[" << task_id << "] error_code[" << ret << "]"; + return RET_ERROR; + } + return RET_OK; +} + +int QuantDTypeCastFp16CPUKernel::Run() { + auto prepare_ret = Prepare(); + if (prepare_ret != RET_OK) { + MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret; + return prepare_ret; + } + + if (in_tensors_[0]->data_type() == TypeId::kNumberTypeInt8 && + out_tensors_[0]->data_type() == TypeId::kNumberTypeFloat16) { + int8_ptr_ = reinterpret_cast(in_tensors_[0]->data_c()); + float16_ptr_ = reinterpret_cast(out_tensors_[0]->data_c()); + } else if (in_tensors_[0]->data_type() == TypeId::kNumberTypeFloat16 && + out_tensors_[0]->data_type() == TypeId::kNumberTypeInt8) { + float16_ptr_ = reinterpret_cast(in_tensors_[0]->data_c()); + int8_ptr_ = reinterpret_cast(out_tensors_[0]->data_c()); + } else { + MS_LOG(ERROR) << "QuantDTypeCastFp16 not support input or output type"; + return RET_ERROR; + } + + auto ret = ParallelLaunch(this->context_->thread_pool_, QuantDTypeCastRun, this, thread_n_num_); + if (ret != RET_OK) { + MS_LOG(ERROR) << "Scale error error_code[" << ret << "]"; + return RET_ERROR; + } + + return RET_OK; +} + +kernel::LiteKernel *CpuQuantDTypeCastFp16KernelCreator(const std::vector &inputs, + const std::vector &outputs, + OpParameter *opParameter, const lite::InnerContext *ctx, + const kernel::KernelKey &desc, + const mindspore::lite::PrimitiveC *primitive) { + if (opParameter == nullptr) { + MS_LOG(ERROR) << "Input opParameter is nullptr!"; + return nullptr; + } + auto *kernel = new (std::nothrow) QuantDTypeCastFp16CPUKernel(opParameter, inputs, outputs, ctx, primitive); + if (kernel == nullptr) { + MS_LOG(ERROR) << "new QuantDTypeCastFp16CPUKernel fail!"; + free(opParameter); + return nullptr; + } + auto ret = kernel->Init(); + if (ret != RET_OK) { + MS_LOG(ERROR) << "Init kernel failed! name: " << opParameter->name_ << ", type: " + << schema::EnumNamePrimitiveType(static_cast(opParameter->type_)); + delete kernel; + return nullptr; + } + return kernel; +} +REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_QuantDTypeCast, CpuQuantDTypeCastFp16KernelCreator) +} // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/quant_dtype_cast_fp16.h b/mindspore/lite/src/runtime/kernel/arm/fp16/quant_dtype_cast_fp16.h new file mode 100644 index 0000000000..0c7dc353b5 --- /dev/null +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/quant_dtype_cast_fp16.h @@ -0,0 +1,49 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_BASE_QUANTDTYPECAST_FP16_H_ +#define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_BASE_QUANTDTYPECAST_FP16_H_ + +#include +#include +#include "src/lite_kernel.h" + +namespace mindspore::kernel { +class QuantDTypeCastFp16CPUKernel : public LiteKernel { + public: + QuantDTypeCastFp16CPUKernel(OpParameter *parameter, const std::vector &inputs, + const std::vector &outputs, const lite::InnerContext *ctx, + const mindspore::lite::PrimitiveC *primitive) + : LiteKernel(parameter, inputs, outputs, ctx, primitive), thread_num_(ctx->thread_num_) {} + ~QuantDTypeCastFp16CPUKernel() override = default; + + int Init() override; + int ReSize() override; + int Run() override; + int QuantDTypeCast(int task_id); + + private: + int thread_num_; + int thread_n_num_; + int thread_n_stride_; + int num_unit_; + int8_t *int8_ptr_; + float16_t *float16_ptr_; + bool inverse_; +}; +} // namespace mindspore::kernel + +#endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_BASE_QUANTDTYPECAST_FP16_H_ diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/reduce_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/reduce_fp16.cc index e9c7730dd7..6e36b6e470 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/reduce_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/reduce_fp16.cc @@ -205,11 +205,13 @@ kernel::LiteKernel *CpuMeanFp16KernelCreator(const std::vector & } if (desc.type != schema::PrimitiveType_Mean) { MS_LOG(ERROR) << "Reduce op desc.type should be PrimitiveType_Mean, got " << desc.type; + free(opParameter); return nullptr; } auto *kernel = new (std::nothrow) ReduceFp16CPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "Reduce new ReduceCPUKernel failed."; + free(opParameter); return nullptr; } auto ret = kernel->Init(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/reshape_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/reshape_fp16.cc index 5309201bd9..c1c89626f6 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/reshape_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/reshape_fp16.cc @@ -86,6 +86,7 @@ kernel::LiteKernel *CpuReshapeFp16KernelCreator(const std::vectorInit(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/scale_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/scale_fp16.cc index 0c26ae469b..0caf6a5e59 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/scale_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/scale_fp16.cc @@ -198,6 +198,7 @@ kernel::LiteKernel *CpuScaleFp16KernelCreator(const std::vector auto *kernel = new (std::nothrow) ScaleFp16CPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "New kernel fails."; + free(opParameter); return nullptr; } auto ret = kernel->Init(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/slice_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/slice_fp16.cc index e482e33ded..432505e4a1 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/slice_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/slice_fp16.cc @@ -75,6 +75,7 @@ kernel::LiteKernel *CpuSliceFp16KernelCreator(const std::vector auto *kernel = new (std::nothrow) SliceFp16CPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "new SliceFp16CPUKernel fail!"; + free(opParameter); return nullptr; } auto ret = kernel->Init(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/softmax_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/softmax_fp16.cc index 48715273e6..7a7c7914d6 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/softmax_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/softmax_fp16.cc @@ -136,6 +136,7 @@ kernel::LiteKernel *CpuSoftmaxFp16KernelCreator(const std::vectorInit(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/split_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/split_fp16.cc index 112abd516c..f50b8a2d24 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/split_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/split_fp16.cc @@ -133,6 +133,7 @@ kernel::LiteKernel *CpuSplitFp16KernelCreator(const std::vector auto *kernel = new (std::nothrow) SplitFp16CPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "new SplitFp16CPUKernel fail!"; + free(opParameter); return nullptr; } auto ret = kernel->Init(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/stack_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/stack_fp16.cc index 6f0684155b..ba64988322 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/stack_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/stack_fp16.cc @@ -117,6 +117,7 @@ kernel::LiteKernel *CpuStackFp16KernelCreator(const std::vector auto *kernel = new (std::nothrow) StackFp16CPUKernel(op_parameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "new StackFp16CPUKernel fail!"; + free(op_parameter); return nullptr; } diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/transpose_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/transpose_fp16.cc index faaff7f53c..995ca4e28b 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/transpose_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/transpose_fp16.cc @@ -190,6 +190,7 @@ kernel::LiteKernel *CpuTransposeFp16KernelCreator(const std::vectorInit(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/addn.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/addn.cc index d5cc423c41..4aa4febfa2 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/addn.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/addn.cc @@ -101,6 +101,7 @@ kernel::LiteKernel *CpuAddNFp32KernelCreator(const std::vector & } if (ctx == nullptr) { MS_LOG(ERROR) << "Input context is nullptr!"; + free(op_parameter); return nullptr; } MS_ASSERT(desc.type == schema::PrimitiveType_AddN); @@ -108,6 +109,7 @@ kernel::LiteKernel *CpuAddNFp32KernelCreator(const std::vector & auto *kernel = new (std::nothrow) AddNCPUKernel(op_parameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "new AddNCPUKernel fail!"; + free(op_parameter); return nullptr; } auto ret = kernel->Init(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/arithmetic.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/arithmetic.cc index e6552994d7..5e91a446d2 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/arithmetic.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/arithmetic.cc @@ -285,6 +285,7 @@ kernel::LiteKernel *CpuArithmeticFp32KernelCreator(const std::vectorname_; + free(parameter); return nullptr; } auto ret = kernel->Init(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/arithmetic_self.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/arithmetic_self.cc index bb1bd6411b..0a086faeb3 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/arithmetic_self.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/arithmetic_self.cc @@ -108,6 +108,7 @@ kernel::LiteKernel *CpuArithmeticSelfFp32KernelCreator(const std::vectorInit(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/batchnorm.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/batchnorm.cc index d17bac7c40..67ed41f422 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/batchnorm.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/batchnorm.cc @@ -105,6 +105,7 @@ kernel::LiteKernel *CpuBatchnormKernelCreator(const std::vector auto *kernel = new (std::nothrow) BatchnormCPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "new BatchNormCPUKernel fail!"; + free(opParameter); return nullptr; } auto ret = kernel->Init(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/bias.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/bias.cc index d6140becba..b09c87651b 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/bias.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/bias.cc @@ -83,6 +83,7 @@ kernel::LiteKernel *CpuBiasFp32KernelCreator(const std::vector & auto kernel = new (std::nothrow) BiasCPUKernel(parameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "Create kernel failed, name: " << parameter->name_; + free(parameter); return nullptr; } diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/broadcast_to.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/broadcast_to.cc index e55a05e335..3d23907b91 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/broadcast_to.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/broadcast_to.cc @@ -73,6 +73,7 @@ kernel::LiteKernel *CpuBroadcastToFp32KernelCreator(const std::vector & } if (ctx == nullptr) { MS_LOG(ERROR) << "Input context is nullptr!"; + free(opParameter); return nullptr; } if (ctx->thread_num_ == 0) { MS_LOG(ERROR) << "context thread num is 0!"; + free(opParameter); return nullptr; } auto *kernel = new (std::nothrow) CastCPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "new CastCPUKernel fail!"; + free(opParameter); return nullptr; } auto ret = kernel->Init(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/constant_of_shape.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/constant_of_shape.cc index 0fd35de6b3..51656cd5a2 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/constant_of_shape.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/constant_of_shape.cc @@ -84,6 +84,7 @@ kernel::LiteKernel *CpuConstantOfShapeFp32KernelCreator(const std::vectorInit(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/convolution.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/convolution.cc index 92c983d57c..913f46fabf 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/convolution.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/convolution.cc @@ -190,6 +190,7 @@ kernel::LiteKernel *CpuConvFp32KernelCreator(const std::vector & auto *dequant_weight = kernel::LiteKernelUtil::DequantWeight(weight_tensor); if (dequant_weight == nullptr) { MS_LOG(ERROR) << "dequant data is nullptr."; + free(op_parameter); return nullptr; } weight_tensor->SetData(dequant_weight); @@ -210,6 +211,7 @@ kernel::LiteKernel *CpuConvFp32KernelCreator(const std::vector & weight_tensor->FreeData(); weight_tensor->SetData(restore_data); } + free(op_parameter); return nullptr; } auto ret = kernel->Init(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_depthwise.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_depthwise.cc index f022bdd653..73988f7d79 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_depthwise.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_depthwise.cc @@ -137,6 +137,7 @@ kernel::LiteKernel *CpuConvDwFp32KernelCreator(const std::vector auto *dequant_weight = kernel::LiteKernelUtil::DequantWeight(weight_tensor); if (dequant_weight == nullptr) { MS_LOG(ERROR) << "dequant data is nullptr."; + free(opParameter); return nullptr; } weight_tensor->SetData(dequant_weight); @@ -155,6 +156,7 @@ kernel::LiteKernel *CpuConvDwFp32KernelCreator(const std::vector weight_tensor->FreeData(); weight_tensor->SetData(restore_data); } + free(opParameter); return nullptr; } auto ret = kernel->Init(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/deconvolution.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/deconvolution.cc index 1e3b824de5..d219b44def 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/deconvolution.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/deconvolution.cc @@ -241,6 +241,7 @@ kernel::LiteKernel *CpuDeConvFp32KernelCreator(const std::vector auto *dequant_weight = kernel::LiteKernelUtil::DequantWeight(weight_tensor); if (dequant_weight == nullptr) { MS_LOG(ERROR) << "dequant data is nullptr."; + free(opParameter); return nullptr; } weight_tensor->SetData(dequant_weight); @@ -252,6 +253,7 @@ kernel::LiteKernel *CpuDeConvFp32KernelCreator(const std::vector weight_tensor->FreeData(); weight_tensor->SetData(restore_data); } + free(opParameter); return nullptr; } auto ret = kernel->Init(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/deconvolution_depthwise.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/deconvolution_depthwise.cc index 3f076152c0..76948aed66 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/deconvolution_depthwise.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/deconvolution_depthwise.cc @@ -205,6 +205,7 @@ kernel::LiteKernel *CpuDeconvDwFp32KernelCreator(const std::vectorSetData(dequant_weight); @@ -217,6 +218,7 @@ kernel::LiteKernel *CpuDeconvDwFp32KernelCreator(const std::vectorFreeData(); weight_tensor->SetData(restore_data); } + free(opParameter); return nullptr; } auto ret = kernel->Init(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/detection_post_process.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/detection_post_process.cc index fb51509985..25e6986e45 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/detection_post_process.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/detection_post_process.cc @@ -136,6 +136,7 @@ kernel::LiteKernel *CpuDetectionPostProcessFp32KernelCreator(const std::vectorInit(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/elu.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/elu.cc index e0ff87f98c..900d07ff46 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/elu.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/elu.cc @@ -77,14 +77,20 @@ kernel::LiteKernel *CpuEluFp32KernelCreator(const std::vector &i const std::vector &outputs, OpParameter *parameter, const lite::InnerContext *ctx, const KernelKey &desc, const mindspore::lite::PrimitiveC *primitive) { - if (parameter == nullptr || ctx == nullptr) { - MS_LOG(ERROR) << "parameter or ctx is nullptr"; + if (parameter == nullptr) { + MS_LOG(ERROR) << "parameter is nullptr"; + return nullptr; + } + if (ctx == nullptr) { + MS_LOG(ERROR) << "ctx is nullptr"; + free(parameter); return nullptr; } MS_ASSERT(desc.type == PrimitiveType_Elu); auto *kernel = new (std::nothrow) EluCPUKernel(parameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "Create Kernel failed, name: " << parameter->name_; + free(parameter); return nullptr; } diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/embedding_lookup.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/embedding_lookup.cc index 59adeb36b4..19d76e5eeb 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/embedding_lookup.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/embedding_lookup.cc @@ -117,14 +117,20 @@ kernel::LiteKernel *CpuEmbeddingLookupFp32KernelCreator(const std::vectorname_; + free(parameter); return nullptr; } diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/exp.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/exp.cc index 0216bc977b..e2559a3daa 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/exp.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/exp.cc @@ -90,14 +90,20 @@ kernel::LiteKernel *CpuExpFp32KernelCreator(const std::vector &i const std::vector &outputs, OpParameter *parameter, const lite::InnerContext *ctx, const KernelKey &desc, const mindspore::lite::PrimitiveC *primitive) { - if (parameter == nullptr || ctx == nullptr) { - MS_LOG(ERROR) << "parameter or ctx is nullptr"; + if (parameter == nullptr) { + MS_LOG(ERROR) << "parameter is nullptr"; + return nullptr; + } + if (ctx == nullptr) { + MS_LOG(ERROR) << "ctx is nullptr"; + free(parameter); return nullptr; } MS_ASSERT(desc.type == PrimitiveType_Exp); auto *kernel = new (std::nothrow) ExpCPUKernel(parameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "Create Kernel failed, name: " << parameter->name_; + free(parameter); return nullptr; } diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/expandDims.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/expandDims.cc index 43bd33fb6d..240438881a 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/expandDims.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/expandDims.cc @@ -49,15 +49,15 @@ int ExpandDimsCPUKernel::DoExpandDims(int task_id) { } int offset = task_id * thread_sz_stride_; if (this->in_tensors_[0]->data_type() == kNumberTypeFloat32) { - int ret = ExpandDims(reinterpret_cast(in_ptr_) + offset, - reinterpret_cast(out_ptr_) + offset, size * sizeof(float)); + int ret = ExpandDims(reinterpret_cast(in_ptr_) + offset, reinterpret_cast(out_ptr_) + offset, + size * sizeof(float)); if (ret != RET_OK) { MS_LOG(ERROR) << "ExpandDimsRun error task_id[" << task_id << "] error_code[" << ret << "]"; return ret; } } else if (this->in_tensors_[0]->data_type() == kNumberTypeInt8) { - int ret = ExpandDims(reinterpret_cast(in_ptr_) + offset, - reinterpret_cast(out_ptr_) + offset, size * sizeof(int8_t)); + int ret = ExpandDims(reinterpret_cast(in_ptr_) + offset, reinterpret_cast(out_ptr_) + offset, + size * sizeof(int8_t)); if (ret != RET_OK) { MS_LOG(ERROR) << "ExpandDimsRun error task_id[" << task_id << "] error_code[" << ret << "]"; return ret; @@ -102,6 +102,7 @@ kernel::LiteKernel *CpuExpandsDimsFp32KernelCreator(const std::vectorInit(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/fill.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/fill.cc index e04e4affb4..3a1cd4697d 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/fill.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/fill.cc @@ -98,6 +98,7 @@ kernel::LiteKernel *CpuFillFp32KernelCreator(const std::vector & auto *kernel = new (std::nothrow) FillCPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "new FillCPUKernel fail!"; + free(opParameter); return nullptr; } auto ret = kernel->Init(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/flatten.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/flatten.cc index a0db0abed8..654772e4f0 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/flatten.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/flatten.cc @@ -68,6 +68,7 @@ kernel::LiteKernel *CpuFlattenFp32KernelCreator(const std::vectorInit(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/fused_batchnorm.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/fused_batchnorm.cc index 4741ed5c29..1d45d4ba66 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/fused_batchnorm.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/fused_batchnorm.cc @@ -149,6 +149,7 @@ kernel::LiteKernel *CpuFusedBatchnormKernelCreator(const std::vectorInit(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/gather.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/gather.cc index 7d9e1206f4..96d52426aa 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/gather.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/gather.cc @@ -150,6 +150,7 @@ kernel::LiteKernel *CpuGatherFp32KernelCreator(const std::vector } auto *kernel = new (std::nothrow) GatherCPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { + free(opParameter); return nullptr; } auto ret = kernel->Init(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/gatherNd.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/gatherNd.cc index af659f543c..20fd199fef 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/gatherNd.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/gatherNd.cc @@ -140,6 +140,7 @@ kernel::LiteKernel *CpuGatherNdFp32KernelCreator(const std::vectorInit(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/l2_norm.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/l2_norm.cc index a6c4250794..c081056d08 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/l2_norm.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/l2_norm.cc @@ -191,6 +191,7 @@ kernel::LiteKernel *CpuL2NormFp32KernelCreator(const std::vector auto *kernel = new (std::nothrow) L2NormCPUKernel(param, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "new L2NormCPUKernel fail!"; + free(param); return nullptr; } auto ret = kernel->Init(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/local_response_norm.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/local_response_norm.cc index c22af789da..f5d3870ea5 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/local_response_norm.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/local_response_norm.cc @@ -98,6 +98,7 @@ kernel::LiteKernel *CpuLocalResponseNormFp32KernelCreator(const std::vectorInit(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/lsh_projection.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/lsh_projection.cc index 6cde59fb0b..7bfbe6d0ec 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/lsh_projection.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/lsh_projection.cc @@ -161,12 +161,14 @@ kernel::LiteKernel *CpuLshProjectionFp32KernelCreator(const std::vectorInit(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/lstm.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/lstm.cc index d50bfcf749..1fff7550c6 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/lstm.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/lstm.cc @@ -188,6 +188,7 @@ kernel::LiteKernel *CpuLstmKernelCreator(const std::vector &inpu auto *kernel = new (std::nothrow) LstmCPUKernel(parameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "kernel is nullptr."; + free(parameter); return nullptr; } auto ret = kernel->Init(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/nchw2nhwc.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/nchw2nhwc.cc index 025e8e4e0a..61cb77a624 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/nchw2nhwc.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/nchw2nhwc.cc @@ -59,6 +59,7 @@ kernel::LiteKernel *CpuNchw2NhwcFp32KernelCreator(const std::vectorInit(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/nhwc2nchw.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/nhwc2nchw.cc index 5868eb8740..58e048e9b4 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/nhwc2nchw.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/nhwc2nchw.cc @@ -59,6 +59,7 @@ kernel::LiteKernel *CpuNhwc2NchwFp32KernelCreator(const std::vectorInit(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/one_hot.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/one_hot.cc index 5aa7840109..ef48273ab6 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/one_hot.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/one_hot.cc @@ -184,11 +184,13 @@ kernel::LiteKernel *CpuOneHotFp32KernelCreator(const std::vector } if (desc.type != schema::PrimitiveType_OneHot) { MS_LOG(ERROR) << "OneHot desc type should be " << schema::PrimitiveType_OneHot << " got " << desc.type; + free(opParameter); return nullptr; } auto *kernel = new (std::nothrow) OneHotCPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "OneHot new kernel failed."; + free(opParameter); return nullptr; } auto ret = kernel->Init(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/prelu.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/prelu.cc index 436d770fad..67c9bdd6d5 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/prelu.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/prelu.cc @@ -159,6 +159,7 @@ kernel::LiteKernel *CpuPReluFp32KernelCreator(const std::vector auto *kernel = new (std::nothrow) PReluCPUKernel(param, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "new PReluCPUKernel fail!"; + free(param); return nullptr; } auto ret = kernel->Init(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/range.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/range.cc index 2c7b156414..23c6f6aabd 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/range.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/range.cc @@ -55,6 +55,7 @@ kernel::LiteKernel *CpuRangeFp32KernelCreator(const std::vector auto *kernel = new (std::nothrow) RangeCPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "new RangeCPUKernel fail!"; + free(opParameter); return nullptr; } auto ret = kernel->Init(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/rank.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/rank.cc index f7a722fcd3..636112dbda 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/rank.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/rank.cc @@ -54,6 +54,7 @@ kernel::LiteKernel *CpuRankFp32KernelCreator(const std::vector & auto *kernel = new (std::nothrow) RankCPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "new RankCPUKernel fail!"; + free(opParameter); return nullptr; } auto ret = kernel->Init(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/reverse.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/reverse.cc index d885ca365f..9734f13cf9 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/reverse.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/reverse.cc @@ -153,6 +153,7 @@ kernel::LiteKernel *CpuReverseFp32KernelCreator(const std::vectorname_ << ", type: " << schema::EnumNamePrimitiveType(static_cast(opParameter->type_)); + free(opParameter); return nullptr; } diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/reverse_sequence.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/reverse_sequence.cc index bc6d6055f1..df23b8a39e 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/reverse_sequence.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/reverse_sequence.cc @@ -111,6 +111,7 @@ kernel::LiteKernel *CpuReverseSequenceFp32KernelCreator(const std::vectorname_; + free(parameter); return nullptr; } auto ret = kernel->Init(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/roi_pooling.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/roi_pooling.cc index 7312b29115..b591cc7105 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/roi_pooling.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/roi_pooling.cc @@ -119,15 +119,18 @@ kernel::LiteKernel *CpuROIPoolingFp32KernelCreator(const std::vectorthread_num_ == 0) { MS_LOG(ERROR) << "context thread num is 0!"; + free(opParameter); return nullptr; } auto *kernel = new (std::nothrow) ROIPoolingCPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "new ROIPoolingCPUKernel fail!"; + free(opParameter); return nullptr; } auto ret = kernel->Init(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/scale.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/scale.cc index 4b2d79b8d2..7dfdcde954 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/scale.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/scale.cc @@ -213,6 +213,7 @@ kernel::LiteKernel *CpuScaleFp32KernelCreator(const std::vector auto *kernel = new (std::nothrow) ScaleCPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "New kernel fails."; + free(opParameter); return nullptr; } auto ret = kernel->Init(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/scatter_nd.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/scatter_nd.cc index da3e40eb31..f34d1a220c 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/scatter_nd.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/scatter_nd.cc @@ -174,6 +174,7 @@ kernel::LiteKernel *CpuScatterNDFp32KernelCreator(const std::vector auto *kernel = new (std::nothrow) ShapeCPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "New kernel fails."; + free(opParameter); return nullptr; } diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/skip_gram.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/skip_gram.cc index 06c78b7136..214e401e0a 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/skip_gram.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/skip_gram.cc @@ -108,14 +108,20 @@ kernel::LiteKernel *CpuSkipGramFp32KernelCreator(const std::vector &outputs, OpParameter *parameter, const lite::InnerContext *ctx, const KernelKey &desc, const mindspore::lite::PrimitiveC *primitive) { - if (parameter == nullptr || ctx == nullptr) { - MS_LOG(ERROR) << "parameter or ctx is nullptr"; + if (parameter == nullptr) { + MS_LOG(ERROR) << "parameter is nullptr"; + return nullptr; + } + if (ctx == nullptr) { + MS_LOG(ERROR) << "ctx is nullptr"; + free(parameter); return nullptr; } MS_ASSERT(desc.type == PrimitiveType_SkipGram); auto *kernel = new (std::nothrow) SkipGramCPUKernel(parameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "Create Kernel failed, name: " << parameter->name_; + free(parameter); return nullptr; } diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/slice.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/slice.cc index 3cc1e71ef9..212116c01a 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/slice.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/slice.cc @@ -94,6 +94,7 @@ kernel::LiteKernel *CpuSliceFp32KernelCreator(const std::vector auto *kernel = new (std::nothrow) SliceCPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "new SliceCPUKernel fail!"; + free(opParameter); return nullptr; } auto ret = kernel->Init(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/space_to_batch.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/space_to_batch.cc index a7f37feb7c..c893a467b7 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/space_to_batch.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/space_to_batch.cc @@ -110,6 +110,7 @@ kernel::LiteKernel *CpuSpaceToBatchFp32KernelCreator(const std::vectorInit(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/space_to_depth.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/space_to_depth.cc index 1b11c9e5bd..42ed11f745 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/space_to_depth.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/space_to_depth.cc @@ -118,6 +118,7 @@ kernel::LiteKernel *CpuSpaceToDepthFp32KernelCreator(const std::vectorInit(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/squeeze.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/squeeze.cc index 949a8a61fc..6287d76d92 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/squeeze.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/squeeze.cc @@ -68,6 +68,7 @@ kernel::LiteKernel *CpuSqueezeFp32KernelCreator(const std::vector auto *kernel = new (std::nothrow) StackCPUKernel(op_parameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "new StackCPUKernel fail!"; + free(op_parameter); return nullptr; } diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/tile.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/tile.cc index 835f326b13..8bd0a16e67 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/tile.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/tile.cc @@ -67,14 +67,20 @@ kernel::LiteKernel *CpuTileFp32KernelCreator(const std::vector & const std::vector &outputs, OpParameter *parameter, const lite::InnerContext *ctx, const KernelKey &desc, const mindspore::lite::PrimitiveC *primitive) { - if (parameter == nullptr || ctx == nullptr) { - MS_LOG(ERROR) << "parameter or ctx is nullptr"; + if (parameter == nullptr) { + MS_LOG(ERROR) << "parameter is nullptr"; + return nullptr; + } + if (ctx == nullptr) { + MS_LOG(ERROR) << "ctx is nullptr"; + free(parameter); return nullptr; } MS_ASSERT(desc.type == PrimitiveType_Tile); auto *kernel = new (std::nothrow) TileCPUKernel(parameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "Create kernel failed, name: " << parameter->name_; + free(parameter); return nullptr; } diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/topk.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/topk.cc index 7a69a45f66..c862c7464e 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/topk.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/topk.cc @@ -78,6 +78,7 @@ kernel::LiteKernel *CpuTopKFp32KernelCreator(const std::vector & auto *kernel = new (std::nothrow) TopKCPUKernel(parameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "new TopKCPUKernel fail!"; + free(parameter); return nullptr; } diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/transpose.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/transpose.cc index 7cc437d853..1aa181a16f 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/transpose.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/transpose.cc @@ -146,6 +146,7 @@ kernel::LiteKernel *CpuTransposeFp32KernelCreator(const std::vector auto *kernel = new (std::nothrow) UniqueCPUKernel(parameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "Create kernel failed, name: " << parameter->name_; + free(parameter); return nullptr; } auto ret = kernel->Init(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/unsqueeze.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/unsqueeze.cc index e003050c77..8bfc148ce7 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/unsqueeze.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/unsqueeze.cc @@ -90,6 +90,7 @@ kernel::LiteKernel *CpuUnsqueezeFp32KernelCreator(const std::vectorInit(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/unstack.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/unstack.cc index e638eaf084..0f953b60d5 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/unstack.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/unstack.cc @@ -87,6 +87,7 @@ kernel::LiteKernel *CpuUnstackFp32KernelCreator(const std::vectorname_; + free(parameter); return nullptr; } auto ret = kernel->Init(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/where.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/where.cc index 38b6e0b3c3..b5f0712bd0 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/where.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/where.cc @@ -99,6 +99,7 @@ kernel::LiteKernel *CpuWhereFp32KernelCreator(const std::vector auto *kernel = new (std::nothrow) WhereCPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "new WhereCPUKernel fail!"; + free(opParameter); return nullptr; } auto ret = kernel->Init(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/zeroslike.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/zeroslike.cc index adbd5c3fa4..2e321530e3 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/zeroslike.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/zeroslike.cc @@ -54,6 +54,7 @@ kernel::LiteKernel *CpuZerosLikeFp32KernelCreator(const std::vectorInit(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32_grad/activation_grad.cc b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/activation_grad.cc index 12ede4a061..0d14a25b3c 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32_grad/activation_grad.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/activation_grad.cc @@ -119,6 +119,7 @@ kernel::LiteKernel *CpuActivationGradFp32KernelCreator(const std::vectorInit(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32_grad/apply_momentum.cc b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/apply_momentum.cc index 8f53a60c3d..527b260fd7 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32_grad/apply_momentum.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/apply_momentum.cc @@ -95,7 +95,11 @@ kernel::LiteKernel *CpuApplyMomentumFp32KernelCreator(const std::vectorInit(); if (0 != ret) { diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32_grad/arithmetic_grad.cc b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/arithmetic_grad.cc index 980f22f381..1a89ae99ed 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32_grad/arithmetic_grad.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/arithmetic_grad.cc @@ -227,6 +227,7 @@ kernel::LiteKernel *CpuArithmeticGradFp32KernelCreator(const std::vector auto *kernel = new (std::nothrow) BNGradCPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "new BNGradCPUKernel fail!"; + free(opParameter); return nullptr; } auto ret = kernel->Init(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32_grad/convolution.cc b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/convolution.cc index 3193971ef4..8ba98f13f6 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32_grad/convolution.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/convolution.cc @@ -136,7 +136,11 @@ kernel::LiteKernel *CpuConvTrainFp32KernelCreator(const std::vectorInit(); if (RET_OK != ret) { diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32_grad/convolution_grad_filter.cc b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/convolution_grad_filter.cc index cf54e4675b..4606551c1e 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32_grad/convolution_grad_filter.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/convolution_grad_filter.cc @@ -141,6 +141,7 @@ kernel::LiteKernel *CpuConvGradFilterFp32KernelCreator(const std::vector &i const lite::PrimitiveC *primitive) { MS_ASSERT(desc.type == schema::PrimitiveType_Sgd); auto *kernel = new (std::nothrow) SgdCPUKernel(opParameter, inputs, outputs, ctx, primitive); - MS_ASSERT(kernel != nullptr); + if (kernel == nullptr) { + MS_LOG(ERROR) << "new SgdCPUKernel failed!"; + free(opParameter); + return nullptr; + } auto ret = kernel->Init(); - if (0 != ret) { + if (RET_OK != ret) { MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: " << schema::EnumNamePrimitiveType(static_cast(opParameter->type_)); delete kernel; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32_grad/softmax_cross_entropy_with_logits.cc b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/softmax_cross_entropy_with_logits.cc index 494b322f60..2ece13d195 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32_grad/softmax_cross_entropy_with_logits.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/softmax_cross_entropy_with_logits.cc @@ -140,7 +140,11 @@ kernel::LiteKernel *CpuSoftmaxCrossEntropyFp32KernelCreator(const std::vector
  • Init(); if (RET_OK != ret) { MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: " diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32_grad/softmax_grad.cc b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/softmax_grad.cc index 209ac702c7..630066fa60 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32_grad/softmax_grad.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/softmax_grad.cc @@ -102,6 +102,7 @@ kernel::LiteKernel *CpuSoftmaxGradFp32KernelCreator(const std::vectorInit(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32_grad/sparse_softmax_cross_entropy_with_logits.cc b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/sparse_softmax_cross_entropy_with_logits.cc index 77397fa1b7..86501eab04 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32_grad/sparse_softmax_cross_entropy_with_logits.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/sparse_softmax_cross_entropy_with_logits.cc @@ -163,7 +163,11 @@ kernel::LiteKernel *CpuSparseSoftmaxCrossEntropyFp32KernelCreator( MS_ASSERT(desc.type == schema::PrimitiveType_SoftmaxCrossEntropy); auto *kernel = new (std::nothrow) SparseSoftmaxCrossEntropyWithLogitsCPUKernel(opParameter, inputs, outputs, ctx, primitive); - MS_ASSERT(kernel != nullptr); + if (kernel == nullptr) { + MS_LOG(ERROR) << "new SparseSoftmaxCrossEntropyWithLogitsCPUKernel failed!"; + free(opParameter); + return nullptr; + } auto ret = kernel->Init(); if (RET_OK != ret) { MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: " diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32_grad/tuple_getitem.cc b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/tuple_getitem.cc index e1523c8694..c109db82db 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32_grad/tuple_getitem.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/tuple_getitem.cc @@ -83,7 +83,11 @@ kernel::LiteKernel *CpuTupleGetItemFp32KernelCreator(const std::vectorInit(); if (RET_OK != ret) { diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/activation.cc b/mindspore/lite/src/runtime/kernel/arm/int8/activation.cc index 8acb32b15e..588cd37334 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/activation.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/activation.cc @@ -62,6 +62,7 @@ kernel::LiteKernel *CpuActivationInt8KernelCreator(const std::vectorInit(); diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/add_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/add_int8.cc index ec816290c0..eed2fd2f7d 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/add_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/add_int8.cc @@ -130,14 +130,20 @@ kernel::LiteKernel *CpuAddInt8KernelCreator(const std::vector &i const std::vector &outputs, OpParameter *parameter, const lite::InnerContext *ctx, const KernelKey &desc, const mindspore::lite::PrimitiveC *primitive) { - if (parameter == nullptr || ctx == nullptr) { - MS_LOG(ERROR) << "parameter or ctx is nullptr"; + if (parameter == nullptr) { + MS_LOG(ERROR) << "parameter is nullptr"; + return nullptr; + } + if (ctx == nullptr) { + MS_LOG(ERROR) << "ctx is nullptr"; + free(parameter); return nullptr; } MS_ASSERT(desc.type == PrimitiveType_Add); auto *kernel = new (std::nothrow) QuantizedAddCPUKernel(parameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "kernel is nullptr."; + free(parameter); return nullptr; } auto ret = kernel->Init(); diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/arithmetic_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/arithmetic_int8.cc index 852a0add51..50df6da255 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/arithmetic_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/arithmetic_int8.cc @@ -171,6 +171,7 @@ kernel::LiteKernel *CpuArithmeticInt8KernelCreator(const std::vectorname_; + free(parameter); return nullptr; } auto ret = kernel->Init(); diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/arithmetic_self_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/arithmetic_self_int8.cc index 499160f939..43307f6a43 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/arithmetic_self_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/arithmetic_self_int8.cc @@ -126,6 +126,7 @@ kernel::LiteKernel *CpuArithmeticSelfInt8KernelCreator(const std::vectorInit(); diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/bias_add_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/bias_add_int8.cc index f78af52d2d..79fc9fd819 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/bias_add_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/bias_add_int8.cc @@ -72,14 +72,20 @@ kernel::LiteKernel *CpuBiasAddInt8KernelCreator(const std::vector &outputs, OpParameter *parameter, const lite::InnerContext *ctx, const KernelKey &desc, const mindspore::lite::PrimitiveC *primitive) { - if (parameter == nullptr || ctx == nullptr) { - MS_LOG(ERROR) << "parameter or context is nullptr"; + if (parameter == nullptr) { + MS_LOG(ERROR) << "parameter is nullptr"; + return nullptr; + } + if (ctx == nullptr) { + MS_LOG(ERROR) << "ctx is nullptr"; + free(parameter); return nullptr; } MS_ASSERT(desc.type == PrimitiveType_BiasAdd); auto *kernel = new (std::nothrow) BiasAddInt8CPUKernel(parameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "Create kernel failed, name: " << parameter->name_; + free(parameter); return nullptr; } diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/convolution_depthwise_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/convolution_depthwise_int8.cc index fd917fc3f1..239a5c01bf 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/convolution_depthwise_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/convolution_depthwise_int8.cc @@ -190,6 +190,7 @@ kernel::LiteKernel *CpuConvDwInt8KernelCreator(const std::vector if (kernel == nullptr) { MS_LOG(ERROR) << "kernel is nullptr."; + free(opParameter); return nullptr; } auto ret = kernel->Init(); diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/convolution_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/convolution_int8.cc index 65fc726330..5d2bc2fead 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/convolution_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/convolution_int8.cc @@ -397,6 +397,7 @@ kernel::LiteKernel *CpuConvInt8KernelCreator(const std::vector & } if (kernel == nullptr) { MS_LOG(ERROR) << "kernel is nullptr."; + free(opParameter); return nullptr; } auto ret = kernel->Init(); diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/deconvolution_depthwise_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/deconvolution_depthwise_int8.cc index 4b651bb535..0b9785c764 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/deconvolution_depthwise_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/deconvolution_depthwise_int8.cc @@ -222,6 +222,7 @@ kernel::LiteKernel *CpuDeconvDwInt8KernelCreator(const std::vectorInit(); diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/deconvolution_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/deconvolution_int8.cc index a202de2fdf..83b34cddfd 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/deconvolution_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/deconvolution_int8.cc @@ -300,6 +300,7 @@ kernel::LiteKernel *CpuDeConvInt8KernelCreator(const std::vector auto kernel = new (std::nothrow) kernel::DeConvInt8CPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "kernel is nullptr."; + free(opParameter); return nullptr; } auto ret = kernel->Init(); diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/div_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/div_int8.cc index 9eddd941a9..4785f2aae4 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/div_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/div_int8.cc @@ -136,14 +136,20 @@ kernel::LiteKernel *CpuDivInt8KernelCreator(const std::vector &i const std::vector &outputs, OpParameter *parameter, const lite::InnerContext *ctx, const KernelKey &desc, const mindspore::lite::PrimitiveC *primitive) { - if (parameter == nullptr || ctx == nullptr) { - MS_LOG(ERROR) << "parameter or ctx is nullptr"; + if (parameter == nullptr) { + MS_LOG(ERROR) << "parameter is nullptr"; + return nullptr; + } + if (ctx == nullptr) { + MS_LOG(ERROR) << "ctx is nullptr"; + free(parameter); return nullptr; } MS_ASSERT(desc.type == PrimitiveType_Div); auto *kernel = new (std::nothrow) DivInt8CPUKernel(parameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "kernel is nullptr."; + free(parameter); return nullptr; } auto ret = kernel->Init(); diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/gatherNd_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/gatherNd_int8.cc index 341c1c0f94..aae2c94dd7 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/gatherNd_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/gatherNd_int8.cc @@ -149,6 +149,7 @@ kernel::LiteKernel *CpuGatherNdInt8KernelCreator(const std::vectorInit(); diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/gather_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/gather_int8.cc index 6cfcd0488b..0867a98d23 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/gather_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/gather_int8.cc @@ -130,6 +130,7 @@ kernel::LiteKernel *CpuGatherInt8KernelCreator(const std::vector } auto *kernel = new (std::nothrow) GatherInt8CPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { + free(opParameter); return nullptr; } auto ret = kernel->Init(); diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/mul_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/mul_int8.cc index 9f29ac88ba..25809304f2 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/mul_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/mul_int8.cc @@ -161,6 +161,7 @@ kernel::LiteKernel *CpuMulInt8KernelCreator(const std::vector &i if (kernel == nullptr) { MS_LOG(ERROR) << "kernel is nullptr."; + free(opParameter); return nullptr; } auto ret = kernel->Init(); diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/scale_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/scale_int8.cc index 2c988fe842..11add9dad0 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/scale_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/scale_int8.cc @@ -250,6 +250,7 @@ kernel::LiteKernel *CpuScaleInt8KernelCreator(const std::vector auto *kernel = new (std::nothrow) ScaleInt8CPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "New kernel fails."; + free(opParameter); return nullptr; } diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/slice_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/slice_int8.cc index 134cbec714..b47819fb58 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/slice_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/slice_int8.cc @@ -99,6 +99,7 @@ kernel::LiteKernel *CpuSliceInt8KernelCreator(const std::vector auto *kernel = new (std::nothrow) SliceInt8CPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "new SliceInt8CPUKernel fail!"; + free(opParameter); return nullptr; } auto ret = kernel->Init(); diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/space_to_batch_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/space_to_batch_int8.cc index d08016c27e..19a3ecfa6a 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/space_to_batch_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/space_to_batch_int8.cc @@ -71,6 +71,7 @@ kernel::LiteKernel *CpuSpaceToBatchInt8KernelCreator(const std::vectorInit(); diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/sub_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/sub_int8.cc index 064611b4ad..9d0b11936a 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/sub_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/sub_int8.cc @@ -160,14 +160,20 @@ kernel::LiteKernel *CpuSubInt8KernelCreator(const std::vector &i const std::vector &outputs, OpParameter *parameter, const lite::InnerContext *ctx, const KernelKey &desc, const mindspore::lite::PrimitiveC *primitive) { - if (parameter == nullptr || ctx == nullptr) { - MS_LOG(ERROR) << "parameter or ctx is nullptr"; + if (parameter == nullptr) { + MS_LOG(ERROR) << "parameter is nullptr"; + return nullptr; + } + if (ctx == nullptr) { + MS_LOG(ERROR) << "ctx is nullptr"; + free(parameter); return nullptr; } MS_ASSERT(desc.type == PrimitiveType_Sub); auto *kernel = new (std::nothrow) SubInt8CPUKernel(parameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "kernel is nullptr."; + free(parameter); return nullptr; } auto ret = kernel->Init(); diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/topk_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/topk_int8.cc index 2d7bf12e0d..8125ba80f2 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/topk_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/topk_int8.cc @@ -80,6 +80,7 @@ kernel::LiteKernel *CpuTopKInt8KernelCreator(const std::vector & TopKInt8CPUKernel *kernel = new (std::nothrow) TopKInt8CPUKernel(parameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "new TopKInt8CPUKernel fail!"; + free(parameter); return nullptr; } diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/unsqueeze_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/unsqueeze_int8.cc index 454d370b48..363d45d07e 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/unsqueeze_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/unsqueeze_int8.cc @@ -105,6 +105,7 @@ kernel::LiteKernel *CpuUnsqueezeInt8KernelCreator(const std::vectorInit(); diff --git a/mindspore/lite/src/runtime/kernel/arm/string/extract_feature.cc b/mindspore/lite/src/runtime/kernel/arm/string/extract_feature.cc index 08bb100db0..4215e8f5b0 100644 --- a/mindspore/lite/src/runtime/kernel/arm/string/extract_feature.cc +++ b/mindspore/lite/src/runtime/kernel/arm/string/extract_feature.cc @@ -81,6 +81,7 @@ kernel::LiteKernel *CpuExtractFeatureKernelCreator(const std::vectorInit(); diff --git a/mindspore/lite/src/runtime/kernel/arm/string/hashtable_lookup.cc b/mindspore/lite/src/runtime/kernel/arm/string/hashtable_lookup.cc index 8a87074b15..77d5607f90 100644 --- a/mindspore/lite/src/runtime/kernel/arm/string/hashtable_lookup.cc +++ b/mindspore/lite/src/runtime/kernel/arm/string/hashtable_lookup.cc @@ -80,6 +80,7 @@ kernel::LiteKernel *CpuHashtableLookupKernelCreator(const std::vectorInit(); diff --git a/mindspore/lite/src/runtime/kernel/arm/string/normalize.cc b/mindspore/lite/src/runtime/kernel/arm/string/normalize.cc index 4412ae97ab..7865bca8f5 100644 --- a/mindspore/lite/src/runtime/kernel/arm/string/normalize.cc +++ b/mindspore/lite/src/runtime/kernel/arm/string/normalize.cc @@ -144,6 +144,7 @@ kernel::LiteKernel *CpuNormalizeKernelCreator(const std::vector auto *kernel = new (std::nothrow) NormalizeCPUKernel(parameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "new NormalizeCPUKernel fail!"; + free(parameter); return nullptr; } auto ret = kernel->Init(); diff --git a/mindspore/lite/src/runtime/kernel/arm/string/predict.cc b/mindspore/lite/src/runtime/kernel/arm/string/predict.cc index dd30921f17..fc552a075b 100644 --- a/mindspore/lite/src/runtime/kernel/arm/string/predict.cc +++ b/mindspore/lite/src/runtime/kernel/arm/string/predict.cc @@ -102,6 +102,7 @@ kernel::LiteKernel *CpuPredictKernelCreator(const std::vector &i auto *kernel = new (std::nothrow) PredictCPUKernel(parameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "new PredictCPUKernel fail!"; + free(parameter); return nullptr; } auto ret = kernel->Init(); diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/activation.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/activation.cc index b86a7e9f28..463655af94 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/activation.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/activation.cc @@ -143,12 +143,14 @@ kernel::LiteKernel *OpenClActivationKernelCreator(const std::vectorshape().size() > 2 && inputs[0]->shape()[0] > 1) { MS_LOG(ERROR) << "Activation kernel:" << opParameter->name_ << " failed: Unsupported multi-batch."; + free(opParameter); return nullptr; } auto *kernel = new (std::nothrow) ActivationOpenClKernel(reinterpret_cast(opParameter), inputs, outputs); if (kernel == nullptr) { MS_LOG(ERROR) << "New kernel:" << opParameter->name_ << "is nullptr."; + free(opParameter); return nullptr; } auto ret = kernel->Init(); diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/arithmetic.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/arithmetic.cc index bc8e30bf49..25a2596eff 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/arithmetic.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/arithmetic.cc @@ -359,6 +359,7 @@ kernel::LiteKernel *OpenCLArithmeticKernelCreator(const std::vector(opParameter), inputs, outputs, ctx); if (kernel == nullptr) { MS_LOG(ERROR) << "Create OpenCL Arithmetic kernel failed!"; + free(opParameter); return nullptr; } auto ret = kernel->Init(); diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/arithmetic_self.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/arithmetic_self.cc index b1e3cd1766..13c6c2256d 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/arithmetic_self.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/arithmetic_self.cc @@ -208,6 +208,7 @@ kernel::LiteKernel *OpenCLArithmeticSelfKernelCreator(const std::vectorInit(); diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/batch_to_space_nd.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/batch_to_space_nd.cc index 393640a71e..1980fc148e 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/batch_to_space_nd.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/batch_to_space_nd.cc @@ -128,6 +128,7 @@ kernel::LiteKernel *OpenCLBatchToSpaceNDKernelCreator(const std::vectorname_ << " new failed."; + free(opParameter); return nullptr; } auto ret = kernel->Init(); diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/batchnorm.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/batchnorm.cc index 335768e6b8..680956e2e1 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/batchnorm.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/batchnorm.cc @@ -128,6 +128,7 @@ kernel::LiteKernel *OpenCLBatchnormKernelCreator(const std::vectorInit(); diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/biasadd.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/biasadd.cc index 3a3a2db6ee..0e00d6e257 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/biasadd.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/biasadd.cc @@ -140,15 +140,18 @@ kernel::LiteKernel *OpenCLBiasAddKernelCreator(const std::vector const lite::PrimitiveC *primitive) { if (inputs.size() == 0) { MS_LOG(ERROR) << "Input data size must be greater than 0, but your size is " << inputs.size(); + free(opParameter); return nullptr; } if (inputs[0]->shape()[0] > 1) { MS_LOG(ERROR) << "Input data size unsupported multi-batch."; + free(opParameter); return nullptr; } auto *kernel = new (std::nothrow) BiasAddOpenCLKernel(reinterpret_cast(opParameter), inputs, outputs); if (kernel == nullptr) { MS_LOG(ERROR) << "Kernel " << opParameter->name_ << "is nullptr."; + free(opParameter); return nullptr; } diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/cast.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/cast.cc index 2e85a596a5..e15e54fb28 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/cast.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/cast.cc @@ -134,6 +134,7 @@ kernel::LiteKernel *OpenCLCastKernelCreator(const std::vector &i auto *kernel = new (std::nothrow) CastOpenCLKernel(opParameter, inputs, outputs); if (kernel == nullptr) { MS_LOG(ERROR) << " new CastOpenCLKernel failed "; + free(opParameter); return nullptr; } auto ret = kernel->Init(); diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/concat.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/concat.cc index 935a154f67..f0ca267c67 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/concat.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/concat.cc @@ -213,6 +213,7 @@ kernel::LiteKernel *OpenCLConcatKernelCreator(const std::vector auto *kernel = new (std::nothrow) ConcatOpenCLKernel(opParameter, inputs, outputs); if (kernel == nullptr) { MS_LOG(ERROR) << " new ConcatOpenCLKernel failed "; + free(opParameter); return nullptr; } auto ret = kernel->Init(); diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/conv2d_transpose.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/conv2d_transpose.cc index e954a4ee0f..14471f599c 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/conv2d_transpose.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/conv2d_transpose.cc @@ -220,6 +220,7 @@ kernel::LiteKernel *OpenCLConv2dTransposeKernelCreator(const std::vector(opParameter), inputs, outputs); if (kernel == nullptr) { MS_LOG(ERROR) << "kernel " << opParameter->name_ << "is nullptr."; + free(opParameter); return nullptr; } auto ret = kernel->Init(); diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/convolution.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/convolution.cc index 84cc574606..5cef4ff002 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/convolution.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/convolution.cc @@ -908,6 +908,7 @@ kernel::LiteKernel *OpenCLConvolutionKernelCreator(const std::vector(opParameter), inputs, outputs); if (kernel == nullptr) { MS_LOG(ERROR) << "Create OpenCL Convolution kernel failed!"; + free(opParameter); return nullptr; } auto ret = kernel->Init(); diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/depthwise_conv2d.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/depthwise_conv2d.cc index 496e0804f9..5f1d24243a 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/depthwise_conv2d.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/depthwise_conv2d.cc @@ -228,6 +228,7 @@ kernel::LiteKernel *OpenCLDepthwiseConv2dKernelCreator(const std::vector(opParameter), inputs, outputs); if (kernel == nullptr) { MS_LOG(ERROR) << "kernel " << opParameter->name_ << "is nullptr."; + free(opParameter); return nullptr; } auto ret = kernel->Init(); diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/fullconnection.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/fullconnection.cc index 191cdfd7d2..a2d16c0c5c 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/fullconnection.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/fullconnection.cc @@ -235,6 +235,7 @@ kernel::LiteKernel *OpenCLFullConnectionKernelCreator(const std::vector(opParameter), inputs, outputs); if (kernel == nullptr) { MS_LOG(ERROR) << "kernel " << opParameter->name_ << "is nullptr."; + free(opParameter); return nullptr; } auto ret = kernel->Init(); diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/gather.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/gather.cc index 95a53c6f2e..98570f31e4 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/gather.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/gather.cc @@ -157,6 +157,7 @@ kernel::LiteKernel *OpenCLGatherKernelCreator(const std::vector auto *kernel = new (std::nothrow) GatherOpenCLKernel(opParameter, inputs, outputs); if (kernel == nullptr) { MS_LOG(ERROR) << "Kernel " << opParameter->name_ << " new failed."; + free(opParameter); return nullptr; } auto ret = kernel->Init(); diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/matmul.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/matmul.cc index b94da9367e..59384a9b10 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/matmul.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/matmul.cc @@ -196,6 +196,7 @@ kernel::LiteKernel *OpenCLMatMulKernelCreator(const std::vector auto *kernel = new (std::nothrow) MatMulOpenCLKernel(reinterpret_cast(opParameter), inputs, outputs); if (kernel == nullptr) { MS_LOG(ERROR) << "kernel " << opParameter->name_ << "is nullptr."; + free(opParameter); return nullptr; } auto ret = kernel->Init(); diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/pad.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/pad.cc index e9411191b6..bc9f977f83 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/pad.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/pad.cc @@ -141,6 +141,7 @@ kernel::LiteKernel *OpenCLPadKernelCreator(const std::vector &in auto *kernel = new (std::nothrow) PadOpenCLKernel(reinterpret_cast(opParameter), inputs, outputs); if (kernel == nullptr) { MS_LOG(ERROR) << "Create OpenCL Pad kernel failed!"; + free(opParameter); return nullptr; } auto ret = kernel->Init(); diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/pooling2d.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/pooling2d.cc index 1fc968ab62..cf59e9e9a4 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/pooling2d.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/pooling2d.cc @@ -166,6 +166,7 @@ kernel::LiteKernel *OpenCLPooling2dKernelCreator(const std::vector(opParameter), inputs, outputs); if (kernel == nullptr) { MS_LOG(ERROR) << "Create OpenCL Pooling kernel failed!"; + free(opParameter); return nullptr; } auto ret = kernel->Init(); diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/prelu.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/prelu.cc index cfcec4f379..3501f4e6d5 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/prelu.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/prelu.cc @@ -184,11 +184,13 @@ kernel::LiteKernel *OpenCLPReluKernelCreator(const std::vector & const lite::PrimitiveC *primitive) { if (inputs.empty()) { MS_LOG(ERROR) << "Input data size must be greater than 0, but your size is " << inputs.size(); + free(opParameter); return nullptr; } auto *kernel = new (std::nothrow) PReluOpenCLKernel(reinterpret_cast(opParameter), inputs, outputs); if (kernel == nullptr) { MS_LOG(ERROR) << "kernel " << opParameter->name_ << "is nullptr."; + free(opParameter); return nullptr; } auto ret = kernel->Init(); diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/reduce.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/reduce.cc index a4b13f181a..799625c34d 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/reduce.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/reduce.cc @@ -146,6 +146,7 @@ kernel::LiteKernel *OpenCLReduceKernelCreator(const std::vector auto *kernel = new (std::nothrow) ReduceOpenCLKernel(reinterpret_cast(opParameter), inputs, outputs); if (kernel == nullptr) { MS_LOG(ERROR) << "kernel " << opParameter->name_ << " create failed."; + free(opParameter); return nullptr; } auto ret = kernel->Init(); diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/reshape.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/reshape.cc index eaead966ac..d8ad378064 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/reshape.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/reshape.cc @@ -125,6 +125,7 @@ kernel::LiteKernel *OpenCLReshapeKernelCreator(const std::vector auto *kernel = new (std::nothrow) ReshapeOpenCLKernel(reinterpret_cast(opParameter), inputs, outputs); if (kernel == nullptr) { MS_LOG(ERROR) << "kernel " << opParameter->name_ << " create failed."; + free(opParameter); return nullptr; } auto ret = kernel->Init(); diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/resize.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/resize.cc index 9e2289b6e8..a5bae33119 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/resize.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/resize.cc @@ -135,6 +135,7 @@ kernel::LiteKernel *OpenCLResizeKernelCreator(const std::vector auto *kernel = new (std::nothrow) ResizeOpenCLKernel(reinterpret_cast(opParameter), inputs, outputs); if (kernel == nullptr) { MS_LOG(ERROR) << "kernel " << opParameter->name_ << " create failed."; + free(opParameter); return nullptr; } auto ret = kernel->Init(); diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/scale.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/scale.cc index bfc9ad3d40..a5390b1848 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/scale.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/scale.cc @@ -357,6 +357,7 @@ kernel::LiteKernel *OpenCLScaleKernelCreator(const std::vector & new (std::nothrow) ScaleOpenCLKernel(reinterpret_cast(opParameter), inputs, outputs, ctx); if (kernel == nullptr) { MS_LOG(ERROR) << "Create OpenCL Scale kernel failed!"; + free(opParameter); return nullptr; } auto ret = kernel->Init(); diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/slice.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/slice.cc index 7c95688cc0..e464c65b36 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/slice.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/slice.cc @@ -124,6 +124,7 @@ kernel::LiteKernel *OpenCLSliceKernelCreator(const std::vector & auto *kernel = new (std::nothrow) SliceOpenCLKernel(opParameter, inputs, outputs); if (kernel == nullptr) { MS_LOG(ERROR) << " new SliceOpenCLKernel failed "; + free(opParameter); return nullptr; } auto ret = kernel->Init(); diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/softmax.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/softmax.cc index b92f018c37..86f6424f81 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/softmax.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/softmax.cc @@ -192,6 +192,7 @@ kernel::LiteKernel *OpenCLSoftMaxKernelCreator(const std::vector auto *kernel = new (std::nothrow) SoftmaxOpenCLKernel(reinterpret_cast(opParameter), inputs, outputs); if (kernel == nullptr) { MS_LOG(ERROR) << "kernel " << opParameter->name_ << "is nullptr."; + free(opParameter); delete kernel; return nullptr; } diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/space_to_batch_nd.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/space_to_batch_nd.cc index c0f115f867..8eb29cee5a 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/space_to_batch_nd.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/space_to_batch_nd.cc @@ -132,6 +132,7 @@ kernel::LiteKernel *OpenCLSpaceToBatchNDKernelCreator(const std::vectorname_ << " new failed."; + free(opParameter); return nullptr; } auto ret = kernel->Init(); diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/to_format.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/to_format.cc index f5e274519c..27a59c92fd 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/to_format.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/to_format.cc @@ -179,6 +179,7 @@ kernel::LiteKernel *OpenCLToFormatKernelCreator(const std::vector(opParameter), inputs, outputs); if (kernel == nullptr) { MS_LOG(ERROR) << "kernel " << opParameter->name_ << " create failed."; + free(opParameter); return nullptr; } auto ret = kernel->Init(); diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/transpose.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/transpose.cc index f79f10c513..cca38b6aee 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/transpose.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/transpose.cc @@ -131,6 +131,7 @@ kernel::LiteKernel *OpenCLTransposeKernelCreator(const std::vector(opParameter), inputs, outputs); if (kernel == nullptr) { MS_LOG(ERROR) << "kernel " << opParameter->name_ << "is nullptr."; + free(opParameter); return nullptr; } auto ret = kernel->Init();