Refactor handle_inter_mode and separate single and compound mode searches - #5239
Refactor handle_inter_mode and separate single and compound mode searches#5239kslu-aom wants to merge 6 commits into
Conversation
Combine ref_mv_id_1 and ref_mv_id_0 loops into a single flat_idx loop in handle_inter_mode. TAG=agy CONV=f3d7c114-6aba-4bcd-85bc-35cff99055d5
|
Please review this large scale refactoring and let me know. I can do another iteration based on the comments and suggestions, and mark it as ready once I have rebased it with new test results. |
|
Thanks Lester for helping refactor the code. I’ll review it today. With so many internal and external code reviews, I still prefer that we review the code carefully to identify issues as early as possible. |
|
@kslu-aom Thanks for the refactoring. Regarding "The double search loops for compound DRL and for BAWP are flattened as one single loop", separating single and compound mode search is needed to achieve this loop flattening? |
No, it is a separate cleanup with the intention to reduce the nesting. |
|
Looks good - thanks. |
yeqing-wu
left a comment
There was a problem hiding this comment.
Thanks Lester. Hare are my comments.
| for (i = 0; i < is_comp_pred + 1; ++i) { | ||
| bawp_off_mv[i].as_int = cur_mv[i].as_int; | ||
| } | ||
| set_precision_set(cm, xd, mbmi, bsize, 0); |
There was a problem hiding this comment.
We do not need ref_mv_idx inside set_precision_set(), thus please help clean it up so that it can avoid one input parameter
| mbmi->motion_mode = SIMPLE_TRANSLATION; | ||
| mbmi->ref_mv_idx[1] = ref_mv_idx[1]; | ||
| mbmi->ref_mv_idx[0] = ref_mv_idx[0]; | ||
| set_mv_precision(mbmi, mbmi->max_mv_precision); |
There was a problem hiding this comment.
With the code in 5248 (mbmi->pb_mv_precision = pb_mv_precision;), I think set_mv_precision() call cite is redundant
There was a problem hiding this comment.
Please check other places since inside set_mv_precision(), it only has one line code to assign the mv precision, which is similar as mbmi->pb_mv_precision = pb_mv_precision;
void set_mv_precision(MB_MODE_INFO *mbmi, MvSubpelPrecision precision) {
mbmi->pb_mv_precision = precision;
}
There was a problem hiding this comment.
I have removed a few of these.
| mbmi->ref_mv_idx[1] = 0; | ||
| mbmi->ref_mv_idx[0] = ref_mv_idx0; | ||
| int ref_mv_idx_type = av2_ref_mv_idx_type(mbmi, ref_mv_idx); | ||
| set_mv_precision(mbmi, mbmi->max_mv_precision); |
There was a problem hiding this comment.
With the code in 5248 (mbmi->pb_mv_precision = pb_mv_precision;), I think set_mv_precision() call cite is redundant
| int_mv bawp_off_mv[2]; | ||
| int64_t bawp_off_newmv_ret_val = 0; | ||
| int bawp_off_rate_mv = 0; | ||
| for (i = 0; i < is_comp_pred + 1; ++i) { |
There was a problem hiding this comment.
is_comp_pred is hardcoded to 0, thus I think we do not need this for loop. Meanwhile, as the function name indicates it is for single, I think we also do not need to is_comp_pred inside this function.
const int is_comp_pred = 0;
| if (mbmi->bawp_flag[0] >= 1) { | ||
| bawp_off_mv[1].as_int = -1; | ||
| assert(is_comp_pred == 0); | ||
| for (i = 0; i < is_comp_pred + 1; ++i) { |
| end_timing(cpi, handle_newmv_time); | ||
| #endif | ||
| bawp_off_rate_mv = rate_mv; | ||
| for (i = 0; i < is_comp_pred + 1; ++i) { |
| int prune_modes_based_on_tpl, int ref_match_found_in_above_nb, | ||
| int ref_match_found_in_left_nb, | ||
| PruneInfoFromTpl *inter_cost_info_from_tpl, int jmvd_scaling_factor_num, | ||
| PREDICTION_MODE best_ref_mode) { |
There was a problem hiding this comment.
In the future, we need to think about how to refactor the code to avoid enormous parameter lists. Not for this PR.
There was a problem hiding this comment.
Will try to clean up some parameters in the next iteration
| av2_zero(cwp_search_mask); | ||
|
|
||
| const int total_ref_mv_idx = ref_set[1] * ref_set[0]; | ||
| for (int flat_idx = 0; flat_idx < total_ref_mv_idx; ++flat_idx) { |
There was a problem hiding this comment.
5209–5390 (single) vs 5422–5609 (compound), has lots of duplicate near-identical code. We can refactor it later, but add a TODO so that we would not forget this
There was a problem hiding this comment.
Sounds good. I have added a TODO
| bawp_off_mv[i].as_int = cur_mv[i].as_int; | ||
| } | ||
|
|
||
| int bawp_eanbled = cm->features.enable_bawp && |
There was a problem hiding this comment.
typo, should be 'bawp_enabled'. Even it is from the existing code
|
|
||
| int rate_mv = 0; | ||
| int64_t newmv_ret_val = 0; | ||
| int i; |
There was a problem hiding this comment.
Loose int i; C-style declaration, Move to for (int i = 0; ...) at each use
Reduce the search loop nesting by using a helper function for single and another for compound. The order of nested loops has been changed, so that a common search loop for MV precision is moved to higher level and remains in handle_inter_mode, while the other loops are moved to the helper functions. The double search loops for compound DRL and for BAWP are flattened as one single loop. Some pruning logic of skip_newmv are refactored using an inline function.
There is an ongoing effort to further unnest the loops inside handle_compound_inter_prediction.
Evaluation based on aba7683 with 33 frames
Speed 0 (1 point remaining for each set)
Speed 1
STATS_CHANGED