Bladeren bron

In addition to the use of environment variables to specify the number of
workers, or which scheduling policy should be enforced, it is now possible to
specify those parameter when initializing StarPU.

Cédric Augonnet 16 jaren geleden
bovenliggende
commit
3ef1ce23aa

+ 1 - 1
examples/cholesky/dw_cholesky.c

@@ -214,7 +214,7 @@ static void _dw_cholesky(starpu_data_handle dataA, unsigned nblocks)
 
 void initialize_system(float **A, unsigned dim, unsigned pinned)
 {
-	starpu_init();
+	starpu_init(NULL);
 
 	timing_init();
 

+ 1 - 1
examples/cholesky/dw_cholesky_no_stride.c

@@ -245,7 +245,7 @@ int main(int argc, char **argv)
 
 	fprintf(stderr, "BLOCK SIZE = %d\n", size / nblocks);
 
-	starpu_init();
+	starpu_init(NULL);
 	timing_init();
 
 	for (y = 0; y < nblocks; y++)

+ 1 - 1
examples/heat/dw_factolu.c

@@ -683,7 +683,7 @@ void dw_codelet_facto_v2(starpu_data_handle dataA, unsigned nblocks)
 
 void initialize_system(float **A, float **B, unsigned dim, unsigned pinned)
 {
-	starpu_init();
+	starpu_init(NULL);
 
 	timing_init();
 

+ 2 - 2
examples/heat/dw_sparse_cg.c

@@ -428,7 +428,7 @@ void do_conjugate_gradient(float *nzvalA, float *vecb, float *vecx, uint32_t nnz
 			unsigned nrow, uint32_t *colind, uint32_t *rowptr)
 {
 	/* start the runtime */
-	starpu_init();
+	starpu_init(NULL);
 
 
 #ifdef USE_CUDA
@@ -447,7 +447,7 @@ int main(__attribute__ ((unused)) int argc,
 	timing_init();
 
 	/* start the runtime */
-	starpu_init();
+	starpu_init(NULL);
 
 
 #ifdef USE_CUDA

+ 1 - 1
examples/incrementer/incrementer.c

@@ -113,7 +113,7 @@ int main(__attribute__ ((unused)) int argc, __attribute__ ((unused)) char **argv
 {
 	unsigned counter = 0;
 
-	starpu_init();
+	starpu_init(NULL);
 	fprintf(stderr, "StarPU initialized ...\n");
 
 	pthread_mutex_init(&mutex, NULL);

+ 1 - 1
examples/mult/dw_mult.c

@@ -324,7 +324,7 @@ int main(__attribute__ ((unused)) int argc,
 	parse_args(argc, argv);
 
 	/* start the runtime */
-	starpu_init();
+	starpu_init(NULL);
 
 	pthread_mutex_init(&mutex, NULL);
 	pthread_cond_init(&cond, NULL);

+ 1 - 1
examples/mult/dw_mult_no_stride.c

@@ -458,7 +458,7 @@ int main(__attribute__ ((unused)) int argc,
 	parse_args(argc, argv);
 
 	/* start the runtime */
-	starpu_init();
+	starpu_init(NULL);
 
 	pthread_mutex_init(&mutex, NULL);
 	pthread_cond_init(&cond, NULL);

+ 1 - 1
examples/mult/dw_mult_no_stride_no_tag.c

@@ -464,7 +464,7 @@ int main(__attribute__ ((unused)) int argc,
 	parse_args(argc, argv);
 
 	/* start the runtime */
-	starpu_init();
+	starpu_init(NULL);
 
 	pthread_mutex_init(&mutex, NULL);
 	pthread_cond_init(&cond, NULL);

+ 1 - 1
examples/pastix-wrappers/starpu-blas-wrapper.c

@@ -53,7 +53,7 @@ void STARPU_INIT(void)
 {
 	if (!inited) {
 		inited = 1;
-		starpu_init();	
+		starpu_init(NULL);	
 	}
 }
 

+ 1 - 1
examples/spmv/dw_block_spmv.c

@@ -263,7 +263,7 @@ int main(__attribute__ ((unused)) int argc,
 	inputfile = argv[1];
 
 	/* start the runtime */
-	starpu_init();
+	starpu_init(NULL);
 
 	sem_init(&sem, 0, 0U);
 

+ 1 - 1
examples/spmv/dw_spmv.c

@@ -326,7 +326,7 @@ int main(__attribute__ ((unused)) int argc,
 	parse_args(argc, argv);
 
 	/* start the runtime */
-	starpu_init();
+	starpu_init(NULL);
 
 	sem_init(&sem, 0, 0U);
 

+ 1 - 1
examples/strassen/test_strassen.c

@@ -174,7 +174,7 @@ int main(__attribute__ ((unused)) int argc,
 	parse_args(argc, argv);
 
 	/* start the runtime */
-	starpu_init();
+	starpu_init(NULL);
 
 	sem_init(&sem, 0, 0U);
 

+ 1 - 1
examples/strassen2/strassen2.c

@@ -762,7 +762,7 @@ int main(int argc, char **argv)
 
 	parse_args(argc, argv);
 
-	starpu_init();
+	starpu_init(NULL);
 
 #ifdef USE_CUDA
         if (pin) {

+ 1 - 1
examples/tag_example/tag_example.c

@@ -183,7 +183,7 @@ static void express_deps(unsigned i, unsigned j, unsigned iter)
 
 int main(int argc __attribute__((unused)) , char **argv __attribute__((unused)))
 {
-	starpu_init();
+	starpu_init(NULL);
 
 	parse_args(argc, argv);
 

+ 1 - 1
examples/tag_example/tag_example2.c

@@ -104,7 +104,7 @@ int main(int argc __attribute__((unused)) , char **argv __attribute__((unused)))
 {
 	unsigned i;
 
-	starpu_init();
+	starpu_init(NULL);
 
 	parse_args(argc, argv);
 

+ 19 - 2
include/starpu.h

@@ -26,8 +26,25 @@
 #include <starpu-perfmodel.h>
 #include <starpu-task.h>
 
-/* Initialization method: it must be called prior to any other StarPU call */
-void starpu_init(void);
+struct starpu_conf {
+	/* which scheduling policy should be used ? (NULL for default) */
+	const char *sched_policy;
+
+	/* maximum number of CPUs (-1 for default) */
+	int ncpus;
+	/* maximum number of CUDA GPUs (-1 for default) */
+	int ncuda;
+	/* maximum number of Cell's SPUs (-1 for default) */
+	int nspus;
+
+	/* calibrate performance models, if any */
+	unsigned calibrate;
+};
+
+/* Initialization method: it must be called prior to any other StarPU call
+ * Default configuration is used if NULL is passed as argument.
+ */
+void starpu_init(struct starpu_conf *conf);
 
 /* Shutdown method: note that statistics are only generated once StarPU is
  * shutdown */

+ 18 - 10
src/core/policies/sched_policy.c

@@ -16,6 +16,7 @@
 
 #include <pthread.h>
 
+#include <starpu.h>
 #include <core/mechanisms/queues.h>
 #include <core/policies/sched_policy.h>
 #include <core/policies/no-prio-policy.h>
@@ -35,48 +36,55 @@ struct sched_policy_s *get_sched_policy(void)
 	return &policy;
 }
 
-void init_sched_policy(struct machine_config_s *config)
+void init_sched_policy(struct machine_config_s *config, struct starpu_conf *user_conf)
 {
 	/* eager policy is taken by default */
-	char *sched_env;
-	sched_env = getenv("SCHED");
-	if (sched_env) {
-		 if (strcmp(sched_env, "ws") == 0) {
+	char *sched_pol;
+	if (user_conf && (user_conf->sched_policy))
+	{
+		sched_pol = user_conf->sched_policy;
+	}
+	else {
+		sched_pol = getenv("SCHED");
+	}
+
+	if (sched_pol) {
+		 if (strcmp(sched_pol, "ws") == 0) {
 #ifdef VERBOSE
 		 	fprintf(stderr, "USE WS SCHEDULER !! \n");
 #endif
 			policy.init_sched = initialize_ws_policy;
 			policy.get_local_queue = get_local_queue_ws;
 		 }
-		 else if (strcmp(sched_env, "prio") == 0) {
+		 else if (strcmp(sched_pol, "prio") == 0) {
 #ifdef VERBOSE
 		 	fprintf(stderr, "USE PRIO EAGER SCHEDULER !! \n");
 #endif
 			policy.init_sched = initialize_eager_center_priority_policy;
 			policy.get_local_queue = get_local_queue_eager_priority;
 		 }
-		 else if (strcmp(sched_env, "no-prio") == 0) {
+		 else if (strcmp(sched_pol, "no-prio") == 0) {
 #ifdef VERBOSE
 		 	fprintf(stderr, "USE _NO_ PRIO EAGER SCHEDULER !! \n");
 #endif
 			policy.init_sched = initialize_no_prio_policy;
 			policy.get_local_queue = get_local_queue_no_prio;
 		 }
-		 else if (strcmp(sched_env, "dm") == 0) {
+		 else if (strcmp(sched_pol, "dm") == 0) {
 #ifdef VERBOSE
 		 	fprintf(stderr, "USE MODEL SCHEDULER !! \n");
 #endif
 			policy.init_sched = initialize_dm_policy;
 			policy.get_local_queue = get_local_queue_dm;
 		 }
-		 else if (strcmp(sched_env, "dmda") == 0) {
+		 else if (strcmp(sched_pol, "dmda") == 0) {
 #ifdef VERBOSE
 		 	fprintf(stderr, "USE DATA AWARE MODEL SCHEDULER !! \n");
 #endif
 			policy.init_sched = initialize_dmda_policy;
 			policy.get_local_queue = get_local_queue_dmda;
 		 }
-		 else if (strcmp(sched_env, "random") == 0) {
+		 else if (strcmp(sched_pol, "random") == 0) {
 #ifdef VERBOSE
 		 	fprintf(stderr, "USE RANDOM SCHEDULER !! \n");
 #endif

+ 2 - 1
src/core/policies/sched_policy.h

@@ -17,6 +17,7 @@
 #ifndef __SCHED_POLICY_H__
 #define __SCHED_POLICY_H__
 
+#include <starpu.h>
 #include <core/mechanisms/queues.h>
 //#include <core/mechanisms/work_stealing_queues.h>
 //#include <core/mechanisms/central_queues.h>
@@ -42,7 +43,7 @@ struct sched_policy_s {
 
 struct sched_policy_s *get_sched_policy(void);
 
-void init_sched_policy(struct machine_config_s *config);
+void init_sched_policy(struct machine_config_s *config, struct starpu_conf *user_conf);
 //void set_local_queue(struct jobq_s *jobq);
 
 int push_task(job_t task);

+ 48 - 21
src/core/workers.c

@@ -58,26 +58,41 @@ static unsigned ngordon_spus;
 extern unsigned get_cuda_device_count(void);
 #endif
 
-static void init_machine_config(struct machine_config_s *config)
+static void init_machine_config(struct machine_config_s *config,
+				struct starpu_conf *user_conf)
 {
-	int envval __attribute__((unused));
+	int explicitval __attribute__((unused));
 	unsigned use_accelerator = 0;
 
 	config->nworkers = 0;
 
 #ifdef USE_CUDA
-	/* we need to initialize CUDA early to count the number of devices */
-	init_cuda();
+	if (user_conf && (user_conf->ncuda == 0))
+	{
+		/* the user explicitely disabled CUDA */
+		ncudagpus = 0;
+	}
+	else {
+		/* we need to initialize CUDA early to count the number of devices */
+		init_cuda();
 
-	envval = starpu_get_env_number("NCUDA");
-	if (envval < 0) {
-		ncudagpus = STARPU_MIN(get_cuda_device_count(), MAXCUDADEVS);
-	} else {
-		/* use the specified value */
-		ncudagpus = (unsigned)envval;
-		STARPU_ASSERT(ncudagpus <= MAXCUDADEVS);
+		if (user_conf && (user_conf->ncuda != -1))
+		{
+			explicitval = user_conf->ncuda;
+		}
+		else {
+			explicitval = starpu_get_env_number("NCUDA");
+		}
+
+		if (explicitval < 0) {
+			ncudagpus = STARPU_MIN(get_cuda_device_count(), MAXCUDADEVS);
+		} else {
+			/* use the specified value */
+			ncudagpus = (unsigned)explicitval;
+			STARPU_ASSERT(ncudagpus <= MAXCUDADEVS);
+		}
+		STARPU_ASSERT(ncudagpus + config->nworkers <= NMAXWORKERS);
 	}
-	STARPU_ASSERT(ncudagpus + config->nworkers <= NMAXWORKERS);
 
 	if (ncudagpus > 0)
 		use_accelerator = 1;
@@ -95,12 +110,18 @@ static void init_machine_config(struct machine_config_s *config)
 #endif
 	
 #ifdef USE_GORDON
-	envval = starpu_get_env_number("NGORDON");
-	if (envval < 0) {
+	if (user_conf && (user_conf->ncuda != -1)) {
+		explicitval = user_conf->ncuda;
+	}
+	else {
+		explicitval = starpu_get_env_number("NGORDON");
+	}
+
+	if (explicitval < 0) {
 		ngordon_spus = spe_cpu_info_get(SPE_COUNT_USABLE_SPES, -1);
 	} else {
 		/* use the specified value */
-		ngordon_spus = (unsigned)envval;
+		ngordon_spus = (unsigned)explicitval;
 		STARPU_ASSERT(ngordon_spus <= NMAXGORDONSPUS);
 	}
 	STARPU_ASSERT(ngordon_spus + config->nworkers <= NMAXWORKERS);
@@ -124,14 +145,20 @@ static void init_machine_config(struct machine_config_s *config)
 /* we put the CPU section after the accelerator : in case there was an
  * accelerator found, we devote one core */
 #ifdef USE_CPUS
-	envval = starpu_get_env_number("NCPUS");
-	if (envval < 0) {
+	if (user_conf && (user_conf->ncpus != -1)) {
+		explicitval = user_conf->ncpus;
+	}
+	else {
+		explicitval = starpu_get_env_number("NCPUS");
+	}
+
+	if (explicitval < 0) {
 		long avail_cores = sysconf(_SC_NPROCESSORS_ONLN) 
 						- (use_accelerator?1:0);
 		ncores = STARPU_MIN(avail_cores, NMAXCORES);
 	} else {
 		/* use the specified value */
-		ncores = (unsigned)envval;
+		ncores = (unsigned)explicitval;
 		STARPU_ASSERT(ncores <= NMAXCORES);
 	}
 	STARPU_ASSERT(ncores + config->nworkers <= NMAXWORKERS);
@@ -303,7 +330,7 @@ static void init_workers(struct machine_config_s *config)
 	}
 }
 
-void starpu_init(void)
+void starpu_init(struct starpu_conf *user_conf)
 {
 	srand(2008);
 
@@ -313,7 +340,7 @@ void starpu_init(void)
 
 	timing_init();
 
-	init_machine_config(&config);
+	init_machine_config(&config, user_conf);
 
 	/* for the data wizard */
 	init_memory_nodes();
@@ -323,7 +350,7 @@ void starpu_init(void)
 	/* initialize the scheduler */
 
 	/* initialize the queue containing the jobs */
-	init_sched_policy(&config);
+	init_sched_policy(&config, user_conf);
 
 	init_workers(&config);
 }

+ 1 - 1
tests/microbenchs/async-tasks-overhead.c

@@ -95,7 +95,7 @@ int main(int argc, char **argv)
 
 	cnt = ntasks;
 
-	starpu_init();
+	starpu_init(NULL);
 
 	fprintf(stderr, "#tasks : %d\n", ntasks);
 

+ 1 - 1
tests/microbenchs/sync-tasks-overhead.c

@@ -70,7 +70,7 @@ int main(int argc, char **argv)
 
 	parse_args(argc, argv);
 
-	starpu_init();
+	starpu_init(NULL);
 
 	fprintf(stderr, "#tasks : %d\n", ntasks);