[Openmp-commits] [openmp] r330283 - [OpenMP] Fix affinity API for KMP_AFFINITY=none|compact|scatter

Jonathan Peyton via Openmp-commits openmp-commits at lists.llvm.org
Wed Apr 18 12:25:48 PDT 2018


Author: jlpeyton
Date: Wed Apr 18 12:25:48 2018
New Revision: 330283

URL: http://llvm.org/viewvc/llvm-project?rev=330283&view=rev
Log:
[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

Modified:
    openmp/trunk/runtime/src/kmp.h
    openmp/trunk/runtime/src/kmp_affinity.cpp
    openmp/trunk/runtime/src/kmp_ftn_entry.h
    openmp/trunk/runtime/src/kmp_settings.cpp

Modified: openmp/trunk/runtime/src/kmp.h
URL: http://llvm.org/viewvc/llvm-project/openmp/trunk/runtime/src/kmp.h?rev=330283&r1=330282&r2=330283&view=diff
==============================================================================
--- openmp/trunk/runtime/src/kmp.h (original)
+++ openmp/trunk/runtime/src/kmp.h Wed Apr 18 12:25:48 2018
@@ -781,6 +781,11 @@ extern kmp_nested_proc_bind_t __kmp_nest
 #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;

Modified: openmp/trunk/runtime/src/kmp_affinity.cpp
URL: http://llvm.org/viewvc/llvm-project/openmp/trunk/runtime/src/kmp_affinity.cpp?rev=330283&r1=330282&r2=330283&view=diff
==============================================================================
--- openmp/trunk/runtime/src/kmp_affinity.cpp (original)
+++ openmp/trunk/runtime/src/kmp_affinity.cpp Wed Apr 18 12:25:48 2018
@@ -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_initializ
       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 gt
   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 gt
       }
 #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);

Modified: openmp/trunk/runtime/src/kmp_ftn_entry.h
URL: http://llvm.org/viewvc/llvm-project/openmp/trunk/runtime/src/kmp_ftn_entry.h?rev=330283&r1=330282&r2=330283&view=diff
==============================================================================
--- openmp/trunk/runtime/src/kmp_ftn_entry.h (original)
+++ openmp/trunk/runtime/src/kmp_ftn_entry.h Wed Apr 18 12:25:48 2018
@@ -691,6 +691,9 @@ int FTN_STDCALL FTN_GET_PARTITION_NUM_PL
   }
   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
     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)

Modified: openmp/trunk/runtime/src/kmp_settings.cpp
URL: http://llvm.org/viewvc/llvm-project/openmp/trunk/runtime/src/kmp_settings.cpp?rev=330283&r1=330282&r2=330283&view=diff
==============================================================================
--- openmp/trunk/runtime/src/kmp_settings.cpp (original)
+++ openmp/trunk/runtime/src/kmp_settings.cpp Wed Apr 18 12:25:48 2018
@@ -5407,6 +5407,8 @@ void __kmp_env_initialize(char const *st
     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
   }
 




More information about the Openmp-commits mailing list