Fix multithread mismatch due to intra cnn partitioning

This prevents an edge case where uninitialized outputs from CNN are used
to determine intra-frame partitioning.

STATS_CHANGED

BUG=aomedia:2424

Change-Id: I102a25e5a715d55462a1db59b806187897a9f11c
diff --git a/av1/encoder/block.h b/av1/encoder/block.h
index 363deca..72a59e0 100644
--- a/av1/encoder/block.h
+++ b/av1/encoder/block.h
@@ -413,6 +413,7 @@
 
 #if !CONFIG_REALTIME_ONLY
   int quad_tree_idx;
+  int cnn_output_valid;
   float cnn_buffer[CNN_OUT_BUF_SIZE];
   float log_q;
 #endif
diff --git a/av1/encoder/encodeframe.c b/av1/encoder/encodeframe.c
index 256916a..a6fefb4 100644
--- a/av1/encoder/encodeframe.c
+++ b/av1/encoder/encodeframe.c
@@ -2370,6 +2370,7 @@
 
   if (frame_is_intra_only(cm) && bsize == BLOCK_64X64) {
     x->quad_tree_idx = 0;
+    x->cnn_output_valid = 0;
   }
 
   if (bsize == cm->seq_params.sb_size) x->must_find_valid_partition = 0;
@@ -4007,6 +4008,9 @@
         !frame_is_intra_only(cm) && !use_nonrd_mode) {
       init_simple_motion_search_mvs(pc_root);
     }
+#if !CONFIG_REALTIME_ONLY
+    td->mb.cnn_output_valid = 0;
+#endif
 
     xd->cur_frame_force_integer_mv = cm->cur_frame_force_integer_mv;
 
diff --git a/av1/encoder/partition_strategy.c b/av1/encoder/partition_strategy.c
index c63dbae..f16532a 100644
--- a/av1/encoder/partition_strategy.c
+++ b/av1/encoder/partition_strategy.c
@@ -64,7 +64,7 @@
   const int bsize_idx = convert_bsize_to_idx(bsize);
 
   // Precompute the CNN part and cache the result in MACROBLOCK
-  if (bsize == BLOCK_64X64) {
+  if (bsize == BLOCK_64X64 && !x->cnn_output_valid) {
     aom_clear_system_state();
     const CNN_CONFIG *cnn_config = &av1_intra_mode_cnn_partition_cnn_config;
 
@@ -121,6 +121,12 @@
       av1_cnn_predict_img_multi_out(image, width, height, stride, cnn_config,
                                     &thread_data, &output);
     }
+
+    x->cnn_output_valid = 1;
+  }
+
+  if (!x->cnn_output_valid) {
+    return;
   }
 
   const NN_CONFIG *dnn_configs[5] = {