diff options
| author | Jonathan Peyton <jonathan.l.peyton@intel.com> | 2016-09-12 19:02:53 +0000 |
|---|---|---|
| committer | Jonathan Peyton <jonathan.l.peyton@intel.com> | 2016-09-12 19:02:53 +0000 |
| commit | 7c465a5f41f5e862bb6438a93c34fa089e5dd109 (patch) | |
| tree | 26eb14949731a60e7304a78f285cd0805b4a7256 /openmp | |
| parent | 5730bf04292dfeed06b3717a32b26acaa1690c69 (diff) | |
| download | bcm5719-llvm-7c465a5f41f5e862bb6438a93c34fa089e5dd109.tar.gz bcm5719-llvm-7c465a5f41f5e862bb6438a93c34fa089e5dd109.zip | |
Fix bitmask upper bounds check
Rather than checking KMP_CPU_SETSIZE, which doesn't exist when using Hwloc, we
use the get_max_proc() function which can vary based on the operating system.
For example on Windows with multiple processor groups, it might be the case that
the highest bit possible in the bitmask is not equal to the number of hardware
threads on the machine but something higher than that.
Differential Revision: https://reviews.llvm.org/D24206
llvm-svn: 281245
Diffstat (limited to 'openmp')
| -rw-r--r-- | openmp/runtime/src/kmp.h | 1 | ||||
| -rw-r--r-- | openmp/runtime/src/kmp_affinity.cpp | 31 | ||||
| -rw-r--r-- | openmp/runtime/src/kmp_ftn_entry.h | 11 |
3 files changed, 18 insertions, 25 deletions
diff --git a/openmp/runtime/src/kmp.h b/openmp/runtime/src/kmp.h index 88e288bef35..60ae3164eae 100644 --- a/openmp/runtime/src/kmp.h +++ b/openmp/runtime/src/kmp.h @@ -3170,6 +3170,7 @@ extern void __kmp_affinity_set_place(int gtid); extern void __kmp_affinity_determine_capable( const char *env_var ); extern int __kmp_aux_set_affinity(void **mask); extern int __kmp_aux_get_affinity(void **mask); +extern int __kmp_aux_get_affinity_max_proc(); extern int __kmp_aux_set_affinity_mask_proc(int proc, void **mask); extern int __kmp_aux_unset_affinity_mask_proc(int proc, void **mask); extern int __kmp_aux_get_affinity_mask_proc(int proc, void **mask); diff --git a/openmp/runtime/src/kmp_affinity.cpp b/openmp/runtime/src/kmp_affinity.cpp index 251ee0c2971..93299b53e0a 100644 --- a/openmp/runtime/src/kmp_affinity.cpp +++ b/openmp/runtime/src/kmp_affinity.cpp @@ -4534,6 +4534,19 @@ __kmp_aux_get_affinity(void **mask) } int +__kmp_aux_get_affinity_max_proc() { + if (! KMP_AFFINITY_CAPABLE()) { + return 0; + } +#if KMP_GROUP_AFFINITY + if ( __kmp_num_proc_groups > 1 ) { + return (int)(__kmp_num_proc_groups*sizeof(DWORD_PTR)*CHAR_BIT); + } +#endif + return __kmp_xproc; +} + +int __kmp_aux_set_affinity_mask_proc(int proc, void **mask) { int retval; @@ -4557,11 +4570,7 @@ __kmp_aux_set_affinity_mask_proc(int proc, void **mask) } } - if ((proc < 0) -# if !KMP_USE_HWLOC - || ((unsigned)proc >= KMP_CPU_SETSIZE) -# endif - ) { + if ((proc < 0) || (proc >= __kmp_aux_get_affinity_max_proc())) { return -1; } if (! KMP_CPU_ISSET(proc, __kmp_affin_fullMask)) { @@ -4597,11 +4606,7 @@ __kmp_aux_unset_affinity_mask_proc(int proc, void **mask) } } - if ((proc < 0) -# if !KMP_USE_HWLOC - || ((unsigned)proc >= KMP_CPU_SETSIZE) -# endif - ) { + if ((proc < 0) || (proc >= __kmp_aux_get_affinity_max_proc())) { return -1; } if (! KMP_CPU_ISSET(proc, __kmp_affin_fullMask)) { @@ -4637,11 +4642,7 @@ __kmp_aux_get_affinity_mask_proc(int proc, void **mask) } } - if ((proc < 0) -# if !KMP_USE_HWLOC - || ((unsigned)proc >= KMP_CPU_SETSIZE) -# endif - ) { + if ((proc < 0) || (proc >= __kmp_aux_get_affinity_max_proc())) { return -1; } if (! KMP_CPU_ISSET(proc, __kmp_affin_fullMask)) { diff --git a/openmp/runtime/src/kmp_ftn_entry.h b/openmp/runtime/src/kmp_ftn_entry.h index 7ad15e3740a..8f58b528f09 100644 --- a/openmp/runtime/src/kmp_ftn_entry.h +++ b/openmp/runtime/src/kmp_ftn_entry.h @@ -266,16 +266,7 @@ FTN_GET_AFFINITY_MAX_PROC( void ) if ( ! TCR_4(__kmp_init_middle) ) { __kmp_middle_initialize(); } - if ( ! ( KMP_AFFINITY_CAPABLE() ) ) { - return 0; - } - - #if KMP_GROUP_AFFINITY - if ( __kmp_num_proc_groups > 1 ) { - return (int)(__kmp_num_proc_groups*sizeof(DWORD_PTR)*CHAR_BIT); - } - #endif /* KMP_GROUP_AFFINITY */ - return __kmp_xproc; + return __kmp_aux_get_affinity_max_proc(); #endif } |

