From 0e0d7eda1910ba1218d33f74db4cc429d1c78cfb Mon Sep 17 00:00:00 2001 From: John Tzanakakis Date: Fri, 18 Sep 2020 06:40:13 -0400 Subject: [PATCH] code refactor --- mindspore/ccsrc/backend/session/ascend_session.cc | 8 -------- mindspore/ccsrc/backend/session/gpu_session.cc | 8 -------- mindspore/ccsrc/backend/session/gpu_session.h | 2 -- mindspore/ccsrc/backend/session/session_basic.h | 6 +++--- .../ccsrc/runtime/device/gpu/gpu_kernel_runtime.cc | 12 ------------ 5 files changed, 3 insertions(+), 33 deletions(-) diff --git a/mindspore/ccsrc/backend/session/ascend_session.cc b/mindspore/ccsrc/backend/session/ascend_session.cc index 5101cb42d1..517b110697 100644 --- a/mindspore/ccsrc/backend/session/ascend_session.cc +++ b/mindspore/ccsrc/backend/session/ascend_session.cc @@ -174,11 +174,9 @@ GraphId AscendSession::CompileGraph(NotNull func_graph) { device::KernelAdjust::GetInstance().Profiling(NOT_NULL(root_graph.get())); // build kernel BuildKernel(root_graph); -#ifdef ENABLE_DEBUGGER if (debugger_) { debugger_->PreExecute(root_graph); } -#endif // alloc mem MemoryAlloc(root_graph.get()); // generate and load task into device @@ -249,11 +247,9 @@ void AscendSession::BuildGraph(GraphId graph_id) { BuildKernel(graph); auto ms_context = MsContext::GetInstance(); MS_EXCEPTION_IF_NULL(ms_context); -#ifdef ENABLE_DEBUGGER if (debugger_) { debugger_->PreExecute(graph); } -#endif if (ms_context->get_param(MS_CTX_PRECOMPILE_ONLY)) { MS_LOG(INFO) << "Precompile only, stop in build kernel step"; } else { @@ -325,18 +321,14 @@ void AscendSession::RunGraph(const GraphId &graph_id, const std::vectordebugger_enabled()) { LoadTensor(kernel_graph); } -#endif -#ifdef ENABLE_DEBUGGER // debugger post-execution processing if (debugger_) { debugger_->PostExecute(); } -#endif MS_LOG(INFO) << "Finish!"; } diff --git a/mindspore/ccsrc/backend/session/gpu_session.cc b/mindspore/ccsrc/backend/session/gpu_session.cc index ce8a6eed0f..82ef5a4486 100644 --- a/mindspore/ccsrc/backend/session/gpu_session.cc +++ b/mindspore/ccsrc/backend/session/gpu_session.cc @@ -281,9 +281,7 @@ GraphId GPUSession::CompileGraph(const AnfNodePtrList &lst, const AnfNodePtrList void GPUSession::RunGraph(const GraphId &graph_id, const std::vector &inputs, VectorRef *outputs) { auto &kernel_graph = graphs_[graph_id]; -#ifdef ENABLE_DEBUGGER PreIterationDbg(kernel_graph); -#endif // Load input data from user input LoadInputData(kernel_graph, inputs); #if (ENABLE_CPU && (ENABLE_D || ENABLE_GPU)) @@ -292,18 +290,14 @@ void GPUSession::RunGraph(const GraphId &graph_id, const std::vectorget_param(MS_CTX_ENABLE_GPU_SUMMARY)) { Summary(kernel_graph.get()); } -#ifdef ENABLE_DEBUGGER PostIterationDbg(kernel_graph); -#endif } void GPUSession::BuildOp(const OpRunInfo &op_run_info, const GraphInfo &graph_info, @@ -338,7 +332,6 @@ void GPUSession::RunOp(const OpRunInfo &op_run_info, const GraphInfo &graph_info RunOpClearMemory(kernel_graph.get()); } -#ifdef ENABLE_DEBUGGER void GPUSession::Dump(const std::shared_ptr &kernel_graph) const { if (debugger_->DebuggerBackendEnabled()) { MS_EXCEPTION_IF_NULL(kernel_graph); @@ -397,7 +390,6 @@ void GPUSession::PostLoadTensor(const std::shared_ptr &kernel_graph TensorLoader *tensor_loader = debug_services->tensor_loader(); tensor_loader->EmptyPrevTensor(); } -#endif } // namespace gpu } // namespace session } // namespace mindspore diff --git a/mindspore/ccsrc/backend/session/gpu_session.h b/mindspore/ccsrc/backend/session/gpu_session.h index 677d70e005..73b82bdd06 100644 --- a/mindspore/ccsrc/backend/session/gpu_session.h +++ b/mindspore/ccsrc/backend/session/gpu_session.h @@ -69,7 +69,6 @@ class GPUSession : public SessionBasic { void Execute(const std::shared_ptr &kernel_graph) const; -#ifdef ENABLE_DEBUGGER void Dump(const std::shared_ptr &kernel_graph) const; bool DumpDataEnabledIteration() const; @@ -81,7 +80,6 @@ class GPUSession : public SessionBasic { void PreLoadTensor(const std::shared_ptr &kernel_graph) const; void PostLoadTensor(const std::shared_ptr &kernel_graph) const; -#endif }; using GPUSessionPtr = std::shared_ptr; MS_REG_SESSION(kGPUDevice, GPUSession); diff --git a/mindspore/ccsrc/backend/session/session_basic.h b/mindspore/ccsrc/backend/session/session_basic.h index 3e1d76a4bd..a8fb3e95a9 100644 --- a/mindspore/ccsrc/backend/session/session_basic.h +++ b/mindspore/ccsrc/backend/session/session_basic.h @@ -32,7 +32,7 @@ #include "utils/contract.h" #include "runtime/device/kernel_info.h" #include "utils/ms_context.h" -#ifdef ENABLE_DEBUGGER +#if !defined(_WIN32) && !defined(_WIN64) #include "debug/debugger/debugger.h" #endif @@ -57,7 +57,7 @@ class Executor; class SessionBasic : public std::enable_shared_from_this { public: SessionBasic() : context_(nullptr), summary_callback_(nullptr), device_id_(0) { -#ifdef ENABLE_DEBUGGER +#if !defined(_WIN32) && !defined(_WIN64) debugger_ = nullptr; #endif } @@ -179,7 +179,7 @@ class SessionBasic : public std::enable_shared_from_this { static GraphId graph_sum_; uint32_t device_id_; std::shared_ptr executor_; -#ifdef ENABLE_DEBUGGER +#if !defined(_WIN32) && !defined(_WIN64) std::shared_ptr debugger_; #endif }; diff --git a/mindspore/ccsrc/runtime/device/gpu/gpu_kernel_runtime.cc b/mindspore/ccsrc/runtime/device/gpu/gpu_kernel_runtime.cc index 5e35021438..c6c766e322 100644 --- a/mindspore/ccsrc/runtime/device/gpu/gpu_kernel_runtime.cc +++ b/mindspore/ccsrc/runtime/device/gpu/gpu_kernel_runtime.cc @@ -75,7 +75,6 @@ bool GPUKernelRuntime::Init() { return ret; } -#ifdef ENABLE_DEBUGGER namespace { void LoadKernelData(Debugger *debugger, const CNodePtr &kernel, const std::vector &kernel_inputs, @@ -187,7 +186,6 @@ void ClearCurrentData(Debugger *debugger, bool dump_enabled) { } } } // namespace -#endif DeviceAddressPtr GPUKernelRuntime::CreateDeviceAddress(void *device_ptr, size_t device_size, const string &format, TypeId type_id) { @@ -546,13 +544,11 @@ bool GPUKernelRuntime::LaunchKernelDynamic(const session::KernelGraph *graph, De // The inputs and outputs memory of communication kernel need be continuous, so separate processing. AllocCommunicationOpDynamicRes(graph); -#ifdef ENABLE_DEBUGGER debugger_ = debugger; bool dump_enabled = GPUKernelRuntime::DumpDataEnabledIteration(); if (!mock) { UpdateStepNum(debugger, dump_enabled); } -#endif auto &kernels = graph->execution_order(); int exec_order = 1; @@ -567,12 +563,10 @@ bool GPUKernelRuntime::LaunchKernelDynamic(const session::KernelGraph *graph, De AddressPtrList kernel_outputs; auto ret = AllocKernelDynamicRes(*kernel_mod, kernel, &kernel_inputs, &kernel_workspaces, &kernel_outputs, mock); if (!ret) { -#ifdef ENABLE_DEBUGGER if (!mock) { // invalidate current data collected by the debugger ClearCurrentData(debugger, dump_enabled); } -#endif return false; } if (!mock) { @@ -591,29 +585,23 @@ bool GPUKernelRuntime::LaunchKernelDynamic(const session::KernelGraph *graph, De } else { LaunchKernelWithTimeProfiling(kernel, kernel_inputs, kernel_workspaces, kernel_outputs); } -#ifdef ENABLE_DEBUGGER // called once per kernel to collect the outputs to the kernel (does a SyncDeviceToHost) LoadKernelData(debugger, kernel, kernel_inputs, kernel_workspaces, kernel_outputs, exec_order, stream_, dump_enabled); -#endif } exec_order = exec_order + 1; FreeKernelDynamicRes(kernel); if (!UpdateMemorySwapTask(kernel, mock, profiling)) { -#ifdef ENABLE_DEBUGGER if (!mock) { // invalidate current data collected by the debugger ClearCurrentData(debugger, dump_enabled); } -#endif return false; } } if (!mock) { -#ifdef ENABLE_DEBUGGER // collect weights and bias for dump mode LoadParameters(graph, debugger, dump_enabled); -#endif CHECK_OP_RET_WITH_EXCEPT(SyncStream(), "SyncStream failed."); } ClearSwapInfo(mock);