Kaynağa Gözat

- Use a write-back cache policy for the "counter" data
- Add some timing measurement

Cédric Augonnet 15 yıl önce
ebeveyn
işleme
be0570c9d2
2 değiştirilmiş dosya ile 18 ekleme ve 9 silme
  1. 17 8
      examples/pi/pi.c
  2. 1 1
      examples/pi/pi.h

+ 17 - 8
examples/pi/pi.c

@@ -76,17 +76,16 @@ int main(int argc, char **argv)
 	starpu_data_handle cnt_array_handle;
 	starpu_register_vector_data(&cnt_array_handle, 0, (uintptr_t)cnt_array, NTASKS, sizeof(unsigned));
 
-	/* TODO use a write-back mechanism */
+	/* Use a write-back policy : when the data is modified on an
+	 * accelerator, we know that it will only be modified once and be
+	 * accessed by the CPU later on */
+	starpu_data_set_wb_mask(cnt_array_handle, (1<<0));
 
 	struct starpu_filter_t f = {
 		.filter_func = starpu_block_filter_func_vector,
 		.filter_arg = NTASKS
 	};
 	
-#if 0
-	starpu_partition_data(random_array_handle_x, &f);
-	starpu_partition_data(random_array_handle_y, &f);
-#endif
 	starpu_partition_data(cnt_array_handle, &f);
 
 	static struct starpu_perfmodel_t model = {
@@ -104,6 +103,11 @@ int main(int argc, char **argv)
 		.model = &model
 	};
 
+	struct timeval start;
+	struct timeval end;
+
+	gettimeofday(&start, NULL);
+
 	for (i = 0; i < NTASKS; i++)
 	{
 		struct starpu_task *task = starpu_task_create();
@@ -132,13 +136,18 @@ int main(int argc, char **argv)
 	for (i = 0; i < NTASKS; i++)
 		total_cnt += cnt_array[i];
 
-	starpu_release_data_from_mem(cnt_array_handle);
+	gettimeofday(&end, NULL);
 
-	starpu_shutdown();
+	double timing = (double)((end.tv_sec - start.tv_sec)*1000000 + (end.tv_usec - start.tv_usec));
 
 	/* Total surface : Pi * r^ 2 = Pi*1^2, total square surface : 2^2 = 4, probability to impact the disk: pi/4 */
-
 	fprintf(stderr, "Pi approximation : %f (%ld / %ld)\n", ((TYPE)total_cnt*4)/(SIZE), total_cnt, SIZE);
+	fprintf(stderr, "Total time : %f ms\n", timing/1000.0);
+	fprintf(stderr, "Speed : %f GShot/s\n", (SIZE)/(10e3*timing));
+
+	starpu_release_data_from_mem(cnt_array_handle);
+
+	starpu_shutdown();
 
 	return 0;
 }

+ 1 - 1
examples/pi/pi.h

@@ -20,7 +20,7 @@
 #include <starpu.h>
 #include <stdio.h>
 
-#define NTASKS	(16384ULL)
+#define NTASKS	(256ULL)
 #define NSHOT_PER_TASK	(16*1024*1024ULL)
 
 #define SIZE	(NTASKS*NSHOT_PER_TASK)