From 515099d0a964eeb0fb2f4c3985a28bdbe80c495e Mon Sep 17 00:00:00 2001
From: lichen_101010
Date: Wed, 15 Jul 2020 16:28:30 -0400
Subject: [PATCH] save .pb graphs for GPU version
fix Cppcheck error
---
mindspore/ccsrc/backend/session/gpu_session.cc | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/mindspore/ccsrc/backend/session/gpu_session.cc b/mindspore/ccsrc/backend/session/gpu_session.cc
index 14e30c1a44..a22d756702 100644
--- a/mindspore/ccsrc/backend/session/gpu_session.cc
+++ b/mindspore/ccsrc/backend/session/gpu_session.cc
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+#include "debug/anf_ir_utils.h"
#include "backend/session/gpu_session.h"
#include "runtime/device/gpu/kernel_info_setter.h"
#include "runtime/device/gpu/gpu_kernel_build.h"
@@ -163,6 +164,10 @@ GraphId GPUSession::CompileGraph(const AnfNodePtrList &lst, const AnfNodePtrList
auto graph_id = graph_sum_;
auto graph = ConstructKernelGraph(lst, outputs);
MS_EXCEPTION_IF_NULL(graph);
+ // Prepare ms context info for dump .pb graph
+ auto context_ptr = MsContext::GetInstance();
+ MS_EXCEPTION_IF_NULL(context_ptr);
+ bool save_graphs = context_ptr->save_graphs_flag();
// Optimize
Optimize(graph);
// Select kernel build info
@@ -171,8 +176,16 @@ GraphId GPUSession::CompileGraph(const AnfNodePtrList &lst, const AnfNodePtrList
predictmodel::StepConvertGraph(graph);
// Start gpu kernel runtime
StartKernelRT();
+ // Dump .pb graph before hardware optimization
+ if (save_graphs) {
+ DumpIRProto(graph, "before_hwopt_" + std::to_string(graph_id));
+ }
// HardwareOptimize
HardwareOptimize(graph);
+ // Dump .pb graph after hardware optimization
+ if (save_graphs) {
+ DumpIRProto(graph, "after_hwopt_" + std::to_string(graph_id));
+ }
// Assign CUDA streams
AssignStream(graph);
// Hide NoOp from execution graph