Przeglądaj źródła

Add env var STARPU_WORKERS_COREID

Philippe SWARTVAGHER 4 lat temu
rodzic
commit
ce006e6ac1

+ 2 - 0
ChangeLog

@@ -57,6 +57,8 @@ Small features:
     automatically called when the task does not define itself a
     callback function, in that case, it can still be called from the
     task callback function.
+  * New STARPU_WORKERS_COREID environment variable to bind workers to cores
+    instead of hyperthreads.
 
 StarPU 1.3.7
 ====================================================================

+ 7 - 0
doc/doxygen/chapters/501_environment_variables.doxy

@@ -228,7 +228,14 @@ and the third (resp. second and fourth) workers will be put on CPU #0
 This variable is ignored if the field
 starpu_conf::use_explicit_workers_bindid passed to starpu_init() is
 set.
+</dd>
 
+<dt>STARPU_WORKERS_COREID</dt>
+<dd>
+\anchor STARPU_WORKERS_COREID
+\addindex __env__STARPU_WORKERS_COREID
+Same as \ref STARPU_WORKERS_CPUID, but bind the workers to cores instead of PUs
+(hyperthreads).
 </dd>
 
 <dt>STARPU_MAIN_THREAD_BIND</dt>

+ 21 - 4
src/core/topology.c

@@ -935,9 +935,17 @@ static void _starpu_initialize_workers_bindid(struct _starpu_machine_config *con
 	unsigned i;
 
 	struct _starpu_machine_topology *topology = &config->topology;
+	int nhyperthreads = topology->nhwpus / topology->nhwcpus;
+	unsigned bind_on_core = 0;
+	int scale = 1;
 
 	config->current_bindid = 0;
 
+	if (starpu_getenv("STARPU_WORKERS_CPUID") && starpu_getenv("STARPU_WORKERS_COREID"))
+	{
+		_STARPU_DISP("Warning: STARPU_WORKERS_CPUID and STARPU_WORKERS_COREID cannot be set at the same time. STARPU_WORKERS_CPUID will be used.\n");
+	}
+
 	/* conf->workers_bindid indicates the successive logical PU identifier that
 	 * should be used to bind the workers. It should be either filled
 	 * according to the user's explicit parameters (from starpu_conf) or
@@ -947,6 +955,16 @@ static void _starpu_initialize_workers_bindid(struct _starpu_machine_config *con
 
 	/* what do we use, explicit value, env. variable, or round-robin ? */
 	strval = starpu_getenv("STARPU_WORKERS_CPUID");
+	if (strval == NULL)
+	{
+		strval = starpu_getenv("STARPU_WORKERS_COREID");
+		if (strval)
+		{
+			bind_on_core = 1;
+			scale = nhyperthreads;
+		}
+	}
+
 	if (strval)
 	{
 		/* STARPU_WORKERS_CPUID certainly contains less entries than
@@ -967,7 +985,7 @@ static void _starpu_initialize_workers_bindid(struct _starpu_machine_config *con
 				val = strtol(strval, &endptr, 10);
 				if (endptr != strval)
 				{
-					topology->workers_bindid[i] = (unsigned)(val % topology->nhwpus);
+					topology->workers_bindid[i] = (unsigned)((val * scale) % topology->nhwpus);
 					strval = endptr;
 					if (*strval == '-')
 					{
@@ -981,14 +999,14 @@ static void _starpu_initialize_workers_bindid(struct _starpu_machine_config *con
 						}
 						else
 						{
-							endval = topology->nhwpus-1;
+							endval = (bind_on_core ? topology->nhwcpus : topology->nhwpus) - 1;
 							if (*strval)
 								strval++;
 						}
 						for (val++; val <= endval && i < STARPU_NMAXWORKERS-1; val++)
 						{
 							i++;
-							topology->workers_bindid[i] = (unsigned)(val % topology->nhwpus);
+							topology->workers_bindid[i] = (unsigned)((val * scale) % topology->nhwpus);
 						}
 					}
 					if (*strval == ',')
@@ -1027,7 +1045,6 @@ static void _starpu_initialize_workers_bindid(struct _starpu_machine_config *con
 		int nth_per_core = starpu_get_env_number_default("STARPU_NTHREADS_PER_CORE", 1);
 		int k;
 		int nbindids=0;
-		int nhyperthreads = topology->nhwpus / topology->nhwcpus;
 		STARPU_ASSERT_MSG(nth_per_core > 0 && nth_per_core <= nhyperthreads , "Incorrect number of hyperthreads");
 
 		i = 0; /* PU number currently assigned */