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
This commit is contained in:
Jonathan Peyton 2016-09-12 19:02:53 +00:00
parent 5730bf0429
commit 7c465a5f41
3 changed files with 18 additions and 25 deletions

View File

@ -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);

View File

@ -4533,6 +4533,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)
{
@ -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)) {

View File

@ -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
}