From 5e34877480dfcb8c3cd6f95ac0a46aca417b19bc Mon Sep 17 00:00:00 2001 From: "Peyton, Jonathan L" Date: Mon, 2 Nov 2020 12:28:13 -0600 Subject: [PATCH] [OpenMP] Add ident_t flags for compiler OpenMP version This patch adds the mask and ident_t function to get the openmp version. It also adds logic to force monotonic:dynamic behavior when OpenMP version less than 5.0. The OpenMP version is stored in the format: major*10+minor e.g., OpenMP 5.0 = 50 Differential Revision: https://reviews.llvm.org/D90632 --- openmp/runtime/src/kmp.h | 5 +++++ openmp/runtime/src/kmp_dispatch.cpp | 24 ++++++++++++++++-------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/openmp/runtime/src/kmp.h b/openmp/runtime/src/kmp.h index 594c5ad..ee0e2cc 100644 --- a/openmp/runtime/src/kmp.h +++ b/openmp/runtime/src/kmp.h @@ -218,6 +218,7 @@ enum { KMP_IDENT_ATOMIC_HINT_CONTENDED = 0x020000, KMP_IDENT_ATOMIC_HINT_NONSPECULATIVE = 0x040000, KMP_IDENT_ATOMIC_HINT_SPECULATIVE = 0x080000, + KMP_IDENT_OPENMP_SPEC_VERSION_MASK = 0xFF000000 }; /*! @@ -237,6 +238,10 @@ typedef struct ident { The string is composed of semi-colon separated fields which describe the source file, the function and a pair of line numbers that delimit the construct. */ + // Returns the OpenMP version in form major*10+minor (e.g., 50 for 5.0) + kmp_int32 get_openmp_version() { + return (((flags & KMP_IDENT_OPENMP_SPEC_VERSION_MASK) >> 24) & 0xFF); + } } ident_t; /*! @} diff --git a/openmp/runtime/src/kmp_dispatch.cpp b/openmp/runtime/src/kmp_dispatch.cpp index 610c9a0..ad71f996 100644 --- a/openmp/runtime/src/kmp_dispatch.cpp +++ b/openmp/runtime/src/kmp_dispatch.cpp @@ -69,16 +69,24 @@ void __kmp_dispatch_dxo_error(int *gtid_ref, int *cid_ref, ident_t *loc_ref) { } // Returns either SCHEDULE_MONOTONIC or SCHEDULE_NONMONOTONIC -static inline int __kmp_get_monotonicity(enum sched_type schedule, +static inline int __kmp_get_monotonicity(ident_t *loc, enum sched_type schedule, bool use_hier = false) { // Pick up the nonmonotonic/monotonic bits from the scheduling type - int monotonicity; - // default to monotonic - monotonicity = SCHEDULE_MONOTONIC; - if (SCHEDULE_HAS_NONMONOTONIC(schedule)) + // TODO: make nonmonotonic when static_steal is fixed + int monotonicity = SCHEDULE_MONOTONIC; + + // Let default be monotonic for executables + // compiled with OpenMP* 4.5 or less compilers + if (loc->get_openmp_version() < 50) + monotonicity = SCHEDULE_MONOTONIC; + + if (use_hier) + monotonicity = SCHEDULE_MONOTONIC; + else if (SCHEDULE_HAS_NONMONOTONIC(schedule)) monotonicity = SCHEDULE_NONMONOTONIC; else if (SCHEDULE_HAS_MONOTONIC(schedule)) monotonicity = SCHEDULE_MONOTONIC; + return monotonicity; } @@ -146,7 +154,7 @@ void __kmp_dispatch_init_algorithm(ident_t *loc, int gtid, #endif /* Pick up the nonmonotonic/monotonic bits from the scheduling type */ - monotonicity = __kmp_get_monotonicity(schedule, use_hier); + monotonicity = __kmp_get_monotonicity(loc, schedule, use_hier); schedule = SCHEDULE_WITHOUT_MODIFIERS(schedule); /* Pick up the nomerge/ordered bits from the scheduling type */ @@ -177,7 +185,7 @@ void __kmp_dispatch_init_algorithm(ident_t *loc, int gtid, // Use the scheduling specified by OMP_SCHEDULE (or __kmp_sch_default if // not specified) schedule = team->t.t_sched.r_sched_type; - monotonicity = __kmp_get_monotonicity(schedule, use_hier); + monotonicity = __kmp_get_monotonicity(loc, schedule, use_hier); schedule = SCHEDULE_WITHOUT_MODIFIERS(schedule); // Detail the schedule if needed (global controls are differentiated // appropriately) @@ -244,7 +252,7 @@ void __kmp_dispatch_init_algorithm(ident_t *loc, int gtid, if (schedule == kmp_sch_runtime_simd) { // compiler provides simd_width in the chunk parameter schedule = team->t.t_sched.r_sched_type; - monotonicity = __kmp_get_monotonicity(schedule, use_hier); + monotonicity = __kmp_get_monotonicity(loc, schedule, use_hier); schedule = SCHEDULE_WITHOUT_MODIFIERS(schedule); // Detail the schedule if needed (global controls are differentiated // appropriately) -- 2.7.4