Browse Source

!5620 check nullptr in lite/src/runtime

Merge pull request !5620 from lyvette/parser
tags/v1.0.0
mindspore-ci-bot Gitee 5 years ago
parent
commit
55650d2ef4
14 changed files with 61 additions and 13 deletions
  1. +3
    -1
      mindspore/lite/src/runtime/allocator.cc
  2. +5
    -1
      mindspore/lite/src/runtime/kernel/arm/base/matrix.cc
  3. +2
    -2
      mindspore/lite/src/runtime/kernel/arm/base/softmax_base.cc
  4. +4
    -1
      mindspore/lite/src/runtime/kernel/arm/fp16/deconvolution_fp16.h
  5. +4
    -1
      mindspore/lite/src/runtime/kernel/arm/fp32/convolution_1x1.h
  6. +5
    -1
      mindspore/lite/src/runtime/kernel/arm/fp32_grad/arithmetic_grad.cc
  7. +4
    -1
      mindspore/lite/src/runtime/kernel/arm/fp32_grad/bias_grad.cc
  8. +5
    -1
      mindspore/lite/src/runtime/kernel/arm/fp32_grad/bn_grad.cc
  9. +5
    -1
      mindspore/lite/src/runtime/kernel/arm/fp32_grad/convolution_grad_filter.cc
  10. +4
    -1
      mindspore/lite/src/runtime/kernel/arm/fp32_grad/opt_momentum.cc
  11. +5
    -1
      mindspore/lite/src/runtime/kernel/arm/fp32_grad/pooling_grad.cc
  12. +5
    -0
      mindspore/lite/src/runtime/kernel/arm/fp32_grad/power_grad.cc
  13. +5
    -1
      mindspore/lite/src/runtime/kernel/arm/fp32_grad/sparse_softmax_cross_entropy_with_logits.cc
  14. +5
    -0
      mindspore/lite/src/runtime/kernel/arm/int8/deconvolution_int8.cc

+ 3
- 1
mindspore/lite/src/runtime/allocator.cc View File

@@ -19,7 +19,9 @@
#include "utils/log_adapter.h"

namespace mindspore::lite {
std::shared_ptr<Allocator> Allocator::Create() { return std::shared_ptr<Allocator>(new DefaultAllocator()); }
std::shared_ptr<Allocator> Allocator::Create() {
return std::shared_ptr<Allocator>(new (std::nothrow) DefaultAllocator());
}

DefaultAllocator::DefaultAllocator() {}



+ 5
- 1
mindspore/lite/src/runtime/kernel/arm/base/matrix.cc View File

@@ -19,7 +19,11 @@

namespace mindspore::kernel {
Matrix *TransformMatrixGenerator(int m, int k) {
auto matrix = new Matrix;
auto matrix = new (std::nothrow) Matrix;
if (matrix == nullptr) {
MS_LOG(ERROR) << "matrix is nullptr.";
return nullptr;
}
auto data = malloc(m * k * sizeof(float));
if (data == nullptr) {
MS_LOG(ERROR) << "Malloc matrix data failed.";


+ 2
- 2
mindspore/lite/src/runtime/kernel/arm/base/softmax_base.cc View File

@@ -66,7 +66,7 @@ kernel::LiteKernel *CpuSoftmaxInt8KernelCreator(const std::vector<lite::tensor::
return nullptr;
}
MS_ASSERT(desc.type == schema::PrimitiveType_SoftMax);
SoftmaxInt8CPUKernel *kernel = new (std::nothrow) SoftmaxInt8CPUKernel(opParameter, inputs, outputs, ctx, primitive);
auto *kernel = new (std::nothrow) SoftmaxInt8CPUKernel(opParameter, inputs, outputs, ctx, primitive);
if (kernel == nullptr) {
MS_LOG(ERROR) << "new SoftmaxCPUKernel fail!";
return nullptr;
@@ -91,7 +91,7 @@ kernel::LiteKernel *CpuSoftmaxFp32KernelCreator(const std::vector<lite::tensor::
return nullptr;
}
MS_ASSERT(desc.type == schema::PrimitiveType_SoftMax);
SoftmaxCPUKernel *kernel = new (std::nothrow) SoftmaxCPUKernel(opParameter, inputs, outputs, ctx, primitive);
auto *kernel = new (std::nothrow) SoftmaxCPUKernel(opParameter, inputs, outputs, ctx, primitive);
if (kernel == nullptr) {
MS_LOG(ERROR) << "new SoftmaxCPUKernel fail!";
return nullptr;


+ 4
- 1
mindspore/lite/src/runtime/kernel/arm/fp16/deconvolution_fp16.h View File

@@ -36,7 +36,10 @@ class DeConvolutionFp16CPUKernel : public ConvolutionBaseFP16CPUKernel {
const std::vector<lite::tensor::Tensor *> &outputs, const lite::Context *ctx,
const mindspore::lite::PrimitiveC *primitive)
: ConvolutionBaseFP16CPUKernel(parameter, inputs, outputs, ctx, primitive) {
matmul_param_ = new MatMulParameter();
matmul_param_ = new (std::nothrow) MatMulParameter();
if (matmul_param_ == nullptr) {
MS_LOG(ERROR) << "new MatMulParameter fail!";
}
}
~DeConvolutionFp16CPUKernel() override;
int Init() override;


+ 4
- 1
mindspore/lite/src/runtime/kernel/arm/fp32/convolution_1x1.h View File

@@ -37,7 +37,10 @@ class Convolution1x1CPUKernel : public ConvolutionBaseCPUKernel {
const std::vector<lite::tensor::Tensor *> &outputs, const lite::Context *ctx,
const mindspore::lite::PrimitiveC *primitive)
: ConvolutionBaseCPUKernel(parameter, inputs, outputs, ctx, primitive) {
matmul_param_ = new MatMulParameter();
matmul_param_ = new (std::nothrow) MatMulParameter();
if (matmul_param_ == nullptr) {
MS_LOG(ERROR) << "new MatMulParameter fail!";
}
}
~Convolution1x1CPUKernel();
int Init() override;


+ 5
- 1
mindspore/lite/src/runtime/kernel/arm/fp32_grad/arithmetic_grad.cc View File

@@ -282,7 +282,11 @@ kernel::LiteKernel *CpuArithmeticGradFp32KernelCreator(const std::vector<lite::t
return nullptr;
}
auto *kernel = new (std::nothrow) ArithmeticGradCPUKernel(opParameter, inputs, outputs, ctx, primitive);
MS_ASSERT(kernel != nullptr);
if (kernel == nullptr) {
MS_LOG(ERROR) << "new ArithmeticGradCPUKernel fail!";
return nullptr;
}

auto ret = kernel->Init();
if (ret != RET_OK) {
MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: "


+ 4
- 1
mindspore/lite/src/runtime/kernel/arm/fp32_grad/bias_grad.cc View File

@@ -103,7 +103,10 @@ kernel::LiteKernel *CpuBiasGradFp32KernelCreator(const std::vector<lite::tensor:
MS_ASSERT(desc.type == schema::PrimitiveType_BiasGrad);
auto *kernel =
new (std::nothrow) BiasGradCPUKernel(reinterpret_cast<OpParameter *>(opParameter), inputs, outputs, ctx, primitive);
MS_ASSERT(kernel != nullptr);
if (kernel == nullptr) {
MS_LOG(ERROR) << "new BiasGradCPUKernel fail!";
return nullptr;
}

auto ret = kernel->Init();
if (RET_OK != ret) {


+ 5
- 1
mindspore/lite/src/runtime/kernel/arm/fp32_grad/bn_grad.cc View File

@@ -33,7 +33,11 @@ namespace mindspore::kernel {
int BNGradInputCPUKernel::Init() {
auto bn_param = reinterpret_cast<bnParameter *>(opParameter);
workspace_size = 5 * bn_param->channels;
workspace = new float[workspace_size];
workspace = new (std::nothrow) float[workspace_size];
if (workspace == nullptr) {
MS_LOG(ERROR) << "new workspace fail!";
return RET_ERROR;
}

if (2 != this->inputs_.size()) {
MS_LOG(ERROR) << "Conv2d Grad should has 2 inputs";


+ 5
- 1
mindspore/lite/src/runtime/kernel/arm/fp32_grad/convolution_grad_filter.cc View File

@@ -61,7 +61,11 @@ int ConvolutionGradFilterCPUKernel::Init() {
int ws_size = conv_param->output_h_ * conv_param->output_w_ * conv_param->kernel_h_ * conv_param->kernel_w_ *
conv_param->input_channel_ / conv_param->group_;

workspace = new float[ws_size];
workspace = new (std::nothrow) float[ws_size];
if (workspace == nullptr) {
MS_LOG(ERROR) << "new workspace fail!";
return RET_ERROR;
}

int output_w = 0;
int output_h = 0;


+ 4
- 1
mindspore/lite/src/runtime/kernel/arm/fp32_grad/opt_momentum.cc View File

@@ -68,7 +68,10 @@ kernel::LiteKernel *CpuOptMomentumFp32KernelCreator(const std::vector<lite::tens
const mindspore::lite::PrimitiveC *primitive) {
MS_ASSERT(desc.type == schema::PrimitiveType_OptMomentum);
auto *kernel = new (std::nothrow) OptMomentumCPUKernel(opParameter, inputs, outputs, ctx, primitive);
MS_ASSERT(kernel != nullptr);
if (kernel == nullptr) {
MS_LOG(ERROR) << "new OptMomentumCPUKernel fail!";
return nullptr;
}

auto ret = kernel->Init();
if (0 != ret) {


+ 5
- 1
mindspore/lite/src/runtime/kernel/arm/fp32_grad/pooling_grad.cc View File

@@ -181,7 +181,11 @@ kernel::LiteKernel *CpuPoolingGradFp32KernelCreator(const std::vector<lite::tens
MS_ASSERT(desc.type == schema::PrimitiveType_PoolingGrad);

auto *kernel = new (std::nothrow) PoolingGradCPUKernel(opParameter, inputs, outputs, ctx, primitive);
MS_ASSERT(kernel != nullptr);
if (kernel == nullptr) {
MS_LOG(ERROR) << "new PoolingGradCPUKernel fail!";
return nullptr;
}

auto ret = kernel->Init();
if (RET_OK != ret) {
MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: "


+ 5
- 0
mindspore/lite/src/runtime/kernel/arm/fp32_grad/power_grad.cc View File

@@ -55,6 +55,11 @@ kernel::LiteKernel *CpuPowerGradFp32KernelCreator(const std::vector<lite::tensor
MS_ASSERT(opParameter != nullptr);
MS_ASSERT(desc.type == schema::PrimitiveType_PowerGrad);
auto *kernel = new (std::nothrow) PowerGradCPUKernel(opParameter, inputs, outputs, ctx, primitive);
if (kernel == nullptr) {
MS_LOG(ERROR) << "new PowerGradCPUKernel fail!";
return nullptr;
}

auto ret = kernel->Init();
if (ret != RET_OK) {
MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: "


+ 5
- 1
mindspore/lite/src/runtime/kernel/arm/fp32_grad/sparse_softmax_cross_entropy_with_logits.cc View File

@@ -79,7 +79,11 @@ int SparseSoftmaxCrossEntropyWithLogitsCPUKernel::Run() {
}
size_t data_size = inputs_.at(0)->ElementsNum();
float *losses = new (std::nothrow) float[data_size];
MS_ASSERT(losses != nullptr);
if (losses == nullptr) {
MS_LOG(ERROR) << "losses is null";
return nullptr;
}

std::fill(losses, losses + data_size, 0);

MS_ASSERT(out != nullptr);


+ 5
- 0
mindspore/lite/src/runtime/kernel/arm/int8/deconvolution_int8.cc View File

@@ -29,6 +29,11 @@ namespace mindspore::kernel {
DeConvInt8CPUKernel::~DeConvInt8CPUKernel() {
FreeTmpBuffer();
ConvolutionBaseCPUKernel::FreeQuantParam();

if (matmul_param_ != nullptr) {
delete matmul_param_;
matmul_param_ = nullptr;
}
}

void DeConvInt8CPUKernel::FreeTmpBuffer() {


Loading…
Cancel
Save