From 099fb9e80ebc7643f8fa10a40eabf6b3811d9e8d Mon Sep 17 00:00:00 2001 From: yefeng Date: Fri, 27 Aug 2021 10:47:35 +0800 Subject: [PATCH] code review --- mindspore/lite/src/runtime/kernel/arm/base/slice_base.cc | 4 ++-- .../src/runtime/kernel/arm/control/tensorlist_setitem.cc | 1 - mindspore/lite/src/runtime/kernel/arm/fp16/slice_fp16.cc | 5 +++-- mindspore/lite/src/runtime/kernel/arm/fp32/adder_fp32.cc | 1 + .../lite/src/runtime/kernel/arm/fp32/batchnorm_fp32.cc | 2 +- .../lite/src/runtime/kernel/arm/int8/batchnorm_int8.cc | 1 + mindspore/lite/src/runtime/kernel/arm/int8/slice_int8.cc | 5 +++-- .../lite/src/runtime/kernel/arm/string/extract_feature.cc | 1 + .../lite/src/runtime/kernel/arm/string/lsh_projection.cc | 1 + mindspore/lite/src/runtime/kernel/arm/string/skip_gram.cc | 5 +++-- .../lite/src/runtime/kernel/opencl/kernel/batchnorm.cc | 7 ++++++- 11 files changed, 22 insertions(+), 11 deletions(-) diff --git a/mindspore/lite/src/runtime/kernel/arm/base/slice_base.cc b/mindspore/lite/src/runtime/kernel/arm/base/slice_base.cc index 2f329518189..151bbc91915 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/slice_base.cc +++ b/mindspore/lite/src/runtime/kernel/arm/base/slice_base.cc @@ -65,8 +65,8 @@ int SliceCPUKernel::ReSize() { } int SliceCPUKernel::Init() { - CHECK_LESS_RETURN(in_tensors_, 3); - CHECK_LESS_RETURN(out_tensors_, 1); + CHECK_LESS_RETURN(in_tensors_.size(), 3); + CHECK_LESS_RETURN(out_tensors_.size(), 1); if (!InferShapeDone()) { return RET_OK; } diff --git a/mindspore/lite/src/runtime/kernel/arm/control/tensorlist_setitem.cc b/mindspore/lite/src/runtime/kernel/arm/control/tensorlist_setitem.cc index 83ee5635988..38cfec4fd4a 100644 --- a/mindspore/lite/src/runtime/kernel/arm/control/tensorlist_setitem.cc +++ b/mindspore/lite/src/runtime/kernel/arm/control/tensorlist_setitem.cc @@ -70,7 +70,6 @@ int TensorListSetItemCPUKernel::Run() { int dim0 = output0_->ElementsNum() - 1; index_ = reinterpret_cast(in_tensors_[1]->data_c())[0]; - CHECK_NULL_RETURN(index_); if (index_ < 0 || index_ > dim0) { if (IncrementOutputSize(output0_->tensors().size()) != RET_OK) { MS_LOG(ERROR) << "Resizeoutput Error ,index tensor:[" << index_ << "] must be in [0, " << dim0 << "]!"; 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 2afb0230f8e..08f359a0d1f 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/slice_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/slice_fp16.cc @@ -21,6 +21,7 @@ using mindspore::lite::KernelRegistrar; using mindspore::lite::RET_ERROR; +using mindspore::lite::RET_NULL_PTR; using mindspore::lite::RET_OK; using mindspore::schema::PrimitiveType_SliceFusion; @@ -43,8 +44,8 @@ SliceFp16CPUKernel::~SliceFp16CPUKernel() { } int SliceFp16CPUKernel::Init() { - CHECK_LESS_RETURN(in_tensors_, 1); - CHECK_LESS_RETURN(out_tensors_, 1); + CHECK_LESS_RETURN(in_tensors_.size(), 1); + CHECK_LESS_RETURN(out_tensors_.size(), 1); auto input_tensor = in_tensors_.at(0); if (input_tensor->data_type() == kNumberTypeFloat32 && input_tensor->data_c() != nullptr) { input_data_ = diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/adder_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/adder_fp32.cc index 8038cb2b40c..06078b43ce1 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/adder_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/adder_fp32.cc @@ -25,6 +25,7 @@ using mindspore::kernel::KERNEL_ARCH; using mindspore::lite::KernelRegistrar; using mindspore::lite::RET_ERROR; using mindspore::lite::RET_INFER_INVALID; +using mindspore::lite::RET_NULL_PTR; using mindspore::lite::RET_OK; using mindspore::schema::Format; using mindspore::schema::PrimitiveType_AdderFusion; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/batchnorm_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/batchnorm_fp32.cc index 07017835f4c..cadb7c43219 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/batchnorm_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/batchnorm_fp32.cc @@ -19,6 +19,7 @@ using mindspore::lite::KernelRegistrar; using mindspore::lite::RET_ERROR; +using mindspore::lite::RET_NULL_PTR; using mindspore::lite::RET_OK; using mindspore::schema::PrimitiveType_BatchNorm; @@ -53,7 +54,6 @@ void BatchnormCPUKernel::FillParam() { auto input_shapes = in_tensors_.at(0)->shape(); auto n_dim = input_shapes.size(); auto param = reinterpret_cast(op_parameter_); - CHECK_NULL_RETURN(param); param->channel_ = input_shapes[n_dim - 1]; param->unit_ = 1; for (size_t i = 0; i < n_dim - 1; i++) { diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/batchnorm_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/batchnorm_int8.cc index ac03bf3f8b2..504a48e4c6e 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/batchnorm_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/batchnorm_int8.cc @@ -24,6 +24,7 @@ using mindspore::kernel::KERNEL_ARCH; using mindspore::lite::KernelRegistrar; using mindspore::lite::RET_ERROR; +using mindspore::lite::RET_NULL_PTR; using mindspore::lite::RET_OK; using mindspore::schema::PrimitiveType_BatchNorm; using mindspore::schema::PrimitiveType_FusedBatchNorm; 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 c7494f2282a..7cc068b2833 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/slice_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/slice_int8.cc @@ -22,13 +22,14 @@ using mindspore::lite::KernelRegistrar; using mindspore::lite::RET_ERROR; +using mindspore::lite::RET_NULL_PTR; using mindspore::lite::RET_OK; using mindspore::schema::PrimitiveType_SliceFusion; namespace mindspore::kernel { int SliceInt8CPUKernel::Init() { - CHECK_LESS_RETURN(in_tensors_, 1); - CHECK_LESS_RETURN(out_tensors_, 1); + CHECK_LESS_RETURN(in_tensors_.size(), 1); + CHECK_LESS_RETURN(out_tensors_.size(), 1); auto input = in_tensors_.at(0); auto output = out_tensors_.at(0); MS_ASSERT(input != nullptr); 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 a39600ab000..8c428d89bd8 100644 --- a/mindspore/lite/src/runtime/kernel/arm/string/extract_feature.cc +++ b/mindspore/lite/src/runtime/kernel/arm/string/extract_feature.cc @@ -19,6 +19,7 @@ using mindspore::lite::KernelRegistrar; using mindspore::lite::RET_ERROR; +using mindspore::lite::RET_NULL_PTR; using mindspore::lite::RET_OK; using mindspore::schema::PrimitiveType_CustomExtractFeatures; diff --git a/mindspore/lite/src/runtime/kernel/arm/string/lsh_projection.cc b/mindspore/lite/src/runtime/kernel/arm/string/lsh_projection.cc index ba62ca081f3..fd770b15ef2 100644 --- a/mindspore/lite/src/runtime/kernel/arm/string/lsh_projection.cc +++ b/mindspore/lite/src/runtime/kernel/arm/string/lsh_projection.cc @@ -22,6 +22,7 @@ using mindspore::kernel::KERNEL_ARCH; using mindspore::lite::KernelRegistrar; using mindspore::lite::RET_ERROR; +using mindspore::lite::RET_NULL_PTR; using mindspore::lite::RET_OK; using mindspore::schema::PrimitiveType_LshProjection; diff --git a/mindspore/lite/src/runtime/kernel/arm/string/skip_gram.cc b/mindspore/lite/src/runtime/kernel/arm/string/skip_gram.cc index 1b481eb54ea..83d2dceebaf 100644 --- a/mindspore/lite/src/runtime/kernel/arm/string/skip_gram.cc +++ b/mindspore/lite/src/runtime/kernel/arm/string/skip_gram.cc @@ -21,6 +21,7 @@ using mindspore::lite::KernelRegistrar; using mindspore::lite::RET_ERROR; +using mindspore::lite::RET_NULL_PTR; using mindspore::lite::RET_OK; using mindspore::lite::StringPack; using mindspore::schema::PrimitiveType_SkipGram; @@ -38,7 +39,7 @@ int SkipGramCPUKernel::Init() { int SkipGramCPUKernel::ReSize() { return RET_OK; } void ParseSentenceToWords(const StringPack &sentence, std::vector *words) { - CHECK_NULL_RETURN(words); + MS_ASSERT(words != nullptr); int pre = 0; int i; for (i = 0; i < sentence.len; i++) { @@ -78,7 +79,7 @@ int SkipGramCPUKernel::Run() { int index = 1; int size = words.size(); - CHECK_LESS_RETURN(stack.size(), index); + CHECK_LESS_RETURN(static_cast(stack.size()), index); while (index >= 0) { if (index < skip_gram_parameter_->ngram_size && stack.at(index) + 1 < size && (index == 0 || stack.at(index) - stack.at(index - 1) <= skip_gram_parameter_->max_skip_size)) { diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/batchnorm.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/batchnorm.cc index 56577306bbe..e0d82d4247a 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/batchnorm.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/batchnorm.cc @@ -163,7 +163,10 @@ int BatchNormOpenCLKernel::Initweight() { memset(offset_, 0x00, weight_size); memset(mean_, 0x00, weight_size); memset(variance_, 0x00, weight_size); - + CHECK_NULL_RETURN(in_tensors_.at(1)->data_c()); + CHECK_NULL_RETURN(in_tensors_.at(2)->data_c()); + CHECK_NULL_RETURN(in_tensors_.at(3)->data_c()); + CHECK_NULL_RETURN(in_tensors_.at(4)->data_c()); if (weight_tensor->data_type() == kNumberTypeFloat16) { if (use_fp16_enable_) { memcpy(scale_, in_tensors_.at(1)->data_c(), weight_size); @@ -251,6 +254,8 @@ int BatchNormOpenCLKernel::Prepare() { } int BatchNormOpenCLKernel::Run() { + CHECK_NULL_RETURN(in_tensors_.at(0)->data_c()); + CHECK_NULL_RETURN(out_tensors_.at(0)->data_c()); MS_LOG(DEBUG) << this->name() << " Running! "; int arg_cn = 0; if (ocl_runtime_->SetKernelArg(kernel_, arg_cn++, in_tensors_.at(0)->data_c()) != CL_SUCCESS) {