Browse Source

Fix estimated times in dm*, thanks Suraj for the notice

Samuel Thibault 8 years ago
parent
commit
fd78462465

+ 20 - 13
src/sched_policies/component_worker.c

@@ -280,12 +280,6 @@ static inline struct starpu_task * _starpu_worker_task_list_pop(struct _starpu_w
 
 			l->ntasks--;
 
-			if(!isnan(task->predicted))
-			{
-				l->exp_len -= task->predicted_transfer;
-				l->exp_end = l->exp_start + l->exp_len;
-			}
-
 			return task;
 		}
 		t = t->up;
@@ -845,21 +839,34 @@ int starpu_sched_component_worker_get_workerid(struct starpu_sched_component * w
 
 void starpu_sched_component_worker_pre_exec_hook(struct starpu_task * task)
 {
-	if(!isnan(task->predicted))
+	double model = task->predicted;
+	double transfer_model = task->predicted_transfer;
+
+	if(!isnan(task->predicted) || !isnan(task->predicted_transfer))
 	{
 		unsigned sched_ctx_id = task->sched_ctx;
 		struct _starpu_worker_task_list * list = _worker_get_list(sched_ctx_id);
 		STARPU_PTHREAD_MUTEX_LOCK(&list->mutex);
 
-		list->exp_start = starpu_timing_now() + task->predicted;
+		list->exp_start = STARPU_MAX(starpu_timing_now(), list->exp_start);
 
-		if(list->ntasks == 0)
+		/* The transfer is over, get rid of it in the completion
+		 * prediction */
+		if (!isnan(transfer_model))
+			list->exp_len -= transfer_model;
+
+		if (!isnan(model))
 		{
-			list->exp_end = list->exp_start;
-			list->exp_len = 0.0;
+			/* We now start the computation, get rid of it in the
+			 * completion prediction */
+			list->exp_len -= model;
+			list->exp_start += model;
 		}
-		else
-			list->exp_end = list->exp_start + list->exp_len;
+		
+		if(list->ntasks == 0)
+			list->exp_len = 0.0;
+
+		list->exp_end = list->exp_start + list->exp_len;
 		STARPU_PTHREAD_MUTEX_UNLOCK(&list->mutex);
 	}
 }

+ 33 - 63
src/sched_policies/deque_modeling_policy_data_aware.c

@@ -190,27 +190,12 @@ static struct starpu_task *dmda_pop_ready_task(unsigned sched_ctx_id)
 
 	unsigned node = starpu_worker_get_memory_node(workerid);
 
+	/* Take the opportunity to update start time */
+	fifo->exp_start = STARPU_MAX(starpu_timing_now(), fifo->exp_start);
+
 	task = _starpu_fifo_pop_first_ready_task(fifo, node, dt->num_priorities);
 	if (task)
 	{
-		/* We now start the transfer, get rid of it in the completion
-		 * prediction */
-		double transfer_model = task->predicted_transfer;
-		if(!isnan(transfer_model))
-		{
-			fifo->exp_len -= transfer_model;
-			fifo->exp_start = starpu_timing_now() + transfer_model;
-			fifo->exp_end = fifo->exp_start + fifo->exp_len;
-			if(dt->num_priorities != -1)
-			{
-				int i;
-				int task_prio = _normalize_prio(task->priority, dt->num_priorities, task->sched_ctx);
-				for(i = 0; i <= task_prio; i++)
-					fifo->exp_len_per_priority[i] -= transfer_model;
-			}
-
-		}
-
 		starpu_sched_ctx_list_task_counters_decrement(sched_ctx_id, workerid);
 
 #ifdef STARPU_VERBOSE
@@ -237,31 +222,14 @@ static struct starpu_task *dmda_pop_task(unsigned sched_ctx_id)
 	unsigned workerid = starpu_worker_get_id_check();
 	struct _starpu_fifo_taskq *fifo = dt->queue_array[workerid];
 
+	/* Take the opportunity to update start time */
+	fifo->exp_start = STARPU_MAX(starpu_timing_now(), fifo->exp_start);
+
 	STARPU_ASSERT_MSG(fifo, "worker %d does not belong to ctx %d anymore.\n", workerid, sched_ctx_id);
 
 	task = _starpu_fifo_pop_local_task(fifo);
 	if (task)
 	{
-		double transfer_model = task->predicted_transfer;
-		/* We now start the transfer, get rid of it in the completion
-		 * prediction */
-
-		if(!isnan(transfer_model))
-		{
-			double model = task->predicted;
-			fifo->exp_len -= transfer_model;
-			fifo->exp_start = starpu_timing_now() + transfer_model+model;
-			fifo->exp_end = fifo->exp_start + fifo->exp_len;
-			if(dt->num_priorities != -1)
-			{
-				int i;
-				int task_prio = _normalize_prio(task->priority, dt->num_priorities, task->sched_ctx);
-				for(i = 0; i <= task_prio; i++)
-					fifo->exp_len_per_priority[i] -= transfer_model;
-			}
-
-		}
-
 		starpu_sched_ctx_list_task_counters_decrement(sched_ctx_id, workerid);
 
 #ifdef STARPU_VERBOSE
@@ -288,6 +256,9 @@ static struct starpu_task *dmda_pop_every_task(unsigned sched_ctx_id)
 	unsigned workerid = starpu_worker_get_id_check();
 	struct _starpu_fifo_taskq *fifo = dt->queue_array[workerid];
 
+	/* Take the opportunity to update start time */
+	fifo->exp_start = STARPU_MAX(starpu_timing_now(), fifo->exp_start);
+
 	starpu_pthread_mutex_t *sched_mutex;
 	starpu_pthread_cond_t *sched_cond;
 	starpu_worker_get_sched_condition(workerid, &sched_mutex, &sched_cond);
@@ -297,28 +268,6 @@ static struct starpu_task *dmda_pop_every_task(unsigned sched_ctx_id)
 
 	starpu_sched_ctx_list_task_counters_reset(sched_ctx_id, workerid);
 
-	while (new_list)
-	{
-		double transfer_model = new_list->predicted_transfer;
-		/* We now start the transfer, get rid of it in the completion
-		 * prediction */
-		if(!isnan(transfer_model))
-		{
-			fifo->exp_len -= transfer_model;
-			fifo->exp_start = starpu_timing_now() + transfer_model;
-			fifo->exp_end = fifo->exp_start + fifo->exp_len;
-			if(dt->num_priorities != -1)
-			{
-				int i;
-				for(i = 0; i < new_list->priority; i++)
-					fifo->exp_len_per_priority[i] -= transfer_model;
-			}
-
-		}
-
-		new_list = new_list->next;
-	}
-
 	return new_list;
 }
 
@@ -1082,6 +1031,7 @@ static void dmda_pre_exec_hook(struct starpu_task *task)
 	struct _starpu_dmda_data *dt = (struct _starpu_dmda_data*)starpu_sched_ctx_get_policy_data(sched_ctx_id);
 	struct _starpu_fifo_taskq *fifo = dt->queue_array[workerid];
 	double model = task->predicted;
+	double transfer_model = task->predicted_transfer;
 
 	starpu_pthread_mutex_t *sched_mutex;
 	starpu_pthread_cond_t *sched_cond;
@@ -1090,13 +1040,31 @@ static void dmda_pre_exec_hook(struct starpu_task *task)
 	/* Once the task is executing, we can update the predicted amount
 	 * of work. */
 	STARPU_PTHREAD_MUTEX_LOCK_SCHED(sched_mutex);
+
+	/* Take the opportunity to update start time */
+	fifo->exp_start = STARPU_MAX(starpu_timing_now(), fifo->exp_start);
+
+	if(!isnan(transfer_model))
+	{
+		/* The transfer is over, get rid of it in the completion
+		 * prediction */
+		fifo->exp_len -= transfer_model;
+		if(dt->num_priorities != -1)
+		{
+			int i;
+			int task_prio = _normalize_prio(task->priority, dt->num_priorities, task->sched_ctx);
+			for(i = 0; i <= task_prio; i++)
+				fifo->exp_len_per_priority[i] -= transfer_model;
+		}
+
+	}
+
 	if(!isnan(model))
 	{
 		/* We now start the computation, get rid of it in the completion
 		 * prediction */
-		fifo->exp_len-= model;
-		fifo->exp_start = starpu_timing_now() + model;
-		fifo->exp_end= fifo->exp_start + fifo->exp_len;
+		fifo->exp_len -= model;
+		fifo->exp_start += model;
 		if(dt->num_priorities != -1)
 		{
 			int i;
@@ -1105,6 +1073,8 @@ static void dmda_pre_exec_hook(struct starpu_task *task)
 				fifo->exp_len_per_priority[i] -= model;
 		}
 	}
+
+	fifo->exp_end = fifo->exp_start + fifo->exp_len;
 	STARPU_PTHREAD_MUTEX_UNLOCK_SCHED(sched_mutex);
 }