Browse Source

Add commute testcase

Samuel Thibault 10 years ago
parent
commit
0180a21f9b
2 changed files with 152 additions and 0 deletions
  1. 4 0
      tests/Makefile.am
  2. 148 0
      tests/datawizard/testCommute.cpp

+ 4 - 0
tests/Makefile.am

@@ -211,6 +211,7 @@ noinst_PROGRAMS =				\
 	datawizard/readonly			\
 	datawizard/specific_node		\
 	datawizard/task_with_multiple_time_the_same_handle	\
+	datawizard/testCommute			\
 	disk/disk_copy				\
 	disk/disk_compute			\
 	disk/disk_pack				\
@@ -455,6 +456,9 @@ datawizard_specific_node_SOURCES +=			\
 	datawizard/opencl_codelet_unsigned_inc.c
 endif
 
+datawizard_testCommute_SOURCES =	\
+	datawizard/testCommute.cpp
+
 main_deprecated_func_CFLAGS = $(AM_CFLAGS) -Wno-deprecated-declarations
 
 main_subgraph_repeat_SOURCES =		\

+ 148 - 0
tests/datawizard/testCommute.cpp

@@ -0,0 +1,148 @@
+/* StarPU --- Runtime system for heterogeneous multicore architectures.
+ *
+ * Copyright (C) 2015  INRIA
+ *
+ * StarPU is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or (at
+ * your option) any later version.
+ *
+ * StarPU is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * See the GNU Lesser General Public License in COPYING.LGPL for more details.
+ */
+
+/*
+ * for i from 0 to nbA
+ *  insert task handles[i] in STARPU_RW|STARPU_COMMUTE
+ *  for j from 0 to nbA
+ *	  if i != j
+			 insert task handles[i] in STARPU_RW|STARPU_COMMUTE, and handles[j] in STARPU_RW|STARPU_COMMUTE
+ */
+
+
+// @FUSE_STARPU
+
+
+#ifdef STARPU_QUICK_CHECK
+#define SLEEP_SLOW 6000
+#define SLEEP_FAST 1000
+#else
+#define SLEEP_SLOW 600000
+#define SLEEP_FAST 100000
+#endif
+
+#include <starpu.h>
+#include "../helper.h"
+
+#include <vector>
+#include <unistd.h>
+
+void callback(void * /*buffers*/[], void * /*cl_arg*/)
+{
+	usleep(SLEEP_FAST);
+	FPRINTF(stdout,"COMMUTE_LOG] callback\n"); fflush(stdout);
+}
+
+void callback_slow(void * /*buffers*/[], void * /*cl_arg*/)
+{
+	usleep(SLEEP_SLOW);
+	FPRINTF(stdout,"COMMUTE_LOG] callback_slow\n"); fflush(stdout);
+}
+
+
+int main(int /*argc*/, char** /*argv*/)
+{
+	unsigned ret;
+	struct starpu_conf conf;
+	ret = starpu_conf_init(&conf);
+	STARPU_ASSERT(ret == 0);
+	//conf.ncpus = 1;//// 4
+	ret = starpu_init(&conf);
+	STARPU_ASSERT(ret == 0);
+
+	FPRINTF(stdout, "Max Thread %d\n", starpu_worker_get_count());
+
+	//////////////////////////////////////////////////////
+
+	starpu_codelet normalCodelete;
+	{
+		memset(&normalCodelete, 0, sizeof(normalCodelete));
+		normalCodelete.where = STARPU_CPU;
+		normalCodelete.cpu_funcs[0] = callback;
+		normalCodelete.nbuffers = 2;
+		normalCodelete.modes[0] = starpu_data_access_mode(STARPU_RW|STARPU_COMMUTE);
+		normalCodelete.modes[1] = starpu_data_access_mode(STARPU_RW|STARPU_COMMUTE);
+		normalCodelete.name = "normalCodelete";
+	}
+	starpu_codelet slowCodelete;
+	{
+		memset(&slowCodelete, 0, sizeof(slowCodelete));
+		slowCodelete.where = STARPU_CPU;
+		slowCodelete.cpu_funcs[0] = callback_slow;
+		slowCodelete.nbuffers = 1;
+		slowCodelete.modes[0] = starpu_data_access_mode (STARPU_RW|STARPU_COMMUTE);
+		slowCodelete.name = "slowCodelete";
+	}
+
+	//////////////////////////////////////////////////////
+	//////////////////////////////////////////////////////
+
+	///const int nbA = 3;
+	const int nbA = 10;
+	FPRINTF(stdout, "Nb A = %d\n", nbA);
+
+	std::vector<starpu_data_handle_t> handleA(nbA);
+	std::vector<int> dataA(nbA);
+	for(int idx = 0 ; idx < nbA ; ++idx)
+	{
+		dataA[idx] = idx;
+	}
+	for(int idxHandle = 0 ; idxHandle < nbA ; ++idxHandle)
+	{
+		starpu_variable_data_register(&handleA[idxHandle], 0, (uintptr_t)&dataA[idxHandle], sizeof(dataA[idxHandle]));
+	}
+
+	//////////////////////////////////////////////////////
+	//////////////////////////////////////////////////////
+	FPRINTF(stdout,"Submit tasks\n");
+
+	for(int idxHandleA1 = 0 ; idxHandleA1 < nbA ; ++idxHandleA1)
+	{
+		starpu_insert_task(&slowCodelete,
+				(STARPU_RW|STARPU_COMMUTE), handleA[idxHandleA1],
+				0);
+		for(int idxHandleA2 = 0 ; idxHandleA2 < nbA ; ++idxHandleA2)
+		{
+			if(idxHandleA1 != idxHandleA2)
+			{
+				starpu_insert_task(&normalCodelete,
+						(STARPU_RW|STARPU_COMMUTE), handleA[idxHandleA1],
+						(STARPU_RW|STARPU_COMMUTE), handleA[idxHandleA2],
+						0);
+			}
+		}
+	}
+
+	//////////////////////////////////////////////////////
+	FPRINTF(stdout,"Wait task\n");
+
+	starpu_task_wait_for_all();
+
+	//////////////////////////////////////////////////////
+	FPRINTF(stdout,"Release data\n");
+
+	for(int idxHandle = 0 ; idxHandle < nbA ; ++idxHandle)
+	{
+		starpu_data_unregister(handleA[idxHandle]);
+	}
+
+	//////////////////////////////////////////////////////
+	FPRINTF(stdout,"Shutdown\n");
+
+	starpu_shutdown();
+
+	return 0;
+}