Skip to content

Add SIMD optimization and speed up nonsep Wiener - #5362

Merged
urvangjoshi merged 1 commit into
AOMediaCodec:av2-encfrom
kslu-aom:av2enc-wns3
Sep 4, 2026
Merged

Add SIMD optimization and speed up nonsep Wiener#5362
urvangjoshi merged 1 commit into
AOMediaCodec:av2-encfrom
kslu-aom:av2enc-wns3

Conversation

@kslu-aom

@kslu-aom kslu-aom commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

This patch accelerates the nonseparable Wiener restoration search through search pruning at speed >= 1 and SIMD optimizations for the autocovariance matrix accumulation:

  1. Search Pruning for speed >= 1: Extend speed features reduce_lr_unit_size_by_pyr and reduce_lr_unit_size_by_pyr_drop_low from speed >=4 to speed >= 1 to prune RU unit-size evaluations based on pyramid level (drops the largest RU size for pyr_level >= 3, and the smallest RU size for pyr_level >= 5). Add a speed feature wienerns_fast_frame_filter_opt for speed >= 1 to prune frame-level filter search iterations during optimal class and filter determination.

  2. SIMD Vectorization: Add SSE4.1 and AVX2 implementations to accelerate autocovariance matrix and cross-correlation vector accumulation in WienerNS filter stats collection. Unit tests have been added to verify numerical equivalence between SIMD (SSE4.1, AVX2) and reference C implementations. This change is applied to all speed levels, and is bit-exact. Encoder instruction count savings on A3-A5 with 17 frames:
    0.11% at speed 0
    0.26% at speed 1
    0.95% at speed 2

STATS_CHANGED for speed >= 1

Results with the above changes combined, evaluated on 2128e7e with 33 frames:

    1) Speed 1
      +------------+-------+-------+-------+-------+-------+-------+
      | Class      |     Y |    Cb |    Cr |  wAvg |  Enc% |  Dec% |
      +------------+-------+-------+-------+-------+-------+-------+
      | A1         | +0.03 | +0.12 | +0.19 | +0.04 |  93.4 |  97.9 |
      | A2         | +0.06 | -0.12 | -0.22 | +0.04 |  96.8 |  99.3 |
      +------------+-------+-------+-------+-------+-------+-------+
    
    2) Speed 2
      +------------+-------+-------+-------+-------+-------+-------+
      | Class      |     Y |    Cb |    Cr |  wAvg |  Enc% |  Dec% |
      +------------+-------+-------+-------+-------+-------+-------+
      | A1         | -0.01 | -0.16 | +0.21 | -0.01 |  88.6 | 100.6 |
      | A2         | +0.08 | +0.03 | -0.14 | +0.08 |  93.2 | 102.1 |
      +------------+-------+-------+-------+-------+-------+-------+
    
    3) Speed 3
      +------------+-------+-------+-------+-------+-------+-------+
      | Class      |     Y |    Cb |    Cr |  wAvg |  Enc% |  Dec% |
      +------------+-------+-------+-------+-------+-------+-------+
      | A1         | +0.07 | +0.11 | -0.13 | +0.06 |  86.9 | 101.2 |
      | A2         | +0.01 | -0.01 | -0.05 | +0.00 |  94.8 | 101.4 |
      +------------+-------+-------+-------+-------+-------+-------+

    4) Speed 4
      +------------+-------+-------+-------+-------+-------+-------+
      | Class      |     Y |    Cb |    Cr |  wAvg |  Enc% |  Dec% |
      +------------+-------+-------+-------+-------+-------+-------+
      | A1         | -0.07 | -0.07 | +0.01 | -0.06 |  92.9 | 101.8 |
      | A2         | -0.00 | -0.07 | -0.13 | -0.00 |  97.2 | 102.2 |
      +------------+-------+-------+-------+-------+-------+-------+

@kslu-aom kslu-aom changed the title Ad SIMD optimization and speed up nonsep Wiener Add SIMD optimization and speed up nonsep Wiener Sep 2, 2026
@urvangjoshi

urvangjoshi commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

@kslu-aom : FYI, I have intentionally cancelled CI pipeline, so runners are free to run on the rebase PR: #5364

We can run CI on this one later.

@urvangjoshi

Copy link
Copy Markdown
Contributor

@kslu-aom : pls rebase.

@yeqing-wu

Copy link
Copy Markdown
Contributor

@jjustiss-apple, since you’re the expert in SIMD, could you please help review the code?

@jjustiss-apple

Copy link
Copy Markdown
Contributor

There looks to be a good amount of room to improve the SIMD code here, e.g. switching to integer accumulators, use of FMA3 madd instructions in the matrix and vector inner loops, plus a few other optimization opportunities. libaom av1 is a good reference.

Are we looking for optimal SIMD code in this PR or just focus on the algorithm changes?

@urvangjoshi

Copy link
Copy Markdown
Contributor

There looks to be a good amount of room to improve the SIMD code here, e.g. switching to integer accumulators, use of FMA3 madd instructions in the matrix and vector inner loops, plus a few other optimization opportunities. libaom av1 is a good reference.

Are we looking for optimal SIMD code in this PR or just focus on the algorithm changes?

I'd suggest merging this PR first and making further improvements to SIMD in later PRs, given the significant speed-up from this PR.

Of course, if there are any concrete suggestions to improve SIMD right here, those could be addressed in this PR as well.

What do you think @yeqing-wu @yunqingwang1 @leolzhao ?

@yeqing-wu

Copy link
Copy Markdown
Contributor

There looks to be a good amount of room to improve the SIMD code here, e.g. switching to integer accumulators, use of FMA3 madd instructions in the matrix and vector inner loops, plus a few other optimization opportunities. libaom av1 is a good reference.
Are we looking for optimal SIMD code in this PR or just focus on the algorithm changes?

I'd suggest merging this PR first and making further improvements to SIMD in later PRs, given the significant speed-up from this PR.

Of course, if there are any concrete suggestions to improve SIMD right here, those could be addressed in this PR as well.

What do you think @yeqing-wu @yunqingwang1 @leolzhao ?

@jjustiss-apple, what are your thoughts on this? If we decide to merge this PR, it would be beneficial to create a ticket to track it. This way, we won’t forget to optimize it later. SIMD part in this PR is lossless optimization, so we should maximize the available space.

@yunqingwang1

Copy link
Copy Markdown
Contributor

There looks to be a good amount of room to improve the SIMD code here, e.g. switching to integer accumulators, use of FMA3 madd instructions in the matrix and vector inner loops, plus a few other optimization opportunities. libaom av1 is a good reference.
Are we looking for optimal SIMD code in this PR or just focus on the algorithm changes?

I'd suggest merging this PR first and making further improvements to SIMD in later PRs, given the significant speed-up from this PR.
Of course, if there are any concrete suggestions to improve SIMD right here, those could be addressed in this PR as well.
What do you think @yeqing-wu @yunqingwang1 @leolzhao ?

@jjustiss-apple, what are your thoughts on this? If we decide to merge this PR, it would be beneficial to create a ticket to track it. This way, we won’t forget to optimize it later. SIMD part in this PR is lossless optimization, so we should maximize the available space.

I am fine with merging this PR and further improving SIMD in a separate PR. Thanks.

@kslu-aom

kslu-aom commented Sep 3, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the suggestions. I can give it a try to improve the SIMD here later if no one else has plans on doing it.

…lation

Implement algorithmic search pruning methods and SIMD optimizations for
nonseparable wiener restoration:
- Add SIMD (AVX2, SSE4.1) RTCD dispatch for wienerns correlation matrix
  accumulation (av2_accumulate_wienerns_correlation)
- Add speed >= 1 algorithmic prunings guarded by configurable macros:
  - prune RU search sizes based on pyramid level
  - single iteration for frame filter optimization
@urvangjoshi
urvangjoshi merged commit 903c7d5 into AOMediaCodec:av2-enc Sep 4, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants