!4829 fix op_parameter free

Merge pull request !4829 from hangq/master
This commit is contained in:
mindspore-ci-bot 2020-08-20 16:44:51 +08:00 committed by Gitee
commit 3fc897506c
3 changed files with 12 additions and 7 deletions

View File

@ -108,6 +108,7 @@ kernel::LiteKernel *KernelRegistry::GetKernel(const std::vector<tensor::Tensor *
<< schema::EnumNamePrimitiveType((schema::PrimitiveType)primitive->Type());
return nullptr;
}
this->op_parameters_.emplace_back(parameter);
auto creator = GetCreator(key);
if (creator != nullptr) {
auto kernel = creator(in_tensors, out_tensors, parameter, ctx, key, primitive);
@ -115,4 +116,11 @@ kernel::LiteKernel *KernelRegistry::GetKernel(const std::vector<tensor::Tensor *
}
return nullptr;
}
KernelRegistry::~KernelRegistry() {
for (auto op_parameter : op_parameters_) {
delete(op_parameter);
}
op_parameters_.clear();
}
} // namespace mindspore::lite

View File

@ -32,7 +32,7 @@ namespace mindspore::lite {
class KernelRegistry {
public:
KernelRegistry() = default;
virtual ~KernelRegistry() = default;
virtual ~KernelRegistry();
static KernelRegistry *GetInstance();
int Init();
@ -54,6 +54,7 @@ class KernelRegistry {
static const int op_type_length_{PrimitiveType_MAX - PrimitiveType_MIN + 1};
static const int array_size_{device_type_length_ * data_type_length_ * op_type_length_};
kernel::KernelCreator creator_arrays_[array_size_] = {0};
std::vector<OpParameter *> op_parameters_;
};
class KernelRegistrar {

View File

@ -57,6 +57,7 @@ struct KernelKey {
class LiteKernel {
public:
LiteKernel() = default;
// parameter should be deleted or freed by caller, and should be deleted or freed after LiteKernel is deleted
LiteKernel(OpParameter *parameter, const std::vector<lite::tensor::Tensor *> &in_tensors,
const std::vector<lite::tensor::Tensor *> &out_tensors, const lite::Context *ctx,
const mindspore::lite::PrimitiveC *primitive)
@ -72,12 +73,7 @@ class LiteKernel {
this->out_kernels_.clear();
}
virtual ~LiteKernel() {
if (op_parameter_ != nullptr) {
delete op_parameter_;
op_parameter_ = nullptr;
}
}
virtual ~LiteKernel() = default;
virtual int Prepare() {
if (!InferShapeDone()) {