Allintra: Allocate 'tmp_pred_bufs[]' conditionally
The buffers 'tmp_pred_bufs[]' are used to hold temporary prediction
results in handle_inter_mode() and in case of OBMC prediction.
Hence, the memory allocation for the same is made conditional by
avoiding it for allintra encoding mode.
For AVIF image encode with speed = 6,
HEAP Memory reduction(%)
Resolution threads=1 threads=4
640x360 1.28 3.03
768x512 0.79 1.46
832x480 0.81 2.33
1280x720 0.44 1.33
HEAP memory reduction was measured using the following command.
$valgrind --tool=massif ./avifenc ...
Change-Id: I043271551a0727927f0b5dadd9cf6574969c4bf0
diff --git a/av1/encoder/encoder.c b/av1/encoder/encoder.c
index d77d50b..51feb0c 100644
--- a/av1/encoder/encoder.c
+++ b/av1/encoder/encoder.c
@@ -760,12 +760,17 @@
aom_memalign(32, MAX_SB_SIZE * MAX_SB_SIZE * sizeof(*x->tmp_conv_dst)));
x->e_mbd.tmp_conv_dst = x->tmp_conv_dst;
}
- for (int i = 0; i < 2; ++i) {
- if (x->tmp_pred_bufs[i] == NULL) {
- CHECK_MEM_ERROR(cm, x->tmp_pred_bufs[i],
- aom_memalign(32, 2 * MAX_MB_PLANE * MAX_SB_SQUARE *
- sizeof(*x->tmp_pred_bufs[i])));
- x->e_mbd.tmp_obmc_bufs[i] = x->tmp_pred_bufs[i];
+ // The buffers 'tmp_pred_bufs[]' are used in inter frames to store temporary
+ // prediction results. Hence, the memory allocation is avoided for allintra
+ // encode.
+ if (cpi->oxcf.kf_cfg.key_freq_max != 0) {
+ for (int i = 0; i < 2; ++i) {
+ if (x->tmp_pred_bufs[i] == NULL) {
+ CHECK_MEM_ERROR(cm, x->tmp_pred_bufs[i],
+ aom_memalign(32, 2 * MAX_MB_PLANE * MAX_SB_SQUARE *
+ sizeof(*x->tmp_pred_bufs[i])));
+ x->e_mbd.tmp_obmc_bufs[i] = x->tmp_pred_bufs[i];
+ }
}
}
diff --git a/av1/encoder/ethread.c b/av1/encoder/ethread.c
index c7a07d2..b6e2c2b 100644
--- a/av1/encoder/ethread.c
+++ b/av1/encoder/ethread.c
@@ -742,11 +742,17 @@
alloc_compound_type_rd_buffers(&ppi->error,
&thread_data->td->comp_rd_buffer);
- for (int j = 0; j < 2; ++j) {
- AOM_CHECK_MEM_ERROR(
- &ppi->error, thread_data->td->tmp_pred_bufs[j],
- aom_memalign(32, 2 * MAX_MB_PLANE * MAX_SB_SQUARE *
- sizeof(*thread_data->td->tmp_pred_bufs[j])));
+ // The buffers 'tmp_pred_bufs[]' are used in inter frames to store
+ // temporary prediction results. Hence, the memory allocation is avoided
+ // for allintra encode.
+ if (ppi->cpi->oxcf.kf_cfg.key_freq_max != 0) {
+ for (int j = 0; j < 2; ++j) {
+ AOM_CHECK_MEM_ERROR(
+ &ppi->error, thread_data->td->tmp_pred_bufs[j],
+ aom_memalign(32,
+ 2 * MAX_MB_PLANE * MAX_SB_SQUARE *
+ sizeof(*thread_data->td->tmp_pred_bufs[j])));
+ }
}
const SPEED_FEATURES *sf = &ppi->cpi->sf;