Selaa lähdekoodia

Fix against hwloc 2

Samuel Thibault 7 vuotta sitten
vanhempi
commit
144b5661bd

+ 6 - 0
src/core/perfmodel/perfmodel_bus.c

@@ -635,7 +635,13 @@ static void measure_bandwidth_between_numa_nodes_and_dev(int dev, struct dev_tim
 		hwloc_obj_t obj = hwloc_get_obj_by_type(hwtopology, HWLOC_OBJ_NODE, numa_id);
 
 		if (obj)
+		{
+#if HWLOC_API_VERSION >= 0x00020000
+			/* From hwloc 2.0, NUMAnode objects do not contain CPUs, they are contained in a group which contain the CPUs. */
+			obj = obj->parent;
+#endif
 			cpu_id = find_cpu_from_numa_node(obj);
+		}
 		else
                         /* No such NUMA node, probably hwloc 1.x with no NUMA
                          * node, just take one CPU from the whole system */

+ 25 - 26
src/core/topology.c

@@ -111,9 +111,17 @@ int starpu_memory_nodes_get_numa_count(void)
 }
 
 #if defined(STARPU_HAVE_HWLOC)
-static int numa_get_logical_id(hwloc_obj_t obj)
+static hwloc_obj_t numa_get_obj(hwloc_obj_t obj)
 {
-	STARPU_ASSERT(obj);
+#if HWLOC_API_VERSION >= 0x00020000
+	while (obj->memory_first_child == NULL)
+	{
+		obj = obj->parent;
+		/* There should always be memory objects with hwloc 2 */
+		STARPU_ASSERT(obj);
+	}
+	return obj->memory_first_child;
+#else
 	while (obj->type != HWLOC_OBJ_NODE)
 	{
 		obj = obj->parent;
@@ -122,24 +130,25 @@ static int numa_get_logical_id(hwloc_obj_t obj)
 		 * hwloc does not know whether there are numa nodes or not, so
 		 * we should not use a per-node sampling in that case. */
 		if (!obj)
-			return STARPU_NUMA_MAIN_RAM;
+			return NULL;
 	}
+#endif
+}
+static int numa_get_logical_id(hwloc_obj_t obj)
+{
+	STARPU_ASSERT(obj);
+	obj = numa_get_obj(obj);
+	if (!obj)
+		return 0;
 	return obj->logical_index;
 }
 
 static int numa_get_physical_id(hwloc_obj_t obj)
 {
 	STARPU_ASSERT(obj);
-	while (obj->type != HWLOC_OBJ_NODE)
-	{
-		obj = obj->parent;
-
-		/* If we don't find a "node" obj before the root, this means
-		 * hwloc does not know whether there are numa nodes or not, so
-		 * we should not use a per-node sampling in that case. */
-		if (!obj)
-			return STARPU_NUMA_MAIN_RAM;
-	}
+	obj = numa_get_obj(obj);
+	if (!obj)
+		return 0;
 	return obj->os_index;
 }
 #endif
@@ -2027,12 +2036,7 @@ static void _starpu_init_numa_node(struct _starpu_machine_config *config)
 		for (i = 0; i < config->topology.ncudagpus; i++)
 		{
 			hwloc_obj_t obj = hwloc_cuda_get_device_osdev_by_index(config->topology.hwtopology, i);
-
-			/* If we don't find a "node" obj before the root, this means
-			 * hwloc does not know whether there are numa nodes or not, so
-			 * we should not use a per-node sampling in that case. */
-			while (obj && obj->type != HWLOC_OBJ_NODE)
-				obj = obj->parent;
+			obj = numa_get_obj(obj);
 			/* Hwloc cannot recognize some devices */
 			if (!obj)
 				continue;
@@ -2090,12 +2094,7 @@ static void _starpu_init_numa_node(struct _starpu_machine_config *config)
 				for (i = 0; i < num; i++)
 				{
 					hwloc_obj_t obj = hwloc_opencl_get_device_osdev_by_index(config->topology.hwtopology, platform, i);
-
-					/* If we don't find a "node" obj before the root, this means
-					 * hwloc does not know whether there are numa nodes or not, so
-					 * we should not use a per-node sampling in that case. */
-					while (obj && obj->type != HWLOC_OBJ_NODE)
-						obj = obj->parent;
+					obj = numa_get_obj(obj);
 					/* Hwloc cannot recognize some devices */
 					if (!obj)
 						continue;
@@ -2717,7 +2716,7 @@ starpu_topology_print (FILE *output)
 	{
 #ifdef STARPU_HAVE_HWLOC
 		pu_obj = hwloc_get_obj_by_type(topo, HWLOC_OBJ_PU, pu);
-		numa_obj = hwloc_get_ancestor_obj_by_type(topo, HWLOC_OBJ_NODE, pu_obj);
+		numa_obj = numa_get_obj(pu_obj);
 		if (numa_obj != last_numa_obj)
 		{
 			fprintf(output, "numa %u", numa_obj->logical_index);

+ 12 - 0
src/drivers/cpu/driver_cpu.c

@@ -165,13 +165,21 @@ static size_t _starpu_cpu_get_global_mem_size(int nodeid STARPU_ATTRIBUTE_UNUSED
 
 		if (depth_node == HWLOC_TYPE_DEPTH_UNKNOWN)
 		{
+#if HWLOC_API_VERSION >= 0x00020000
+			global_mem = hwloc_get_root_obj(topology->hwtopology)->total_memory;
+#else
 			global_mem = hwloc_get_root_obj(topology->hwtopology)->memory.total_memory;
+#endif
 		}
 		else
 		{
 			char name[32];
 			hwloc_obj_t obj = hwloc_get_obj_by_depth(topology->hwtopology, depth_node, nodeid);
+#if HWLOC_API_VERSION >= 0x00020000
+			global_mem = obj->attr->numanode.local_memory;
+#else
 			global_mem = obj->memory.local_memory;
+#endif
 			snprintf(name, sizeof(name), "STARPU_LIMIT_CPU_NUMA_%d_MEM", obj->os_index);
 			limit = starpu_get_env_number(name);
 		}
@@ -179,7 +187,11 @@ static size_t _starpu_cpu_get_global_mem_size(int nodeid STARPU_ATTRIBUTE_UNUSED
 	else
 	{
 		/* Do not limit ourself to a single NUMA node */
+#if HWLOC_API_VERSION >= 0x00020000
+		global_mem = hwloc_get_root_obj(topology->hwtopology)->total_memory;
+#else
 		global_mem = hwloc_get_root_obj(topology->hwtopology)->memory.total_memory;
+#endif
 	}
 
 #else /* STARPU_HAVE_HWLOC */

+ 3 - 1
src/sched_policies/scheduler_maker.c

@@ -71,6 +71,7 @@ static struct sched_component_list helper_make_scheduler(struct starpu_sched_tre
 	switch(obj->type)
 	{
 		CASE(HWLOC_OBJ_MACHINE,hwloc_machine_composed_sched_component);
+		CASE(HWLOC_OBJ_GROUP,hwloc_component_composed_sched_component);
 		CASE(HWLOC_OBJ_NODE,hwloc_component_composed_sched_component);
 		CASE(HWLOC_OBJ_SOCKET,hwloc_socket_composed_sched_component);
 		CASE(HWLOC_OBJ_CACHE,hwloc_cache_composed_sched_component);
@@ -144,6 +145,7 @@ static struct starpu_sched_component * find_mem_component(struct starpu_sched_co
 {
 	struct starpu_sched_component * component = worker_component;
 	while(component->obj->type != HWLOC_OBJ_NODE
+	      && component->obj->type != HWLOC_OBJ_GROUP
 	      && component->obj->type != HWLOC_OBJ_MACHINE)
 	{
 		hwloc_obj_t tmp = component->obj;
@@ -172,7 +174,7 @@ static struct starpu_sched_component * where_should_we_plug_this(struct starpu_s
 		   && is_same_kind_of_all(parent->children[i], worker_component->data))
 			return parent->children[i];
 	}
-	if(obj->type == HWLOC_OBJ_NODE)
+	if(obj->type == HWLOC_OBJ_NODE || obj->type == HWLOC_OBJ_GROUP)
 	{
 		struct starpu_sched_component * component = starpu_sched_component_composed_component_create(root->tree, specs.hwloc_component_composed_sched_component);
 		component->obj = obj;

+ 4 - 0
tests/datawizard/reclaim.c

@@ -53,7 +53,11 @@ static uint64_t get_total_memory_size(void)
 	hwloc_topology_init(&hwtopology);
 	hwloc_topology_load(hwtopology);
 	hwloc_obj_t root = hwloc_get_root_obj(hwtopology);
+#if HWLOC_API_VERSION >= 0x00020000
+	size = root->total_memory;
+#else
 	size = root->memory.total_memory;
+#endif
 	hwloc_topology_destroy(hwtopology);
 	return size;
 }