Skip to content

Commit

Permalink
refactor the code for creating dreamplace.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 660069219
Change-Id: I366c32a4bd5ba3d0e518e166253f4e34ba242a3d
  • Loading branch information
esonghori authored and copybara-github committed Aug 6, 2024
1 parent 8a01606 commit 6c96bb9
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions circuit_training/environment/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,20 +245,7 @@ def __init__(
self._saved_cost = np.inf

if self._std_cell_placer_mode == 'dreamplace':
canvas_width, canvas_height = self._plc.get_canvas_width_height()
dreamplace_params = dreamplace_util.get_dreamplace_params(
canvas_width=canvas_width,
canvas_height=canvas_height,
)
# Dreamplace requires that movable nodes appear first
# and then fixed nodes.
# Since the first node to be placed (becoming fixed) is the first node in
# _sorted_node_indices, we reverse the order and send it to dreamplace.
hard_macro_order = self._sorted_node_indices[: self._num_hard_macros]
hard_macro_order = hard_macro_order[::-1]
self._dreamplace = dreamplace_core.SoftMacroPlacer(
self._plc, dreamplace_params, hard_macro_order
)
self._dreamplace = self.create_dreamplace()

# Call dreamplace mixed-size before making ObservationExtractor, so we
# use its placement as the initial location in the features.
Expand All @@ -273,7 +260,8 @@ def __init__(
logging.warning("Initial DREAMPlace mixed-size didn't converge.")

self._dp_mixed_macro_locations = {
m: self._plc.get_node_location(m) for m in hard_macro_order
m: self._plc.get_node_location(m)
for m in self._sorted_node_indices[: self._num_hard_macros]
}
else: # fd
# Call fd mixed-size before making ObservationExtractor, so we
Expand Down Expand Up @@ -329,6 +317,23 @@ def macro_names(self) -> list[str]:
macro_ids = self._sorted_node_indices[: self._num_hard_macros]
return [self._plc.get_node_name(m) for m in macro_ids]

def create_dreamplace(self) -> dreamplace_core.SoftMacroPlacer:
"""Creates the SoftMacroPlacer."""
canvas_width, canvas_height = self._plc.get_canvas_width_height()
dreamplace_params = dreamplace_util.get_dreamplace_params(
canvas_width=canvas_width,
canvas_height=canvas_height,
)
# Dreamplace requires that movable nodes appear first
# and then fixed nodes.
# Since the first node to be placed (becoming fixed) is the first node in
# _sorted_node_indices, we reverse the order and send it to dreamplace.
hard_macro_order = self._sorted_node_indices[: self._num_hard_macros]
hard_macro_order = hard_macro_order[::-1]
return dreamplace_core.SoftMacroPlacer(
self._plc, dreamplace_params, hard_macro_order
)

def get_static_obs(self):
"""Get the static observation for the environment.
Expand Down

0 comments on commit 6c96bb9

Please sign in to comment.