diff --git a/mindspore/ccsrc/backend/common/session/kernel_graph_mgr.cc b/mindspore/ccsrc/backend/common/session/kernel_graph_mgr.cc index a6681e23acb2f9886e412d2474615ae958fc1e2f..726918cb35cefb40647f8c45a9f34386ff0effa2 100644 --- a/mindspore/ccsrc/backend/common/session/kernel_graph_mgr.cc +++ b/mindspore/ccsrc/backend/common/session/kernel_graph_mgr.cc @@ -473,7 +473,8 @@ void SaveKernelInfoRuntimeCache(KernelInfoDevice *kernel_info, nlohmann::json *c nlohmann::json SaveAnfKernelInfo(const AnfNodePtr &node) { nlohmann::json single_json; - if (AnfUtils::IsRealKernel(node)) { + if (AnfUtils::IsRealKernel(node) && + (dynamic_cast(node->kernel_info())->select_kernel_build_info() != nullptr)) { single_json[kOriginDataFormat] = AnfAlgo::GetOriginDataFormat(node); const auto &input_formats = AnfAlgo::GetAllInputFormats(node); if (!input_formats.empty()) { @@ -622,10 +623,6 @@ void SaveNodesKernelInfoAndParamsName(const KernelGraphPtr &kg, const std::vecto MS_LOG(INFO) << "The node " << node->DebugString() << " has not kernel_info."; continue; } - if (dynamic_cast(node->kernel_info())->select_kernel_build_info() == nullptr) { - MS_LOG(INFO) << "The node " << node->DebugString() << " has kernel_info but build info is null."; - continue; - } const auto &kernel_info_json = SaveAnfKernelInfo(node); if (!kernel_info_json.empty()) { kernels_info_json[name] = kernel_info_json; @@ -1985,6 +1982,9 @@ KernelGraphPtr KernelGraphMgr::ConstructKernelGraph(const AnfNodePtrList &lst, c std::vector> child_graph_order; auto graph = NewKernelGraph(); MS_EXCEPTION_IF_NULL(graph); + if ((!lst.empty()) && lst[0] != nullptr && lst[0]->func_graph() != nullptr) { + front_backend_graph_map_[lst[0]->func_graph().get()] = graph; + } // Set the zero copy flag in subgraph sink mode. if (is_enable_zero_copy) { MS_LOG(INFO) << "Set zero copy flag for graph:" << graph->ToString(); diff --git a/mindspore/ccsrc/common/debug/mindir_exporter.cc b/mindspore/ccsrc/common/debug/mindir_exporter.cc index d8f5699445e84640b5e0ca1ddf5d16bfcd9ef709..a700af2ac6363c6ee9e766ee5a39cbea74acd599 100644 --- a/mindspore/ccsrc/common/debug/mindir_exporter.cc +++ b/mindspore/ccsrc/common/debug/mindir_exporter.cc @@ -190,7 +190,7 @@ bool IrExportBuilder::BuildPrimitivesByMap(std::map * continue; } if (attr.second == nullptr) { - MS_LOG(ERROR) << "attr: " << attr.first << " has no value."; + MS_LOG(INFO) << "attr: " << attr.first << " has no value."; continue; } mind_ir::AttributeProto *attr_proto = prim_proto->add_attribute(); diff --git a/mindspore/ccsrc/runtime/graph_scheduler/graph_compiler.cc b/mindspore/ccsrc/runtime/graph_scheduler/graph_compiler.cc index 203f7944fc920acad3eaceeb402729eb1b4a7ad5..967aef12945e23f9c3bd8c5d307708b55b2472f9 100644 --- a/mindspore/ccsrc/runtime/graph_scheduler/graph_compiler.cc +++ b/mindspore/ccsrc/runtime/graph_scheduler/graph_compiler.cc @@ -95,9 +95,9 @@ bool EnableBackendCompileCache(const FuncGraphPtr &func_graph, const device::Dev if (context.RestrictedScenarios()) { return false; } - // if (MsContext::GetInstance()->backend_policy() == "ge") { - // return false; - // } + if (MsContext::GetInstance()->backend_policy() == "ge") { + return false; + } if (device_type != device::DeviceType::kAscend) { return false; } @@ -120,6 +120,23 @@ bool UseCacheToCompileGraph(const FuncGraphPtr &func_graph, const device::Device return true; } +bool UseCacheToCompileGraphKBK(const FuncGraphPtr &func_graph, const device::DeviceType &device_type) { + if (!CompileCacheEnable()) { + return false; + } + auto &context = CompileCacheContext::GetInstance(); + if (context.FrontGraph() != func_graph) { + return false; + } + if (device_type != device::DeviceType::kAscend) { + return false; + } + if (!context.UseCompileCache()) { + return false; + } + return true; +} + bool ExportCompileCache(const FuncGraphPtr &func_graph, const device::DeviceType &device_type) { if (!EnableBackendCompileCache(func_graph, device_type)) { return false; @@ -652,19 +669,15 @@ std::pair GraphCompiler::CompileGraphForKernelRunModeUseCache(con MS_EXCEPTION_IF_NULL(session_); MS_EXCEPTION_IF_NULL(func_graph); const auto &context = MsContext::GetInstance(); - if (!UseCacheToCompileGraph(func_graph, device_context->GetDeviceType())) { + if (!UseCacheToCompileGraphKBK(func_graph, device_context->GetDeviceType())) { export_kbk_compile_cache_ = UpdateCacheFlag(func_graph, device_context); return {false, 0}; } - MS_LOG(WARNING) << "Status record: start use cache to compile graph kbk."; + MS_LOG(INFO) << "Status record: start use cache to compile graph kbk."; std::vector all_graphs; KernelGraphPtr graph = session_->ConstructKernelGraph(&all_graphs); GraphId graph_id = graph->graph_id(); use_cache_to_compile_graph_ = true; - std::string ir_name = "after_load_cache_" + std::to_string(graph_id) + ".ir"; - MS_LOG(WARNING) << "TEST: Save graphs after load: " << ir_name; - DumpIR(ir_name, graph); - MS_LOG(WARNING) << "TEST: recreate kernel and address"; PROF_START(CreateKernel); device_context->GetKernelExecutor(false)->CreateKernel(graph->execution_order()); PROF_END(CreateKernel); @@ -707,7 +720,7 @@ std::pair GraphCompiler::CompileGraphForKernelRunModeUseCache(con CompileCacheContext::GetInstance().Clear(); } graph->EnableRuntimeCache(); - MS_LOG(WARNING) << "Status record: end use cache to compile graph kbk. graph id: " << graph_id; + MS_LOG(INFO) << "Status record: end use cache to compile graph kbk. graph id: " << graph_id; return {true, graph_id}; } diff --git a/mindspore/core/load_mindir/load_model.cc b/mindspore/core/load_mindir/load_model.cc index 12be681d1a2d872388c147d49e744b1b4f830b3d..a4028cc845219881417bf688c11c75cbc023c0a0 100644 --- a/mindspore/core/load_mindir/load_model.cc +++ b/mindspore/core/load_mindir/load_model.cc @@ -2227,6 +2227,18 @@ bool MSANFModelParser::Parse(const mind_ir::ModelProto &model_proto, const std:: return true; }; + // Build value node first + const mind_ir::GraphProto &proto = model_proto.graph(); + for (int i = 0; i < proto.node_size(); ++i) { + const mind_ir::NodeProto &node_proto = proto.node(i); + if (node_proto.op_type() == kConstantValueNode) { + if (!BuildValueNodeForFuncGraph(node_proto)) { + MS_LOG(ERROR) << "Build value node failed for " << node_proto.output(0); + return false; + } + } + } + // GraphKernel contains attribute with graph, so build other primitives first, than deal with the GraphKernels. std::vector graph_kernel_prim_proto; for (int i = 0; i < model_proto.primitives_size(); ++i) {