diff options
author | Jonathan Peyton <jonathan.l.peyton@intel.com> | 2015-11-30 20:02:59 +0000 |
---|---|---|
committer | Jonathan Peyton <jonathan.l.peyton@intel.com> | 2015-11-30 20:02:59 +0000 |
commit | 01dcf36bd54be75dcf6c3cc9cc8d1f20e783d86a (patch) | |
tree | 538111ad7545036c7e9d75ab83e37da63b4ddaa9 /openmp/runtime/src/z_Linux_util.c | |
parent | 7a096596b2eead02405329a5504b0d71dd5b4a8d (diff) | |
download | bcm5719-llvm-01dcf36bd54be75dcf6c3cc9cc8d1f20e783d86a.tar.gz bcm5719-llvm-01dcf36bd54be75dcf6c3cc9cc8d1f20e783d86a.zip |
Adding Hwloc library option for affinity mechanism
These changes allow libhwloc to be used as the topology discovery/affinity
mechanism for libomp. It is supported on Unices. The code additions:
* Canonicalize KMP_CPU_* interface macros so bitmask operations are
implementation independent and work with both hwloc bitmaps and libomp
bitmaps. So there are new KMP_CPU_ALLOC_* and KMP_CPU_ITERATE() macros and
the like. These are all in kmp.h and appropriately placed.
* Hwloc topology discovery code in kmp_affinity.cpp. This uses the hwloc
interface to create a libomp address2os object which the rest of libomp knows
how to handle already.
* To build, use -DLIBOMP_USE_HWLOC=on and
-DLIBOMP_HWLOC_INSTALL_DIR=/path/to/install/dir [default /usr/local]. If CMake
can't find the library or hwloc.h, then it will tell you and exit.
Differential Revision: http://reviews.llvm.org/D13991
llvm-svn: 254320
Diffstat (limited to 'openmp/runtime/src/z_Linux_util.c')
-rw-r--r-- | openmp/runtime/src/z_Linux_util.c | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/openmp/runtime/src/z_Linux_util.c b/openmp/runtime/src/z_Linux_util.c index 890ec5cfaaf..237677b24cf 100644 --- a/openmp/runtime/src/z_Linux_util.c +++ b/openmp/runtime/src/z_Linux_util.c @@ -175,8 +175,11 @@ __kmp_set_system_affinity( kmp_affin_mask_t const *mask, int abort_on_error ) { KMP_ASSERT2(KMP_AFFINITY_CAPABLE(), "Illegal set affinity operation when not capable"); - +#if KMP_USE_HWLOC + int retval = hwloc_set_cpubind(__kmp_hwloc_topology, (hwloc_cpuset_t)mask, HWLOC_CPUBIND_THREAD); +#else int retval = syscall( __NR_sched_setaffinity, 0, __kmp_affin_mask_size, mask ); +#endif if (retval >= 0) { return 0; } @@ -198,7 +201,11 @@ __kmp_get_system_affinity( kmp_affin_mask_t *mask, int abort_on_error ) KMP_ASSERT2(KMP_AFFINITY_CAPABLE(), "Illegal get affinity operation when not capable"); +#if KMP_USE_HWLOC + int retval = hwloc_get_cpubind(__kmp_hwloc_topology, (hwloc_cpuset_t)mask, HWLOC_CPUBIND_THREAD); +#else int retval = syscall( __NR_sched_getaffinity, 0, __kmp_affin_mask_size, mask ); +#endif if (retval >= 0) { return 0; } @@ -220,10 +227,12 @@ __kmp_affinity_bind_thread( int which ) KMP_ASSERT2(KMP_AFFINITY_CAPABLE(), "Illegal set affinity operation when not capable"); - kmp_affin_mask_t *mask = (kmp_affin_mask_t *)KMP_ALLOCA(__kmp_affin_mask_size); + kmp_affin_mask_t *mask; + KMP_CPU_ALLOC_ON_STACK(mask); KMP_CPU_ZERO(mask); KMP_CPU_SET(which, mask); __kmp_set_system_affinity(mask, TRUE); + KMP_CPU_FREE_FROM_STACK(mask); } /* |