forked from mindspore-Ecosystem/mindspore
!25952 unified runtime support the auto monad in the subgraphs connecting scene
Merge pull request !25952 from limingqi107/new_actor_runtime
This commit is contained in:
commit
1509d3f848
|
@ -442,7 +442,9 @@ std::vector<KernelWithIndex> AnfRuntimeAlgorithm::GetAllOutputWithIndex(const An
|
|||
// The output may be the tuple of node, so need visit all the outputs of node.
|
||||
for (size_t i = 0; i < outputs_num; ++i) {
|
||||
// Maybe this scene: tupleGetItem + depend + makeTuple, can be done correctly in VisitKernelWithReturnType.
|
||||
auto output_with_index = AnfAlgo::VisitKernelWithReturnType(node, i, false);
|
||||
// The output may be updataState node for connecting dependencies between subgraphs.
|
||||
auto output_with_index =
|
||||
AnfAlgo::VisitKernelWithReturnType(node, i, false, {prim::kPrimMakeTuple, prim::kPrimUpdateState});
|
||||
MS_EXCEPTION_IF_NULL(output_with_index.first);
|
||||
|
||||
// The makeTuple node need recurse.
|
||||
|
|
|
@ -102,7 +102,7 @@ bool IsInternalParameter(const AnfNodePtr &node, const KernelGraphPtr &graph) {
|
|||
|
||||
bool IsKernelActor(const AnfNodePtr &node, GraphExecutionStrategy strategy) {
|
||||
MS_EXCEPTION_IF_NULL(node);
|
||||
if (!node->isa<CNode>()) {
|
||||
if (!AnfAlgo::IsRealCNodeKernel(node)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -410,14 +410,13 @@ void GraphScheduler::CacheGraphOutputToActor(const GraphCompilerInfo &graph_comp
|
|||
MS_LOG(INFO) << "The graph " << graph->graph_id() << " output node:" << output_kernel->fullname_with_scope()
|
||||
<< " with index:" << output_with_index.second
|
||||
<< " is not actor, and the kernel type is:" << kernel_type;
|
||||
continue;
|
||||
}
|
||||
|
||||
auto output_actor = dynamic_cast<AbstractActor *>(FetchActor(kernel_name));
|
||||
MS_EXCEPTION_IF_NULL(output_actor);
|
||||
auto output_actor_name = (output_actor != nullptr) ? output_actor->GetAID().Name() : "";
|
||||
(void)graph_output_to_actor_.emplace(origin_output_with_index, GraphOutputPair(output_actor, output_with_index));
|
||||
MS_LOG(INFO) << "Cache the graph " << graph->graph_id() << " output node:" << output_kernel->fullname_with_scope()
|
||||
<< " with index:" << output_with_index.second << " to actor:" << output_actor->GetAID().Name()
|
||||
<< " with index:" << output_with_index.second << " to actor:" << output_actor_name
|
||||
<< ", from front node:" << origin_output_with_index.first->fullname_with_scope()
|
||||
<< " with index:" << origin_output_with_index.second;
|
||||
}
|
||||
|
@ -798,7 +797,7 @@ void GraphScheduler::LinkDataArrowInNonSinkMode(const KernelGraphPtr &graph,
|
|||
for (size_t i = 0; i < AnfAlgo::GetInputNum(kernel); ++i) {
|
||||
auto input_node = AnfAlgo::GetInputNode(kernel, i);
|
||||
// Link the control arrows of kernel actor by the auto monad, the inputs include monad node.
|
||||
if (AnfAlgo::IsOneOfPrimitiveCNode(input_node, auto_monad_prims)) {
|
||||
if (AnfAlgo::IsOneOfPrimitiveCNode(input_node, auto_monad_prims) || HasAbstractMonad(input_node)) {
|
||||
LinkControlArrowByAutoMonad(kernel_actor, input_node, graph);
|
||||
}
|
||||
if (HasAbstractMonad(input_node)) {
|
||||
|
@ -1084,31 +1083,37 @@ void GraphScheduler::LinkControlArrowByAutoMonad(AbstractActor *to_actor, const
|
|||
|
||||
for (const auto &real_depend_input : real_depend_inputs) {
|
||||
auto real_depend_input_with_idx = AnfAlgo::VisitKernelWithReturnType(real_depend_input, 0, false, return_types);
|
||||
MS_EXCEPTION_IF_NULL(real_depend_input_with_idx.first);
|
||||
auto real_depend_kernel = real_depend_input_with_idx.first;
|
||||
// Update the real depend kernel in the subgraphs connecting scene.
|
||||
if (IsInternalParameter(real_depend_kernel, graph)) {
|
||||
auto front_output_with_index = graph->GetFrontNodeByInternalParameter(real_depend_kernel);
|
||||
MS_EXCEPTION_IF_NULL(front_output_with_index.first);
|
||||
if (graph_output_to_actor_.count(front_output_with_index) == 0) {
|
||||
MS_LOG(EXCEPTION) << "Can't find graph output by front node:" << front_output_with_index.first->DebugString();
|
||||
}
|
||||
real_depend_kernel = graph_output_to_actor_[front_output_with_index].second.first;
|
||||
MS_EXCEPTION_IF_NULL(real_depend_kernel);
|
||||
MS_LOG(INFO) << "The graph " << graph->graph_id() << " link control arrow by auto monad from internal parameter: "
|
||||
<< real_depend_input_with_idx.first->DebugString()
|
||||
<< ", front output node: " << front_output_with_index.first->fullname_with_scope()
|
||||
<< ", backend output node: " << real_depend_kernel->fullname_with_scope();
|
||||
}
|
||||
|
||||
// The monad node and make tuple node need recursion.
|
||||
if (AnfAlgo::IsOneOfPrimitiveCNode(real_depend_kernel, recursion_prims)) {
|
||||
LinkControlArrowByAutoMonad(to_actor, real_depend_kernel, graph);
|
||||
continue;
|
||||
}
|
||||
|
||||
KernelActor *from_actor = nullptr;
|
||||
if (IsKernelActor(real_depend_kernel)) {
|
||||
from_actor = dynamic_cast<KernelActor *>(FetchActor(real_depend_kernel->fullname_with_scope()));
|
||||
} else if (IsInternalParameter(real_depend_kernel, graph)) {
|
||||
auto front_output_with_index = graph->GetFrontNodeByInternalParameter(real_depend_kernel);
|
||||
MS_EXCEPTION_IF_NULL(front_output_with_index.first);
|
||||
if (IsKernelActor(front_output_with_index.first)) {
|
||||
if (graph_output_to_actor_.count(front_output_with_index) == 0) {
|
||||
MS_LOG(EXCEPTION) << "Can't find actor by front node:" << front_output_with_index.first->DebugString();
|
||||
}
|
||||
from_actor = dynamic_cast<KernelActor *>(graph_output_to_actor_[front_output_with_index].first);
|
||||
}
|
||||
}
|
||||
auto from_actor = dynamic_cast<KernelActor *>(FetchActor(real_depend_kernel->fullname_with_scope()));
|
||||
if (from_actor == nullptr) {
|
||||
MS_LOG(DEBUG) << "Link control arrow by auto monad from depend node:" << real_depend_kernel->fullname_with_scope()
|
||||
<< " is not actor for the graph: " << graph->graph_id();
|
||||
continue;
|
||||
}
|
||||
MS_LOG(INFO) << "Link control arrow by auto monad, from actor: " << from_actor->GetAID().Name()
|
||||
<< ", to actor: " << to_actor->GetAID().Name();
|
||||
MS_LOG(INFO) << "Link control arrow by auto monad from actor: " << from_actor->GetAID().Name()
|
||||
<< ", to actor: " << to_actor->GetAID().Name() << " for the graph: " << graph->graph_id();
|
||||
AddControlArrow(from_actor, to_actor);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -400,7 +400,6 @@ bool GPUDeviceContext::LaunchKernel(const CNodePtr &kernel, const std::vector<Ad
|
|||
const std::vector<AddressPtr> &workspace, const std::vector<AddressPtr> &outputs,
|
||||
bool is_dynamic_shape) const {
|
||||
MS_EXCEPTION_IF_NULL(kernel);
|
||||
MS_LOG(DEBUG) << "Launch kernel: " << kernel->fullname_with_scope();
|
||||
if (!BindDeviceToCurrentThread()) {
|
||||
return false;
|
||||
}
|
||||
|
@ -415,10 +414,12 @@ bool GPUDeviceContext::LaunchKernel(const CNodePtr &kernel, const std::vector<Ad
|
|||
if (!profiler_inst->GetEnableFlag()) {
|
||||
#endif
|
||||
std::lock_guard<std::mutex> locker(launch_mutex_);
|
||||
MS_LOG(DEBUG) << "Launch kernel: " << kernel->fullname_with_scope();
|
||||
ret = DoLaunchKernel(kernel_mod, inputs, workspace, outputs);
|
||||
#ifndef ENABLE_SECURITY
|
||||
} else {
|
||||
std::lock_guard<std::mutex> locker(launch_mutex_);
|
||||
MS_LOG(DEBUG) << "Launch kernel: " << kernel->fullname_with_scope();
|
||||
ret = LaunchKernelWithProfiling(kernel, inputs, workspace, outputs);
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue