Repository navigation
Speed up the GDF and LR encoder searches without changing the output - #5589
Conversation
e0f848a to
c25c6ac
Compare
|
Hello all, could you please help review the code? Thanks |
|
Thanks @yeqing-wu. The speed-up looks great, especially for higher resolution! It will be best if folks more familiar with GDF / LR can review. @jianle973 : pls review if you can. |
Hi @urvangjoshi, it’s the wall clock time. Our cloud resources are very stable, which ensures a stable wall clock time. I’ve conducted multiple runs after code rebasing and internal code reviews, and the saving encoding time is consistent. Meanwhile, multithreading for LR and GDF can only save wall clock time and not the instruction count since it is not tile based. Some code changes have also helped save about 5% of the instruction count, so even with one thread, the optimizations from this PR can still save encoding time. Please refer to the attached results for the instruction count of speed 6.
|
|
Hello @jianle973 or @yunqingwang1, could you please help review the code? |
|
Thanks for the speed improvements! I also have a working patch on batch integer SIMD and stats collection improvements for nonseparable Wiener filter. I will also help reviewing this patch. |
Thanks @kslu-aom. BTW, one of commits is related to SIMD and stats collection in LR, I am not sure if that is overlap with yours. |
Yes, there is an overlap, and some of my changes may be integrated or added on top of this patch. Let me figure out which way is simpler. |
kslu-aom
left a comment
There was a problem hiding this comment.
I have reviewed the Wiener filter code and it looks good to me. This seems to largely overlap with my working patch, so I do not plan to upload any new PR, but only leave a few minor comments (mostly optional). I will leave the GDF related changes to other reviewers.
f69d42b to
62b9296
Compare
|
@yeqing-wu : pls rebase to resolve merge conflict. |
Each thread now copies the guided frame rows it needs into its own buffer, so the GDF blocks can be split into jobs and run on the encoder workers. The output does not change. The new speed feature enable_gdf_mt turns this off with one thread or with BRU. Anchor: commit 9c72cb5 Speed 0 (cpu-used=0): CTC (33 frames, AI, RA and LD), no BD-rate change Speed 2 (cpu-used=2): CTC (65 frames, class A1 and A2, RA), no BD-rate change Speed 4 (cpu-used=4): CTC (65 frames, class A1 and A2, RA), no BD-rate change Speed 6 (cpu-used=6): CTC (65 frames, class A1 and A2, RA), no BD-rate change ``` 1) Speed 0 (cpu-used=0) +-----+------------+------+------+------+------+------+---------+------+----------+------+------+ | Cfg | Class | Y | Cb | Cr | wAvg | SSIM | MS-SSIM | VMAF | VMAF-neg | Enc% | Dec% | +-----+------------+------+------+------+------+------+---------+------+----------+------+------+ | AI | A1 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 100 | 97 | | | A2 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 101 | 98 | | | A3 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 100 | 100 | | | A4 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 100 | 99 | | | A5 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 101 | 101 | | | B1 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 101 | 99 | | | B2 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 101 | 98 | | | Avg w/o B2 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 101 | 98 | +-----+------------+------+------+------+------+------+---------+------+----------+------+------+ | RA | A1 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 100 | 98 | | | A2 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 100 | 98 | | | A3 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 100 | 100 | | | A4 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 100 | 100 | | | A5 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 100 | 100 | | | B1 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 100 | 98 | | | B2 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 100 | 99 | | | Avg w/o B2 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 100 | 99 | +-----+------------+------+------+------+------+------+---------+------+----------+------+------+ | LD | A2 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 100 | 98 | | | A3 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 100 | 100 | | | A4 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 100 | 100 | | | A5 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 100 | 101 | | | B1 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 100 | 98 | | | B2 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 101 | 100 | | | Avg w/o B2 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 100 | 99 | +-----+------------+------+------+------+------+------+---------+------+----------+------+------+ 2) Speed 2 (cpu-used=2) +-------+------+------+------+------+------+------+ | Class | Y | Cb | Cr | wAvg | Enc% | Dec% | +-------+------+------+------+------+------+------+ | A1 | 0.00 | 0.00 | 0.00 | 0.00 | 99 | 99 | | A2 | 0.00 | 0.00 | 0.00 | 0.00 | 100 | 100 | +-------+------+------+------+------+------+------+ 3) Speed 4 (cpu-used=4) +-------+------+------+------+------+------+------+ | Class | Y | Cb | Cr | wAvg | Enc% | Dec% | +-------+------+------+------+------+------+------+ | A1 | 0.00 | 0.00 | 0.00 | 0.00 | 99 | 100 | | A2 | 0.00 | 0.00 | 0.00 | 0.00 | 99 | 100 | +-------+------+------+------+------+------+------+ 4) Speed 6 (cpu-used=6) +-------+------+------+------+------+------+------+ | Class | Y | Cb | Cr | wAvg | Enc% | Dec% | +-------+------+------+------+------+------+------+ | A1 | 0.00 | 0.00 | 0.00 | 0.00 | 98 | 99 | | A2 | 0.00 | 0.00 | 0.00 | 0.00 | 99 | 100 | +-------+------+------+------+------+------+------+ ```
The Wiener stats, the RD search over RU-tiles and the frame filter fitting now run on the encoder workers. Filtering uses a per-thread copy of each stripe, so the frame is only read, and each job writes only its own RUs, so the output does not change. The new speed feature enable_lr_mt turns this off with one thread or with BRU. Anchor: commit 9c72cb5 Test: this commit plus the previous commit Speed 0 (cpu-used=0): CTC (33 frames, AI, RA and LD), no BD-rate change Speed 2 (cpu-used=2): CTC (65 frames, class A1 and A2, RA), no BD-rate change Speed 4 (cpu-used=4): CTC (65 frames, class A1 and A2, RA), no BD-rate change Speed 6 (cpu-used=6): CTC (65 frames, class A1 and A2, RA), no BD-rate change ``` 1) Speed 0 (cpu-used=0) +-----+------------+------+------+------+------+------+---------+------+----------+------+------+ | Cfg | Class | Y | Cb | Cr | wAvg | SSIM | MS-SSIM | VMAF | VMAF-neg | Enc% | Dec% | +-----+------------+------+------+------+------+------+---------+------+----------+------+------+ | AI | A1 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 96 | 98 | | | A2 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 100 | 98 | | | A3 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 100 | 99 | | | A4 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 100 | 99 | | | A5 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 100 | 100 | | | B1 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 100 | 98 | | | B2 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 101 | 99 | | | Avg w/o B2 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 99 | 98 | +-----+------------+------+------+------+------+------+---------+------+----------+------+------+ | RA | A1 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 97 | 98 | | | A2 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 99 | 99 | | | A3 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 100 | 99 | | | A4 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 100 | 99 | | | A5 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 100 | 101 | | | B1 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 99 | 99 | | | B2 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 100 | 99 | | | Avg w/o B2 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 99 | 99 | +-----+------------+------+------+------+------+------+---------+------+----------+------+------+ | LD | A2 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 98 | 99 | | | A3 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 100 | 101 | | | A4 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 100 | 101 | | | A5 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 100 | 100 | | | B1 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 99 | 99 | | | B2 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 100 | 99 | | | Avg w/o B2 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 99 | 100 | +-----+------------+------+------+------+------+------+---------+------+----------+------+------+ 2) Speed 2 (cpu-used=2) +-------+------+------+------+------+------+------+ | Class | Y | Cb | Cr | wAvg | Enc% | Dec% | +-------+------+------+------+------+------+------+ | A1 | 0.00 | 0.00 | 0.00 | 0.00 | 94 | 99 | | A2 | 0.00 | 0.00 | 0.00 | 0.00 | 99 | 99 | +-------+------+------+------+------+------+------+ 3) Speed 4 (cpu-used=4) +-------+------+------+------+------+------+------+ | Class | Y | Cb | Cr | wAvg | Enc% | Dec% | +-------+------+------+------+------+------+------+ | A1 | 0.00 | 0.00 | 0.00 | 0.00 | 93 | 99 | | A2 | 0.00 | 0.00 | 0.00 | 0.00 | 98 | 99 | +-------+------+------+------+------+------+------+ 4) Speed 6 (cpu-used=6), EncTime%/DecTime% are wall clock +-------+------+------+------+------+----------+----------+ | Class | Y | Cb | Cr | wAvg | EncTime% | DecTime% | +-------+------+------+------+------+----------+----------+ | A1 | 0.00 | 0.00 | 0.00 | 0.00 | 88 | 99 | | A2 | 0.00 | 0.00 | 0.00 | 0.00 | 96 | 100 | +-------+------+------+------+------+----------+----------+ ```
The Wiener stats now gather the features of up to 64 pixels per class and add their products with the new RTCD function av2_wienerns_stats_batch() (C, SSE4.1 and AVX2), summing in int64_t instead of double. The sums are exact, so the output does not change. This replaces av2_accumulate_wienerns_correlation(). Anchor: commit 9c72cb5 Test: this commit plus the previous two commits Speed 0 (cpu-used=0): CTC (33 frames, AI, RA and LD), no BD-rate change Speed 2 (cpu-used=2): CTC (65 frames, class A1 and A2, RA), no BD-rate change Speed 4 (cpu-used=4): CTC (65 frames, class A1 and A2, RA), no BD-rate change Speed 6 (cpu-used=6): CTC (65 frames, class A1 and A2, RA), no BD-rate change ``` 1) Speed 0 (cpu-used=0) +-----+------------+------+------+------+------+------+---------+------+----------+------+------+ | Cfg | Class | Y | Cb | Cr | wAvg | SSIM | MS-SSIM | VMAF | VMAF-neg | Enc% | Dec% | +-----+------------+------+------+------+------+------+---------+------+----------+------+------+ | AI | A1 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 97 | 98 | | | A2 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 100 | 98 | | | A3 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 101 | 100 | | | A4 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 100 | 100 | | | A5 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 101 | 99 | | | B1 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 100 | 98 | | | B2 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 101 | 101 | | | Avg w/o B2 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 100 | 99 | +-----+------------+------+------+------+------+------+---------+------+----------+------+------+ | RA | A1 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 96 | 98 | | | A2 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 99 | 99 | | | A3 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 100 | 100 | | | A4 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 100 | 101 | | | A5 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 100 | 99 | | | B1 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 100 | 98 | | | B2 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 100 | 100 | | | Avg w/o B2 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 99 | 99 | +-----+------------+------+------+------+------+------+---------+------+----------+------+------+ | LD | A2 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 99 | 99 | | | A3 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 100 | 100 | | | A4 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 100 | 102 | | | A5 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 100 | 100 | | | B1 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 99 | 99 | | | B2 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 100 | 100 | | | Avg w/o B2 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 99 | 99 | +-----+------------+------+------+------+------+------+---------+------+----------+------+------+ 2) Speed 2 (cpu-used=2) +-------+------+------+------+------+------+------+ | Class | Y | Cb | Cr | wAvg | Enc% | Dec% | +-------+------+------+------+------+------+------+ | A1 | 0.00 | 0.00 | 0.00 | 0.00 | 93 | 99 | | A2 | 0.00 | 0.00 | 0.00 | 0.00 | 98 | 98 | +-------+------+------+------+------+------+------+ 3) Speed 4 (cpu-used=4) +-------+------+------+------+------+------+------+ | Class | Y | Cb | Cr | wAvg | Enc% | Dec% | +-------+------+------+------+------+------+------+ | A1 | 0.00 | 0.00 | 0.00 | 0.00 | 91 | 99 | | A2 | 0.00 | 0.00 | 0.00 | 0.00 | 97 | 100 | +-------+------+------+------+------+------+------+ 4) Speed 6 (cpu-used=6) +-------+------+------+------+------+------+------+ | Class | Y | Cb | Cr | wAvg | Enc% | Dec% | +-------+------+------+------+------+------+------+ | A1 | 0.00 | 0.00 | 0.00 | 0.00 | 85 | 99 | | A2 | 0.00 | 0.00 | 0.00 | 0.00 | 94 | 99 | +-------+------+------+------+------+------+------+ ```
62b9296 to
986f679
Compare
Thanks @urvangjoshi. Done. |

Speed up the GDF and LR encoder searches without changing the output
These three commits speed up two encoder loop filter steps, GDF and LR,
without changing the encoded output.
These tests show two things:
The speedup grows with resolution. GDF and LR used to run in order
over the whole frame, so their time grows with frame size. Running
them in parallel saves more time on large frames, with no change in
output.
The speedup grows as the rest of the encoder gets faster. If mode
decision (prediction, transform, quantization) gets faster, for
example because it gets more threads, GDF and LR take a larger share
of the total time. Running them in parallel then saves a larger
share of it.
Anchor: commit 9c72cb5
Test: this commit plus the previous two commits 946af69 and a21ea29
Speed 0 (cpu-used=0): CTC (33 frames, AI, RA and LD), no BD-rate change
Speed 2 (cpu-used=2): CTC (65 frames, class A1 and A2, RA), no BD-rate change
Speed 4 (cpu-used=4): CTC (65 frames, class A1 and A2, RA), no BD-rate change
Speed 6 (cpu-used=6): CTC (65 frames, class A1 and A2, RA), no BD-rate change