-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdev.sh
More file actions
executable file
·420 lines (388 loc) · 12 KB
/
Copy pathdev.sh
File metadata and controls
executable file
·420 lines (388 loc) · 12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_ROOT="$SCRIPT_DIR"
CMAKE_BIN="${CMAKE:-cmake}"
BUILD_DIR="${BUILD_DIR:-$REPO_ROOT/build}"
TOP="${TOP:-soc_top}"
DEFAULT_BUILD_JOBS="$(nproc)"
if (( DEFAULT_BUILD_JOBS > 4 )); then
DEFAULT_BUILD_JOBS=$((DEFAULT_BUILD_JOBS - 4))
fi
JOBS="${JOBS:-$DEFAULT_BUILD_JOBS}"
VERILATOR_THREADS="${VERILATOR_THREADS:-16}"
VERILATOR_LINT_THREADS="${VERILATOR_LINT_THREADS:-1}"
VERILATOR_THREADS_DPI="${VERILATOR_THREADS_DPI:-pure}"
VERILATOR_ALLOW_UNOPTTHREADS="${VERILATOR_ALLOW_UNOPTTHREADS:-1}"
VERILATOR_OUTPUT_SPLIT="${VERILATOR_OUTPUT_SPLIT:-10000}"
VERILATOR_OUTPUT_SPLIT_CFUNCS="${VERILATOR_OUTPUT_SPLIT_CFUNCS:-10000}"
RTL_NUM_CORES="${RTL_NUM_CORES:-1}"
ENABLE_UARCH_DIFF="${ENABLE_UARCH_DIFF:-0}"
ENABLE_TOPDOWN_PERF="${ENABLE_TOPDOWN_PERF:-1}"
ENABLE_IQ_DEPCHAIN_PROFILE="${ENABLE_IQ_DEPCHAIN_PROFILE:-1}"
ENABLE_SC_MODEL="${ENABLE_SC_MODEL:-0}"
SPIKE_ROOT="${SPIKE_ROOT:-$REPO_ROOT/thirdparty/spike-install}"
ELF="${ELF:-}"
CYCLES="${CYCLES:-10000000}"
TRACE_FORMAT="${TRACE_FORMAT:-}"
FST="${FST:-}"
VCD="${VCD:-}"
TRACE_DEPTH="${TRACE_DEPTH:-}"
TOPDOWN_JSON="${TOPDOWN_JSON:-}"
PROGRESS_INTERVAL="${PROGRESS_INTERVAL:-}"
MODEL_OPT_LEVEL="${MODEL_OPT_LEVEL:--O2}"
if [[ -n "$FST" && -n "$VCD" ]]; then
echo "Set only one waveform output: FST or VCD, not both." >&2
exit 2
fi
if [[ -n "$FST" ]]; then
if [[ -z "$TRACE_FORMAT" ]]; then
TRACE_FORMAT=fst
elif [[ "$TRACE_FORMAT" != "fst" ]]; then
echo "FST output requires TRACE_FORMAT=fst, got TRACE_FORMAT=$TRACE_FORMAT" >&2
exit 2
fi
fi
if [[ -n "$VCD" ]]; then
if [[ -z "$TRACE_FORMAT" ]]; then
TRACE_FORMAT=vcd
elif [[ "$TRACE_FORMAT" != "vcd" ]]; then
echo "VCD output requires TRACE_FORMAT=vcd, got TRACE_FORMAT=$TRACE_FORMAT" >&2
exit 2
fi
fi
usage() {
cat <<'EOF'
Usage: ./dev.sh <target> [cmake-build-args...]
Targets:
Setup / generated artifacts
configure
init-submodules init thirdparty submodules (legacy: submodules)
build-spike build/install Spike (legacy: spike)
synth run ASAP7 synthesis/OpenSTA estimate
Model builds
lint-rtl run RTL lint gates
build-rtl build Verilated RTL model
build-sc-model build SystemC model (legacy: sc)
build-models build RTL and SystemC models (legacy: both)
Harness builds
build-sc-spike build SYSTEMC-vs-Spike runner
build-rtl-spike build RTL-vs-Spike runner (CMake: rtl_spike)
Validation runs
run-sc-spike run SYSTEMC-vs-Spike (CMake: sc_spike)
run-rtl-spike run RTL vs Spike with AXI DRAM/topdown
Maintenance
install-hooks
clean
Configuration comes from environment variables such as TOP, BUILD_DIR,
SPIKE_ROOT, ELF, CYCLES, and JOBS.
dev.sh RTL smoke defaults to RTL_NUM_CORES=1; set RTL_NUM_CORES explicitly for
multi-core debug runs.
EOF
}
install_hooks() {
git -C "$REPO_ROOT" config core.hooksPath .githooks
echo "Configured git hooks path: .githooks"
}
configure() {
local cmd=()
cmd=(
"$CMAKE_BIN"
-S "$REPO_ROOT"
-B "$BUILD_DIR"
"-DTOP=$TOP"
"-DSPIKE_ROOT=$SPIKE_ROOT"
"-DELF=$ELF"
"-DCYCLES=$CYCLES"
"-DTOPDOWN_JSON=$TOPDOWN_JSON"
"-DVERILATOR_JOBS=$JOBS"
"-DVERILATOR_THREADS=$VERILATOR_THREADS"
"-DVERILATOR_LINT_THREADS=$VERILATOR_LINT_THREADS"
"-DVERILATOR_THREADS_DPI=$VERILATOR_THREADS_DPI"
"-DVERILATOR_ALLOW_UNOPTTHREADS=$VERILATOR_ALLOW_UNOPTTHREADS"
"-DVERILATOR_OUTPUT_SPLIT=$VERILATOR_OUTPUT_SPLIT"
"-DVERILATOR_OUTPUT_SPLIT_CFUNCS=$VERILATOR_OUTPUT_SPLIT_CFUNCS"
"-DRTL_NUM_CORES=$RTL_NUM_CORES"
"-DENABLE_UARCH_DIFF=$ENABLE_UARCH_DIFF"
"-DENABLE_TOPDOWN_PERF=$ENABLE_TOPDOWN_PERF"
"-DENABLE_IQ_DEPCHAIN_PROFILE=$ENABLE_IQ_DEPCHAIN_PROFILE"
"-DENABLE_SC_MODEL=$ENABLE_SC_MODEL"
"-DMODEL_OPT_LEVEL=$MODEL_OPT_LEVEL"
"-DTRACE_FORMAT=$TRACE_FORMAT"
)
printf '>> %q ' "${cmd[@]}"
printf '\n'
"${cmd[@]}"
}
build_target() {
local target="$1"
shift || true
local saved_enable_uarch_diff="$ENABLE_UARCH_DIFF"
local saved_enable_sc_model="$ENABLE_SC_MODEL"
if target_uses_uarch_diff "$target"; then
ENABLE_UARCH_DIFF=1
fi
if target_uses_sc_model "$target"; then
ENABLE_SC_MODEL=1
fi
configure
ENABLE_UARCH_DIFF="$saved_enable_uarch_diff"
ENABLE_SC_MODEL="$saved_enable_sc_model"
local cmd=("$CMAKE_BIN" --build "$BUILD_DIR" --target "$target" -j "$JOBS")
if (($# > 0)); then
cmd+=(-- "$@")
fi
printf '>> %q ' "${cmd[@]}"
printf '\n'
"${cmd[@]}"
}
clean_repo() {
if [[ -d "$BUILD_DIR" ]]; then
local repo_clean_cmd=("$CMAKE_BIN" --build "$BUILD_DIR" --target repo_clean -j "$JOBS")
printf '>> %q ' "${repo_clean_cmd[@]}"
printf '\n'
"${repo_clean_cmd[@]}"
fi
local rm_cmd=(rm -rf "$BUILD_DIR" "$REPO_ROOT/obj_dir_synth" "$REPO_ROOT/obj_dir_sc" "$REPO_ROOT/obj_dir_sc_spike" "$REPO_ROOT/sc_spike")
printf '>> %q ' "${rm_cmd[@]}"
printf '\n'
"${rm_cmd[@]}"
}
target_uses_uarch_diff() {
case "$1" in
run-rtl-spike|rtl_spike|build-rtl-spike)
return 0
;;
*)
return 1
;;
esac
}
target_uses_sc_model() {
case "$1" in
sc|sc_spike|build-sc-model|build-sc-spike|run-sc-spike)
return 0
;;
*)
return 1
;;
esac
}
append_ramulator_args() {
local -n out_args=$1
if [[ -n "${RAMULATOR_CONFIG:-}" ]]; then
out_args+=("--ramulator-config=$RAMULATOR_CONFIG")
fi
if [[ -n "${RAMULATOR_OVERRIDE:-}" ]]; then
out_args+=("--ramulator-override=$RAMULATOR_OVERRIDE")
fi
if [[ "${RAMULATOR_DISABLE:-0}" == "1" ]]; then
out_args+=("--ramulator-disable")
fi
}
rtl_spike() {
if [[ -z "$ELF" ]]; then
echo "ELF is required for run-rtl-spike debug runs." >&2
echo "Benchmark workload runs use the Python benchmark entrypoint." >&2
return 2
fi
python3 "$REPO_ROOT/harness/check_custom_elf.py" "$ELF"
build_target rtl_spike
local tohost_addr="${TOHOST:-}"
if [[ -z "$tohost_addr" ]]; then
local nm_bin
nm_bin="$(command -v riscv64-unknown-elf-nm || true)"
if [[ -n "$nm_bin" ]]; then
tohost_addr="$($nm_bin "$ELF" 2>/dev/null | awk '$3 == "tohost" { print "0x" $1; exit }')"
fi
fi
if [[ -z "$tohost_addr" ]]; then
echo "Could not find tohost symbol; set TOHOST=0x... explicitly" >&2
return 2
fi
local ld_path="${SPIKE_ROOT}/lib"
if [[ -n "${LD_LIBRARY_PATH:-}" ]]; then
ld_path="$ld_path:$LD_LIBRARY_PATH"
fi
local trace_args=()
if [[ -n "$FST" ]]; then
trace_args+=("--fst=$FST")
fi
if [[ -n "$VCD" ]]; then
trace_args+=("--vcd=$VCD")
fi
if [[ -n "$TRACE_DEPTH" ]]; then
trace_args+=("--trace-depth=$TRACE_DEPTH")
fi
if [[ -n "${DUMP_START_CYCLE:-}" ]]; then
trace_args+=("--dump-start-cycle=$DUMP_START_CYCLE")
fi
if [[ -n "${DUMP_END_CYCLE:-}" ]]; then
trace_args+=("--dump-end-cycle=$DUMP_END_CYCLE")
fi
if [[ -n "$TOPDOWN_JSON" ]]; then
trace_args+=("--topdown-json=$TOPDOWN_JSON")
fi
if [[ -n "$PROGRESS_INTERVAL" ]]; then
trace_args+=("--progress-interval=$PROGRESS_INTERVAL")
fi
if [[ -n "${RTL_WATCHDOG_CYCLES:-}" ]]; then
trace_args+=("--watchdog-cycles=$RTL_WATCHDOG_CYCLES")
fi
if [[ -n "$VERILATOR_THREADS" ]]; then
trace_args+=("--threads=$VERILATOR_THREADS")
fi
append_ramulator_args trace_args
local cmd=(env LD_LIBRARY_PATH="$ld_path" "$BUILD_DIR/rtl_spike" "--elf=$ELF" "--cycles=$CYCLES" "--tohost=$tohost_addr" "${trace_args[@]}")
printf '>> %q ' "${cmd[@]}"
printf '\n'
"${cmd[@]}"
}
run_sc_spike() {
if [[ -z "$ELF" ]]; then
echo "ELF is required for run-sc-spike debug runs." >&2
echo "Benchmark workload runs use the Python benchmark entrypoint." >&2
return 2
fi
build_target sc_spike
local tohost_arg=()
local tohost_addr="${TOHOST:-}"
if [[ -z "$tohost_addr" ]]; then
local nm_bin
nm_bin="$(command -v riscv64-unknown-elf-nm || true)"
if [[ -n "$nm_bin" ]]; then
tohost_addr="$($nm_bin "$ELF" 2>/dev/null | awk '$3 == "tohost" { print "0x" $1; exit }')"
fi
fi
if [[ -n "$tohost_addr" ]]; then
tohost_arg=("--tohost=$tohost_addr")
fi
local ld_path="${SPIKE_ROOT}/lib"
if [[ -n "${LD_LIBRARY_PATH:-}" ]]; then
ld_path="$ld_path:$LD_LIBRARY_PATH"
fi
local trace_args=()
if [[ -n "$FST" ]]; then
trace_args+=("--fst=$FST")
fi
if [[ -n "$VCD" ]]; then
trace_args+=("--vcd=$VCD")
fi
if [[ -n "$TRACE_DEPTH" ]]; then
trace_args+=("--trace-depth=$TRACE_DEPTH")
fi
if [[ -n "${DUMP_START_CYCLE:-}" ]]; then
trace_args+=("--dump-start-cycle=$DUMP_START_CYCLE")
fi
if [[ -n "${DUMP_END_CYCLE:-}" ]]; then
trace_args+=("--dump-end-cycle=$DUMP_END_CYCLE")
fi
if [[ -n "$TOPDOWN_JSON" ]]; then
trace_args+=("--topdown-json=$TOPDOWN_JSON")
fi
if [[ -n "$VERILATOR_THREADS" ]]; then
trace_args+=("--threads=$VERILATOR_THREADS")
fi
local cmd=(env LD_LIBRARY_PATH="$ld_path" "$BUILD_DIR/sc_spike" "--elf=$ELF" "--cycles=$CYCLES" "${tohost_arg[@]}" "${trace_args[@]}")
printf '>> %q ' "${cmd[@]}"
printf '\n'
"${cmd[@]}"
}
legacy_alias() {
local old="$1"
local new="$2"
printf 'NOTE: target %q is a compatibility alias; prefer %q.\n' "$old" "$new" >&2
}
deprecated_alias() {
local old="$1"
local new="$2"
printf 'WARNING: target %q is ambiguous/deprecated; prefer %q.\n' "$old" "$new" >&2
}
main() {
if (($# == 0)); then
usage
exit 1
fi
local target="$1"
shift
case "$target" in
install-hooks)
install_hooks
;;
configure)
configure
;;
run-sc-spike)
run_sc_spike
;;
sc-spike)
legacy_alias sc-spike run-sc-spike
run_sc_spike
;;
clean)
clean_repo
;;
init-submodules)
build_target submodules "$@"
;;
build-spike)
build_target spike "$@"
;;
lint-rtl)
build_target verilator_lint "$@"
;;
build-rtl)
build_target verilator_rtl "$@"
;;
build-sc-model)
build_target sc "$@"
;;
build-models)
build_target verilator_rtl "$@"
build_target sc "$@"
;;
build-sc-spike)
build_target sc_spike "$@"
;;
build-rtl-spike)
build_target rtl_spike "$@"
;;
run-rtl-spike)
rtl_spike
;;
submodules)
legacy_alias submodules init-submodules
build_target "$target" "$@"
;;
spike)
legacy_alias spike build-spike
build_target "$target" "$@"
;;
synth)
build_target synth "$@"
;;
both)
legacy_alias both build-models
build_target verilator_rtl "$@"
build_target sc "$@"
;;
rtl_spike)
legacy_alias rtl_spike build-rtl-spike
build_target rtl_spike "$@"
;;
sc)
legacy_alias sc build-sc-model
build_target sc "$@"
;;
sc_spike)
legacy_alias sc_spike build-sc-spike
build_target sc_spike "$@"
;;
*)
echo "Unknown target: $target" >&2
usage >&2
exit 1
;;
esac
}
main "$@"