The-OpenROAD-Project / OpenLane

OpenLane is an automated RTL to GDSII flow based on several components including OpenROAD, Yosys, Magic, Netgen and custom methodology scripts for design exploration and optimization.
https://openlane.readthedocs.io/
Apache License 2.0
1.36k stars 374 forks source link

Please add hooks for user scripts into openroad tcl files #1964

Open chaufe opened 1 year ago

chaufe commented 1 year ago

Description

I like OpenLane being a good reference flow for the use of OpenROAD etc. But as OpenLane cannot fit all user purposes, sometimes files need individual changes that users may have to re-apply whenever new versions of OpenLane are available. I would like to propose adding hooks into the OpenLane tcl scripts such that users do no longer need to locally patch OpenLane, but just need to provide their user scripts that OpenLane will source-in at pre-defined positions.

/cc @proppy /cc @dhaentz1

Proposal

Please find attached example code that adds the following changes to the OpenROAD tcl files contained inside scripts/openroad:

An environment variable OPENROAD_USER_SCRIPTS points to a directory containing all user scripts. If the variable does not exist, or if the directory does not exist, no user scripts will be read in.

There are four classes of user scripts for the following phases: setup: These files will be read during setup, right prior to reading-in the data base via read pre: These files will be read-in right prior to the actual task of a script, i.e. right prior to detailed routing. post: These scripts will be read-in after the actual task of a script, i.e. prior to reporting and saving results via write. final: These scripts will be read-in at the very end.

Setup-scripts can be used to modify variables etc to change how data is read in. Pre-scripts can be used to modify how the actual main task is performed. Post-scripts can be used to modify or enhance the result of the main task. Final-scripts can be used to modify the data written to disk or to add reporting etc.

For all four classes, there are two file names supported:

If user script are not available for a certain phase or step, execution continues w/o complaint.

The following code illustrates how user script hook could be added into the script droute.tcl:

source $::env(SCRIPTS_DIR)/openroad/common/io.tcl

execute_user_setup_hook "droute"

read

set_thread_count $::env(ROUTING_CORES)

set min_layer $::env(RT_MIN_LAYER)
if { [info exists ::env(DRT_MIN_LAYER)] } {
    set min_layer $::env(DRT_MIN_LAYER)
}

set max_layer $::env(RT_MAX_LAYER)
if { [info exists ::env(DRT_MAX_LAYER)] } {
    set max_layer $::env(DRT_MAX_LAYER)
}

read_guides $::env(CURRENT_GUIDE)

execute_user_pre_hook "droute"

detailed_route\
    -bottom_routing_layer $min_layer\
    -top_routing_layer $max_layer\
    -output_maze $::env(_tmp_drt_file_prefix)_maze.log\
    -output_drc $::env(_tmp_drt_rpt_prefix).drc\
    -droute_end_iter $::env(DRT_OPT_ITERS)\
    -or_seed 42\
    -verbose 1

execute_user_post_hook "droute"

write

execute_user_final_hook "droute"

The procedures execute_user_*_hook have been defined inside io.tcl.

openroad_scripts_with_user_hooks.zip

donn commented 1 year ago

It's not a bad idea- but a couple notes:

  1. The rewrite of OpenLane is already designed to let you subclass and replace step scripts entirely as follows: e.g. https://github.com/efabless/openlane2/blob/169378e8b2eba0fe5d177779107a4f16af0d6c1a/openlane/steps/openroad.py#L926
  2. We'd have to commit to an API for these scripts. Currently, we enjoy the flexibility of being able to modify them with prejudice.

I'll bring this up with the team internally, though.