Skip to content

Commit ce91cf3

Browse files
committed
[OpenMP][RISCV] Add riscv32 support
CMake flags and some core changes are added to support riscv32 platform basically. Fix #99427
1 parent 2f925d7 commit ce91cf3

13 files changed

+80
-51
lines changed

openmp/README.rst

Lines changed: 2 additions & 2 deletions
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|aarch64_32|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|riscv32|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

@@ -198,7 +198,7 @@ Optional Features
198198
**LIBOMP_OMPT_SUPPORT** = ``ON|OFF``
199199
Include support for the OpenMP Tools Interface (OMPT).
200200
This option is supported and ``ON`` by default for x86, x86_64, AArch64,
201-
PPC64, RISCV64, LoongArch64, and s390x on Linux* and macOS*.
201+
PPC64, RISCV32, RISCV64, LoongArch64, and s390x on Linux* and macOS*.
202202
This option is ``OFF`` if this feature is not supported for the platform.
203203

204204
**LIBOMP_OMPT_OPTIONAL** = ``ON|OFF``

openmp/runtime/CMakeLists.txt

Lines changed: 7 additions & 2 deletions
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/aarch64_32/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/riscv32/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?")
@@ -63,6 +63,8 @@ else() # Part of LLVM build
6363
set(LIBOMP_ARCH aarch64)
6464
elseif(LIBOMP_NATIVE_ARCH MATCHES "arm")
6565
set(LIBOMP_ARCH arm)
66+
elseif(LIBOMP_NATIVE_ARCH MATCHES "riscv32")
67+
set(LIBOMP_ARCH riscv32)
6668
elseif(LIBOMP_NATIVE_ARCH MATCHES "riscv64")
6769
set(LIBOMP_ARCH riscv64)
6870
elseif(LIBOMP_NATIVE_ARCH MATCHES "loongarch64")
@@ -93,7 +95,7 @@ if(LIBOMP_ARCH STREQUAL "aarch64")
9395
endif()
9496
endif()
9597

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)
98+
libomp_check_variable(LIBOMP_ARCH 32e x86_64 32 i386 arm ppc ppc64 ppc64le aarch64 aarch64_32 aarch64_a64fx mic mips mips64 riscv32 riscv64 loongarch64 ve s390x wasm32)
9799

98100
set(LIBOMP_LIB_TYPE normal CACHE STRING
99101
"Performance,Profiling,Stubs library (normal/profile/stubs)")
@@ -180,6 +182,7 @@ set(PPC64 FALSE)
180182
set(MIC FALSE)
181183
set(MIPS64 FALSE)
182184
set(MIPS FALSE)
185+
set(RISCV32 FALSE)
183186
set(RISCV64 FALSE)
184187
set(LOONGARCH64 FALSE)
185188
set(VE FALSE)
@@ -212,6 +215,8 @@ elseif("${LIBOMP_ARCH}" STREQUAL "mips") # MIPS architecture
212215
set(MIPS TRUE)
213216
elseif("${LIBOMP_ARCH}" STREQUAL "mips64") # MIPS64 architecture
214217
set(MIPS64 TRUE)
218+
elseif("${LIBOMP_ARCH}" STREQUAL "riscv32") # RISCV32 architecture
219+
set(RISCV32 TRUE)
215220
elseif("${LIBOMP_ARCH}" STREQUAL "riscv64") # RISCV64 architecture
216221
set(RISCV64 TRUE)
217222
elseif("${LIBOMP_ARCH}" STREQUAL "loongarch64") # LoongArch64 architecture

openmp/runtime/README.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ Architectures Supported
5353
* IBM(R) Power architecture (big endian)
5454
* IBM(R) Power architecture (little endian)
5555
* MIPS and MIPS64 architecture
56-
* RISCV64 architecture
56+
* RISC-V 32 bits architecture
57+
* RISC-V 64 bits architecture
5758
* LoongArch64 architecture
5859

5960
Supported RTL Build Configurations

openmp/runtime/cmake/LibompGetArchitecture.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ function(libomp_get_architecture return_arch)
4949
#error ARCHITECTURE=mips64
5050
#elif defined(__mips__) && !defined(__mips64)
5151
#error ARCHITECTURE=mips
52+
#elif defined(__riscv) && __riscv_xlen == 32
53+
#error ARCHITECTURE=riscv32
5254
#elif defined(__riscv) && __riscv_xlen == 64
5355
#error ARCHITECTURE=riscv64
5456
#elif defined(__loongarch__) && __loongarch_grlen == 64

openmp/runtime/cmake/LibompMicroTests.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ else()
208208
elseif(${MIPS} OR ${MIPS64})
209209
libomp_append(libomp_expected_library_deps libc.so.6)
210210
libomp_append(libomp_expected_library_deps ld.so.1)
211-
elseif(${RISCV64})
211+
elseif(${RISCV32} OR ${RISCV64})
212212
libomp_append(libomp_expected_library_deps libc.so.6)
213213
libomp_append(libomp_expected_library_deps ld.so.1)
214214
elseif(${LOONGARCH64})

openmp/runtime/cmake/LibompUtils.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ function(libomp_get_legal_arch return_arch_string)
109109
set(${return_arch_string} "MIPS" PARENT_SCOPE)
110110
elseif(${MIPS64})
111111
set(${return_arch_string} "MIPS64" PARENT_SCOPE)
112+
elseif(${RISCV32})
113+
set(${return_arch_string} "RISCV32" PARENT_SCOPE)
112114
elseif(${RISCV64})
113115
set(${return_arch_string} "RISCV64" PARENT_SCOPE)
114116
elseif(${LOONGARCH64})

openmp/runtime/cmake/config-ix.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ else()
314314
(LIBOMP_ARCH STREQUAL aarch64_a64fx) OR
315315
(LIBOMP_ARCH STREQUAL ppc64le) OR
316316
(LIBOMP_ARCH STREQUAL ppc64) OR
317+
(LIBOMP_ARCH STREQUAL riscv32) OR
317318
(LIBOMP_ARCH STREQUAL riscv64) OR
318319
(LIBOMP_ARCH STREQUAL loongarch64) OR
319320
(LIBOMP_ARCH STREQUAL s390x))

openmp/runtime/src/kmp_affinity.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ class KMPHwlocAffinity : public KMPAffinity {
278278
#elif __NR_sched_getaffinity != 123
279279
#error Wrong code for getaffinity system call.
280280
#endif /* __NR_sched_getaffinity */
281-
#elif KMP_ARCH_RISCV64
281+
#elif KMP_ARCH_RISCV64 || KMP_ARCH_RISCV32
282282
#ifndef __NR_sched_setaffinity
283283
#define __NR_sched_setaffinity 122
284284
#elif __NR_sched_setaffinity != 122

openmp/runtime/src/kmp_os.h

Lines changed: 4 additions & 3 deletions
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 || KMP_ARCH_AARCH64_32
182+
KMP_ARCH_PPC || KMP_ARCH_AARCH64_32 || KMP_ARCH_RISCV32
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 || \
@@ -1050,8 +1050,9 @@ extern kmp_real64 __kmp_xchg_real64(volatile kmp_real64 *p, kmp_real64 v);
10501050
#endif /* KMP_OS_WINDOWS */
10511051

10521052
#if KMP_ARCH_PPC64 || KMP_ARCH_ARM || KMP_ARCH_AARCH64 || KMP_ARCH_MIPS || \
1053-
KMP_ARCH_MIPS64 || KMP_ARCH_RISCV64 || KMP_ARCH_LOONGARCH64 || \
1054-
KMP_ARCH_VE || KMP_ARCH_S390X || KMP_ARCH_PPC || KMP_ARCH_AARCH64_32
1053+
KMP_ARCH_MIPS64 || KMP_ARCH_RISCV32 || KMP_ARCH_RISCV64 || \
1054+
KMP_ARCH_LOONGARCH64 || KMP_ARCH_VE || KMP_ARCH_S390X || KMP_ARCH_PPC || \
1055+
KMP_ARCH_AARCH64_32
10551056
#if KMP_OS_WINDOWS
10561057
#undef KMP_MB
10571058
#define KMP_MB() std::atomic_thread_fence(std::memory_order_seq_cst)

openmp/runtime/src/kmp_platform.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@
118118
#define KMP_ARCH_PPC_XCOFF 0
119119
#define KMP_ARCH_MIPS 0
120120
#define KMP_ARCH_MIPS64 0
121+
#define KMP_ARCH_RISCV32 0
121122
#define KMP_ARCH_RISCV64 0
122123
#define KMP_ARCH_LOONGARCH64 0
123124
#define KMP_ARCH_VE 0
@@ -178,6 +179,9 @@
178179
#undef KMP_ARCH_MIPS
179180
#define KMP_ARCH_MIPS 1
180181
#endif
182+
#elif defined __riscv && __riscv_xlen == 32
183+
#undef KMP_ARCH_RISCV32
184+
#define KMP_ARCH_RISCV32 1
181185
#elif defined __riscv && __riscv_xlen == 64
182186
#undef KMP_ARCH_RISCV64
183187
#define KMP_ARCH_RISCV64 1
@@ -263,8 +267,8 @@
263267
// TODO: Fixme - This is clever, but really fugly
264268
#if (1 != KMP_ARCH_X86 + KMP_ARCH_X86_64 + KMP_ARCH_ARM + KMP_ARCH_PPC64 + \
265269
KMP_ARCH_AARCH64 + KMP_ARCH_MIPS + KMP_ARCH_MIPS64 + \
266-
KMP_ARCH_RISCV64 + KMP_ARCH_LOONGARCH64 + KMP_ARCH_VE + \
267-
KMP_ARCH_S390X + KMP_ARCH_WASM + KMP_ARCH_PPC + \
270+
KMP_ARCH_RISCV32 + KMP_ARCH_RISCV64 + KMP_ARCH_LOONGARCH64 + \
271+
KMP_ARCH_VE + KMP_ARCH_S390X + KMP_ARCH_WASM + KMP_ARCH_PPC + \
268272
KMP_ARCH_AARCH64_32)
269273
#error Unknown or unsupported architecture
270274
#endif

0 commit comments

Comments
 (0)