diff --git a/openmp/runtime/CMakeLists.txt b/openmp/runtime/CMakeLists.txt --- a/openmp/runtime/CMakeLists.txt +++ b/openmp/runtime/CMakeLists.txt @@ -66,7 +66,18 @@ endif () set(LIBOMP_ENABLE_ASSERTIONS ${LLVM_ENABLE_ASSERTIONS}) endif() -libomp_check_variable(LIBOMP_ARCH 32e x86_64 32 i386 arm ppc64 ppc64le aarch64 mic mips mips64 riscv64) + +# FUJITSU A64FX is a special processor because its cache line size is 256. +# We need to pass this information into kmp_config.h. +if(LIBOMP_ARCH STREQUAL "aarch64") + libomp_is_aarch64_a64fx(LIBOMP_DETECT_AARCH64_A64FX) + if (LIBOMP_DETECT_AARCH64_A64FX MATCHES "1") + set(LIBOMP_ARCH "aarch64_a64fx") + set(LIBOMP_ARCH_AARCH64_A64FX TRUE) + endif() +endif() + +libomp_check_variable(LIBOMP_ARCH 32e x86_64 32 i386 arm ppc64 ppc64le aarch64 aarch64_a64fx mic mips mips64 riscv64) set(LIBOMP_LIB_TYPE normal CACHE STRING "Performance,Profiling,Stubs library (normal/profile/stubs)") @@ -136,6 +147,7 @@ set(INTEL64 FALSE) set(ARM FALSE) set(AARCH64 FALSE) +set(AARCH64_A64FX FALSE) set(PPC64BE FALSE) set(PPC64LE FALSE) set(PPC64 FALSE) @@ -157,6 +169,8 @@ set(PPC64 TRUE) elseif("${LIBOMP_ARCH}" STREQUAL "aarch64") # AARCH64 architecture set(AARCH64 TRUE) +elseif("${LIBOMP_ARCH}" STREQUAL "aarch64_a64fx") # AARCH64_A64FX architecture + set(AARCH64_A64FX TRUE) elseif("${LIBOMP_ARCH}" STREQUAL "mic") # Intel(R) Many Integrated Core Architecture set(MIC TRUE) elseif("${LIBOMP_ARCH}" STREQUAL "mips") # MIPS architecture diff --git a/openmp/runtime/cmake/LibompGetArchitecture.cmake b/openmp/runtime/cmake/LibompGetArchitecture.cmake --- a/openmp/runtime/cmake/LibompGetArchitecture.cmake +++ b/openmp/runtime/cmake/LibompGetArchitecture.cmake @@ -69,3 +69,78 @@ # Remove ${detect_arch_src_txt} from cmake/ subdirectory file(REMOVE "${CMAKE_CURRENT_BINARY_DIR}/libomp_detect_arch.c") endfunction() + +function(libomp_is_aarch64_a64fx return_is_aarch64_a64fx) + set(detect_aarch64_a64fx_src_txt " + #include + + typedef struct aarch64_cpuid { + int implementer\; + int architecture\; + int variant\; + int partno\; + int revision\; + } aarch64_cpuid_t\; + + int main(int argc, char *argv[]) { + char buf[256]\; + int value\; + FILE *f\; + + aarch64_cpuid_t cpuid\; + + cpuid.implementer = -1\; + cpuid.architecture = -1\; + cpuid.variant = -1\; + cpuid.partno = -1\; + cpuid.revision = -1\; + + f = fopen(\"/proc/cpuinfo\", \"r\")\; + if (!f) { + printf(\"0\\n\")\; + return 0\; + } + + while (fgets(buf, sizeof(buf), f)) { + if (sscanf(buf, \"CPU implementer : 0x%x\", &value) == 1) { + cpuid.implementer = value\; + } else if (sscanf(buf, \"CPU architecture : %d\", &value) == 1) { + cpuid.architecture = value\; + } else if (sscanf(buf, \"CPU variant : 0x%x\", &value) == 1) { + cpuid.variant = value\; + } else if (sscanf(buf, \"CPU part : 0x%x\", &value) == 1) { + cpuid.partno = value\; + } else if (sscanf(buf, \"CPU revision : %d\", &value) == 1) { + cpuid.revision = value\; + } + + if ((cpuid.implementer != -1) && (cpuid.architecture != -1) && + (cpuid.variant != -1) && (cpuid.partno != -1) && + (cpuid.revision != -1)) { + break\; + } + } + + fclose(f)\; + + if (cpuid.implementer == 0x46 && cpuid.architecture == 8) { + printf(\"1\\n\")\; + } else { + printf(\"0\\n\")\; + } + + return 0\; + } + ") + + # Write out ${detect_a64fx_src_txt} to a file within the cmake/ subdirectory + file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/libomp_detect_aarch64_a64fx.c" ${detect_aarch64_a64fx_src_txt}) + + # Compile using the C Compiler. It will always error out with an #error directive, so store error output to ${is_aarch64_a64fx} + try_run(run_dummy compile_dummy "${CMAKE_CURRENT_BINARY_DIR}" "${CMAKE_CURRENT_BINARY_DIR}/libomp_detect_aarch64_a64fx.c" RUN_OUTPUT_VARIABLE is_aarch64_a64fx) + + set(${return_is_aarch64_a64fx} "${is_aarch64_a64fx}" PARENT_SCOPE) + + # Remove ${detect_aarch64_a64fx_src_txt} from cmake/ subdirectory + file(REMOVE "${CMAKE_CURRENT_BINARY_DIR}/libomp_detect_aarch64_a64fx.c") +endfunction(libomp_is_aarch64_a64fx) diff --git a/openmp/runtime/cmake/LibompUtils.cmake b/openmp/runtime/cmake/LibompUtils.cmake --- a/openmp/runtime/cmake/LibompUtils.cmake +++ b/openmp/runtime/cmake/LibompUtils.cmake @@ -101,6 +101,8 @@ set(${return_arch_string} "PPC64LE" PARENT_SCOPE) elseif(${AARCH64}) set(${return_arch_string} "AARCH64" PARENT_SCOPE) + elseif(${AARCH64_A64FX}) + set(${return_arch_string} "AARCH64_A64FX" PARENT_SCOPE) elseif(${MIPS}) set(${return_arch_string} "MIPS" PARENT_SCOPE) elseif(${MIPS64}) diff --git a/openmp/runtime/src/kmp_config.h.cmake b/openmp/runtime/src/kmp_config.h.cmake --- a/openmp/runtime/src/kmp_config.h.cmake +++ b/openmp/runtime/src/kmp_config.h.cmake @@ -82,10 +82,14 @@ #define KMP_HAVE_ATTRIBUTE_WAITPKG LIBOMP_HAVE_ATTRIBUTE_WAITPKG #cmakedefine01 LIBOMP_HAVE_ATTRIBUTE_RTM #define KMP_HAVE_ATTRIBUTE_RTM LIBOMP_HAVE_ATTRIBUTE_RTM +#cmakedefine01 LIBOMP_ARCH_AARCH64_A64FX +#define KMP_ARCH_AARCH64_A64FX LIBOMP_ARCH_AARCH64_A64FX // Configured cache line based on architecture #if KMP_ARCH_PPC64 # define CACHE_LINE 128 +#elif KMP_ARCH_AARCH64_A64FX +# define CACHE_LINE 256 #else # define CACHE_LINE 64 #endif