forked from huawei/mindspore2022
!32680 [r1.7]fix segmentation fault caused by static resource free disorder.
Merge pull request !32680 from wYann/fix47_1.7
This commit is contained in:
commit
61bd874677
|
|
@ -18,8 +18,6 @@
|
|||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <set>
|
||||
#include <utility>
|
||||
#include "utils/anf_utils.h"
|
||||
#include "backend/common/session/anf_runtime_algorithm.h"
|
||||
#include "include/common/utils/anfalgo.h"
|
||||
|
|
@ -28,27 +26,18 @@
|
|||
|
||||
namespace mindspore {
|
||||
namespace opt::dynamic_shape {
|
||||
namespace {
|
||||
constexpr size_t kTupleFirstItemIndex = 0;
|
||||
constexpr size_t kFirstDataInputIndex = 1;
|
||||
using DependPair = std::pair<AnfNodePtr, AnfNodePtr>;
|
||||
struct DependPairCmp {
|
||||
bool operator()(const DependPair &lhs, const DependPair &rhs) const {
|
||||
if (lhs.first != rhs.first) {
|
||||
return lhs.first > rhs.first;
|
||||
}
|
||||
return lhs.second > rhs.second;
|
||||
}
|
||||
};
|
||||
void InsertDepend(const FuncGraphPtr &g, const AnfNodePtr &prev, const AnfNodePtr &next, AnfNodePtrList *depend_nodes) {
|
||||
|
||||
void LinkCustomOp::InsertDepend(const FuncGraphPtr &g, const AnfNodePtr &prev, const AnfNodePtr &next,
|
||||
AnfNodePtrList *depend_nodes) {
|
||||
MS_EXCEPTION_IF_NULL(g);
|
||||
MS_EXCEPTION_IF_NULL(prev);
|
||||
MS_EXCEPTION_IF_NULL(next);
|
||||
MS_EXCEPTION_IF_NULL(depend_nodes);
|
||||
static std::set<DependPair, DependPairCmp> added_set = std::set<DependPair, DependPairCmp>();
|
||||
|
||||
DependPair cur_pair = std::make_pair(prev, next);
|
||||
if (added_set.count(cur_pair) > 0) {
|
||||
if (added_set_.count(cur_pair) > 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -57,10 +46,10 @@ void InsertDepend(const FuncGraphPtr &g, const AnfNodePtr &prev, const AnfNodePt
|
|||
std::vector<AnfNodePtr>{NewValueNode(std::make_shared<Primitive>(prim::kPrimDepend->name())), next, prev});
|
||||
MS_EXCEPTION_IF_NULL(depend_node);
|
||||
depend_nodes->push_back(depend_node);
|
||||
(void)added_set.insert(cur_pair);
|
||||
(void)added_set_.insert(cur_pair);
|
||||
}
|
||||
|
||||
bool LinkInternalOp(const FuncGraphPtr &g, const AnfNodePtr &node, AnfNodePtrList *depend_nodes) {
|
||||
bool LinkCustomOp::LinkInternalOp(const FuncGraphPtr &g, const AnfNodePtr &node, AnfNodePtrList *depend_nodes) {
|
||||
MS_EXCEPTION_IF_NULL(g);
|
||||
MS_EXCEPTION_IF_NULL(node);
|
||||
MS_EXCEPTION_IF_NULL(depend_nodes);
|
||||
|
|
@ -82,7 +71,7 @@ bool LinkInternalOp(const FuncGraphPtr &g, const AnfNodePtr &node, AnfNodePtrLis
|
|||
return changed;
|
||||
}
|
||||
|
||||
bool LinkInputOp(const FuncGraphPtr &g, const CNodePtr &cnode, AnfNodePtrList *depend_nodes) {
|
||||
bool LinkCustomOp::LinkInputOp(const FuncGraphPtr &g, const CNodePtr &cnode, AnfNodePtrList *depend_nodes) {
|
||||
MS_EXCEPTION_IF_NULL(g);
|
||||
MS_EXCEPTION_IF_NULL(cnode);
|
||||
MS_EXCEPTION_IF_NULL(depend_nodes);
|
||||
|
|
@ -134,7 +123,7 @@ bool LinkInputOp(const FuncGraphPtr &g, const CNodePtr &cnode, AnfNodePtrList *d
|
|||
return changed;
|
||||
}
|
||||
|
||||
bool LinkDependSync(const FuncGraphPtr &g, const CNodePtr &cnode, AnfNodePtrList *depend_nodes) {
|
||||
bool LinkCustomOp::LinkDependSync(const FuncGraphPtr &g, const CNodePtr &cnode, AnfNodePtrList *depend_nodes) {
|
||||
MS_EXCEPTION_IF_NULL(g);
|
||||
MS_EXCEPTION_IF_NULL(cnode);
|
||||
MS_EXCEPTION_IF_NULL(depend_nodes);
|
||||
|
|
@ -193,7 +182,7 @@ bool LinkDependSync(const FuncGraphPtr &g, const CNodePtr &cnode, AnfNodePtrList
|
|||
* @param g Graph.
|
||||
* @param depend_nodes Custom's Depend nodes.
|
||||
*/
|
||||
void AttachDependNodes(const FuncGraphPtr &g, const AnfNodePtrList &depend_nodes) {
|
||||
void LinkCustomOp::AttachDependNodes(const FuncGraphPtr &g, const AnfNodePtrList &depend_nodes) {
|
||||
if (depend_nodes.empty()) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -215,13 +204,13 @@ void AttachDependNodes(const FuncGraphPtr &g, const AnfNodePtrList &depend_nodes
|
|||
// Attach back.
|
||||
return_node->set_input(kFirstDataInputIndex, get_1st_item);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
bool LinkCustomOp::Run(const FuncGraphPtr &func_graph) {
|
||||
MS_EXCEPTION_IF_NULL(func_graph);
|
||||
bool changed = false;
|
||||
AnfNodePtrList depend_nodes;
|
||||
auto node_list = TopoSort(func_graph->get_return());
|
||||
added_set_.clear();
|
||||
for (const auto &node : node_list) {
|
||||
CNodePtr cnode = node->cast<CNodePtr>();
|
||||
if (cnode == nullptr || !CustomActorNodeManager::Instance().IsRegistered(cnode)) {
|
||||
|
|
|
|||
|
|
@ -17,15 +17,37 @@
|
|||
#ifndef MINDSPORE_CCSRC_BACKEND_COMMON_OPTIMIZER_DYNAMIC_SHAPE_LINK_CUSTOM_OP_H
|
||||
#define MINDSPORE_CCSRC_BACKEND_COMMON_OPTIMIZER_DYNAMIC_SHAPE_LINK_CUSTOM_OP_H
|
||||
|
||||
#include <set>
|
||||
#include <utility>
|
||||
#include "ir/anf.h"
|
||||
#include "backend/common/optimizer/optimizer.h"
|
||||
|
||||
namespace mindspore::opt::dynamic_shape {
|
||||
using DependPair = std::pair<AnfNodePtr, AnfNodePtr>;
|
||||
struct DependPairCmp {
|
||||
bool operator()(const DependPair &lhs, const DependPair &rhs) const {
|
||||
if (lhs.first != rhs.first) {
|
||||
return lhs.first > rhs.first;
|
||||
}
|
||||
return lhs.second > rhs.second;
|
||||
}
|
||||
};
|
||||
|
||||
class LinkCustomOp : public Pass {
|
||||
public:
|
||||
LinkCustomOp() : Pass("link_custom_op") {}
|
||||
~LinkCustomOp() override = default;
|
||||
bool Run(const FuncGraphPtr &func_graph) override;
|
||||
|
||||
private:
|
||||
void InsertDepend(const FuncGraphPtr &g, const AnfNodePtr &prev, const AnfNodePtr &next,
|
||||
AnfNodePtrList *depend_nodes);
|
||||
bool LinkInternalOp(const FuncGraphPtr &g, const AnfNodePtr &node, AnfNodePtrList *depend_nodes);
|
||||
bool LinkInputOp(const FuncGraphPtr &g, const CNodePtr &cnode, AnfNodePtrList *depend_nodes);
|
||||
bool LinkDependSync(const FuncGraphPtr &g, const CNodePtr &cnode, AnfNodePtrList *depend_nodes);
|
||||
void AttachDependNodes(const FuncGraphPtr &g, const AnfNodePtrList &depend_nodes);
|
||||
|
||||
std::set<DependPair, DependPairCmp> added_set_;
|
||||
};
|
||||
} // namespace mindspore::opt::dynamic_shape
|
||||
#endif // MINDSPORE_CCSRC_BACKEND_COMMON_OPTIMIZER_DYNAMIC_SHAPE_LINK_CUSTOM_OP_H
|
||||
|
|
|
|||
Loading…
Reference in New Issue