codedex clean

This commit is contained in:
Margaret_wangrui 2021-07-29 12:55:46 +08:00
parent e187cfc889
commit ee0877c9c2
8 changed files with 33 additions and 13 deletions

View File

@ -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<int>(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<RunFunc>(
[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<BaseRef> 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<GraphCompiler> &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<tensor::TensorPtr> 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 &parameter : 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);

View File

@ -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<FuncGraphPtr> fg) override;
VectorRef RunGraph(GraphId graph_id, const VectorRef &args);

View File

@ -471,6 +471,8 @@ struct SplitDynamicNodesHelper {
}
void AddSegments(std::vector<GraphSegmentPtr> *segments, std::map<AnfNodePtr, GraphSegmentPtr> *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 {

View File

@ -36,7 +36,6 @@
namespace mindspore {
namespace compile {
namespace {
// Return the list of nodes whose values are required beyond this segment.
// Arguments:

View File

@ -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<bool>(MS_CTX_ENABLE_MINDRT, true);
}
} // namespace compile
} // namespace mindspore

View File

@ -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:

View File

@ -489,7 +489,7 @@ void FinalVM::SyncData(const py::object &arg) {
}
if (py::isinstance<tensor::Tensor>(arg)) {
auto tensor = py::cast<tensor::TensorPtr>(arg);
(void)tensor->data_sync();
tensor->data_sync();
}
}

View File

@ -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<ssize_t>(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<ReturnWrap>(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<FuncGraphPtr>(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<SetRef>(iterG->second).size() != 0) {