Pārlūkot izejas kodu

Fix core/thread confusions

Samuel Thibault 11 gadi atpakaļ
vecāks
revīzija
b97472e2df

+ 2 - 1
src/core/perfmodel/perfmodel_bus.c

@@ -678,6 +678,7 @@ static void benchmark_all_gpu_devices(void)
 #endif
 
 	struct _starpu_machine_config *config = _starpu_get_machine_config();
+	ncpus = _starpu_topology_get_nhwcpu(config);
 
 #ifdef STARPU_USE_CUDA
 	ncuda = _starpu_get_cuda_device_count();
@@ -1563,7 +1564,7 @@ static void check_bus_config_file(void)
                 fclose(f);
 
                 // Loading current configuration
-                ncpus = _starpu_topology_get_nhwpu(config);
+                ncpus = _starpu_topology_get_nhwcpu(config);
 #ifdef STARPU_USE_CUDA
 		ncuda = _starpu_get_cuda_device_count();
 #endif

+ 17 - 12
src/core/topology.c

@@ -418,6 +418,7 @@ _starpu_init_topology (struct _starpu_machine_config *config)
 	if (topology_is_initialized)
 		return;
 
+	topology->nhwcpus = 0;
 	topology->nhwpus = 0;
 
 #ifndef STARPU_SIMGRID
@@ -428,7 +429,7 @@ _starpu_init_topology (struct _starpu_machine_config *config)
 #endif
 
 #ifdef STARPU_SIMGRID
-	config->topology.nhwpus = _starpu_simgrid_get_nbhosts("CPU");
+	config->topology->nhwcpus = config->topology.nhwpus = _starpu_simgrid_get_nbhosts("CPU");
 #elif defined(STARPU_HAVE_HWLOC)
 	/* Discover the CPUs relying on the hwloc interface and fills CONFIG
 	 * accordingly. */
@@ -458,17 +459,17 @@ _starpu_init_topology (struct _starpu_machine_config *config)
 	/* Discover the CPUs relying on the sysconf(3) function and fills
 	 * CONFIG accordingly. */
 
-	config->topology.nhwpus = sysconf(_SC_NPROCESSORS_ONLN);
+	config->topology->nhwcpus = config->topology.nhwpus = sysconf(_SC_NPROCESSORS_ONLN);
 
 #elif defined(__MINGW32__) || defined(__CYGWIN__)
 	/* Discover the CPUs on Cygwin and MinGW systems. */
 
 	SYSTEM_INFO sysinfo;
 	GetSystemInfo(&sysinfo);
-	config->topology.nhwpus = sysinfo.dwNumberOfProcessors;
+	config->topology->nhwcpus = config->topology.nhwpus = sysinfo.dwNumberOfProcessors;
 #else
 #warning no way to know number of cores, assuming 1
-	config->topology.nhwpus = 1;
+	config->topology->nhwcpus = config->topology.nhwpus = 1;
 #endif
 
 	_starpu_cuda_discover_devices(config);
@@ -555,8 +556,7 @@ _starpu_initialize_workers_bindid (struct _starpu_machine_config *config)
 	}
 	else
 	{
-		int nth_per_core = starpu_get_env_number("STARPU_NTHREADS_PER_CORE");
-		nth_per_core = nth_per_core == -1 ? 1 : nth_per_core;
+		int nth_per_core = starpu_get_env_number_default("STARPU_NTHREADS_PER_CORE", 1);
 		int k, l;
 		int nbindids=0;
 		int nhyperthreads = topology->nhwpus / topology->nhwcpus;
@@ -1036,9 +1036,11 @@ _starpu_init_machine_config (struct _starpu_machine_config *config, int no_mp_co
 			unsigned already_busy_cpus = mic_busy_cpus + topology->ncudagpus
 				+ topology->nopenclgpus + topology->nsccdevices;
 
-			long avail_cpus = (long) topology->nhwpus - (long) already_busy_cpus;
+			long avail_cpus = (long) topology->nhwcpus - (long) already_busy_cpus;
 			if (avail_cpus < 0)
 				avail_cpus = 0;
+			int nth_per_core = starpu_get_env_number_default("STARPU_NTHREADS_PER_CORE", 1);
+			avail_cpus *= nth_per_core;
 			ncpu = STARPU_MIN(avail_cpus, STARPU_MAXCPUS);
 		}
 		else
@@ -1568,21 +1570,24 @@ starpu_topology_print (FILE *output)
 {
 	struct _starpu_machine_config *config = _starpu_get_machine_config();
 	struct _starpu_machine_topology *topology = &config->topology;
-	unsigned core;
+	unsigned pu;
 	unsigned worker;
 	unsigned nworkers = starpu_worker_get_count();
 	unsigned ncombinedworkers = topology->ncombinedworkers;
+	unsigned nthreads_per_core = topology->nhwpus / topology->nhwcpus;
 
-	for (core = 0; core < topology->nhwpus; core++)
+	for (pu = 0; pu < topology->nhwpus; pu++)
 	{
-		fprintf(output, "core %u\t", core);
+		if ((pu % nthreads_per_core) == 0)
+			fprintf(output, "core %u", pu / nthreads_per_core);
+		fprintf(output, "\tPU %u\t", pu);
 		for (worker = 0;
 		     worker < nworkers + ncombinedworkers;
 		     worker++)
 		{
 			if (worker < nworkers)
 			{
-				if (topology->workers_bindid[worker] == core)
+				if (topology->workers_bindid[worker] == pu)
 				{
 					char name[256];
 					starpu_worker_get_name (worker, name,
@@ -1597,7 +1602,7 @@ starpu_topology_print (FILE *output)
 				starpu_combined_worker_get_description(worker, &worker_size, &combined_workerid);
 				for (i = 0; i < worker_size; i++)
 				{
-					if (topology->workers_bindid[combined_workerid[i]] == core)
+					if (topology->workers_bindid[combined_workerid[i]] == pu)
 						fprintf(output, "comb %u\t", worker-nworkers);
 				}
 			}

+ 1 - 1
tools/starpu_machine_display.c

@@ -148,7 +148,7 @@ int main(int argc, char **argv)
 
 	fprintf(stdout, "StarPU has found :\n");
 
-	fprintf(stdout, "\t%u CPU cores\n", ncpu);
+	fprintf(stdout, "\t%u CPU threads\n", ncpu);
 	display_worker_names(STARPU_CPU_WORKER);
 
 	fprintf(stdout, "\t%u CUDA devices\n", ncuda);