!21230 fix python kernel execute lock
Merge pull request !21230 from chenweifeng/python-kernel-sync-execute
This commit is contained in:
commit
eb5b2c478e
|
|
@ -380,8 +380,8 @@ void Executor::RunGraphAsync(const SessionPtr &session, const GraphId &graph_id,
|
|||
session->CreateOutputTensors(graph_id, inputs, outputs, &task->tensor_to_node_);
|
||||
// maintain a copy of output vector
|
||||
task->outputs_ = *outputs;
|
||||
// sync run graph without output tensor(int dataset graph)
|
||||
if (!TensorInVector(outputs) && !graph->HasPostGraph()) {
|
||||
// sync run graph without output tensor(int dataset graph) or the graph require gil.
|
||||
if ((!TensorInVector(outputs) && !graph->HasPostGraph()) || graph->is_need_gil()) {
|
||||
task->sync_run_ = true;
|
||||
RunTask(task, true, true);
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -341,6 +341,10 @@ class KernelGraph : public FuncGraph {
|
|||
void set_is_all_nop_node(bool is_all_nop_node) { is_all_nop_node_ = is_all_nop_node; }
|
||||
std::map<AnfWithOutIndex, AnfWithOutIndex> graph_output_map() { return graph_output_to_front_node_map_; }
|
||||
|
||||
// The interface to set/get the graph GIL flag.
|
||||
void set_is_need_gil(bool flag) { is_need_gil_ = flag; }
|
||||
bool is_need_gil() { return is_need_gil_; }
|
||||
|
||||
private:
|
||||
// remove value node form graph
|
||||
bool RemoveValueNodeFromGraph(const ValueNodePtr &value_node);
|
||||
|
|
@ -446,6 +450,9 @@ class KernelGraph : public FuncGraph {
|
|||
|
||||
// If all the nodes of graph is the nop node.
|
||||
bool is_all_nop_node_{false};
|
||||
|
||||
// Indicate whether the kernels in the graphs acquire Python GIL.
|
||||
bool is_need_gil_{false};
|
||||
};
|
||||
} // namespace session
|
||||
using KernelGraphPtr = std::shared_ptr<session::KernelGraph>;
|
||||
|
|
|
|||
|
|
@ -435,6 +435,17 @@ void CheckInputTensorShape(const TensorPtr &tensor, const CNodePtr &kernel, size
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateGraphAquireGilAttr(const NotNull<KernelGraphPtr> &root_graph) {
|
||||
for (const auto &cnode : root_graph->execution_order()) {
|
||||
if (AnfAlgo::CheckPrimitiveType(cnode, prim::kPyFunc)) {
|
||||
MS_LOG(INFO) << "The Graph require GIL. Graph id: " << root_graph->graph_id();
|
||||
root_graph->set_is_need_gil(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
GraphId SessionBasic::graph_sum_ = 0;
|
||||
|
|
@ -1103,6 +1114,7 @@ KernelGraphPtr SessionBasic::ConstructKernelGraph(const AnfNodePtrList &lst, con
|
|||
UnifyMindIR(graph);
|
||||
// Update Graph Dynamic Shape Attr
|
||||
UpdateGraphDynamicShapeAttr(NOT_NULL(graph));
|
||||
UpdateGraphAquireGilAttr(NOT_NULL(graph));
|
||||
opt::BackendCommonOptimization(graph);
|
||||
graph->SetInputNodes();
|
||||
SetInputNodeUsage(graph, manager);
|
||||
|
|
|
|||
|
|
@ -556,6 +556,7 @@ inline const PrimitivePtr kPrimWhile = std::make_shared<Primitive>("While");
|
|||
inline const PrimitivePtr kPrimPull = std::make_shared<Primitive>("Pull");
|
||||
inline const PrimitivePtr kPrimPush = std::make_shared<Primitive>("Push");
|
||||
inline const PrimitivePtr kPrimNPUAllocFloatStatus = std::make_shared<Primitive>("NPUAllocFloatStatus");
|
||||
inline const PrimitivePtr kPyFunc = std::make_shared<Primitive>("PyFunc");
|
||||
|
||||
// Structures
|
||||
inline const PrimitivePtr kPrimMakeList = std::make_shared<Primitive>("make_list");
|
||||
|
|
|
|||
Loading…
Reference in New Issue