Skip to content

Commit

Permalink
NVHPC: undo debug flag workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
awnawab committed Mar 15, 2024
1 parent bdb065a commit 9b0a36b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 25 deletions.
15 changes: 7 additions & 8 deletions cmake/ecwam_compile_flags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
# nor does it submit to any jurisdiction.

# Capture ecbuild defaults and/or flags set by a toolchain
set( ${PNAME}_Fortran_FLAGS ${ECBUILD_Fortran_FLAGS} )
set( ${PNAME}_Fortran_FLAGS_BIT ${ECBUILD_Fortran_FLAGS_BIT} )
set( ${PNAME}_Fortran_FLAGS_DEBUG ${ECBUILD_Fortran_FLAGS_DEBUG} )
set( ${PNAME}_Fortran_FLAGS "${${PNAME}_Fortran_FLAGS} ${ECBUILD_Fortran_FLAGS}" )
set( ${PNAME}_Fortran_FLAGS_BIT "${${PNAME}_Fortran_FLAGS_BIT} ${ECBUILD_Fortran_FLAGS_BIT}" )
set( ${PNAME}_Fortran_FLAGS_DEBUG "${${PNAME}_Fortran_FLAGS_DEBUG} ${ECBUILD_Fortran_FLAGS_DEBUG}" )

if(CMAKE_Fortran_COMPILER_ID MATCHES "Cray")
set(autopromote_flags "-sreal64")
Expand Down Expand Up @@ -37,7 +37,7 @@ elseif(CMAKE_Fortran_COMPILER_ID MATCHES "PGI|NVHPC")
set(fpe_flags "-Ktrap=fp")
set(vectorization_flags "-O3 -fast")
string(REPLACE "-O2" "" ${PNAME}_Fortran_FLAGS_BIT ${${PNAME}_Fortran_FLAGS_BIT})
# set(checkbounds_flags "-Mbounds") # Added by default by CMake in NVHPC debug builds
set(checkbounds_flags "-Mbounds")

elseif(CMAKE_Fortran_COMPILER_ID MATCHES "Flang")
set(autopromote_flags "-fdefault-real-8")
Expand All @@ -59,16 +59,15 @@ if( DEFINED transcendentals_flags )
ecbuild_add_fortran_flags( "${transcendentals_flags}" NAME transcendentals )
endif()

## Debug flags for NVHPC are applied selectively to sourcefiles in src/ecwam/CMakeLists.txt
if( CMAKE_BUILD_TYPE MATCHES "Debug" AND NOT CMAKE_Fortran_COMPILER_ID MATCHES PGI|NVHPC )
if( CMAKE_BUILD_TYPE MATCHES "Debug" )
foreach( debug_flag fpe initsnan checkbounds )
if( ${debug_flag}_flags )
ecbuild_add_fortran_flags( "${${debug_flag}_flags}" NAME ${debug_flag} )
set( ${PNAME}_Fortran_FLAGS_DEBUG "${${PNAME}_Fortran_FLAGS_DEBUG} ${${debug_flag}_flags}" )
endif()
endforeach()
if(CMAKE_Fortran_COMPILER_ID MATCHES "Intel")
# In case '-check all' has been added, we need to remove the '-check arg_temp_created' warnings
ecbuild_add_fortran_flags( "-check noarg_temp_created" NAME check_noarg_temp_created BUILD DEBUG ) # the BUILD DEBUG argument makes sure it is appended after '-check all'
set( ${PNAME}_Fortran_FLAGS_DEBUG "${${PNAME}_Fortran_FLAGS_DEBUG} -check noarg_temp_created" )
endif()
endif()

Expand Down
21 changes: 4 additions & 17 deletions src/ecwam/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,10 @@ elseif(CMAKE_Fortran_COMPILER_ID MATCHES "PGI|NVHPC" AND CMAKE_BUILD_TYPE MATCHE
set_source_files_properties(
sbottom.F90 PROPERTIES COMPILE_FLAGS " -g -O1 -Mflushz -Mno-signed-zeros "
)
elseif(CMAKE_Fortran_COMPILER_ID MATCHES "PGI|NVHPC" AND CMAKE_BUILD_TYPE MATCHES "Debug")
string(REPLACE "-Ktrap=fp" "" ${PNAME}_Fortran_FLAGS_DEBUG ${${PNAME}_Fortran_FLAGS_DEBUG})
set_source_files_properties( outbeta.F90 PROPERTIES COMPILE_OPTIONS "${${PNAME}_Fortran_FLAGS_DEBUG} -Ktrap=divz")
set_source_files_properties( secondhh.F90 PROPERTIES COMPILE_OPTIONS "${${PNAME}_Fortran_FLAGS_DEBUG} -Ktrap=inv,ovf")
endif()

### The file grib2wgrid.F90 is sensitive to optimizations in single precision builds.
Expand All @@ -464,20 +468,3 @@ endif()
if( CMAKE_Fortran_COMPILER_ID MATCHES Intel AND HAVE_SINGLE_PRECISION )
set_source_files_properties( grib2wgrid.F90 PROPERTIES COMPILE_OPTIONS "-fp-model;strict" )
endif()

### NVHPC debug flags applied selectively to sourcefiles to avoid single-precision overflow
if( CMAKE_Fortran_COMPILER_ID MATCHES PGI|NVHPC AND CMAKE_BUILD_TYPE MATCHES "Debug" )
foreach( debug_flag initsnan checkbounds )
if( ${debug_flag}_flags )
ecbuild_add_fortran_flags( "${${debug_flag}_flags}" NAME ${debug_flag} )
endif()
endforeach()

list(REMOVE_ITEM ecwam_srcs outbeta.F90 secondhh.F90)
if( fpe_flags )
set_source_files_properties( ${ecwam_srcs} PROPERTIES COMPILE_OPTIONS ${fpe_flags} )
set_source_files_properties( outbeta.F90 PROPERTIES COMPILE_OPTIONS "-Ktrap=divz" )
set_source_files_properties( secondhh.F90 PROPERTIES COMPILE_OPTIONS "-Ktrap=inv,ovf" )
endif()
list(APPEND ecwam_srcs outbeta.F90 secondhh.F90)
endif()

0 comments on commit 9b0a36b

Please sign in to comment.