Skip to content

Commit

Permalink
mpl2: add cmd and function to set file name
Browse files Browse the repository at this point in the history
Signed-off-by: Arthur Koucher <arthurckoucher@gmail.com>
  • Loading branch information
AcKoucher committed Oct 10, 2023
1 parent 58fe420 commit 39d1a8e
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 18 deletions.
3 changes: 2 additions & 1 deletion src/mpl2/include/mpl2/rtl_mp.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace odb {
class dbDatabase;
class dbInst;
class dbOrientType;
}
} // namespace odb

namespace sta {
class dbNetwork;
Expand Down Expand Up @@ -107,6 +107,7 @@ class MacroPlacer2
const std::string& orientation_string);
odb::dbOrientType stringToOrientType(const std::string& orientation_string);

void setMacroPlacementFile(const char* file_name);
void writeMacroPlacement(const char* file_name);

void setDebug(std::unique_ptr<Mpl2Observer>& graphics);
Expand Down
32 changes: 32 additions & 0 deletions src/mpl2/src/hier_rtlmp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,8 @@ void HierRTLMP::hierRTLMacroPlacer()

correctAllMacrosOrientation();

writeMacroPlacement(macro_placement_file_.c_str());

// Clear the memory to avoid memory leakage
// release all the pointers
// metrics map
Expand Down Expand Up @@ -6064,6 +6066,36 @@ void HierRTLMP::correctAllMacrosOrientation()
}
}

void HierRTLMP::setMacroPlacementFile(const char* file_name)
{
macro_placement_file_ = file_name;
}

void HierRTLMP::writeMacroPlacement(const char* file_name)
{
std::string filename = file_name;

if (filename.empty()) {
return;
}

std::ofstream out(filename);

if (!out) {
logger_->error(MPL, 11, "Cannot open file {}.", filename);
}

// Use only insts that were placed by mpl2
for (auto& [inst, hard_macro] : hard_macro_map_) {
float x = dbuToMicron(inst->getLocation().x(), dbu_);
float y = dbuToMicron(inst->getLocation().y(), dbu_);

out << "place_macro -macro_name " << inst->getName() << " -location {" << x
<< " " << y << "} -orientation " << inst->getOrient().getString()
<< '\n';
}
}

void HierRTLMP::setDebug(std::unique_ptr<Mpl2Observer>& graphics)
{
graphics_ = std::move(graphics);
Expand Down
5 changes: 5 additions & 0 deletions src/mpl2/src/hier_rtlmp.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ class HierRTLMP
bus_planning_flag_ = bus_planning_flag;
}

void setMacroPlacementFile(const char* file_name);
void writeMacroPlacement(const char* file_name);

private:
void setDefaultThresholds();
void createDataFlow();
Expand Down Expand Up @@ -290,6 +293,8 @@ class HierRTLMP

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

// User can specify a global region for some designs
float global_fence_lx_ = std::numeric_limits<float>::max();
float global_fence_ly_ = std::numeric_limits<float>::max();
Expand Down
6 changes: 6 additions & 0 deletions src/mpl2/src/mpl.i
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@ place_macro(odb::dbInst* macro_name, float x_origin, float y_origin, const char*
getMacroPlacer2()->placeMacro(macro_name, x_origin, y_origin, orientation_string);
}

void
set_macro_placement_file(const char* file_name)
{
getMacroPlacer2()->setMacroPlacementFile(file_name);
}

void
write_macro_placement(const char* file_name)
{
Expand Down
8 changes: 7 additions & 1 deletion src/mpl2/src/mpl.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ sta::define_cmd_args "rtl_macro_placer" { -max_num_macro max_num_macro \
-snap_layer snap_layer \
-bus_planning_flag bus_planning_flag \
-report_directory report_directory \
-write_macro_placement file_name \
}
proc rtl_macro_placer { args } {
sta::parse_key_args "rtl_macro_placer" args keys {
Expand All @@ -75,6 +76,7 @@ proc rtl_macro_placer { args } {
-target_dead_space -min_ar -snap_layer \
-bus_planning_flag \
-report_directory \
-write_macro_placement \
} flag { }
#
# Check for valid design
Expand Down Expand Up @@ -216,11 +218,15 @@ proc rtl_macro_placer { args } {
set bus_planning_flag $keys(-bus_planning_flag)
}
if { [info exists keys(-report_directory)] } {
set report_directory $keys(-report_directory)
set report_directory $keys(-report_directory)
}

file mkdir $report_directory

if { [info exists keys(-write_macro_placement)] } {
mpl2::set_macro_placement_file $keys(-write_macro_placement)
}

if {![mpl2::rtl_macro_placer_cmd $max_num_macro \
$min_num_macro \
$max_num_inst \
Expand Down
30 changes: 14 additions & 16 deletions src/mpl2/src/rtl_mp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ void MacroPlacer2::placeMacro(odb::dbInst* inst,

odb::Rect macro_new_bbox(x1, y1, x2, y2);
odb::Rect core_area = inst->getBlock()->getCoreArea();

if (!core_area.contains(macro_new_bbox)) {
logger_->error(MPL,
34,
Expand All @@ -176,31 +176,29 @@ void MacroPlacer2::placeMacro(odb::dbInst* inst,

HardMacro macro(inst, dbu_per_micron, manufacturing_grid, 0, 0);

mpl2::Rect macro_new_bbox_micron(x_origin,
y_origin,
dbuToMicron(macro_new_bbox.xMax(), dbu_per_micron),
dbuToMicron(macro_new_bbox.yMax(), dbu_per_micron));
mpl2::Rect macro_new_bbox_micron(
x_origin,
y_origin,
dbuToMicron(macro_new_bbox.xMax(), dbu_per_micron),
dbuToMicron(macro_new_bbox.yMax(), dbu_per_micron));

float pitch_x = 0.0;
float pitch_y = 0.0;

macro.alignOriginWithGrids(macro_new_bbox_micron, orientation, pitch_x, pitch_y, inst->getBlock());
macro.alignOriginWithGrids(
macro_new_bbox_micron, orientation, pitch_x, pitch_y, inst->getBlock());

inst->setPlacementStatus(odb::dbPlacementStatus::LOCKED);
}

void MacroPlacer2::writeMacroPlacement(const char* file_name)
void MacroPlacer2::setMacroPlacementFile(const char* file_name)
{
std::string filename = file_name;
if (filename.empty()) {
return;
}

std::ofstream out(filename);
hier_rtlmp_->setMacroPlacementFile(file_name);
}

if (!out) {
logger_->error(MPL, 11, "Cannot open file {}.", filename);
}
void MacroPlacer2::writeMacroPlacement(const char* file_name)
{
hier_rtlmp_->writeMacroPlacement(file_name);
}

void MacroPlacer2::setDebug(std::unique_ptr<Mpl2Observer>& graphics)
Expand Down

0 comments on commit 39d1a8e

Please sign in to comment.