From 8cfd6cffb079a32e2f180bf3f45405d050e50844 Mon Sep 17 00:00:00 2001 From: Camus Kevin Date: Fri, 1 Dec 2023 09:16:45 +0100 Subject: [PATCH] Add support for Flang compiler in CMakeLists and FindSIMD, this cover both Flang and aocc-flang (#282) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Kévin Camus --- CMakeLists.txt | 14 ++++++++++++++ CMakeModules/FindSIMD.cmake | 34 +++++++++++++++++++++------------- 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9a471e0c..c0b2dda3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -276,6 +276,20 @@ elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "IntelLLVM") set(CMAKE_Fortran_FORMAT_FIXED_FLAG "-free") # List of Fortran flags for Intel's LLVM based compiler ends here +#List of Fortran flags for LLVM "classic" Flang based compiler begins here + #This include flang and aocc-flang and shouldn't be confused with flang-new (LLVMFlang in cmake) +elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "Flang") + list(APPEND Fortran_FLAGS "-O2" "-cpp" "-mcmodel=large") + list(APPEND Fortran_FLAGS "-D_MPI_") + list(APPEND Fortran_FLAGS "-DCLUSTER") + if (TREXIO_FOUND) + list(APPEND Fortran_FLAGS "-ltrexio") + endif() + + set(CMAKE_Fortran_FORMAT_FIXED_FLAG "-ffixed-form -ffixed-line-length-132") + +#List of Fortran flags for LLVM Flang based compiler ends here + elseif(Fortran_COMPILER_ID MATCHES "PGI") list(APPEND CMAKE_Fortran_FLAGS "-Mfreeform -Mdclchk -Mstandard -Mallocatable=03") endif() diff --git a/CMakeModules/FindSIMD.cmake b/CMakeModules/FindSIMD.cmake index 30579f47..5afdf32d 100644 --- a/CMakeModules/FindSIMD.cmake +++ b/CMakeModules/FindSIMD.cmake @@ -16,6 +16,8 @@ if(VECTORIZED STREQUAL "yes") list(APPEND Fortran_FLAGS "-axCORE-AVX512") elseif(CMAKE_Fortran_COMPILER_ID MATCHES "GNU") list(APPEND Fortran_FLAGS "-march=native") + elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "Flang") + list(APPEND Fortran_FLAGS "-march=native") else() list(APPEND Fortran_FLAGS "-axCORE-AVX512") endif() @@ -26,7 +28,9 @@ if(VECTORIZED STREQUAL "yes") list(APPEND Fortran_FLAGS "-march=core-avx2") elseif(CMAKE_Fortran_COMPILER_ID MATCHES "GNU") list(APPEND Fortran_FLAGS "-march=native") - else() + elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "Flang") + list(APPEND Fortran_FLAGS "-march=native") + else() list(APPEND Fortran_FLAGS "-axCORE-AVX2") endif() set(TARGET_ARCHITECTURE "avx2") @@ -43,26 +47,30 @@ else() message(STATUS "Vectorization is default " ) if(_cpu_flags MATCHES "avx512") if(CMAKE_Fortran_COMPILER_ID MATCHES "Intel") - list(APPEND Fortran_FLAGS "-axCORE-AVX512") + list(APPEND Fortran_FLAGS "-axCORE-AVX512") elseif(CMAKE_Fortran_COMPILER_ID MATCHES "GNU") - list(APPEND Fortran_FLAGS "-march=native") - elseif(CMAKE_Fortran_COMPILER_ID MATCHES "NVHPC") - list(APPEND Fortran_FLAGS "-Mvect") + list(APPEND Fortran_FLAGS "-march=native") + elseif(CMAKE_Fortran_COMPILER_ID MATCHES "NVHPC") + list(APPEND Fortran_FLAGS "-Mvect") + elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "Flang") + list(APPEND Fortran_FLAGS "-march=native") else() - list(APPEND Fortran_FLAGS "-axCORE-AVX512") + list(APPEND Fortran_FLAGS "-axCORE-AVX512") endif() set(TARGET_ARCHITECTURE "avx512") add_definitions(-DVECTORIZATION="avx512") elseif(_cpu_flags MATCHES "avx2") if(CMAKE_Fortran_COMPILER_ID MATCHES "Intel") - list(APPEND Fortran_FLAGS "-march=core-avx2") + list(APPEND Fortran_FLAGS "-march=core-avx2") elseif(CMAKE_Fortran_COMPILER_ID MATCHES "GNU") - list(APPEND Fortran_FLAGS "-march=native") - elseif(CMAKE_Fortran_COMPILER_ID MATCHES "NVHPC") - list(APPEND Fortran_FLAGS "-Mvect") - else() - list(APPEND Fortran_FLAGS "-axCORE-AVX2") - endif() + list(APPEND Fortran_FLAGS "-march=native") + elseif(CMAKE_Fortran_COMPILER_ID MATCHES "NVHPC") + list(APPEND Fortran_FLAGS "-Mvect") + elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "Flang") + list(APPEND Fortran_FLAGS "-march=native") + else() + list(APPEND Fortran_FLAGS "-axCORE-AVX2") + endif() set(TARGET_ARCHITECTURE "avx2") add_definitions(-DVECTORIZATION="avx2") endif()