|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -euo pipefail |
| 3 | + |
| 4 | +ROOT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)" |
| 5 | +cd "$ROOT_DIR" |
| 6 | + |
| 7 | +OPENROAD_EXE="${OPENROAD_EXE:-$ROOT_DIR/tools/OpenROAD/build/bin/openroad}" |
| 8 | +NUM_CORES="${NUM_CORES:-4}" |
| 9 | +VALIDATE_N="${VALIDATE_N:-18}" |
| 10 | +VALIDATE_JOBS="${VALIDATE_JOBS:-18}" |
| 11 | +TIME_BUDGET_S="${TIME_BUDGET_S:-3000}" |
| 12 | + |
| 13 | +SURROGATE_SAMPLES="${SURROGATE_SAMPLES:-100000000000}" |
| 14 | +SURROGATE_TOP_N="${SURROGATE_TOP_N:-200}" |
| 15 | +SURROGATE_GLOBAL_TOP_N="${SURROGATE_GLOBAL_TOP_N:-200}" |
| 16 | + |
| 17 | +DATE_TAG="${DATE_TAG:-20260211}" |
| 18 | +SEED="${SEED:-1}" |
| 19 | + |
| 20 | +need_file() { |
| 21 | + local path="$1" |
| 22 | + if [[ ! -f "$path" ]]; then |
| 23 | + echo "Missing required file: $path" >&2 |
| 24 | + exit 1 |
| 25 | + fi |
| 26 | +} |
| 27 | + |
| 28 | +surrogate_done() { |
| 29 | + local summary="$1" |
| 30 | + python3 - <<'PY' "$summary" |
| 31 | +import json, sys |
| 32 | +from pathlib import Path |
| 33 | +p = Path(sys.argv[1]) |
| 34 | +if not p.exists(): |
| 35 | + raise SystemExit(1) |
| 36 | +try: |
| 37 | + obj = json.loads(p.read_text()) |
| 38 | +except Exception: |
| 39 | + raise SystemExit(1) |
| 40 | +val = obj.get("validation") if isinstance(obj, dict) else None |
| 41 | +enabled = bool(val.get("enabled")) if isinstance(val, dict) else False |
| 42 | +raise SystemExit(0 if enabled else 1) |
| 43 | +PY |
| 44 | +} |
| 45 | + |
| 46 | +random_done() { |
| 47 | + local summary="$1" |
| 48 | + [[ -f "$summary" ]] |
| 49 | +} |
| 50 | + |
| 51 | +wait_for_idle() { |
| 52 | + while pgrep -f "flow/scripts/surrogate_autotune.py" >/dev/null 2>&1; do |
| 53 | + echo "[bench] Waiting: surrogate_autotune.py already running..." |
| 54 | + sleep 60 |
| 55 | + done |
| 56 | + while pgrep -f "flow/scripts/random_baseline.py" >/dev/null 2>&1; do |
| 57 | + echo "[bench] Waiting: random_baseline.py already running..." |
| 58 | + sleep 60 |
| 59 | + done |
| 60 | +} |
| 61 | + |
| 62 | +run_surrogate_ecp() { |
| 63 | + local platform="$1" |
| 64 | + local design="$2" |
| 65 | + local variant="$3" |
| 66 | + local design_config="designs/${platform}/${design}/config.mk" |
| 67 | + local space_file="designs/${platform}/${design}/surrogate_space.json" |
| 68 | + local summary="flow/results/${platform}/${design}/${variant}/surrogate_autotune.json" |
| 69 | + |
| 70 | + need_file "flow/${design_config}" |
| 71 | + need_file "flow/${space_file}" |
| 72 | + |
| 73 | + if surrogate_done "$summary"; then |
| 74 | + echo "[bench] surrogate done: ${platform}/${design} (${variant})" |
| 75 | + return 0 |
| 76 | + fi |
| 77 | + |
| 78 | + echo "[bench] surrogate start: ${platform}/${design} (${variant})" |
| 79 | + wait_for_idle |
| 80 | + OPENROAD_EXE="$OPENROAD_EXE" make -C flow surrogate_autotune \ |
| 81 | + "DESIGN_CONFIG=${design_config}" \ |
| 82 | + "FLOW_VARIANT=${variant}" \ |
| 83 | + "NUM_CORES=${NUM_CORES}" \ |
| 84 | + "SURROGATE_SPACE_FILE=${space_file}" \ |
| 85 | + "SURROGATE_OBJECTIVE=effective_clock_period" \ |
| 86 | + "SURROGATE_RESUME=1" \ |
| 87 | + "SURROGATE_TIME_BUDGET_S=${TIME_BUDGET_S}" \ |
| 88 | + "SURROGATE_SAMPLES=${SURROGATE_SAMPLES}" \ |
| 89 | + "SURROGATE_TOP_N=${SURROGATE_TOP_N}" \ |
| 90 | + "SURROGATE_GLOBAL_TOP_N=${SURROGATE_GLOBAL_TOP_N}" \ |
| 91 | + "SURROGATE_VALIDATE=1" \ |
| 92 | + "SURROGATE_VALIDATE_N=${VALIDATE_N}" \ |
| 93 | + "SURROGATE_VALIDATE_JOBS=${VALIDATE_JOBS}" \ |
| 94 | + "SURROGATE_VALIDATE_MAKE_TARGET=report" \ |
| 95 | + "SURROGATE_ROUTE_VALIDATE_N=${VALIDATE_N}" \ |
| 96 | + "SURROGATE_ROUTE_VALIDATE_JOBS=${VALIDATE_JOBS}" \ |
| 97 | + "SURROGATE_ROUTE_INJECT_RANDOM_N=0" |
| 98 | +} |
| 99 | + |
| 100 | +run_random_ecp() { |
| 101 | + local platform="$1" |
| 102 | + local design="$2" |
| 103 | + local synth_from_variant="$3" |
| 104 | + local platform_tag="$platform" |
| 105 | + if [[ "$platform" == "nangate45" ]]; then |
| 106 | + platform_tag="ng45" |
| 107 | + fi |
| 108 | + local prefix="rand18_${platform_tag}_${design}_${DATE_TAG}" |
| 109 | + local summary="flow/results/${platform}/${design}/${prefix}_ecp/random_baseline.json" |
| 110 | + |
| 111 | + need_file "flow/designs/${platform}/${design}/config.mk" |
| 112 | + |
| 113 | + if random_done "$summary"; then |
| 114 | + echo "[bench] random done: ${platform}/${design} (${prefix}_ecp)" |
| 115 | + return 0 |
| 116 | + fi |
| 117 | + |
| 118 | + echo "[bench] random start: ${platform}/${design} (${prefix}_ecp)" |
| 119 | + wait_for_idle |
| 120 | + OPENROAD_EXE="$OPENROAD_EXE" python3 flow/scripts/random_baseline.py \ |
| 121 | + --platforms "$platform" \ |
| 122 | + --designs "$design" \ |
| 123 | + --objectives ecp \ |
| 124 | + --validate-n "$VALIDATE_N" \ |
| 125 | + --validate-jobs "$VALIDATE_JOBS" \ |
| 126 | + --num-cores "$NUM_CORES" \ |
| 127 | + --make-target report \ |
| 128 | + --clock-strategy space \ |
| 129 | + --clock-sweep-n 9 \ |
| 130 | + --synth-from-variant "$synth_from_variant" \ |
| 131 | + --compare-to-variant-ecp "$synth_from_variant" \ |
| 132 | + --variant-prefix "$prefix" \ |
| 133 | + --resume \ |
| 134 | + --seed "$SEED" |
| 135 | +} |
| 136 | + |
| 137 | +variant_for() { |
| 138 | + local platform="$1" |
| 139 | + local design="$2" |
| 140 | + if [[ "$design" == "ibex" && ( "$platform" == "asap7" || "$platform" == "nangate45" ) ]]; then |
| 141 | + echo "ecpwall_modelv2_ibex_t3000s" |
| 142 | + else |
| 143 | + echo "ecpwall_modelv2_t3000s_ecp_${platform}_${design}" |
| 144 | + fi |
| 145 | +} |
| 146 | + |
| 147 | +main() { |
| 148 | + need_file "$OPENROAD_EXE" |
| 149 | + |
| 150 | + local platforms=(asap7 nangate45 sky130hd) |
| 151 | + local designs=(aes ibex jpeg) |
| 152 | + |
| 153 | + for platform in "${platforms[@]}"; do |
| 154 | + for design in "${designs[@]}"; do |
| 155 | + local variant |
| 156 | + variant="$(variant_for "$platform" "$design")" |
| 157 | + run_surrogate_ecp "$platform" "$design" "$variant" |
| 158 | + run_random_ecp "$platform" "$design" "$variant" |
| 159 | + done |
| 160 | + done |
| 161 | + |
| 162 | + echo "[bench] done" |
| 163 | +} |
| 164 | + |
| 165 | +main "$@" |
0 commit comments