diff --git a/src/mpl/include/mpl/rtl_mp.h b/src/mpl/include/mpl/rtl_mp.h index 1b98289cd04..d39344f8319 100644 --- a/src/mpl/include/mpl/rtl_mp.h +++ b/src/mpl/include/mpl/rtl_mp.h @@ -65,8 +65,7 @@ class MacroPlacer float target_util, float min_ar, const char* report_directory, - bool keep_clustering_data, - bool data_flow_driven); + bool keep_clustering_data); void placeMacro(odb::dbInst* inst, const float& x_origin, diff --git a/src/mpl/src/clusterEngine.cpp b/src/mpl/src/clusterEngine.cpp index 69704875bc3..5ccfbdce8c7 100644 --- a/src/mpl/src/clusterEngine.cpp +++ b/src/mpl/src/clusterEngine.cpp @@ -54,11 +54,6 @@ void ClusteringEngine::run() createRoot(); setBaseThresholds(); - - if (data_flow_driven_) { - createDataFlow(); - } - createIOClusters(); if (design_metrics_->getNumStdCell() == 0) { @@ -653,234 +648,6 @@ void ClusteringEngine::createIOPadCluster(odb::dbInst* pad) tree_->root->addChild(std::move(cluster)); } -// Dataflow is used to improve quality of macro placement. -// Here we model each std cell instance, IO pin and macro pin as vertices. -void ClusteringEngine::createDataFlow() -{ - if (design_metrics_->getNumStdCell() != 0 && !stdCellsHaveLiberty()) { - logger_->warn( - MPL, - 14, - "No Liberty data found for std cells. Continuing without dataflow."); - data_connections_.is_empty = true; - return; - } - - // Create vertices IDs. - const VerticesMaps vertices_maps = computeVertices(); - const int num_of_vertices = static_cast(vertices_maps.stoppers.size()); - - const DataFlowHypergraph hypergraph = computeHypergraph(num_of_vertices); - - // Traverse hypergraph to build dataflow. - for (auto [src, src_pin] : vertices_maps.id_to_bterm) { - int idx = 0; - std::vector visited(num_of_vertices, false); - std::vector> insts(max_num_of_hops_); - dataFlowDFSIOPin( - src, idx, vertices_maps, hypergraph, insts, visited, false); - dataFlowDFSIOPin(src, idx, vertices_maps, hypergraph, insts, visited, true); - - data_connections_.io_and_regs.emplace_back(src_pin, insts); - } - - for (auto [src, src_pin] : vertices_maps.id_to_macro_pin) { - int idx = 0; - std::vector visited(num_of_vertices, false); - std::vector> std_cells(max_num_of_hops_); - std::vector> macros(max_num_of_hops_); - dataFlowDFSMacroPin( - src, idx, vertices_maps, hypergraph, std_cells, macros, visited, false); - dataFlowDFSMacroPin( - src, idx, vertices_maps, hypergraph, std_cells, macros, visited, true); - - data_connections_.macro_pins_and_regs.emplace_back(src_pin, std_cells); - data_connections_.macro_pins_and_macros.emplace_back(src_pin, macros); - } -} - -// Here we assume that there are std cells in the design! -bool ClusteringEngine::stdCellsHaveLiberty() -{ - for (odb::dbInst* inst : block_->getInsts()) { - if (isIgnoredInst(inst) || inst->isBlock()) { - continue; - } - - const sta::LibertyCell* liberty_cell = network_->libertyCell(inst); - if (liberty_cell) { - return true; - } - } - - return false; -} - -VerticesMaps ClusteringEngine::computeVertices() -{ - VerticesMaps vertices_maps; - - if (tree_->io_pads.empty()) { - computeIOVertices(vertices_maps); - } else { - computePadVertices(vertices_maps); - } - - computeStdCellVertices(vertices_maps); - computeMacroPinVertices(vertices_maps); - - debugPrint(logger_, - MPL, - "multilevel_autoclustering", - 1, - "Number of vertices: {}", - vertices_maps.stoppers.size()); - - return vertices_maps; -} - -void ClusteringEngine::computeIOVertices(VerticesMaps& vertices_maps) -{ - for (odb::dbBTerm* bterm : block_->getBTerms()) { - const int id = static_cast(vertices_maps.stoppers.size()); - odb::dbIntProperty::create(bterm, "vertex_id", id); - vertices_maps.id_to_bterm[id] = bterm; - vertices_maps.stoppers.push_back(true); - } -} - -void ClusteringEngine::computePadVertices(VerticesMaps& vertices_maps) -{ - for (odb::dbInst* pad : tree_->io_pads) { - const int id = static_cast(vertices_maps.stoppers.size()); - odb::dbIntProperty::create(pad, "vertex_id", id); - vertices_maps.id_to_std_cell[id] = pad; - vertices_maps.stoppers.push_back(true); - } -} - -void ClusteringEngine::computeStdCellVertices(VerticesMaps& vertices_maps) -{ - for (odb::dbInst* inst : block_->getInsts()) { - if (isIgnoredInst(inst) || inst->isBlock()) { - continue; - } - - const sta::LibertyCell* liberty_cell = network_->libertyCell(inst); - if (!liberty_cell) { - continue; - } - - const int id = static_cast(vertices_maps.stoppers.size()); - - // Registers are stoppers. - odb::dbIntProperty::create(inst, "vertex_id", id); - vertices_maps.id_to_std_cell[id] = inst; - - if (liberty_cell->hasSequentials()) { - vertices_maps.stoppers.push_back(true); - } else { - vertices_maps.stoppers.push_back(false); - } - } -} - -void ClusteringEngine::computeMacroPinVertices(VerticesMaps& vertices_maps) -{ - for (auto& [macro, hard_macro] : tree_->maps.inst_to_hard) { - for (odb::dbITerm* pin : macro->getITerms()) { - if (pin->getSigType() != odb::dbSigType::SIGNAL - && pin->getSigType() != odb::dbSigType::CLOCK) { - continue; - } - - const int id = static_cast(vertices_maps.stoppers.size()); - odb::dbIntProperty::create(pin, "vertex_id", id); - vertices_maps.id_to_macro_pin[id] = pin; - vertices_maps.stoppers.push_back(true); - } - } -} - -DataFlowHypergraph ClusteringEngine::computeHypergraph( - const int num_of_vertices) -{ - DataFlowHypergraph graph; - graph.vertices.resize(num_of_vertices); - graph.backward_vertices.resize(num_of_vertices); - - for (odb::dbNet* net : block_->getNets()) { - if (!isValidNet(net)) { - continue; - } - - int driver_id = -1; - std::set loads_id; - bool net_has_stdcell_without_liberty = false; - for (odb::dbITerm* iterm : net->getITerms()) { - odb::dbInst* inst = iterm->getInst(); - int vertex_id = -1; - - if (inst->isBlock()) { - vertex_id = odb::dbIntProperty::find(iterm, "vertex_id")->getValue(); - } else if (inst->isPad()) { - vertex_id = odb::dbIntProperty::find(inst, "vertex_id")->getValue(); - } else { - odb::dbIntProperty* int_prop - = odb::dbIntProperty::find(inst, "vertex_id"); - - // Std cells without liberty data are not marked as vertices - if (int_prop) { - vertex_id = int_prop->getValue(); - } else { - net_has_stdcell_without_liberty = true; - break; - } - } - - if (iterm->getIoType() == odb::dbIoType::OUTPUT) { - driver_id = vertex_id; - } else { - loads_id.insert(vertex_id); - } - } - - if (net_has_stdcell_without_liberty) { - continue; - } - - for (odb::dbBTerm* bterm : net->getBTerms()) { - const int vertex_id - = odb::dbIntProperty::find(bterm, "vertex_id")->getValue(); - if (bterm->getIoType() == odb::dbIoType::INPUT) { - driver_id = vertex_id; - } else { - loads_id.insert(vertex_id); - } - } - - // Skip high fanout nets or nets that do not have valid driver or loads - if (driver_id < 0 || loads_id.empty() - || loads_id.size() > tree_->large_net_threshold) { - continue; - } - - std::vector hyperedge{driver_id}; - for (auto& load : loads_id) { - if (load != driver_id) { - hyperedge.push_back(load); - } - } - graph.vertices[driver_id].push_back(graph.hyperedges.size()); - for (int i = 1; i < hyperedge.size(); i++) { - graph.backward_vertices[hyperedge[i]].push_back(graph.hyperedges.size()); - } - graph.hyperedges.push_back(std::move(hyperedge)); - } - - return graph; -} - void ClusteringEngine::addIgnorableMacro(odb::dbInst* inst) { if (!inst->isBlock()) { @@ -904,192 +671,6 @@ bool ClusteringEngine::isIgnoredInst(odb::dbInst* inst) return master->isPad() || master->isCover() || master->isEndCap(); } -// Forward or Backward DFS search to find sequential paths from/to IO pins based -// on hop count to macro pins -void ClusteringEngine::dataFlowDFSIOPin( - const int parent, - int idx, - const VerticesMaps& vertices_maps, - const DataFlowHypergraph& hypergraph, - std::vector>& insts, - std::vector& visited, - bool backward_search) -{ - visited[parent] = true; - if (vertices_maps.stoppers[parent]) { - if (parent < vertices_maps.id_to_bterm.size()) { - ; // currently we do not consider IO pin to IO pin connection - } else if (parent < vertices_maps.id_to_bterm.size() - + vertices_maps.id_to_std_cell.size()) { - insts[idx].insert(vertices_maps.id_to_std_cell.at(parent)); - } else { - insts[idx].insert(vertices_maps.id_to_macro_pin.at(parent)->getInst()); - } - idx++; - } - - if (idx >= max_num_of_hops_) { - return; - } - - if (!backward_search) { - for (auto& hyperedge : hypergraph.vertices[parent]) { - for (auto& vertex : hypergraph.hyperedges[hyperedge]) { - // we do not consider pin to pin - if (visited[vertex] || vertex < vertices_maps.id_to_bterm.size()) { - continue; - } - dataFlowDFSIOPin(vertex, - idx, - vertices_maps, - hypergraph, - insts, - visited, - backward_search); - } - } - } else { - for (auto& hyperedge : hypergraph.backward_vertices[parent]) { - const int vertex - = hypergraph.hyperedges[hyperedge].front(); // driver vertex - // we do not consider pin to pin - if (visited[vertex] || vertex < vertices_maps.id_to_bterm.size()) { - continue; - } - dataFlowDFSIOPin(vertex, - idx, - vertices_maps, - hypergraph, - insts, - visited, - backward_search); - } - } -} - -// Forward or Backward DFS search to find sequential paths between Macros based -// on hop count -void ClusteringEngine::dataFlowDFSMacroPin( - const int parent, - int idx, - const VerticesMaps& vertices_maps, - const DataFlowHypergraph& hypergraph, - std::vector>& std_cells, - std::vector>& macros, - std::vector& visited, - bool backward_search) -{ - visited[parent] = true; - if (vertices_maps.stoppers[parent]) { - if (parent < vertices_maps.id_to_bterm.size()) { - ; // the connection between IO and macro pins have been considers - } else if (parent < vertices_maps.id_to_bterm.size() - + vertices_maps.id_to_std_cell.size()) { - std_cells[idx].insert(vertices_maps.id_to_std_cell.at(parent)); - } else { - macros[idx].insert(vertices_maps.id_to_macro_pin.at(parent)->getInst()); - } - idx++; - } - - if (idx >= max_num_of_hops_) { - return; - } - - if (!backward_search) { - for (auto& hyperedge : hypergraph.vertices[parent]) { - for (auto& vertex : hypergraph.hyperedges[hyperedge]) { - // we do not consider pin to pin - if (visited[vertex] || vertex < vertices_maps.id_to_bterm.size()) { - continue; - } - dataFlowDFSMacroPin(vertex, - idx, - vertices_maps, - hypergraph, - std_cells, - macros, - visited, - backward_search); - } - } - } else { - for (auto& hyperedge : hypergraph.backward_vertices[parent]) { - const int vertex = hypergraph.hyperedges[hyperedge].front(); - // we do not consider pin to pin - if (visited[vertex] || vertex < vertices_maps.id_to_bterm.size()) { - continue; - } - dataFlowDFSMacroPin(vertex, - idx, - vertices_maps, - hypergraph, - std_cells, - macros, - visited, - backward_search); - } - } -} - -void ClusteringEngine::buildDataFlowConnections() -{ - if (data_connections_.is_empty) { - return; - } - - // bterm, macros or ffs - for (const auto& [bterm, insts] : data_connections_.io_and_regs) { - const int driver_id = tree_->maps.bterm_to_cluster_id.at(bterm); - Cluster* driver_cluster = tree_->maps.id_to_cluster.at(driver_id); - - for (int hops = 0; hops < max_num_of_hops_; hops++) { - std::set sink_clusters = computeSinks(insts[hops]); - const float conn_weight = computeConnWeight(hops); - for (const int sink_id : sink_clusters) { - if (driver_id != sink_id) { - Cluster* sink_cluster = tree_->maps.id_to_cluster.at(sink_id); - connect(driver_cluster, sink_cluster, conn_weight); - } - } - } - } - - // macros to ffs - for (const auto& [iterm, insts] : data_connections_.macro_pins_and_regs) { - const int driver_id = tree_->maps.inst_to_cluster_id.at(iterm->getInst()); - Cluster* driver_cluster = tree_->maps.id_to_cluster.at(driver_id); - - for (int hops = 0; hops < max_num_of_hops_; hops++) { - std::set sink_clusters = computeSinks(insts[hops]); - const float conn_weight = computeConnWeight(hops); - for (const int sink_id : sink_clusters) { - if (driver_id != sink_id) { - Cluster* sink_cluster = tree_->maps.id_to_cluster.at(sink_id); - connect(driver_cluster, sink_cluster, conn_weight); - } - } - } - } - - // macros to macros - for (const auto& [iterm, insts] : data_connections_.macro_pins_and_macros) { - const int driver_id = tree_->maps.inst_to_cluster_id.at(iterm->getInst()); - Cluster* driver_cluster = tree_->maps.id_to_cluster.at(driver_id); - - for (int hops = 0; hops < max_num_of_hops_; hops++) { - std::set sink_clusters = computeSinks(insts[hops]); - const float conn_weight = computeConnWeight(hops); - for (const int sink_id : sink_clusters) { - if (driver_id != sink_id) { - Cluster* sink_cluster = tree_->maps.id_to_cluster.at(sink_id); - connect(driver_cluster, sink_cluster, conn_weight); - } - } - } - } -} - void ClusteringEngine::connect(Cluster* a, Cluster* b, const float connection_weight) const @@ -1098,26 +679,6 @@ void ClusteringEngine::connect(Cluster* a, b->addConnection(a, connection_weight); } -float ClusteringEngine::computeConnWeight(const int hops) -{ - const float base_remoteness_factor = 2.0; - const float base_connection_weight = 1; - const float remoteness_factor = std::pow(base_remoteness_factor, hops); - - return base_connection_weight / remoteness_factor; -} - -std::set ClusteringEngine::computeSinks( - const std::set& insts) -{ - std::set sink_clusters; - for (auto& inst : insts) { - const int cluster_id = tree_->maps.inst_to_cluster_id.at(inst); - sink_clusters.insert(cluster_id); - } - return sink_clusters; -} - void ClusteringEngine::treatEachMacroAsSingleCluster() { odb::dbModule* module = block_->getTopModule(); @@ -2024,7 +1585,6 @@ void ClusteringEngine::rebuildConnections() { clearConnections(); buildNetListConnections(); - buildDataFlowConnections(); } void ClusteringEngine::clearConnections() diff --git a/src/mpl/src/clusterEngine.h b/src/mpl/src/clusterEngine.h index 696833192d0..69845d438a4 100644 --- a/src/mpl/src/clusterEngine.h +++ b/src/mpl/src/clusterEngine.h @@ -38,44 +38,6 @@ using InstToHardMap = std::map>; using ModuleToMetricsMap = std::map>; using PathInsts = std::vector>; -struct DataFlowHypergraph -{ - std::vector> vertices; - std::vector> backward_vertices; - std::vector> hyperedges; -}; - -// For data flow computation. -struct VerticesMaps -{ - std::map id_to_bterm; - std::map id_to_std_cell; - std::map id_to_macro_pin; - - // Each index represents a vertex in which - // the flow is interrupted. - std::vector stoppers; -}; - -struct DataFlow -{ - bool is_empty{false}; - - // Macro Pins --> Registers - // Registers --> Macro Pins - std::vector> macro_pins_and_regs; - - // IO --> Register - // Register --> IO - // IO --> Macro Pin - // Macro Pin --> IO - std::vector> io_and_regs; - - // Macro Pin --> Macros - // Macros --> Macro Pin - std::vector> macro_pins_and_macros; -}; - struct PhysicalHierarchyMaps { std::map id_to_cluster; @@ -144,7 +106,6 @@ class ClusteringEngine void setTree(PhysicalHierarchy* tree); void setHalos(std::map& macro_to_halo); - void setDataFlowDriven() { data_flow_driven_ = true; }; // Methods to update the tree as the hierarchical // macro placement runs. @@ -256,38 +217,10 @@ class ClusteringEngine void clearConnections(); void buildNetListConnections(); - void buildDataFlowConnections(); Net buildNet(odb::dbNet* db_net) const; void connectClusters(const Net& net); void connect(Cluster* a, Cluster* b, float connection_weight) const; - // Methods for data flow - void createDataFlow(); - bool stdCellsHaveLiberty(); - VerticesMaps computeVertices(); - void computeIOVertices(VerticesMaps& vertices_maps); - void computePadVertices(VerticesMaps& vertices_maps); - void computeStdCellVertices(VerticesMaps& vertices_maps); - void computeMacroPinVertices(VerticesMaps& vertices_maps); - DataFlowHypergraph computeHypergraph(int num_of_vertices); - void dataFlowDFSIOPin(int parent, - int idx, - const VerticesMaps& vertices_maps, - const DataFlowHypergraph& hypergraph, - std::vector>& insts, - std::vector& visited, - bool backward_search); - void dataFlowDFSMacroPin(int parent, - int idx, - const VerticesMaps& vertices_maps, - const DataFlowHypergraph& hypergraph, - std::vector>& std_cells, - std::vector>& macros, - std::vector& visited, - bool backward_search); - std::set computeSinks(const std::set& insts); - float computeConnWeight(int hops); - void printPhysicalHierarchyTree(Cluster* parent, int level); int64_t computeArea(odb::dbInst* inst); @@ -314,13 +247,6 @@ class ClusteringEngine int max_std_cell_{0}; int min_std_cell_{0}; - // Variables for data flow: - DataFlow data_connections_; - // The register distance between two macros for - // them to be considered connected when creating data flow. - const int max_num_of_hops_{5}; - bool data_flow_driven_{false}; - const float minimum_connection_ratio_{0.08}; int first_io_bundle_id_{-1}; diff --git a/src/mpl/src/hier_rtlmp.cpp b/src/mpl/src/hier_rtlmp.cpp index 2865b0a70ca..15cb995a368 100644 --- a/src/mpl/src/hier_rtlmp.cpp +++ b/src/mpl/src/hier_rtlmp.cpp @@ -182,11 +182,6 @@ void HierRTLMP::setKeepClusteringData(bool keep_clustering_data) keep_clustering_data_ = keep_clustering_data; } -void HierRTLMP::setDataFlowDriven() -{ - clustering_engine_->setDataFlowDriven(); -} - // Top Level Function // The flow of our MacroPlacer is divided into 6 stages. // 1) Multilevel Autoclustering: diff --git a/src/mpl/src/hier_rtlmp.h b/src/mpl/src/hier_rtlmp.h index 3a59e3daa83..458c374e0fa 100644 --- a/src/mpl/src/hier_rtlmp.h +++ b/src/mpl/src/hier_rtlmp.h @@ -103,7 +103,6 @@ class HierRTLMP void setMinAR(float min_ar); void setReportDirectory(const char* report_directory); void setKeepClusteringData(bool keep_clustering_data); - void setDataFlowDriven(); void setDebug(std::unique_ptr& graphics); void setDebugShowBundledNets(bool show_bundled_nets); diff --git a/src/mpl/src/mpl.i b/src/mpl/src/mpl.i index 881361ad64c..de5f515de9a 100644 --- a/src/mpl/src/mpl.i +++ b/src/mpl/src/mpl.i @@ -51,8 +51,7 @@ bool rtl_macro_placer_cmd(const int max_num_macro, const float target_util, const float min_ar, const char* report_directory, - const bool keep_clustering_data, - const bool data_flow_driven) { + const bool keep_clustering_data) { auto macro_placer = getMacroPlacer(); const int num_threads = ord::OpenRoad::openRoad()->getThreadCount(); @@ -84,8 +83,7 @@ bool rtl_macro_placer_cmd(const int max_num_macro, target_util, min_ar, report_directory, - keep_clustering_data, - data_flow_driven); + keep_clustering_data); } void set_debug_cmd(odb::dbBlock* block, diff --git a/src/mpl/src/mpl.tcl b/src/mpl/src/mpl.tcl index d552c846c8e..9f9dc3f8327 100644 --- a/src/mpl/src/mpl.tcl +++ b/src/mpl/src/mpl.tcl @@ -28,7 +28,6 @@ sta::define_cmd_args "rtl_macro_placer" { -max_num_macro max_num_macro \ -report_directory report_directory \ -write_macro_placement file_name \ -keep_clustering_data \ - -data_flow_driven \ } proc rtl_macro_placer { args } { sta::parse_key_args "rtl_macro_placer" args \ @@ -42,7 +41,7 @@ proc rtl_macro_placer { args } { -min_ar \ -report_directory \ -write_macro_placement } \ - flags {-keep_clustering_data -data_flow_driven} + flags {-keep_clustering_data} sta::check_argc_eq0 "rtl_macro_placer" $args @@ -189,8 +188,7 @@ proc rtl_macro_placer { args } { $target_util \ $min_ar \ $report_directory \ - [info exists flags(-keep_clustering_data)] \ - [info exists flags(-data_flow_driven)]] + [info exists flags(-keep_clustering_data)]] } { return false } diff --git a/src/mpl/src/rtl_mp.cpp b/src/mpl/src/rtl_mp.cpp index d6945d1a83f..274684c8173 100644 --- a/src/mpl/src/rtl_mp.cpp +++ b/src/mpl/src/rtl_mp.cpp @@ -56,8 +56,7 @@ bool MacroPlacer::place(const int num_threads, const float target_util, const float min_ar, const char* report_directory, - const bool keep_clustering_data, - const bool data_flow_driven) + const bool keep_clustering_data) { hier_rtlmp_->init(); hier_rtlmp_->setClusterSize( @@ -81,9 +80,6 @@ bool MacroPlacer::place(const int num_threads, hier_rtlmp_->setReportDirectory(report_directory); hier_rtlmp_->setNumThreads(num_threads); hier_rtlmp_->setKeepClusteringData(keep_clustering_data); - if (data_flow_driven) { - hier_rtlmp_->setDataFlowDriven(); - } hier_rtlmp_->setGuidanceRegions(guidance_regions_); hier_rtlmp_->run();