Browse Source

modular scheds: factorize MCT decision

Samuel Thibault 5 years ago
parent
commit
4bd41a4522

+ 3 - 28
src/sched_policies/component_heft.c

@@ -70,7 +70,7 @@ static int heft_progress_one(struct starpu_sched_component *component)
 	{
 		struct _starpu_mct_data * d = data->mct_data;
 		struct starpu_sched_component * best_component = NULL;
-		unsigned n, i;
+		unsigned n;
 
 		/* Estimated task duration for each child */
 		double estimated_lengths[component->nchildren * ntasks];
@@ -120,8 +120,7 @@ static int heft_progress_one(struct starpu_sched_component *component)
 			}
 		}
 
-		double best_fitness = DBL_MAX;
-		int best_icomponent = -1;
+		STARPU_ASSERT(best_task >= 0);
 
 		/* Push back the other tasks */
 		STARPU_COMPONENT_MUTEX_LOCK(mutex);
@@ -132,35 +131,11 @@ static int heft_progress_one(struct starpu_sched_component *component)
 
 		unsigned offset = component->nchildren * best_task;
 
-		/* And now find out which worker suits best for this task,
-		 * including data transfer */
-		for(i = 0; i < nsuitable_components[best_task]; i++)
-		{
-			unsigned icomponent = suitable_components[offset + i];
-#ifdef STARPU_DEVEL
-#warning FIXME: take energy consumption into account
-#endif
-			double tmp = starpu_mct_compute_fitness(d,
-						     estimated_ends_with_task[offset + icomponent],
-						     min_exp_end_with_task[best_task],
-						     max_exp_end_with_task[best_task],
-						     estimated_transfer_length[offset + icomponent],
-						     0.0);
-
-			if(tmp < best_fitness)
-			{
-				best_fitness = tmp;
-				best_icomponent = icomponent;
-			}
-		}
+		int best_icomponent = starpu_mct_get_best_component(d, tasks[best_task], estimated_lengths + offset, estimated_transfer_length + offset, estimated_ends_with_task + offset, min_exp_end_with_task[best_task], max_exp_end_with_task[best_task], suitable_components + offset, nsuitable_components[best_task]);
 
 		STARPU_ASSERT(best_icomponent != -1);
-		STARPU_ASSERT(best_task >= 0);
 		best_component = component->children[best_icomponent];
 
-		tasks[best_task]->predicted = estimated_lengths[offset + best_icomponent];
-		tasks[best_task]->predicted_transfer = estimated_transfer_length[offset + best_icomponent];
-
 		if(starpu_sched_component_is_worker(best_component))
 		{
 			best_component->can_pull(best_component);

+ 2 - 26
src/sched_policies/component_mct.c

@@ -37,8 +37,6 @@ static int mct_push_task(struct starpu_sched_component * component, struct starp
 	/* Estimated transfer+task termination for each child */
 	double estimated_ends_with_task[component->nchildren];
 
-	unsigned i;
-
 	/* Minimum transfer+task termination on all children */
 	double min_exp_end_with_task;
 	/* Maximum transfer+task termination on all children */
@@ -66,27 +64,8 @@ static int mct_push_task(struct starpu_sched_component * component, struct starp
 	starpu_mct_compute_expected_times(component, task, estimated_lengths, estimated_transfer_length,
 					  estimated_ends_with_task, &min_exp_end_with_task, &max_exp_end_with_task, suitable_components, nsuitable_components);
 
-	double best_fitness = DBL_MAX;
-	int best_icomponent = -1;
-	for(i = 0; i < nsuitable_components; i++)
-	{
-		int icomponent = suitable_components[i];
-#ifdef STARPU_DEVEL
-#warning FIXME: take energy consumption into account
-#endif
-		double tmp = starpu_mct_compute_fitness(d,
-					     estimated_ends_with_task[icomponent],
-					     min_exp_end_with_task,
-					     max_exp_end_with_task,
-					     estimated_transfer_length[icomponent],
-					     0.0);
-
-		if(tmp < best_fitness)
-		{
-			best_fitness = tmp;
-			best_icomponent = icomponent;
-		}
-	}
+	int best_icomponent = starpu_mct_get_best_component(d, task, estimated_lengths, estimated_transfer_length,
+					  estimated_ends_with_task, min_exp_end_with_task, max_exp_end_with_task, suitable_components, nsuitable_components);
 
 	/* If no best component is found, it means that the perfmodel of
 	 * the task had been purged since it has been pushed on the mct component.
@@ -100,9 +79,6 @@ static int mct_push_task(struct starpu_sched_component * component, struct starp
 
 	best_component = component->children[best_icomponent];
 
-	task->predicted = estimated_lengths[best_icomponent];
-	task->predicted_transfer = estimated_transfer_length[best_icomponent];
-
 	if(starpu_sched_component_is_worker(best_component))
 	{
 		best_component->can_pull(best_component);

+ 35 - 0
src/sched_policies/helper_mct.c

@@ -146,3 +146,38 @@ void starpu_mct_compute_expected_times(struct starpu_sched_component *component,
 			*max_exp_end_with_task = estimated_ends_with_task[icomponent];
 	}
 }
+
+int starpu_mct_get_best_component(struct _starpu_mct_data *d, struct starpu_task *task, double *estimated_lengths, double *estimated_transfer_length, double *estimated_ends_with_task, double min_exp_end_with_task, double max_exp_end_with_task, unsigned *suitable_components, unsigned nsuitable_components)
+{
+	double best_fitness = DBL_MAX;
+	int best_icomponent = -1;
+	unsigned i;
+
+	for(i = 0; i < nsuitable_components; i++)
+	{
+		int icomponent = suitable_components[i];
+#ifdef STARPU_DEVEL
+#warning FIXME: take energy consumption into account
+#endif
+		double tmp = starpu_mct_compute_fitness(d,
+					     estimated_ends_with_task[icomponent],
+					     min_exp_end_with_task,
+					     max_exp_end_with_task,
+					     estimated_transfer_length[icomponent],
+					     0.0);
+
+		if(tmp < best_fitness)
+		{
+			best_fitness = tmp;
+			best_icomponent = icomponent;
+		}
+	}
+
+	if (best_icomponent != -1)
+	{
+		task->predicted = estimated_lengths[best_icomponent];
+		task->predicted_transfer = estimated_transfer_length[best_icomponent];
+	}
+
+	return best_icomponent;
+}

+ 10 - 0
src/sched_policies/helper_mct.h

@@ -50,3 +50,13 @@ double starpu_mct_compute_fitness(struct _starpu_mct_data * d,
 				  double max_exp_end,
 				  double transfer_len,
 				  double local_energy);
+
+int starpu_mct_get_best_component(struct _starpu_mct_data *d,
+				  struct starpu_task *task,
+				  double *estimated_lengths,
+				  double *estimated_transfer_length,
+				  double *estimated_ends_with_task,
+				  double min_exp_end_with_task,
+				  double max_exp_end_with_task,
+				  unsigned *suitable_components,
+				  unsigned nsuitable_components);