浏览代码

Use a structure to store starpu-specific data in hwloc tree, to allow more fields

Samuel Thibault 8 年之前
父节点
当前提交
2e7bcad876
共有 3 个文件被更改,包括 54 次插入16 次删除
  1. 8 7
      src/core/detect_combined_workers.c
  2. 36 8
      src/core/topology.c
  3. 10 1
      src/core/topology.h

+ 8 - 7
src/core/detect_combined_workers.c

@@ -26,10 +26,11 @@
 
 
 static void find_workers(hwloc_obj_t obj, int cpu_workers[STARPU_NMAXWORKERS], unsigned *n)
 static void find_workers(hwloc_obj_t obj, int cpu_workers[STARPU_NMAXWORKERS], unsigned *n)
 {
 {
-	if (!obj->userdata)
+	struct _starpu_hwloc_userdata *data = obj->userdata;
+	if (!data->worker_list)
 		/* Not something we run something on, don't care */
 		/* Not something we run something on, don't care */
 		return;
 		return;
-	if (obj->userdata == (void*) -1)
+	if (data->worker_list == (void*) -1)
 	{
 	{
 		/* Intra node, recurse */
 		/* Intra node, recurse */
 		unsigned i;
 		unsigned i;
@@ -39,7 +40,7 @@ static void find_workers(hwloc_obj_t obj, int cpu_workers[STARPU_NMAXWORKERS], u
 	}
 	}
 
 
 	/* Got to a PU leaf */
 	/* Got to a PU leaf */
-	struct _starpu_worker_list *workers = obj->userdata;
+	struct _starpu_worker_list *workers = data->worker_list;
 	struct _starpu_worker *worker;
 	struct _starpu_worker *worker;
 	for(worker = _starpu_worker_list_begin(workers); worker != _starpu_worker_list_end(workers); worker = _starpu_worker_list_next(worker))
 	for(worker = _starpu_worker_list_begin(workers); worker != _starpu_worker_list_end(workers); worker = _starpu_worker_list_next(worker))
 	{
 	{
@@ -73,7 +74,7 @@ static void synthesize_intermediate_workers(hwloc_obj_t *children, unsigned min,
 	chunk_start = 0;
 	chunk_start = 0;
 	for (i = 0 ; i < arity; i++)
 	for (i = 0 ; i < arity; i++)
 	{
 	{
-		if (children[i]->userdata)
+		if (((struct _starpu_hwloc_userdata*)children[i]->userdata)->worker_list)
 		{
 		{
 			n++;
 			n++;
 			_STARPU_DEBUG("child %u\n", i);
 			_STARPU_DEBUG("child %u\n", i);
@@ -120,7 +121,7 @@ static void find_and_assign_combinations(hwloc_obj_t obj, unsigned min, unsigned
 	_STARPU_DEBUG("Looking at %s\n", name);
 	_STARPU_DEBUG("Looking at %s\n", name);
 
 
 	for (n = 0, i = 0; i < obj->arity; i++)
 	for (n = 0, i = 0; i < obj->arity; i++)
-		if (obj->children[i]->userdata)
+		if (((struct _starpu_hwloc_userdata *)obj->children[i]->userdata)->worker_list)
 			/* it has a CPU worker */
 			/* it has a CPU worker */
 			n++;
 			n++;
 
 
@@ -154,7 +155,7 @@ static void find_and_assign_combinations(hwloc_obj_t obj, unsigned min, unsigned
 
 
 	/* And recurse */
 	/* And recurse */
 	for (i = 0; i < obj->arity; i++)
 	for (i = 0; i < obj->arity; i++)
-		if (obj->children[i]->userdata == (void*) -1)
+		if (((struct _starpu_hwloc_userdata*) obj->children[i]->userdata)->worker_list == (void*) -1)
 			find_and_assign_combinations(obj->children[i], min, max, synthesize_arity);
 			find_and_assign_combinations(obj->children[i], min, max, synthesize_arity);
 }
 }
 
 
@@ -187,7 +188,7 @@ static void find_and_assign_combinations_with_hwloc(int *workerids, int nworkers
 			obj = obj->parent;
 			obj = obj->parent;
 			while (obj)
 			while (obj)
 			{
 			{
-				obj->userdata = (void*) -1;
+				((struct _starpu_hwloc_userdata*) obj->userdata)->worker_list = (void*) -1;
 				obj = obj->parent;
 				obj = obj->parent;
 			}
 			}
 		}
 		}

+ 36 - 8
src/core/topology.c

@@ -469,6 +469,32 @@ _starpu_init_mic_node (struct _starpu_machine_config *config, int mic_idx,
 }
 }
 #endif
 #endif
 
 
+#ifndef STARPU_SIMGRID
+#ifdef STARPU_HAVE_HWLOC
+static void
+_starpu_allocate_topology_userdata(hwloc_obj_t obj)
+{
+	unsigned i;
+
+	obj->userdata = calloc(1, sizeof(struct _starpu_hwloc_userdata));
+	for (i = 0; i < obj->arity; i++)
+		_starpu_allocate_topology_userdata(obj->children[i]);
+}
+
+static void
+_starpu_deallocate_topology_userdata(hwloc_obj_t obj)
+{
+	unsigned i;
+	struct _starpu_hwloc_userdata *data = obj->userdata;
+
+	STARPU_ASSERT(!data->worker_list || data->worker_list == (void*)-1);
+	free(data);
+	for (i = 0; i < obj->arity; i++)
+		_starpu_allocate_topology_userdata(obj->children[i]);
+}
+#endif
+#endif
+
 static void
 static void
 _starpu_init_topology (struct _starpu_machine_config *config)
 _starpu_init_topology (struct _starpu_machine_config *config)
 {
 {
@@ -491,6 +517,7 @@ _starpu_init_topology (struct _starpu_machine_config *config)
 #ifdef STARPU_HAVE_HWLOC
 #ifdef STARPU_HAVE_HWLOC
 	hwloc_topology_init(&topology->hwtopology);
 	hwloc_topology_init(&topology->hwtopology);
 	hwloc_topology_load(topology->hwtopology);
 	hwloc_topology_load(topology->hwtopology);
+	_starpu_allocate_topology_userdata(hwloc_get_root_obj(topology->hwtopology));
 #endif
 #endif
 #endif
 #endif
 
 
@@ -1245,10 +1272,11 @@ void _starpu_destroy_machine_config(struct _starpu_machine_config *config)
 			hwloc_obj_t worker_obj = hwloc_get_obj_by_depth(config->topology.hwtopology,
 			hwloc_obj_t worker_obj = hwloc_get_obj_by_depth(config->topology.hwtopology,
 									config->pu_depth,
 									config->pu_depth,
 									bindid);
 									bindid);
-			if (worker_obj->userdata)
+			struct _starpu_hwloc_userdata *data = worker_obj->userdata;
+			if (data->worker_list)
 			{
 			{
-				_starpu_worker_list_delete(worker_obj->userdata);
-				worker_obj->userdata = NULL;
+				_starpu_worker_list_delete(data->worker_list);
+				data->worker_list = NULL;
 			}
 			}
 		}
 		}
 #endif
 #endif
@@ -1272,6 +1300,7 @@ void _starpu_destroy_machine_config(struct _starpu_machine_config *config)
 	}
 	}
 
 
 #ifdef STARPU_HAVE_HWLOC
 #ifdef STARPU_HAVE_HWLOC
+	_starpu_deallocate_topology_userdata(hwloc_get_root_obj(config->topology.hwtopology));
 	hwloc_topology_destroy(config->topology.hwtopology);
 	hwloc_topology_destroy(config->topology.hwtopology);
 #endif
 #endif
 
 
@@ -1693,11 +1722,10 @@ _starpu_init_workers_binding (struct _starpu_machine_config *config, int no_mp_c
 			hwloc_obj_t worker_obj = hwloc_get_obj_by_depth(config->topology.hwtopology,
 			hwloc_obj_t worker_obj = hwloc_get_obj_by_depth(config->topology.hwtopology,
 									config->pu_depth,
 									config->pu_depth,
 									workerarg->bindid);
 									workerarg->bindid);
-			if (worker_obj->userdata == NULL)
-			{
-				worker_obj->userdata = _starpu_worker_list_new();
-			}
-			_starpu_worker_list_push_front(worker_obj->userdata, workerarg);
+			struct _starpu_hwloc_userdata *data = worker_obj->userdata;
+			if (data->worker_list == NULL)
+				data->worker_list = _starpu_worker_list_new();
+			_starpu_worker_list_push_front(data->worker_list, workerarg);
 
 
 			/* Clear the cpu set and set the cpu */
 			/* Clear the cpu set and set the cpu */
 			workerarg->hwloc_cpu_set = hwloc_bitmap_dup (worker_obj->cpuset);
 			workerarg->hwloc_cpu_set = hwloc_bitmap_dup (worker_obj->cpuset);

+ 10 - 1
src/core/topology.h

@@ -1,6 +1,6 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
  *
- * Copyright (C) 2009-2010, 2012, 2014-2015  Université de Bordeaux
+ * Copyright (C) 2009-2010, 2012, 2014-2016  Université de Bordeaux
  * Copyright (C) 2010, 2015  CNRS
  * Copyright (C) 2010, 2015  CNRS
  *
  *
  * StarPU is free software; you can redistribute it and/or modify
  * StarPU is free software; you can redistribute it and/or modify
@@ -26,6 +26,15 @@
 /* TODO actually move this struct into this header */
 /* TODO actually move this struct into this header */
 struct _starpu_machine_config;
 struct _starpu_machine_config;
 
 
+#ifndef STARPU_SIMGRID
+#ifdef STARPU_HAVE_HWLOC
+/* This is allocated for each hwloc object */
+struct _starpu_hwloc_userdata {
+	struct _starpu_worker_list *worker_list; /* List of workers running on this obj */
+};
+#endif
+#endif
+
 /* Detect the number of memory nodes and where to bind the different workers. */
 /* Detect the number of memory nodes and where to bind the different workers. */
 int _starpu_build_topology(struct _starpu_machine_config *config, int no_mp_config);
 int _starpu_build_topology(struct _starpu_machine_config *config, int no_mp_config);