From 20ff7a5d4ba4e2db2a448d6766addca298298426 Mon Sep 17 00:00:00 2001 From: huanruizhi Date: Mon, 30 Dec 2024 20:06:41 +0800 Subject: [PATCH] add log --- .../optimizers/om_partition_subgraphs_pass.cc | 56 +++++-------------- 1 file changed, 14 insertions(+), 42 deletions(-) diff --git a/tf_adapter/optimizers/om_partition_subgraphs_pass.cc b/tf_adapter/optimizers/om_partition_subgraphs_pass.cc index 3eced9e72..6944c5e05 100644 --- a/tf_adapter/optimizers/om_partition_subgraphs_pass.cc +++ b/tf_adapter/optimizers/om_partition_subgraphs_pass.cc @@ -736,7 +736,7 @@ Status FindNpuSupportCandidates(const Graph &graph, OrderedNodeSet *candidates, } } int64 endTime = InferShapeUtil::GetCurrentTimestap(); - ADP_LOG(INFO) << "TFadapter find Npu support candidates cost: [" << ((endTime - startTime) / kMicrosToMillis) + ADP_LOG(EVENT) << "TFadapter find Npu support candidates cost: [" << ((endTime - startTime) / kMicrosToMillis) << " ms]"; return Status::OK(); } @@ -802,6 +802,7 @@ struct Cluster { void MergeClusters(const Edge *edge, std::map> &cluster_map, bool swap = false) { Node *src = edge->src(); Node *dst = edge->dst(); + LOG(INFO) << "begin merge dst cluster:" << dst->name() << " to src_cluster:" << src->name(); if (swap) { std::swap(src, dst); @@ -816,6 +817,7 @@ void MergeClusters(const Edge *edge, std::map> (void) cluster_map[src]->nodes.insert(node); cluster_map[node] = cluster_map[src]; } + LOG(INFO) << "end merge dst cluster:" << dst->name() << " to src_cluster:" << src->name(); } Status MergeSubgraphsInNewWay(std::vector> &sortedCluster, OrderedNodeSet &npuSupportCandidates, @@ -936,7 +938,7 @@ Status MarkForPartition(const std::unique_ptr *graph_in, int &clusterNum, TF_RETURN_IF_ERROR(FindNpuSupportCandidates(*graph, &npuSupportCandidates, func_lib, pass_options)); TF_RETURN_IF_ERROR(AddRelationalConst(*graph, &npuSupportCandidates)); } - + LOG(INFO) << "begin find clusters"; std::map> cluster_map; tensorflow::GraphCycles cycles; std::string job = pass_options["job"]; @@ -958,6 +960,7 @@ Status MarkForPartition(const std::unique_ptr *graph_in, int &clusterNum, } } } + LOG(INFO) << "end init cluster_map"; // Check for existing cyclicity in the graph for (auto edge : graph->edges()) { REQUIRES_NOT_NULL(edge); @@ -976,6 +979,7 @@ Status MarkForPartition(const std::unique_ptr *graph_in, int &clusterNum, dst->DebugString(), " would create a cycle)"); } } + LOG(INFO) << "end check existing cycle"; bool changed = false; do { @@ -1002,6 +1006,7 @@ Status MarkForPartition(const std::unique_ptr *graph_in, int &clusterNum, // Check if contracting the edge will lead to cycles // if not, MergeClusters + LOG(INFO) << "begin contracting clusters" << "src node:" << src->name() << ", dst node:" << dst->name(); if (cycles.HasEdge(src_index, dst_index)) { auto contracted = cycles.ContractEdge(src_index, dst_index); if (!contracted) { @@ -1038,7 +1043,7 @@ Status MarkForPartition(const std::unique_ptr *graph_in, int &clusterNum, std::map> clusterIndexToMerge; std::set seen; std::set clusterSet; - + LOG(INFO) << "begin merge clusters to generate geop"; for (const auto &item : cluster_map) { auto cluster = item.second.get(); if (seen.count(cluster) != 0) { continue; } @@ -1082,53 +1087,20 @@ Status MarkForPartition(const std::unique_ptr *graph_in, int &clusterNum, } (void) seen.insert(cluster); } + LOG(INFO) << "end init clusterSet and clusterInfo"; // Generate Merge possibility between clusters if (clusterSet.size() > 1) { + LOG(INFO) << "begin Generate Merge possibility between clusters"; for (int src : clusterSet) { for (int dst : clusterSet) { if (src == dst) { continue; } if (!cycles.IsReachableNonConst(src, dst) && !cycles.IsReachableNonConst(dst, src)) { - if (mix_compile_mode) { - bool canReach = false; - for (auto cluster : clusterIndexToMerge[src]) { - if (cycles.IsReachableNonConst(dst, cluster) || cycles.IsReachableNonConst(cluster, dst)) { - canReach = true; - break; - } - } - - if (!canReach && job != "localhost") { - Cluster *cluster_src = nullptr; - Cluster *cluster_dst = nullptr; - for (const auto &cluster_item : cluster_map) { - if (cluster_src == nullptr && src == cluster_item.second->index) { - cluster_src = cluster_item.second.get(); - } - if (cluster_dst == nullptr && dst == cluster_item.second->index) { - cluster_dst = cluster_item.second.get(); - } - if (cluster_src != nullptr && cluster_dst != nullptr) { break; } - } - bool find_same_start = false; - for (const auto &src_start_name : cluster_src->start_nodes_name) { - if (std::any_of(cluster_dst->start_nodes_name.begin(), cluster_dst->start_nodes_name.end(), - [&src_start_name](const std::string dst_start_name) { return src_start_name == dst_start_name; })) { - find_same_start = true; - } - if (find_same_start) { break; } - } - if (find_same_start) { canReach = true; } - } - if (!canReach) { - (void) clusterToMerge[clusterInfo[src].first].insert(clusterInfo[dst].first); - (void) clusterIndexToMerge[src].insert(dst); - } - } else { - (void) clusterToMerge[clusterInfo[src].first].insert(clusterInfo[dst].first); - } + LOG(INFO) << "cluster:" << clusterInfo[src].first << " can merge with:" << clusterInfo[dst].first; + (void) clusterToMerge[clusterInfo[src].first].insert(clusterInfo[dst].first); } } } + LOG(INFO) << "end Generate Merge possibility between clusters"; } struct ClusterCompare { @@ -1146,7 +1118,7 @@ Status MarkForPartition(const std::unique_ptr *graph_in, int &clusterNum, return errors::Internal("Sorted cluster size should be equal to origin subgraph num. ", "Sorted cluster size is ", sortedCluster.size(), ", origin subgraph num is ", clusterNum); } - ADP_LOG(INFO) << "Cluster num is " << clusterNum; + ADP_LOG(EVENT) << "Cluster num is " << clusterNum; if (clusterNum == 0) { return Status::OK(); } int minGroupSize = 1; // default threshold is 10. -- Gitee