Skip to content

Multithread the CDEF and CCSO filters and the CDEF search - #5603

Open
YixinDu1 wants to merge 1 commit into
AOMediaCodec:av2-encfrom
YixinDu1:yixin/1014_cdef_search_mt_aom
Open

YixinDu1 wants to merge 1 commit into
AOMediaCodec:av2-encfrom
YixinDu1:yixin/1014_cdef_search_mt_aom

Conversation

@YixinDu1

Copy link
Copy Markdown
Contributor

Run the CDEF strength search and the CDEF and CCSO filtering on the encoder worker threads. Worker 0 now gets a thread, so the existing loop filter and loop restoration multithreading also runs on it. The enable_cdef_mt and enable_ccso_mt speed features, on by default, turn the threading off.

Anchor: commit b38429d
CTC: AV2 CTC v8 (33 frames, RA)

Speed 0 (cpu-used=0)
  +--------------+-------+-------+-------+-------+-------+--------+
  | Class        |     Y |    Cb |    Cr |  wAvg |  Enc% |  Ratio |
  +--------------+-------+-------+-------+-------+-------+--------+
  | A1           |  0.00 |  0.00 |  0.00 |  0.00 |  99.9 |    N/A |
  | A2           |  0.00 |  0.00 |  0.00 |  0.00 |  99.9 |    N/A |
  | Avg w/o B2   |  0.00 |  0.00 |  0.00 |  0.00 | 100.0 |    N/A |
  +--------------+-------+-------+-------+-------+-------+--------+

Speed 1 (cpu-used=1)
  +--------------+-------+-------+-------+-------+-------+--------+
  | Class        |     Y |    Cb |    Cr |  wAvg |  Enc% |  Ratio |
  +--------------+-------+-------+-------+-------+-------+--------+
  | A1           |  0.00 |  0.00 |  0.00 |  0.00 | 100.0 |    N/A |
  | A2           |  0.00 |  0.00 |  0.00 |  0.00 |  99.8 |    N/A |
  | Avg w/o B2   |  0.00 |  0.00 |  0.00 |  0.00 | 100.0 |    N/A |
  +--------------+-------+-------+-------+-------+-------+--------+

Speed 2 (cpu-used=2)
  +--------------+-------+-------+-------+-------+-------+--------+
  | Class        |     Y |    Cb |    Cr |  wAvg |  Enc% |  Ratio |
  +--------------+-------+-------+-------+-------+-------+--------+
  | A1           |  0.00 |  0.00 |  0.00 |  0.00 |  98.7 |    N/A |
  | A2           |  0.00 |  0.00 |  0.00 |  0.00 |  99.6 |    N/A |
  | Avg w/o B2   |  0.00 |  0.00 |  0.00 |  0.00 |  99.8 |    N/A |
  +--------------+-------+-------+-------+-------+-------+--------+

Speed 3 (cpu-used=3)
  +--------------+-------+-------+-------+-------+-------+--------+
  | Class        |     Y |    Cb |    Cr |  wAvg |  Enc% |  Ratio |
  +--------------+-------+-------+-------+-------+-------+--------+
  | A1           |  0.00 |  0.00 |  0.00 |  0.00 |  98.9 |    N/A |
  | A2           |  0.00 |  0.00 |  0.00 |  0.00 |  99.4 |    N/A |
  | Avg w/o B2   |  0.00 |  0.00 |  0.00 |  0.00 |  99.7 |    N/A |
  +--------------+-------+-------+-------+-------+-------+--------+

Speed 4 (cpu-used=4)
  +--------------+-------+-------+-------+-------+-------+--------+
  | Class        |     Y |    Cb |    Cr |  wAvg |  Enc% |  Ratio |
  +--------------+-------+-------+-------+-------+-------+--------+
  | A1           |  0.00 |  0.00 |  0.00 |  0.00 |  98.9 |    N/A |
  | A2           |  0.00 |  0.00 |  0.00 |  0.00 |  99.1 |    N/A |
  | Avg w/o B2   |  0.00 |  0.00 |  0.00 |  0.00 |  99.5 |    N/A |
  +--------------+-------+-------+-------+-------+-------+--------+

Speed 5 (cpu-used=5)
  +--------------+-------+-------+-------+-------+-------+--------+
  | Class        |     Y |    Cb |    Cr |  wAvg |  Enc% |  Ratio |
  +--------------+-------+-------+-------+-------+-------+--------+
  | A1           |  0.00 |  0.00 |  0.00 |  0.00 |  98.3 |    N/A |
  | A2           |  0.00 |  0.00 |  0.00 |  0.00 |  99.2 |    N/A |
  | Avg w/o B2   |  0.00 |  0.00 |  0.00 |  0.00 |  99.2 |    N/A |
  +--------------+-------+-------+-------+-------+-------+--------+

Speed 6 (cpu-used=6)
  +--------------+-------+-------+-------+-------+-------+--------+
  | Class        |     Y |    Cb |    Cr |  wAvg |  Enc% |  Ratio |
  +--------------+-------+-------+-------+-------+-------+--------+
  | A1           |  0.00 |  0.00 |  0.00 |  0.00 |  97.9 |    N/A |
  | A2           |  0.00 |  0.00 |  0.00 |  0.00 |  99.4 |    N/A |
  | Avg w/o B2   |  0.00 |  0.00 |  0.00 |  0.00 |  99.4 |    N/A |
  +--------------+-------+-------+-------+-------+-------+--------+

Speed 6 (cpu-used=6), threads=8, row-mt=1, A1 and A2 only
  +--------------+-------+-------+-------+-------+-------+--------+
  | Class        |     Y |    Cb |    Cr |  wAvg |  Enc% |  Ratio |
  +--------------+-------+-------+-------+-------+-------+--------+
  | A1           |  0.00 |  0.00 |  0.00 |  0.00 |  97.9 |    N/A |
  | A2           |  0.00 |  0.00 |  0.00 |  0.00 |  98.3 |    N/A |
  +--------------+-------+-------+-------+-------+-------+--------+

@YixinDu1
YixinDu1 marked this pull request as ready for review October 21, 2026 21:34
// Run the CDEF strength search and the CDEF filtering on the encoder worker
// threads when there are several. The output is the same with or without it.
// 0: single thread.
int enable_cdef_mt;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest to remove the speed features here. MT functions should be called whenever there are > 1 threads available. Please refer to existing MT implementation.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Yunqing for the comment.

Hi @yeqing-wu, what do you think about this?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yunqingwang1, We may need to re-evaluate all MT implementations. As more components get multithreaded and the single-threaded baseline keeps getting faster, the fixed cost of MT (job dispatch, thread synchronization/barriers, per-thread data setup and merging, load imbalance, cache contention) becomes a larger share of the runtime. For lightweight stages, that overhead can cancel out the gain or even make things slower. A per-component switch lets us A/B each MT path in the future to test their performance, if they cannot help, we can remove the MT code of that component to simplify the code. What do you think?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once av2-enc is finalized or stable enough, we can re-evaluate every MT implementation. And then remove the control flags when MT can help. MT paths that don't help will be removed entirely.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I understand now - thanks for the explanation. That is fine for testing. I am ok with these 2 options: 1. keep these flags in a separate struct instead of LOOP_FILTER_SPEED_FEATURES; 2. If you prefer to add them in LOOP_FILTER_SPEED_FEATURES, please add comment to explain why they are needed and when they will be removed. Would this be ok?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I'll go with option 2: the flags stay in LOOP_FILTER_SPEED_FEATURES with a comment explaining that they exist for A/B testing and will be removed once av2-enc is stable and the MT paths are re-evaluated.

@yunqingwang1

Copy link
Copy Markdown
Contributor

@YixinDu1 Thank you for adding MT support in this area. Do you see how much time CDEF + CCSO take in the encoder now, and is the achieved encoder speedup with A1 (4 threads)/A2 (2 threads) good enough (i.e. in line with the expectation)?

@YixinDu1

Copy link
Copy Markdown
Contributor Author

@YixinDu1 Thank you for adding MT support in this area. Do you see how much time CDEF + CCSO take in the encoder now, and is the achieved encoder speedup with A1 (4 threads)/A2 (2 threads) good enough (i.e. in line with the expectation)?

Let me run a quick tool off test for CDEF/CCSO to provide more context.

@YixinDu1

Copy link
Copy Markdown
Contributor Author

@YixinDu1 Thank you for adding MT support in this area. Do you see how much time CDEF + CCSO take in the encoder now, and is the achieved encoder speedup with A1 (4 threads)/A2 (2 threads) good enough (i.e. in line with the expectation)?

Hi @yunqingwang1, here are the tool off results compared with our patch savings:

image

The patch recovers about 38% of the CDEF + CCSO time on A1 (2.1 of 5.5) and about 25% on A2 (0.6 of 2.4).

@YixinDu1
YixinDu1 force-pushed the yixin/1014_cdef_search_mt_aom branch 2 times, most recently from 58f5335 to 40eb4df Compare October 22, 2026 16:37
@yeqing-wu

Copy link
Copy Markdown
Contributor

Same for this PR

Run the CDEF strength search and the CDEF and CCSO filtering on the
encoder worker threads. Worker 0 now gets a thread, so the existing loop
filter and loop restoration multithreading also runs on it. The
enable_cdef_mt and enable_ccso_mt speed features, on by default, turn the
threading off.

Anchor: commit b38429d
CTC: AV2 CTC v8 (33 frames, RA)

```
Speed 0 (cpu-used=0)
  +--------------+-------+-------+-------+-------+-------+--------+
  | Class        |     Y |    Cb |    Cr |  wAvg |  Enc% |  Ratio |
  +--------------+-------+-------+-------+-------+-------+--------+
  | A1           |  0.00 |  0.00 |  0.00 |  0.00 |  99.9 |    N/A |
  | A2           |  0.00 |  0.00 |  0.00 |  0.00 |  99.9 |    N/A |
  | Avg w/o B2   |  0.00 |  0.00 |  0.00 |  0.00 | 100.0 |    N/A |
  +--------------+-------+-------+-------+-------+-------+--------+

Speed 1 (cpu-used=1)
  +--------------+-------+-------+-------+-------+-------+--------+
  | Class        |     Y |    Cb |    Cr |  wAvg |  Enc% |  Ratio |
  +--------------+-------+-------+-------+-------+-------+--------+
  | A1           |  0.00 |  0.00 |  0.00 |  0.00 | 100.0 |    N/A |
  | A2           |  0.00 |  0.00 |  0.00 |  0.00 |  99.8 |    N/A |
  | Avg w/o B2   |  0.00 |  0.00 |  0.00 |  0.00 | 100.0 |    N/A |
  +--------------+-------+-------+-------+-------+-------+--------+

Speed 2 (cpu-used=2)
  +--------------+-------+-------+-------+-------+-------+--------+
  | Class        |     Y |    Cb |    Cr |  wAvg |  Enc% |  Ratio |
  +--------------+-------+-------+-------+-------+-------+--------+
  | A1           |  0.00 |  0.00 |  0.00 |  0.00 |  98.7 |    N/A |
  | A2           |  0.00 |  0.00 |  0.00 |  0.00 |  99.6 |    N/A |
  | Avg w/o B2   |  0.00 |  0.00 |  0.00 |  0.00 |  99.8 |    N/A |
  +--------------+-------+-------+-------+-------+-------+--------+

Speed 3 (cpu-used=3)
  +--------------+-------+-------+-------+-------+-------+--------+
  | Class        |     Y |    Cb |    Cr |  wAvg |  Enc% |  Ratio |
  +--------------+-------+-------+-------+-------+-------+--------+
  | A1           |  0.00 |  0.00 |  0.00 |  0.00 |  98.9 |    N/A |
  | A2           |  0.00 |  0.00 |  0.00 |  0.00 |  99.4 |    N/A |
  | Avg w/o B2   |  0.00 |  0.00 |  0.00 |  0.00 |  99.7 |    N/A |
  +--------------+-------+-------+-------+-------+-------+--------+

Speed 4 (cpu-used=4)
  +--------------+-------+-------+-------+-------+-------+--------+
  | Class        |     Y |    Cb |    Cr |  wAvg |  Enc% |  Ratio |
  +--------------+-------+-------+-------+-------+-------+--------+
  | A1           |  0.00 |  0.00 |  0.00 |  0.00 |  98.9 |    N/A |
  | A2           |  0.00 |  0.00 |  0.00 |  0.00 |  99.1 |    N/A |
  | Avg w/o B2   |  0.00 |  0.00 |  0.00 |  0.00 |  99.5 |    N/A |
  +--------------+-------+-------+-------+-------+-------+--------+

Speed 5 (cpu-used=5)
  +--------------+-------+-------+-------+-------+-------+--------+
  | Class        |     Y |    Cb |    Cr |  wAvg |  Enc% |  Ratio |
  +--------------+-------+-------+-------+-------+-------+--------+
  | A1           |  0.00 |  0.00 |  0.00 |  0.00 |  98.3 |    N/A |
  | A2           |  0.00 |  0.00 |  0.00 |  0.00 |  99.2 |    N/A |
  | Avg w/o B2   |  0.00 |  0.00 |  0.00 |  0.00 |  99.2 |    N/A |
  +--------------+-------+-------+-------+-------+-------+--------+

Speed 6 (cpu-used=6)
  +--------------+-------+-------+-------+-------+-------+--------+
  | Class        |     Y |    Cb |    Cr |  wAvg |  Enc% |  Ratio |
  +--------------+-------+-------+-------+-------+-------+--------+
  | A1           |  0.00 |  0.00 |  0.00 |  0.00 |  97.9 |    N/A |
  | A2           |  0.00 |  0.00 |  0.00 |  0.00 |  99.4 |    N/A |
  | Avg w/o B2   |  0.00 |  0.00 |  0.00 |  0.00 |  99.4 |    N/A |
  +--------------+-------+-------+-------+-------+-------+--------+

Speed 6 (cpu-used=6), threads=8, row-mt=1, A1 and A2 only
  +--------------+-------+-------+-------+-------+-------+--------+
  | Class        |     Y |    Cb |    Cr |  wAvg |  Enc% |  Ratio |
  +--------------+-------+-------+-------+-------+-------+--------+
  | A1           |  0.00 |  0.00 |  0.00 |  0.00 |  97.9 |    N/A |
  | A2           |  0.00 |  0.00 |  0.00 |  0.00 |  98.3 |    N/A |
  +--------------+-------+-------+-------+-------+-------+--------+
```
@YixinDu1
YixinDu1 force-pushed the yixin/1014_cdef_search_mt_aom branch from 40eb4df to 76bd8ce Compare October 23, 2026 21:48
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.

4 participants