Browse Source

_starpu_worker_exists : use task->cl->can_execute when it is defined.

Cyril Roelandt 13 years ago
parent
commit
f501a6d2bd
3 changed files with 41 additions and 5 deletions
  1. 1 1
      src/core/task.c
  2. 39 3
      src/core/workers.c
  3. 1 1
      src/core/workers.h

+ 1 - 1
src/core/task.c

@@ -296,7 +296,7 @@ int starpu_task_submit(struct starpu_task *task)
 		_starpu_codelet_check_deprecated_fields(task->cl);
 
 		/* Check the type of worker(s) required by the task exist */
-		if (!_starpu_worker_exists(where))
+		if (!_starpu_worker_exists(task))
 		{
                         _STARPU_LOG_OUT_TAG("ENODEV");
 			return -ENODEV;

+ 39 - 3
src/core/workers.c

@@ -46,12 +46,48 @@ struct _starpu_machine_config *_starpu_get_machine_config(void)
 	return &config;
 }
 
+/* Makes sure that at least one of the workers of type <arch> can execute
+ * <task>*/
+static uint32_t _starpu_worker_exists_and_can_execute(struct starpu_task *task,
+						      enum starpu_archtype arch)
+{
+	int i;
+	int nworkers = starpu_worker_get_count_by_type(arch);
+	int workers[nworkers];
+	STARPU_ASSERT(nworkers != -EINVAL);
+	(void) starpu_worker_get_ids_by_type(arch, workers, nworkers);
+	for (i = 0; i < nworkers; i++)
+		if (task->cl->can_execute(workers[i], task, 0))
+			return 1;
+	return 0;
+}
+
 /* in case a task is submitted, we may check whether there exists a worker
    that may execute the task or not */
-
-uint32_t _starpu_worker_exists(uint32_t task_mask)
+uint32_t _starpu_worker_exists(struct starpu_task *task)
 {
-	return (task_mask & config.worker_mask);
+	if (!(task->cl->where & config.worker_mask))
+		return 0;
+
+	if (!task->cl->can_execute)
+		return 1;
+
+#ifdef STARPU_USE_CPU
+	if ((task->cl->where & STARPU_CPU) &&
+	    _starpu_worker_exists_and_can_execute(task, STARPU_CPU_WORKER))
+		return 1;
+#endif
+#ifdef STARPU_USE_CUDA
+	if ((task->cl->where & STARPU_CUDA) &&
+	    _starpu_worker_exists_and_can_execute(task, STARPU_CUDA_WORKER))
+		return 1;
+#endif
+#ifdef STARPU_USE_OPENCL
+	if ((task->cl->where & STARPU_OPENCL) &&
+	    _starpu_worker_exists_and_can_execute(task, STARPU_OPENCL_WORKER))
+		return 1;
+#endif
+	return 0;
 }
 
 uint32_t _starpu_can_submit_cuda_task(void)

+ 1 - 1
src/core/workers.h

@@ -162,7 +162,7 @@ struct _starpu_machine_config
 unsigned _starpu_machine_is_running(void);
 
 /* Check if there is a worker that may execute the task. */
-uint32_t _starpu_worker_exists(uint32_t task_mask);
+uint32_t _starpu_worker_exists(struct starpu_task *);
 
 /* Is there a worker that can execute CUDA code ? */
 uint32_t _starpu_can_submit_cuda_task(void);