@@ -138,8 +138,9 @@ float SACoreSoftMacro::getNormNotchPenalty() const
138138float 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
344385void 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
610669void SACoreSoftMacro::resize ()
@@ -693,24 +752,59 @@ void SACoreSoftMacro::shrink()
693752
694753void 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
710803void 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