33
44function print_help() {
55 printf " Usage:
6- bash $0 <config_file_or_script> workload_list.lst checkpoint_top_dir task_tag [extra_gem5_args]
6+ bash $0 <config_file_or_script> workload_list.lst checkpoint_top_dir task_tag [benchmark_filters] [ extra_gem5_args]
77
88Arguments:
99 config_file_or_script: Config file (*.py) or wrapper script (*.sh).
1010 If relative, it is resolved relative to the repo root (gem5_home).
1111 workload_list.lst: List of workloads to run
1212 checkpoint_top_dir: Root directory for checkpoints
1313 task_tag: Tag for this experiment
14+ benchmark_filters: Optional comma-separated benchmark filters, case-insensitive.
15+ Empty means no filter (run all workloads in workload_list).
1416 extra_gem5_args: Optional extra arguments for gem5 (only for .py mode)
1517
1618Examples:
@@ -20,8 +22,14 @@ Examples:
2022 # New mode (using .py config)
2123 bash $0 configs/example/idealkmhv3.py workload.lst /cpt/dir my_exp
2224
25+ # New mode with benchmark filters
26+ bash $0 configs/example/idealkmhv3.py workload.lst /cpt/dir my_exp_subset \" mcf,gcc\"
27+
2328 # New mode with extra args
24- bash $0 configs/example/idealkmhv3.py workload.lst /cpt/dir my_exp_nosc \" --disable-mgsc\"
29+ bash $0 configs/example/idealkmhv3.py workload.lst /cpt/dir my_exp_nosc \"\" \" --disable-mgsc\"
30+
31+ # New mode with filters + extra args
32+ bash $0 configs/example/idealkmhv3.py workload.lst /cpt/dir my_exp_nosc \" mcf,gcc\" \" --disable-mgsc\"
2533\n"
2634 exit 1
2735}
@@ -47,17 +55,28 @@ if [[ "$first_param" == *.sh ]]; then
4755 # Legacy mode: using wrapper script
4856 export use_legacy_mode=true
4957 export arch_script=" $first_param "
58+ export benchmark_filters=" ${5:- } " # Optional 5th parameter in legacy mode
5059 echo " Legacy mode: using script $arch_script "
5160else
5261 # New mode: using config file directly
5362 export use_legacy_mode=false
5463 export config_file=" $first_param "
55- export extra_gem5_args=" ${5:- } " # Optional 5th parameter
64+ export benchmark_filters=" ${5:- } " # Optional 5th parameter (new order)
65+ export extra_gem5_args=" ${6:- } " # Optional 6th parameter (new order)
66+ # Backward compatibility: if only one optional arg and it looks like gem5 args,
67+ # keep treating it as extra_gem5_args.
68+ if [ " $# " -eq 5 ] && [[ " ${5} " == -* ]]; then
69+ export extra_gem5_args=" ${5} "
70+ export benchmark_filters=" "
71+ fi
5672 echo " Config mode: using $config_file "
5773 if [ -n " $extra_gem5_args " ]; then
5874 echo " Extra gem5 args: $extra_gem5_args "
5975 fi
6076fi
77+ if [ -n " ${benchmark_filters// [[:space:],]/ } " ]; then
78+ echo " Benchmark filters: $benchmark_filters "
79+ fi
6180
6281# Note 1: workload list contains the workload name, checkpoint path, and parameters, looks like:
6382# astar_biglakes_122060000000 astar_biglakes_122060000000_0.244818/0/ 0 0 20 20
@@ -80,6 +99,49 @@ export full_work_dir=$ds/$tag # work dir wheter stats data stored
8099mkdir -p $full_work_dir
81100ln -sf $full_work_dir . # optional, you can customize it yourself
82101
102+ declare -a filtered_workloads=()
103+
104+ function apply_benchmark_filter() {
105+ if [ -z " ${benchmark_filters// [[:space:],]/ } " ]; then
106+ echo " No benchmark filter provided, run all workloads."
107+ return
108+ fi
109+
110+ mapfile -t filtered_workloads < <( awk -v filters=" $benchmark_filters " '
111+ BEGIN {
112+ n = split(filters, raw_filters, ",")
113+ valid = 0
114+ for (i = 1; i <= n; i++) {
115+ token = raw_filters[i]
116+ gsub(/^[[:space:]]+|[[:space:]]+$/, "", token)
117+ token = tolower(token)
118+ if (token != "") {
119+ patterns[++valid] = token
120+ }
121+ }
122+ }
123+ /^[[:space:]]*$/ { next }
124+ {
125+ lower_line = tolower($0)
126+ for (i = 1; i <= valid; i++) {
127+ if (index(lower_line, patterns[i]) > 0) {
128+ print $0
129+ next
130+ }
131+ }
132+ }
133+ ' " $workload_list " )
134+
135+ local selected_count
136+ selected_count=" ${# filtered_workloads[@]} "
137+ if [ " $selected_count " -eq 0 ]; then
138+ echo " Error: benchmark_filters '$benchmark_filters ' matched no workloads in '$workload_list '"
139+ exit 1
140+ fi
141+
142+ echo " Applied benchmark filters: '$benchmark_filters ' -> $selected_count workloads selected."
143+ }
144+
83145check () {
84146 if [ $1 -ne 0 ]; then
85147 echo FAIL
@@ -176,7 +238,12 @@ num_threads=${xsgem5_para_jobs:-63}
176238function parallel_run() {
177239 # We use gnu parallel to control the parallelism.
178240 # If your server has 32 core and 64 SMT threads, we suggest to run with no more than 32 threads.
179- cat $workload_list | parallel -a - -j $num_threads arg_wrapper {}
241+ if [ " ${# filtered_workloads[@]} " -gt 0 ]; then
242+ printf ' %s\n' " ${filtered_workloads[@]} " | parallel -a - -j $num_threads arg_wrapper {}
243+ else
244+ cat " $workload_list " | parallel -a - -j $num_threads arg_wrapper {}
245+ fi
180246}
181247
248+ apply_benchmark_filter
182249parallel_run
0 commit comments