diff options
| author | Jonathan Peyton <jonathan.l.peyton@intel.com> | 2018-04-18 19:25:48 +0000 |
|---|---|---|
| committer | Jonathan Peyton <jonathan.l.peyton@intel.com> | 2018-04-18 19:25:48 +0000 |
| commit | 1482db9e03f00dc646c02b0bbc1652ca9d31557f (patch) | |
| tree | fbc65f67f52b603c61806db2f2c1c004785a5da9 /openmp/runtime/src | |
| parent | 27a677fc95c77d9cc31762bb1dd11da3173de8a1 (diff) | |
| download | bcm5719-llvm-1482db9e03f00dc646c02b0bbc1652ca9d31557f.tar.gz bcm5719-llvm-1482db9e03f00dc646c02b0bbc1652ca9d31557f.zip | |
[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
llvm-svn: 330283
Diffstat (limited to 'openmp/runtime/src')
| -rw-r--r-- | openmp/runtime/src/kmp.h | 5 | ||||
| -rw-r--r-- | openmp/runtime/src/kmp_affinity.cpp | 17 | ||||
| -rw-r--r-- | openmp/runtime/src/kmp_ftn_entry.h | 7 | ||||
| -rw-r--r-- | openmp/runtime/src/kmp_settings.cpp | 2 |
4 files changed, 29 insertions, 2 deletions
diff --git a/openmp/runtime/src/kmp.h b/openmp/runtime/src/kmp.h index 27c2a5368b0..94485a15e4d 100644 --- a/openmp/runtime/src/kmp.h +++ b/openmp/runtime/src/kmp.h @@ -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; diff --git a/openmp/runtime/src/kmp_affinity.cpp b/openmp/runtime/src/kmp_affinity.cpp index 9cc504b6520..b7da8d4f8e8 100644 --- a/openmp/runtime/src/kmp_affinity.cpp +++ b/openmp/runtime/src/kmp_affinity.cpp @@ -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); diff --git a/openmp/runtime/src/kmp_ftn_entry.h b/openmp/runtime/src/kmp_ftn_entry.h index f98ee9d8d55..0f09828480f 100644 --- a/openmp/runtime/src/kmp_ftn_entry.h +++ b/openmp/runtime/src/kmp_ftn_entry.h @@ -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) diff --git a/openmp/runtime/src/kmp_settings.cpp b/openmp/runtime/src/kmp_settings.cpp index 6fb772b3b78..d2502d0ad07 100644 --- a/openmp/runtime/src/kmp_settings.cpp +++ b/openmp/runtime/src/kmp_settings.cpp @@ -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 } |

