Sfoglia il codice sorgente

Add another commute test, from Stojce

Samuel Thibault 10 anni fa
parent
commit
d341e82c30
3 ha cambiato i file con 107 aggiunte e 0 eliminazioni
  1. 1 0
      AUTHORS
  2. 1 0
      tests/Makefile.am
  3. 105 0
      tests/datawizard/commute2.c

+ 1 - 0
AUTHORS

@@ -16,6 +16,7 @@ Xavier Lacoste <xavier.lacoste@inria.fr>
 Benoît Lizé <benoit.lize@gmail.com>
 Antoine Lucas <antoine.lucas.33@gmail.com>
 Brice Mortier <brice.mortier@etu.u-bordeaux1.fr>
+Stojce Nakov <stojce.nakov@inria.fr>
 Joris Pablo <joris.pablo@orange.fr>
 Damien Pasqualinotto <dam.pasqualinotto@wanadoo.fr>
 Nguyen Quôc-Dinh <nguyen.quocdinh@gmail.com>

+ 1 - 0
tests/Makefile.am

@@ -153,6 +153,7 @@ noinst_PROGRAMS =				\
 	datawizard/acquire_release2		\
 	datawizard/cache			\
 	datawizard/commute			\
+	datawizard/commute2			\
 	datawizard/copy				\
 	datawizard/data_implicit_deps		\
 	datawizard/data_lookup			\

+ 105 - 0
tests/datawizard/commute2.c

@@ -0,0 +1,105 @@
+/* StarPU --- Runtime system for heterogeneous multicore architectures.
+ *
+ * Copyright (C) 2014 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.
+ */
+
+#include <starpu.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#ifdef STARPU_USE_CUDA
+#include <starpu_cuda.h>
+#endif
+
+static unsigned cnt;
+
+static void cpu_memcpy(void *descr[], void *cl_arg)
+{
+	double *res = (double *)STARPU_VECTOR_GET_PTR(descr[0]);
+	double *dst = (double *)STARPU_VECTOR_GET_PTR(descr[1]);
+	int n = (int) STARPU_VECTOR_GET_NX(descr[0]);
+	int me = (uintptr_t)cl_arg;
+
+	if (me == 0)
+	{
+		sleep(1);
+		STARPU_ASSERT(STARPU_ATOMIC_ADD(&cnt,1) == 1);
+	}
+	else
+		STARPU_ASSERT(STARPU_ATOMIC_ADD(&cnt,1) != 1);
+
+	memcpy(dst, res, n*sizeof(double));
+}
+
+
+static struct starpu_codelet my_cl = {
+	.where =  STARPU_CPU,
+	.cpu_funcs = {cpu_memcpy, NULL}, 
+	.nbuffers = STARPU_VARIABLE_NBUFFERS
+};
+
+int 
+main()
+{
+	double *res, *a;
+	unsigned n=100000, i;
+	starpu_data_handle_t res_handle, a_handle;
+	unsigned nb_tasks = 10, worker;
+
+	if (starpu_init(NULL)) 
+		exit(-1);
+
+	starpu_malloc((void**)&res, n*sizeof(double));
+	starpu_malloc((void**)&a,   n*sizeof(double));
+
+	for(i=0; i < n; i++)
+		res[i] = a[i] = 1.0;
+		
+	starpu_vector_data_register(&res_handle, 0, (uintptr_t)res, (uint32_t)n, sizeof(double));
+	starpu_vector_data_register(&a_handle,   0, (uintptr_t)a,   (uint32_t)n, sizeof(double));
+
+	for (i = 0; i < nb_tasks; i++) {
+		struct starpu_task *task = starpu_task_create();
+		task->cl=&my_cl;
+		task->nbuffers = 2;
+		task->handles[0] = res_handle;
+
+		if (i == 0)
+			task->modes[0]   = STARPU_RW;
+		else
+			task->modes[0]   = STARPU_RW | STARPU_COMMUTE;
+		
+		task->handles[1] = a_handle;
+		task->modes[1]   = STARPU_R;
+		task->cl_arg = (void*)(uintptr_t)i;
+		
+		if (starpu_task_submit(task)) {
+			fprintf(stderr,"taks submmition failed!");
+			exit(EXIT_FAILURE);
+		}
+	}
+
+	starpu_task_wait_for_all ();
+
+	starpu_data_unregister(res_handle);
+	starpu_data_unregister(a_handle);
+
+	starpu_free(res);
+	starpu_free(a);
+
+	starpu_shutdown();
+	return EXIT_SUCCESS;
+}
+
+