diff --git a/mindspore/ccsrc/runtime/framework/graph_compiler.cc b/mindspore/ccsrc/runtime/framework/graph_compiler.cc index 2fe7caf1372..bb9560084c9 100644 --- a/mindspore/ccsrc/runtime/framework/graph_compiler.cc +++ b/mindspore/ccsrc/runtime/framework/graph_compiler.cc @@ -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()); diff --git a/mindspore/ccsrc/runtime/hardware/gpu/gpu_device_context.cc b/mindspore/ccsrc/runtime/hardware/gpu/gpu_device_context.cc index 6d34080a308..98a6821819a 100644 --- a/mindspore/ccsrc/runtime/hardware/gpu/gpu_device_context.cc +++ b/mindspore/ccsrc/runtime/hardware/gpu/gpu_device_context.cc @@ -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(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(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 &nodes) const {