[OpenMP] Fix affinity API for KMP_AFFINITY=none|compact|scatter
Currently, the affinity API reports garbage for the initial place list and any thread's place lists when using KMP_AFFINITY=none|compact|scatter. This patch does two things: for KMP_AFFINITY=none, Creates a one entry table for the places, this way, the initial place list is just a single place with all the proc ids in it. We also set the initial place of any thread to 0 instead of KMP_PLACE_ALL so that the thread reports that single place (place 0) instead of garbage (-1) when using the affinity API. When non-OMP_PROC_BIND affinity is used (including KMP_AFFINITY=compact|scatter), a thread's place list is populated correctly. We assume that each thread is assigned to a single place. This is implemented in two of the affinity API functions Differential Revision: https://reviews.llvm.org/D45527 git-svn-id: https://llvm.org/svn/llvm-project/openmp/trunk@330283 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -781,6 +781,11 @@ extern kmp_nested_proc_bind_t __kmp_nested_proc_bind;
|
||||
#if KMP_AFFINITY_SUPPORTED
|
||||
#define KMP_PLACE_ALL (-1)
|
||||
#define KMP_PLACE_UNDEFINED (-2)
|
||||
// Is KMP_AFFINITY is being used instead of OMP_PROC_BIND/OMP_PLACES?
|
||||
#define KMP_AFFINITY_NON_PROC_BIND \
|
||||
((__kmp_nested_proc_bind.bind_types[0] == proc_bind_false || \
|
||||
__kmp_nested_proc_bind.bind_types[0] == proc_bind_intel) && \
|
||||
(__kmp_affinity_num_masks > 0 || __kmp_affinity_type == affinity_balanced))
|
||||
#endif /* KMP_AFFINITY_SUPPORTED */
|
||||
|
||||
extern int __kmp_affinity_num_places;
|
||||
|
||||
@@ -3957,8 +3957,20 @@ static int __kmp_aff_depth = 0;
|
||||
KMP_ASSERT(__kmp_affinity_type == affinity_none); \
|
||||
KMP_ASSERT(address2os == NULL); \
|
||||
__kmp_apply_thread_places(NULL, 0); \
|
||||
__kmp_create_affinity_none_places(); \
|
||||
return;
|
||||
|
||||
// Create a one element mask array (set of places) which only contains the
|
||||
// initial process's affinity mask
|
||||
static void __kmp_create_affinity_none_places() {
|
||||
KMP_ASSERT(__kmp_affin_fullMask != NULL);
|
||||
KMP_ASSERT(__kmp_affinity_type == affinity_none);
|
||||
__kmp_affinity_num_masks = 1;
|
||||
KMP_CPU_ALLOC_ARRAY(__kmp_affinity_masks, __kmp_affinity_num_masks);
|
||||
kmp_affin_mask_t *dest = KMP_CPU_INDEX(__kmp_affinity_masks, 0);
|
||||
KMP_CPU_COPY(dest, __kmp_affin_fullMask);
|
||||
}
|
||||
|
||||
static int __kmp_affinity_cmp_Address_child_num(const void *a, const void *b) {
|
||||
const Address *aa = &(((const AddrUnsPair *)a)->first);
|
||||
const Address *bb = &(((const AddrUnsPair *)b)->first);
|
||||
@@ -4295,6 +4307,7 @@ static void __kmp_aux_affinity_initialize(void) {
|
||||
KMP_WARNING(ErrorInitializeAffinity);
|
||||
}
|
||||
__kmp_affinity_type = affinity_none;
|
||||
__kmp_create_affinity_none_places();
|
||||
KMP_AFFINITY_DISABLE();
|
||||
return;
|
||||
}
|
||||
@@ -4578,7 +4591,7 @@ void __kmp_affinity_set_init_mask(int gtid, int isa_root) {
|
||||
int i;
|
||||
|
||||
#if OMP_40_ENABLED
|
||||
if (__kmp_nested_proc_bind.bind_types[0] == proc_bind_intel)
|
||||
if (KMP_AFFINITY_NON_PROC_BIND)
|
||||
#endif
|
||||
{
|
||||
if ((__kmp_affinity_type == affinity_none) ||
|
||||
@@ -4589,7 +4602,7 @@ void __kmp_affinity_set_init_mask(int gtid, int isa_root) {
|
||||
}
|
||||
#endif
|
||||
KMP_ASSERT(__kmp_affin_fullMask != NULL);
|
||||
i = KMP_PLACE_ALL;
|
||||
i = 0;
|
||||
mask = __kmp_affin_fullMask;
|
||||
} else {
|
||||
KMP_DEBUG_ASSERT(__kmp_affinity_num_masks > 0);
|
||||
|
||||
@@ -691,6 +691,9 @@ int FTN_STDCALL FTN_GET_PARTITION_NUM_PLACES(void) {
|
||||
}
|
||||
if (!KMP_AFFINITY_CAPABLE())
|
||||
return 0;
|
||||
if (KMP_AFFINITY_NON_PROC_BIND) {
|
||||
return 1;
|
||||
}
|
||||
gtid = __kmp_entry_gtid();
|
||||
thread = __kmp_thread_from_gtid(gtid);
|
||||
first_place = thread->th.th_first_place;
|
||||
@@ -718,6 +721,10 @@ void FTN_STDCALL FTN_GET_PARTITION_PLACE_NUMS(int *place_nums) {
|
||||
return;
|
||||
gtid = __kmp_entry_gtid();
|
||||
thread = __kmp_thread_from_gtid(gtid);
|
||||
if (KMP_AFFINITY_NON_PROC_BIND) {
|
||||
place_nums[0] = thread->th.th_current_place;
|
||||
return;
|
||||
}
|
||||
first_place = thread->th.th_first_place;
|
||||
last_place = thread->th.th_last_place;
|
||||
if (first_place < 0 || last_place < 0)
|
||||
|
||||
@@ -5407,6 +5407,8 @@ void __kmp_env_initialize(char const *string) {
|
||||
KMP_DEBUG_ASSERT(__kmp_affinity_type != affinity_default);
|
||||
#if OMP_40_ENABLED
|
||||
KMP_DEBUG_ASSERT(__kmp_nested_proc_bind.bind_types[0] != proc_bind_default);
|
||||
K_DIAG(1, ("__kmp_nested_proc_bind.bind_types[0] == %d\n",
|
||||
__kmp_nested_proc_bind.bind_types[0]));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user