!46506 [2.0alpha]delete kDidAtexitFlag
Merge pull request !46506 from huanghui/2.0alpha-fix-bad-weak-ptr
This commit is contained in:
commit
a38d401ec4
|
@ -115,8 +115,6 @@ std::unordered_map<abstract::AbstractBasePtrList, uint64_t, abstract::AbstractBa
|
|||
abstract::AbstractBasePtrListEqual>
|
||||
g_args_cache;
|
||||
|
||||
static bool kDidAtexitFlag = False;
|
||||
|
||||
namespace {
|
||||
#ifdef ENABLE_DUMP_IR
|
||||
std::string GetBaseNameForIR(int64_t stage_idx, const std::string &action_name) {
|
||||
|
@ -616,7 +614,7 @@ void GraphExecutorPy::DelOneNetRes(const py::handle &py_phase) {
|
|||
(void)info_.erase(phase);
|
||||
MS_LOG(DEBUG) << "Delete phase: " << phase << ", info size: " << info_.size();
|
||||
}
|
||||
if (clear && !kDidAtexitFlag) {
|
||||
if (clear) {
|
||||
// Do clear here to avoid any pointer for resource.
|
||||
FuncGraphLoopBreaker::Inst().ClearCellGraphs(phase);
|
||||
}
|
||||
|
@ -1970,7 +1968,6 @@ void ClearSingleton() {
|
|||
|
||||
void ClearResAtexit() {
|
||||
MS_LOG(INFO) << "Pipeline clear all resource";
|
||||
kDidAtexitFlag = True;
|
||||
ClearResPart1();
|
||||
ClearResPart2();
|
||||
ClearResPart3();
|
||||
|
|
|
@ -105,7 +105,7 @@ class MS_CORE_API FuncGraph : public FuncGraphBase, public EffectInfoHolder {
|
|||
|
||||
FuncGraph();
|
||||
explicit FuncGraph(GraphDebugInfoPtr &&debug_info);
|
||||
~FuncGraph() override = default;
|
||||
~FuncGraph() { subclass_destruct_flag_ = true; }
|
||||
MS_DECLARE_PARENT(FuncGraph, FuncGraphBase);
|
||||
|
||||
void DoBreakLoop() override;
|
||||
|
|
|
@ -24,7 +24,7 @@ namespace mindspore {
|
|||
FuncGraphLoopBreaker::~FuncGraphLoopBreaker() {
|
||||
std::lock_guard<std::mutex> lock_set(func_mutex_);
|
||||
for (auto fg : func_set_) {
|
||||
fg->reg_flg = false;
|
||||
fg->reg_flg_ = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -38,9 +38,15 @@ void FuncGraphLoopBreaker::BreakLoop() {
|
|||
std::list<FuncGraphBasePtr> func_list;
|
||||
|
||||
// Generate shared_ptr for every graph, to avoid func_set_ changes while BreakLoop
|
||||
(void)std::transform(func_set_.begin(), func_set_.end(), std::back_inserter(func_list),
|
||||
[](FuncGraphBase *fun) -> FuncGraphBasePtr { return fun->shared_from_base<FuncGraphBase>(); });
|
||||
std::for_each(func_set_.begin(), func_set_.end(), [&func_list](FuncGraphBase *fun) {
|
||||
if (fun != nullptr && !fun->subclass_destruct_flag_) {
|
||||
func_list.emplace_back(fun->shared_from_base<FuncGraphBase>());
|
||||
}
|
||||
});
|
||||
for (auto &item : func_list) {
|
||||
if (item == nullptr) {
|
||||
continue;
|
||||
}
|
||||
item->DoBreakLoop();
|
||||
}
|
||||
func_list.clear();
|
||||
|
@ -62,10 +68,13 @@ void FuncGraphLoopBreaker::CleanMetaFuncGraphCache() {
|
|||
std::list<FuncGraphBasePtr> func_list;
|
||||
|
||||
// Generate shared_ptr for every graph, to avoid func_set_ changes while BreakLoop
|
||||
(void)std::transform(func_set_.begin(), func_set_.end(), std::back_inserter(func_list),
|
||||
[](FuncGraphBase *fun) -> FuncGraphBasePtr { return fun->shared_from_base<FuncGraphBase>(); });
|
||||
std::for_each(func_set_.begin(), func_set_.end(), [&func_list](FuncGraphBase *fun) {
|
||||
if (fun != nullptr && !fun->subclass_destruct_flag_) {
|
||||
func_list.emplace_back(fun->shared_from_base<FuncGraphBase>());
|
||||
}
|
||||
});
|
||||
for (auto item : func_list) {
|
||||
if (item->isa<MetaFuncGraph>()) {
|
||||
if (item != nullptr && item->isa<MetaFuncGraph>()) {
|
||||
item->DoBreakLoop();
|
||||
}
|
||||
}
|
||||
|
@ -73,14 +82,16 @@ void FuncGraphLoopBreaker::CleanMetaFuncGraphCache() {
|
|||
|
||||
void FuncGraphLoopBreaker::ClearCellGraphs(const std::string &phase) {
|
||||
std::list<FuncGraphBasePtr> func_list;
|
||||
|
||||
// Generate shared_ptr for every graph, to avoid func_set_ changes while BreakLoop
|
||||
(void)std::transform(func_set_.begin(), func_set_.end(), std::back_inserter(func_list),
|
||||
[](FuncGraphBase *fun) -> FuncGraphBasePtr { return fun->shared_from_base<FuncGraphBase>(); });
|
||||
std::for_each(func_set_.begin(), func_set_.end(), [&func_list](FuncGraphBase *fun) {
|
||||
if (fun != nullptr && !fun->subclass_destruct_flag_) {
|
||||
func_list.emplace_back(fun->shared_from_base<FuncGraphBase>());
|
||||
}
|
||||
});
|
||||
for (auto item : func_list) {
|
||||
if (item->isa<FuncGraph>()) {
|
||||
if (item != nullptr && item->isa<FuncGraph>()) {
|
||||
auto func_graph = item->cast<FuncGraphPtr>();
|
||||
if (func_graph->phase() == phase) {
|
||||
if (func_graph != nullptr && func_graph->phase() == phase) {
|
||||
func_graph->DoBreakLoop();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,11 +57,11 @@ class FuncGraphBase : public Value {
|
|||
public:
|
||||
FuncGraphBase() {
|
||||
FuncGraphLoopBreaker::Inst().RegFuncGraphBase(this);
|
||||
reg_flg = true;
|
||||
reg_flg_ = true;
|
||||
}
|
||||
|
||||
~FuncGraphBase() override {
|
||||
if (reg_flg) {
|
||||
if (reg_flg_) {
|
||||
FuncGraphLoopBreaker::Inst().UnRegFuncGraphBase(this);
|
||||
}
|
||||
}
|
||||
|
@ -77,7 +77,9 @@ class FuncGraphBase : public Value {
|
|||
|
||||
protected:
|
||||
friend FuncGraphLoopBreaker;
|
||||
bool reg_flg{false};
|
||||
bool reg_flg_{false};
|
||||
// If the subclass (such as FuncGraph) has started destructing.
|
||||
bool subclass_destruct_flag_{false};
|
||||
|
||||
private:
|
||||
// If the nodes or their callee's nodes contain Depend CNode with isolated side-effect node.
|
||||
|
|
|
@ -43,7 +43,7 @@ class MS_CORE_API MetaFuncGraph : public FuncGraphBase {
|
|||
debug_info_ = std::make_shared<DebugInfo>();
|
||||
}
|
||||
|
||||
~MetaFuncGraph() override = default;
|
||||
~MetaFuncGraph() { subclass_destruct_flag_ = true; }
|
||||
|
||||
MS_DECLARE_PARENT(MetaFuncGraph, FuncGraphBase);
|
||||
// Return normalized versions of the arguments.
|
||||
|
|
Loading…
Reference in New Issue