Skip to content

Commit

Permalink
Add support for Flang compiler in CMakeLists and FindSIMD, this cover…
Browse files Browse the repository at this point in the history
… both Flang and aocc-flang (#282)

Co-authored-by: Kévin Camus <[email protected]>
  • Loading branch information
krahmouasy and krahmouasy authored Dec 1, 2023
1 parent 8367cf3 commit 8cfd6cf
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 13 deletions.
14 changes: 14 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
34 changes: 21 additions & 13 deletions CMakeModules/FindSIMD.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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")
Expand All @@ -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()
Expand Down

0 comments on commit 8cfd6cf

Please sign in to comment.