!49825 cache the Operator to avoid memory leak of GE interface

Merge pull request !49825 from hanhuifeng/cache_ge_op
This commit is contained in:
i-robot 2023-03-08 06:19:27 +00:00 committed by Gitee
commit 750c875e77
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
1 changed files with 11 additions and 3 deletions

View File

@ -228,8 +228,7 @@ class OpAdapter : public BaseOpAdapter {
std::string getOpType() override { std::string getOpType() override {
if (op_type_.empty()) { if (op_type_.empty()) {
auto op = std::make_unique<OpType>(); op_type_ = getOp()->GetOpType();
op_type_ = op->GetOpType();
} }
return op_type_; return op_type_;
} }
@ -242,7 +241,7 @@ class OpAdapter : public BaseOpAdapter {
const mindspore::HashMap<int, DynOutputDesc> &getDynOutputMap() override { return dyn_output_map_; } const mindspore::HashMap<int, DynOutputDesc> &getDynOutputMap() override { return dyn_output_map_; }
const mindspore::HashMap<int, DynSubGraphDesc> &getDynSubgraphMap() override { return dyn_subgraph_map_; } const mindspore::HashMap<int, DynSubGraphDesc> &getDynSubgraphMap() override { return dyn_subgraph_map_; }
std::map<std::string, ValuePtr> GetNormalOpAttrList(const AnfNodePtr &node) override { std::map<std::string, ValuePtr> GetNormalOpAttrList(const AnfNodePtr &node) override {
return impl_->GetNormalOpAttrList(std::make_shared<::ge::Operator>(op_type_), node); return impl_->GetNormalOpAttrList(getOp(), node);
} }
bool IsDynInputOp(uint64_t index) override { return dyn_input_map_.find(index) != dyn_input_map_.end(); } bool IsDynInputOp(uint64_t index) override { return dyn_input_map_.find(index) != dyn_input_map_.end(); }
bool IsDyOutputOp(uint64_t index) override { return dyn_output_map_.find(index) != dyn_output_map_.end(); } bool IsDyOutputOp(uint64_t index) override { return dyn_output_map_.find(index) != dyn_output_map_.end(); }
@ -516,6 +515,13 @@ class OpAdapter : public BaseOpAdapter {
return output_size; return output_size;
} }
OperatorPtr getOp() {
if (op_ == nullptr) {
op_ = std::make_shared<OpType>();
}
return op_;
}
static const mindspore::HashMap<int, InputDesc> input_map_; static const mindspore::HashMap<int, InputDesc> input_map_;
static const mindspore::HashMap<int, DynInputDesc> dyn_input_map_; static const mindspore::HashMap<int, DynInputDesc> dyn_input_map_;
// note: To keep the outputs in order, the 'output_map_' and 'cus_output_map_' must be std::map instead of Hashmap. // note: To keep the outputs in order, the 'output_map_' and 'cus_output_map_' must be std::map instead of Hashmap.
@ -534,6 +540,8 @@ class OpAdapter : public BaseOpAdapter {
mindspore::HashMap<std::string, int> name_counts_; mindspore::HashMap<std::string, int> name_counts_;
const std::shared_ptr<OpAdapterImpl> impl_; const std::shared_ptr<OpAdapterImpl> impl_;
std::string op_type_; std::string op_type_;
// cache the Operator to avoid memory leak caused by 'std::make_shared<OpType>()'
OperatorPtr op_{nullptr};
}; };
template <typename T> template <typename T>