Browse Source

handling energy for modular-heft and heteroprio

root 5 years ago
parent
commit
2ce327864f

+ 7 - 1
src/sched_policies/component_heft.c

@@ -77,6 +77,9 @@ static int heft_progress_one(struct starpu_sched_component *component)
 		/* Estimated transfer+task termination for each child */
 		double estimated_ends_with_task[component->nchildren * ntasks];
 
+		/* estimated energy */
+		double local_energy[component->nchildren * ntasks];
+
 		/* Minimum transfer+task termination on all children */
 		double min_exp_end_with_task[ntasks];
 		/* Maximum transfer+task termination on all children */
@@ -102,6 +105,9 @@ static int heft_progress_one(struct starpu_sched_component *component)
 					estimated_ends_with_task + offset,
 					&min_exp_end_with_task[n], &max_exp_end_with_task[n],
 							  suitable_components + offset, nsuitable_components[n]);
+			
+			/* Compute the energy, if provided*/
+			starpu_mct_compute_energy(component, tasks[n], local_energy + offset, suitable_components + offset, nsuitable_components[n]);
 		}
 
 		int best_task = 0;
@@ -129,7 +135,7 @@ static int heft_progress_one(struct starpu_sched_component *component)
 
 		unsigned offset = component->nchildren * best_task;
 
-		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]);
+		int best_icomponent = starpu_mct_get_best_component(d, tasks[best_task], estimated_lengths + offset, estimated_transfer_length + offset, estimated_ends_with_task + offset, local_energy + 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);
 		best_component = component->children[best_icomponent];

+ 16 - 0
src/sched_policies/component_heteroprio.c

@@ -106,6 +106,9 @@ static int heteroprio_progress_accel(struct starpu_sched_component *component, s
 	/* Estimated transfer+task termination for each child */
 	double estimated_ends_with_task[component->nchildren];
 
+	/* provided local energy */
+	double local_energy[component->nchildren];
+
 	/* Minimum transfer+task termination on all children */
 	double min_exp_end_with_task;
 	/* Maximum transfer+task termination on all children */
@@ -158,12 +161,17 @@ static int heteroprio_progress_accel(struct starpu_sched_component *component, s
 			&min_exp_end_with_task, &max_exp_end_with_task,
 			suitable_components, nsuitable_components);
 
+	/* Compute the energy, if provided*/
+	starpu_mct_compute_energy(component, task, local_energy, suitable_components, nsuitable_components);
+
 	/* And now find out which worker suits best for this task,
 	 * including data transfer */
+
 	int best_icomponent = starpu_mct_get_best_component(d, task,
 			estimated_lengths,
 			estimated_transfer_length,
 			estimated_ends_with_task,
+                        local_energy,
 			min_exp_end_with_task, max_exp_end_with_task,
 			suitable_components, nsuitable_components);
 
@@ -236,6 +244,9 @@ static int heteroprio_progress_noaccel(struct starpu_sched_component *component,
 	/* Estimated transfer+task termination for each child */
 	double estimated_ends_with_task[component->nchildren];
 
+	/* estimated energy */
+	double local_energy[component->nchildren];
+
 	/* Minimum transfer+task termination on all children */
 	double min_exp_end_with_task;
 	/* Maximum transfer+task termination on all children */
@@ -267,12 +278,17 @@ static int heteroprio_progress_noaccel(struct starpu_sched_component *component,
 			&min_exp_end_with_task, &max_exp_end_with_task,
 			suitable_components, nsuitable_components);
 
+	/* Compute the energy, if provided*/
+	starpu_mct_compute_energy(component, task, local_energy, suitable_components, nsuitable_components);
+	
 	/* And now find out which worker suits best for this task,
 	 * including data transfer */
+
 	int best_icomponent = starpu_mct_get_best_component(d, task,
 			estimated_lengths,
 			estimated_transfer_length,
 			estimated_ends_with_task,
+                        local_energy,
 			min_exp_end_with_task, max_exp_end_with_task,
 			suitable_components, nsuitable_components);
 

+ 8 - 2
src/sched_policies/component_mct.c

@@ -35,6 +35,9 @@ 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];
 
+	/* estimated energy */
+	double local_energy[component->nchildren];
+
 	/* Minimum transfer+task termination on all children */
 	double min_exp_end_with_task;
 	/* Maximum transfer+task termination on all children */
@@ -58,12 +61,14 @@ static int mct_push_task(struct starpu_sched_component * component, struct starp
 	   make scheduling decisions at the same time */
 	STARPU_COMPONENT_MUTEX_LOCK(&d->scheduling_mutex);
 
-
 	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);
 
+	/* Compute the energy, if provided*/
+	starpu_mct_compute_energy(component, task, local_energy, suitable_components, nsuitable_components);
+
 	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);
+							    estimated_ends_with_task, local_energy, 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.
@@ -105,6 +110,7 @@ static void mct_component_deinit_data(struct starpu_sched_component * component)
 
 int starpu_sched_component_is_mct(struct starpu_sched_component * component)
 {
+
 	return component->push_task == mct_push_task;
 }
 

+ 42 - 9
src/sched_policies/helper_mct.c

@@ -82,11 +82,19 @@ static double compute_expected_time(double now, double predicted_end, double pre
 double starpu_mct_compute_fitness(struct _starpu_mct_data * d, double exp_end, double min_exp_end, double max_exp_end, double transfer_len, double local_energy)
 {
 	/* Note: the expected end includes the data transfer duration, which we want to be able to tune separately */
-
-	return d->alpha * (exp_end - min_exp_end)
-		+ d->beta * transfer_len
-		+ d->_gamma * local_energy
-		+ d->_gamma * d->idle_power * (exp_end - max_exp_end);
+	
+	/* min_exp_end is the minimum end time of the task over all workers */
+	double fitness = d->alpha * (exp_end - min_exp_end) + d->beta * transfer_len + d->_gamma * local_energy;
+	
+	/* max_exp_end is the maximum end time of the workers. If the total execution time is increased, then an 
+          additional energy penalty must be considered*/
+	if(exp_end > max_exp_end)
+		fitness += d->_gamma * d->idle_power * (exp_end - max_exp_end) / 1000000.0;
+	return fitness;
+	/* return d->alpha * (exp_end - min_exp_end) */
+	/* 	+ d->beta * transfer_len */
+	/* 	+ d->_gamma * local_energy / 1000000.0 */
+	/* 	+ d->_gamma * d->idle_power * (exp_end - max_exp_end) / 1000000.0; */
 }
 
 unsigned starpu_mct_compute_execution_times(struct starpu_sched_component *component, struct starpu_task *task,
@@ -138,14 +146,38 @@ void starpu_mct_compute_expected_times(struct starpu_sched_component *component,
 								    estimated_end,
 								    estimated_lengths[icomponent],
 								    estimated_transfer_length[icomponent]);
+		
+		/* estimated_ends_with_task[icomponent]: estimated end of execution on the worker icomponent
+		   estimated_end: estimatated end of the worker
+		   min_exp_end_with_task: minimum estimated execution time of the task over all workers
+		   max_exp_end_with_task: maximum estimated end of all workers 
+		*/
 		if(estimated_ends_with_task[icomponent] < *min_exp_end_with_task)
 			*min_exp_end_with_task = estimated_ends_with_task[icomponent];
-		if(estimated_ends_with_task[icomponent] > *max_exp_end_with_task)
-			*max_exp_end_with_task = estimated_ends_with_task[icomponent];
+		if(estimated_end > *max_exp_end_with_task)
+			*max_exp_end_with_task = estimated_end;
+	}
+}
+
+void starpu_mct_compute_energy(struct starpu_sched_component *component, struct starpu_task *task , double *local_energy, unsigned *suitable_components, unsigned nsuitable_components)
+{
+	unsigned i;
+	for(i = 0; i < nsuitable_components; i++)
+	{
+		unsigned icomponent = suitable_components[i];
+		int nimpl = 0;
+		local_energy[icomponent] = starpu_task_worker_expected_energy(task, icomponent,  component->tree->sched_ctx_id, nimpl);
+		for (nimpl  = 1; nimpl < STARPU_MAXIMPLEMENTATIONS; nimpl++)
+		{
+			double e;
+			e = starpu_task_worker_expected_energy(task, icomponent,  component->tree->sched_ctx_id, nimpl);
+			if (e < local_energy[icomponent])
+				local_energy[icomponent] = e;
+		}
 	}
 }
 
-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)
+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 *local_energy, 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;
@@ -157,12 +189,13 @@ int starpu_mct_get_best_component(struct _starpu_mct_data *d, struct starpu_task
 #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);
+					     local_energy[icomponent]);
 
 		if(tmp < best_fitness)
 		{

+ 8 - 0
src/sched_policies/helper_mct.h

@@ -56,7 +56,15 @@ int starpu_mct_get_best_component(struct _starpu_mct_data *d,
 				  double *estimated_lengths,
 				  double *estimated_transfer_length,
 				  double *estimated_ends_with_task,
+				  double *local_energy,
 				  double min_exp_end_with_task,
 				  double max_exp_end_with_task,
 				  unsigned *suitable_components,
 				  unsigned nsuitable_components);
+
+
+void starpu_mct_compute_energy(struct starpu_sched_component *component,
+			       struct starpu_task *task ,
+			       double *local_energy,
+			       unsigned *suitable_components,
+			       unsigned nsuitable_components);