浏览代码

add hypervisor strategy monitoring perf counter (not portable, the counter reading the flops dependent on the architecture)

Andra Hugo 9 年之前
父节点
当前提交
39ccc67d88

+ 1 - 0
include/starpu_sched_ctx.h

@@ -159,6 +159,7 @@ int starpu_sched_ctx_get_worker_rank(unsigned sched_ctx_id);
 
 void (*starpu_sched_ctx_get_sched_policy_init(unsigned sched_ctx_id))(void);
 
+unsigned starpu_sched_ctx_has_starpu_scheduler(unsigned sched_ctx_id, unsigned *awake_workers);
 #ifdef STARPU_USE_SC_HYPERVISOR
 void starpu_sched_ctx_call_pushed_task_cb(int workerid, unsigned sched_ctx_id);
 #endif /* STARPU_USE_SC_HYPERVISOR */

+ 2 - 0
include/starpu_worker.h

@@ -123,6 +123,8 @@ unsigned starpu_worker_is_slave_somewhere(int workerid);
 
 char *starpu_worker_get_type_as_string(enum starpu_worker_archtype type);
 
+int starpu_worker_get_workerids(int bindid, int *workerids);
+
 #ifdef __cplusplus
 }
 #endif

+ 7 - 0
sc_hypervisor/include/sc_hypervisor.h

@@ -66,6 +66,12 @@ struct sc_hypervisor_policy
 	
 	/* the hypervisor takes a decision when a certain ctx was deleted */
 	void (*end_ctx)(unsigned sched_ctx);
+
+	/* the hypervisor takes a decision when a certain ctx was registerd */
+	void (*start_ctx)(unsigned sched_ctx);
+	
+	/* the hypervisor initializes values for the workers */
+	void (*init_worker)(int workerid, unsigned sched_ctx);
 };
 
 /* start the hypervisor indicating the resizing policy to user */
@@ -145,6 +151,7 @@ double sc_hypervisor_get_nready_flops_of_all_sons_of_sched_ctx(unsigned sched_ct
 
 void sc_hypervisor_print_overhead();
 
+void sc_hypervisor_init_worker(int workerid, unsigned sched_ctx);
 #ifdef __cplusplus
 }
 #endif

+ 3 - 2
sc_hypervisor/src/Makefile.am

@@ -12,7 +12,7 @@
 #
 # See the GNU Lesser General Public License in COPYING.LGPL for more details.
 
-AM_CFLAGS = -Wall $(STARPU_CUDA_CPPFLAGS) $(STARPU_OPENCL_CPPFLAGS) $(FXT_CFLAGS) $(MAGMA_CFLAGS) $(HWLOC_CFLAGS) $(GLOBAL_AM_CFLAGS)
+AM_CFLAGS = -Wall $(STARPU_CUDA_CPPFLAGS) $(STARPU_OPENCL_CPPFLAGS) $(FXT_CFLAGS) $(MAGMA_CFLAGS) $(HWLOC_CFLAGS) $(GLOBAL_AM_CFLAGS) -fopenmp
 LIBS = $(top_builddir)/src/libstarpu-@STARPU_EFFECTIVE_VERSION@.la
 AM_CPPFLAGS = -I$(top_builddir)/include -I$(top_srcdir)/include -I$(top_srcdir)/sc_hypervisor/include/ -I$(top_srcdir)/sc_hypervisor/src
 AM_LDFLAGS = $(STARPU_CUDA_LDFLAGS) $(STARPU_OPENCL_LDFLAGS) $(STARPU_COI_LDFLAGS) $(STARPU_SCIF_LDFLAGS)
@@ -38,7 +38,8 @@ libsc_hypervisor_la_SOURCES = 				\
 	hypervisor_policies/ispeed_policy.c		\
 	hypervisor_policies/ispeed_lp_policy.c		\
 	hypervisor_policies/throughput_lp_policy.c	\
-	hypervisor_policies/hard_coded_policy.c
+	hypervisor_policies/hard_coded_policy.c		\
+	hypervisor_policies/perf_count_policy.c
 
 noinst_HEADERS = sc_hypervisor_intern.h		
 

+ 1 - 0
sc_hypervisor/src/hypervisor_policies/app_driven_policy.c

@@ -30,6 +30,7 @@ struct sc_hypervisor_policy app_driven_policy =
 	.handle_post_exec_hook = app_driven_handle_post_exec_hook,
 	.handle_submitted_job = NULL,
 	.end_ctx = NULL,
+	.init_worker = NULL,
 	.custom = 0,
 	.name = "app_driven"
 };

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

@@ -371,6 +371,7 @@ struct sc_hypervisor_policy feft_lp_policy = {
 	.handle_post_exec_hook = NULL,
 	.handle_submitted_job = NULL,
 	.end_ctx = NULL,
+	.init_worker = NULL,
 	.custom = 0,
 	.name = "feft_lp"
 };

+ 1 - 0
sc_hypervisor/src/hypervisor_policies/gflops_rate_policy.c

@@ -305,6 +305,7 @@ struct sc_hypervisor_policy gflops_rate_policy = {
 	.handle_post_exec_hook = NULL,
 	.handle_submitted_job = NULL,
 	.end_ctx = NULL,
+	.init_worker = NULL,
 	.custom = 0,
 	.name = "gflops_rate"
 };

+ 1 - 0
sc_hypervisor/src/hypervisor_policies/hard_coded_policy.c

@@ -112,6 +112,7 @@ struct sc_hypervisor_policy hard_coded_policy =
 	.handle_post_exec_hook = NULL,
 	.handle_submitted_job = NULL,
 	.end_ctx = NULL,
+	.init_worker = NULL,
 	.custom = 0,
 	.name = "hard_coded"
 };

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

@@ -49,6 +49,7 @@ struct sc_hypervisor_policy idle_policy =
 	.handle_post_exec_hook = NULL,
 	.handle_submitted_job = NULL,
 	.end_ctx = NULL,
+	.init_worker = NULL,
 	.custom = 0,
 	.name = "idle"
 };

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

@@ -248,6 +248,7 @@ struct sc_hypervisor_policy ispeed_lp_policy = {
 	.handle_post_exec_hook = NULL,
 	.handle_submitted_job = NULL,
 	.end_ctx = ispeed_lp_end_ctx,
+	.init_worker = NULL,
 	.custom = 0,
 	.name = "ispeed_lp"
 };

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

@@ -189,6 +189,7 @@ struct sc_hypervisor_policy ispeed_policy = {
 	.handle_post_exec_hook = NULL,
 	.handle_submitted_job = NULL,
 	.end_ctx = NULL,
+	.init_worker = NULL,
 	.custom = 0,
 	.name = "ispeed"
 };

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

@@ -338,6 +338,7 @@ struct sc_hypervisor_policy teft_lp_policy = {
 	.handle_post_exec_hook = NULL,
 	.handle_submitted_job = teft_lp_handle_submitted_job,
 	.end_ctx = NULL,
+	.init_worker = NULL,
 	.custom = 0,
 	.name = "teft_lp"
 };

+ 1 - 0
sc_hypervisor/src/hypervisor_policies/throughput_lp_policy.c

@@ -349,6 +349,7 @@ struct sc_hypervisor_policy throughput_lp_policy = {
 	.handle_post_exec_hook = NULL,
 	.handle_submitted_job = NULL,
 	.end_ctx = throughput_lp_end_ctx,
+	.init_worker = NULL,
 	.custom = 0,
 	.name = "throughput_lp"
 };

+ 14 - 1
sc_hypervisor/src/sc_hypervisor.c

@@ -43,6 +43,7 @@ extern struct sc_hypervisor_policy throughput_lp_policy;
 #endif // STARPU_HAVE_GLPK_
 extern struct sc_hypervisor_policy ispeed_policy;
 extern struct sc_hypervisor_policy hard_coded_policy;
+extern struct sc_hypervisor_policy perf_count_policy;
 
 
 static struct sc_hypervisor_policy *predefined_policies[] =
@@ -57,7 +58,8 @@ static struct sc_hypervisor_policy *predefined_policies[] =
 #endif // STARPU_HAVE_GLPK_H
 	&gflops_rate_policy,
 	&ispeed_policy,
-	&hard_coded_policy
+	&hard_coded_policy,
+	&perf_count_policy
 };
 
 static void _load_hypervisor_policy(struct sc_hypervisor_policy *policy)
@@ -74,6 +76,8 @@ static void _load_hypervisor_policy(struct sc_hypervisor_policy *policy)
 	hypervisor.policy.handle_post_exec_hook = policy->handle_post_exec_hook;
 	hypervisor.policy.handle_submitted_job = policy->handle_submitted_job;
 	hypervisor.policy.end_ctx = policy->end_ctx;
+	hypervisor.policy.start_ctx = policy->start_ctx;
+	hypervisor.policy.init_worker = policy->init_worker;
 }
 
 
@@ -331,6 +335,9 @@ void sc_hypervisor_print_overhead()
 /* the hypervisor is in charge only of the contexts registered to it*/
 void sc_hypervisor_register_ctx(unsigned sched_ctx, double total_flops)
 {
+	if(hypervisor.policy.start_ctx)
+		hypervisor.policy.start_ctx(sched_ctx);
+
 	starpu_pthread_mutex_lock(&act_hypervisor_mutex);
 	hypervisor.configurations[sched_ctx] = NULL;
 	hypervisor.resize_requests[sched_ctx] = NULL;
@@ -1684,3 +1691,9 @@ void sc_hypervisor_get_leaves(unsigned *sched_ctxs, int nsched_ctxs, unsigned *l
 	return;
 }
 
+
+void sc_hypervisor_init_worker(int workerid, unsigned sched_ctx)
+{
+	if(hypervisor.policy.init_worker)
+                hypervisor.policy.init_worker(workerid, sched_ctx);
+}

+ 7 - 0
src/core/sched_ctx.c

@@ -2479,3 +2479,10 @@ void (*starpu_sched_ctx_get_sched_policy_init(unsigned sched_ctx_id))(void)
 	struct _starpu_sched_ctx *sched_ctx = _starpu_get_sched_ctx_struct(sched_ctx_id);
 	return sched_ctx->init_sched;
 }
+
+unsigned starpu_sched_ctx_has_starpu_scheduler(unsigned sched_ctx_id, unsigned *awake_workers)
+{
+	struct _starpu_sched_ctx *sched_ctx = _starpu_get_sched_ctx_struct(sched_ctx_id);
+	*awake_workers = sched_ctx->awake_workers;
+	return sched_ctx->sched_policy != NULL;
+}

+ 3 - 3
src/core/tree.c

@@ -23,7 +23,7 @@ void starpu_tree_reset_visited(struct starpu_tree *tree, int *visited)
 	if(tree->arity == 0)
 	{
 		int workerids[STARPU_NMAXWORKERS];
-		int nworkers = _starpu_worker_get_workerids(tree->id, workerids);
+		int nworkers = starpu_worker_get_workerids(tree->id, workerids);
 		int w;
 		for(w = 0; w < nworkers; w++)
 		{
@@ -82,7 +82,7 @@ struct starpu_tree* _get_down_to_leaves(struct starpu_tree *node, int *visited,
 			if(node->nodes[i]->is_pu)
 			{
 				int workerids[STARPU_NMAXWORKERS];
-				int nworkers = _starpu_worker_get_workerids(node->nodes[i]->id, workerids);
+				int nworkers = starpu_worker_get_workerids(node->nodes[i]->id, workerids);
 				int w;
 				for(w = 0; w < nworkers; w++)
 				{
@@ -123,7 +123,7 @@ struct starpu_tree* starpu_tree_get_neighbour(struct starpu_tree *tree, struct s
 				if(father->nodes[i]->is_pu)
 				{
 					int workerids[STARPU_NMAXWORKERS];
-					int nworkers = _starpu_worker_get_workerids(father->nodes[i]->id, workerids);
+					int nworkers = starpu_worker_get_workerids(father->nodes[i]->id, workerids);
 					int w;
 					for(w = 0; w < nworkers; w++)
 					{

+ 1 - 1
src/core/workers.c

@@ -1878,7 +1878,7 @@ int starpu_worker_get_bindid(int workerid)
 	return config.workers[workerid].bindid;
 }
 
-int _starpu_worker_get_workerids(int bindid, int *workerids)
+int starpu_worker_get_workerids(int bindid, int *workerids)
 {
 	unsigned nworkers = starpu_worker_get_count();
 	int nw = 0;

+ 0 - 3
src/core/workers.h

@@ -440,9 +440,6 @@ int starpu_worker_get_nids_by_type(enum starpu_worker_archtype type, int *worker
    the list might not be updated */
 int starpu_worker_get_nids_ctx_free_by_type(enum starpu_worker_archtype type, int *workerids, int maxsize);
 
-/* geet starpu workerids corresponding to the os physical id bindid */
-int _starpu_worker_get_workerids(int bindid, int *workerids);
-
 /* if the current worker has the lock release it */
 void _starpu_unlock_mutex_if_prev_locked();
 

+ 19 - 9
src/worker_collection/worker_tree.c

@@ -39,14 +39,24 @@ static unsigned tree_has_next_unblocked_worker(struct starpu_worker_collection *
 	}
 	int id = -1;
 	int workerids[STARPU_NMAXWORKERS];
-	int nworkers = _starpu_worker_get_workerids(neighbour->id, workerids);
+	int nworkers = starpu_worker_get_workerids(neighbour->id, workerids);
 	int w;
 	for(w = 0; w < nworkers; w++)
 	{
-		if(!it->visited[workerids[w]] && workers->present[workerids[w]] && workers->is_unblocked[workerids[w]])
+		if(!it->visited[workerids[w]] && workers->present[workerids[w]])
 		{
-			id = workerids[w];
-			it->possible_value = neighbour;
+			if(workers->is_unblocked[workerids[w]])
+			{	
+				id = workerids[w];
+				it->possible_value = neighbour;
+			}
+			else
+			{
+				it->visited[workerids[w]] = 1;
+				it->value = neighbour;
+			
+				return tree_has_next_unblocked_worker(workers, it);
+			}
 		}
 	}
 
@@ -73,7 +83,7 @@ static int tree_get_next_unblocked_worker(struct starpu_worker_collection *worke
 
 
 	int workerids[STARPU_NMAXWORKERS];
-	int nworkers = _starpu_worker_get_workerids(neighbour->id, workerids);
+	int nworkers = starpu_worker_get_workerids(neighbour->id, workerids);
 	int w;
 	for(w = 0; w < nworkers; w++)
 	{
@@ -106,7 +116,7 @@ static unsigned tree_has_next_master(struct starpu_worker_collection *workers, s
 	}
 	int id = -1;
 	int workerids[STARPU_NMAXWORKERS];
-	int nworkers = _starpu_worker_get_workerids(neighbour->id, workerids);
+	int nworkers = starpu_worker_get_workerids(neighbour->id, workerids);
 	int w;
 	for(w = 0; w < nworkers; w++)
 	{
@@ -140,7 +150,7 @@ static int tree_get_next_master(struct starpu_worker_collection *workers, struct
 
 
 	int workerids[STARPU_NMAXWORKERS];
-	int nworkers = _starpu_worker_get_workerids(neighbour->id, workerids);
+	int nworkers = starpu_worker_get_workerids(neighbour->id, workerids);
 	int w;
 	for(w = 0; w < nworkers; w++)
 	{
@@ -179,7 +189,7 @@ static unsigned tree_has_next(struct starpu_worker_collection *workers, struct s
 	}
 	int id = -1;
 	int workerids[STARPU_NMAXWORKERS];
-	int nworkers = _starpu_worker_get_workerids(neighbour->id, workerids);
+	int nworkers = starpu_worker_get_workerids(neighbour->id, workerids);
 	int w;
 	for(w = 0; w < nworkers; w++)
 	{
@@ -218,7 +228,7 @@ static int tree_get_next(struct starpu_worker_collection *workers, struct starpu
 
 
 	int workerids[STARPU_NMAXWORKERS];
-	int nworkers = _starpu_worker_get_workerids(neighbour->id, workerids);
+	int nworkers = starpu_worker_get_workerids(neighbour->id, workerids);
 	int w;
 	for(w = 0; w < nworkers; w++)
 	{