summaryrefslogtreecommitdiffstats
path: root/openmp/runtime/src/kmp_settings.c
diff options
context:
space:
mode:
authorJonathan Peyton <jonathan.l.peyton@intel.com>2015-11-30 20:02:59 +0000
committerJonathan Peyton <jonathan.l.peyton@intel.com>2015-11-30 20:02:59 +0000
commit01dcf36bd54be75dcf6c3cc9cc8d1f20e783d86a (patch)
tree538111ad7545036c7e9d75ab83e37da63b4ddaa9 /openmp/runtime/src/kmp_settings.c
parent7a096596b2eead02405329a5504b0d71dd5b4a8d (diff)
downloadbcm5719-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/kmp_settings.c')
-rw-r--r--openmp/runtime/src/kmp_settings.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/openmp/runtime/src/kmp_settings.c b/openmp/runtime/src/kmp_settings.c
index 51b23ee2e46..d9485b05af0 100644
--- a/openmp/runtime/src/kmp_settings.c
+++ b/openmp/runtime/src/kmp_settings.c
@@ -3009,6 +3009,11 @@ __kmp_stg_parse_topology_method( char const * name, char const * value,
else if ( __kmp_str_match( "flat", 1, value ) ) {
__kmp_affinity_top_method = affinity_top_method_flat;
}
+# if KMP_USE_HWLOC
+ else if ( __kmp_str_match( "hwloc", 1, value) ) {
+ __kmp_affinity_top_method = affinity_top_method_hwloc;
+ }
+# endif
else {
KMP_WARNING( StgInvalidValue, name, value );
}
@@ -5119,11 +5124,43 @@ __kmp_env_initialize( char const * string ) {
// affinity.
//
const char *var = "KMP_AFFINITY";
+# if KMP_USE_HWLOC
+ if(hwloc_topology_init(&__kmp_hwloc_topology) < 0) {
+ __kmp_hwloc_error = TRUE;
+ if(__kmp_affinity_verbose)
+ KMP_WARNING(AffHwlocErrorOccurred, var, "hwloc_topology_init()");
+ }
+ hwloc_topology_ignore_type(__kmp_hwloc_topology, HWLOC_OBJ_CACHE);
+# endif
if ( __kmp_affinity_type == affinity_disabled ) {
KMP_AFFINITY_DISABLE();
}
else if ( ! KMP_AFFINITY_CAPABLE() ) {
+# if KMP_USE_HWLOC
+ const hwloc_topology_support* topology_support = hwloc_topology_get_support(__kmp_hwloc_topology);
+ if(hwloc_topology_load(__kmp_hwloc_topology) < 0) {
+ __kmp_hwloc_error = TRUE;
+ if(__kmp_affinity_verbose)
+ KMP_WARNING(AffHwlocErrorOccurred, var, "hwloc_topology_load()");
+ }
+ // Is the system capable of setting/getting this thread's affinity?
+ // also, is topology discovery possible? (pu indicates ability to discover processing units)
+ // and finally, were there no errors when calling any hwloc_* API functions?
+ if(topology_support->cpubind->set_thisthread_cpubind &&
+ topology_support->cpubind->get_thisthread_cpubind &&
+ topology_support->discovery->pu &&
+ !__kmp_hwloc_error)
+ {
+ // enables affinity according to KMP_AFFINITY_CAPABLE() macro
+ KMP_AFFINITY_ENABLE(TRUE);
+ } else {
+ // indicate that hwloc didn't work and disable affinity
+ __kmp_hwloc_error = TRUE;
+ KMP_AFFINITY_DISABLE();
+ }
+# else
__kmp_affinity_determine_capable( var );
+# endif // KMP_USE_HWLOC
if ( ! KMP_AFFINITY_CAPABLE() ) {
if ( __kmp_affinity_verbose || ( __kmp_affinity_warnings
&& ( __kmp_affinity_type != affinity_default )
OpenPOWER on IntegriCloud