Remove nop node optimizer for cpu

This commit is contained in:
lizhenyu 2021-07-08 17:06:23 +08:00
parent 1ac696d044
commit 1d81102fd0
2 changed files with 19 additions and 4 deletions

View File

@ -379,10 +379,6 @@ GraphId GraphCompiler::CompileGraph(const session::OpRunInfo &op_run_info, const
MS_EXCEPTION_IF_NULL(device_context);
device_context->OptimizeSingleOpGraph(graph);
MS_EXCEPTION_IF_NULL(session_);
session_->RunOpHideNopNode(graph);
session_->RunOpRemoveNopNode(graph);
// Generate 'KernelMod' for kernel in graph.
device_context->CreateKernel(graph->execution_order());

View File

@ -314,6 +314,22 @@ void RunOpHardwareOptimize(const KernelGraphPtr &kernel_graph) {
(void)optimizer->Optimize(kernel_graph);
kernel_graph->SetExecOrderByDefault();
}
void RunOpHideNopNode(const KernelGraphPtr &kernel_graph) {
auto ms_context = MsContext::GetInstance();
MS_EXCEPTION_IF_NULL(ms_context);
if (!ms_context->get_param<bool>(MS_CTX_ENABLE_PYNATIVE_INFER)) {
opt::HideNopNode(kernel_graph.get());
}
}
void RunOpRemoveNopNode(const KernelGraphPtr &kernel_graph) {
auto ms_context = MsContext::GetInstance();
MS_EXCEPTION_IF_NULL(ms_context);
if (!ms_context->get_param<bool>(MS_CTX_ENABLE_PYNATIVE_INFER)) {
opt::RemoveNopNode(kernel_graph.get());
}
}
} // namespace
void GPUDeviceContext::OptimizeSingleOpGraph(const KernelGraphPtr &graph) const {
@ -324,6 +340,9 @@ void GPUDeviceContext::OptimizeSingleOpGraph(const KernelGraphPtr &graph) const
SetOperatorInfo(graph->execution_order());
RunOpHardwareOptimize(graph);
RunOpHideNopNode(graph);
RunOpRemoveNopNode(graph);
}
void GPUDeviceContext::SetOperatorInfo(const std::vector<CNodePtr> &nodes) const {