Skip to content

Commit 27cfa44

Browse files
Kaiweitumeta-codesync[bot]
authored andcommitted
Add a control knob to reduce the job amount in svt_mini
Differential Revision: D115075783 fbshipit-source-id: d2227984f948a08b7da1927704c60fe1324093f8
1 parent 634bc47 commit 27cfa44

3 files changed

Lines changed: 120 additions & 28 deletions

File tree

benchpress/config/jobs.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,16 +1434,20 @@
14341434
- '--sample-rate {sample_rate}'
14351435
- '--sampling-seed {sampling_seed}'
14361436
- '--sleep-before-perf {sleep_before_perf}'
1437+
- '--sweep-stride {sweep_stride}'
14371438
vars:
14381439
- 'encoder=svt'
14391440
- 'levels=0:0'
14401441
- 'output=video_transcode_bench_results.txt'
14411442
- 'runtime=medium'
14421443
- 'parallelism=1'
1444+
# -1 = one encoder per usable core. Peak memory is roughly
1445+
# procs * 0.5GB, so override this to fit a memory budget; see README.
14431446
- 'procs=-1'
14441447
- 'sample_rate=0.01'
14451448
- 'sampling_seed=1000'
14461449
- 'sleep_before_perf=0'
1450+
- 'sweep_stride=3'
14471451
hooks:
14481452
- hook: copymove
14491453
options:

packages/video_transcode_bench/README.md

Lines changed: 71 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ LICENSE file in the root directory of this source tree.
66
-->
77
# VideoTranscodeBench
88

9-
This is a benchmark based on ffmpeg that represents the video encoding workloads. It can apply different encoders and videos, and run them at various encoding levels.
9+
This is a benchmark based on ffmpeg that represents video encoding workloads. It can apply different encoders and videos, and run them at various encoding levels.
1010

1111
## Install VideoTranscodeBench
1212
Installing VideoTranscodeBench involves two steps.
@@ -19,9 +19,9 @@ Installing VideoTranscodeBench involves two steps.
1919

2020
### 2. Download and prepare datasets
2121
We recommend using the `El Fuente Test Sequence` from
22-
[CDVL](https://www.cdvl.org/). the CDVL website requires (free) registration, so
22+
[CDVL](https://www.cdvl.org/). The CDVL website requires (free) registration, so
2323
this step is not included in the install script. After registering and logging
24-
in, search for `ElFuente Shots for SI/TI, Y4M format, 1080p 29.96fps` and
24+
in, search for `ElFuente Shots for SI/TI, Y4M format, 1080p 29.96fps` and
2525
download the zip file to your local machine. We recommend `p7zip` for
2626
decompression (and please ignore the header error during decompression). After
2727
decompression, move all the `.y4m` files to the folder
@@ -42,8 +42,8 @@ cp frames_y4m/*.y4m <path_to_DCPerf>/benchmarks/video_transcode_bench/datasets/c
4242

4343
### Example job - `video_transcode_bench_svt`
4444

45-
`video_transcode_bench_svt` is the version of VideoTranscodeBench that use all
46-
CPU cores to conduct video encoding with `SVT-AV1` encoder.
45+
`video_transcode_bench_svt` is the version of VideoTranscodeBench that uses all
46+
CPU cores to conduct video encoding with the `SVT-AV1` encoder.
4747

4848
To run VideoTranscodeBench, simply execute the following command
4949

@@ -52,9 +52,9 @@ To run VideoTranscodeBench, simply execute the following command
5252
```
5353

5454
This job also has the following optional parameters:
55-
- `runtime`: select a pre-defined set of levels to run based on the runtime length. Three options (`short|medium|long`) are avaiable.
55+
- `runtime`: select a pre-defined set of levels to run based on the runtime length. Three options (`short|medium|long`) are available.
5656
- `output`: output file name.
57-
- `levels`: manually specify the encoding levels of `SVT-AV1` encoder in the format of `low:high`. Default value is `0:0`, meaning is not specified, and the `runtime` parameter should be used instead.
57+
- `levels`: manually specify the encoding levels of `SVT-AV1` encoder in the format of `low:high`. Default value is `0:0`, meaning it is not specified, and the `runtime` parameter should be used instead.
5858
- **The user can either pass `levels` or `runtime` to run the benchmark, but `runtime` is highly recommended.**
5959

6060

@@ -64,18 +64,65 @@ For example, If you would like to run predefined short workloads, you can run th
6464
./benchpress_cli.py run video_transcode_bench_svt -i '{"runtime": "short"}'
6565
```
6666

67-
Another example. if you would like to run level 5 to 11, you can run the following:
67+
Another example: if you would like to run level 5 to 11, you can run the following:
6868

6969
```
7070
./benchpress_cli.py run video_transcode_bench_svt -i '{"levels": "5:11"}'
7171
```
7272

73-
## VideoTranscodeBench Timed Mini (Two-Run Pattern)
73+
## DCPerf Mini
7474

75-
The timed mini variant uses a two-run pattern to reduce execution time,
76-
similar to DjangoBench and SparkBench mini versions.
75+
Two mini variants shrink VideoTranscodeBench so it finishes in tens of
76+
seconds instead of tens of minutes, for compute- and memory-constrained
77+
environments such as emulators. They differ in how many runs they take and
78+
in which phases they measure:
7779

78-
### Run 1: Prep (on a real machine with the full dataset)
80+
| | `video_transcode_bench_svt_mini` | `..._timed_mini_prep` + `..._timed_mini_reuse` |
81+
|---|---|---|
82+
| Phases measured | downscale **and** encode | encode only |
83+
| Source dataset (~42GB) needed | every run | prep run only |
84+
85+
### Downscale + Encode: `video_transcode_bench_svt_mini`
86+
87+
This mini job downscales the sampled clips and encodes them in the same run. Both the runtime and the peak memory vary
88+
from machine to machine: the defaults size themselves from the cores the job
89+
can actually use, so the same job is heavier on a large host than on a small
90+
one. Two recommend knobs to tune the runtime and peak memory usage of the benchmark:
91+
92+
93+
- `procs` is the number of concurrent single-threaded encoders. At `-1` it
94+
follows the usable core count, so the peak memory footprint scales with the
95+
machine (or with the cpuset the job runs in). To fit a memory budget, set
96+
`procs` explicitly:
97+
98+
```
99+
./benchpress_cli.py run video_transcode_bench_svt_mini -i '{"procs": "6"}'
100+
```
101+
Memory usage varies from machine to machine, but a smaller `procs` always
102+
gives a smaller memory footprint. Tune it down if the test machine has limited
103+
memory capacity.
104+
105+
106+
- `sweep_stride` downsamples the number of encoding jobs, keeping one job out
107+
of every N. The default `3` therefore runs a third of them. Raise it to drop
108+
more jobs and shorten the run further, or lower it towards `1` for a fuller
109+
run:
110+
111+
```
112+
./benchpress_cli.py run video_transcode_bench_svt_mini -i '{"sweep_stride": "3"}'
113+
```
114+
115+
Because it drops whole jobs rather than shrinking them, it changes the
116+
runtime and the score's sample size but not the peak memory.
117+
118+
### Encode-only: `..._timed_mini_prep` + `..._timed_mini_reuse`
119+
120+
This variant splits the work in two so that the measured run contains only
121+
encoding, the same two-run pattern used by the DjangoBench and SparkBench
122+
minis. The prep run is not itself a measurement; it exists to produce the
123+
cached clips the reuse run consumes.
124+
125+
#### Run 1: Prep (on a real machine with the full dataset)
79126

80127
Run the prep variant to downscale a sampled subset of clips and cache them
81128
for reuse:
@@ -93,7 +140,7 @@ This creates the following cached artifacts inside
93140

94141
Back up these files for use on other machines or emulators.
95142

96-
### (Optional) Delete source dataset to save space
143+
#### (Optional) Delete source dataset to save space
97144

98145
After the prep run, the original dataset (~42GB) in `datasets/cuts/` is no
99146
longer needed. You can delete it to reduce disk usage:
@@ -102,7 +149,7 @@ longer needed. You can delete it to reduce disk usage:
102149
rm -rf ./benchmarks/video_transcode_bench/datasets/cuts/
103150
```
104151

105-
### Run 2+: Reuse (on emulator or target machine)
152+
#### Run 2+: Reuse (on emulator or target machine)
106153

107154
Copy the cached artifacts to the target machine, then run the reuse variant:
108155

@@ -119,9 +166,7 @@ can be run repeatedly without re-prepping.
119166
If `resized_clips/` is not found, the reuse variant will exit with an error
120167
directing you to run the prep variant first.
121168

122-
### Tuning parameters
123-
124-
#### Sample rate (`sample_rate`)
169+
#### `sample_rate`
125170

126171
The mini prep variant (`video_transcode_bench_svt_timed_mini_prep`) uses
127172
`sample_rate=0.2` by default, selecting ~20% of the source clips
@@ -141,12 +186,13 @@ and **image size**:
141186
effective measurement window.
142187

143188
To override the default:
189+
144190
```bash
145191
./benchpress_cli.py run video_transcode_bench_svt_timed_mini_prep \
146192
-i '{"sample_rate": "0.5"}'
147193
```
148194

149-
#### Fast jobs first (`--fast-jobs-first`)
195+
#### `fast_jobs_first`
150196

151197
The prep variant uses `--fast-jobs-first` to reverse the command file order so
152198
that small-resolution (fast) encoding jobs run first. This is useful for the
@@ -164,7 +210,7 @@ Without `--fast-jobs-first`, the truncated subset includes a mix of clip sizes
164210
and resolutions, producing a throughput measurement that better reflects the
165211
full workload.
166212

167-
### Full timed variant (prep/reuse)
213+
## Full timed variant (prep/reuse)
168214

169215
The same two-run pattern is available for the full (non-mini) timed variant:
170216

@@ -182,22 +228,22 @@ reuse variant can be compared with the prep variant and the original
182228

183229
## Note
184230

185-
This benchmark normally takes around tens of minutes to finish, depending on the levels or predefined workload you choose. Note that lower levels (like level 1, 2, and 3) can take hours to complete. **We suggest starting form higher levels (or `short` as runtime) for fast iterations.** The default `runtime` is `medium`.
231+
This benchmark normally takes around tens of minutes to finish, depending on the levels or predefined workload you choose. Note that lower levels (like level 1, 2, and 3) can take hours to complete. **We suggest starting from higher levels (or `short` as runtime) for fast iterations.** The default `runtime` is `medium`.
186232

187233

188-
It is also recommended to turn on CPU boost before running this benchmark, otherwise it might yield very low result.
234+
It is also recommended to turn on CPU boost before running this benchmark, otherwise it might yield very low results.
189235

190236
## Encoders
191237

192-
For now, this benchmark support three encoders -- `SVT-AV1`, `libaom`, and `x264` (`SVT-AV1` is the default one). To add more, please modify the `BENCHMARK CONFIG` section, adn the function `build_ffmpeg` in `./packages/video_transcode_bench/install_video_transcode_bench.sh`, as well as a new `build_encoder_name` function inside.
238+
For now, this benchmark supports three encoders -- `SVT-AV1`, `libaom`, and `x264` (`SVT-AV1` is the default one). To add more, please modify the `BENCHMARK CONFIG` section and the function `build_ffmpeg` in `./packages/video_transcode_bench/install_video_transcode_bench.sh`, as well as a new `build_encoder_name` function inside.
193239

194240
## Datasets
195241

196-
For now, this benchmark support three videos -- `chimera`, `elfuente` and `elfuente_footmarket` (`chimera` is the default one in the scirpt). To add more, please modify the `BENCHMARK CONFIG` section and the `BUILD AND INSTALL ` section in `./packages/video_transcode_bench/install_video_transcode_bench.sh`
242+
For now, this benchmark supports three videos -- `chimera`, `elfuente` and `elfuente_footmarket` (`chimera` is the default one in the script). To add more, please modify the `BENCHMARK CONFIG` section and the `BUILD AND INSTALL` section in `./packages/video_transcode_bench/install_video_transcode_bench.sh`.
197243

198244
## Reporting and Measurement
199245

200-
After the ffmpeg benchmark finishing, benchpress will report the results in
246+
After the ffmpeg benchmark finishes, benchpress will report the results in
201247
JSON format like the following:
202248

203249
```
@@ -247,7 +293,7 @@ JSON format like the following:
247293
The result report will include performance numbers of each encoding level (named `level12` and `level13`), as well as the h-mean of all levels, in the `metrics` section.
248294

249295

250-
Ffmpeg will also generate metrics reports at
296+
ffmpeg will also generate a metrics report at
251297
`benchmark_metrics_<run_id>/video_transcode_bench_results.txt`
252298

253299

packages/video_transcode_bench/run.sh

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ source "${BENCHPRESS_ROOT}/packages/common/runtime_breakdown_utils.sh"
2929

3030
show_help() {
3131
cat <<EOF
32-
Usage: ${0##*/} [-h] [--encoder svt|aom|x264] [--levels low:high]|[--runtime long|medium|short]|[--parallelism 0-6]|[--procs {number of jobs}]|[--sample-rate 0.0-1.0]|[--sampling-seed {seed}] [--sleep-before-perf {seconds}] [--max-time {seconds}] [--score-mode throughput|megapixel] [--output {output file name}]
32+
Usage: ${0##*/} [-h] [--encoder svt|aom|x264] [--levels low:high]|[--runtime long|medium|short]|[--parallelism 0-6]|[--procs {number of jobs}]|[--sample-rate 0.0-1.0]|[--sampling-seed {seed}] [--sleep-before-perf {seconds}] [--max-time {seconds}] [--score-mode throughput|megapixel] [--sweep-stride {N}] [--output {output file name}]
3333
3434
-h Display this help and exit
3535
--encoder encoder name. Default: svt
@@ -41,6 +41,7 @@ Usage: ${0##*/} [-h] [--encoder svt|aom|x264] [--levels low:high]|[--runtime lon
4141
--max-time max encoding time in seconds. 0 means no limit. Default: 0
4242
--score-mode scoring method: throughput (GB/s) or megapixel (MPx/s). Default: throughput
4343
--fast-jobs-first reverse command order so fast (small resolution) jobs run first
44+
--sweep-stride {N} keep every Nth encode of the resolution x QP grid. 1 = keep all. Default: 1
4445
-output Result output file name. Default: "ffmpeg_video_workload_results.txt"
4546
EOF
4647
}
@@ -54,6 +55,31 @@ delete_replicas() {
5455
fi
5556
}
5657

58+
# Keep every Nth QP from each generated command file.
59+
apply_sweep_stride() {
60+
local stride="$1" test_id="$2" lo="$3" hi="$4"
61+
62+
if ! [[ "${stride}" =~ ^[1-9][0-9]*$ ]]; then
63+
echo "Invalid sweep-stride '${stride}': expected a positive integer" 1>&2
64+
return 1
65+
fi
66+
67+
if [ "${stride}" -le 1 ]; then
68+
return 0
69+
fi
70+
71+
local m f total kept
72+
for m in $(seq "${lo}" "${hi}"); do
73+
f="run-${test_id}-m${m}.txt"
74+
[ -f "${f}" ] || continue
75+
total=$(wc -l < "${f}")
76+
awk -v n="${stride}" 'NR % n == 1' "${f}" > "${f}.strided"
77+
mv "${f}.strided" "${f}"
78+
kept=$(wc -l < "${f}")
79+
echo "sweep-stride ${stride}: ${f} ${total} -> ${kept} encodes"
80+
done
81+
}
82+
5783
collect_perf_record() {
5884
sleep $sleep_before_perf
5985
if [ -f "perf.data" ]; then
@@ -106,6 +132,10 @@ main() {
106132
local keep_downscaled
107133
keep_downscaled=0
108134

135+
# Keep every Nth encode of the resolution x QP grid. 1 = keep all (default, unchanged behaviour)
136+
local sweep_stride
137+
sweep_stride=1
138+
109139
# Create a backup of generate_commands_all.py before making any changes, to restore it later and avoid replicating changes for susequent runs
110140
cp ${FFMPEG_ROOT}/generate_commands_all.py ${FFMPEG_ROOT}/generate_commands_all.backup.py
111141

@@ -147,6 +177,13 @@ main() {
147177
--fast-jobs-first)
148178
fast_jobs_first="$2"
149179
;;
180+
--sweep-stride)
181+
if ! [[ "$2" =~ ^[1-9][0-9]*$ ]]; then
182+
echo "Invalid --sweep-stride '$2': expected a positive integer" 1>&2
183+
exit 1
184+
fi
185+
sweep_stride="$2"
186+
;;
150187
--skip-downscale)
151188
skip_downscale=1
152189
;;
@@ -166,7 +203,7 @@ main() {
166203
esac
167204

168205
case $1 in
169-
--levels|--encoder|--output|--runtime|--parallelism|--procs|--sample-rate|--sampling-seed|--sleep-before-perf|--max-time|--score-mode|--fast-jobs-first)
206+
--levels|--encoder|--output|--runtime|--parallelism|--procs|--sample-rate|--sampling-seed|--sleep-before-perf|--max-time|--score-mode|--fast-jobs-first|--sweep-stride)
170207
if [ -z "$2" ]; then
171208
echo "Invalid option: $1 requires an argument" 1>&2
172209
exit 1
@@ -297,14 +334,19 @@ main() {
297334
# Reuse command files and scripts from a prior prep run.
298335
# Command files are always stored in original order on disk.
299336
# fast_jobs_first reversal is applied at runtime in run-paral-cpu.sh.
300-
true
337+
338+
if [ "${sweep_stride}" -gt 1 ]; then
339+
echo "Note: --sweep-stride ${sweep_stride} is ignored on a --skip-downscale reuse run;" 1>&2
340+
echo " the reused command files already carry the prep run's stride." 1>&2
341+
fi
301342
else
302343
# Use the Python script to modify generate_commands_all.py
303344
python3 ./modify_generate_commands_all.py --sample-rate ${sample_rate} --sampling-seed ${sampling_seed} --lp-number "${lp_number}" --num-pool "${num_pool}" --range "${range}" --encoder $encoder
304345
# create a copy of generate_commands_all.py to generate_commands_all.debug.py for debugging purposes
305346
cp ${FFMPEG_ROOT}/generate_commands_all.py ${FFMPEG_ROOT}/generate_commands_all.debug.py
306347
#generate commands
307348
python3 ./generate_commands_all.py
349+
apply_sweep_stride "$sweep_stride" "$enc_test_id" "$low" "$high"
308350
fi
309351

310352
# Overwrite run-paral-cpu to use the timed parallel feeder.

0 commit comments

Comments
 (0)