gfn.gym.helpers.chip_design.utils

A collection of non-prod utility functions for placement.

All the dependencies in this files should be non-prod.

Attributes

COST_COMPONENTS

ORIENTATIONS

Functions

_proxy_cost(plc, wirelength_weight, density_weight, ...)

cost_info_function(plc, done[, infeasible_state, ...])

Returns the RL cost and info.

create_blockages_by_spacing_constraints(canvas_width, ...)

Create blockages using macro-to-boundary spacing constraints.

create_placement_cost(netlist_file, init_placement[, ...])

Creates a placement_cost object.

disconnect_high_fanout_nets(plc[, max_allowed_fanouts])

extract_attribute_from_comments(attribute, filenames)

Parses the files' comments section, tries to extract the attribute.

extract_blockages_from_file(filename, canvas_width, ...)

Reads blockage information from a given file.

extract_sizes_from_comments(filenames)

Parses the file's comments section, tries to extract canvas/grid sizes.

fd_placement_schedule(plc[, num_steps, io_factor, ...])

A placement schedule that uses force directed method.

fix_macros_by_regex(plc, macro_regex_str_list)

Fix macro locations given a list of macro name regex strings.

fix_port_coordinates(plc)

Find all ports and fix their coordinates.

get_blockages_from_comments(filenames)

Returns list of blockages if they exist in the file's comments section.

get_macro_orientations(plc)

Returns all macros' orientations in a dict.

get_node_locations(plc)

Returns all node grid locations (macros and stdcells) in a dict.

get_node_ordering_by_size(plc)

Returns the list of nodes (macros and stdcells) ordered by area.

get_node_type_counts(plc)

Returns number of each type of nodes in the netlist.

get_node_xy_coordinates(plc)

Returns all node x,y coordinates (canvas) in a dict.

get_ordered_node_indices(mode, plc[, seed, ...])

Returns an ordering of node indices according to the specified mode.

grid_locations_near(plc, start_grid_index)

Yields node indices closest to the start_grid_index.

legalize_placement(plc)

Places the nodes to legal positions snapping to grid cells.

make_blockage_text(plc)

nodes_of_types(plc, type_list)

Yields the index of a node of certain types.

optimize_orientations(plc[, wirelength_weight, ...])

Coordinate descent over macro orientations.

place_near(plc, node_index, location)

Places a node (legally) closest to the given location.

read_node_order_file(plc, node_order_file)

Reads the node order from a file.

restore_macro_orientations(plc, macro_orientations)

restore_node_xy_coordinates(plc, node_coords)

save_node_order_file(plc, node_order, node_order_file)

Saves the node order to a file.

save_placement(plc, filename[, user_comments])

Saves the placement file with some information in the comments section.

Module Contents

gfn.gym.helpers.chip_design.utils.COST_COMPONENTS = ['wirelength', 'congestion', 'density']
gfn.gym.helpers.chip_design.utils.ORIENTATIONS = ['N', 'S', 'E', 'W', 'FN', 'FS', 'FE', 'FW']
gfn.gym.helpers.chip_design.utils._proxy_cost(plc, wirelength_weight, density_weight, congestion_weight)
Parameters:
Return type:

float

gfn.gym.helpers.chip_design.utils.cost_info_function(plc, done, infeasible_state=False, wirelength_weight=1.0, density_weight=1.0, congestion_weight=0.5)

Returns the RL cost and info.

Parameters:
Return type:

tuple[float, dict[str, float]]

gfn.gym.helpers.chip_design.utils.create_blockages_by_spacing_constraints(canvas_width, canvas_height, macro_boundary_x_spacing=0, macro_boundary_y_spacing=0, rectilinear_blockages=None)

Create blockages using macro-to-boundary spacing constraints.

Parameters:
  • canvas_width (float)

  • canvas_height (float)

  • macro_boundary_x_spacing (float)

  • macro_boundary_y_spacing (float)

  • rectilinear_blockages (Optional[List[List[float]]])

Return type:

List[List[float]]

gfn.gym.helpers.chip_design.utils.create_placement_cost(netlist_file, init_placement, overlap_threshold=0.004, congestion_smooth_range=5, macro_macro_x_spacing=0.1, macro_macro_y_spacing=0.1, boundary_check=False, horizontal_routes_per_micron=70.33, vertical_routes_per_micron=74.51, macro_horizontal_routing_allocation=51.79, macro_vertical_routing_allocation=51.79, routes_per_congestion_grid=1000, blockages=None, fixed_macro_names_regex=None, legacy_congestion_grid=False, singularity_image=None)

Creates a placement_cost object.

Parameters:
  • netlist_file (str)

  • init_placement (str)

  • overlap_threshold (float)

  • congestion_smooth_range (int)

  • macro_macro_x_spacing (float)

  • macro_macro_y_spacing (float)

  • boundary_check (bool)

  • horizontal_routes_per_micron (float)

  • vertical_routes_per_micron (float)

  • macro_horizontal_routing_allocation (float)

  • macro_vertical_routing_allocation (float)

  • routes_per_congestion_grid (int)

  • blockages (Optional[List[List[float]]])

  • fixed_macro_names_regex (Optional[List[str]])

  • legacy_congestion_grid (bool)

  • singularity_image (Optional[str])

Return type:

gfn.gym.helpers.chip_design.plc_client.PlacementCost

gfn.gym.helpers.chip_design.utils.disconnect_high_fanout_nets(plc, max_allowed_fanouts=500)
Parameters:
Return type:

None

gfn.gym.helpers.chip_design.utils.extract_attribute_from_comments(attribute, filenames)

Parses the files’ comments section, tries to extract the attribute.

Parameters:
  • attribute (str)

  • filenames (List[str])

Return type:

Optional[str]

gfn.gym.helpers.chip_design.utils.extract_blockages_from_file(filename, canvas_width, canvas_height)

Reads blockage information from a given file.

Parameters:
  • filename (str)

  • canvas_width (float)

  • canvas_height (float)

Return type:

Optional[List[List[float]]]

gfn.gym.helpers.chip_design.utils.extract_sizes_from_comments(filenames)

Parses the file’s comments section, tries to extract canvas/grid sizes.

Parameters:

filenames (List[str])

Return type:

Tuple[Optional[float], Optional[float], Optional[int], Optional[int]]

gfn.gym.helpers.chip_design.utils.fd_placement_schedule(plc, num_steps=(100, 100, 100), io_factor=1.0, move_distance_factors=(1.0, 1.0, 1.0), attract_factor=(100.0, 0.001, 1e-05), repel_factor=(0.0, 1000000.0, 10000000.0), use_current_loc=False, move_macros=False)

A placement schedule that uses force directed method.

Parameters:
  • plc (gfn.gym.helpers.chip_design.plc_client.PlacementCost)

  • num_steps (Tuple[int, Ellipsis])

  • io_factor (float)

  • move_distance_factors (Tuple[float, Ellipsis])

  • attract_factor (Tuple[float, Ellipsis])

  • repel_factor (Tuple[float, Ellipsis])

  • use_current_loc (bool)

  • move_macros (bool)

Return type:

None

gfn.gym.helpers.chip_design.utils.fix_macros_by_regex(plc, macro_regex_str_list)

Fix macro locations given a list of macro name regex strings.

Parameters:
gfn.gym.helpers.chip_design.utils.fix_port_coordinates(plc)

Find all ports and fix their coordinates.

Parameters:

plc (gfn.gym.helpers.chip_design.plc_client.PlacementCost)

Return type:

None

gfn.gym.helpers.chip_design.utils.get_blockages_from_comments(filenames)

Returns list of blockages if they exist in the file’s comments section.

Parameters:

filenames (Union[str, List[str]])

Return type:

Optional[List[List[float]]]

gfn.gym.helpers.chip_design.utils.get_macro_orientations(plc)

Returns all macros’ orientations in a dict.

Parameters:

plc (gfn.gym.helpers.chip_design.plc_client.PlacementCost)

Return type:

Dict[int, int]

gfn.gym.helpers.chip_design.utils.get_node_locations(plc)

Returns all node grid locations (macros and stdcells) in a dict.

Parameters:

plc (gfn.gym.helpers.chip_design.plc_client.PlacementCost)

Return type:

Dict[int, int]

gfn.gym.helpers.chip_design.utils.get_node_ordering_by_size(plc)

Returns the list of nodes (macros and stdcells) ordered by area.

Parameters:

plc (gfn.gym.helpers.chip_design.plc_client.PlacementCost)

Return type:

List[int]

gfn.gym.helpers.chip_design.utils.get_node_type_counts(plc)

Returns number of each type of nodes in the netlist.

Parameters:

plc (gfn.gym.helpers.chip_design.plc_client.PlacementCost)

Return type:

Dict[str, int]

gfn.gym.helpers.chip_design.utils.get_node_xy_coordinates(plc)

Returns all node x,y coordinates (canvas) in a dict.

Parameters:

plc (gfn.gym.helpers.chip_design.plc_client.PlacementCost)

Return type:

Dict[int, Tuple[float, float]]

gfn.gym.helpers.chip_design.utils.get_ordered_node_indices(mode, plc, seed=111, node_order_file='', exclude_fixed_nodes=True)

Returns an ordering of node indices according to the specified mode.

Parameters:
Return type:

List[int]

gfn.gym.helpers.chip_design.utils.grid_locations_near(plc, start_grid_index)

Yields node indices closest to the start_grid_index.

Parameters:
Return type:

Iterator[int]

gfn.gym.helpers.chip_design.utils.legalize_placement(plc)

Places the nodes to legal positions snapping to grid cells.

Parameters:

plc (gfn.gym.helpers.chip_design.plc_client.PlacementCost)

Return type:

bool

gfn.gym.helpers.chip_design.utils.make_blockage_text(plc)
Parameters:

plc (gfn.gym.helpers.chip_design.plc_client.PlacementCost)

Return type:

str

gfn.gym.helpers.chip_design.utils.nodes_of_types(plc, type_list)

Yields the index of a node of certain types.

Parameters:
Return type:

Iterator[int]

gfn.gym.helpers.chip_design.utils.optimize_orientations(plc, wirelength_weight=1.0, density_weight=1.0, congestion_weight=0.5, max_iterations=2)

Coordinate descent over macro orientations.

For each macro, tries all 8 orientations and greedily picks the one that minimizes the proxy cost. Repeats for max_iterations sweeps (convergence is typically reached in 1-2).

Parameters:
Return type:

None

gfn.gym.helpers.chip_design.utils.place_near(plc, node_index, location)

Places a node (legally) closest to the given location.

Parameters:
Return type:

bool

gfn.gym.helpers.chip_design.utils.read_node_order_file(plc, node_order_file)

Reads the node order from a file.

Parameters:
Return type:

List[int]

gfn.gym.helpers.chip_design.utils.restore_macro_orientations(plc, macro_orientations)
Parameters:
Return type:

None

gfn.gym.helpers.chip_design.utils.restore_node_xy_coordinates(plc, node_coords)
Parameters:
Return type:

None

gfn.gym.helpers.chip_design.utils.save_node_order_file(plc, node_order, node_order_file)

Saves the node order to a file.

Parameters:
Return type:

None

gfn.gym.helpers.chip_design.utils.save_placement(plc, filename, user_comments='')

Saves the placement file with some information in the comments section.

Parameters:
Return type:

None