瀏覽代碼

Honor workerids in all versions of worker_can_execute_task

Lionel ED 5 年之前
父節點
當前提交
ed8839959f
共有 1 個文件被更改,包括 25 次插入25 次删除
  1. 25 25
      src/core/workers.c

+ 25 - 25
src/core/workers.c

@@ -426,12 +426,21 @@ static inline int _starpu_can_use_nth_implementation(enum starpu_worker_archtype
 	return 0;
 	return 0;
 }
 }
 
 
-/* must be called with sched_mutex locked to protect state_blocked_in_parallel */
-int starpu_worker_can_execute_task(unsigned workerid, struct starpu_task *task, unsigned nimpl)
-{
+/* Test if this task can be processed on this worker, regardless of the implementation */
+/* must be called with sched_mutex locked to protect state_blocked */
+static inline int _starpu_can_execute_task_any_impl(unsigned workerid, struct starpu_task *task) {
+
 	if (!_starpu_config.workers[workerid].enable_knob)
 	if (!_starpu_config.workers[workerid].enable_knob)
 		return 0;
 		return 0;
 
 
+	if (task->workerids_len)
+	{
+		size_t div = sizeof(*task->workerids) * 8;
+		if (workerid / div >= task->workerids_len || ! (task->workerids[workerid / div] & (1UL << workerid % div)))
+			return 0;
+	}
+
+	
 	/* if the worker is blocked in a parallel ctx don't submit tasks on it */
 	/* if the worker is blocked in a parallel ctx don't submit tasks on it */
 #ifdef STARPU_DEVEL
 #ifdef STARPU_DEVEL
 #warning FIXME: this is very expensive, while can_execute is supposed to be not very costly so schedulers can call it a lot
 #warning FIXME: this is very expensive, while can_execute is supposed to be not very costly so schedulers can call it a lot
@@ -439,8 +448,18 @@ int starpu_worker_can_execute_task(unsigned workerid, struct starpu_task *task,
 	if(starpu_worker_is_blocked_in_parallel(workerid))
 	if(starpu_worker_is_blocked_in_parallel(workerid))
 		return 0;
 		return 0;
 
 
+	if (!(task->where & _starpu_config.workers[workerid].worker_mask))
+		return 0;
+
+	return 1; 
+}
+
+/* must be called with sched_mutex locked to protect state_blocked_in_parallel */
+int starpu_worker_can_execute_task(unsigned workerid, struct starpu_task *task, unsigned nimpl)
+{
+
 	/* TODO: check that the task operand sizes will fit on that device */
 	/* TODO: check that the task operand sizes will fit on that device */
-	return (task->where & _starpu_config.workers[workerid].worker_mask) &&
+	return  _starpu_can_execute_task_any_impl(workerid, task) &&
 		_starpu_can_use_nth_implementation(_starpu_config.workers[workerid].arch, task->cl, nimpl) &&
 		_starpu_can_use_nth_implementation(_starpu_config.workers[workerid].arch, task->cl, nimpl) &&
 		(!task->cl->can_execute || task->cl->can_execute(workerid, task, nimpl));
 		(!task->cl->can_execute || task->cl->can_execute(workerid, task, nimpl));
 }
 }
@@ -448,11 +467,7 @@ int starpu_worker_can_execute_task(unsigned workerid, struct starpu_task *task,
 /* must be called with sched_mutex locked to protect state_blocked_in_parallel */
 /* must be called with sched_mutex locked to protect state_blocked_in_parallel */
 int starpu_worker_can_execute_task_impl(unsigned workerid, struct starpu_task *task, unsigned *impl_mask)
 int starpu_worker_can_execute_task_impl(unsigned workerid, struct starpu_task *task, unsigned *impl_mask)
 {
 {
-	if (!_starpu_config.workers[workerid].enable_knob)
-		return 0;
-
-	/* if the worker is blocked in a parallel ctx don't submit tasks on it */
-	if(starpu_worker_is_blocked_in_parallel(workerid))
+	if (!_starpu_can_execute_task_any_impl(workerid, task))
 		return 0;
 		return 0;
 
 
 	unsigned mask;
 	unsigned mask;
@@ -461,15 +476,6 @@ int starpu_worker_can_execute_task_impl(unsigned workerid, struct starpu_task *t
 	struct starpu_codelet *cl;
 	struct starpu_codelet *cl;
 	/* TODO: check that the task operand sizes will fit on that device */
 	/* TODO: check that the task operand sizes will fit on that device */
 	cl = task->cl;
 	cl = task->cl;
-	if (!(task->where & _starpu_config.workers[workerid].worker_mask))
-		return 0;
-
-	if (task->workerids_len)
-	{
-		size_t div = sizeof(*task->workerids) * 8;
-		if (workerid / div >= task->workerids_len || ! (task->workerids[workerid / div] & (1UL << workerid % div)))
-			return 0;
-	}
 
 
 	mask = 0;
 	mask = 0;
 	arch = _starpu_config.workers[workerid].arch;
 	arch = _starpu_config.workers[workerid].arch;
@@ -502,19 +508,13 @@ int starpu_worker_can_execute_task_impl(unsigned workerid, struct starpu_task *t
 /* must be called with sched_mutex locked to protect state_blocked */
 /* must be called with sched_mutex locked to protect state_blocked */
 int starpu_worker_can_execute_task_first_impl(unsigned workerid, struct starpu_task *task, unsigned *nimpl)
 int starpu_worker_can_execute_task_first_impl(unsigned workerid, struct starpu_task *task, unsigned *nimpl)
 {
 {
-	if (!_starpu_config.workers[workerid].enable_knob)
-		return 0;
-
-	/* if the worker is blocked in a parallel ctx don't submit tasks on it */
-	if(starpu_worker_is_blocked_in_parallel(workerid))
+	if (!_starpu_can_execute_task_any_impl(workerid, task))
 		return 0;
 		return 0;
 	int i;
 	int i;
 	enum starpu_worker_archtype arch;
 	enum starpu_worker_archtype arch;
 	struct starpu_codelet *cl;
 	struct starpu_codelet *cl;
 	/* TODO: check that the task operand sizes will fit on that device */
 	/* TODO: check that the task operand sizes will fit on that device */
 	cl = task->cl;
 	cl = task->cl;
-	if (!(task->where & _starpu_config.workers[workerid].worker_mask))
-		return 0;
 
 
 	arch = _starpu_config.workers[workerid].arch;
 	arch = _starpu_config.workers[workerid].arch;
 	if (!task->cl->can_execute)
 	if (!task->cl->can_execute)