Browse Source

src/drivers/cpu/driver_cpu.c: Introduce new variables STARPU_LIMIT_CPU_MEM and STARPU_LIMIT_CPU_devid_MEM to limit memory per all CPU or per specific device

Nathalie Furmento 12 years ago
parent
commit
449b29bd8e
2 changed files with 27 additions and 3 deletions
  1. 3 0
      ChangeLog
  2. 24 3
      src/drivers/cpu/driver_cpu.c

+ 3 - 0
ChangeLog

@@ -92,6 +92,9 @@ New features:
     instead STARPU_LIMIT_CUDA_MEM and STARPU_LIMIT_OPENCL_MEM
   * Introduce new variables STARPU_LIMIT_CUDA_devid_MEM and
     STARPU_LIMIT_OPENCL_devid_MEM to limit memory per specific device
+  * Introduce new variables STARPU_LIMIT_CPU_MEM and
+    STARPU_LIMIT_CPU_devid_MEM to limit memory per all CPU or per
+    specific device
 
 Small features:
   * Add starpu_worker_get_by_type and starpu_worker_get_by_devid

+ 24 - 3
src/drivers/cpu/driver_cpu.c

@@ -191,22 +191,43 @@ _starpu_get_worker_from_driver(struct starpu_driver *d)
 
 static size_t _starpu_cpu_get_global_mem_size(int devid, struct _starpu_machine_config *config)
 {
+	ssize_t global_mem;
+	ssize_t limit;
+	char name[30];
+
+	limit = starpu_get_env_number("STARPU_LIMIT_CPU_MEM");
+	if (limit == -1)
+	{
+		sprintf(name, "STARPU_LIMIT_CPU_%u_MEM", devid);
+		limit = starpu_get_env_number(name);
+	}
+
 #if defined(STARPU_HAVE_HWLOC)
         int depth_node;
 	struct starpu_machine_topology *topology = &config->topology;
         depth_node = hwloc_get_type_depth(topology->hwtopology, HWLOC_OBJ_NODE);
 
 	if (depth_node == HWLOC_TYPE_DEPTH_UNKNOWN)
-	     return hwloc_get_root_obj(topology->hwtopology)->memory.total_memory;
+	     global_mem = hwloc_get_root_obj(topology->hwtopology)->memory.total_memory;
 	else
-	     return hwloc_get_obj_by_depth(topology->hwtopology, depth_node, devid)->memory.local_memory;
+	     global_mem = hwloc_get_obj_by_depth(topology->hwtopology, depth_node, devid)->memory.local_memory;
 
 #else /* STARPU_HAVE_HWLOC */
 #ifdef STARPU_DEVEL
 #  warning use sysinfo when available to get global size
 #endif
-	return 0;
+	global_mem = 0;
 #endif
+
+	if (limit == -1)
+		// No limit is defined, we return the global memory size
+		return global_mem;
+	else if (limit > global_mem)
+		// The requested limit is higher than what is available, we return the global memory size
+		return global_mem;
+	else
+		// We limit the memory
+		return limit;
 }
 
 int _starpu_cpu_driver_init(struct starpu_driver *d)