Prechádzať zdrojové kódy

Avoid initializing cuda/opencl when user doesn't want it anyway

Samuel Thibault 6 rokov pred
rodič
commit
f5f57fd4c9
1 zmenil súbory, kde vykonal 30 pridanie a 16 odobranie
  1. 30 16
      src/core/topology.c

+ 30 - 16
src/core/topology.c

@@ -881,8 +881,10 @@ _starpu_init_topology (struct _starpu_machine_config *config)
 	config->topology.nhwcpus = config->topology.nhwpus = 1;
 #endif
 
-	_starpu_cuda_discover_devices(config);
-	_starpu_opencl_discover_devices(config);
+	if (config->conf.ncuda != 0)
+		_starpu_cuda_discover_devices(config);
+	if (config->conf.nopencl != 0)
+		_starpu_opencl_discover_devices(config);
 #ifdef STARPU_USE_SCC
 	config->topology.nhwscc = _starpu_scc_src_get_device_count();
 #endif
@@ -1132,10 +1134,12 @@ unsigned
 _starpu_topology_get_nhwcpu (struct _starpu_machine_config *config)
 {
 #if defined(STARPU_USE_OPENCL) || defined(STARPU_SIMGRID)
-	_starpu_opencl_init();
+	if (config->conf.nopencl != 0)
+		_starpu_opencl_init();
 #endif
 #if defined(STARPU_USE_CUDA) || defined(STARPU_SIMGRID)
-	_starpu_init_cuda();
+	if (config->conf.ncuda != 0)
+		_starpu_init_cuda();
 #endif
 	_starpu_init_topology(config);
 
@@ -1146,10 +1150,12 @@ unsigned
 _starpu_topology_get_nhwpu (struct _starpu_machine_config *config)
 {
 #if defined(STARPU_USE_OPENCL) || defined(STARPU_SIMGRID)
-	_starpu_opencl_init();
+	if (config->conf.nopencl != 0)
+		_starpu_opencl_init();
 #endif
 #if defined(STARPU_USE_CUDA) || defined(STARPU_SIMGRID)
-	_starpu_init_cuda();
+	if (config->conf.ncuda != 0)
+		_starpu_init_cuda();
 #endif
 	_starpu_init_topology(config);
 
@@ -1159,10 +1165,12 @@ _starpu_topology_get_nhwpu (struct _starpu_machine_config *config)
 unsigned _starpu_topology_get_nnumanodes(struct _starpu_machine_config *config STARPU_ATTRIBUTE_UNUSED)
 {
 #if defined(STARPU_USE_OPENCL) || defined(STARPU_SIMGRID)
-        _starpu_opencl_init();
+	if (config->conf.nopencl != 0)
+		_starpu_opencl_init();
 #endif
 #if defined(STARPU_USE_CUDA) || defined(STARPU_SIMGRID)
-        _starpu_init_cuda();
+	if (config->conf.ncuda != 0)
+		_starpu_init_cuda();
 #endif
         _starpu_init_topology(config);
 
@@ -1516,10 +1524,12 @@ _starpu_init_machine_config(struct _starpu_machine_config *config, int no_mp_con
 	topology->nsched_ctxs = 0;
 
 #if defined(STARPU_USE_OPENCL) || defined(STARPU_SIMGRID)
-	_starpu_opencl_init();
+	if (config->conf.nopencl != 0)
+		_starpu_opencl_init();
 #endif
 #if defined(STARPU_USE_CUDA) || defined(STARPU_SIMGRID)
-	_starpu_init_cuda();
+	if (config->conf.ncuda != 0)
+		_starpu_init_cuda();
 #endif
 	_starpu_init_topology(config);
 
@@ -2017,14 +2027,16 @@ _starpu_bind_thread_on_cpu (
 
 #ifdef STARPU_HAVE_HWLOC
 	const struct hwloc_topology_support *support;
+	struct _starpu_machine_config *config = _starpu_get_machine_config();
 
 #ifdef STARPU_USE_OPENCL
-	_starpu_opencl_init();
+	if (config->conf.nopencl != 0)
+		_starpu_opencl_init();
 #endif
 #ifdef STARPU_USE_CUDA
-	_starpu_init_cuda();
+	if (config->conf.ncuda != 0)
+		_starpu_init_cuda();
 #endif
-	struct _starpu_machine_config *config = _starpu_get_machine_config();
 	_starpu_init_topology(config);
 
 	if (workerid != STARPU_NOWORKERID && cpuid < STARPU_MAXCPUS)
@@ -2137,14 +2149,16 @@ _starpu_bind_thread_on_cpus (
 #endif
 #ifdef STARPU_HAVE_HWLOC
 	const struct hwloc_topology_support *support;
+	struct _starpu_machine_config *config = _starpu_get_machine_config();
 
 #ifdef STARPU_USE_OPENC
-	_starpu_opencl_init();
+	if (config->conf.nopencl != 0)
+		_starpu_opencl_init();
 #endif
 #ifdef STARPU_USE_CUDA
-	_starpu_init_cuda();
+	if (config->conf.ncuda != 0)
+		_starpu_init_cuda();
 #endif
-	struct _starpu_machine_config *config = _starpu_get_machine_config();
 	_starpu_init_topology(config);
 
 	support = hwloc_topology_get_support(config->topology.hwtopology);