Skip to content

Commit 1234011

Browse files
committed
[OpenMP][libomp] Introduce oneAPI compiler support
Introduce KMP_COMPILER_ICX macro to represent compilation with oneAPI compiler. Fixup flag detection and compiler ID detection in CMake. Older CMake's detect IntelLLVM as Clang. Fix compiler warnings. Fixup many of the tests to have non-empty parallel regions as they are elided by oneAPI compiler.
1 parent aabf6e6 commit 1234011

35 files changed

+210
-135
lines changed

openmp/cmake/DetectTestCompiler/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ function(write_compiler_information lang)
1010
set(information "${information}\\;${CMAKE_${lang}_COMPILER_VERSION}")
1111
set(information "${information}\\;${${lang}_FLAGS}")
1212
set(information "${information}\\;${${lang}_HAS_TSAN_FLAG}")
13+
set(information "${information}\\;${${lang}_HAS_OMIT_FRAME_POINTER}")
1314
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/${lang}CompilerInformation.txt ${information})
1415
endfunction(write_compiler_information)
1516

@@ -40,6 +41,9 @@ if (CMAKE_C_COMPILER_ID STREQUAL "Clang")
4041
add_experimental_isel_flag(CXX)
4142
endif()
4243

44+
check_c_compiler_flag("-fno-omit-frame-pointer" C_HAS_OMIT_FRAME_POINTER)
45+
check_cxx_compiler_flag("-fno-omit-frame-pointer" CXX_HAS_OMIT_FRAME_POINTER)
46+
4347
SET(CMAKE_REQUIRED_FLAGS "-fsanitize=thread")
4448
check_c_compiler_flag("" C_HAS_TSAN_FLAG)
4549
check_cxx_compiler_flag("" CXX_HAS_TSAN_FLAG)

openmp/cmake/OpenMPTesting.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,14 @@ macro(extract_test_compiler_information lang file)
7676
list(GET information 2 version)
7777
list(GET information 3 openmp_flags)
7878
list(GET information 4 has_tsan_flags)
79+
list(GET information 5 has_omit_frame_pointer_flags)
7980

8081
set(OPENMP_TEST_${lang}_COMPILER_PATH ${path})
8182
set(OPENMP_TEST_${lang}_COMPILER_ID ${id})
8283
set(OPENMP_TEST_${lang}_COMPILER_VERSION ${version})
8384
set(OPENMP_TEST_${lang}_COMPILER_OPENMP_FLAGS ${openmp_flags})
8485
set(OPENMP_TEST_${lang}_COMPILER_HAS_TSAN_FLAGS ${has_tsan_flags})
86+
set(OPENMP_TEST_${lang}_COMPILER_HAS_OMIT_FRAME_POINTER_FLAGS ${has_omit_frame_pointer_flags})
8587
endmacro()
8688

8789
# Function to set variables with information about the test compiler.
@@ -98,6 +100,7 @@ function(set_test_compiler_information dir)
98100
set(OPENMP_TEST_COMPILER_VERSION "${OPENMP_TEST_C_COMPILER_VERSION}" PARENT_SCOPE)
99101
set(OPENMP_TEST_COMPILER_OPENMP_FLAGS "${OPENMP_TEST_C_COMPILER_OPENMP_FLAGS}" PARENT_SCOPE)
100102
set(OPENMP_TEST_COMPILER_HAS_TSAN_FLAGS "${OPENMP_TEST_C_COMPILER_HAS_TSAN_FLAGS}" PARENT_SCOPE)
103+
set(OPENMP_TEST_COMPILER_HAS_OMIT_FRAME_POINTER_FLAGS "${OPENMP_TEST_C_COMPILER_HAS_OMIT_FRAME_POINTER_FLAGS}" PARENT_SCOPE)
101104

102105
# Determine major version.
103106
string(REGEX MATCH "[0-9]+" major "${OPENMP_TEST_C_COMPILER_VERSION}")
@@ -149,6 +152,7 @@ else()
149152
endif()
150153
# TODO: Implement blockaddress in GlobalISel and remove this flag!
151154
set(OPENMP_TEST_COMPILER_OPENMP_FLAGS "-fopenmp ${OPENMP_TEST_COMPILER_THREAD_FLAGS} -fno-experimental-isel")
155+
set(OPENMP_TEST_COMPILER_HAS_OMIT_FRAME_POINTER_FLAGS 1)
152156
endif()
153157

154158
# Function to set compiler features for use in lit.

openmp/cmake/config-ix.cmake

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,20 @@
11
include(CheckCXXCompilerFlag)
2+
include(CheckCXXSourceCompiles)
3+
4+
# Check for oneAPI compiler (some older CMake versions detect as Clang)
5+
if (CMAKE_C_COMPILER_ID STREQUAL "Clang")
6+
check_cxx_source_compiles("#if (defined(__INTEL_CLANG_COMPILER) || defined(__INTEL_LLVM_COMPILER))
7+
int main() { return 0; }
8+
#else
9+
not oneAPI
10+
#endif" OPENMP_HAVE_ONEAPI_COMPILER)
11+
if (OPENMP_HAVE_ONEAPI_COMPILER)
12+
# According to CMake documentation, the compiler id should
13+
# be IntelLLVM when detected oneAPI
14+
set(CMAKE_C_COMPILER_ID "IntelLLVM")
15+
set(CMAKE_CXX_COMPILER_ID "IntelLLVM")
16+
endif()
17+
endif()
218

319
check_cxx_compiler_flag(-Wall OPENMP_HAVE_WALL_FLAG)
420
check_cxx_compiler_flag(-Werror OPENMP_HAVE_WERROR_FLAG)

openmp/runtime/cmake/LibompCheckLinkerFlag.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function(libomp_check_linker_flag flag boolean)
2525
add_library(foo SHARED src_to_link.c)")
2626
# Compiling as a part of runtimes introduces ARCH-unknown-linux-gnu as a part
2727
# of a working directory. So adding a guard for unknown.
28-
set(failed_regexes "[Ee]rror;[Uu]nknown[^-];[Ss]kipping;LINK : warning")
28+
set(failed_regexes "[Ee]rror;[Uu]nknown[^-];[Ss]kipping;LINK : warning;Unsupported command line")
2929
set(base_dir ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/link_flag_check_${boolean})
3030
file(MAKE_DIRECTORY ${base_dir})
3131
file(MAKE_DIRECTORY ${base_dir}/build)

openmp/runtime/cmake/config-ix.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ elseif(NOT APPLE)
139139
endif()
140140

141141
# Check Intel(R) C Compiler specific flags
142-
if(CMAKE_C_COMPILER_ID STREQUAL "Intel")
142+
if(CMAKE_C_COMPILER_ID STREQUAL "Intel" OR CMAKE_C_COMPILER_ID STREQUAL "IntelLLVM")
143143
check_cxx_compiler_flag(/Qlong_double LIBOMP_HAVE_LONG_DOUBLE_FLAG)
144144
check_cxx_compiler_flag(/Qdiag-disable:177 LIBOMP_HAVE_DIAG_DISABLE_177_FLAG)
145145
check_cxx_compiler_flag(/Qinline-min-size=1 LIBOMP_HAVE_INLINE_MIN_SIZE_FLAG)
@@ -247,7 +247,7 @@ libomp_check_version_symbols(LIBOMP_HAVE_VERSION_SYMBOLS)
247247
# Check if quad precision types are available
248248
if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
249249
set(LIBOMP_HAVE_QUAD_PRECISION TRUE)
250-
elseif(CMAKE_C_COMPILER_ID STREQUAL "Intel")
250+
elseif(CMAKE_C_COMPILER_ID STREQUAL "Intel" OR CMAKE_C_COMPILER_ID STREQUAL "IntelLLVM")
251251
if(LIBOMP_HAVE_EXTENDED_FLOAT_TYPES_FLAG)
252252
set(LIBOMP_HAVE_QUAD_PRECISION TRUE)
253253
else()

openmp/runtime/src/kmp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1124,7 +1124,7 @@ extern void __kmp_init_target_mem();
11241124
#if KMP_OS_UNIX && (KMP_ARCH_X86 || KMP_ARCH_X86_64)
11251125
// HW TSC is used to reduce overhead (clock tick instead of nanosecond).
11261126
extern kmp_uint64 __kmp_ticks_per_msec;
1127-
#if KMP_COMPILER_ICC
1127+
#if KMP_COMPILER_ICC || KMP_COMPILER_ICX
11281128
#define KMP_NOW() ((kmp_uint64)_rdtsc())
11291129
#else
11301130
#define KMP_NOW() __kmp_hardware_timestamp()

openmp/runtime/src/kmp_affinity.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1765,7 +1765,7 @@ static bool __kmp_affinity_create_hwloc_map(kmp_i18n_id_t *const msg_id) {
17651765

17661766
hw_thread_index = 0;
17671767
pu = NULL;
1768-
while (pu = hwloc_get_next_obj_by_type(tp, HWLOC_OBJ_PU, pu)) {
1768+
while ((pu = hwloc_get_next_obj_by_type(tp, HWLOC_OBJ_PU, pu))) {
17691769
int index = depth - 1;
17701770
bool included = KMP_CPU_ISSET(pu->os_index, __kmp_affin_fullMask);
17711771
kmp_hw_thread_t &hw_thread = __kmp_topology->at(hw_thread_index);

openmp/runtime/src/kmp_atomic.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2452,6 +2452,7 @@ ATOMIC_CMPXCHG_CPT(float8, mul_cpt, kmp_real64, 64, *,
24522452
RTYPE, LCK_ID, MASK, GOMP_FLAG) \
24532453
ATOMIC_BEGIN_CPT_MIX(TYPE_ID, OP_ID, TYPE, RTYPE_ID, RTYPE) \
24542454
TYPE new_value; \
2455+
(void)new_value; \
24552456
OP_GOMP_CRITICAL_CPT(TYPE, OP, GOMP_FLAG) \
24562457
OP_CMPXCHG_CPT(TYPE, BITS, OP) \
24572458
}
@@ -2461,6 +2462,7 @@ ATOMIC_CMPXCHG_CPT(float8, mul_cpt, kmp_real64, 64, *,
24612462
LCK_ID, GOMP_FLAG) \
24622463
ATOMIC_BEGIN_CPT_MIX(TYPE_ID, OP_ID, TYPE, RTYPE_ID, RTYPE) \
24632464
TYPE new_value; \
2465+
(void)new_value; \
24642466
OP_GOMP_CRITICAL_CPT(TYPE, OP, GOMP_FLAG) /* send assignment */ \
24652467
OP_UPDATE_CRITICAL_CPT(TYPE, OP, LCK_ID) /* send assignment */ \
24662468
}
@@ -3162,6 +3164,7 @@ ATOMIC_CRITICAL_CPT_REV(cmplx16, div_a16_cpt_rev, kmp_cmplx128_a16_t, /, 32c,
31623164
RTYPE, LCK_ID, MASK, GOMP_FLAG) \
31633165
ATOMIC_BEGIN_CPT_MIX(TYPE_ID, OP_ID, TYPE, RTYPE_ID, RTYPE) \
31643166
TYPE new_value; \
3167+
(void)new_value; \
31653168
OP_GOMP_CRITICAL_CPT_REV(TYPE, OP, GOMP_FLAG) \
31663169
OP_CMPXCHG_CPT_REV(TYPE, BITS, OP) \
31673170
}
@@ -3171,6 +3174,7 @@ ATOMIC_CRITICAL_CPT_REV(cmplx16, div_a16_cpt_rev, kmp_cmplx128_a16_t, /, 32c,
31713174
LCK_ID, GOMP_FLAG) \
31723175
ATOMIC_BEGIN_CPT_MIX(TYPE_ID, OP_ID, TYPE, RTYPE_ID, RTYPE) \
31733176
TYPE new_value; \
3177+
(void)new_value; \
31743178
OP_GOMP_CRITICAL_CPT_REV(TYPE, OP, GOMP_FLAG) /* send assignment */ \
31753179
OP_CRITICAL_CPT_REV(TYPE, OP, LCK_ID) /* send assignment */ \
31763180
}

openmp/runtime/src/kmp_atomic.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,9 @@ struct KMP_DO_ALIGN(4) kmp_cmplx128_a4_t {
251251

252252
kmp_cmplx128_a4_t() : q() {}
253253

254+
#if defined(__cplusplus) && (KMP_OS_WINDOWS)
255+
kmp_cmplx128_a4_t(const std::complex<_Quad> &c128) : q(c128) {}
256+
#endif
254257
kmp_cmplx128_a4_t(const kmp_cmplx128 &c128) : q(c128) {}
255258

256259
kmp_cmplx128_a4_t operator+(const kmp_cmplx128_a4_t &b) {
@@ -314,6 +317,9 @@ struct KMP_DO_ALIGN(16) kmp_cmplx128_a16_t {
314317

315318
kmp_cmplx128_a16_t() : q() {}
316319

320+
#if defined(__cplusplus) && (KMP_OS_WINDOWS)
321+
kmp_cmplx128_a16_t(const std::complex<_Quad> &c128) : q(c128) {}
322+
#endif
317323
kmp_cmplx128_a16_t(const kmp_cmplx128 &c128) : q(c128) {}
318324

319325
kmp_cmplx128_a16_t operator+(const kmp_cmplx128_a16_t &b) {

openmp/runtime/src/kmp_barrier.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2163,7 +2163,6 @@ void __kmp_join_barrier(int gtid) {
21632163

21642164
kmp_info_t *this_thr = __kmp_threads[gtid];
21652165
kmp_team_t *team;
2166-
kmp_uint nproc;
21672166
int tid;
21682167
#ifdef KMP_DEBUG
21692168
int team_id;
@@ -2176,12 +2175,14 @@ void __kmp_join_barrier(int gtid) {
21762175
itt_sync_obj = __kmp_itt_barrier_object(gtid, bs_forkjoin_barrier);
21772176
#endif
21782177
#endif /* USE_ITT_BUILD */
2178+
#if ((USE_ITT_BUILD && USE_ITT_NOTIFY) || defined KMP_DEBUG)
2179+
int nproc = this_thr->th.th_team_nproc;
2180+
#endif
21792181
KMP_MB();
21802182

21812183
// Get current info
21822184
team = this_thr->th.th_team;
2183-
nproc = this_thr->th.th_team_nproc;
2184-
KMP_DEBUG_ASSERT((int)nproc == team->t.t_nproc);
2185+
KMP_DEBUG_ASSERT(nproc == team->t.t_nproc);
21852186
tid = __kmp_tid_from_gtid(gtid);
21862187
#ifdef KMP_DEBUG
21872188
team_id = team->t.t_id;
@@ -2354,7 +2355,7 @@ void __kmp_join_barrier(int gtid) {
23542355
// Set arrive time to zero to be able to check it in
23552356
// __kmp_invoke_task(); the same is done inside the loop below
23562357
this_thr->th.th_bar_arrive_time = 0;
2357-
for (kmp_uint i = 1; i < nproc; ++i) {
2358+
for (int i = 1; i < nproc; ++i) {
23582359
delta += (cur_time - other_threads[i]->th.th_bar_arrive_time);
23592360
other_threads[i]->th.th_bar_arrive_time = 0;
23602361
}

0 commit comments

Comments
 (0)