소스 검색

src: modify the field user_conf of struct _starpu_machine_config

	- rename it to conf
	- if starpu_init() is called with a non NULL pointer to struct starpu_conf, it will be used as configuration
        - otherwise a default configuration is created by calling starpu_conf_init(struct starpu_conf *conf)

        - in both cases, environment variables are checked and prefered to values defined in the given configuration

This does not change the current behaviour, it just makes the code more readable by always defining a configuration (either the one given by the user or the default one).
Nathalie Furmento 13 년 전
부모
커밋
d1ef85e5da
5개의 변경된 파일63개의 추가작업 그리고 78개의 파일을 삭제
  1. 6 19
      src/core/sched_policy.c
  2. 15 41
      src/core/topology.c
  3. 39 11
      src/core/workers.c
  4. 2 6
      src/core/workers.h
  5. 1 1
      src/sched_policies/detect_combined_workers.c

+ 6 - 19
src/core/sched_policy.c

@@ -144,20 +144,14 @@ static void display_sched_help_message(void)
 static struct starpu_sched_policy *select_sched_policy(struct _starpu_machine_config *config)
 {
 	struct starpu_sched_policy *selected_policy = NULL;
-	struct starpu_conf *user_conf = config->user_conf;
 
 	/* First, we check whether the application explicitely gave a scheduling policy or not */
-	if (user_conf && (user_conf->sched_policy))
-		return user_conf->sched_policy;
+	if (config->conf->sched_policy)
+		return config->conf->sched_policy;
 
 	/* Otherwise, we look if the application specified the name of a policy to load */
-	const char *sched_pol_name;
-	sched_pol_name = getenv("STARPU_SCHED");
-	if (sched_pol_name == NULL && user_conf && user_conf->sched_policy_name)
-		sched_pol_name = user_conf->sched_policy_name;
-
-	if (sched_pol_name)
-		selected_policy = find_sched_policy_from_name(sched_pol_name);
+	if (config->conf->sched_policy_name)
+		selected_policy = find_sched_policy_from_name(config->conf->sched_policy_name);
 
 	/* Perhaps there was no policy that matched the name */
 	if (selected_policy)
@@ -177,15 +171,8 @@ void _starpu_init_sched_policy(struct _starpu_machine_config *config)
 	if (use_prefetch == -1)
 		use_prefetch = 1;
 
-	/* By default, we don't calibrate */
-	unsigned do_calibrate = 0;
-	int res = starpu_get_env_number("STARPU_CALIBRATE");
-	if (res == -1 && config->user_conf)
-		res = config->user_conf->calibrate;
-
-	do_calibrate = (res < 0)?0:(unsigned)res;
-
-	_starpu_set_calibrate_flag(do_calibrate);
+	/* Set calibrate flag */
+	_starpu_set_calibrate_flag(config->conf->calibrate);
 
 	struct starpu_sched_policy *selected_policy;
 	selected_policy = select_sched_policy(config);

+ 15 - 41
src/core/topology.c

@@ -54,7 +54,7 @@ static struct starpu_htbl32_node *devices_using_cuda = NULL;
 #  ifdef STARPU_USE_OPENCL
 static void _starpu_initialize_workers_opencl_gpuid(struct _starpu_machine_config *config);
 #  endif
-static void _starpu_initialize_workers_gpuid(int use_explicit_workers_gpuid, int *explicit_workers_gpuid,
+static void _starpu_initialize_workers_gpuid(int *explicit_workers_gpuid,
                                              int *current, int *workers_gpuid, const char *varname, unsigned nhwgpus);
 static unsigned may_bind_automatically = 0;
 #endif
@@ -68,8 +68,7 @@ static void _starpu_initialize_workers_cuda_gpuid(struct _starpu_machine_config
 {
 	struct starpu_machine_topology *topology = &config->topology;
 
-        _starpu_initialize_workers_gpuid(config->user_conf==NULL?0:config->user_conf->use_explicit_workers_cuda_gpuid,
-                                         config->user_conf==NULL?NULL:(int *)config->user_conf->workers_cuda_gpuid,
+        _starpu_initialize_workers_gpuid(config->conf->use_explicit_workers_cuda_gpuid==0?NULL:(int *)config->conf->workers_cuda_gpuid,
                                          &(config->current_cuda_gpuid), (int *)topology->workers_cuda_gpuid, "STARPU_WORKERS_CUDAID",
                                          topology->nhwcudagpus);
 }
@@ -80,8 +79,7 @@ static void _starpu_initialize_workers_opencl_gpuid(struct _starpu_machine_confi
 {
 	struct starpu_machine_topology *topology = &config->topology;
 
-        _starpu_initialize_workers_gpuid(config->user_conf==NULL?0:config->user_conf->use_explicit_workers_opencl_gpuid,
-                                         config->user_conf==NULL?NULL:(int *)config->user_conf->workers_opencl_gpuid,
+        _starpu_initialize_workers_gpuid(config->conf->use_explicit_workers_opencl_gpuid==0?NULL:(int *)config->conf->workers_opencl_gpuid,
                                          &(config->current_opencl_gpuid), (int *)topology->workers_opencl_gpuid, "STARPU_WORKERS_OPENCLID",
                                          topology->nhwopenclgpus);
 
@@ -129,7 +127,7 @@ static void _starpu_initialize_workers_opencl_gpuid(struct _starpu_machine_confi
 
 
 #if defined(STARPU_USE_CUDA) || defined(STARPU_USE_OPENCL)
-static void _starpu_initialize_workers_gpuid(int use_explicit_workers_gpuid, int *explicit_workers_gpuid,
+static void _starpu_initialize_workers_gpuid(int *explicit_workers_gpuid,
                                              int *current, int *workers_gpuid, const char *varname, unsigned nhwgpus)
 {
 	char *strval;
@@ -184,7 +182,7 @@ static void _starpu_initialize_workers_gpuid(int use_explicit_workers_gpuid, int
 			}
 		}
 	}
-	else if (use_explicit_workers_gpuid)
+	else if (explicit_workers_gpuid)
 	{
 		/* we use the explicit value from the user */
 		memcpy(workers_gpuid,
@@ -195,8 +193,8 @@ static void _starpu_initialize_workers_gpuid(int use_explicit_workers_gpuid, int
 	{
 		/* by default, we take a round robin policy */
 		if (nhwgpus > 0)
-		for (i = 0; i < STARPU_NMAXWORKERS; i++)
-			workers_gpuid[i] = (unsigned)(i % nhwgpus);
+		     for (i = 0; i < STARPU_NMAXWORKERS; i++)
+			  workers_gpuid[i] = (unsigned)(i % nhwgpus);
 
 		/* StarPU can use sampling techniques to bind threads correctly */
 		may_bind_automatically = 1;
@@ -272,8 +270,7 @@ unsigned _starpu_topology_get_nhwcpu(struct _starpu_machine_config *config)
 	return config->topology.nhwcpus;
 }
 
-static int _starpu_init_machine_config(struct _starpu_machine_config *config,
-				struct starpu_conf *user_conf)
+static int _starpu_init_machine_config(struct _starpu_machine_config *config)
 {
 	int i;
 	for (i = 0; i < STARPU_NMAXWORKERS; i++)
@@ -288,14 +285,8 @@ static int _starpu_init_machine_config(struct _starpu_machine_config *config,
 	_starpu_initialize_workers_bindid(config);
 
 #ifdef STARPU_USE_CUDA
-	int ncuda;
-	ncuda = starpu_get_env_number("STARPU_NCUDA");
-
-	/* STARPU_NCUDA is not set. Did the user specify anything ? */
-	if (ncuda == -1 && user_conf)
-		ncuda = user_conf->ncuda;
+	int ncuda = config->conf->ncuda;
 
-	
 	if (ncuda != 0)
 	{
 		/* The user did not disable CUDA. We need to initialize CUDA
@@ -361,12 +352,7 @@ static int _starpu_init_machine_config(struct _starpu_machine_config *config,
 #endif
 
 #ifdef STARPU_USE_OPENCL
-	int nopencl;
-	nopencl = starpu_get_env_number("STARPU_NOPENCL");
-
-	/* STARPU_NOPENCL is not set. Did the user specify anything ? */
-	if (nopencl == -1 && user_conf)
-		nopencl = user_conf->nopencl;
+	int nopencl = config->conf->nopencl;
 
 	if (nopencl != 0)
 	{
@@ -436,12 +422,7 @@ static int _starpu_init_machine_config(struct _starpu_machine_config *config,
 #endif
 
 #ifdef STARPU_USE_GORDON
-	int ngordon;
-	ngordon = starpu_get_env_number("STARPU_NGORDON");
-
-	/* STARPU_NGORDON is not set. Did the user specify anything ? */
-	if (ngordon == -1 && user_conf)
-		ngordon = user_conf->ngordon;
+	int ngordon = config->conf->ngordon;
 
 	if (ngordon != 0)
 	{
@@ -483,12 +464,7 @@ static int _starpu_init_machine_config(struct _starpu_machine_config *config,
 /* we put the CPU section after the accelerator : in case there was an
  * accelerator found, we devote one cpu */
 #ifdef STARPU_USE_CPU
-	int ncpu;
-	ncpu = starpu_get_env_number("STARPU_NCPUS");
-
-	/* STARPU_NCPUS is not set. Did the user specify anything ? */
-	if (ncpu == -1 && user_conf)
-		ncpu = user_conf->ncpus;
+	int ncpu = config->conf->ncpus;
 
 	if (ncpu != 0)
 	{
@@ -597,11 +573,11 @@ static void _starpu_initialize_workers_bindid(struct _starpu_machine_config *con
 			}
 		}
 	}
-	else if (config->user_conf && config->user_conf->use_explicit_workers_bindid)
+	else if (config->conf->use_explicit_workers_bindid)
 	{
 		/* we use the explicit value from the user */
 		memcpy(topology->workers_bindid,
-			config->user_conf->workers_bindid,
+			config->conf->workers_bindid,
 			STARPU_NMAXWORKERS*sizeof(unsigned));
 	}
 	else
@@ -873,9 +849,7 @@ int _starpu_build_topology(struct _starpu_machine_config *config)
 {
 	int ret;
 
-	struct starpu_conf *user_conf = config->user_conf;
-
-	ret = _starpu_init_machine_config(config, user_conf);
+	ret = _starpu_init_machine_config(config);
 	if (ret)
 		return ret;
 

+ 39 - 11
src/core/workers.c

@@ -362,17 +362,49 @@ int starpu_conf_init(struct starpu_conf *conf)
 	conf->nspus = starpu_get_env_number("STARPU_NGORDON");
 	conf->calibrate = starpu_get_env_number("STARPU_CALIBRATE");
 
+	if (conf->calibrate == -1)
+	     conf->calibrate = 0;
+
 	conf->use_explicit_workers_bindid = 0; /* TODO */
 	conf->use_explicit_workers_cuda_gpuid = 0; /* TODO */
 	conf->use_explicit_workers_opencl_gpuid = 0; /* TODO */
 
 	conf->single_combined_worker = starpu_get_env_number("STARPU_SINGLE_COMBINED_WORKER");
+	if (conf->single_combined_worker == -1)
+	     conf->single_combined_worker = 0;
 
 	conf->disable_asynchronous_copy = starpu_get_env_number("STARPU_DISABLE_ASYNCHRONOUS_COPY");
 
 	return 0;
 }
 
+static void _starpu_conf_set_value_against_environment(char *name, int *value)
+{
+	int number;
+	number = starpu_get_env_number(name);
+	if (number != -1)
+	{
+		*value = number;
+	}
+}
+
+static void _starpu_conf_check_environment(struct starpu_conf *conf)
+{
+	char *sched = getenv("STARPU_SCHED");
+	if (sched)
+	{
+		conf->sched_policy_name = sched;
+	}
+
+	_starpu_conf_set_value_against_environment("STARPU_NCPUS", &conf->ncpus);
+	_starpu_conf_set_value_against_environment("STARPU_NCUDA", &conf->ncuda);
+	_starpu_conf_set_value_against_environment("STARPU_NOPENCL", &conf->nopencl);
+	_starpu_conf_set_value_against_environment("STARPU_NGORDON", &conf->nspus);
+	_starpu_conf_set_value_against_environment("STARPU_CALIBRATE", &conf->calibrate);
+	_starpu_conf_set_value_against_environment("STARPU_SINGLE_COMBINED_WORKER", &conf->single_combined_worker);
+	_starpu_conf_set_value_against_environment("STARPU_DISABLE_ASYNCHRONOUS_COPY", &conf->disable_asynchronous_copy);
+}
+
 int starpu_init(struct starpu_conf *user_conf)
 {
 	int ret;
@@ -444,21 +476,17 @@ int starpu_init(struct starpu_conf *user_conf)
 
 	/* store the pointer to the user explicit configuration during the
 	 * initialization */
-	config.user_conf = user_conf;
-
-	if (user_conf)
+	if (user_conf == NULL)
 	{
-	     int asynchronous_copy_disabled = starpu_get_env_number("STARPU_DISABLE_ASYNCHRONOUS_COPY");
-	     if (asynchronous_copy_disabled == 1)
-		  config.disable_asynchronous_copy = 1;
-	     else
-		  config.disable_asynchronous_copy = (user_conf->disable_asynchronous_copy == 1);
+	     struct starpu_conf conf;
+	     starpu_conf_init(&conf);
+	     config.conf = &conf;
 	}
 	else
 	{
-	     int asynchronous_copy_disabled = starpu_get_env_number("STARPU_DISABLE_ASYNCHRONOUS_COPY");
-	     config.disable_asynchronous_copy = (asynchronous_copy_disabled == 1);
+	     config.conf = user_conf;
 	}
+	_starpu_conf_check_environment(config.conf);
 
 	ret = _starpu_build_topology(&config);
 	if (ret)
@@ -707,7 +735,7 @@ unsigned starpu_spu_worker_get_count(void)
 
 int starpu_asynchronous_copy_disabled()
 {
-	return config.disable_asynchronous_copy;
+	return config.conf->disable_asynchronous_copy;
 }
 
 /* When analyzing performance, it is useful to see what is the processing unit

+ 2 - 6
src/core/workers.h

@@ -151,15 +151,11 @@ struct _starpu_machine_config
 	 * the result of (worker_mask & STARPU_CUDA). */
 	uint32_t worker_mask;
 
-	/* in case the user gives an explicit configuration, this is only valid
-	 * during starpu_init. */
-	struct starpu_conf *user_conf;
+        /* either the user given configuration passed to starpu_init or a default configuration */
+	struct starpu_conf *conf;
 
 	/* this flag is set until the runtime is stopped */
 	unsigned running;
-
-        /* indicate if the asynchronous copies should be disabled */
-        int disable_asynchronous_copy;
 };
 
 /* Has starpu_shutdown already been called ? */

+ 1 - 1
src/sched_policies/detect_combined_workers.c

@@ -478,7 +478,7 @@ void _starpu_sched_find_worker_combinations(struct starpu_machine_topology *topo
 {
     struct _starpu_machine_config *config = _starpu_get_machine_config();
 
-    if ((config->user_conf && config->user_conf->single_combined_worker > 0) || starpu_get_env_number("STARPU_SINGLE_COMBINED_WORKER") > 0)
+    if (config->conf->single_combined_worker > 0)
 	combine_all_cpu_workers(topology);
     else
     {