Forráskód Böngészése

Add starpu_execute_on_specific_workers method.
Add starpu_execute_on_each_worker_ex with additional task name parameter

Sylvain Henry 12 éve
szülő
commit
7670a024ae
2 módosított fájl, 88 hozzáadás és 4 törlés
  1. 9 0
      include/starpu_util.h
  2. 79 4
      src/util/execute_on_all.c

+ 9 - 0
include/starpu_util.h

@@ -231,6 +231,15 @@ void starpu_trace_user_event(unsigned long code);
  * */
 void starpu_execute_on_each_worker(void (*func)(void *), void *arg, uint32_t where);
 
+/* Same as starpu_execute_on_each_worker, except that the task name is specified in the "name" parameter. */
+void starpu_execute_on_each_worker_ex(void (*func)(void *), void *arg, uint32_t where, const char * name);
+
+/* Call func(arg) on every worker in the "workers" array. "num_workers"
+ * indicates the number of workers in this array.  This function is
+ * synchronous, but the different workers may execute the function in parallel.
+ * */
+void starpu_execute_on_specific_workers(void (*func)(void*), void * arg, unsigned num_workers, unsigned * workers, const char * name);
+
 /* Copy the content of the src_handle into the dst_handle handle.  The
  * asynchronous parameter indicates whether the function should block or not.
  * In the case of an asynchronous call, it is possible to synchronize with the

+ 79 - 4
src/util/execute_on_all.c

@@ -32,8 +32,78 @@ static void wrapper_func(void *buffers[] __attribute__ ((unused)), void *_args)
 	args->func(args->arg);
 }
 
+/**
+ * Execute func(arg) on the given workers.
+ */
+void starpu_execute_on_specific_workers(void (*func)(void*), void * arg, unsigned num_workers, unsigned * workers, const char * name) {
+
+	int ret;
+	unsigned w;
+	struct starpu_task *tasks[STARPU_NMAXWORKERS];
+
+	/* create a wrapper codelet */
+	struct starpu_codelet wrapper_cl =
+	{
+		.where = 0xFF,
+		.cuda_funcs = {wrapper_func, NULL},
+		.cpu_funcs = {wrapper_func, NULL},
+		.opencl_funcs = {wrapper_func, NULL},
+		/* XXX we do not handle Cell .. */
+		.nbuffers = 0,
+		.name = name
+	};
+
+	struct wrapper_func_args args =
+	{
+		.func = func,
+		.arg = arg
+	};
+
+
+	for (w = 0; w < num_workers; w++)
+	{
+	  unsigned worker = workers[w];
+		tasks[w] = starpu_task_create();
+
+		tasks[w]->cl = &wrapper_cl;
+		tasks[w]->cl_arg = &args;
+
+		tasks[w]->execute_on_a_specific_worker = 1;
+		tasks[w]->workerid = worker;
+
+		tasks[w]->detach = 0;
+		tasks[w]->destroy = 0;
+   
+#ifdef STARPU_USE_FXT
+		_starpu_get_job_associated_to_task(tasks[w])->model_name = name;
+#endif
+   
+		_starpu_exclude_task_from_dag(tasks[w]);
+
+		ret = starpu_task_submit(tasks[w]);
+		if (ret == -ENODEV)
+		{
+			/* if the worker is not able to execute this tasks, we
+			 * don't insist as this means the worker is not
+			 * designated by the "where" bitmap */
+			starpu_task_destroy(tasks[w]);
+			tasks[w] = NULL;
+		}
+	}
+
+	for (w= 0; w < num_workers; w++)
+	{
+		if (tasks[w])
+		{
+			ret = starpu_task_wait(tasks[w]);
+			STARPU_ASSERT(!ret);
+			starpu_task_destroy(tasks[w]);
+		}
+	}
+}
+
 /* execute func(arg) on each worker that matches the "where" flag */
-void starpu_execute_on_each_worker(void (*func)(void *), void *arg, uint32_t where)
+void starpu_execute_on_each_worker_ex(void (*func)(void *), void *arg, uint32_t where, const char * name)
 {
 	int ret;
 	unsigned worker;
@@ -48,7 +118,8 @@ void starpu_execute_on_each_worker(void (*func)(void *), void *arg, uint32_t whe
 		.cpu_funcs = {wrapper_func, NULL},
 		.opencl_funcs = {wrapper_func, NULL},
 		/* XXX we do not handle Cell .. */
-		.nbuffers = 0
+		.nbuffers = 0,
+		.name = (name != NULL ? name : "execute_on_all_wrapper")
 	};
 
 	struct wrapper_func_args args =
@@ -57,6 +128,7 @@ void starpu_execute_on_each_worker(void (*func)(void *), void *arg, uint32_t whe
 		.arg = arg
 	};
 
+
 	for (worker = 0; worker < nworkers; worker++)
 	{
 		tasks[worker] = starpu_task_create();
@@ -71,8 +143,7 @@ void starpu_execute_on_each_worker(void (*func)(void *), void *arg, uint32_t whe
 		tasks[worker]->destroy = 0;
 
 #ifdef STARPU_USE_FXT
-                struct _starpu_job *job = _starpu_get_job_associated_to_task(tasks[worker]);
-                job->model_name = "execute_on_all_wrapper";
+		_starpu_get_job_associated_to_task(tasks[worker])->model_name = wrapper_cl.name;
 #endif
 
 		_starpu_exclude_task_from_dag(tasks[worker]);
@@ -98,3 +169,7 @@ void starpu_execute_on_each_worker(void (*func)(void *), void *arg, uint32_t whe
 		}
 	}
 }
+
+void starpu_execute_on_each_worker(void (*func)(void *), void *arg, uint32_t where) {
+	starpu_execute_on_each_worker_ex(func, arg, where, NULL);
+}