Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hier-RTLMP Fix #6371

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 66 additions & 11 deletions src/mpl2/src/clusterEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1367,20 +1367,32 @@ void ClusteringEngine::breakLargeFlatCluster(Cluster* parent)
cluster_vertex_id_map[cluster_id] = vertex_id++;
vertex_weight.push_back(0.0f);
}
const int num_other_cluster_vertices = vertex_id;

std::vector<odb::dbInst*> insts;
std::map<odb::dbInst*, int> inst_vertex_id_map;
for (auto& macro : parent->getLeafMacros()) {
inst_vertex_id_map[macro] = vertex_id++;
vertex_weight.push_back(computeMicronArea(macro));
insts.push_back(macro);
}

float std_cell_area = 0.0f;
int num_std_cells = 0;
int std_cell_start_index = vertex_id;
for (auto& std_cell : parent->getLeafStdCells()) {
inst_vertex_id_map[std_cell] = vertex_id++;
vertex_weight.push_back(computeMicronArea(std_cell));
std_cell_area += vertex_weight.back();
num_std_cells++;
insts.push_back(std_cell);
}
int std_cell_index_end = insts.size();

float avg_std_cell_area = std_cell_area / num_std_cells;
logger_->report(
"During partitioning, modeling each macro as a vertex with an area of "
"%.2f",
avg_std_cell_area);
for (auto& macro : parent->getLeafMacros()) {
inst_vertex_id_map[macro] = vertex_id++;
vertex_weight.push_back(avg_std_cell_area);
insts.push_back(macro);
}

std::vector<std::vector<int>> hyperedges;
for (odb::dbNet* net : block_->getNets()) {
Expand Down Expand Up @@ -1432,8 +1444,8 @@ void ClusteringEngine::breakLargeFlatCluster(Cluster* parent)
}

const int seed = 0;
const float balance_constraint = 1.0;
const int num_parts = 2; // We use two-way partitioning here
float balance_constraint = 5.0; // relax the balance constraint to 5%
const int num_parts = 2; // We use two-way partitioning here
const int num_vertices = static_cast<int>(vertex_weight.size());
std::vector<float> hyperedge_weights(hyperedges.size(), 1.0f);

Expand All @@ -1452,16 +1464,59 @@ void ClusteringEngine::breakLargeFlatCluster(Cluster* parent)
vertex_weight,
hyperedge_weights);

// Check if the partitioning was successful
auto checkBalance = [&]() -> bool {
float balance_part_0 = 0.0;
float balance_part_1 = 0.0;
for (int i = 0; i < num_vertices; i++) {
if (part[i] == 0) {
balance_part_0 += vertex_weight[i];
} else {
balance_part_1 += vertex_weight[i];
}
}

float balance_ratio
= std::abs(balance_part_0 / (balance_part_0 + balance_part_1) - 0.5);
if (balance_ratio < balance_constraint) {
logger_->report("Partitioning successful with balance ratio of %.2f%%",
balance_ratio * 100);
return true;
}

logger_->report("Partitioning failed with balance ratio of %.2f%%",
balance_ratio * 100);
return false;
};

if (checkBalance() == false) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This appears to just be a workaround to the underlying TP bug. I think @AcKoucher has identified the root cause as being bad initial partitioning.

logger_->report("Relaxing balance constraint to 10%");
balance_constraint = 10.0;
part.clear();
part = triton_part_->PartitionKWaySimpleMode(num_parts,
balance_constraint,
seed,
hyperedges,
vertex_weight,
hyperedge_weights);
if (checkBalance() == false) {
logger_->error(
MPL,
206,
"Partitioning failed with balance constriant of {}. Exiting...",
balance_constraint);
}
}

parent->clearLeafStdCells();
parent->clearLeafMacros();

const std::string cluster_name = parent->getName();
parent->setName(cluster_name + std::string("_0"));
auto cluster_part_1 = std::make_unique<Cluster>(
id_, cluster_name + std::string("_1"), logger_);

for (int i = num_other_cluster_vertices; i < num_vertices; i++) {
odb::dbInst* inst = insts[i - num_other_cluster_vertices];
for (int i = std_cell_start_index; i < std_cell_index_end; i++) {
odb::dbInst* inst = insts[i - std_cell_start_index];
if (part[i] == 0) {
parent->addLeafInst(inst);
} else {
Expand Down
69 changes: 63 additions & 6 deletions src/mpl2/src/hier_rtlmp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -952,7 +952,17 @@ void HierRTLMP::setIOClustersBlockages()
io_spans[L].second);

boundary_to_io_blockage_[L] = left_io_blockage;
macro_blockages_.push_back(left_io_blockage);
if (real_blockage_flag_ == true) {
placement_blockages_.push_back(left_io_blockage);
logger_->report(
"Add left IO blockage : lx = {}, ly = {}, ux = {}, uy = {}",
left_io_blockage.xMin(),
left_io_blockage.yMin(),
left_io_blockage.xMax(),
left_io_blockage.yMax());
} else {
macro_blockages_.push_back(left_io_blockage);
}
}

if (io_spans[T].second > io_spans[T].first) {
Expand All @@ -962,17 +972,36 @@ void HierRTLMP::setIOClustersBlockages()
root.yMax());

boundary_to_io_blockage_[T] = top_io_blockage;
macro_blockages_.push_back(top_io_blockage);
if (real_blockage_flag_ == true) {
placement_blockages_.push_back(top_io_blockage);
logger_->report(
"Add top IO blockage : lx = {}, ly = {}, ux = {}, uy = {}",
top_io_blockage.xMin(),
top_io_blockage.yMin(),
top_io_blockage.xMax(),
top_io_blockage.yMax());
} else {
macro_blockages_.push_back(top_io_blockage);
}
}

if (io_spans[R].second > io_spans[R].first) {
const Rect right_io_blockage(root.xMax() - depth,
io_spans[R].first,
root.xMax(),
io_spans[R].second);

boundary_to_io_blockage_[R] = right_io_blockage;
macro_blockages_.push_back(right_io_blockage);
if (real_blockage_flag_ == true) {
placement_blockages_.push_back(right_io_blockage);
logger_->report(
"Add right IO blockage : lx = {}, ly = {}, ux = {}, uy = {}",
right_io_blockage.xMin(),
right_io_blockage.yMin(),
right_io_blockage.xMax(),
right_io_blockage.yMax());
} else {
macro_blockages_.push_back(right_io_blockage);
}
}

if (io_spans[B].second > io_spans[B].first) {
Expand All @@ -982,7 +1011,17 @@ void HierRTLMP::setIOClustersBlockages()
root.yMin() + depth);

boundary_to_io_blockage_[B] = bottom_io_blockage;
macro_blockages_.push_back(bottom_io_blockage);
if (real_blockage_flag_ == true) {
placement_blockages_.push_back(bottom_io_blockage);
logger_->report(
"Add bottom IO blockage : lx = {}, ly = {}, ux = {}, uy = {}",
bottom_io_blockage.xMin(),
bottom_io_blockage.yMin(),
bottom_io_blockage.xMax(),
bottom_io_blockage.yMax());
} else {
macro_blockages_.push_back(bottom_io_blockage);
}
}
}

Expand Down Expand Up @@ -2810,6 +2849,22 @@ void HierRTLMP::runEnhancedHierarchicalMacroPlacement(Cluster* parent)
}
}

// Model each placement blockage as macros with fence constraints
if (real_blockage_flag_ == true) {
for (auto& rect : placement_blockages) {
soft_macro_id_map["blockage" + std::to_string(macros.size())]
= macros.size();
macros.emplace_back(std::pair<float, float>(rect.xMin() - outline.xMin(),
rect.yMin() - outline.yMin()),
"blockage" + std::to_string(macros.size()),
rect.getWidth(),
rect.getHeight(),
nullptr);
Rect fence(rect.xMin(), rect.yMin(), rect.xMax(), rect.yMax());
fences[macros.size() - 1] = fence;
}
}

// update the connnection
clustering_engine_->updateConnections();
debugPrint(logger_,
Expand Down Expand Up @@ -3004,7 +3059,9 @@ void HierRTLMP::runEnhancedHierarchicalMacroPlacement(Cluster* parent)
sa->setFences(fences);
sa->setGuides(guides);
sa->setNets(nets);
sa->addBlockages(placement_blockages);
if (real_blockage_flag_ == false) {
sa->addBlockages(placement_blockages);
}
sa->addBlockages(macro_blockages);
sa_batch.push_back(std::move(sa));
}
Expand Down
3 changes: 3 additions & 0 deletions src/mpl2/src/hier_rtlmp.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,9 @@ class HierRTLMP
// ASASP7, you should turn off this option.
bool bus_planning_on_ = false;

// For testing
bool real_blockage_flag_ = true;

// Parameters related to macro placement
std::string report_directory_;
std::string macro_placement_file_;
Expand Down
Loading
Loading