Browse Source

fixes + refact in the hyp

Andra Hugo 12 years ago
parent
commit
d0b859619b

+ 2 - 3
sc_hypervisor/include/sc_hypervisor_policy.h

@@ -94,12 +94,11 @@ double sc_hypervisor_get_velocity_per_worker_type(struct sc_hypervisor_wrapper*
 /* compute the velocity of a type of worker in a context depending on its history */ 
 double sc_hypervisor_get_ref_velocity_per_worker_type(struct sc_hypervisor_wrapper* sc_w, enum starpu_worker_archtype arch);
 
-/* check if there are contexts a lot more delayed than others */
-int sc_hypervisor_has_velocity_gap_btw_ctxs(void);
-
 /* get the list of workers grouped by type */
 void sc_hypervisor_group_workers_by_type(int *workers, int nworkers, int ntypes_of_workers, int total_nw[ntypes_of_workers]);
 
+/* check if we trigger resizing or not */
+unsigned sc_hypervisor_criteria_fulfilled(unsigned sched_ctx, int worker);
 
 #ifdef __cplusplus
 }

+ 1 - 1
sc_hypervisor/src/hypervisor_policies/debit_lp_policy.c

@@ -232,7 +232,7 @@ static void debit_lp_handle_poped_task(unsigned sched_ctx, int worker, struct st
 	int ret = starpu_pthread_mutex_trylock(&act_hypervisor_mutex);
 	if(ret != EBUSY)
 	{
-		if(sc_hypervisor_has_velocity_gap_btw_ctxs())
+		if(sc_hypervisor_criteria_fulfilled(sched_ctx, worker))
 		{
 			int ns = sc_hypervisor_get_nsched_ctxs();
 			int nw = starpu_worker_get_count(); /* Number of different workers */

+ 1 - 1
sc_hypervisor/src/hypervisor_policies/feft_lp_policy.c

@@ -21,7 +21,7 @@
 #ifdef STARPU_HAVE_GLPK_H
 static void feft_lp_handle_poped_task(unsigned sched_ctx, int worker, struct starpu_task *task, uint32_t footprint)
 {
-	if(sc_hypervisor_has_velocity_gap_btw_ctxs())
+	if(sc_hypervisor_criteria_fulfilled(sched_ctx, worker))
 	{
 		int nsched_ctxs = sc_hypervisor_get_nsched_ctxs();
 

+ 1 - 3
sc_hypervisor/src/hypervisor_policies/idle_policy.c

@@ -30,9 +30,7 @@ unsigned worker_belong_to_other_sched_ctx(unsigned sched_ctx, int worker)
 
 void idle_handle_idle_cycle(unsigned sched_ctx, int worker)
 {
-	struct sc_hypervisor_wrapper* sc_w = sc_hypervisor_get_wrapper(sched_ctx);
-	struct sc_hypervisor_policy_config *config = sc_w->config;
-	if(config != NULL &&  sc_w->current_idle_time[worker] > config->max_idle[worker])
+	if(sc_hypervisor_criteria_fulfilled(sched_ctx, worker))
 	{
 		if(worker_belong_to_other_sched_ctx(sched_ctx, worker))
 			sc_hypervisor_remove_workers_from_sched_ctx(&worker, 1, sched_ctx, 1);

+ 1 - 1
sc_hypervisor/src/hypervisor_policies/ispeed_lp_policy.c

@@ -334,7 +334,7 @@ static void ispeed_lp_handle_poped_task(unsigned sched_ctx, int worker, struct s
 	int ret = starpu_pthread_mutex_trylock(&act_hypervisor_mutex);
 	if(ret != EBUSY)
 	{
-		if(sc_hypervisor_has_velocity_gap_btw_ctxs())
+		if(sc_hypervisor_criteria_fulfilled(sched_ctx, worker))
 		{
 			int ns = sc_hypervisor_get_nsched_ctxs();
 			int nw = starpu_worker_get_count(); /* Number of different workers */

+ 1 - 1
sc_hypervisor/src/hypervisor_policies/ispeed_policy.c

@@ -146,7 +146,7 @@ static void ispeed_handle_poped_task(unsigned sched_ctx, int worker, struct star
 	int ret = starpu_pthread_mutex_trylock(&act_hypervisor_mutex);
 	if(ret != EBUSY)
 	{
-		if(sc_hypervisor_has_velocity_gap_btw_ctxs())
+		if(sc_hypervisor_criteria_fulfilled(sched_ctx, worker))
 		{
 			unsigned fastest_sched_ctx = _get_fastest_sched_ctx();
 			unsigned slowest_sched_ctx = _get_slowest_sched_ctx();

+ 1 - 1
sc_hypervisor/src/hypervisor_policies/teft_lp_policy.c

@@ -168,7 +168,7 @@ static void teft_lp_handle_poped_task(unsigned sched_ctx, int worker, struct sta
 			return;
 		}
 
-		if(sc_hypervisor_has_velocity_gap_btw_ctxs())
+		if(sc_hypervisor_criteria_fulfilled(sched_ctx, worker))
 		{
 			int ns = sc_hypervisor_get_nsched_ctxs();
 			int nw = starpu_worker_get_count(); /* Number of different workers */

+ 25 - 3
sc_hypervisor/src/policies_utils/policy_tools.c

@@ -16,7 +16,7 @@
 
 
 #include "sc_hypervisor_policy.h"
-
+#include "sc_hypervisor_intern.h"
 static int _compute_priority(unsigned sched_ctx)
 {
 	struct sc_hypervisor_policy_config *config = sc_hypervisor_get_config(sched_ctx);
@@ -526,7 +526,7 @@ double sc_hypervisor_get_velocity_per_worker_type(struct sc_hypervisor_wrapper*
 
 
 /* check if there is a big velocity gap between the contexts */
-int sc_hypervisor_has_velocity_gap_btw_ctxs()
+unsigned _check_velocity_gap_btw_ctxs()
 {
 	int *sched_ctxs = sc_hypervisor_get_sched_ctxs();
 	int nsched_ctxs = sc_hypervisor_get_nsched_ctxs();
@@ -554,7 +554,7 @@ int sc_hypervisor_has_velocity_gap_btw_ctxs()
 					{
 						double gap = ctx_v < other_ctx_v ? other_ctx_v / ctx_v : ctx_v / other_ctx_v ;
 //						if(gap > 1.5)
-						if(gap > 3.0)
+						if(gap > _get_max_velocity_gap())
 							return 1;
 					}
 				}
@@ -628,3 +628,25 @@ void sc_hypervisor_get_tasks_times(int nw, int nt, double times[nw][nt], int *wo
         }
 }
 
+static unsigned _check_idle(unsigned sched_ctx, int worker)
+{
+	struct sc_hypervisor_wrapper* sc_w = sc_hypervisor_get_wrapper(sched_ctx);
+	struct sc_hypervisor_policy_config *config = sc_w->config;
+	if(config != NULL &&  sc_w->current_idle_time[worker] > config->max_idle[worker])
+		return 1;
+	return 0;
+}
+
+unsigned sc_hypervisor_criteria_fulfilled(unsigned sched_ctx, int worker)
+{
+	unsigned criteria = _get_resize_criteria();
+	if(criteria != SC_NOTHING)
+	{
+		if(criteria == SC_IDLE)
+			return _check_idle(sched_ctx, worker);
+		else
+			return _check_velocity_gap_btw_ctxs();
+	}
+	else
+		return 0;
+}

+ 31 - 13
sc_hypervisor/src/sc_hypervisor.c

@@ -133,6 +133,11 @@ struct starpu_sched_ctx_performance_counters* sc_hypervisor_init(struct sc_hyper
 {
 	hypervisor.min_tasks = 0;
 	hypervisor.nsched_ctxs = 0;
+	char* vel_gap = getenv("MAX_VELOCITY_GAP");
+	hypervisor.max_velocity_gap = vel_gap ? atof(vel_gap) : SC_VELOCITY_MAX_GAP_DEFAULT;
+	char* crit =  getenv("HYPERVISOR_TRIGGER_RESIZE");
+	hypervisor.resize_criteria = strcmp(crit,"idle") == 0 ? SC_IDLE : (strcmp(crit,"speed") == 0 ? SC_SPEED : SC_NOTHING);
+
 	starpu_pthread_mutex_init(&act_hypervisor_mutex, NULL);
 	hypervisor.start_executing_time = starpu_timing_now();
 	int i;
@@ -210,21 +215,24 @@ void sc_hypervisor_start_resize(unsigned sched_ctx)
 
 static void _print_current_time()
 {
-	double curr_time = starpu_timing_now();
-	double elapsed_time = (curr_time - hypervisor.start_executing_time) / 1000000.0; /* in seconds */
-	fprintf(stdout, "Time: %lf\n", elapsed_time);
-	int i;
-	for(i = 0; i < STARPU_NMAX_SCHED_CTXS; i++)
+	if(!getenv("HYPERVISOR_STOP_PRINT"))
 	{
-		if(hypervisor.sched_ctxs[i] != STARPU_NMAX_SCHED_CTXS)
+		double curr_time = starpu_timing_now();
+		double elapsed_time = (curr_time - hypervisor.start_executing_time) / 1000000.0; /* in seconds */
+		fprintf(stdout, "Time: %lf\n", elapsed_time);
+		int i;
+		for(i = 0; i < STARPU_NMAX_SCHED_CTXS; i++)
 		{
-			struct sc_hypervisor_wrapper *sc_w = &hypervisor.sched_ctx_w[hypervisor.sched_ctxs[i]];
-
-			double cpu_speed = sc_hypervisor_get_velocity(sc_w, STARPU_CPU_WORKER);
-			double cuda_speed = sc_hypervisor_get_velocity(sc_w, STARPU_CUDA_WORKER);
-			int ncpus = sc_hypervisor_get_nworkers_ctx(sc_w->sched_ctx, STARPU_CPU_WORKER);
-			int ncuda = sc_hypervisor_get_nworkers_ctx(sc_w->sched_ctx, STARPU_CUDA_WORKER);
-			fprintf(stdout, "%d: cpu_v = %lf cuda_v = %lf ncpus = %d ncuda = %d\n", hypervisor.sched_ctxs[i], cpu_speed, cuda_speed, ncpus, ncuda);
+			if(hypervisor.sched_ctxs[i] != STARPU_NMAX_SCHED_CTXS)
+			{
+				struct sc_hypervisor_wrapper *sc_w = &hypervisor.sched_ctx_w[hypervisor.sched_ctxs[i]];
+				
+				double cpu_speed = sc_hypervisor_get_velocity(sc_w, STARPU_CPU_WORKER);
+				double cuda_speed = sc_hypervisor_get_velocity(sc_w, STARPU_CUDA_WORKER);
+				int ncpus = sc_hypervisor_get_nworkers_ctx(sc_w->sched_ctx, STARPU_CPU_WORKER);
+				int ncuda = sc_hypervisor_get_nworkers_ctx(sc_w->sched_ctx, STARPU_CUDA_WORKER);
+				fprintf(stdout, "%d: cpu_v = %lf cuda_v = %lf ncpus = %d ncuda = %d\n", hypervisor.sched_ctxs[i], cpu_speed, cuda_speed, ncpus, ncuda);
+			}
 		}
 	}
 	return;
@@ -364,6 +372,16 @@ static double _get_best_total_elapsed_flops(struct sc_hypervisor_wrapper* sc_w,
 	return ret_val;
 }
 
+double _get_max_velocity_gap()
+{
+	return hypervisor.max_velocity_gap;
+}
+
+unsigned _get_resize_criteria()
+{
+	return hypervisor.resize_criteria;
+}
+
 /* compute an average value of the cpu/cuda velocity */
 double sc_hypervisorsc_hypervisor_get_velocity_per_worker_type(struct sc_hypervisor_wrapper* sc_w, enum starpu_worker_archtype arch)
 {

+ 15 - 0
sc_hypervisor/src/sc_hypervisor_intern.h

@@ -16,6 +16,11 @@
 
 #include <sc_hypervisor.h>
 #include <common/uthash.h>
+
+#define SC_VELOCITY_MAX_GAP_DEFAULT 50
+#define SC_NOTHING 0
+#define SC_IDLE 1
+#define SC_SPEED 2
 struct size_request
 {
 	int *workers;
@@ -74,6 +79,12 @@ struct sc_hypervisor
 
 	/* time when the hypervisor started */
 	double start_executing_time;
+
+	/* max velocity diff btw ctx before triggering resizing */
+	double max_velocity_gap;
+	
+	/* criteria to trigger resizing */
+	unsigned resize_criteria;
 };
 
 struct sc_hypervisor_adjustment
@@ -88,3 +99,7 @@ struct sc_hypervisor hypervisor;
 void _add_config(unsigned sched_ctx);
 
 void _remove_config(unsigned sched_ctx);
+
+double _get_max_velocity_gap();
+
+unsigned _get_resize_criteria();