From b4f2706a1543456f05e3852c47ecc6cf14e46883 Mon Sep 17 00:00:00 2001 From: yangruoqi713 Date: Sat, 30 Jul 2022 10:44:04 +0800 Subject: [PATCH] [CODE CHECK] clean some code check warnings --- include/api/data_type.h | 2 +- .../device/cpu/kernel/maxpool_grad_grad_cpu_kernel.cc | 1 + .../plugin/device/cpu/kernel/nnacl/base/gather_d_base.c | 4 ++-- .../device/cpu/kernel/nnacl/fp32_grad/maxpool_grad_grad.c | 1 + .../device/cpu/kernel/nnacl/fp32_grad/maxpool_grad_grad.h | 1 - .../ccsrc/plugin/device/cpu/kernel/nnacl/kernel/gather_d.c | 1 + mindspore/ccsrc/plugin/device/cpu/kernel/nnacl/op_base.h | 7 +++++++ 7 files changed, 13 insertions(+), 4 deletions(-) diff --git a/include/api/data_type.h b/include/api/data_type.h index 053244241b8..9c4958f2846 100644 --- a/include/api/data_type.h +++ b/include/api/data_type.h @@ -16,7 +16,7 @@ #ifndef MINDSPORE_INCLUDE_API_DATA_TYPE_H_ #define MINDSPORE_INCLUDE_API_DATA_TYPE_H_ -#include +#include namespace mindspore { enum class DataType : int { diff --git a/mindspore/ccsrc/plugin/device/cpu/kernel/maxpool_grad_grad_cpu_kernel.cc b/mindspore/ccsrc/plugin/device/cpu/kernel/maxpool_grad_grad_cpu_kernel.cc index 72ddc53c899..1a56a5cda80 100644 --- a/mindspore/ccsrc/plugin/device/cpu/kernel/maxpool_grad_grad_cpu_kernel.cc +++ b/mindspore/ccsrc/plugin/device/cpu/kernel/maxpool_grad_grad_cpu_kernel.cc @@ -22,6 +22,7 @@ #include "utils/profile.h" #include "mindspore/ccsrc/kernel/common_utils.h" #include "nnacl/fp32_grad/maxpool_grad_grad.h" +#include "nnacl/errorcode.h" namespace mindspore { namespace kernel { diff --git a/mindspore/ccsrc/plugin/device/cpu/kernel/nnacl/base/gather_d_base.c b/mindspore/ccsrc/plugin/device/cpu/kernel/nnacl/base/gather_d_base.c index 2f1f9e14656..176a04cada1 100644 --- a/mindspore/ccsrc/plugin/device/cpu/kernel/nnacl/base/gather_d_base.c +++ b/mindspore/ccsrc/plugin/device/cpu/kernel/nnacl/base/gather_d_base.c @@ -60,7 +60,7 @@ int InitCalVec(size_t *in_strides, size_t *out_strides, size_t *pos, const size_ for (size_t i = 0; i < input_shape_size; ++i) { in_strides[i] = 1; } - for (int i = input_shape_size - 2; i >= 0; --i) { + for (int i = (int)input_shape_size - 2; i >= 0; --i) { in_strides[i] = input_shape[i + 1] * in_strides[i + 1]; } @@ -69,7 +69,7 @@ int InitCalVec(size_t *in_strides, size_t *out_strides, size_t *pos, const size_ for (size_t i = 0; i < output_shape_size; ++i) { out_strides[i] = 1; } - for (int i = output_shape_size - 2; i >= 0; --i) { + for (int i = (int)output_shape_size - 2; i >= 0; --i) { out_strides[i] = output_shape[i + 1] * out_strides[i + 1]; } diff --git a/mindspore/ccsrc/plugin/device/cpu/kernel/nnacl/fp32_grad/maxpool_grad_grad.c b/mindspore/ccsrc/plugin/device/cpu/kernel/nnacl/fp32_grad/maxpool_grad_grad.c index f6ee3dbca69..2a2ae77b2d3 100644 --- a/mindspore/ccsrc/plugin/device/cpu/kernel/nnacl/fp32_grad/maxpool_grad_grad.c +++ b/mindspore/ccsrc/plugin/device/cpu/kernel/nnacl/fp32_grad/maxpool_grad_grad.c @@ -14,6 +14,7 @@ * limitations under the License. */ #include "nnacl/fp32_grad/maxpool_grad_grad.h" +#include "nnacl/errorcode.h" int MaxPoolGradGrad(const float *input, const float *grad, float *output, size_t start, size_t end, PoolingParameter *param) { diff --git a/mindspore/ccsrc/plugin/device/cpu/kernel/nnacl/fp32_grad/maxpool_grad_grad.h b/mindspore/ccsrc/plugin/device/cpu/kernel/nnacl/fp32_grad/maxpool_grad_grad.h index 7bb2297ddf7..b6dda8a909a 100644 --- a/mindspore/ccsrc/plugin/device/cpu/kernel/nnacl/fp32_grad/maxpool_grad_grad.h +++ b/mindspore/ccsrc/plugin/device/cpu/kernel/nnacl/fp32_grad/maxpool_grad_grad.h @@ -19,7 +19,6 @@ #include "nnacl/op_base.h" #include "nnacl/pooling_parameter.h" -#include "nnacl/errorcode.h" #ifdef __cplusplus extern "C" { diff --git a/mindspore/ccsrc/plugin/device/cpu/kernel/nnacl/kernel/gather_d.c b/mindspore/ccsrc/plugin/device/cpu/kernel/nnacl/kernel/gather_d.c index 94fad95f8c8..d31ab165739 100644 --- a/mindspore/ccsrc/plugin/device/cpu/kernel/nnacl/kernel/gather_d.c +++ b/mindspore/ccsrc/plugin/device/cpu/kernel/nnacl/kernel/gather_d.c @@ -106,6 +106,7 @@ int gather_d_compute(struct KernelBase *self) { KernelBase *CreateGatherD(OpParameter *param, TensorC *in, size_t insize, TensorC *out, size_t outsize, int data_type, FormatC format) { GatherDStru *gather_d = (GatherDStru *)malloc(sizeof(GatherDStru)); + NNACL_CHECK_NULL_RETURN_NULL(gather_d); gather_d->base.param = param; gather_d->base.in = in; gather_d->base.insize = insize; diff --git a/mindspore/ccsrc/plugin/device/cpu/kernel/nnacl/op_base.h b/mindspore/ccsrc/plugin/device/cpu/kernel/nnacl/op_base.h index e52bb851864..cc16cdb2f64 100644 --- a/mindspore/ccsrc/plugin/device/cpu/kernel/nnacl/op_base.h +++ b/mindspore/ccsrc/plugin/device/cpu/kernel/nnacl/op_base.h @@ -173,6 +173,7 @@ #define NNACL_CHECK_ZERO_RETURN(val) #define NNACL_CHECK_NULL_RETURN_ERR(ptr) #define NNACL_CHECK_NULL_RETURN_VOID(ptr) +#define NNACL_CHECK_NULL_RETURN_NULL(ptr) #else // Check whether value is true, if not return 'errcode' #define MS_CHECK_TRUE_RET(value, errcode) \ @@ -288,6 +289,12 @@ } \ } while (0) +#define NNACL_CHECK_NULL_RETURN_NULL(ptr) \ + do { \ + if ((ptr) == NULL) { \ + return NULL; \ + } \ + } while (0) #endif enum PrimType {