Add initial support for OpenMP 4.5 task priority feature
authorJonathan Peyton <jonathan.l.peyton@intel.com>
Thu, 25 Feb 2016 18:04:09 +0000 (18:04 +0000)
committerJonathan Peyton <jonathan.l.peyton@intel.com>
Thu, 25 Feb 2016 18:04:09 +0000 (18:04 +0000)
The maximum task priority value is read from envirable: OMP_MAX_TASK_PRIORITY.
But as of now, nothing is done with it.  We just handle the environment variable
and add the new api: omp_get_max_task_priority() which returns that value or
zero if it is not set.

Differential Revision: http://reviews.llvm.org/D17411

llvm-svn: 261908

12 files changed:
openmp/runtime/src/dllexports
openmp/runtime/src/include/41/omp.h.var
openmp/runtime/src/include/41/omp_lib.f.var
openmp/runtime/src/include/41/omp_lib.f90.var
openmp/runtime/src/include/41/omp_lib.h.var
openmp/runtime/src/kmp.h
openmp/runtime/src/kmp_ftn_entry.h
openmp/runtime/src/kmp_ftn_os.h
openmp/runtime/src/kmp_global.c
openmp/runtime/src/kmp_settings.c
openmp/runtime/src/kmp_tasking.c
openmp/runtime/test/lit.cfg

index ca7d736..f14da70 100644 (file)
@@ -497,6 +497,7 @@ kmp_set_warnings_off                        780
 %ifdef OMP_41
     omp_init_lock_with_hint                 870
     omp_init_nest_lock_with_hint            871
+    omp_get_max_task_priority               872
 %endif # OMP_41
 
 %ifndef stub
index 6d9fa43..4597d0e 100644 (file)
@@ -62,6 +62,7 @@
     extern int    __KAI_KMPC_CONVENTION  omp_get_thread_limit        (void);
     extern int    __KAI_KMPC_CONVENTION  omp_get_max_active_levels   (void);
     extern void   __KAI_KMPC_CONVENTION  omp_get_schedule            (omp_sched_t *, int *);
+    extern int    __KAI_KMPC_CONVENTION  omp_get_max_task_priority   (void);
 
     /* lock API functions */
     typedef struct omp_lock_t {
index c801908..d3406e0 100644 (file)
             integer (kind=omp_nest_lock_kind) lockvar
           end function omp_test_nest_lock
 
+          function omp_get_max_task_priority()
+            use omp_lib_kinds
+            integer (kind=omp_integer_kind) omp_get_max_task_priority
+          end function omp_get_max_task_priority
+
 !         ***
 !         *** kmp_* entry points
 !         ***
 !dec$ attributes alias:'OMP_GET_TEAM_NUM' :: omp_get_team_num
 !dec$ attributes alias:'OMP_GET_CANCELLATION' :: omp_get_cancellation
 !dec$ attributes alias:'OMP_IS_INITIAL_DEVICE' :: omp_is_initial_device
+!dec$ attributes alias:'OMP_GET_MAX_TASK_PRIORITY' :: omp_get_max_task_priority
 
 !dec$ attributes alias:'omp_init_lock' :: omp_init_lock
 !dec$ attributes alias:'omp_init_lock_with_hint' :: omp_init_lock_with_hint
 !dec$ attributes alias:'_OMP_GET_TEAM_NUM' :: omp_get_team_num
 !dec$ attributes alias:'_OMP_GET_CANCELLATION' :: omp_get_cancellation
 !dec$ attributes alias:'_OMP_IS_INITIAL_DEVICE' :: omp_is_initial_device
+!dec$ attributes alias:'_OMP_GET_MAX_TASK_PRIORTY' :: omp_get_max_task_priority
 
 !dec$ attributes alias:'_omp_init_lock' :: omp_init_lock
 !dec$ attributes alias:'_omp_init_lock_with_hint' :: omp_init_lock_with_hint
 !dec$ attributes alias:'omp_get_team_num_'::omp_get_team_num
 !dec$ attributes alias:'omp_get_cancellation_'::omp_get_cancellation
 !dec$ attributes alias:'omp_is_initial_device_'::omp_is_initial_device
+!dec$ attributes alias:'omp_get_max_task_priority_'::omp_get_max_task_priority
 
 !dec$ attributes alias:'omp_init_lock_'::omp_init_lock
 !dec$ attributes alias:'omp_init_lock_with_hint_'::omp_init_lock_with_hint
 !dec$ attributes alias:'_omp_get_team_num_'::omp_get_team_num
 !dec$ attributes alias:'_omp_get_cancellation_'::omp_get_cancellation
 !dec$ attributes alias:'_omp_is_initial_device_'::omp_is_initial_device
+!dec$ attributes alias:'_omp_get_max_task_priorty_'::omp_get_max_task_priority
 
 !dec$ attributes alias:'_omp_init_lock_'::omp_init_lock
 !dec$ attributes alias:'_omp_init_lock_with_hint_'::omp_init_lock_with_hint
index 2d23667..18770e4 100644 (file)
             integer (kind=omp_nest_lock_kind) lockvar
           end function omp_test_nest_lock
 
+          function omp_get_max_task_priority() bind(c)
+            use omp_lib_kinds
+            integer (kind=omp_integer_kind) omp_get_max_task_priority
+          end function omp_get_max_task_priority
+
 !         ***
 !         *** kmp_* entry points
 !         ***
index 867bcd9..fbdd848 100644 (file)
           integer (kind=omp_nest_lock_kind) lockvar
         end function omp_test_nest_lock
 
+        function omp_get_max_task_priority() bind(c)
+          import
+          integer (kind=omp_integer_kind) omp_get_max_task_priority
+        end function omp_get_max_task_priority
+
 !       ***
 !       *** kmp_* entry points
 !       ***
 !DIR$ ATTRIBUTES OFFLOAD:MIC :: omp_set_nest_lock
 !DIR$ ATTRIBUTES OFFLOAD:MIC :: omp_unset_nest_lock
 !DIR$ ATTRIBUTES OFFLOAD:MIC :: omp_test_nest_lock
+!DIR$ ATTRIBUTES OFFLOAD:MIC :: omp_get_max_task_priority
 !DIR$ ATTRIBUTES OFFLOAD:MIC :: kmp_set_stacksize
 !DIR$ ATTRIBUTES OFFLOAD:MIC :: kmp_set_stacksize_s
 !DIR$ ATTRIBUTES OFFLOAD:MIC :: kmp_set_blocktime
 !$omp declare target(omp_set_nest_lock )
 !$omp declare target(omp_unset_nest_lock )
 !$omp declare target(omp_test_nest_lock )
+!$omp declare target(omp_get_max_task_priority )
 !$omp declare target(kmp_set_stacksize )
 !$omp declare target(kmp_set_stacksize_s )
 !$omp declare target(kmp_set_blocktime )
index 3e1c63f..71bb323 100644 (file)
@@ -1060,6 +1060,8 @@ extern int __kmp_place_num_threads_per_core;
 
 #define KMP_MAX_ACTIVE_LEVELS_LIMIT INT_MAX
 
+#define KMP_MAX_TASK_PRIORITY_LIMIT INT_MAX
+
 /* Minimum number of threads before switch to TLS gtid (experimentally determined) */
 /* josh TODO: what about OS X* tuning? */
 #if   KMP_ARCH_X86 || KMP_ARCH_X86_64
@@ -1998,6 +2000,9 @@ typedef enum kmp_tasking_mode {
 
 extern kmp_tasking_mode_t __kmp_tasking_mode;         /* determines how/when to execute tasks */
 extern kmp_int32 __kmp_task_stealing_constraint;
+#if OMP_41_ENABLED
+    extern kmp_int32 __kmp_max_task_priority; // Set via OMP_MAX_TASK_PRIORITY if specified, defaults to 0 otherwise
+#endif
 
 /* NOTE: kmp_taskdata_t and kmp_task_t structures allocated in single block with taskdata first */
 #define KMP_TASK_TO_TASKDATA(task)     (((kmp_taskdata_t *) task) - 1)
@@ -2016,6 +2021,18 @@ extern kmp_int32 __kmp_task_stealing_constraint;
  */
 typedef kmp_int32 (* kmp_routine_entry_t)( kmp_int32, void * );
 
+#if OMP_40_ENABLED || OMP_41_ENABLED
+typedef union kmp_cmplrdata {
+#if OMP_41_ENABLED
+    kmp_int32           priority;           /**< priority specified by user for the task */
+#endif // OMP_41_ENABLED
+#if OMP_40_ENABLED
+    kmp_routine_entry_t destructors;        /* pointer to function to invoke deconstructors of firstprivate C++ objects */
+#endif // OMP_40_ENABLED
+    /* future data */
+} kmp_cmplrdata_t;
+#endif
+
 /*  sizeof_kmp_task_t passed as arg to kmpc_omp_task call  */
 /*!
  */
@@ -2023,9 +2040,11 @@ typedef struct kmp_task {                   /* GEH: Shouldn't this be aligned so
     void *              shareds;            /**< pointer to block of pointers to shared vars   */
     kmp_routine_entry_t routine;            /**< pointer to routine to call for executing task */
     kmp_int32           part_id;            /**< part id for the task                          */
-#if OMP_40_ENABLED
-    kmp_routine_entry_t destructors;        /* pointer to function to invoke deconstructors of firstprivate C++ objects */
-#endif // OMP_40_ENABLED
+#if OMP_40_ENABLED || OMP_41_ENABLED
+    kmp_cmplrdata_t data1;                  /* Two known optional additions: destructors and priority */
+    kmp_cmplrdata_t data2;                  /* Process destructors first, priority second */
+    /* future data */
+#endif
     /*  private vars  */
 } kmp_task_t;
 
@@ -2124,7 +2143,8 @@ typedef struct kmp_tasking_flags {          /* Total struct must be exactly 32 b
     unsigned destructors_thunk : 1;         /* set if the compiler creates a thunk to invoke destructors from the runtime */
 #if OMP_41_ENABLED
     unsigned proxy       : 1;               /* task is a proxy task (it will be executed outside the context of the RTL) */
-    unsigned reserved    : 11;              /* reserved for compiler use */
+    unsigned priority_specified :1;         /* set if the compiler provides priority setting for the task */
+    unsigned reserved    : 10;              /* reserved for compiler use */
 #else
     unsigned reserved    : 12;              /* reserved for compiler use */
 #endif
index fcbaacb..2711c5d 100644 (file)
@@ -1089,6 +1089,22 @@ FTN_GET_CANCELLATION_STATUS(int cancel_kind) {
 
 #endif // OMP_40_ENABLED
 
+#if OMP_41_ENABLED
+/* returns the maximum allowed task priority */
+int FTN_STDCALL
+FTN_GET_MAX_TASK_PRIORITY( void )
+{
+#ifdef KMP_STUB
+    return 0;
+#else
+    if ( ! __kmp_init_serial ) {
+        __kmp_serial_initialize();
+    }
+    return __kmp_max_task_priority;
+#endif
+}
+#endif
+
 // GCC compatibility (versioned symbols)
 #ifdef KMP_USE_VERSION_SYMBOLS
 
index 4b41260..d915750 100644 (file)
     #define FTN_GET_CANCELLATION_STATUS          kmp_get_cancellation_status
 #endif
 
+#if OMP_41_ENABLED
+    #define FTN_GET_MAX_TASK_PRIORITY            omp_get_max_task_priority
+#endif
+
 #endif /* KMP_FTN_PLAIN */
 
 /* ------------------------------------------------------------------------ */
     #define FTN_GET_CANCELLATION_STATUS          kmp_get_cancellation_status_
 #endif
 
+#if OMP_41_ENABLED
+    #define FTN_GET_MAX_TASK_PRIORITY            omp_get_max_task_priority_
+#endif
+
 #endif /* KMP_FTN_APPEND */
 
 /* ------------------------------------------------------------------------ */
     #define FTN_GET_CANCELLATION_STATUS          KMP_GET_CANCELLATION_STATUS
 #endif
 
+#if OMP_41_ENABLED
+    #define FTN_GET_MAX_TASK_PRIORITY            OMP_GET_MAX_TASK_PRIORITY
+#endif
+
 #endif /* KMP_FTN_UPPER */
 
 /* ------------------------------------------------------------------------ */
     #define FTN_GET_CANCELLATION_STATUS          KMP_GET_CANCELLATION_STATUS_
 #endif
 
+#if OMP_41_ENABLED
+    #define FTN_GET_MAX_TASK_PRIORITY            OMP_GET_MAX_TASK_PRIORITY_
+#endif
+
 #endif /* KMP_FTN_UAPPEND */
 
 /* ------------------------------------------------------------------ */
index bdac75b..b905fc6 100644 (file)
@@ -259,6 +259,9 @@ int __kmp_place_core_offset = 0;
 int __kmp_place_num_threads_per_core = 0;
 
 kmp_tasking_mode_t __kmp_tasking_mode = tskm_task_teams;
+#if OMP_41_ENABLED
+kmp_int32 __kmp_max_task_priority = 0;
+#endif
 
 /* This check ensures that the compiler is passing the correct data type
  * for the flags formal parameter of the function kmpc_omp_task_alloc().
index 11e340c..ac53c47 100644 (file)
@@ -1163,7 +1163,7 @@ __kmp_stg_print_task_stealing( kmp_str_buf_t * buffer, char const * name, void *
 
 static void
 __kmp_stg_parse_max_active_levels( char const * name, char const * value, void * data ) {
-        __kmp_stg_parse_int( name, value, 0, KMP_MAX_ACTIVE_LEVELS_LIMIT, & __kmp_dflt_max_active_levels );
+    __kmp_stg_parse_int( name, value, 0, KMP_MAX_ACTIVE_LEVELS_LIMIT, & __kmp_dflt_max_active_levels );
 } // __kmp_stg_parse_max_active_levels
 
 static void
@@ -1171,6 +1171,21 @@ __kmp_stg_print_max_active_levels( kmp_str_buf_t * buffer, char const * name, vo
     __kmp_stg_print_int( buffer, name, __kmp_dflt_max_active_levels );
 } // __kmp_stg_print_max_active_levels
 
+#if OMP_41_ENABLED
+// -------------------------------------------------------------------------------------------------
+// OpenMP 4.5: OMP_MAX_TASK_PRIORITY
+// -------------------------------------------------------------------------------------------------
+static void
+__kmp_stg_parse_max_task_priority(char const *name, char const *value, void *data) {
+    __kmp_stg_parse_int(name, value, 0, KMP_MAX_TASK_PRIORITY_LIMIT, &__kmp_max_task_priority);
+} // __kmp_stg_parse_max_task_priority
+
+static void
+__kmp_stg_print_max_task_priority(kmp_str_buf_t *buffer, char const *name, void *data) {
+    __kmp_stg_print_int(buffer, name, __kmp_max_task_priority);
+} // __kmp_stg_print_max_task_priority
+#endif // OMP_41_ENABLED
+
 #if KMP_NESTED_HOT_TEAMS
 // -------------------------------------------------------------------------------------------------
 // KMP_HOT_TEAMS_MAX_LEVEL, KMP_HOT_TEAMS_MODE
@@ -4519,6 +4534,9 @@ static kmp_setting_t __kmp_stg_table[] = {
     { "KMP_TASKING",                       __kmp_stg_parse_tasking,            __kmp_stg_print_tasking,            NULL, 0, 0 },
     { "KMP_TASK_STEALING_CONSTRAINT",      __kmp_stg_parse_task_stealing,      __kmp_stg_print_task_stealing,      NULL, 0, 0 },
     { "OMP_MAX_ACTIVE_LEVELS",             __kmp_stg_parse_max_active_levels,  __kmp_stg_print_max_active_levels,  NULL, 0, 0 },
+#if OMP_41_ENABLED
+    { "OMP_MAX_TASK_PRIORITY",             __kmp_stg_parse_max_task_priority,  __kmp_stg_print_max_task_priority,  NULL, 0, 0 },
+#endif
     { "OMP_THREAD_LIMIT",                  __kmp_stg_parse_all_threads,        __kmp_stg_print_all_threads,        NULL, 0, 0 },
     { "OMP_WAIT_POLICY",                   __kmp_stg_parse_wait_policy,        __kmp_stg_print_wait_policy,        NULL, 0, 0 },
 #if KMP_NESTED_HOT_TEAMS
index 10933f3..3ed9a9d 100644 (file)
@@ -679,9 +679,9 @@ __kmp_task_finish( kmp_int32 gtid, kmp_task_t *task, kmp_taskdata_t *resumed_tas
        hence overlapping the destructor invokations with some other work in the
        released tasks.  The OpenMP spec is not specific on when the destructors are
        invoked, so we should be free to choose.
-     */
+    */
     if (taskdata->td_flags.destructors_thunk) {
-        kmp_routine_entry_t destr_thunk = task->destructors;
+        kmp_routine_entry_t destr_thunk = task->data1.destructors;
         KMP_ASSERT(destr_thunk);
         destr_thunk(gtid, task);
     }
index e6d4467..9e08584 100644 (file)
@@ -70,7 +70,10 @@ if config.operating_system == 'Darwin':
 
 # substitutions
 config.substitutions.append(("%libomp-compile-and-run", \
-    "%clang %cflags %s -o %t -lm && %t"))
+    "%libomp-compile && %libomp-run"))
+config.substitutions.append(("%libomp-compile", \
+    "%clang %cflags %s -o %t -lm"))
+config.substitutions.append(("%libomp-run", "%t"))
 config.substitutions.append(("%clang", config.test_compiler))
 config.substitutions.append(("%openmp_flag", config.test_openmp_flag))
 config.substitutions.append(("%cflags", config.test_cflags))