Pārlūkot izejas kodu

Fix parallel task execution for fork-join tasks: we need to bind the master thread to the parallel worker

Samuel Thibault 13 gadi atpakaļ
vecāks
revīzija
a988aa34df
3 mainītis faili ar 38 papildinājumiem un 1 dzēšanām
  1. 27 0
      src/core/topology.c
  2. 5 1
      src/core/topology.h
  3. 6 0
      src/drivers/cpu/driver_cpu.c

+ 27 - 0
src/core/topology.c

@@ -692,6 +692,33 @@ void _starpu_bind_thread_on_cpu(struct _starpu_machine_config *config STARPU_ATT
 #endif
 }
 
+
+void _starpu_bind_thread_on_cpus(struct _starpu_machine_config *config STARPU_ATTRIBUTE_UNUSED, struct _starpu_combined_worker *combined_worker)
+{
+#ifdef STARPU_HAVE_HWLOC
+	const struct hwloc_topology_support *support;
+
+	_starpu_init_topology(config);
+
+	support = hwloc_topology_get_support(config->topology.hwtopology);
+	if (support->cpubind->set_thisthread_cpubind)
+	{
+		hwloc_cpuset_t set = combined_worker->hwloc_cpu_set;
+		int ret;
+
+		ret = hwloc_set_cpubind(config->topology.hwtopology, set, HWLOC_CPUBIND_THREAD);
+		if (ret)
+		{
+			perror("binding thread");
+			STARPU_ABORT();
+		}
+	}
+#else
+#warning no parallel worker CPU binding support
+#endif
+}
+
+
 static void _starpu_init_workers_binding(struct _starpu_machine_config *config)
 {
 	/* launch one thread per CPU */

+ 5 - 1
src/core/topology.h

@@ -1,6 +1,6 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
- * Copyright (C) 2009, 2010  Université de Bordeaux 1
+ * Copyright (C) 2009-2010, 2012  Université de Bordeaux 1
  * Copyright (C) 2010  Centre National de la Recherche Scientifique
  *
  * StarPU is free software; you can redistribute it and/or modify
@@ -40,4 +40,8 @@ unsigned _starpu_topology_get_nhwcpu(struct _starpu_machine_config *config);
  * or the ordering exposed by the OS. */
 void _starpu_bind_thread_on_cpu(struct _starpu_machine_config *config, unsigned cpuid);
 
+struct _starpu_combined_worker;
+/* Bind the current thread on the set of CPUs for the given combined worker. */
+void _starpu_bind_thread_on_cpus(struct _starpu_machine_config *config STARPU_ATTRIBUTE_UNUSED, struct _starpu_combined_worker *combined_worker);
+
 #endif // __TOPOLOGY_H__

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

@@ -56,8 +56,14 @@ static int execute_job_on_cpu(struct _starpu_job *j, struct _starpu_worker *cpu_
 	if ((rank == 0) || (cl->type != STARPU_FORKJOIN))
 	{
 		_starpu_cl_func_t func = _starpu_task_get_cpu_nth_implementation(cl, j->nimpl);
+		if (is_parallel_task && cl->type == STARPU_FORKJOIN)
+			/* bind to parallel worker */
+			_starpu_bind_thread_on_cpus(cpu_args->config, _starpu_get_combined_worker_struct(j->combined_workerid));
 		STARPU_ASSERT(func);
 		func(task->interfaces, task->cl_arg);
+		if (is_parallel_task && cl->type == STARPU_FORKJOIN)
+			/* rebind to single CPU */
+			_starpu_bind_thread_on_cpu(cpu_args->config, cpu_args->bindid);
 	}
 
 	_starpu_driver_end_job(cpu_args, j, perf_arch, &codelet_end, rank);