Disable hog for realtime mode and remove memory allocation

Currently, realtime mode only searches DC mode, so hog based pruning is
not needed. This commit disables the hog speed feature and stops
allocating memory when the speed feature is disabled.

No significant memory nor speed change was observed.

Change-Id: I9129f02b2c5f1c94585e70f8afcf0f9b165cdc4f
diff --git a/av1/encoder/encoder.c b/av1/encoder/encoder.c
index 03b3961..f5105be 100644
--- a/av1/encoder/encoder.c
+++ b/av1/encoder/encoder.c
@@ -768,13 +768,6 @@
     }
   }
 
-  if (x->pixel_gradient_info == NULL) {
-    const int plane_types = PLANE_TYPES >> cm->seq_params->monochrome;
-    CHECK_MEM_ERROR(cm, x->pixel_gradient_info,
-                    aom_malloc(sizeof(*x->pixel_gradient_info) * plane_types *
-                               MAX_SB_SQUARE));
-  }
-
   av1_reset_segment_features(cm);
 
   av1_set_high_precision_mv(cpi, 1, 0);
@@ -2300,7 +2293,13 @@
     }
   }
 
-  if (cpi->sf.part_sf.partition_search_type == VAR_BASED_PARTITION)
+  const SPEED_FEATURES *sf = &cpi->sf;
+  if (sf->intra_sf.intra_pruning_with_hog ||
+      sf->intra_sf.chroma_intra_pruning_with_hog) {
+    allocate_gradient_info_for_hog(&cpi->td.pixel_gradient_info, cpi);
+  }
+
+  if (sf->part_sf.partition_search_type == VAR_BASED_PARTITION)
     variance_partition_alloc(cpi);
 
   if (cm->current_frame.frame_type == KEY_FRAME) copy_frame_prob_info(cpi);
@@ -2493,7 +2492,13 @@
   q_low = bottom_index;
   q_high = top_index;
 
-  if (cpi->sf.part_sf.partition_search_type == VAR_BASED_PARTITION)
+  const SPEED_FEATURES *sf = &cpi->sf;
+  if (sf->intra_sf.intra_pruning_with_hog ||
+      sf->intra_sf.chroma_intra_pruning_with_hog) {
+    allocate_gradient_info_for_hog(&cpi->td.pixel_gradient_info, cpi);
+  }
+
+  if (sf->part_sf.partition_search_type == VAR_BASED_PARTITION)
     variance_partition_alloc(cpi);
 
   if (cm->current_frame.frame_type == KEY_FRAME) copy_frame_prob_info(cpi);
diff --git a/av1/encoder/encoder_alloc.h b/av1/encoder/encoder_alloc.h
index 5bc957c..5eb485c 100644
--- a/av1/encoder/encoder_alloc.h
+++ b/av1/encoder/encoder_alloc.h
@@ -12,6 +12,7 @@
 #ifndef AOM_AV1_ENCODER_ENCODER_ALLOC_H_
 #define AOM_AV1_ENCODER_ENCODER_ALLOC_H_
 
+#include "av1/encoder/block.h"
 #include "av1/encoder/encoder.h"
 #include "av1/encoder/encodetxb.h"
 #include "av1/encoder/ethread.h"
@@ -229,6 +230,11 @@
   aom_free(cm->tpl_mvs);
   cm->tpl_mvs = NULL;
 
+  if (cpi->td.pixel_gradient_info) {
+    aom_free(cpi->td.pixel_gradient_info);
+    cpi->td.pixel_gradient_info = NULL;
+  }
+
   if (cpi->td.vt64x64) {
     aom_free(cpi->td.vt64x64);
     cpi->td.vt64x64 = NULL;
@@ -267,7 +273,6 @@
   for (int j = 0; j < 2; ++j) {
     aom_free(cpi->td.mb.tmp_pred_bufs[j]);
   }
-  aom_free(cpi->td.mb.pixel_gradient_info);
 
 #if CONFIG_DENOISE
   if (cpi->denoise_and_model) {
@@ -294,6 +299,20 @@
   cpi->mb_variance = NULL;
 }
 
+static AOM_INLINE void allocate_gradient_info_for_hog(
+    PixelLevelGradientInfo **pixel_gradient_info, AV1_COMP *cpi) {
+  const AV1_COMMON *const cm = &cpi->common;
+
+  if (!*pixel_gradient_info) {
+    const int plane_types = PLANE_TYPES >> cm->seq_params->monochrome;
+    CHECK_MEM_ERROR(cm, *pixel_gradient_info,
+                    aom_malloc(sizeof(**pixel_gradient_info) * plane_types *
+                               MAX_SB_SQUARE));
+  }
+
+  cpi->td.mb.pixel_gradient_info = *pixel_gradient_info;
+}
+
 static AOM_INLINE void variance_partition_alloc(AV1_COMP *cpi) {
   AV1_COMMON *const cm = &cpi->common;
   const int num_64x64_blocks = (cm->seq_params->sb_size == BLOCK_64X64) ? 1 : 4;
diff --git a/av1/encoder/ethread.c b/av1/encoder/ethread.c
index b06ac6e..45c041a 100644
--- a/av1/encoder/ethread.c
+++ b/av1/encoder/ethread.c
@@ -749,11 +749,15 @@
                                    sizeof(*thread_data->td->tmp_pred_bufs[j])));
         }
 
-        const int plane_types = PLANE_TYPES >> ppi->seq_params.monochrome;
-        AOM_CHECK_MEM_ERROR(
-            &ppi->error, thread_data->td->pixel_gradient_info,
-            aom_malloc(sizeof(*thread_data->td->pixel_gradient_info) *
-                       plane_types * MAX_SB_SQUARE));
+        const SPEED_FEATURES *sf = &ppi->cpi->sf;
+        if (sf->intra_sf.intra_pruning_with_hog ||
+            sf->intra_sf.chroma_intra_pruning_with_hog) {
+          const int plane_types = PLANE_TYPES >> ppi->seq_params.monochrome;
+          AOM_CHECK_MEM_ERROR(
+              &ppi->error, thread_data->td->pixel_gradient_info,
+              aom_malloc(sizeof(*thread_data->td->pixel_gradient_info) *
+                         plane_types * MAX_SB_SQUARE));
+        }
 
         if (ppi->cpi->sf.part_sf.partition_search_type == VAR_BASED_PARTITION) {
           const int num_64x64_blocks =
diff --git a/av1/encoder/speed_features.c b/av1/encoder/speed_features.c
index 8c70a80..702c950 100644
--- a/av1/encoder/speed_features.c
+++ b/av1/encoder/speed_features.c
@@ -1290,7 +1290,6 @@
   sf->interp_sf.disable_dual_filter = 1;
 
   sf->intra_sf.dv_cost_upd_level = INTERNAL_COST_UPD_OFF;
-  sf->intra_sf.intra_pruning_with_hog = 1;
 
   sf->lpf_sf.dual_sgr_penalty_level = 1;
   sf->lpf_sf.cdef_pick_method = CDEF_FAST_SEARCH_LVL1;