From ee0877c9c24e505bdb77e345e27599aa3c367e71 Mon Sep 17 00:00:00 2001 From: Margaret_wangrui Date: Thu, 29 Jul 2021 12:55:46 +0800 Subject: [PATCH] codedex clean --- mindspore/ccsrc/vm/backend.cc | 21 +++++++++++++++++---- mindspore/ccsrc/vm/backend.h | 2 +- mindspore/ccsrc/vm/graph_partition.cc | 2 ++ mindspore/ccsrc/vm/segment_runner.cc | 1 - mindspore/ccsrc/vm/transform.cc | 5 ++--- mindspore/ccsrc/vm/transform.h | 2 +- mindspore/ccsrc/vm/vm.cc | 2 +- mindspore/ccsrc/vm/vmimpl.cc | 11 +++++++++-- 8 files changed, 33 insertions(+), 13 deletions(-) diff --git a/mindspore/ccsrc/vm/backend.cc b/mindspore/ccsrc/vm/backend.cc index c585a4c7fe..c0107e0694 100644 --- a/mindspore/ccsrc/vm/backend.cc +++ b/mindspore/ccsrc/vm/backend.cc @@ -79,8 +79,10 @@ LinConvertResult MsBackend::MsConvert(const GraphSegmentPtr &segment, const std: MS_EXCEPTION_IF_NULL(graph); for (auto &pre_segment : segment->pre_segments_) { MS_EXCEPTION_IF_NULL(pre_segment); + MS_EXCEPTION_IF_NULL(target_sess_); auto pre_graph = target_sess_->GetGraph(pre_segment->graph_id_); if (pre_graph == nullptr) { + MS_EXCEPTION_IF_NULL(other_sess_); pre_graph = other_sess_->GetGraph(pre_segment->graph_id_); } MS_EXCEPTION_IF_NULL(pre_graph); @@ -97,8 +99,10 @@ LinConvertResult MsBackend::MsConvert(const GraphSegmentPtr &segment, const std: const bool pynative_mode = (ms_context->get_param(MS_CTX_EXECUTION_MODE) == kPynativeMode); if (!pynative_mode || target != "Ascend") { if (target != target_device_ && !target.empty()) { + MS_EXCEPTION_IF_NULL(other_sess_); other_sess_->BuildGraph(graph_id); } else if (!is_multi_graph_sink_) { + MS_EXCEPTION_IF_NULL(target_sess_); target_sess_->BuildGraph(graph_id); } } @@ -107,7 +111,7 @@ LinConvertResult MsBackend::MsConvert(const GraphSegmentPtr &segment, const std: MS_EXCEPTION_IF_NULL(result.run); result.simu_run = std::make_shared( - [graph_id, this](const VectorRef &args) -> VectorRef { return MsSimuRunGraph(graph_id, args); }); + [graph_id, this](const VectorRef &args) -> VectorRef { return MsSimuRunGraph(graph_id); }); MS_EXCEPTION_IF_NULL(result.simu_run); result.graph_id = graph_id; @@ -116,7 +120,7 @@ LinConvertResult MsBackend::MsConvert(const GraphSegmentPtr &segment, const std: } // compile set input output -VectorRef MsBackend::MsSimuRunGraph(const GraphId &g, const VectorRef &args) { +VectorRef MsBackend::MsSimuRunGraph(const GraphId &g) { MS_LOG(DEBUG) << "Set graph input:" << g; std::vector outputs; (void)std::transform(graph_id_map_[g].outputs.begin(), graph_id_map_[g].outputs.end(), std::back_inserter(outputs), @@ -286,6 +290,7 @@ VectorRef MsBackend::MsRunGraph(const GraphId &g, const VectorRef &args, const s } void MsBackend::Link(GraphId graph_id) { + MS_EXCEPTION_IF_NULL(target_sess_); if (graph_id == kInvalidGraphId) { graph_id = target_sess_->GetFinalRunGraph(); } @@ -330,7 +335,10 @@ void MsBackend::ClearSessionGraphs() { } #ifdef ENABLE_DEBUGGER -void MsBackend::SetDebugger() { target_sess_->SetDebugger(); } +void MsBackend::SetDebugger() { + MS_EXCEPTION_IF_NULL(target_sess_); + target_sess_->SetDebugger(); +} #endif MindRTBackend::MindRTBackend(const std::string &backend_name, const std::string &device_name, uint32_t device_id) @@ -414,6 +422,7 @@ void MindRTBackend::CompileGraph(const FuncGraphPtr &func_graph) { if (segment->nodes_.size() == 0) { MS_LOG(EXCEPTION) << "The segments size is 0."; } + MS_EXCEPTION_IF_NULL(segment->nodes_[0]); MS_LOG(INFO) << "Compile normal segment, the first node: " << segment->nodes_[0]->fullname_with_scope(); // Get the device context. @@ -495,6 +504,7 @@ void GetControlOpInput(const std::shared_ptr &graph_compiler, con VectorRef *args) { MS_EXCEPTION_IF_NULL(front_cnode); MS_EXCEPTION_IF_NULL(backend_cnode); + MS_EXCEPTION_IF_NULL(graph_compiler); size_t input_index = 0; auto inputs = front_cnode->inputs(); for (size_t i = 1; i < inputs.size(); i++) { @@ -696,6 +706,7 @@ void PrepareForDebuggr(const GraphCompilerInfo &graph_compiler_info) { if (DumpJsonParser::GetInstance().e2e_dump_enabled()) { DumpJsonParser::GetInstance().ClearGraph(); for (size_t i = 0; i < graph_compiler_info.graphs_.size(); ++i) { + MS_EXCEPTION_IF_NULL(graph_compiler_info.device_contexts_[i]); if (graph_compiler_info.device_contexts_[i]->GetDeviceAddressType() == device::DeviceAddressType::kCPU) { DumpJsonParser::GetInstance().SaveGraph(graph_compiler_info.graphs_[i].get()); } @@ -803,7 +814,7 @@ void MindRTBackend::RunGraph(const ActorInfo &actor_info, const VectorRef &args, // Input tensors of the control node. std::vector input_tensor; - + MS_EXCEPTION_IF_NULL(graph_compiler_info.control_node_parser_); // Get inputs of control node which come from the host actor. const auto &control_node_parameters = graph_compiler_info.control_node_parser_->GetControlNodeParameter(); for (const auto ¶meter : control_node_parameters) { @@ -1034,6 +1045,7 @@ void MindRTBackend::RunGraph(const ActorInfo &actor_info, OpRunInfo *op_run_info } for (auto &tensor : tensors_without_value_node) { + MS_EXCEPTION_IF_NULL(tensor); if (tensor->NeedWaitDevice()) { tensor->WaitDevice(); } @@ -1047,6 +1059,7 @@ void MindRTBackend::RunGraph(const ActorInfo &actor_info, OpRunInfo *op_run_info // Fetch outputs. const auto &graph = graph_compiler_info.graphs_.front(); MS_EXCEPTION_IF_NULL(graph); + MS_EXCEPTION_IF_NULL(graph_compiler_); const auto &output_nodes = graph_compiler_->GetGraphOutputNodes(graph->graph_id()); MS_EXCEPTION_IF_NULL(outputs); UpdateOutput(output_nodes, outputs); diff --git a/mindspore/ccsrc/vm/backend.h b/mindspore/ccsrc/vm/backend.h index 19546f9b1d..005880eb35 100644 --- a/mindspore/ccsrc/vm/backend.h +++ b/mindspore/ccsrc/vm/backend.h @@ -81,7 +81,7 @@ class MsBackend : public Backend { LinConvertResult MsConvert(const GraphSegmentPtr &segment, const std::string &target = ""); VectorRef MsRunGraph(const GraphId &g, const VectorRef &args, const std::string &target = ""); - VectorRef MsSimuRunGraph(const GraphId &g, const VectorRef &args); + VectorRef MsSimuRunGraph(const GraphId &g); void Link(GraphId) override; GraphId CompileGraph(NotNull fg) override; VectorRef RunGraph(GraphId graph_id, const VectorRef &args); diff --git a/mindspore/ccsrc/vm/graph_partition.cc b/mindspore/ccsrc/vm/graph_partition.cc index 8325aa594d..f15cbd509f 100644 --- a/mindspore/ccsrc/vm/graph_partition.cc +++ b/mindspore/ccsrc/vm/graph_partition.cc @@ -471,6 +471,8 @@ struct SplitDynamicNodesHelper { } void AddSegments(std::vector *segments, std::map *node_to_segment) { + MS_EXCEPTION_IF_NULL(segments); + MS_EXCEPTION_IF_NULL(node_to_segment); if (pre_nodes.size() < merge_node_threshold) { AddSegment(pre_nodes, segments, node_to_segment); } else { diff --git a/mindspore/ccsrc/vm/segment_runner.cc b/mindspore/ccsrc/vm/segment_runner.cc index ac266d9a3a..86bf2cb5a1 100644 --- a/mindspore/ccsrc/vm/segment_runner.cc +++ b/mindspore/ccsrc/vm/segment_runner.cc @@ -36,7 +36,6 @@ namespace mindspore { namespace compile { - namespace { // Return the list of nodes whose values are required beyond this segment. // Arguments: diff --git a/mindspore/ccsrc/vm/transform.cc b/mindspore/ccsrc/vm/transform.cc index 3373fc2855..43e6aa9cb6 100644 --- a/mindspore/ccsrc/vm/transform.cc +++ b/mindspore/ccsrc/vm/transform.cc @@ -505,7 +505,7 @@ void CompileGraphs::Compile(const FuncGraphPtr &graph) { } // Link instructions from multiple function graphs together. -FinalVMPtr CompileGraphs::Link(const FuncGraphPtr &graph) { +FinalVMPtr CompileGraphs::Link() { MS_LOG(DEBUG) << "Start"; for (std::size_t i = 0; i < insts_.size(); i++) { InstType inst = insts_[i]; @@ -543,7 +543,7 @@ FinalVMPtr CompileGraphs::CompileAndLink(const FuncGraphPtr &graph) { } } - FinalVMPtr rt = Link(graph); + FinalVMPtr rt = Link(); Reset(); MS_LOG(DEBUG) << "End"; return rt; @@ -609,6 +609,5 @@ void SetMindRTEnable() { MS_LOG(INFO) << "Enable mindRT."; context_ptr->set_param(MS_CTX_ENABLE_MINDRT, true); } - } // namespace compile } // namespace mindspore diff --git a/mindspore/ccsrc/vm/transform.h b/mindspore/ccsrc/vm/transform.h index c892653368..4f0e19f422 100644 --- a/mindspore/ccsrc/vm/transform.h +++ b/mindspore/ccsrc/vm/transform.h @@ -122,7 +122,7 @@ class CompileGraphs { } void Compile(const FuncGraphPtr &func_graph); - FinalVMPtr Link(const FuncGraphPtr &func_graph); + FinalVMPtr Link(); FinalVMPtr CompileAndLink(const FuncGraphPtr &func_graph); private: diff --git a/mindspore/ccsrc/vm/vm.cc b/mindspore/ccsrc/vm/vm.cc index 8e7aec01d7..366405840c 100644 --- a/mindspore/ccsrc/vm/vm.cc +++ b/mindspore/ccsrc/vm/vm.cc @@ -489,7 +489,7 @@ void FinalVM::SyncData(const py::object &arg) { } if (py::isinstance(arg)) { auto tensor = py::cast(arg); - (void)tensor->data_sync(); + tensor->data_sync(); } } diff --git a/mindspore/ccsrc/vm/vmimpl.cc b/mindspore/ccsrc/vm/vmimpl.cc index cbaff3279d..cad846324c 100644 --- a/mindspore/ccsrc/vm/vmimpl.cc +++ b/mindspore/ccsrc/vm/vmimpl.cc @@ -76,6 +76,7 @@ Closure::Closure(const FuncGraphPtr &graph, const AnfNodePtrToBaseRefMap &values BaseRef Closure::operator()(const VectorRef &args) { MS_LOG(DEBUG) << "Start closure"; + MS_EXCEPTION_IF_NULL(vm_); return vm_->Evaluate(func_graph_, args, values_); } @@ -85,6 +86,7 @@ BaseRef Partial::operator()(const VectorRef &nodes) { VectorRef arglist; (void)arglist.insert(arglist.end(), args_.begin(), args_.end()); (void)arglist.insert(arglist.end(), nodes.begin(), nodes.end()); + MS_EXCEPTION_IF_NULL(vm_); return vm_->Call(fn_, arglist); } @@ -115,8 +117,10 @@ void VM::AcquireGraph(const FuncGraphPtr &graph) { if (vars_.find(graph) != vars_.end()) { return; } + MS_EXCEPTION_IF_NULL(manager_); // Add g to manager manager_->AddFuncGraph(graph); + MS_EXCEPTION_IF_NULL(graph->manager()); // Compute fvs for all acquired graph auto graphs = graph->manager()->func_graphs(); for (auto g = graphs.begin(); g != graphs.end(); ++g) { @@ -178,6 +182,7 @@ BaseRef VM::Export(const BaseRef &value) { // Run a graph. // This will evaluate the passed-in graph and return the resulting value. BaseRef VM::Evaluate(const FuncGraphPtr &graph, const VectorRef &args, const AnfNodePtrToBaseRefMap &closure) { + MS_EXCEPTION_IF_NULL(graph); AcquireGraph(graph); MS_LOG(DEBUG) << "Evalue arg size: " << args.size(); if (args.size() != graph->parameters().size()) { @@ -197,6 +202,7 @@ BaseRef VM::Evaluate(const FuncGraphPtr &graph, const VectorRef &args, const Anf // execute frames starting from top frame while (!frames.empty()) { auto frame = frames[frames.size() - 1]; + MS_EXCEPTION_IF_NULL(frame); auto todo = frame->todo(); while (!todo.empty()) { auto except = HandleNode(todo[todo.size() - 1], frame); @@ -213,6 +219,7 @@ BaseRef VM::Evaluate(const FuncGraphPtr &graph, const VectorRef &args, const Anf (void)frames.erase(frames.begin() + (static_cast(frames.size()) - 1)); if (frames.size() > 0) { auto top = frames[frames.size() - 1]; + MS_EXCEPTION_IF_NULL(top); auto td = top->todo(); // set value for top frame's last evaluated node if (td.empty()) { @@ -336,7 +343,7 @@ BaseRef VM::DispatchCall(const AnfNodePtr &node, const VMFramePtr &frame, const MS_LOG(DEBUG) << "Return args:" << args.size(); return std::make_shared(args[0]); } - + MS_EXCEPTION_IF_NULL(frame); if (fnval == prim::kPrimMakeTuple) { frame->values()[node] = args; return BaseRef(); @@ -391,7 +398,7 @@ BaseRef VM::HandleNode(const AnfNodePtr &node, const VMFramePtr &frame) { MS_LOG(EXCEPTION) << "We only visit valuenode graphs "; } auto g = GetValueNode(node); - + MS_EXCEPTION_IF_NULL(frame); // if g is a graph with fvs, we need to make a closure for it auto iterG = vars_.find(g); if (iterG != vars_.end() && utils::cast(iterG->second).size() != 0) {