瀏覽代碼

heft works and eager is defined with regular fifo nodes

Simon Archipoff 12 年之前
父節點
當前提交
1471c703bf

+ 1 - 0
src/core/sched_policy.c

@@ -36,6 +36,7 @@ static struct starpu_sched_policy *predefined_policies[] =
 	&_starpu_sched_tree_eager_policy,
 	&_starpu_sched_tree_random_policy,
 	&_starpu_sched_tree_ws_policy,
+	&_starpu_sched_tree_heft_policy,
 	&_starpu_sched_eager_policy,
 	&_starpu_sched_prio_policy,
 	&_starpu_sched_random_policy,

+ 1 - 1
src/core/sched_policy.h

@@ -68,5 +68,5 @@ extern struct starpu_sched_policy _starpu_sched_peager_policy;
 extern struct starpu_sched_policy _starpu_sched_tree_eager_policy;
 extern struct starpu_sched_policy _starpu_sched_tree_random_policy;
 extern struct starpu_sched_policy _starpu_sched_tree_ws_policy;
-
+extern struct starpu_sched_policy _starpu_sched_tree_heft_policy;
 #endif // __SCHED_POLICY_H__

+ 1 - 87
src/sched_policies/node_eager.c

@@ -2,92 +2,6 @@
 #include <core/sched_policy.h>
 #include "node_sched.h"
 #include "fifo_queues.h"
-/*
-static void _starpu_wake_all_interested_workers(struct starpu_task * task){
-	struct starpu_worker_collection *workers = starpu_sched_ctx_get_worker_collection(task->sched_ctx);
-	struct starpu_sched_ctx_iterator it;
-	if(workers->init_iterator)
-		workers->init_iterator(workers, &it);
-	while(workers->has_next(workers, &it))
-	{
-		unsigned worker = workers->get_next(workers, &it);
-		int nimpl;
-		for(nimpl = 0; nimpl < STARPU_MAXIMPLEMENTATIONS; nimpl++)
-			if(starpu_worker_can_execute_task(worker, task, nimpl))
-			{
-				starpu_pthread_mutex_t *sched_mutex;
-				starpu_pthread_cond_t *sched_cond;
-				starpu_worker_get_sched_condition(worker, &sched_mutex, &sched_cond);
-				_STARPU_PTHREAD_MUTEX_LOCK(sched_mutex);
-				_STARPU_PTHREAD_COND_SIGNAL(sched_cond);
-				_STARPU_PTHREAD_MUTEX_UNLOCK(sched_mutex);
-				break;
-			}
-	}
-
-
-}
-*/
-
-static int _starpu_eager_push_task(struct _starpu_sched_node * node, struct starpu_task * task)
-{
-	STARPU_ASSERT(node->push_task == _starpu_eager_push_task);
-	int ret_val = -1;
-	STARPU_PTHREAD_MUTEX_LOCK(&node->mutex);
-	ret_val = _starpu_fifo_push_task(node->data, task);
-	STARPU_PTHREAD_MUTEX_UNLOCK(&node->mutex);
-	node->available(node);
-	return ret_val;
-}
-
-static struct starpu_task * _starpu_eager_pop_task(struct _starpu_sched_node *node,
-						   unsigned sched_ctx_id)
-{
-	STARPU_ASSERT(node->pop_task == _starpu_eager_pop_task);
-
-	int workerid = starpu_worker_get_id();
-	
-	/* Tell helgrind that it's fine to check for empty fifo without actual
-	 * mutex (it's just a pointer) */
-	/* block until some event happens */
-	if (_starpu_fifo_empty(node->data))
-	{
-		VALGRIND_HG_MUTEX_UNLOCK_PRE(&node->mutex);
-		VALGRIND_HG_MUTEX_UNLOCK_POST(&node->mutex);
-		return NULL;
-	}
-	VALGRIND_HG_MUTEX_UNLOCK_PRE(&node->mutex);
-	VALGRIND_HG_MUTEX_UNLOCK_POST(&node->mutex);
-
-	STARPU_PTHREAD_MUTEX_LOCK(&node->mutex);
-	struct starpu_task* task = _starpu_fifo_pop_task(node->data, workerid);
-	STARPU_PTHREAD_MUTEX_UNLOCK(&node->mutex);
-	if(!task )
-	{
-		struct _starpu_sched_node * father = node->fathers[sched_ctx_id];
-		if(father)
-			task = father->pop_task(father, sched_ctx_id);
-	}
-	return task;
-}
-
-void _starpu_destroy_eager(struct _starpu_sched_node * node)
-{
-	_starpu_destroy_fifo(node->data);
-	_starpu_sched_node_destroy(node);
-}
-
-
-struct _starpu_sched_node * _starpu_sched_node_eager_create(void)
-{
-	struct _starpu_sched_node * node = _starpu_sched_node_create();
-	node->data = _starpu_create_fifo();
-	node->push_task = _starpu_eager_push_task;
-	node->pop_task = _starpu_eager_pop_task;
-	node->childs = NULL;
-	node->destroy_node = _starpu_destroy_eager;
-	return node;
-}
 
 
 
@@ -96,7 +10,7 @@ static void initialize_eager_center_policy(unsigned sched_ctx_id)
 	starpu_sched_ctx_create_worker_collection(sched_ctx_id, STARPU_WORKER_LIST);
 	struct _starpu_sched_tree *data = malloc(sizeof(struct _starpu_sched_tree));
 	STARPU_PTHREAD_MUTEX_INIT(&data->mutex,NULL);
- 	data->root = _starpu_sched_node_eager_create();
+ 	data->root = _starpu_sched_node_fifo_create();
 	
 	starpu_sched_ctx_set_policy_data(sched_ctx_id, (void*)data);
 }

+ 0 - 2
src/sched_policies/node_fifo.c

@@ -78,5 +78,3 @@ struct _starpu_fifo_taskq *  _starpu_sched_node_fifo_get_fifo(struct _starpu_sch
 	STARPU_ASSERT(node->push_task == push_task);
 	return node->data;
 }
-
-

+ 101 - 3
src/sched_policies/node_heft.c

@@ -12,8 +12,6 @@ struct _starpu_dmda_data
 	double idle_power;
 };
 
-
-
 static double compute_fitness_calibration(struct _starpu_sched_node * child,
 					  struct _starpu_dmda_data * data STARPU_ATTRIBUTE_UNUSED,
 					  struct starpu_task * task STARPU_ATTRIBUTE_UNUSED,
@@ -108,6 +106,91 @@ static int push_task(struct _starpu_sched_node * node, struct starpu_task * task
 }
 
 
+
+static void add_child(struct _starpu_sched_node *node,
+		      struct _starpu_sched_node *child,
+		      unsigned sched_ctx_id)
+{
+	STARPU_PTHREAD_MUTEX_LOCK(&node->mutex);
+	int i;
+	for(i = 0; i < node->nchilds; i++){
+		STARPU_ASSERT(node->childs[i] != node);
+		STARPU_ASSERT(node->childs[i] != NULL);
+	}
+	node->childs = realloc(node->childs,
+			       sizeof(struct _starpu_sched_node*)
+			       * (node->nchilds + 1));
+	struct _starpu_sched_node * fifo_node = _starpu_sched_node_fifo_create();
+	_starpu_sched_node_add_child(fifo_node, child, sched_ctx_id);
+
+
+	_starpu_sched_node_set_father(fifo_node, node, sched_ctx_id);
+	node->childs[node->nchilds] = fifo_node;
+	node->nchilds++;
+
+	STARPU_PTHREAD_MUTEX_UNLOCK(&node->mutex);
+
+}
+static void remove_child(struct _starpu_sched_node *node,
+			 struct _starpu_sched_node *child,
+			 unsigned sched_ctx_id)
+{
+	STARPU_PTHREAD_MUTEX_LOCK(&node->mutex);
+	int pos;
+	for(pos = 0; pos < node->nchilds; pos++)
+		if(*node->childs[pos]->childs == child)
+			break;
+	STARPU_ASSERT(pos != node->nchilds);
+	struct _starpu_sched_node * fifo_node = node->childs[pos];
+	node->childs[pos] = node->childs[--node->nchilds];
+	STARPU_ASSERT(fifo_node->fathers[sched_ctx_id] == node);
+	fifo_node->fathers[sched_ctx_id] = NULL;
+	STARPU_PTHREAD_MUTEX_UNLOCK(&node->mutex);
+}
+
+
+
+
+
+static void initialize_heft_center_policy(unsigned sched_ctx_id)
+{
+	starpu_sched_ctx_create_worker_collection(sched_ctx_id, STARPU_WORKER_LIST);
+	struct _starpu_sched_tree *data = malloc(sizeof(struct _starpu_sched_tree));
+	STARPU_PTHREAD_MUTEX_INIT(&data->mutex,NULL);
+	data->root = _starpu_sched_node_heft_create(1,1,1,1);
+	starpu_sched_ctx_set_policy_data(sched_ctx_id, (void*)data);
+}
+
+static void deinitialize_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_tree_destroy(t, sched_ctx_id);
+	starpu_sched_ctx_delete_worker_collection(sched_ctx_id);
+}
+
+
+static void add_worker_heft(unsigned sched_ctx_id, int * workerids, unsigned nworkers)
+{
+	struct _starpu_sched_tree *t = starpu_sched_ctx_get_policy_data(sched_ctx_id);
+	unsigned i;
+	for(i = 0; i < nworkers; i++)
+		t->root->add_child(t->root,
+				   _starpu_sched_node_worker_get(workerids[i]),
+				   sched_ctx_id);
+	_starpu_tree_update_after_modification(t);
+}
+
+static void remove_worker_heft(unsigned sched_ctx_id, int * workerids, unsigned nworkers)
+{
+	struct _starpu_sched_tree *t = starpu_sched_ctx_get_policy_data(sched_ctx_id);
+	unsigned i;
+	for(i = 0; i < nworkers; i++)
+		t->root->remove_child(t->root,
+				   _starpu_sched_node_worker_get(workerids[i]),
+				   sched_ctx_id);
+
+}
+
 struct _starpu_sched_node * _starpu_sched_node_heft_create(double alpha, double beta, double gamma, double idle_power)
 {
 	struct _starpu_sched_node * node = _starpu_sched_node_create();
@@ -122,9 +205,24 @@ struct _starpu_sched_node * _starpu_sched_node_heft_create(double alpha, double
 	node->push_task = push_task;
 	data->alpha = data->beta = data->gamma = data->idle_power = 0.0;
 	//data->total_task_cnt = data->ready_task_cnt = 0;
+	node->add_child = add_child;
+	node->remove_child = remove_child;
 
 	return node;
 }
 
 
-
+struct starpu_sched_policy _starpu_sched_tree_heft_policy =
+{
+	.init_sched = initialize_heft_center_policy,
+	.deinit_sched = deinitialize_heft_center_policy,
+	.add_workers = add_worker_heft,
+	.remove_workers = remove_worker_heft,
+	.push_task = _starpu_tree_push_task,
+	.pop_task = _starpu_tree_pop_task,
+	.pre_exec_hook = NULL,
+	.post_exec_hook = NULL,
+	.pop_every_task = NULL,
+	.policy_name = "tree-heft",
+	.policy_description = "heft tree policy"
+};

+ 3 - 3
src/sched_policies/node_sched.c

@@ -220,7 +220,7 @@ int _starpu_sched_node_can_execute_task(struct _starpu_sched_node * node, struct
 
 int _starpu_sched_node_can_execute_task_with_impl(struct _starpu_sched_node * node, struct starpu_task * task, unsigned nimpl)
 {
-	
+
 	int worker;
 	STARPU_ASSERT(task);
 	STARPU_ASSERT(nimpl < STARPU_MAXIMPLEMENTATIONS);
@@ -245,7 +245,7 @@ struct _starpu_sched_node * _starpu_sched_node_create(void)
 	node->destroy_node = _starpu_sched_node_destroy;
 	node->add_child = _starpu_sched_node_add_child;
 	node->remove_child = _starpu_sched_node_remove_child;
-	
+
 	return node;
 }
 void _starpu_sched_node_destroy(struct _starpu_sched_node *node)
@@ -257,7 +257,7 @@ void _starpu_sched_node_destroy(struct _starpu_sched_node *node)
 		for(j = 0; j < STARPU_NMAX_SCHED_CTXS; j++)
 			if(child->fathers[i] == node)
 				child->fathers[i] = NULL;
-		
+
 	}
 	free(node->childs);
 	free(node);

+ 1 - 1
src/sched_policies/node_sched.h

@@ -117,7 +117,7 @@ struct _starpu_sched_node * _starpu_sched_node_random_create(void);
 
 struct _starpu_sched_node * _starpu_sched_node_eager_create(void);
 
-
+struct _starpu_sched_node * _starpu_sched_node_heft_create(double alpha, double beta, double gamma, double idle_power);