Browse Source

add a public function to get a copy of a worker's hwloc cpuset

Olivier Aumage 8 years ago
parent
commit
e1f6d2a8e4

+ 7 - 0
doc/doxygen/chapters/api/workers.doxy

@@ -320,4 +320,11 @@ if needed during the waiting process. Returns 1 if \p workerid has been woken
 up or its state_keep_awake flag has been set to 1, and 0 otherwise (if \p
 workerid was not in the STATE_SLEEPING or in the STATE_SCHEDULING).
 
+\fn hwloc_cpuset_t starpu_worker_get_hwloc_cpuset(int workerid)
+\ingroup API_Workers_Properties
+If StarPU was compiled with hwloc support, returns a duplicate of the
+hwloc cpuset associated with the worker \p workerid. The returned cpuset is obtained
+from a \c hwloc_bitmap_dup() function call. It must be freed by the caller
+using \c hwloc_bitmap_free().
+
 */

+ 8 - 0
include/starpu_worker.h

@@ -25,6 +25,10 @@
 #include <starpu_thread.h>
 #include <starpu_task.h>
 
+#ifdef STARPU_HAVE_HWLOC
+#include <hwloc.h>
+#endif
+
 #ifdef __cplusplus
 extern "C"
 {
@@ -162,6 +166,10 @@ void starpu_worker_unlock_self(void);
 
 int starpu_wake_worker_relax(int workerid);
 
+#ifdef STARPU_HAVE_HWLOC
+hwloc_cpuset_t starpu_worker_get_hwloc_cpuset(int workerid);
+#endif
+
 #ifdef __cplusplus
 }
 #endif

+ 8 - 0
src/core/workers.c

@@ -2398,3 +2398,11 @@ int starpu_wake_worker_relax(int workerid)
 {
 	return _starpu_wake_worker_relax(workerid);
 }
+
+#ifdef STARPU_HAVE_HWLOC
+hwloc_cpuset_t starpu_worker_get_hwloc_cpuset(int workerid)
+{
+	struct _starpu_worker *worker = _starpu_get_worker_struct(workerid);
+	return hwloc_bitmap_dup(worker->hwloc_cpu_set);
+}
+#endif

+ 1 - 0
tests/Makefile.am

@@ -207,6 +207,7 @@ myPROGRAMS +=				\
 	main/pause_resume			\
 	main/pack				\
 	main/get_children_tasks			\
+	main/hwloc_cpuset			\
 	datawizard/acquire_cb_insert		\
 	datawizard/acquire_release		\
 	datawizard/acquire_release2		\

+ 79 - 0
tests/main/hwloc_cpuset.c

@@ -0,0 +1,79 @@
+/* StarPU --- Runtime system for heterogeneous multicore architectures.
+ *
+ * Copyright (C) 2017  Inria
+ *
+ * StarPU is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or (at
+ * your option) any later version.
+ *
+ * StarPU is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * See the GNU Lesser General Public License in COPYING.LGPL for more details.
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+#include <starpu.h>
+#include "../helper.h"
+
+/*
+ * Test workers hwloc cpusets
+ */
+
+int main(int argc, char **argv)
+{
+	int status = 0;
+#ifdef STARPU_HAVE_HWLOC
+	int ret = starpu_init(NULL);
+	if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
+	STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
+	int nworkers = starpu_worker_get_count_by_type(STARPU_CPU_WORKER);
+	if (nworkers != 0)
+	{
+		hwloc_cpuset_t accumulator_cpuset = hwloc_bitmap_alloc();
+		hwloc_cpuset_t temp_cpuset = hwloc_bitmap_alloc();
+		hwloc_bitmap_zero(accumulator_cpuset);
+		status = 0;
+		int workerids[nworkers];
+		starpu_worker_get_ids_by_type(STARPU_CPU_WORKER, workerids, nworkers);
+		int i;
+		for (i=0; i<nworkers; i++)
+		{
+			hwloc_cpuset_t cpuset = starpu_worker_get_hwloc_cpuset(workerids[i]);
+			/* check that the worker cpuset is not empty */
+			if (hwloc_bitmap_iszero(cpuset))
+			{
+				status = EXIT_FAILURE;
+				hwloc_bitmap_free(cpuset);
+				break;
+			}
+			hwloc_bitmap_zero(temp_cpuset);
+			/* check that the worker cpuset does not overlap other workers cpusets */
+			hwloc_bitmap_and(temp_cpuset, accumulator_cpuset, cpuset);
+			if (!hwloc_bitmap_iszero(temp_cpuset))
+			{
+				status = EXIT_FAILURE;
+				hwloc_bitmap_free(cpuset);
+				break;
+			}
+
+			hwloc_bitmap_or(accumulator_cpuset, accumulator_cpuset, cpuset);
+
+			/* the cpuset returned by starpu_worker_get_hwloc_cpuset() must be freed */
+			hwloc_bitmap_free(cpuset);
+		}
+		hwloc_bitmap_free(temp_cpuset);
+		hwloc_bitmap_free(accumulator_cpuset);
+	}
+	else
+	{
+		status = STARPU_TEST_SKIPPED;
+	}
+#else
+	status = STARPU_TEST_SKIPPED;
+#endif
+	return status;
+}