Browse Source

Same buffer size for BatchQueue and native algo

Ensure buffer size for BatchQueue and the native communication algorithm is the
same in case there is 1 producer and 1 consumer. In case of several
producers or several consumers, the size of the buffer is multiplied by
max(nb producers, nb consumers).
bq-ompstream
Thomas Preud'homme 7 years ago
parent
commit
7545a6222c
1 changed files with 62 additions and 32 deletions
  1. 62
    32
      gcc/omp-low.c

+ 62
- 32
gcc/omp-low.c View File

@@ -7867,29 +7867,38 @@ prepare_streaming_context (omp_region_p region)
7867 7867
 		 parallel region.  */
7868 7868
 	      for (i = 0; VEC_iterate (stream_p, sinfo->streams, i, stream); ++i)
7869 7869
 		{
7870
-#ifdef BATCHQ_ENABLED
7871
-		  int nb_views = 0;
7870
+		  int nb_views = 0, nb_rviews = 0, nb_wviews = 0;
7872 7871
 
7872
+#ifdef BATCHQ_ENABLED
7873 7873
 		  stream->use_batchQ = 0;
7874
+#endif
7874 7875
 		  for (j = 0; VEC_iterate (view_p, stream->rviews, j, view); ++j)
7875 7876
 		    {
7876 7877
 		      if (INTEGER_CST_CHECK(view->sinfo->num_instances))
7877
-			nb_views += TREE_INT_CST_LOW(view->sinfo->num_instances);
7878
+			{
7879
+			  nb_views += TREE_INT_CST_LOW(view->sinfo->num_instances);
7880
+			  nb_rviews += TREE_INT_CST_LOW(view->sinfo->num_instances);
7881
+			}
7878 7882
 		      else
7879 7883
 		        {
7880 7884
 			  /* Ensure we use generic functions */
7881 7885
 			  nb_views += 2;
7886
+			  nb_rviews += 2;
7882 7887
 			  break;
7883 7888
 			}
7884 7889
 		    }
7885 7890
 		  for (j = 0; VEC_iterate (view_p, stream->wviews, j, view); ++j)
7886 7891
 		    {
7887 7892
 		      if (INTEGER_CST_CHECK(view->sinfo->num_instances))
7888
-			nb_views += TREE_INT_CST_LOW(view->sinfo->num_instances);
7893
+			{
7894
+			  nb_views += TREE_INT_CST_LOW(view->sinfo->num_instances);
7895
+		          nb_wviews += TREE_INT_CST_LOW(view->sinfo->num_instances);
7896
+			}
7889 7897
 		      else
7890 7898
 		        {
7891 7899
 			  /* Ensure we use generic functions */
7892 7900
 			  nb_views += 2;
7901
+			  nb_wviews += 2;
7893 7902
 			  break;
7894 7903
 			}
7895 7904
 		    }
@@ -7903,55 +7912,76 @@ prepare_streaming_context (omp_region_p region)
7903 7912
 		      /* If there are firstprivate views, there should be no write views.  */
7904 7913
 		      gcc_assert (VEC_empty (view_p, stream->wviews));
7905 7914
 		      nb_views ++;
7915
+		      nb_wviews ++;
7906 7916
 		    }
7907 7917
 
7918
+#ifdef BATCHQ_ENABLED
7908 7919
 		  if (nb_views == 2)
7909 7920
 		    stream->use_batchQ = 1;
7910 7921
 #endif
7911 7922
 
7912 7923
 		  tree type_size = TYPE_SIZE_UNIT (stream->element_type);
7913 7924
 		  tree horizon_size;
7914
-#ifdef BATCHQ_ENABLED
7915 7925
 		  tree read_burst_size, write_burst_size, burst_size;
7916 7926
 		  view_p rview, wview;
7917 7927
 
7918
-#endif
7919
-
7920 7928
 		  gsi = gsi_last_bb (sinfo->initialization_bb);
7929
+		  horizon_size = create_tmp_var (size_type_node,
7930
+						 "horizon_size");
7931
+		  burst_size = create_tmp_var (size_type_node,
7932
+					       "burst_size");
7933
+		  rview = VEC_index(view_p, stream->rviews, 0);
7934
+		  read_burst_size = get_view_burst_size (rview, &gsi);
7935
+		  if (VEC_empty (view_p, stream->wviews))
7936
+		      wview = VEC_index(view_p, stream->fpviews, 0);
7937
+		  else
7938
+		      wview = VEC_index(view_p, stream->wviews, 0);
7939
+		  write_burst_size = get_view_burst_size (wview, &gsi);
7940
+		  stmt = gimple_build_assign_with_ops (MAX_EXPR,
7941
+						       burst_size,
7942
+						       read_burst_size,
7943
+						       write_burst_size);
7944
+		  gsi_insert_after (&gsi, stmt, GSI_CONTINUE_LINKING);
7945
+		  /* MAX(read_burst_size, write_burst_size) / type_size */
7946
+		  stmt = gimple_build_assign_with_ops (CEIL_DIV_EXPR,
7947
+						       horizon_size,
7948
+						       burst_size,
7949
+						       type_size);
7950
+		  gsi_insert_after (&gsi, stmt, GSI_CONTINUE_LINKING);
7921 7951
 #ifdef BATCHQ_ENABLED
7922 7952
 		  if (stream->use_batchQ)
7953
+		      fn = built_in_decls[BUILT_IN_GOMP_BATCHQ_CREATE_STREAM];
7954
+		  else
7923 7955
 		    {
7924
-		      horizon_size = create_tmp_var (size_type_node,
7925
-						     "horizon_size");
7926
-		      burst_size = create_tmp_var (size_type_node,
7927
-						   "burst_size");
7928
-		      rview = VEC_index(view_p, stream->rviews, 0);
7929
-		      read_burst_size = get_view_burst_size (rview, &gsi);
7930
-		      if (VEC_empty (view_p, stream->wviews))
7931
-			  wview = VEC_index(view_p, stream->fpviews, 0);
7932
-		      else
7933
-			  wview = VEC_index(view_p, stream->wviews, 0);
7934
-		      write_burst_size = get_view_burst_size (wview, &gsi);
7956
+#endif
7957
+		      tree aggregation_factor, nbwviewscst, nbrviewscst;
7958
+		      tree max_nbviews;
7959
+
7960
+		      aggregation_factor = build_int_cst (size_type_node,
7961
+							  AGGREGATION_FACTOR);
7962
+		      nbwviewscst = build_int_cst (size_type_node, nb_wviews);
7963
+		      nbrviewscst = build_int_cst (size_type_node, nb_rviews);
7964
+		      max_nbviews = create_tmp_var (size_type_node,
7965
+						    "max_nbviews");
7935 7966
 		      stmt = gimple_build_assign_with_ops (MAX_EXPR,
7936
-							   burst_size,
7937
-							   read_burst_size,
7938
-							   write_burst_size);
7967
+							   max_nbviews,
7968
+							   nbrviewscst,
7969
+							   nbrviewscst);
7939 7970
 		      gsi_insert_after (&gsi, stmt, GSI_CONTINUE_LINKING);
7940
-		      /* MAX(read_burst_size, write_burst_size) / type_size */
7941
-		      stmt = gimple_build_assign_with_ops (CEIL_DIV_EXPR,
7971
+		      stmt = gimple_build_assign_with_ops (MULT_EXPR,
7972
+							   horizon_size,
7942 7973
 							   horizon_size,
7943
-							   burst_size,
7944
-							   type_size);
7974
+							   max_nbviews);
7975
+		      gsi_insert_after (&gsi, stmt, GSI_CONTINUE_LINKING);
7976
+		      stmt = gimple_build_assign_with_ops (MULT_EXPR,
7977
+							   horizon_size,
7978
+							   horizon_size,
7979
+							   aggregation_factor);
7945 7980
 		      gsi_insert_after (&gsi, stmt, GSI_CONTINUE_LINKING);
7946
-		      fn = built_in_decls[BUILT_IN_GOMP_BATCHQ_CREATE_STREAM];
7947
-		    }
7948
-		  else
7949
-#endif
7950
-		    {
7951
-		      horizon_size = build_int_cst (size_type_node,
7952
-						    HORIZON);
7953 7981
 		      fn = built_in_decls[BUILT_IN_GOMP_STREAM_CREATE_STREAM];
7982
+#ifdef BATCHQ_ENABLED
7954 7983
 		    }
7984
+#endif
7955 7985
 		    stmt = gimple_build_call (fn, 2, type_size, horizon_size);
7956 7986
 		    gimple_call_set_lhs (stmt, stream->stream);
7957 7987
 		    gsi_insert_after (&gsi, stmt, GSI_CONTINUE_LINKING);

Loading…
Cancel
Save