fix code review

This commit is contained in:
sunsuodong 2020-11-28 16:30:41 +08:00
parent 06bc0bd9e1
commit 8dbf7a1033
78 changed files with 124 additions and 107 deletions

View File

@ -115,6 +115,9 @@ int GetStringCount(const void *data) { return *(static_cast<const int32_t *>(dat
int GetStringCount(Tensor *tensor) { return GetStringCount(tensor->MutableData()); }
int StringsToMSTensor(const std::vector<std::string> &inputs, tensor::MSTensor *tensor) {
if (tensor == nullptr) {
return RET_PARAM_INVALID;
}
std::vector<StringPack> all_pack;
for (auto &input : inputs) {
StringPack pack = {static_cast<int>(input.length()), input.data()};
@ -124,6 +127,9 @@ int StringsToMSTensor(const std::vector<std::string> &inputs, tensor::MSTensor *
}
std::vector<std::string> MSTensorToStrings(const tensor::MSTensor *tensor) {
if (tensor == nullptr) {
return {""};
}
const void *ptr = static_cast<const Tensor *>(tensor)->data_c();
std::vector<StringPack> all_pack = ParseStringBuffer(ptr);
std::vector<std::string> result(all_pack.size());

View File

@ -104,9 +104,9 @@ kernel::LiteKernel *CpuArgMinMaxFp32KernelCreator(const std::vector<lite::Tensor
}
auto ret = kernel->Init();
if (ret != RET_OK) {
delete kernel;
MS_LOG(ERROR) << "Init kernel failed, name: " << op_parameter->name_ << ", type: "
<< schema::EnumNamePrimitiveType(static_cast<schema::PrimitiveType>(op_parameter->type_));
delete kernel;
return nullptr;
}
return kernel;

View File

@ -70,9 +70,9 @@ kernel::LiteKernel *CpuBatchToSpaceFp32KernelCreator(const std::vector<lite::Ten
auto ret = kernel->Init();
if (ret != RET_OK) {
delete kernel;
MS_LOG(ERROR) << "Init kernel failed, name: " << op_parameter->name_ << ", type: "
<< schema::EnumNamePrimitiveType(static_cast<schema::PrimitiveType>(op_parameter->type_));
delete kernel;
return nullptr;
}
return kernel;

View File

@ -51,9 +51,9 @@ kernel::LiteKernel *CpuConcatInt32KernelCreator(const std::vector<lite::Tensor *
}
auto ret = kernel->Init();
if (ret != RET_OK) {
delete kernel;
MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: "
<< schema::EnumNamePrimitiveType(static_cast<schema::PrimitiveType>(opParameter->type_));
delete kernel;
return nullptr;
}
return kernel;
@ -76,9 +76,9 @@ kernel::LiteKernel *CpuConcatFp32KernelCreator(const std::vector<lite::Tensor *>
}
auto ret = kernel->Init();
if (ret != RET_OK) {
delete kernel;
MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: "
<< schema::EnumNamePrimitiveType(static_cast<schema::PrimitiveType>(opParameter->type_));
delete kernel;
return nullptr;
}
return kernel;

View File

@ -98,9 +98,9 @@ kernel::LiteKernel *CpuCropInt32KernelCreator(const std::vector<lite::Tensor *>
}
auto ret = kernel->Init();
if (ret != RET_OK) {
delete kernel;
MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: "
<< schema::EnumNamePrimitiveType(static_cast<schema::PrimitiveType>(opParameter->type_));
delete kernel;
return nullptr;
}
return kernel;
@ -123,9 +123,9 @@ kernel::LiteKernel *CpuCropFp32KernelCreator(const std::vector<lite::Tensor *> &
}
auto ret = kernel->Init();
if (ret != RET_OK) {
delete kernel;
MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: "
<< schema::EnumNamePrimitiveType(static_cast<schema::PrimitiveType>(opParameter->type_));
delete kernel;
return nullptr;
}
return kernel;

View File

@ -79,9 +79,9 @@ kernel::LiteKernel *CpuDepthToSpaceFp32KernelCreator(const std::vector<lite::Ten
auto ret = kernel->Init();
if (ret != RET_OK) {
delete kernel;
MS_LOG(ERROR) << "Init kernel failed, name: " << op_parameter->name_ << ", type: "
<< schema::EnumNamePrimitiveType(static_cast<schema::PrimitiveType>(op_parameter->type_));
delete kernel;
return nullptr;
}
return kernel;

View File

@ -66,7 +66,6 @@ kernel::LiteKernel *CpuFullConnectionFp32KernelCreator(const std::vector<lite::T
}
auto ret = kernel->Init();
if (ret != RET_OK) {
delete kernel;
MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: "
<< schema::EnumNamePrimitiveType(static_cast<schema::PrimitiveType>(opParameter->type_));
if (dequant_flag) {
@ -74,6 +73,7 @@ kernel::LiteKernel *CpuFullConnectionFp32KernelCreator(const std::vector<lite::T
weight_tensor->set_data(restore_data);
weight_tensor->set_data_type(restore_type);
}
delete kernel;
return nullptr;
}
if (dequant_flag) {

View File

@ -45,9 +45,9 @@ kernel::LiteKernel *CpuMatmulKernelCreator(const std::vector<lite::Tensor *> &in
}
auto ret = kernel->Init();
if (ret != RET_OK) {
delete kernel;
MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: "
<< schema::EnumNamePrimitiveType(static_cast<schema::PrimitiveType>(opParameter->type_));
delete kernel;
return nullptr;
}
return kernel;

View File

@ -41,9 +41,9 @@ kernel::LiteKernel *CpuPadFp32KernelCreator(const std::vector<lite::Tensor *> &i
}
auto ret = kernel->Init();
if (ret != RET_OK) {
delete kernel;
MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: "
<< schema::EnumNamePrimitiveType(static_cast<schema::PrimitiveType>(opParameter->type_));
delete kernel;
return nullptr;
}
return kernel;

View File

@ -47,8 +47,8 @@ int PoolingBaseCPUKernel::SetQuantParam() {
if (pooling_quant_arg_[1] == nullptr) {
MS_LOG(ERROR) << "malloc pooling_quant_arg[1] failed.";
free(pooling_quant_arg_[0]);
free(pooling_quant_arg_);
pooling_quant_arg_[0] = nullptr;
free(pooling_quant_arg_);
pooling_quant_arg_ = nullptr;
return RET_MEMORY_FAILED;
}
@ -127,9 +127,9 @@ kernel::LiteKernel *CpuPoolingFp32KernelCreator(const std::vector<lite::Tensor *
}
auto ret = kernel->Init();
if (ret != RET_OK) {
delete kernel;
MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: "
<< schema::EnumNamePrimitiveType(static_cast<schema::PrimitiveType>(opParameter->type_));
delete kernel;
return nullptr;
}
return kernel;

View File

@ -44,9 +44,9 @@ kernel::LiteKernel *CpuPowerFp32KernelCreator(const std::vector<lite::Tensor *>
}
auto ret = kernel->Init();
if (ret != RET_OK) {
delete kernel;
MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: "
<< schema::EnumNamePrimitiveType(static_cast<schema::PrimitiveType>(opParameter->type_));
delete kernel;
return nullptr;
}
return kernel;

View File

@ -44,8 +44,8 @@ int PriorBoxCPUKernel::Init() {
MS_LOG(ERROR) << "Size of input tensors is wrong.";
return RET_ERROR;
}
if (in_tensors_.size() != kOutputNum) {
MS_LOG(ERROR) << "Size of input tensors is wrong.";
if (out_tensors_.size() != kOutputNum) {
MS_LOG(ERROR) << "Size of output tensors is wrong.";
return RET_ERROR;
}
@ -195,9 +195,9 @@ kernel::LiteKernel *CpuPriorBoxKernelCreator(const std::vector<lite::Tensor *> &
}
auto ret = kernel->Init();
if (ret != RET_OK) {
delete kernel;
MS_LOG(ERROR) << "Init kernel failed, name: " << op_parameter->name_ << ", type: "
<< schema::EnumNamePrimitiveType(static_cast<schema::PrimitiveType>(op_parameter->type_));
delete kernel;
return nullptr;
}
return kernel;

View File

@ -46,9 +46,9 @@ kernel::LiteKernel *CpuReshapeInt32KernelCreator(const std::vector<lite::Tensor
}
auto ret = kernel->Init();
if (ret != RET_OK) {
delete kernel;
MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: "
<< schema::EnumNamePrimitiveType(static_cast<schema::PrimitiveType>(opParameter->type_));
delete kernel;
return nullptr;
}
return kernel;
@ -71,9 +71,9 @@ kernel::LiteKernel *CpuReshapeFp32KernelCreator(const std::vector<lite::Tensor *
}
auto ret = kernel->Init();
if (ret != RET_OK) {
delete kernel;
MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: "
<< schema::EnumNamePrimitiveType(static_cast<schema::PrimitiveType>(opParameter->type_));
delete kernel;
return nullptr;
}
return kernel;

View File

@ -144,9 +144,9 @@ kernel::LiteKernel *CpuResizeFp32KernelCreator(const std::vector<lite::Tensor *>
}
auto ret = kernel->Init();
if (ret != RET_OK) {
delete kernel;
MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: "
<< schema::EnumNamePrimitiveType(static_cast<schema::PrimitiveType>(opParameter->type_));
delete kernel;
return nullptr;
}

View File

@ -72,9 +72,9 @@ kernel::LiteKernel *CpuSoftmaxFp32KernelCreator(const std::vector<lite::Tensor *
}
auto ret = kernel->Init();
if (ret != RET_OK) {
delete kernel;
MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: "
<< schema::EnumNamePrimitiveType(static_cast<schema::PrimitiveType>(opParameter->type_));
delete kernel;
return nullptr;
}
return kernel;

View File

@ -119,9 +119,9 @@ kernel::LiteKernel *CpuSplitFp32KernelCreator(const std::vector<lite::Tensor *>
}
auto ret = kernel->Init();
if (ret != RET_OK) {
delete kernel;
MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: "
<< schema::EnumNamePrimitiveType(static_cast<schema::PrimitiveType>(opParameter->type_));
delete kernel;
return nullptr;
}
return kernel;

View File

@ -150,9 +150,9 @@ kernel::LiteKernel *CpuActivationFp16KernelCreator(const std::vector<lite::Tenso
}
auto ret = kernel->Init();
if (ret != RET_OK) {
delete kernel;
MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: "
<< schema::EnumNamePrimitiveType(static_cast<schema::PrimitiveType>(opParameter->type_));
delete kernel;
return nullptr;
}
return kernel;

View File

@ -154,9 +154,9 @@ kernel::LiteKernel *CpuCastFp16KernelCreator(const std::vector<lite::Tensor *> &
}
auto ret = kernel->Init();
if (ret != RET_OK) {
delete kernel;
MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: "
<< schema::EnumNamePrimitiveType(static_cast<schema::PrimitiveType>(opParameter->type_));
delete kernel;
return nullptr;
}
return kernel;

View File

@ -174,7 +174,6 @@ kernel::LiteKernel *CpuConvDwFp16KernelCreator(const std::vector<lite::Tensor *>
}
auto ret = kernel->Init();
if (ret != RET_OK) {
delete kernel;
MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: "
<< schema::EnumNamePrimitiveType(static_cast<schema::PrimitiveType>(opParameter->type_));
if (dequant_flag) {
@ -182,6 +181,7 @@ kernel::LiteKernel *CpuConvDwFp16KernelCreator(const std::vector<lite::Tensor *>
weight_tensor->set_data(restore_data);
weight_tensor->set_data_type(restore_type);
}
delete kernel;
return nullptr;
}
if (dequant_flag) {

View File

@ -464,7 +464,6 @@ kernel::LiteKernel *CpuConvFp16KernelCreator(const std::vector<lite::Tensor *> &
}
auto ret = kernel->Init();
if (ret != RET_OK) {
delete kernel;
MS_LOG(INFO) << "Init fp16 kernel failed, name: " << opParameter->name_
<< ", type: " << schema::EnumNamePrimitiveType(static_cast<schema::PrimitiveType>(opParameter->type_));
if (dequant_flag) {
@ -472,6 +471,7 @@ kernel::LiteKernel *CpuConvFp16KernelCreator(const std::vector<lite::Tensor *> &
weight_tensor->set_data(restore_data);
weight_tensor->set_data_type(restore_type);
}
delete kernel;
return nullptr;
}
if (dequant_flag) {

View File

@ -110,9 +110,9 @@ kernel::LiteKernel *CpuCropFp16KernelCreator(const std::vector<lite::Tensor *> &
}
auto ret = kernel->Init();
if (ret != RET_OK) {
delete kernel;
MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: "
<< schema::EnumNamePrimitiveType(static_cast<schema::PrimitiveType>(opParameter->type_));
delete kernel;
return nullptr;
}
return kernel;

View File

@ -241,7 +241,6 @@ kernel::LiteKernel *CpuDeconvDwFp16KernelCreator(const std::vector<lite::Tensor
}
auto ret = kernel->Init();
if (ret != RET_OK) {
delete kernel;
MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: "
<< schema::EnumNamePrimitiveType(static_cast<schema::PrimitiveType>(opParameter->type_));
if (dequant_flag) {
@ -249,6 +248,7 @@ kernel::LiteKernel *CpuDeconvDwFp16KernelCreator(const std::vector<lite::Tensor
weight_tensor->set_data(restore_data);
weight_tensor->set_data_type(restore_type);
}
delete kernel;
return nullptr;
}
if (dequant_flag) {

View File

@ -167,6 +167,11 @@ int DeConvolutionFp16CPUKernel::DoDeconv(int task_id) {
}
int DeConvolutionFp16CPUKernel::Init() {
matmul_param_ = new (std::nothrow) MatMulParameter();
if (matmul_param_ == nullptr) {
MS_LOG(ERROR) << "Memory allocation failed";
return RET_ERROR;
}
int ret = InitWeightBias();
if (ret != RET_OK) {
MS_LOG(ERROR) << "deconv InitWeightBias error!";
@ -251,7 +256,6 @@ kernel::LiteKernel *CpuDeConvFp16KernelCreator(const std::vector<lite::Tensor *>
}
auto ret = kernel->Init();
if (ret != RET_OK) {
delete kernel;
MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: "
<< schema::EnumNamePrimitiveType(static_cast<schema::PrimitiveType>(opParameter->type_));
if (dequant_flag) {
@ -259,6 +263,7 @@ kernel::LiteKernel *CpuDeConvFp16KernelCreator(const std::vector<lite::Tensor *>
weight_tensor->set_data(restore_data);
weight_tensor->set_data_type(restore_type);
}
delete kernel;
return nullptr;
}
if (dequant_flag) {

View File

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

View File

@ -361,6 +361,16 @@ int DeConvWinogradFp16CPUKernel::ReSize() {
}
int DeConvWinogradFp16CPUKernel::Init() {
deconv_param_ = new (std::nothrow) DeConvParam();
if (deconv_param_ == nullptr) {
MS_LOG(ERROR) << "Memory allocation failed";
return RET_ERROR;
}
for (auto &wg : deconv_param_->a_buffer_) {
wg.buf_init_ = false;
wg.dest_buffer_ = nullptr;
wg.middle_buffer_ = nullptr;
}
int error_code = InitComputeParam();
if (error_code != RET_OK) {
MS_LOG(ERROR) << "InitComputeParam error! ret: " << error_code;

View File

@ -30,14 +30,7 @@ class DeConvWinogradFp16CPUKernel : public ConvolutionBaseFP16CPUKernel {
DeConvWinogradFp16CPUKernel(OpParameter *parameter, const std::vector<lite::Tensor *> &inputs,
const std::vector<lite::Tensor *> &outputs, const lite::InnerContext *ctx,
const mindspore::lite::PrimitiveC *primitive)
: ConvolutionBaseFP16CPUKernel(parameter, inputs, outputs, ctx, primitive) {
deconv_param_ = new DeConvParam();
for (auto &wg : deconv_param_->a_buffer_) {
wg.buf_init_ = false;
wg.dest_buffer_ = nullptr;
wg.middle_buffer_ = nullptr;
}
}
: ConvolutionBaseFP16CPUKernel(parameter, inputs, outputs, ctx, primitive) {}
~DeConvWinogradFp16CPUKernel() override;
int Init() override;
int Run() override;

View File

@ -269,12 +269,12 @@ kernel::LiteKernel *CpuFullConnectionFp16KernelCreator(const std::vector<lite::T
if (ret != RET_OK) {
MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: "
<< schema::EnumNamePrimitiveType(static_cast<schema::PrimitiveType>(opParameter->type_));
delete kernel;
if (dequant_flag) {
weight_tensor->FreeData();
weight_tensor->set_data(restore_data);
weight_tensor->set_data_type(restore_type);
}
delete kernel;
return nullptr;
}
if (dequant_flag) {

View File

@ -96,9 +96,9 @@ kernel::LiteKernel *CpuFusedBatchnormFp16KernelCreator(const std::vector<lite::T
}
auto ret = kernel->Init();
if (ret != RET_OK) {
delete kernel;
MS_LOG(ERROR) << "Init kernel failed, name: " << op_parameter->name_ << ", type: "
<< schema::EnumNamePrimitiveType(static_cast<schema::PrimitiveType>(op_parameter->type_));
delete kernel;
return nullptr;
}
return kernel;

View File

@ -129,9 +129,9 @@ kernel::LiteKernel *CpuPoolingFp16KernelCreator(const std::vector<lite::Tensor *
}
auto ret = kernel->Init();
if (ret != RET_OK) {
delete kernel;
MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: "
<< schema::EnumNamePrimitiveType(static_cast<schema::PrimitiveType>(opParameter->type_));
delete kernel;
return nullptr;
}
return kernel;

View File

@ -86,9 +86,9 @@ kernel::LiteKernel *CpuReshapeFp16KernelCreator(const std::vector<lite::Tensor *
}
auto ret = kernel->Init();
if (ret != RET_OK) {
delete kernel;
MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: "
<< schema::EnumNamePrimitiveType(static_cast<schema::PrimitiveType>(opParameter->type_));
delete kernel;
return nullptr;
}
return kernel;

View File

@ -119,6 +119,7 @@ int ScaleFp16CPUKernel::Run() {
ret = ParallelLaunch(this->context_->thread_pool_, ScaleFp16Run, this, op_parameter_->thread_num_);
if (ret != RET_OK) {
MS_LOG(ERROR) << "Scale error error_code[" << ret << "]";
FreeTmpBuffer();
return RET_ERROR;
}

View File

@ -136,9 +136,9 @@ kernel::LiteKernel *CpuSoftmaxFp16KernelCreator(const std::vector<lite::Tensor *
}
auto ret = kernel->Init();
if (ret != RET_OK) {
delete kernel;
MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: "
<< schema::EnumNamePrimitiveType(static_cast<schema::PrimitiveType>(opParameter->type_));
delete kernel;
return nullptr;
}
return kernel;

View File

@ -133,9 +133,9 @@ kernel::LiteKernel *CpuSplitFp16KernelCreator(const std::vector<lite::Tensor *>
}
auto ret = kernel->Init();
if (ret != RET_OK) {
delete kernel;
MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: "
<< schema::EnumNamePrimitiveType(static_cast<schema::PrimitiveType>(opParameter->type_));
delete kernel;
return nullptr;
}
return kernel;

View File

@ -118,9 +118,9 @@ kernel::LiteKernel *CpuStackFp16KernelCreator(const std::vector<lite::Tensor *>
auto ret = kernel->Init();
if (ret != RET_OK) {
delete kernel;
MS_LOG(ERROR) << "Init kernel failed, name: " << op_parameter->name_ << ", type: "
<< schema::EnumNamePrimitiveType(static_cast<schema::PrimitiveType>(op_parameter->type_));
delete kernel;
return nullptr;
}
return kernel;

View File

@ -118,9 +118,9 @@ kernel::LiteKernel *CpuActivationFp32KernelCreator(const std::vector<lite::Tenso
}
auto ret = kernel->Init();
if (ret != RET_OK) {
delete kernel;
MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: "
<< schema::EnumNamePrimitiveType(static_cast<schema::PrimitiveType>(opParameter->type_));
delete kernel;
return nullptr;
}
return kernel;

View File

@ -74,9 +74,9 @@ kernel::LiteKernel *CpuBroadcastToFp32KernelCreator(const std::vector<lite::Tens
auto ret = kernel->Init();
if (ret != RET_OK) {
delete kernel;
MS_LOG(ERROR) << "Init kernel failed, name: " << op_parameter->name_ << ", type: "
<< schema::EnumNamePrimitiveType(static_cast<schema::PrimitiveType>(op_parameter->type_));
delete kernel;
return nullptr;
}
return kernel;

View File

@ -153,9 +153,9 @@ kernel::LiteKernel *CpuCastFp32KernelCreator(const std::vector<lite::Tensor *> &
}
auto ret = kernel->Init();
if (ret != RET_OK) {
delete kernel;
MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: "
<< schema::EnumNamePrimitiveType(static_cast<schema::PrimitiveType>(opParameter->type_));
delete kernel;
return nullptr;
}
return kernel;

View File

@ -126,6 +126,11 @@ int Convolution1x1CPUKernel::InitConv1x1Param() {
}
int Convolution1x1CPUKernel::Init() {
matmul_param_ = new (std::nothrow) MatMulParameter;
if (matmul_param_ == nullptr) {
MS_LOG(ERROR) << "Memory allocation failed";
return RET_ERROR;
}
int error_code = InitConv1x1BiasWeight();
if (error_code != RET_OK) {
MS_LOG(ERROR) << "Convolution base init failed.";

View File

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

View File

@ -169,7 +169,6 @@ kernel::LiteKernel *CpuConvDwFp32KernelCreator(const std::vector<lite::Tensor *>
}
auto ret = kernel->Init();
if (ret != RET_OK && ret != RET_INFER_INVALID) {
delete kernel;
MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: "
<< schema::EnumNamePrimitiveType(static_cast<schema::PrimitiveType>(opParameter->type_));
if (weight_tensor->data_type() == kNumberTypeInt8 || weight_tensor->data_type() == kNumberTypeInt16) {
@ -177,6 +176,7 @@ kernel::LiteKernel *CpuConvDwFp32KernelCreator(const std::vector<lite::Tensor *>
weight_tensor->set_data(restore_data);
weight_tensor->set_data_type(restore_type);
}
delete kernel;
return nullptr;
}

View File

@ -440,7 +440,6 @@ kernel::LiteKernel *CpuConvFp32KernelCreator(const std::vector<lite::Tensor *> &
}
auto ret = kernel->Init();
if (ret != RET_OK && ret != RET_INFER_INVALID) {
delete kernel;
MS_LOG(ERROR) << "Init kernel failed, name: " << op_parameter->name_ << ", type: "
<< schema::EnumNamePrimitiveType(static_cast<schema::PrimitiveType>(op_parameter->type_));
if (dequant_flag) {
@ -448,6 +447,7 @@ kernel::LiteKernel *CpuConvFp32KernelCreator(const std::vector<lite::Tensor *> &
weight_tensor->set_data(restore_data);
weight_tensor->set_data_type(restore_type);
}
delete kernel;
return nullptr;
}

View File

@ -230,7 +230,6 @@ kernel::LiteKernel *CpuDeconvDwFp32KernelCreator(const std::vector<lite::Tensor
}
auto ret = kernel->Init();
if (ret != RET_OK) {
delete kernel;
MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: "
<< schema::EnumNamePrimitiveType(static_cast<schema::PrimitiveType>(opParameter->type_));
if (dequant_flag) {
@ -238,6 +237,7 @@ kernel::LiteKernel *CpuDeconvDwFp32KernelCreator(const std::vector<lite::Tensor
weight_tensor->set_data(restore_data);
weight_tensor->set_data_type(restore_type);
}
delete kernel;
return nullptr;
}
if (dequant_flag) {

View File

@ -134,6 +134,11 @@ int DeConvolutionCPUKernel::DoDeconv(int task_id) {
}
int DeConvolutionCPUKernel::Init() {
matmul_param_ = new (std::nothrow) MatMulParameter();
if (matmul_param_ == nullptr) {
MS_LOG(ERROR) << "Memory allocation failed";
return RET_ERROR;
}
int error_code = InitWeightBias();
if (error_code != RET_OK) {
MS_LOG(ERROR) << "deconv InitWeightBias error!ret: " << error_code;
@ -270,7 +275,6 @@ kernel::LiteKernel *CpuDeConvFp32KernelCreator(const std::vector<lite::Tensor *>
}
auto ret = kernel->Init();
if (ret != RET_OK) {
delete kernel;
MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: "
<< schema::EnumNamePrimitiveType(static_cast<schema::PrimitiveType>(opParameter->type_));
if (dequant_flag) {
@ -278,6 +282,7 @@ kernel::LiteKernel *CpuDeConvFp32KernelCreator(const std::vector<lite::Tensor *>
weight_tensor->set_data(restore_data);
weight_tensor->set_data_type(restore_type);
}
delete kernel;
return nullptr;
}

View File

@ -33,9 +33,7 @@ class DeConvolutionCPUKernel : public ConvolutionBaseCPUKernel {
DeConvolutionCPUKernel(OpParameter *parameter, const std::vector<lite::Tensor *> &inputs,
const std::vector<lite::Tensor *> &outputs, const lite::InnerContext *ctx,
const mindspore::lite::PrimitiveC *primitive)
: ConvolutionBaseCPUKernel(parameter, inputs, outputs, ctx, primitive) {
matmul_param_ = new MatMulParameter();
}
: ConvolutionBaseCPUKernel(parameter, inputs, outputs, ctx, primitive) {}
~DeConvolutionCPUKernel() override;
int Init() override;
int Run() override;

View File

@ -301,6 +301,14 @@ int DeConvolutionWinogradCPUKernel::ReSize() {
}
int DeConvolutionWinogradCPUKernel::Init() {
deconv_param_ = new (std::nothrow) DeConvParam();
if (deconv_param_ == nullptr) {
MS_LOG(ERROR) << "Memory allocation failed";
return RET_ERROR;
}
for (auto &wg : deconv_param_->a_buffer_) {
wg.buf_init_ = false;
}
int error_code = InitComputeParam();
if (error_code != RET_OK) {
MS_LOG(ERROR) << "InitComputeParam error! ret: " << error_code;

View File

@ -33,12 +33,7 @@ class DeConvolutionWinogradCPUKernel : public ConvolutionBaseCPUKernel {
DeConvolutionWinogradCPUKernel(OpParameter *parameter, const std::vector<lite::Tensor *> &inputs,
const std::vector<lite::Tensor *> &outputs, const lite::InnerContext *ctx,
const mindspore::lite::PrimitiveC *primitive)
: ConvolutionBaseCPUKernel(parameter, inputs, outputs, ctx, primitive) {
deconv_param_ = new DeConvParam();
for (auto &wg : deconv_param_->a_buffer_) {
wg.buf_init_ = false;
}
}
: ConvolutionBaseCPUKernel(parameter, inputs, outputs, ctx, primitive) {}
~DeConvolutionWinogradCPUKernel() override;
int Init() override;
int Run() override;

View File

@ -143,9 +143,9 @@ kernel::LiteKernel *CpuFusedBatchnormKernelCreator(const std::vector<lite::Tenso
}
auto ret = kernel->Init();
if (ret != RET_OK) {
delete kernel;
MS_LOG(ERROR) << "Init kernel failed, name: " << op_parameter->name_ << ", type: "
<< schema::EnumNamePrimitiveType(static_cast<schema::PrimitiveType>(op_parameter->type_));
delete kernel;
return nullptr;
}
return kernel;

View File

@ -195,9 +195,9 @@ kernel::LiteKernel *CpuLstmKernelCreator(const std::vector<lite::Tensor *> &inpu
}
auto ret = kernel->Init();
if (ret != RET_OK) {
delete kernel;
MS_LOG(ERROR) << "Init kernel failed, name: " << parameter->name_
<< ", type: " << schema::EnumNamePrimitiveType(static_cast<schema::PrimitiveType>(parameter->type_));
delete kernel;
return nullptr;
}
return kernel;

View File

@ -428,7 +428,6 @@ kernel::LiteKernel *CpuMatmulFp32KernelCreator(const std::vector<lite::Tensor *>
}
auto ret = kernel->Init();
if (ret != RET_OK) {
delete kernel;
MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: "
<< schema::EnumNamePrimitiveType(static_cast<schema::PrimitiveType>(opParameter->type_));
if (dequant_flag) {
@ -436,6 +435,7 @@ kernel::LiteKernel *CpuMatmulFp32KernelCreator(const std::vector<lite::Tensor *>
weight_tensor->set_data(restore_data);
weight_tensor->set_data_type(restore_type);
}
delete kernel;
return nullptr;
}

View File

@ -236,9 +236,9 @@ kernel::LiteKernel *CpuNonMaxSuppressionFp32KernelCreator(const std::vector<lite
}
auto ret = kernel->Init();
if (ret != RET_OK) {
delete kernel;
MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: "
<< schema::EnumNamePrimitiveType(static_cast<schema::PrimitiveType>(opParameter->type_));
delete kernel;
return nullptr;
}
return kernel;

View File

@ -206,9 +206,9 @@ kernel::LiteKernel *CpuOneHotFp32KernelCreator(const std::vector<lite::Tensor *>
}
auto ret = kernel->Init();
if (ret != RET_OK) {
delete kernel;
MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: "
<< schema::EnumNamePrimitiveType(static_cast<schema::PrimitiveType>(opParameter->type_));
delete kernel;
return nullptr;
}
return kernel;

View File

@ -154,9 +154,9 @@ kernel::LiteKernel *CpuReverseFp32KernelCreator(const std::vector<lite::Tensor *
auto ret = kernel->Init();
if (ret != RET_OK) {
delete kernel;
MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: "
<< schema::EnumNamePrimitiveType(static_cast<schema::PrimitiveType>(opParameter->type_));
delete kernel;
return nullptr;
}
return kernel;

View File

@ -135,9 +135,9 @@ kernel::LiteKernel *CpuROIPoolingFp32KernelCreator(const std::vector<lite::Tenso
}
auto ret = kernel->Init();
if (ret != RET_OK) {
delete kernel;
MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: "
<< schema::EnumNamePrimitiveType(static_cast<schema::PrimitiveType>(opParameter->type_));
delete kernel;
return nullptr;
}
return kernel;

View File

@ -103,9 +103,9 @@ kernel::LiteKernel *CpuSliceFp32KernelCreator(const std::vector<lite::Tensor *>
}
auto ret = kernel->Init();
if (ret != RET_OK) {
delete kernel;
MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: "
<< schema::EnumNamePrimitiveType(static_cast<schema::PrimitiveType>(opParameter->type_));
delete kernel;
return nullptr;
}
return kernel;

View File

@ -121,9 +121,9 @@ kernel::LiteKernel *CpuSpaceToDepthFp32KernelCreator(const std::vector<lite::Ten
auto ret = kernel->Init();
if (ret != RET_OK) {
delete kernel;
MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: "
<< schema::EnumNamePrimitiveType(static_cast<schema::PrimitiveType>(opParameter->type_));
delete kernel;
return nullptr;
}
return kernel;

View File

@ -94,9 +94,9 @@ kernel::LiteKernel *CpuStackFp32KernelCreator(const std::vector<lite::Tensor *>
auto ret = kernel->Init();
if (ret != RET_OK) {
delete kernel;
MS_LOG(ERROR) << "Init kernel failed, name: " << op_parameter->name_ << ", type: "
<< schema::EnumNamePrimitiveType(static_cast<schema::PrimitiveType>(op_parameter->type_));
delete kernel;
return nullptr;
}
return kernel;

View File

@ -71,9 +71,9 @@ kernel::LiteKernel *CpuActivationInt8KernelCreator(const std::vector<lite::Tenso
}
auto ret = kernel->Init();
if (ret != RET_OK) {
delete kernel;
MS_LOG(ERROR) << "Init kernel failed, name: " << parameter->name_
<< ", type: " << schema::EnumNamePrimitiveType(static_cast<schema::PrimitiveType>(parameter->type_));
delete kernel;
return nullptr;
}
return kernel;

View File

@ -100,9 +100,9 @@ kernel::LiteKernel *CpuArgMinMaxInt8KernelCreator(const std::vector<lite::Tensor
auto ret = kernel->Init();
if (ret != RET_OK) {
delete kernel;
MS_LOG(ERROR) << "Init kernel failed, name: " << op_parameter->name_ << ", type: "
<< schema::EnumNamePrimitiveType(static_cast<schema::PrimitiveType>(op_parameter->type_));
delete kernel;
return nullptr;
}
return kernel;

View File

@ -99,9 +99,9 @@ kernel::LiteKernel *CpuBatchToSpaceInt8KernelCreator(const std::vector<lite::Ten
auto ret = kernel->Init();
if (ret != RET_OK) {
delete kernel;
MS_LOG(ERROR) << "Init kernel failed, name: " << op_parameter->name_ << ", type: "
<< schema::EnumNamePrimitiveType(static_cast<schema::PrimitiveType>(op_parameter->type_));
delete kernel;
return nullptr;
}
return kernel;

View File

@ -157,9 +157,9 @@ kernel::LiteKernel *CpuConcatInt8KernelCreator(const std::vector<lite::Tensor *>
}
auto ret = kernel->Init();
if (ret != RET_OK) {
delete kernel;
MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: "
<< schema::EnumNamePrimitiveType(static_cast<schema::PrimitiveType>(opParameter->type_));
delete kernel;
return nullptr;
}
return kernel;

View File

@ -203,9 +203,9 @@ kernel::LiteKernel *CpuConvDwInt8KernelCreator(const std::vector<lite::Tensor *>
}
auto ret = kernel->Init();
if (ret != RET_OK) {
delete kernel;
MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: "
<< schema::EnumNamePrimitiveType(static_cast<schema::PrimitiveType>(opParameter->type_));
delete kernel;
return nullptr;
}
return kernel;

View File

@ -274,9 +274,9 @@ kernel::LiteKernel *CpuConvInt8KernelCreator(const std::vector<lite::Tensor *> &
}
auto ret = kernel->Init();
if (ret != RET_OK) {
delete kernel;
MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: "
<< schema::EnumNamePrimitiveType(static_cast<schema::PrimitiveType>(opParameter->type_));
delete kernel;
return nullptr;
}
return kernel;

View File

@ -104,9 +104,9 @@ kernel::LiteKernel *CpuCropInt8KernelCreator(const std::vector<lite::Tensor *> &
}
auto ret = kernel->Init();
if (ret != RET_OK) {
delete kernel;
MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: "
<< schema::EnumNamePrimitiveType(static_cast<schema::PrimitiveType>(opParameter->type_));
delete kernel;
return nullptr;
}
return kernel;

View File

@ -227,9 +227,9 @@ kernel::LiteKernel *CpuDeconvDwInt8KernelCreator(const std::vector<lite::Tensor
}
auto ret = kernel->Init();
if (ret != RET_OK) {
delete kernel;
MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: "
<< schema::EnumNamePrimitiveType(static_cast<schema::PrimitiveType>(opParameter->type_));
delete kernel;
return nullptr;
}
return kernel;

View File

@ -291,9 +291,9 @@ kernel::LiteKernel *CpuDeConvInt8KernelCreator(const std::vector<lite::Tensor *>
}
auto ret = kernel->Init();
if (ret != RET_OK) {
delete kernel;
MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: "
<< schema::EnumNamePrimitiveType(static_cast<schema::PrimitiveType>(opParameter->type_));
delete kernel;
return nullptr;
}
return kernel;

View File

@ -88,9 +88,9 @@ kernel::LiteKernel *CpuDepthToSpaceInt8KernelCreator(const std::vector<lite::Ten
auto ret = kernel->Init();
if (ret != RET_OK) {
delete kernel;
MS_LOG(ERROR) << "Init kernel failed, name: " << op_parameter->name_ << ", type: "
<< schema::EnumNamePrimitiveType(static_cast<schema::PrimitiveType>(op_parameter->type_));
delete kernel;
return nullptr;
}
return kernel;

View File

@ -290,9 +290,9 @@ kernel::LiteKernel *CpuFullConnectionInt8KernelCreator(const std::vector<lite::T
}
auto ret = kernel->Init();
if (ret != RET_OK) {
delete kernel;
MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: "
<< schema::EnumNamePrimitiveType(static_cast<schema::PrimitiveType>(opParameter->type_));
delete kernel;
return nullptr;
}
return kernel;

View File

@ -154,9 +154,9 @@ kernel::LiteKernel *CpuLeakyReluInt8KernelCreator(const std::vector<lite::Tensor
}
auto ret = kernel->Init();
if (ret != RET_OK) {
delete kernel;
MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: "
<< schema::EnumNamePrimitiveType(static_cast<schema::PrimitiveType>(opParameter->type_));
delete kernel;
return nullptr;
}
return kernel;

View File

@ -212,9 +212,9 @@ kernel::LiteKernel *CpuMatMulInt8KernelCreator(const std::vector<lite::Tensor *>
}
auto ret = kernel->Init();
if (ret != RET_OK) {
delete kernel;
MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: "
<< schema::EnumNamePrimitiveType(static_cast<schema::PrimitiveType>(opParameter->type_));
delete kernel;
return nullptr;
}
return kernel;

View File

@ -236,9 +236,9 @@ kernel::LiteKernel *CpuMulInt8KernelCreator(const std::vector<lite::Tensor *> &i
}
auto ret = kernel->Init();
if (ret != RET_OK) {
delete kernel;
MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: "
<< schema::EnumNamePrimitiveType(static_cast<schema::PrimitiveType>(opParameter->type_));
delete kernel;
return nullptr;
}
return kernel;

View File

@ -303,9 +303,9 @@ kernel::LiteKernel *CpuPadInt8KernelCreator(const std::vector<lite::Tensor *> &i
}
auto ret = kernel->Init();
if (ret != RET_OK) {
delete kernel;
MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: "
<< schema::EnumNamePrimitiveType(static_cast<schema::PrimitiveType>(opParameter->type_));
delete kernel;
return nullptr;
}
return kernel;

View File

@ -120,9 +120,9 @@ kernel::LiteKernel *CpuPoolingInt8KernelCreator(const std::vector<lite::Tensor *
}
auto ret = kernel->Init();
if (ret != RET_OK) {
delete kernel;
MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: "
<< schema::EnumNamePrimitiveType(static_cast<schema::PrimitiveType>(opParameter->type_));
delete kernel;
return nullptr;
}
return kernel;

View File

@ -129,9 +129,9 @@ kernel::LiteKernel *CpuPowerInt8KernelCreator(const std::vector<lite::Tensor *>
}
auto ret = kernel->Init();
if (ret != RET_OK) {
delete kernel;
MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: "
<< schema::EnumNamePrimitiveType(static_cast<schema::PrimitiveType>(opParameter->type_));
delete kernel;
return nullptr;
}
return kernel;

View File

@ -99,9 +99,9 @@ kernel::LiteKernel *CpuReshapeInt8KernelCreator(const std::vector<lite::Tensor *
}
auto ret = kernel->Init();
if (ret != RET_OK) {
delete kernel;
MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: "
<< schema::EnumNamePrimitiveType(static_cast<schema::PrimitiveType>(opParameter->type_));
delete kernel;
return nullptr;
}
return kernel;

View File

@ -73,9 +73,12 @@ int ResizeInt8CPUKernel::Init() {
return ret;
}
quant_in_ = new (std::nothrow) QuantArg;
MS_ASSERT(quant_in_);
quant_out_ = new (std::nothrow) QuantArg;
MS_ASSERT(quant_out_);
multiplier_ = new (std::nothrow) QuantMulArg;
if (quant_in_ == nullptr || quant_out_ == nullptr || multiplier_ == nullptr) {
MS_LOG(ERROR) << "Memory allocation failed";
return RET_ERROR;
}
auto input = in_tensors_.at(0);
quant_in_->zp_ = input->quant_params().front().zeroPoint;
quant_in_->scale_ = input->quant_params().front().scale;
@ -83,8 +86,6 @@ int ResizeInt8CPUKernel::Init() {
quant_out_->zp_ = output->quant_params().front().zeroPoint;
quant_out_->scale_ = output->quant_params().front().scale;
multiplier_ = new (std::nothrow) QuantMulArg;
MS_ASSERT(multiplier_);
QuantizeRoundParameter(quant_in_->scale_ / quant_out_->scale_, &multiplier_->multiplier_, &multiplier_->left_shift_,
&multiplier_->right_shift_);
if (!InferShapeDone()) {
@ -379,9 +380,9 @@ kernel::LiteKernel *CpuResizeInt8KernelCreator(const std::vector<lite::Tensor *>
}
auto ret = kernel->Init();
if (ret != RET_OK) {
delete kernel;
MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: "
<< schema::EnumNamePrimitiveType(static_cast<schema::PrimitiveType>(opParameter->type_));
delete kernel;
return nullptr;
}

View File

@ -147,9 +147,9 @@ kernel::LiteKernel *CpuSoftmaxInt8KernelCreator(const std::vector<lite::Tensor *
}
auto ret = kernel->Init();
if (ret != RET_OK) {
delete kernel;
MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: "
<< schema::EnumNamePrimitiveType(static_cast<schema::PrimitiveType>(opParameter->type_));
delete kernel;
return nullptr;
}
return kernel;

View File

@ -123,9 +123,9 @@ kernel::LiteKernel *CpuSplitInt8KernelCreator(const std::vector<lite::Tensor *>
}
auto ret = kernel->Init();
if (ret != RET_OK) {
delete kernel;
MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: "
<< schema::EnumNamePrimitiveType(static_cast<schema::PrimitiveType>(opParameter->type_));
delete kernel;
return nullptr;
}
return kernel;

View File

@ -139,9 +139,9 @@ kernel::LiteKernel *CpuSqueezeInt8KernelCreator(const std::vector<lite::Tensor *
}
auto ret = kernel->Init();
if (ret != RET_OK) {
delete kernel;
MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: "
<< schema::EnumNamePrimitiveType(static_cast<schema::PrimitiveType>(opParameter->type_));
delete kernel;
return nullptr;
}
return kernel;