Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/contrib/MakefileContract.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,13 @@ Several of the rules exist for them.
unsets it before the sub-make, and the fallback fires there with an in-tree
path that a flow supplying its own tools does not have (the "HERE BE
DRAGONS" comment in `flow/scripts/variables.mk`).
- **`OPENROAD_EXE` and `YOSYS_EXE` are commands, never assumed to be a
single path.** A wrapper can come first: `OPENROAD_EXE="gdb --args
openroad"`. A recipe or shell script runs the value as the shell splits
it, Python splits it with `shlex.split`, and a check looks at its first
word.
*Breaks:* running a tool under a debugger, valgrind or perf needs a
switch of its own for each tool.
- **Only the Makefile sets `RESULTS_DIR`, `LOG_DIR`, `REPORTS_DIR` and
`OBJECTS_DIR`.** It derives them from `WORK_HOME`, which a flow sets. A
variable a flow adds never reuses one of these names.
Expand Down
28 changes: 28 additions & 0 deletions docs/user/FAQS.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,34 @@ For development purposes, it is a good practice to work on branches and leave ma

See how to update using the Metrics [guide](../contrib/Metrics.md).

## How do I run OpenROAD under gdb, valgrind or perf?

Put the tool in front of the binary in `OPENROAD_EXE`. Every rule runs
`OPENROAD_EXE` as a command, sub-makes included, so it reaches every
stage and the `open_*`, `gui_*` and `web_*` targets. Below, `openroad`
stands for the binary the flow would run otherwise. The binary is the
last word of `OPENROAD_EXE`: the flow asks it alone for its version when
it writes the metrics, so the tool in front is not run for that.

```shell
# a backtrace when OpenROAD crashes, its own exit code otherwise
make DESIGN_CONFIG=./designs/nangate45/gcd/config.mk OPENROAD_EXE="gdb -batch -return-child-result -ex run -ex 'thread apply all bt' --args openroad" floorplan

# memory errors
make DESIGN_CONFIG=./designs/nangate45/gcd/config.mk OPENROAD_EXE="valgrind openroad" floorplan

# a profile, written to perf.data
make DESIGN_CONFIG=./designs/nangate45/gcd/config.mk OPENROAD_EXE="perf record -g -- openroad" floorplan

# an interactive debugger on a result
make DESIGN_CONFIG=./designs/nangate45/gcd/config.mk OPENROAD_EXE="gdb --args openroad" open_floorplan
```

A stage logs OpenROAD's output through a pipe, so use gdb in batch mode
for a stage, as in the first example; an interactive session suits
`open_*`, `gui_*` and `command`. `OPENROAD_EXE` can also come from the
environment.

## How do I get better search results?

As quoted from [ReadTheDocs](https://docs.readthedocs.io/en/stable/server-side-search/syntax.html#special-queries), this documentation is powered by [Simple Query String](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-simple-query-string-query.html#) from [Elasticsearch](https://www.elastic.co/elasticsearch/). Here are some helpful patterns:
Expand Down
13 changes: 10 additions & 3 deletions flow/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ do-auto-memories: $(RESULTS_DIR)/memories_inferred.json
$(foreach file,$(ADDITIONAL_MEMORIES),--memories $(file)) \
$(foreach file,$(AUTO_MEMORIES_REGFILES),--regfile-spec $(file)) \
$(foreach m,$(AUTO_MEMORIES_MACRO_PLACE),--macro-place $(m)) \
$(if $(AUTO_MEMORIES_REGFILES),--openroad $(OPENROAD_EXE)) \
$(if $(AUTO_MEMORIES_REGFILES),--openroad '$(subst ','\'',$(OPENROAD_EXE))') \
$(foreach file,$(TECH_LEF) $(SC_LEF),--lef $(file))

$(RESULTS_DIR)/memories.json: $(RESULTS_DIR)/memories_inferred.json $(ADDITIONAL_MEMORIES) \
Expand Down Expand Up @@ -366,8 +366,15 @@ UNSET_VARS = for var in $(UNSET_VARIABLES_NAMES); do unset $$var; done
# However, on some versions of make, MAKEFILE_LIST can be empty, so
# don't expand it in that case.
FILE_MAKEFILE ?= $(if $(firstword $(MAKEFILE_LIST)),--file=$(firstword $(MAKEFILE_LIST)),)
SUB_MAKE = $(MAKE) $(foreach V,$(COMMAND_LINE_ARGS), $(if $($V),$V=$(shell echo "$($V)" | $(FLOW_HOME)/scripts/escape.sh),$V='')) --no-print-directory $(FILE_MAKEFILE) DESIGN_CONFIG=$(DESIGN_CONFIG)
UNSET_AND_MAKE = @bash -c '$(UNSET_VARS); $(SUB_MAKE) $$@' --

# UNSET_VARS clears MAKEFLAGS too, so the sub-make gets the command-line
# variables from SUB_MAKE, as command-line variables again. Each one is a
# single shell word holding the value this make sees: single-quoted, with
# ' escaped for the shell and $ for the sub-make. Only the shell running
# the recipe parses it, so quotes, $ and spaces reach the sub-make intact.
SUB_MAKE_ARG = '$(subst ','\'',$1=$(subst $$,$$$$,$($1)))'
Comment thread
oharboe marked this conversation as resolved.
Resolved
SUB_MAKE = $(MAKE) $(foreach V,$(COMMAND_LINE_ARGS),$(call SUB_MAKE_ARG,$V)) --no-print-directory $(FILE_MAKEFILE) DESIGN_CONFIG=$(DESIGN_CONFIG)
UNSET_AND_MAKE = @bash -c '$(UNSET_VARS); "$$@"' -- $(SUB_MAKE)

$(OBJECTS_DIR)/copyright.txt:
@$(OPENROAD_CMD) $(SCRIPTS_DIR)/noop.tcl
Expand Down
2 changes: 0 additions & 2 deletions flow/scripts/escape.sh

This file was deleted.

10 changes: 8 additions & 2 deletions flow/scripts/flow.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,14 @@ rm -f "$RESULTS_DIR/$1-failed.odb" "$RESULTS_DIR/$1-failed.sdc"
eval "$OPENROAD_EXE $OPENROAD_ARGS -exit \"$SCRIPTS_DIR/noop.tcl\"" \
>"$LOG_DIR/$1.tmp.log" 2>&1

$RUN_CMD --log "$(realpath "$LOG_DIR/$1.tmp.log")" --append --tee -- \
$OPENROAD_CMD -no_splash "$SCRIPTS_DIR/run_step.tcl" -metrics "$LOG_DIR/$1.json"
# OPENROAD_CMD is a command line, quotes included: a wrapper in
# OPENROAD_EXE can have a quoted argument of its own, as in
# gdb -ex 'thread apply all bt' --args openroad. The shell parses it,
# as it does in a make recipe; plain word splitting would hand the
# wrapper the quotes and the pieces.
log="$(realpath "$LOG_DIR/$1.tmp.log")"
eval "$RUN_CMD --log \"\$log\" --append --tee -- $OPENROAD_CMD" \
'-no_splash "$SCRIPTS_DIR/run_step.tcl" -metrics "$LOG_DIR/$1.json"'
)

# Log the hash for this step. The summary "make elapsed" in "make finish",
Expand Down
3 changes: 2 additions & 1 deletion flow/scripts/memories/gen_memories.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,8 @@ def main(argv: list[str] | None = None) -> int:
p.add_argument(
"--openroad",
default=None,
help="The openroad that runs generate_ram (OPENROAD_EXE).",
help="The openroad command that runs generate_ram (OPENROAD_EXE), "
"a wrapper first if any: gdb --args openroad.",
)
p.add_argument(
"--lef",
Expand Down
13 changes: 11 additions & 2 deletions flow/scripts/memories/gen_memories_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,14 @@ def test_fold_rule(self):
# never an empty fold: 3 bits fold at most in two
self.assertEqual(folds(600, 17.6, 600, 3), 2)

def _generate(self, bit_folds, outline):
def test_openroad_is_a_command(self):
# OPENROAD_EXE can start with a wrapper; generate_ram runs under it
self._generate(8, "140000 140000 1000\n", "valgrind -q /opt/bin/openroad")
self.assertEqual(len(self.argvs), 2)
for argv in self.argvs:
self.assertEqual(argv[:4], ["valgrind", "-q", "/opt/bin/openroad", "-exit"])

def _generate(self, bit_folds, outline, command="openroad"):
# generate() with generate_ram stubbed: the generate script writes
# the outline (dx dy dbu), the views script stops the run
d = Path(self.tmp.name)
Expand All @@ -418,8 +425,10 @@ class Views(Exception):
pass

scripts = []
self.argvs = []

def openroad(cmd):
self.argvs.append(cmd)
script = Path(cmd[-1])
scripts.append(script.name)
if script.name.endswith(".generate.tcl"):
Expand All @@ -433,7 +442,7 @@ def openroad(cmd):
):
with self.assertRaises((Views, SystemExit)) as stop:
gen_memories.regfile_ram.generate(
spec, "rf", "inline", "openroad", [], d
spec, "rf", "inline", command, [], d
)
return stop.exception, scripts

Expand Down
9 changes: 7 additions & 2 deletions flow/scripts/memories/regfile_ram.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import json
import math
import os
import shlex
import subprocess
from pathlib import Path

Expand Down Expand Up @@ -593,7 +594,9 @@ def build(spec_lines: list[list[str]]) -> tuple[float, float]:
+ 'puts $f "[$die dx] [$die dy] [[ord::get_db_tech] getDbUnitsPerMicron]"\n'
+ "close $f\n"
)
subprocess.check_call([openroad, "-exit", "-no_init", "-no_splash", str(gen)])
subprocess.check_call(
[*shlex.split(openroad), "-exit", "-no_init", "-no_splash", str(gen)]
)
width, height, _ = outline.read_text().split()
return float(width), float(height)

Expand Down Expand Up @@ -662,7 +665,9 @@ def build(spec_lines: list[list[str]]) -> tuple[float, float]:
else:
tcl += _MACRO_TCL.format(out=out_dir, block=block)
views.write_text(tcl)
subprocess.check_call([openroad, "-exit", "-no_init", "-no_splash", str(views)])
subprocess.check_call(
[*shlex.split(openroad), "-exit", "-no_init", "-no_splash", str(views)]
)
core_ports = _buses((out_dir / f"{block}.ports").read_text().splitlines())
ram_ports = core_ports
periphery = ""
Expand Down
9 changes: 6 additions & 3 deletions flow/scripts/synth.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
set -u -eo pipefail
mkdir -p $RESULTS_DIR $LOG_DIR $REPORTS_DIR $OBJECTS_DIR
touch $2
$YOSYS_EXE -V > $(realpath $2)
$PYTHON_EXE "$SCRIPTS_DIR/run_command.py" --log "$(realpath $2)" --append --tee -- \
$YOSYS_EXE $YOSYS_FLAGS -c $1
# YOSYS_EXE is a command line, quotes included: a wrapper in it can have
# a quoted argument of its own. The shell parses it, as it does in a make
# recipe.
eval "$YOSYS_EXE -V" > "$(realpath $2)"
eval '$PYTHON_EXE "$SCRIPTS_DIR/run_command.py" --log "$(realpath $2)" --append --tee --' \
"$YOSYS_EXE $YOSYS_FLAGS" '-c "$1"'

# Log result hash, mirroring flow.sh's epilogue for OpenROAD stages.
# genElapsedTime.py understands .odb/.rtlil/.v so it hashes the yosys
Expand Down
13 changes: 10 additions & 3 deletions flow/scripts/variables.mk
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,14 @@ export RUN_CMD = $(PYTHON_EXE) $(FLOW_HOME)/scripts/run_command.py
export OPENROAD_EXE ?= $(abspath $(FLOW_HOME)/../tools/install/OpenROAD/bin/openroad)
export OPENSTA_EXE ?= $(abspath $(FLOW_HOME)/../tools/install/OpenROAD/bin/sta)

OPENROAD_IS_VALID := $(if $(OPENROAD_EXE),$(shell test -x $(OPENROAD_EXE) && echo "true"),)
# OPENROAD_EXE and YOSYS_EXE are commands, not only paths: a wrapper can
# come first, as in OPENROAD_EXE="gdb --args openroad" or
# OPENROAD_EXE="valgrind openroad". The check is on the program the command
# starts with, a path or a name on PATH. The binary is the last word.
# The shell splits the command, as a recipe does, so a quoted path with
# spaces in it is one program: OPENROAD_EXE="'/opt/my tools/openroad'".
command_is_valid = $(if $(1),$(shell set -- $(1) && command -v "$$1" >/dev/null && echo "true"),)
OPENROAD_IS_VALID := $(call command_is_valid,$(OPENROAD_EXE))

export OPENROAD_ARGS = -no_init -threads $(NUM_CORES) $(OR_ARGS)
export OPENROAD_CMD = $(OPENROAD_EXE) -exit $(OPENROAD_ARGS)
Expand All @@ -137,7 +144,7 @@ export OPENROAD_WEB_CMD = $(OPENROAD_EXE) -web -threads $(NUM_CORES) $(OR_ARGS)

export YOSYS_EXE ?= $(abspath $(FLOW_HOME)/../tools/install/yosys/bin/yosys)

YOSYS_IS_VALID := $(if $(YOSYS_EXE),$(shell test -x $(YOSYS_EXE) && echo "true"),)
YOSYS_IS_VALID := $(call command_is_valid,$(YOSYS_EXE))

KEPLER_FORMAL_EXE ?= $(abspath $(FLOW_HOME)/../tools/install/kepler-formal/bin/kepler-formal)
export KEPLER_FORMAL_EXE
Expand Down Expand Up @@ -191,7 +198,7 @@ export RESULTS_V = $(notdir $(sort $(wildcard $(RESULTS_DIR)/*.v)))
export GDS_MERGED_FILE = $(RESULTS_DIR)/6_1_merged.$(STREAM_SYSTEM_EXT)

define get_variables
$(foreach V, $(.VARIABLES),$(if $(filter-out $(1), $(origin $V)), $(if $(filter-out .% %QT_QPA_PLATFORM% KLAYOUT% OPENROAD_EXE OPENROAD_ARGS OPENROAD_CMD OPENROAD_NO_EXIT_CMD OPENROAD_GUI_CMD OPENROAD_WEB_CMD OPENROAD_IS_VALID OPENSTA% PYTHON% YOSYS% GENERATE_ABSTRACT_RULE% do-step% do-copy% OPEN_GUI% OPEN_GUI_SHORTCUT% SUB_MAKE% UNSET_VARS% export%, $(V)), $V$ )))
$(foreach V, $(.VARIABLES),$(if $(filter-out $(1), $(origin $V)), $(if $(filter-out .% %QT_QPA_PLATFORM% KLAYOUT% OPENROAD_EXE OPENROAD_ARGS OPENROAD_CMD OPENROAD_NO_EXIT_CMD OPENROAD_GUI_CMD OPENROAD_WEB_CMD OPENROAD_IS_VALID command_is_valid OPENSTA% PYTHON% YOSYS% GENERATE_ABSTRACT_RULE% do-step% do-copy% OPEN_GUI% OPEN_GUI_SHORTCUT% SUB_MAKE% UNSET_VARS% export%, $(V)), $V$ )))
endef

export UNSET_VARIABLES_NAMES := $(call get_variables,command% line environment% default automatic)
Expand Down
26 changes: 26 additions & 0 deletions flow/test/test_flow_sh.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,32 @@ def test_run_cmd_runs_the_stage(self):
self.assertIn("Elapsed time:", log)
self.assert_summary(log)

def test_quoted_wrapper_argument_stays_one_argument(self):
# OPENROAD_EXE="gdb -ex 'thread apply all bt' --args openroad": the
# quoted argument reaches the wrapper whole, not split with its quotes.
argv_log = os.path.join(self.tmp_dir.name, "argv.log")
wrapper = os.path.join(self.tmp_dir.name, "wrapper")
with open(wrapper, "w") as f:
f.write("#!/usr/bin/env bash\n" 'printf "%s\\n" "$@" > "$ARGV_LOG"\n')
os.chmod(wrapper, 0o755)
self.env["ARGV_LOG"] = argv_log
self.env["OPENROAD_EXE"] = "true"
self.env["OPENROAD_CMD"] = (
f"{wrapper} -ex 'thread apply all bt' --args openroad -exit"
)

self.run_stage()

with open(argv_log) as f:
argv = f.read().splitlines()
self.assertEqual(
argv[:5],
["-ex", "thread apply all bt", "--args", "openroad", "-exit"],
argv,
)
self.assertEqual(argv[5], "-no_splash", argv)
self.assertEqual(argv[7], "-metrics", argv)


if __name__ == "__main__":
unittest.main()
Loading