浏览代码

small modifs

Andra Hugo 14 年之前
父节点
当前提交
2c5c828774

+ 2 - 0
src/Makefile.am

@@ -93,6 +93,7 @@ noinst_HEADERS = 						\
 	common/fxt.h						\
 	common/utils.h						\
 	common/barrier.h					\
+	common/barrier_counter.h				\
 	drivers/driver_common/driver_common.h			\
 	drivers/cpu/driver_cpu.h				\
 	drivers/gordon/driver_gordon.h				\
@@ -108,6 +109,7 @@ noinst_HEADERS = 						\
 
 libstarpu_la_SOURCES = 						\
 	common/barrier.c					\
+	common/barrier_counter.c					\
 	common/hash.c 						\
 	common/htable32.c					\
 	common/rwlock.c						\

+ 92 - 0
src/common/barrier_counter.c

@@ -0,0 +1,92 @@
+/* StarPU --- Runtime system for heterogeneous multicore architectures.
+ *
+ * Copyright (C) 2010  Centre National de la Recherche Scientifique
+ *
+ * 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 <common/barrier_counter.h>
+
+int _starpu_barrier_counter_init(struct _starpu_barrier_counter_t *barrier_c, int count)
+{
+	_starpu_barrier_init(&barrier_c->barrier, count);
+	pthread_cond_init(&barrier_c->cond2, NULL);
+	return 0;
+}
+
+int _starpu_barrier_counter_destroy(struct _starpu_barrier_counter_t *barrier_c)
+{
+	_starpu_barrier_destroy(&barrier_c->barrier);
+	pthread_cond_destroy(&barrier_c->cond2);
+	return 0;
+}
+
+
+int _starpu_barrier_counter_wait_for_empty_counter(struct _starpu_barrier_counter_t *barrier_c)
+{
+	_starpu_barrier_t *barrier = &barrier_c->barrier;
+	PTHREAD_MUTEX_LOCK(&barrier->mutex);
+
+	while (barrier->reached > 0)
+		PTHREAD_COND_WAIT(&barrier->cond, &barrier->mutex);
+
+	PTHREAD_MUTEX_UNLOCK(&barrier->mutex);
+	return 0;
+}
+
+int _starpu_barrier_counter_wait_for_full_counter(struct _starpu_barrier_counter_t *barrier_c)
+{
+	_starpu_barrier_t *barrier = &barrier_c->barrier;
+	PTHREAD_MUTEX_LOCK(&barrier->mutex);
+
+	while (barrier->reached < barrier->count)
+		PTHREAD_COND_WAIT(&barrier_c->cond2, &barrier->mutex);
+
+	PTHREAD_MUTEX_UNLOCK(&barrier->mutex);
+	return 0;
+}
+
+int _starpu_barrier_counter_decrement_until_empty_counter(struct _starpu_barrier_counter_t *barrier_c)
+{
+	_starpu_barrier_t *barrier = &barrier_c->barrier;
+	PTHREAD_MUTEX_LOCK(&barrier->mutex);
+
+	if (--barrier->reached == 0)
+		PTHREAD_COND_BROADCAST(&barrier->cond);
+
+	PTHREAD_MUTEX_UNLOCK(&barrier->mutex);
+	return 0;
+}
+
+int _starpu_barrier_counter_increment_until_full_counter(struct _starpu_barrier_counter_t *barrier_c)
+{
+	_starpu_barrier_t *barrier = &barrier_c->barrier;
+	PTHREAD_MUTEX_LOCK(&barrier->mutex);
+	
+	if(++barrier->reached == barrier->count)
+		PTHREAD_COND_BROADCAST(&barrier_c->cond2);
+
+	PTHREAD_MUTEX_UNLOCK(&barrier->mutex);
+	return 0;
+}
+
+int _starpu_barrier_counter_increment(struct _starpu_barrier_counter_t *barrier_c)
+{
+	_starpu_barrier_t *barrier = &barrier_c->barrier;
+	PTHREAD_MUTEX_LOCK(&barrier->mutex);
+
+	barrier->reached++;
+	
+	PTHREAD_MUTEX_UNLOCK(&barrier->mutex);
+	return 0;
+}
+

+ 37 - 0
src/common/barrier_counter.h

@@ -0,0 +1,37 @@
+/* StarPU --- Runtime system for heterogeneous multicore architectures.
+ *
+ * Copyright (C) 2010  Centre National de la Recherche Scientifique
+ *
+ * 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 <common/utils.h>
+#include <common/barrier.h>
+
+struct _starpu_barrier_counter_t {
+	_starpu_barrier_t barrier;
+	pthread_cond_t cond2;
+};
+
+int _starpu_barrier_counter_init(struct _starpu_barrier_counter_t *barrier_c, int count);
+
+int _starpu_barrier_counter_destroy(struct _starpu_barrier_counter_t *barrier_c);
+
+int _starpu_barrier_counter_wait_for_empty_counter(struct _starpu_barrier_counter_t *barrier_c);
+
+int _starpu_barrier_counter_wait_for_full_counter(struct _starpu_barrier_counter_t *barrier_c);
+
+int _starpu_barrier_counter_decrement_until_empty_counter(struct _starpu_barrier_counter_t *barrier_c);
+
+int _starpu_barrier_counter_increment_until_full_counter(struct _starpu_barrier_counter_t *barrier_c);
+
+int _starpu_barrier_counter_increment(struct _starpu_barrier_counter_t *barrier_c);
+

+ 1 - 1
src/drivers/cpu/driver_cpu.c

@@ -162,7 +162,7 @@ void *_starpu_cpu_worker(void *arg)
 		PTHREAD_MUTEX_LOCK(changing_ctx_mutex);
 
 		if(cpu_arg->blocking_status == STATUS_CHANGING_CTX){
-			_starpu_increment_nblocked_ths(cpu_arg->nworkers_of_next_ctx);
+			_starpu_increment_nblocked_ths();
 			_starpu_block_worker(workerid, changing_ctx_cond, changing_ctx_mutex);
 			_starpu_decrement_nblocked_ths();
 		}

+ 1 - 1
src/drivers/cuda/driver_cuda.c

@@ -289,7 +289,7 @@ void *_starpu_cuda_worker(void *arg)
                 PTHREAD_MUTEX_LOCK(changing_ctx_mutex);
 
                 if(args->blocking_status == STATUS_CHANGING_CTX){
-			_starpu_increment_nblocked_ths(args->nworkers_of_next_ctx);
+			_starpu_increment_nblocked_ths();
 			_starpu_block_worker(workerid, changing_ctx_cond, changing_ctx_mutex);
 			_starpu_decrement_nblocked_ths();
                 }

+ 10 - 2
src/sched_policies/heft.c

@@ -44,10 +44,15 @@ static void heft_init_for_workers(unsigned sched_ctx_id, int nnew_workers)
 	unsigned nworkers_ctx = sched_ctx->nworkers_in_ctx;
 	heft_data *hd = (heft_data*)sched_ctx->policy_data;
 
-	unsigned initial_nworkers = nworkers_ctx - nnew_workers;
+	//	unsigned initial_nworkers = nworkers_ctx - nnew_workers;
+	struct starpu_machine_config_s *config = (struct starpu_machine_config_s *)_starpu_get_machine_config();
+
+	unsigned ntotal_workers = config->topology.nworkers;
+
+	unsigned all_workers = nnew_workers == ntotal_workers ? ntotal_workers : nworkers_ctx + nnew_workers;
 
 	unsigned workerid_ctx;
-	for (workerid_ctx = initial_nworkers; workerid_ctx < nworkers_ctx; workerid_ctx++)
+	for (workerid_ctx = nworkers_ctx; workerid_ctx < all_workers; workerid_ctx++)
 	  {
 	    hd->exp_start[workerid_ctx] = starpu_timing_now();
 	    hd->exp_len[workerid_ctx] = 0.0;
@@ -59,6 +64,7 @@ static void heft_init_for_workers(unsigned sched_ctx_id, int nnew_workers)
 	    PTHREAD_MUTEX_INIT(sched_ctx->sched_mutex[workerid_ctx], NULL);
 	    PTHREAD_COND_INIT(sched_ctx->sched_cond[workerid_ctx], NULL);
 	  }
+	sched_ctx->nworkers_in_ctx = all_workers;
 }
 static void heft_init(unsigned sched_ctx_id)
 {
@@ -180,6 +186,7 @@ static int push_task_on_best_worker(struct starpu_task *task, int best_workerid,
 		unsigned memory_node = starpu_worker_get_memory_node(best_workerid);
 		starpu_prefetch_task_input_on_node(task, memory_node);
 	}
+	
 	return starpu_push_local_task(best_workerid, task, prio);
 }
 
@@ -329,6 +336,7 @@ static int _heft_push_task(struct starpu_task *task, unsigned prio, unsigned sch
 	for (worker_in_ctx = 0; worker_in_ctx < nworkers_in_ctx; worker_in_ctx++)
 	{
 		worker = sched_ctx->workerid[worker_in_ctx];
+
 		if (!starpu_worker_may_execute_task(worker, task))
 		{
 			/* no one on that queue may execute this task */

+ 0 - 1
src/util/starpu_insert_task_utils.c

@@ -201,7 +201,6 @@ static void _starpu_prepare_task(char *arg_buffer, starpu_codelet *cl, struct st
 int _starpu_insert_task_create_and_submit(char *arg_buffer, starpu_codelet *cl, struct starpu_task **task, va_list varg_list) {
 	unsigned ctx = 0;
 	_starpu_prepare_task(arg_buffer, cl, task, varg_list, &ctx);
-	
 	 int ret = ctx == 0 ? starpu_task_submit(*task) : starpu_task_submit_to_ctx(*task, ctx);
 
 	if (STARPU_UNLIKELY(ret == -ENODEV))