Skip to content

Commit 9f024da

Browse files
Tune mpl2 based on multiple expamples
Signed-off-by: Ravi Varadarajan <[email protected]>
1 parent 5247317 commit 9f024da

File tree

5 files changed

+283
-95
lines changed

5 files changed

+283
-95
lines changed

src/mpl2/src/SACoreHardMacro.cpp

Lines changed: 47 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,9 @@ SACoreHardMacro::SACoreHardMacro(
9292
float SACoreHardMacro::calNormCost() const
9393
{
9494
float cost = 0.0; // Initialize cost
95+
const float outline_area = outline_width_ * outline_height_;
9596
if (norm_area_penalty_ > 0.0) {
96-
cost += area_weight_ * (width_ * height_) / norm_area_penalty_;
97+
cost += area_weight_ * (width_ * height_) / outline_area;
9798
}
9899
if (norm_outline_penalty_ > 0.0) {
99100
cost += outline_weight_ * outline_penalty_ / norm_outline_penalty_;
@@ -234,6 +235,22 @@ void SACoreHardMacro::initialize()
234235
norm_wirelength_ = calAverage(wirelength_list);
235236
norm_guidance_penalty_ = calAverage(guidance_penalty_list);
236237
norm_fence_penalty_ = calAverage(fence_penalty_list);
238+
239+
if (norm_area_penalty_ <= 1e-4)
240+
norm_area_penalty_ = 1.0;
241+
242+
if (norm_outline_penalty_ <= 1e-4)
243+
norm_outline_penalty_ = 1.0;
244+
245+
if (norm_wirelength_ <= 1e-4)
246+
norm_wirelength_ = 1.0;
247+
248+
if (norm_guidance_penalty_ <= 1e-4)
249+
norm_guidance_penalty_ = 1.0;
250+
251+
if (norm_fence_penalty_ <= 1e-4)
252+
norm_fence_penalty_ = 1.0;
253+
237254
// Calculate initial temperature
238255
std::vector<float> cost_list;
239256
for (int i = 0; i < outline_penalty_list.size(); i++) {
@@ -249,48 +266,41 @@ void SACoreHardMacro::initialize()
249266
for (int i = 1; i < cost_list.size(); i++) {
250267
delta_cost += std::abs(cost_list[i] - cost_list[i - 1]);
251268
}
252-
init_temperature_
253-
= (-1.0) * (delta_cost / (cost_list.size() - 1)) / log(init_prob_);
269+
if (cost_list.size() > 1 && delta_cost > 0.0) {
270+
init_temperature_
271+
= (-1.0) * (delta_cost / (cost_list.size() - 1)) / log(init_prob_);
272+
} else {
273+
init_temperature_ = 1.0;
274+
}
254275
}
255276

256277
void SACoreHardMacro::printResults()
257278
{
279+
logger_->report(std::string(80, '*'));
258280
logger_->report("SACoreHardMacro");
259-
logger_->report("outline_penalty_ = {}", outline_penalty_);
260-
logger_->report("wirelength_ = {}", wirelength_);
261-
for (auto& net : nets_) {
262-
logger_->report("net src = {} target = {} weight = {}",
263-
net.terminals.first,
264-
net.terminals.second,
265-
net.weight);
281+
logger_->report("number of macros : {}", macros_.size());
282+
for (auto macro : macros_) {
283+
logger_->report("Debug");
284+
logger_->report("lx = {}, ly = {}, width = {}, height = {}",
285+
macro.getX(),
286+
macro.getY(),
287+
macro.getWidth(),
288+
macro.getHeight());
266289
}
267-
268-
for (auto& macro : macros_) {
269-
logger_->report(
270-
"name : {} lx = {} ly = {} pin_x = {} pin_y = {} orientation = {}",
271-
macro.getName(),
272-
macro.getX(),
273-
macro.getY(),
274-
macro.getPinX(),
275-
macro.getPinY(),
276-
macro.getOrientation());
277-
}
278-
// FlipMacro();
279-
calPenalty();
280-
logger_->report("wirelength_ = {}", wirelength_);
281-
for (auto& macro : macros_) {
282-
logger_->report(
283-
"name : {} lx = {} ly = {} pin_x = {} pin_y = {} orientation = {}",
284-
macro.getName(),
285-
macro.getX(),
286-
macro.getY(),
287-
macro.getPinX(),
288-
macro.getPinY(),
289-
macro.getOrientation());
290-
}
291-
292-
logger_->report("guidance_penalty_ = {}", guidance_penalty_);
293-
logger_->report("fence_penalty_ = {}", fence_penalty_);
290+
logger_->report("width = {}, outline_width = {}", width_, outline_width_);
291+
logger_->report("height = {}, outline_height = {}", height_, outline_height_);
292+
logger_->report("outline_penalty = {}, norm_outline_penalty = {}",
293+
outline_penalty_,
294+
norm_outline_penalty_);
295+
logger_->report(
296+
"wirelength = {}, norm_wirelength = {}", wirelength_, norm_wirelength_);
297+
logger_->report("guidance_penalty = {}, norm_guidance_penalty = {}",
298+
guidance_penalty_,
299+
norm_guidance_penalty_);
300+
logger_->report("fence_penalty = {}, norm_fence_penalty = {}",
301+
fence_penalty_,
302+
norm_fence_penalty_);
303+
logger_->report("final cost = {}", getNormCost());
294304
}
295305

296306
} // namespace mpl2

src/mpl2/src/SACoreSoftMacro.cpp

Lines changed: 126 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,9 @@ float SACoreSoftMacro::getNormNotchPenalty() const
138138
float SACoreSoftMacro::calNormCost() const
139139
{
140140
float cost = 0.0; // Initialize cost
141+
const float outline_area = outline_height_ * outline_width_;
141142
if (norm_area_penalty_ > 0.0) {
142-
cost += area_weight_ * (width_ * height_) / norm_area_penalty_;
143+
cost += area_weight_ * (width_ * height_) / outline_area;
143144
}
144145
if (norm_outline_penalty_ > 0.0) {
145146
cost += outline_weight_ * outline_penalty_ / norm_outline_penalty_;
@@ -275,7 +276,8 @@ void SACoreSoftMacro::initialize()
275276
// store current penalties
276277
width_list.push_back(width_);
277278
height_list.push_back(height_);
278-
area_penalty_list.push_back(width_ * height_);
279+
area_penalty_list.push_back(width_ * height_ / outline_width_
280+
/ outline_height_);
279281
outline_penalty_list.push_back(outline_penalty_);
280282
wirelength_list.push_back(wirelength_);
281283
guidance_penalty_list.push_back(guidance_penalty_);
@@ -292,8 +294,33 @@ void SACoreSoftMacro::initialize()
292294
norm_fence_penalty_ = calAverage(fence_penalty_list);
293295
norm_boundary_penalty_ = calAverage(boundary_penalty_list);
294296
norm_macro_blockage_penalty_ = calAverage(macro_blockage_penalty_list);
295-
// norm_notch_penalty_ = calAverage(notch_penalty_list);
296-
norm_notch_penalty_ = outline_width_ * outline_height_;
297+
norm_notch_penalty_ = calAverage(notch_penalty_list);
298+
299+
// Reset penalites if lower than threshold
300+
301+
if (norm_area_penalty_ <= 1e-4)
302+
norm_area_penalty_ = 1.0;
303+
304+
if (norm_outline_penalty_ <= 1e-4)
305+
norm_outline_penalty_ = 1.0;
306+
307+
if (norm_wirelength_ <= 1e-4)
308+
norm_wirelength_ = 1.0;
309+
310+
if (norm_guidance_penalty_ <= 1e-4)
311+
norm_guidance_penalty_ = 1.0;
312+
313+
if (norm_fence_penalty_ <= 1e-4)
314+
norm_fence_penalty_ = 1.0;
315+
316+
if (norm_macro_blockage_penalty_ <= 1e-4)
317+
norm_macro_blockage_penalty_ = 1.0;
318+
319+
if (norm_boundary_penalty_ <= 1e-4)
320+
norm_boundary_penalty_ = 1.0;
321+
322+
if (norm_notch_penalty_ <= 1e-4)
323+
norm_notch_penalty_ = 1.0;
297324

298325
// Calculate initial temperature
299326
std::vector<float> cost_list;
@@ -313,8 +340,13 @@ void SACoreSoftMacro::initialize()
313340
for (int i = 1; i < cost_list.size(); i++) {
314341
delta_cost += std::abs(cost_list[i] - cost_list[i - 1]);
315342
}
316-
init_temperature_
317-
= (-1.0) * (delta_cost / (cost_list.size() - 1)) / log(init_prob_);
343+
344+
if (cost_list.size() > 1 && delta_cost > 0.0) {
345+
init_temperature_
346+
= (-1.0) * (delta_cost / (cost_list.size() - 1)) / log(init_prob_);
347+
} else {
348+
init_temperature_ = 1.0;
349+
}
318350
}
319351

320352
// We only push hard macro clusters to boundaries
@@ -327,6 +359,14 @@ void SACoreSoftMacro::calBoundaryPenalty()
327359
return;
328360
}
329361

362+
int tot_num_macros = 0;
363+
for (const auto& macro : macros_) {
364+
tot_num_macros += macro.getNumMacro();
365+
}
366+
if (tot_num_macros <= 0) {
367+
return;
368+
}
369+
330370
for (const auto& macro : macros_) {
331371
if (macro.getNumMacro() > 0) {
332372
const float lx = macro.getX();
@@ -335,16 +375,25 @@ void SACoreSoftMacro::calBoundaryPenalty()
335375
const float uy = ly + macro.getHeight();
336376
const float x_dist = std::min(lx, std::abs(outline_width_ - ux));
337377
const float y_dist = std::min(ly, std::abs(outline_height_ - uy));
338-
boundary_penalty_
339-
+= std::pow(std::min(x_dist, y_dist) * macro.getNumMacro(), 2);
378+
boundary_penalty_ += std::min(x_dist, y_dist) * macro.getNumMacro();
340379
}
341380
}
381+
// normalization
382+
boundary_penalty_ = boundary_penalty_ / tot_num_macros;
342383
}
343384

344385
void SACoreSoftMacro::calMacroBlockagePenalty()
345386
{
346387
macro_blockage_penalty_ = 0.0;
347-
if (blockages_.size() == 0) {
388+
if (blockages_.size() == 0 || macro_blockage_weight_ <= 0.0) {
389+
return;
390+
}
391+
392+
int tot_num_macros = 0;
393+
for (const auto& macro : macros_) {
394+
tot_num_macros += macro.getNumMacro();
395+
}
396+
if (tot_num_macros <= 0) {
348397
return;
349398
}
350399

@@ -359,16 +408,23 @@ void SACoreSoftMacro::calMacroBlockagePenalty()
359408
const float region_ly = bbox.yMin();
360409
const float region_ux = bbox.xMax();
361410
const float region_uy = bbox.yMax();
362-
if (ux > region_lx && lx < region_ux && uy > region_ly
363-
&& ly < region_uy) {
364-
const float width = std::min(ux, region_ux) - std::max(lx, region_lx);
365-
const float height
366-
= std::min(uy, region_uy) - std::max(ly, region_ly);
367-
macro_blockage_penalty_ += width * height;
368-
}
411+
// check each dimension seperately
412+
// center to center distance
413+
const float width = ((ux - lx) + (region_ux - region_lx)) / 2.0;
414+
const float height = ((uy - ly) + (region_uy - region_ly)) / 2.0;
415+
float x_dist
416+
= std::abs((region_ux + region_lx) / 2.0 - (ux + lx) / 2.0);
417+
float y_dist
418+
= std::abs((region_uy + region_ly) / 2.0 - (uy + ly) / 2.0);
419+
x_dist = std::max(width - x_dist, 0.0f) / width;
420+
y_dist = std::max(height - y_dist, 0.0f) / height;
421+
macro_blockage_penalty_
422+
+= (x_dist * x_dist + y_dist * y_dist) * macro.getNumMacro();
369423
}
370424
}
371425
}
426+
// normalization
427+
macro_blockage_penalty_ = macro_blockage_penalty_ / tot_num_macros;
372428
}
373429

374430
// Align macro clusters to reduce notch
@@ -425,16 +481,17 @@ void SACoreSoftMacro::calNotchPenalty()
425481
}
426482
// If the floorplan cannot fit into the outline
427483
// We think the entire floorplan is a "huge" notch
428-
if (width_ > outline_width_ || height_ > outline_height_) {
429-
notch_penalty_ += outline_width_ * outline_height_;
484+
if (width_ > outline_width_ * 1.001 || height_ > outline_height_ * 1.001) {
485+
notch_penalty_ += outline_width_ * outline_height_
486+
/ (outline_width_ * outline_height_);
430487
return;
431488
}
432489

433490
pre_macros_ = macros_;
434-
// Fill dead space
435-
fillDeadSpace();
436491
// align macro clusters to reduce notches
437492
alignMacroClusters();
493+
// Fill dead space
494+
fillDeadSpace();
438495
// Create grids based on location of MixedCluster and HardMacroCluster
439496
std::set<float> x_point;
440497
std::set<float> y_point;
@@ -605,6 +662,8 @@ void SACoreSoftMacro::calNotchPenalty()
605662
}
606663
}
607664
macros_ = pre_macros_;
665+
// normalization
666+
notch_penalty_ = notch_penalty_ / (outline_width_ * outline_height_);
608667
}
609668

610669
void SACoreSoftMacro::resize()
@@ -693,24 +752,59 @@ void SACoreSoftMacro::shrink()
693752

694753
void SACoreSoftMacro::printResults() const
695754
{
696-
logger_->report("outline_penalty : {}",
697-
outline_penalty_ / norm_outline_penalty_);
698-
logger_->report("wirelength : {}", wirelength_ / norm_wirelength_);
699-
logger_->report("guidance_penalty : {}",
700-
guidance_penalty_ / norm_guidance_penalty_);
701-
logger_->report("fence_penalty : {}", fence_penalty_ / norm_fence_penalty_);
702-
logger_->report("boundary_penalty : {}",
703-
boundary_penalty_ / norm_boundary_penalty_);
704-
logger_->report("macro_blockage_penalty : {}",
705-
macro_blockage_penalty_ / norm_macro_blockage_penalty_);
706-
logger_->report("notch_penalty : {}", notch_penalty_ / norm_notch_penalty_);
755+
logger_->report(std::string(80, '*'));
756+
logger_->report("SACoreSoftMacro");
757+
logger_->report("number of macros : {}", macros_.size());
758+
for (auto macro : macros_)
759+
logger_->report("lx = {}, ly = {}, width = {}, height = {}, name = {}",
760+
macro.getX(),
761+
macro.getY(),
762+
macro.getWidth(),
763+
macro.getHeight(),
764+
macro.getName());
765+
logger_->report("width = {}, outline_width = {}", width_, outline_width_);
766+
logger_->report("height = {}, outline_height = {}", height_, outline_height_);
767+
logger_->report(
768+
"outline_weight = {}, outline_penalty = {}, norm_outline_penalty = {}",
769+
outline_weight_,
770+
outline_penalty_,
771+
norm_outline_penalty_);
772+
logger_->report(
773+
"wirelength_weight = {}, wirelength = {}, norm_wirelength = {}",
774+
wirelength_weight_,
775+
wirelength_,
776+
norm_wirelength_);
777+
logger_->report(
778+
"guidance_weight = {}, guidance_penalty = {}, norm_guidance_penalty = "
779+
"{}",
780+
guidance_weight_,
781+
guidance_penalty_,
782+
norm_guidance_penalty_);
783+
logger_->report(
784+
"fence_weight = {}, fence_penalty = {}, norm_fence_penalty = {}",
785+
fence_weight_,
786+
fence_penalty_,
787+
norm_fence_penalty_);
788+
logger_->report(
789+
"macro_blockage_weight = {}, macro_blockage_penalty = {}, "
790+
"norm_macro_blockage_penalty = {}",
791+
macro_blockage_weight_,
792+
macro_blockage_penalty_,
793+
norm_macro_blockage_penalty_);
794+
logger_->report(
795+
"notch_weight = {}, notch_penalty = {}, norm_notch_penalty = {}",
796+
notch_weight_,
797+
notch_penalty_,
798+
norm_notch_penalty_);
799+
logger_->report("final cost = {}", getNormCost());
707800
}
708801

709802
// fill the dead space by adjust the size of MixedCluster
710803
void SACoreSoftMacro::fillDeadSpace()
711804
{
712805
// if the floorplan is invalid, do nothing
713-
if (width_ > outline_width_ || height_ > outline_height_) {
806+
if (width_ > outline_width_ * (1.0 + 0.001)
807+
|| height_ > outline_height_ * (1.0 + 0.001)) {
714808
return;
715809
}
716810

0 commit comments

Comments
 (0)