Skip to content

Commit 4ae62e4

Browse files
committed
mpl: create and use method for connecting clusters
Signed-off-by: Arthur Koucher <[email protected]>
1 parent 8daed51 commit 4ae62e4

File tree

4 files changed

+26
-19
lines changed

4 files changed

+26
-19
lines changed

src/mpl/src/clusterEngine.cpp

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,46 +1027,57 @@ void ClusteringEngine::buildDataFlowConnections()
10271027
}
10281028

10291029
const int driver_id = itr->second;
1030+
Cluster* driver_cluster = tree_->maps.id_to_cluster.at(driver_id);
10301031

10311032
for (int hops = 0; hops < max_num_of_hops_; hops++) {
10321033
std::set<int> sink_clusters = computeSinks(insts[hops]);
10331034
const float conn_weight = computeConnWeight(hops);
10341035
for (auto& sink : sink_clusters) {
1035-
tree_->maps.id_to_cluster[driver_id]->addConnection(sink, conn_weight);
1036-
tree_->maps.id_to_cluster[sink]->addConnection(driver_id, conn_weight);
1036+
Cluster* sink_cluster = tree_->maps.id_to_cluster.at(sink);
1037+
connect(driver_cluster, sink_cluster, conn_weight);
10371038
}
10381039
}
10391040
}
10401041

10411042
// macros to ffs
10421043
for (const auto& [iterm, insts] : data_connections_.macro_pins_and_regs) {
10431044
const int driver_id = tree_->maps.inst_to_cluster_id.at(iterm->getInst());
1045+
Cluster* driver_cluster = tree_->maps.id_to_cluster.at(driver_id);
10441046

10451047
for (int hops = 0; hops < max_num_of_hops_; hops++) {
10461048
std::set<int> sink_clusters = computeSinks(insts[hops]);
10471049
const float conn_weight = computeConnWeight(hops);
10481050
for (auto& sink : sink_clusters) {
1049-
tree_->maps.id_to_cluster[driver_id]->addConnection(sink, conn_weight);
1050-
tree_->maps.id_to_cluster[sink]->addConnection(driver_id, conn_weight);
1051+
Cluster* sink_cluster = tree_->maps.id_to_cluster.at(sink);
1052+
connect(driver_cluster, sink_cluster, conn_weight);
10511053
}
10521054
}
10531055
}
10541056

10551057
// macros to macros
10561058
for (const auto& [iterm, insts] : data_connections_.macro_pins_and_macros) {
10571059
const int driver_id = tree_->maps.inst_to_cluster_id.at(iterm->getInst());
1060+
Cluster* driver_cluster = tree_->maps.id_to_cluster.at(driver_id);
10581061

10591062
for (int hops = 0; hops < max_num_of_hops_; hops++) {
10601063
std::set<int> sink_clusters = computeSinks(insts[hops]);
10611064
const float conn_weight = computeConnWeight(hops);
10621065
for (auto& sink : sink_clusters) {
1063-
tree_->maps.id_to_cluster[driver_id]->addConnection(sink, conn_weight);
1064-
tree_->maps.id_to_cluster[sink]->addConnection(driver_id, conn_weight);
1066+
Cluster* sink_cluster = tree_->maps.id_to_cluster.at(sink);
1067+
connect(driver_cluster, sink_cluster, conn_weight);
10651068
}
10661069
}
10671070
}
10681071
}
10691072

1073+
void ClusteringEngine::connect(Cluster* a,
1074+
Cluster* b,
1075+
const float connection_weight) const
1076+
{
1077+
a->addConnection(b, connection_weight);
1078+
b->addConnection(a, connection_weight);
1079+
}
1080+
10701081
float ClusteringEngine::computeConnWeight(const int hops)
10711082
{
10721083
const float base_remoteness_factor = 2.0;
@@ -1863,7 +1874,7 @@ bool ClusteringEngine::attemptMerge(Cluster* receiver, Cluster* incomer)
18631874
for (const auto& [cluster_id, connection_weight] : incomer_connections) {
18641875
Cluster* cluster = tree_->maps.id_to_cluster.at(cluster_id);
18651876
cluster->removeConnection(incomer_id);
1866-
cluster->addConnection(receiver->getId(), connection_weight);
1877+
cluster->addConnection(receiver, connection_weight);
18671878
}
18681879
}
18691880

@@ -1928,13 +1939,12 @@ void ClusteringEngine::buildNetListConnections()
19281939
if (driver_cluster_id != -1 && !load_clusters_ids.empty()
19291940
&& load_clusters_ids.size() < tree_->large_net_threshold) {
19301941
const float weight = net_has_io_pin ? tree_->virtual_weight : 1.0;
1942+
Cluster* driver_cluster = tree_->maps.id_to_cluster.at(driver_cluster_id);
19311943

19321944
for (const int load_cluster_id : load_clusters_ids) {
1933-
if (load_cluster_id != driver_cluster_id) { /* undirected connection */
1934-
tree_->maps.id_to_cluster[driver_cluster_id]->addConnection(
1935-
load_cluster_id, weight);
1936-
tree_->maps.id_to_cluster[load_cluster_id]->addConnection(
1937-
driver_cluster_id, weight);
1945+
if (load_cluster_id != driver_cluster_id) {
1946+
Cluster* load_cluster = tree_->maps.id_to_cluster.at(load_cluster_id);
1947+
connect(driver_cluster, load_cluster, weight);
19381948
}
19391949
}
19401950
}

src/mpl/src/clusterEngine.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ class ClusteringEngine
241241
void clearConnections();
242242
void buildNetListConnections();
243243
void buildDataFlowConnections();
244+
void connect(Cluster* a, Cluster* b, float connection_weight) const;
244245

245246
// Methods for data flow
246247
void createDataFlow();

src/mpl/src/object.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -568,13 +568,9 @@ void Cluster::initConnection()
568568
connections_map_.clear();
569569
}
570570

571-
void Cluster::addConnection(int cluster_id, float weight)
571+
void Cluster::addConnection(Cluster* cluster, const float connection_weight)
572572
{
573-
if (connections_map_.find(cluster_id) == connections_map_.end()) {
574-
connections_map_[cluster_id] = weight;
575-
} else {
576-
connections_map_[cluster_id] += weight;
577-
}
573+
connections_map_[cluster->getId()] += connection_weight;
578574
}
579575

580576
void Cluster::removeConnection(int cluster_id)

src/mpl/src/object.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ class Cluster
209209

210210
// Connection signature support
211211
void initConnection();
212-
void addConnection(int cluster_id, float weight);
212+
void addConnection(Cluster* cluster, float connection_weight);
213213
void removeConnection(int cluster_id);
214214
const ConnectionsMap& getConnectionsMap() const;
215215
bool isSameConnSignature(const Cluster& cluster, float net_threshold);

0 commit comments

Comments
 (0)