Sfoglia il codice sorgente

Fix combined workers in modular schedulers, add some modular schedulers

Samuel Thibault 6 anni fa
parent
commit
b5fa08563b

+ 2 - 0
ChangeLog

@@ -18,6 +18,8 @@
 
 StarPU 1.4.0 (svn revision xxxx)
 ==============================================
+New features:
+  * New schedulers modular-pheft, modular-prandom and modular-prandom-prio
 
 StarPU 1.3.0 (svn revision xxxx)
 ==============================================

+ 1 - 0
include/starpu_sched_component.h

@@ -228,6 +228,7 @@ struct starpu_sched_tree *starpu_sched_component_make_scheduler(unsigned sched_c
 #define STARPU_SCHED_SIMPLE_FIFOS_BELOW		(1<<8)
 #define STARPU_SCHED_SIMPLE_FIFOS_BELOW_PRIO	(1<<9)
 #define STARPU_SCHED_SIMPLE_WS_BELOW		(1<<10)
+#define STARPU_SCHED_SIMPLE_COMBINED_WORKERS	(1<<11)
 
 void starpu_sched_component_initialize_simple_scheduler(starpu_sched_component_create_t create_decision_component, void *data, unsigned flags, unsigned sched_ctx_id);
 

+ 2 - 0
include/starpu_worker.h

@@ -130,6 +130,8 @@ int starpu_combined_worker_get_id(void);
 int starpu_combined_worker_get_size(void);
 int starpu_combined_worker_get_rank(void);
 
+void starpu_sched_find_all_worker_combinations(void);
+
 enum starpu_worker_archtype starpu_worker_get_type(int id);
 
 int starpu_worker_get_count_by_type(enum starpu_worker_archtype type);

+ 2 - 0
src/Makefile.am

@@ -297,7 +297,9 @@ libstarpu_@STARPU_EFFECTIVE_VERSION@_la_SOURCES = 		\
 	sched_policies/modular_prio.c				\
 	sched_policies/modular_prio_prefetching.c				\
 	sched_policies/modular_random.c				\
+	sched_policies/modular_parallel_random.c		\
 	sched_policies/modular_random_prefetching.c			\
+	sched_policies/modular_parallel_heft.c			\
 	sched_policies/modular_heft.c				\
 	sched_policies/modular_heft_prio.c			\
 	sched_policies/modular_heft2.c				\

+ 13 - 0
src/core/detect_combined_workers.c

@@ -371,3 +371,16 @@ void _starpu_sched_find_worker_combinations(int *workerids, int nworkers)
 #endif
 	}
 }
+
+void starpu_sched_find_all_worker_combinations(void)
+{
+	const unsigned nbasic_workers = starpu_worker_get_count();
+	int basic_workerids[nbasic_workers];
+	unsigned i;
+	for(i = 0; i < nbasic_workers; i++)
+	{
+		basic_workerids[i] = i;
+	}
+
+	_starpu_sched_find_worker_combinations(basic_workerids, nbasic_workers);
+}

+ 3 - 0
src/core/sched_policy.c

@@ -63,10 +63,13 @@ static struct starpu_sched_policy *predefined_policies[] =
 	&_starpu_sched_modular_random_prio_policy,
 	&_starpu_sched_modular_random_prefetching_policy,
 	&_starpu_sched_modular_random_prio_prefetching_policy,
+	&_starpu_sched_modular_parallel_random_policy,
+	&_starpu_sched_modular_parallel_random_prio_policy,
 	&_starpu_sched_modular_ws_policy,
 	&_starpu_sched_modular_heft_policy,
 	&_starpu_sched_modular_heft_prio_policy,
 	&_starpu_sched_modular_heft2_policy,
+	&_starpu_sched_modular_parallel_heft_policy,
 	&_starpu_sched_eager_policy,
 	&_starpu_sched_prio_policy,
 	&_starpu_sched_random_policy,

+ 3 - 0
src/core/sched_policy.h

@@ -99,10 +99,13 @@ extern struct starpu_sched_policy _starpu_sched_modular_random_policy;
 extern struct starpu_sched_policy _starpu_sched_modular_random_prio_policy;
 extern struct starpu_sched_policy _starpu_sched_modular_random_prefetching_policy;
 extern struct starpu_sched_policy _starpu_sched_modular_random_prio_prefetching_policy;
+extern struct starpu_sched_policy _starpu_sched_modular_parallel_random_policy;
+extern struct starpu_sched_policy _starpu_sched_modular_parallel_random_prio_policy;
 extern struct starpu_sched_policy _starpu_sched_modular_ws_policy;
 extern struct starpu_sched_policy _starpu_sched_modular_heft_policy;
 extern struct starpu_sched_policy _starpu_sched_modular_heft_prio_policy;
 extern struct starpu_sched_policy _starpu_sched_modular_heft2_policy;
+extern struct starpu_sched_policy _starpu_sched_modular_parallel_heft_policy;
 extern struct starpu_sched_policy _starpu_sched_graph_test_policy;
 extern struct starpu_sched_policy _starpu_sched_tree_heft_hierarchical_policy;
 

+ 25 - 3
src/sched_policies/component_sched.c

@@ -225,6 +225,8 @@ void set_properties(struct starpu_sched_component * component)
 	int worker = starpu_bitmap_first(component->workers_in_ctx);
 	if (worker == -1)
 		return;
+	if (starpu_worker_is_combined_worker(worker))
+		return;
 #ifdef STARPU_DEVEL
 #warning FIXME: Not all CUDA devices have the same speed
 #endif
@@ -236,6 +238,8 @@ void set_properties(struct starpu_sched_component * component)
 	    worker != -1;
 	    worker = starpu_bitmap_next(component->workers_in_ctx, worker))
 	{
+		if(starpu_worker_is_combined_worker(worker))
+			continue;
 		if(first_worker != _starpu_get_worker_struct(worker)->worker_mask)
 			is_homogeneous = 0;
 		if(first_memory_node != _starpu_get_worker_struct(worker)->memory_node)
@@ -278,7 +282,23 @@ void _starpu_sched_component_update_workers_in_ctx(struct starpu_sched_component
 		return;
 	struct starpu_bitmap * workers_in_ctx = _starpu_get_worker_mask(sched_ctx_id);
 	starpu_bitmap_unset_and(component->workers_in_ctx,component->workers, workers_in_ctx);
-	unsigned i;
+	unsigned i,j;
+	for(i = starpu_worker_get_count(); i < starpu_worker_get_count() + starpu_combined_worker_get_count(); i++) {
+		if (starpu_bitmap_get(component->workers, i)) {
+			/* Component has this combined worker, check whether the
+			 * context has all the corresponding workers */
+			int worker_size;
+			int *combined_workerid;
+			starpu_combined_worker_get_description(i, &worker_size, &combined_workerid);
+			for (j = 0; j < (unsigned) worker_size; j++)
+				if (!starpu_bitmap_get(workers_in_ctx, combined_workerid[j]))
+					goto nocombined;
+			/* We have all workers, add it */
+			starpu_bitmap_set(component->workers_in_ctx, i);
+		}
+nocombined:
+		(void)0;
+	}
 	for(i = 0; i < component->nchildren; i++)
 	{
 		struct starpu_sched_component * child = component->children[i];
@@ -307,13 +327,15 @@ struct starpu_bitmap * _starpu_get_worker_mask(unsigned sched_ctx_id)
 void starpu_sched_tree_update_workers_in_ctx(struct starpu_sched_tree * t)
 {
 	STARPU_ASSERT(t);
-	_starpu_sched_component_update_workers_in_ctx(t->root, t->sched_ctx_id);
+	if (t->root)
+		_starpu_sched_component_update_workers_in_ctx(t->root, t->sched_ctx_id);
 }
 
 void starpu_sched_tree_update_workers(struct starpu_sched_tree * t)
 {
 	STARPU_ASSERT(t);
-	_starpu_sched_component_update_workers(t->root);
+	if (t->root)
+		_starpu_sched_component_update_workers(t->root);
 }
 
 

+ 12 - 6
src/sched_policies/modular_ez.c

@@ -58,6 +58,15 @@ void starpu_sched_component_initialize_simple_scheduler(starpu_sched_component_c
 	struct starpu_sched_component *no_perfmodel_component = NULL;
 	struct starpu_sched_component *calibrator_component = NULL;
 
+	/* Start building the tree */
+	t = starpu_sched_tree_create(sched_ctx_id);
+	t->root = NULL;
+	starpu_sched_ctx_set_policy_data(sched_ctx_id, (void*)t);
+
+	/* Create combined workers if requested */
+	if (flags & STARPU_SCHED_SIMPLE_COMBINED_WORKERS)
+		starpu_sched_find_all_worker_combinations();
+
 	/* Components parameters */
 
 	if (flags & STARPU_SCHED_SIMPLE_FIFO_ABOVE_PRIO || flags & STARPU_SCHED_SIMPLE_FIFOS_BELOW_PRIO)
@@ -137,10 +146,6 @@ void starpu_sched_component_initialize_simple_scheduler(starpu_sched_component_c
 	}
 	STARPU_ASSERT(nbelow > 0);
 
-	/* Start building the tree */
-	t = starpu_sched_tree_create(sched_ctx_id);
-	t->root = NULL;
-
 	if (nbelow == 1)
 	{
 		/* Oh, no choice, we don't actually need to decide, just
@@ -211,7 +216,8 @@ void starpu_sched_component_initialize_simple_scheduler(starpu_sched_component_c
 	for(i = 0; i < nbelow; i++)
 	{
 		last = decision_component;
-		if (flags & STARPU_SCHED_SIMPLE_FIFOS_BELOW)
+		if (flags & STARPU_SCHED_SIMPLE_FIFOS_BELOW
+			&& !(flags & STARPU_SCHED_SIMPLE_DECIDE_MASK && i >= starpu_worker_get_count()))
 		{
 			struct starpu_sched_component *fifo_below;
 			if (flags & STARPU_SCHED_SIMPLE_FIFOS_BELOW_PRIO)
@@ -315,5 +321,5 @@ void starpu_sched_component_initialize_simple_scheduler(starpu_sched_component_c
 	}
 
 	starpu_sched_tree_update_workers(t);
-	starpu_sched_ctx_set_policy_data(sched_ctx_id, (void*)t);
+	starpu_sched_tree_update_workers_in_ctx(t);
 }

+ 86 - 0
src/sched_policies/modular_parallel_heft.c

@@ -0,0 +1,86 @@
+/* StarPU --- Runtime system for heterogeneous multicore architectures.
+ *
+ * Copyright (C) 2013-2015,2017                           Inria
+ * Copyright (C) 2014,2015,2017                           CNRS
+ * Copyright (C) 2013-2015,2017,2018-2019                      Université de Bordeaux
+ * Copyright (C) 2013                                     Simon Archipoff
+ *
+ * StarPU is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or (at
+ * your option) any later version.
+ *
+ * StarPU is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * See the GNU Lesser General Public License in COPYING.LGPL for more details.
+ */
+
+#include <starpu_sched_component.h>
+#include <starpu_scheduler.h>
+#include <core/detect_combined_workers.h>
+#include <float.h>
+#include <limits.h>
+
+/* The scheduling strategy look like this :
+ *
+ *                                    |
+ *                              window_component
+ *                                    |
+ * mct_component <--push-- perfmodel_select_component --push--> eager_component
+ *          |                                                    |
+ *          |                                                    |
+ *          >----------------------------------------------------<
+ *                    |                                |
+ *              best_impl_component                    best_impl_component
+ *                    |                                |
+ *                prio_component                        prio_component
+ *                    |                                |
+ *               worker_component                   worker_component
+ *
+ * A window contain the tasks that failed to be pushed, so as when the prio_components reclaim
+ * tasks by calling can_push to their parent (classically, just after a successful pop have
+ * been made by its associated worker_component), this call goes up to the window_component which
+ * pops a task from its local queue and try to schedule it by pushing it to the
+ * decision_component. 
+ * Finally, the task will be pushed to the prio_component which is the direct
+ * parent in the tree of the worker_component the task has been scheduled on. This
+ * component will push the task on its local queue if no one of the two thresholds
+ * have been reached for it, or send a push_error signal to its parent.
+ */
+
+static void initialize_parallel_heft_center_policy(unsigned sched_ctx_id)
+{
+	starpu_sched_component_initialize_simple_scheduler((starpu_sched_component_create_t) starpu_sched_component_mct_create, NULL,
+			STARPU_SCHED_SIMPLE_DECIDE_WORKERS |
+			STARPU_SCHED_SIMPLE_COMBINED_WORKERS |
+			STARPU_SCHED_SIMPLE_PERFMODEL |
+			STARPU_SCHED_SIMPLE_FIFO_ABOVE |
+			STARPU_SCHED_SIMPLE_FIFO_ABOVE_PRIO |
+			STARPU_SCHED_SIMPLE_FIFOS_BELOW |
+			STARPU_SCHED_SIMPLE_FIFOS_BELOW_PRIO |
+			STARPU_SCHED_SIMPLE_IMPL, sched_ctx_id);
+}
+
+static void deinitialize_parallel_heft_center_policy(unsigned sched_ctx_id)
+{
+	struct starpu_sched_tree *t = (struct starpu_sched_tree*)starpu_sched_ctx_get_policy_data(sched_ctx_id);
+	starpu_sched_tree_destroy(t);
+}
+
+struct starpu_sched_policy _starpu_sched_modular_parallel_heft_policy =
+{
+	.init_sched = initialize_parallel_heft_center_policy,
+	.deinit_sched = deinitialize_parallel_heft_center_policy,
+	.add_workers = starpu_sched_tree_add_workers,
+	.remove_workers = starpu_sched_tree_remove_workers,
+	.push_task = starpu_sched_tree_push_task,
+	.pop_task = starpu_sched_tree_pop_task,
+	.pre_exec_hook = starpu_sched_component_worker_pre_exec_hook,
+	.post_exec_hook = starpu_sched_component_worker_post_exec_hook,
+	.pop_every_task = NULL,
+	.policy_name = "modular-pheft",
+	.policy_description = "parallel heft modular policy",
+	.worker_type = STARPU_WORKER_LIST,
+};

+ 91 - 0
src/sched_policies/modular_parallel_random.c

@@ -0,0 +1,91 @@
+/* StarPU --- Runtime system for heterogeneous multicore architectures.
+ *
+ * Copyright (C) 2013-2015,2017                           Inria
+ * Copyright (C) 2017                                     CNRS
+ * Copyright (C) 2014,2017,2018-2019                      Université de Bordeaux
+ * Copyright (C) 2013                                     Simon Archipoff
+ *
+ * StarPU is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or (at
+ * your option) any later version.
+ *
+ * StarPU is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * See the GNU Lesser General Public License in COPYING.LGPL for more details.
+ */
+
+#include <starpu_sched_component.h>
+#include <starpu_scheduler.h>
+#include <limits.h>
+
+/* Random scheduler with a fifo queue for its scheduling window */
+
+static void initialize_parallel_random_fifo_center_policy(unsigned sched_ctx_id)
+{
+	starpu_sched_component_initialize_simple_scheduler((starpu_sched_component_create_t) starpu_sched_component_random_create, NULL,
+			STARPU_SCHED_SIMPLE_DECIDE_WORKERS |
+			STARPU_SCHED_SIMPLE_COMBINED_WORKERS |
+			STARPU_SCHED_SIMPLE_FIFO_ABOVE |
+			STARPU_SCHED_SIMPLE_FIFOS_BELOW |
+			STARPU_SCHED_SIMPLE_IMPL, sched_ctx_id);
+}
+
+static void deinitialize_parallel_random_fifo_center_policy(unsigned sched_ctx_id)
+{
+	struct starpu_sched_tree *tree = (struct starpu_sched_tree*)starpu_sched_ctx_get_policy_data(sched_ctx_id);
+	starpu_sched_tree_destroy(tree);
+}
+
+struct starpu_sched_policy _starpu_sched_modular_parallel_random_policy =
+{
+	.init_sched = initialize_parallel_random_fifo_center_policy,
+	.deinit_sched = deinitialize_parallel_random_fifo_center_policy,
+	.add_workers = starpu_sched_tree_add_workers,
+	.remove_workers = starpu_sched_tree_remove_workers,
+	.push_task = starpu_sched_tree_push_task,
+	.pop_task = starpu_sched_tree_pop_task,
+	.pre_exec_hook = NULL,
+	.post_exec_hook = NULL,
+	.pop_every_task = NULL,
+	.policy_name = "modular-prandom",
+	.policy_description = "prandom modular policy",
+	.worker_type = STARPU_WORKER_LIST,
+};
+
+/* Random scheduler with a priority queue for its scheduling window */
+
+static void initialize_parallel_random_prio_center_policy(unsigned sched_ctx_id)
+{
+	starpu_sched_component_initialize_simple_scheduler((starpu_sched_component_create_t) starpu_sched_component_random_create, NULL,
+			STARPU_SCHED_SIMPLE_DECIDE_WORKERS |
+			STARPU_SCHED_SIMPLE_COMBINED_WORKERS |
+			STARPU_SCHED_SIMPLE_FIFO_ABOVE |
+			STARPU_SCHED_SIMPLE_FIFOS_BELOW |
+			STARPU_SCHED_SIMPLE_FIFOS_BELOW_PRIO |
+			STARPU_SCHED_SIMPLE_IMPL, sched_ctx_id);
+}
+
+static void deinitialize_parallel_random_prio_center_policy(unsigned sched_ctx_id)
+{
+	struct starpu_sched_tree *tree = (struct starpu_sched_tree*)starpu_sched_ctx_get_policy_data(sched_ctx_id);
+	starpu_sched_tree_destroy(tree);
+}
+
+struct starpu_sched_policy _starpu_sched_modular_parallel_random_prio_policy =
+{
+	.init_sched = initialize_parallel_random_prio_center_policy,
+	.deinit_sched = deinitialize_parallel_random_prio_center_policy,
+	.add_workers = starpu_sched_tree_add_workers,
+	.remove_workers = starpu_sched_tree_remove_workers,
+	.push_task = starpu_sched_tree_push_task,
+	.pop_task = starpu_sched_tree_pop_task,
+	.pre_exec_hook = NULL,
+	.post_exec_hook = NULL,
+	.pop_every_task = NULL,
+	.policy_name = "modular-prandom-prio",
+	.policy_description = "prandom-prio modular policy",
+	.worker_type = STARPU_WORKER_LIST,
+};

+ 2 - 7
src/sched_policies/parallel_eager.c

@@ -2,7 +2,7 @@
  *
  * Copyright (C) 2011-2013,2015,2017,2018                 Inria
  * Copyright (C) 2011-2014,2016-2019                      CNRS
- * Copyright (C) 2011-2016,2018                           Université de Bordeaux
+ * Copyright (C) 2011-2016,2018-2019                      Université de Bordeaux
  * Copyright (C) 2013                                     Thibaut Lambert
  * Copyright (C) 2011                                     Télécom-SudParis
  *
@@ -51,14 +51,9 @@ static void initialize_peager_common(void)
 		_peager_common_data = common_data;
 
 		const unsigned nbasic_workers = starpu_worker_get_count();
-		int basic_workerids[nbasic_workers];
 		unsigned i;
-		for(i = 0; i < nbasic_workers; i++)
-		{
-			basic_workerids[i] = i;
-		}
 
-		_starpu_sched_find_worker_combinations(basic_workerids, nbasic_workers);
+		starpu_sched_find_all_worker_combinations();
 		const unsigned ncombined_workers = starpu_combined_worker_get_count();
 		common_data->no_combined_workers = ncombined_workers == 0;