ソースを参照

Make _starpu_workers_able_to_execute_task faster in the usual case by not actually computing how many workers can execute a task

Samuel Thibault 5 年 前
コミット
3d682bb3e4
共有3 個のファイルを変更した16 個の追加14 個の削除を含む
  1. 9 6
      src/core/sched_ctx.c
  2. 2 2
      src/core/sched_ctx.h
  3. 5 6
      src/core/sched_policy.c

+ 9 - 6
src/core/sched_ctx.c

@@ -1137,8 +1137,8 @@ static void fetch_tasks_from_empty_ctx_list(struct _starpu_sched_ctx *sched_ctx)
 
 		/* if no workers are able to execute the task, it will be put
 		 * in the empty_ctx_tasks list forever again */
-		unsigned nworkers = _starpu_nworkers_able_to_execute_task(old_task, sched_ctx);
-		STARPU_ASSERT(nworkers > 0);
+		unsigned able = _starpu_workers_able_to_execute_task(old_task, sched_ctx);
+		STARPU_ASSERT(able);
 
 		int ret =  _starpu_push_task_to_workers(old_task);
 		/* if we should stop poping from empty ctx tasks */
@@ -1421,9 +1421,9 @@ void starpu_sched_ctx_remove_workers(int *workers_to_remove, unsigned nworkers_t
 	}
 }
 
-int _starpu_nworkers_able_to_execute_task(struct starpu_task *task, struct _starpu_sched_ctx *sched_ctx)
+int _starpu_workers_able_to_execute_task(struct starpu_task *task, struct _starpu_sched_ctx *sched_ctx)
 {
-	unsigned nworkers = 0;
+	unsigned able = 0;
 
 	_starpu_sched_ctx_lock_read(sched_ctx->id);
 	struct starpu_worker_collection *workers = sched_ctx->workers;
@@ -1436,11 +1436,14 @@ int _starpu_nworkers_able_to_execute_task(struct starpu_task *task, struct _star
 		unsigned worker = workers->get_next(workers, &it);
 		STARPU_ASSERT_MSG(worker < STARPU_NMAXWORKERS, "worker id %u", worker);
 		if (starpu_worker_can_execute_task_first_impl(worker, task, NULL))
-			nworkers++;
+		{
+			able++;
+			break;
+		}
 	}
 	_starpu_sched_ctx_unlock_read(sched_ctx->id);
 
-	return nworkers;
+	return able;
 }
 
 /* unused sched_ctx have the id STARPU_NMAX_SCHED_CTXS */

+ 2 - 2
src/core/sched_ctx.h

@@ -233,8 +233,8 @@ unsigned _starpu_sched_ctx_last_worker_awake(struct _starpu_worker *worker);
  * id set by its last call, or the id of the initial context */
 unsigned _starpu_sched_ctx_get_current_context();
 
-/* verify how many workers can execute a certain task */
-int _starpu_nworkers_able_to_execute_task(struct starpu_task *task, struct _starpu_sched_ctx *sched_ctx);
+/* verify that some worker can execute a certain task */
+int _starpu_workers_able_to_execute_task(struct starpu_task *task, struct _starpu_sched_ctx *sched_ctx);
 
 void _starpu_fetch_tasks_from_empty_ctx_list(struct _starpu_sched_ctx *sched_ctx);
 

+ 5 - 6
src/core/sched_policy.c

@@ -466,9 +466,9 @@ int _starpu_repush_task(struct _starpu_job *j)
 	{
 		/*if there are workers in the ctx that are not able to execute tasks
 		  we consider the ctx empty */
-		unsigned nworkers = _starpu_nworkers_able_to_execute_task(task, sched_ctx);
+		unsigned able = _starpu_workers_able_to_execute_task(task, sched_ctx);
 
-		if(nworkers == 0)
+		if(!able)
 		{
 			_starpu_sched_ctx_lock_write(sched_ctx->id);
 			starpu_task_list_push_front(&sched_ctx->empty_ctx_tasks, task);
@@ -536,7 +536,6 @@ int _starpu_repush_task(struct _starpu_job *j)
 int _starpu_push_task_to_workers(struct starpu_task *task)
 {
 	struct _starpu_sched_ctx *sched_ctx = _starpu_get_sched_ctx_struct(task->sched_ctx);
-	unsigned nworkers = 0;
 
 	_STARPU_TRACE_JOB_PUSH(task, task->priority > 0);
 
@@ -546,9 +545,9 @@ int _starpu_push_task_to_workers(struct starpu_task *task)
 	{
 		/*if there are workers in the ctx that are not able to execute tasks
 		  we consider the ctx empty */
-		nworkers = _starpu_nworkers_able_to_execute_task(task, sched_ctx);
+		unsigned able = _starpu_workers_able_to_execute_task(task, sched_ctx);
 
-		if (nworkers == 0)
+		if (!able)
 		{
 			_starpu_sched_ctx_lock_write(sched_ctx->id);
 			starpu_task_list_push_back(&sched_ctx->empty_ctx_tasks, task);
@@ -640,7 +639,7 @@ int _starpu_push_task_to_workers(struct starpu_task *task)
 		{
 			STARPU_ASSERT(sched_ctx->sched_policy->push_task);
 			/* check out if there are any workers in the context */
-			nworkers = starpu_sched_ctx_get_nworkers(sched_ctx->id);
+			unsigned nworkers = starpu_sched_ctx_get_nworkers(sched_ctx->id);
 			if (nworkers == 0)
 				ret = -1;
 			else