Skip to content

Commit c5bbdb6

Browse files
authoredApr 2, 2024
[OpenMP] arm64_32 port for Apple WatchOS (#87246)
detect `aarch64_32` with compiler defined macro `__ARM64_ARCH_8_32__` reuse ARM `__kmp_unnamed_critical_addr` and add `KMP_PREFIX_UNDERSCORE` macro like AARCH64 reuse AARCH64 `__kmp_invoke_microtask` build log for watchos armv7k + arm64_32 and watchos simulator x86_64 + arm64 https://github.com/nihui/action-protobuf/actions/runs/8520684611/job/23337305030
1 parent 4c7de02 commit c5bbdb6

14 files changed

+47
-21
lines changed
 

‎openmp/README.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ Options for all Libraries
141141
Options for ``libomp``
142142
----------------------
143143

144-
**LIBOMP_ARCH** = ``aarch64|arm|i386|loongarch64|mic|mips|mips64|ppc64|ppc64le|x86_64|riscv64|s390x``
144+
**LIBOMP_ARCH** = ``aarch64|aarch64_32|arm|i386|loongarch64|mic|mips|mips64|ppc64|ppc64le|x86_64|riscv64|s390x``
145145
The default value for this option is chosen based on probing the compiler for
146146
architecture macros (e.g., is ``__x86_64__`` predefined by compiler?).
147147

‎openmp/runtime/CMakeLists.txt

+7-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ if(${OPENMP_STANDALONE_BUILD})
3030
# If adding a new architecture, take a look at cmake/LibompGetArchitecture.cmake
3131
libomp_get_architecture(LIBOMP_DETECTED_ARCH)
3232
set(LIBOMP_ARCH ${LIBOMP_DETECTED_ARCH} CACHE STRING
33-
"The architecture to build for (x86_64/i386/arm/ppc/ppc64/ppc64le/aarch64/mic/mips/mips64/riscv64/loongarch64/ve/s390x/wasm32).")
33+
"The architecture to build for (x86_64/i386/arm/ppc/ppc64/ppc64le/aarch64/aarch64_32/mic/mips/mips64/riscv64/loongarch64/ve/s390x/wasm32).")
3434
# Should assertions be enabled? They are on by default.
3535
set(LIBOMP_ENABLE_ASSERTIONS TRUE CACHE BOOL
3636
"enable assertions?")
@@ -55,6 +55,8 @@ else() # Part of LLVM build
5555
set(LIBOMP_ARCH ppc64)
5656
elseif(LIBOMP_NATIVE_ARCH MATCHES "powerpc")
5757
set(LIBOMP_ARCH ppc)
58+
elseif(LIBOMP_NATIVE_ARCH MATCHES "aarch64_32")
59+
set(LIBOMP_ARCH aarch64_32)
5860
elseif(LIBOMP_NATIVE_ARCH MATCHES "aarch64")
5961
set(LIBOMP_ARCH aarch64)
6062
elseif(LIBOMP_NATIVE_ARCH MATCHES "arm64")
@@ -91,7 +93,7 @@ if(LIBOMP_ARCH STREQUAL "aarch64")
9193
endif()
9294
endif()
9395

94-
libomp_check_variable(LIBOMP_ARCH 32e x86_64 32 i386 arm ppc ppc64 ppc64le aarch64 aarch64_a64fx mic mips mips64 riscv64 loongarch64 ve s390x wasm32)
96+
libomp_check_variable(LIBOMP_ARCH 32e x86_64 32 i386 arm ppc ppc64 ppc64le aarch64 aarch64_32 aarch64_a64fx mic mips mips64 riscv64 loongarch64 ve s390x wasm32)
9597

9698
set(LIBOMP_LIB_TYPE normal CACHE STRING
9799
"Performance,Profiling,Stubs library (normal/profile/stubs)")
@@ -167,6 +169,7 @@ set(IA32 FALSE)
167169
set(INTEL64 FALSE)
168170
set(ARM FALSE)
169171
set(AARCH64 FALSE)
172+
set(AARCH64_32 FALSE)
170173
set(AARCH64_A64FX FALSE)
171174
set(PPC64BE FALSE)
172175
set(PPC64LE FALSE)
@@ -196,6 +199,8 @@ elseif("${LIBOMP_ARCH}" STREQUAL "ppc64le") # PPC64LE architecture
196199
set(PPC64 TRUE)
197200
elseif("${LIBOMP_ARCH}" STREQUAL "aarch64") # AARCH64 architecture
198201
set(AARCH64 TRUE)
202+
elseif("${LIBOMP_ARCH}" STREQUAL "aarch64_32") # AARCH64_32 architecture
203+
set(AARCH64_32 TRUE)
199204
elseif("${LIBOMP_ARCH}" STREQUAL "aarch64_a64fx") # AARCH64_A64FX architecture
200205
set(AARCH64_A64FX TRUE)
201206
elseif("${LIBOMP_ARCH}" STREQUAL "mic") # Intel(R) Many Integrated Core Architecture

‎openmp/runtime/cmake/LibompGetArchitecture.cmake

+2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ function(libomp_get_architecture return_arch)
3535
#error ARCHITECTURE=arm
3636
#elif defined(__arm__) || defined(_M_ARM) || defined(_ARM)
3737
#error ARCHITECTURE=arm
38+
#elif defined(__ARM64_ARCH_8_32__)
39+
#error ARCHITECTURE=aarch64_32
3840
#elif defined(__aarch64__) || defined(_M_ARM64)
3941
#error ARCHITECTURE=aarch64
4042
#elif defined(__powerpc64__) && defined(__LITTLE_ENDIAN__)

‎openmp/runtime/cmake/LibompUtils.cmake

+2
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ function(libomp_get_legal_arch return_arch_string)
101101
set(${return_arch_string} "PPC64LE" PARENT_SCOPE)
102102
elseif(${AARCH64})
103103
set(${return_arch_string} "AARCH64" PARENT_SCOPE)
104+
elseif(${AARCH64_32})
105+
set(${return_arch_string} "AARCH64_32" PARENT_SCOPE)
104106
elseif(${AARCH64_A64FX})
105107
set(${return_arch_string} "AARCH64_A64FX" PARENT_SCOPE)
106108
elseif(${MIPS})

‎openmp/runtime/cmake/config-ix.cmake

+1
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ else()
326326
(LIBOMP_ARCH STREQUAL i386) OR
327327
# (LIBOMP_ARCH STREQUAL arm) OR
328328
(LIBOMP_ARCH STREQUAL aarch64) OR
329+
(LIBOMP_ARCH STREQUAL aarch64_32) OR
329330
(LIBOMP_ARCH STREQUAL aarch64_a64fx) OR
330331
(LIBOMP_ARCH STREQUAL ppc64le) OR
331332
(LIBOMP_ARCH STREQUAL ppc64) OR

‎openmp/runtime/src/kmp_gsupport.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ void KMP_EXPAND_NAME(KMP_API_NAME_GOMP_ORDERED_END)(void) {
358358
// (IA-32 architecture) or 64-bit signed (Intel(R) 64).
359359

360360
#if KMP_ARCH_X86 || KMP_ARCH_ARM || KMP_ARCH_MIPS || KMP_ARCH_WASM || \
361-
KMP_ARCH_PPC
361+
KMP_ARCH_PPC || KMP_ARCH_AARCH64_32
362362
#define KMP_DISPATCH_INIT __kmp_aux_dispatch_init_4
363363
#define KMP_DISPATCH_FINI_CHUNK __kmp_aux_dispatch_fini_chunk_4
364364
#define KMP_DISPATCH_NEXT __kmpc_dispatch_next_4

‎openmp/runtime/src/kmp_os.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ typedef unsigned long long kmp_uint64;
179179
#endif /* KMP_OS_UNIX */
180180

181181
#if KMP_ARCH_X86 || KMP_ARCH_ARM || KMP_ARCH_MIPS || KMP_ARCH_WASM || \
182-
KMP_ARCH_PPC
182+
KMP_ARCH_PPC || KMP_ARCH_AARCH64_32
183183
#define KMP_SIZE_T_SPEC KMP_UINT32_SPEC
184184
#elif KMP_ARCH_X86_64 || KMP_ARCH_PPC64 || KMP_ARCH_AARCH64 || \
185185
KMP_ARCH_MIPS64 || KMP_ARCH_RISCV64 || KMP_ARCH_LOONGARCH64 || \
@@ -1051,7 +1051,7 @@ extern kmp_real64 __kmp_xchg_real64(volatile kmp_real64 *p, kmp_real64 v);
10511051

10521052
#if KMP_ARCH_PPC64 || KMP_ARCH_ARM || KMP_ARCH_AARCH64 || KMP_ARCH_MIPS || \
10531053
KMP_ARCH_MIPS64 || KMP_ARCH_RISCV64 || KMP_ARCH_LOONGARCH64 || \
1054-
KMP_ARCH_VE || KMP_ARCH_S390X || KMP_ARCH_PPC
1054+
KMP_ARCH_VE || KMP_ARCH_S390X || KMP_ARCH_PPC || KMP_ARCH_AARCH64_32
10551055
#if KMP_OS_WINDOWS
10561056
#undef KMP_MB
10571057
#define KMP_MB() std::atomic_thread_fence(std::memory_order_seq_cst)

‎openmp/runtime/src/kmp_platform.h

+7-2
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@
105105
#define KMP_ARCH_X86 0
106106
#define KMP_ARCH_X86_64 0
107107
#define KMP_ARCH_AARCH64 0
108+
#define KMP_ARCH_AARCH64_32 0
108109
#define KMP_ARCH_PPC64_ELFv1 0
109110
#define KMP_ARCH_PPC64_ELFv2 0
110111
#define KMP_ARCH_PPC64_XCOFF 0
@@ -157,6 +158,9 @@
157158
#define KMP_ARCH_PPC_XCOFF 1
158159
#undef KMP_ARCH_PPC
159160
#define KMP_ARCH_PPC 1
161+
#elif defined __ARM64_ARCH_8_32__
162+
#undef KMP_ARCH_AARCH64_32
163+
#define KMP_ARCH_AARCH64_32 1
160164
#elif defined __aarch64__
161165
#undef KMP_ARCH_AARCH64
162166
#define KMP_ARCH_AARCH64 1
@@ -244,7 +248,7 @@
244248
/* Specify 32 bit architectures here */
245249
#define KMP_32_BIT_ARCH \
246250
(KMP_ARCH_X86 || KMP_ARCH_ARM || KMP_ARCH_MIPS || KMP_ARCH_WASM || \
247-
KMP_ARCH_PPC)
251+
KMP_ARCH_PPC || KMP_ARCH_AARCH64_32)
248252

249253
// Platforms which support Intel(R) Many Integrated Core Architecture
250254
#define KMP_MIC_SUPPORTED \
@@ -254,7 +258,8 @@
254258
#if (1 != KMP_ARCH_X86 + KMP_ARCH_X86_64 + KMP_ARCH_ARM + KMP_ARCH_PPC64 + \
255259
KMP_ARCH_AARCH64 + KMP_ARCH_MIPS + KMP_ARCH_MIPS64 + \
256260
KMP_ARCH_RISCV64 + KMP_ARCH_LOONGARCH64 + KMP_ARCH_VE + \
257-
KMP_ARCH_S390X + KMP_ARCH_WASM + KMP_ARCH_PPC)
261+
KMP_ARCH_S390X + KMP_ARCH_WASM + KMP_ARCH_PPC + \
262+
KMP_ARCH_AARCH64_32)
258263
#error Unknown or unsupported architecture
259264
#endif
260265

‎openmp/runtime/src/kmp_runtime.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -8926,7 +8926,7 @@ __kmp_determine_reduction_method(
89268926
// KMP_OS_SOLARIS || KMP_OS_WASI || KMP_OS_AIX
89278927

89288928
#elif KMP_ARCH_X86 || KMP_ARCH_ARM || KMP_ARCH_AARCH || KMP_ARCH_MIPS || \
8929-
KMP_ARCH_WASM || KMP_ARCH_PPC
8929+
KMP_ARCH_WASM || KMP_ARCH_PPC || KMP_ARCH_AARCH64_32
89308930

89318931
#if KMP_OS_LINUX || KMP_OS_DRAGONFLY || KMP_OS_FREEBSD || KMP_OS_NETBSD || \
89328932
KMP_OS_OPENBSD || KMP_OS_WINDOWS || KMP_OS_HURD || KMP_OS_SOLARIS || \

‎openmp/runtime/src/z_Linux_asm.S

+13-10
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ KMP_PREFIX_UNDERSCORE(\proc):
108108
# endif // KMP_OS_DARWIN
109109
#endif // KMP_ARCH_X86 || KMP_ARCH_x86_64
110110

111-
#if (KMP_OS_LINUX || KMP_OS_DARWIN || KMP_OS_WINDOWS) && (KMP_ARCH_AARCH64 || KMP_ARCH_ARM)
111+
#if (KMP_OS_LINUX || KMP_OS_DARWIN || KMP_OS_WINDOWS) && (KMP_ARCH_AARCH64 || KMP_ARCH_AARCH64_32 || KMP_ARCH_ARM)
112112

113113
# if KMP_OS_DARWIN
114114
# define KMP_PREFIX_UNDERSCORE(x) _##x // extra underscore for OS X* symbols
@@ -176,7 +176,7 @@ KMP_PREFIX_UNDERSCORE(\proc):
176176
.endm
177177
# endif // KMP_OS_DARWIN
178178

179-
#endif // (KMP_OS_LINUX || KMP_OS_DARWIN || KMP_OS_WINDOWS) && (KMP_ARCH_AARCH64 || KMP_ARCH_ARM)
179+
#endif // (KMP_OS_LINUX || KMP_OS_DARWIN || KMP_OS_WINDOWS) && (KMP_ARCH_AARCH64 || KMP_ARCH_AARCH64_32 || KMP_ARCH_ARM)
180180

181181
.macro COMMON name, size, align_power
182182
#if KMP_OS_DARWIN
@@ -1236,7 +1236,7 @@ KMP_LABEL(kmp_1_exit):
12361236
#endif /* KMP_ARCH_X86_64 */
12371237

12381238
// '
1239-
#if (KMP_OS_LINUX || KMP_OS_DARWIN || KMP_OS_WINDOWS) && KMP_ARCH_AARCH64
1239+
#if (KMP_OS_LINUX || KMP_OS_DARWIN || KMP_OS_WINDOWS) && (KMP_ARCH_AARCH64 || KMP_ARCH_AARCH64_32)
12401240

12411241
//------------------------------------------------------------------------
12421242
// int
@@ -1360,7 +1360,7 @@ KMP_LABEL(kmp_1):
13601360
DEBUG_INFO __kmp_invoke_microtask
13611361
// -- End __kmp_invoke_microtask
13621362

1363-
#endif /* (KMP_OS_LINUX || KMP_OS_DARWIN || KMP_OS_WINDOWS) && KMP_ARCH_AARCH64 */
1363+
#endif /* (KMP_OS_LINUX || KMP_OS_DARWIN || KMP_OS_WINDOWS) && (KMP_ARCH_AARCH64 || KMP_ARCH_AARCH64_32) */
13641364

13651365
#if (KMP_OS_LINUX || KMP_OS_DARWIN || KMP_OS_WINDOWS) && KMP_ARCH_ARM
13661366

@@ -1505,7 +1505,7 @@ KMP_LABEL(kmp_1):
15051505
DEBUG_INFO __kmp_invoke_microtask
15061506
// -- End __kmp_invoke_microtask
15071507

1508-
#endif /* (KMP_OS_LINUX || KMP_OS_DARWIN || KMP_OS_WINDOWS) && KMP_ARCH_AARCH64 */
1508+
#endif /* (KMP_OS_LINUX || KMP_OS_DARWIN || KMP_OS_WINDOWS) && KMP_ARCH_ARM */
15091509

15101510
#if KMP_ARCH_PPC64
15111511

@@ -2405,18 +2405,21 @@ __kmp_invoke_microtask:
24052405

24062406
#endif /* KMP_ARCH_S390X */
24072407

2408-
#if KMP_ARCH_ARM || KMP_ARCH_MIPS
2408+
#if KMP_ARCH_ARM || KMP_ARCH_MIPS || KMP_ARCH_AARCH64_32
2409+
#ifndef KMP_PREFIX_UNDERSCORE
2410+
# define KMP_PREFIX_UNDERSCORE(x) x
2411+
#endif
24092412
.data
24102413
COMMON .gomp_critical_user_, 32, 3
24112414
.data
24122415
.align 4
2413-
.global __kmp_unnamed_critical_addr
2414-
__kmp_unnamed_critical_addr:
2416+
.global KMP_PREFIX_UNDERSCORE(__kmp_unnamed_critical_addr)
2417+
KMP_PREFIX_UNDERSCORE(__kmp_unnamed_critical_addr):
24152418
.4byte .gomp_critical_user_
24162419
#ifdef __ELF__
2417-
.size __kmp_unnamed_critical_addr,4
2420+
.size KMP_PREFIX_UNDERSCORE(__kmp_unnamed_critical_addr),4
24182421
#endif
2419-
#endif /* KMP_ARCH_ARM */
2422+
#endif /* KMP_ARCH_ARM || KMP_ARCH_MIPS || KMP_ARCH_AARCH64_32 */
24202423

24212424
#if KMP_ARCH_PPC64 || KMP_ARCH_AARCH64 || KMP_ARCH_MIPS64 || \
24222425
KMP_ARCH_RISCV64 || KMP_ARCH_LOONGARCH64 || KMP_ARCH_VE || \

‎openmp/runtime/src/z_Linux_util.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -2635,7 +2635,8 @@ int __kmp_get_load_balance(int max) {
26352635
#if !(KMP_ARCH_X86 || KMP_ARCH_X86_64 || KMP_MIC || \
26362636
((KMP_OS_LINUX || KMP_OS_DARWIN) && KMP_ARCH_AARCH64) || \
26372637
KMP_ARCH_PPC64 || KMP_ARCH_RISCV64 || KMP_ARCH_LOONGARCH64 || \
2638-
KMP_ARCH_ARM || KMP_ARCH_VE || KMP_ARCH_S390X || KMP_ARCH_PPC_XCOFF)
2638+
KMP_ARCH_ARM || KMP_ARCH_VE || KMP_ARCH_S390X || KMP_ARCH_PPC_XCOFF || \
2639+
KMP_ARCH_AARCH64_32)
26392640

26402641
// Because WebAssembly will use `call_indirect` to invoke the microtask and
26412642
// WebAssembly indirect calls check that the called signature is a precise

‎openmp/runtime/test/ompt/callback.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ ompt_label_##id:
186186
#define print_possible_return_addresses(addr) \
187187
printf("%" PRIu64 ": current_address=%p or %p\n", ompt_get_thread_data()->value, \
188188
((char *)addr) - 8, ((char *)addr) - 12)
189-
#elif KMP_ARCH_AARCH64
189+
#elif KMP_ARCH_AARCH64 || KMP_ARCH_AARCH64_32
190190
// On AArch64 the NOP instruction is 4 bytes long, can be followed by inserted
191191
// store instruction (another 4 bytes long).
192192
// FIXME: PR #65696 addded a third possibility (12 byte offset) to make the

‎openmp/runtime/tools/lib/Platform.pm

+5
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ sub canon_arch($) {
5353
$arch = "ppc64le";
5454
} elsif ( $arch =~ m{\Appc64} ) {
5555
$arch = "ppc64";
56+
} elsif ( $arch =~ m{\Aaarch64_32} ) {
57+
$arch = "aarch64_32";
5658
} elsif ( $arch =~ m{\Aaarch64} ) {
5759
$arch = "aarch64";
5860
} elsif ( $arch =~ m{\Amic} ) {
@@ -97,6 +99,7 @@ sub canon_mic_arch($) {
9799
"32e" => "Intel(R) 64",
98100
"arm" => "ARM",
99101
"aarch64" => "AArch64",
102+
"aarch64_32" => "AArch64_32",
100103
"loongarch64" => "LoongArch64",
101104
"mic" => "Intel(R) Many Integrated Core Architecture",
102105
"mips" => "MIPS",
@@ -222,6 +225,8 @@ sub target_options() {
222225
$_host_arch = "ppc64le";
223226
} elsif ( $hardware_platform eq "ppc64" ) {
224227
$_host_arch = "ppc64";
228+
} elsif ( $hardware_platform eq "aarch64_32" ) {
229+
$_host_arch = "aarch64_32";
225230
} elsif ( $hardware_platform eq "aarch64" ) {
226231
$_host_arch = "aarch64";
227232
} elsif ( $hardware_platform eq "mips64" ) {

‎openmp/runtime/tools/lib/Uname.pm

+2
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ if ( 0 ) {
150150
$values{ hardware_platform } = "ppc64le";
151151
} elsif ( $values{ machine } =~ m{\Appc64\z} ) {
152152
$values{ hardware_platform } = "ppc64";
153+
} elsif ( $values{ machine } =~ m{\Aaarch64_32\z} ) {
154+
$values{ hardware_platform } = "aarch64_32";
153155
} elsif ( $values{ machine } =~ m{\Aaarch64\z} ) {
154156
$values{ hardware_platform } = "aarch64";
155157
} elsif ( $values{ machine } =~ m{\Amips64\z} ) {

0 commit comments

Comments
 (0)
Please sign in to comment.