Objet : Developers list for StarPU
Archives de la liste
[Starpu-devel] [PATCH] src/sched_policies: add starpu_sched_policies_common.{c, h}, that will contain code that can easily be shared between schedulers.
Chronologique Discussions
- From: Cyril Roelandt <cyril.roelandt@inria.fr>
- To: starpu-devel@lists.gforge.inria.fr
- Subject: [Starpu-devel] [PATCH] src/sched_policies: add starpu_sched_policies_common.{c, h}, that will contain code that can easily be shared between schedulers.
- Date: Tue, 6 Mar 2012 18:31:21 +0100
- List-archive: <http://lists.gforge.inria.fr/pipermail/starpu-devel>
- List-id: "Developers list. For discussion of new features, code changes, etc." <starpu-devel.lists.gforge.inria.fr>
Hello,
This patch creates two new files:
src/sched_policies/starpu_sched_policies_common.c
src/sched_policies/starpu_sched_policies_common.h
that should contain code that can easily be shared among our schedulers. The
header may even be made public, so that users can use this code in their own
schedulers.
Here, the _starpu_compute_best_fitness function is defined, and used in
heft.c.
With this patch, _heft_push_task is smaller and uses less local variables.
_starpu_compute_best_fitness() will probably be easily reusable in pheft and
dmda.
Another way of factorizing this code would have been to pass a function
pointer
to _starpu_compute_best_fitness(), thus allowing every scheduler to define its
own way of computer the fitness metric for a given worker, but it would have
added lots of function calls. Plus, it seems to me that the fitness is always
computed the same way, so this is not really necessary.
Does this look good to you ?
WBR,
Cyril Roelandt.
---
trunk/src/Makefile.am | 2 +
trunk/src/sched_policies/heft.c | 53 +++++-------------
.../sched_policies/starpu_sched_policies_common.c | 61
++++++++++++++++++++
.../sched_policies/starpu_sched_policies_common.h | 29 +++++++++
4 files changed, 106 insertions(+), 39 deletions(-)
create mode 100644 trunk/src/sched_policies/starpu_sched_policies_common.c
create mode 100644 trunk/src/sched_policies/starpu_sched_policies_common.h
diff --git a/trunk/src/Makefile.am b/trunk/src/Makefile.am
index 595a510..413e4cf 100644
--- a/trunk/src/Makefile.am
+++ b/trunk/src/Makefile.am
@@ -75,6 +75,7 @@ noinst_HEADERS =
\
sched_policies/fifo_queues.h \
sched_policies/deque_queues.h \
sched_policies/stack_queues.h \
+ sched_policies/starpu_sched_policies_common.h \
datawizard/footprint.h \
datawizard/datawizard.h \
datawizard/data_request.h \
@@ -159,6 +160,7 @@ libstarpu_@STARPU_EFFECTIVE_VERSION@_la_SOURCES =
\
sched_policies/detect_combined_workers.c \
sched_policies/parallel_heft.c \
sched_policies/parallel_greedy.c \
+ sched_policies/starpu_sched_policies_common.c \
drivers/driver_common/driver_common.c \
datawizard/memory_nodes.c \
datawizard/write_back.c \
diff --git a/trunk/src/sched_policies/heft.c b/trunk/src/sched_policies/heft.c
index 096cfa6..b8e164e 100644
--- a/trunk/src/sched_policies/heft.c
+++ b/trunk/src/sched_policies/heft.c
@@ -23,6 +23,7 @@
#include <core/perfmodel/perfmodel.h>
#include <core/task_bundle.h>
#include <core/workers.h>
+#include <sched_policies/starpu_sched_policies_common.h>
#include <starpu_parameters.h>
#include <starpu_task_bundle.h>
#include <starpu_top.h>
@@ -383,7 +384,6 @@ static int push_conversion_tasks(struct starpu_task
*task, unsigned int workerid
static int _heft_push_task(struct starpu_task *task, unsigned prio)
{
- unsigned worker, nimpl;
int best = -1;
int selected_impl= -1;
@@ -432,45 +432,20 @@ static int _heft_push_task(struct starpu_task *task,
unsigned prio)
}
/*
- * Determine which worker optimizes the fitness metric which is a
- * trade-off between load-balacing, data locality, and energy
- * consumption.
+ * Let's find the "best" worker and the "best" implementation.
*/
-
- double fitness[nworkers][STARPU_MAXIMPLEMENTATIONS];
- double best_fitness = -1;
-
- for (worker = 0; worker < nworkers; worker++)
- {
- for (nimpl = 0; nimpl < STARPU_MAXIMPLEMENTATIONS; nimpl++)
- {
- if (!starpu_worker_can_execute_task(worker, task,
nimpl))
- {
- /* no one on that queue may execute this task
*/
- continue;
- }
-
- fitness[worker][nimpl] =
alpha*(exp_end[worker][nimpl] - best_exp_end)
- +
beta*(local_data_penalty[worker][nimpl])
- +
_gamma*(local_power[worker][nimpl]);
-
- if (exp_end[worker][nimpl] > max_exp_end)
- {
- /* This placement will make the computation
- * longer, take into account the idle
- * consumption of other cpus */
- fitness[worker][nimpl] += _gamma * idle_power
* (exp_end[worker][nimpl] - max_exp_end) / 1000000.0;
- }
-
- if (best == -1 || fitness[worker][nimpl] <
best_fitness)
- {
- /* we found a better solution */
- best_fitness = fitness[worker][nimpl];
- best = worker;
- selected_impl = nimpl;
- }
- }
- }
+ struct _starpu_fitness_args args;
+ args.alpha = alpha;
+ args.beta = beta;
+ args.gamma = _gamma;
+ args.exp_end = exp_end;
+ args.max_exp_end = max_exp_end;
+ args.idle_power = idle_power;
+ args.data_penalty = local_data_penalty;
+ args.power = local_power;
+ args.best_exp_end = best_exp_end;
+
+ _starpu_compute_best_fitness(&args, &best, &selected_impl, task);
/* By now, we must have found a solution */
STARPU_ASSERT(best != -1);
diff --git a/trunk/src/sched_policies/starpu_sched_policies_common.c
b/trunk/src/sched_policies/starpu_sched_policies_common.c
new file mode 100644
index 0000000..9714541
--- /dev/null
+++ b/trunk/src/sched_policies/starpu_sched_policies_common.c
@@ -0,0 +1,61 @@
+#include <sched_policies/starpu_sched_policies_common.h>
+
+void
+_starpu_compute_best_fitness(struct _starpu_fitness_args *_args,
+ int *selected_worker,
+ int *selected_impl,
+ struct starpu_task *task)
+{
+ unsigned int worker, nworkers, impl;
+ nworkers = starpu_worker_get_count();
+ STARPU_ASSERT(nworkers > 0);
+
+ double fitness[nworkers][STARPU_MAXIMPLEMENTATIONS];
+ double best_fitness = -1;
+ *selected_worker = -1;
+
+ /* Unpacking the variables needed to compute the fitness */
+ struct _starpu_fitness_args *args;
+ args = (struct _starpu_fitness_args *) _args;
+ double alpha = args->alpha;
+ double beta = args->beta;
+ double gamma = args->gamma;
+ double best_exp_end = args->best_exp_end;
+ double max_exp_end = args->max_exp_end;
+ double idle_power = args->idle_power;
+ double (*exp_end)[STARPU_MAXIMPLEMENTATIONS] = args->exp_end;
+ double (*data_penalty)[STARPU_MAXIMPLEMENTATIONS] =
args->data_penalty;
+ double (*power)[STARPU_MAXIMPLEMENTATIONS] = args->power;
+
+ for (worker = 0; worker < nworkers; worker++)
+ {
+ for (impl = 0; impl < STARPU_MAXIMPLEMENTATIONS; impl++)
+ {
+ if (!starpu_worker_can_execute_task(worker, task,
impl))
+ {
+ /* No one on that queue may execute this task
*/
+ continue;
+ }
+
+ fitness[worker][impl] = alpha *
(exp_end[worker][impl] - best_exp_end)
+ + beta *
data_penalty[worker][impl]
+ + gamma * power[worker][impl];
+
+ if (exp_end[worker][impl] > max_exp_end)
+ {
+ /* This placement will make the computation
+ * longer, take into account the idle
+ * consumption of other cpus */
+ fitness[worker][impl] += gamma * idle_power *
(exp_end[worker][impl] - max_exp_end) / 1000000.0;
+ }
+
+ if (*selected_worker == -1 || fitness[worker][impl] <
best_fitness)
+ {
+ /* We found a better solution */
+ best_fitness = fitness[worker][impl];
+ *selected_worker = worker;
+ *selected_impl = impl;
+ }
+ }
+ }
+}
diff --git a/trunk/src/sched_policies/starpu_sched_policies_common.h
b/trunk/src/sched_policies/starpu_sched_policies_common.h
new file mode 100644
index 0000000..d65f03e
--- /dev/null
+++ b/trunk/src/sched_policies/starpu_sched_policies_common.h
@@ -0,0 +1,29 @@
+#ifndef __STARPU_SCHED_POLICIES_COMMON_H__
+#define __STARPU_SCHED_POLICIES_COMMON_H__
+
+#include <starpu.h>
+#include <starpu_task.h>
+
+struct _starpu_fitness_args
+{
+ double alpha, beta, gamma;
+ double best_exp_end;
+ double max_exp_end;
+ double idle_power;
+ double (*exp_end)[STARPU_MAXIMPLEMENTATIONS];
+ double (*data_penalty)[STARPU_MAXIMPLEMENTATIONS];
+ double (*power)[STARPU_MAXIMPLEMENTATIONS];
+};
+
+/*
+ * Determine which worker optimizes the fitness metric which is a
+ * trade-off between load-balacing, data locality, and energy
+ * consumption.
+ */
+void
+_starpu_compute_best_fitness(struct _starpu_fitness_args *args,
+ int *selected_worker,
+ int *selected_impl,
+ struct starpu_task *task);
+
+#endif /* __STARPU_SCHED_POLICIES_COMMON_H__ */
--
1.7.9
- [Starpu-devel] [PATCH] src/sched_policies: add starpu_sched_policies_common.{c, h}, that will contain code that can easily be shared between schedulers., Cyril Roelandt, 06/03/2012
Archives gérées par MHonArc 2.6.19+.