Skip to content

Commit

Permalink
Update config with nvhpc compile flags (HDFGroup#624)
Browse files Browse the repository at this point in the history
  • Loading branch information
byrnHDF authored Feb 26, 2024
1 parent 1a38d2f commit 90c8a38
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 81 deletions.
1 change: 0 additions & 1 deletion config/clang-flags
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ load_clang_arguments()
done)
IFS=' ' echo "$*"
}

# Get the compiler version in a way that works for clang
# unless a compiler version is already known
#
Expand Down
22 changes: 1 addition & 21 deletions config/cmake/HDF4UseFortran.cmake
Original file line number Diff line number Diff line change
@@ -1,27 +1,7 @@
#
# This file provides functions for Fortran support.
# This file provides functions for additional Fortran support.
#
#-------------------------------------------------------------------------------
enable_language (Fortran)

#-----------------------------------------------------------------------------
# Detect name mangling convention used between Fortran and C
#-----------------------------------------------------------------------------
include (FortranCInterface)
FortranCInterface_HEADER (
${CMAKE_BINARY_DIR}/F77Mangle.h
MACRO_NAMESPACE "H4_F77_"
SYMBOL_NAMESPACE "H4_F77_"
SYMBOLS mysub mymod:my_sub
)

file (STRINGS ${CMAKE_BINARY_DIR}/F77Mangle.h CONTENTS REGEX "H4_F77_GLOBAL\\(.*,.*\\) +(.*)")
string (REGEX MATCH "H4_F77_GLOBAL\\(.*,.*\\) +(.*)" RESULT ${CONTENTS})
set (H4_F77_FUNC "H4_F77_FUNC(name,NAME) ${CMAKE_MATCH_1}")

file (STRINGS ${CMAKE_BINARY_DIR}/F77Mangle.h CONTENTS REGEX "H4_F77_GLOBAL_\\(.*,.*\\) +(.*)")
string (REGEX MATCH "H4_F77_GLOBAL_\\(.*,.*\\) +(.*)" RESULT ${CONTENTS})
set (H4_F77_FUNC_ "H4_F77_FUNC_(name,NAME) ${CMAKE_MATCH_1}")

include (${HDF_RESOURCES_DIR}/HDFUseFortran.cmake)

Expand Down
49 changes: 49 additions & 0 deletions config/cmake/HDFCompilerFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,55 @@ if(_CLANG_MSVC_WINDOWS AND "x${CMAKE_C_COMPILER_FRONTEND_VARIANT}" STREQUAL "xGN
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Xlinker -stack:20000000")
endif()

if (CMAKE_C_COMPILER_ID STREQUAL "NVHPC" )
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Minform=warn")
if (NOT ${HDF_CFG_NAME} MATCHES "Debug")
if (NOT ${HDF_CFG_NAME} MATCHES "RelWithDebInfo")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -s")
endif ()
else ()
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Mbounds -g")
endif ()

# With at least NVHPC 23.5 - 23.9, compiling with -O2 or higher and -DNDEBUG
# appears to have issues that manifest in the tests as incorrect metadata
# checksums being read or memory being corrupted. Compiling without -DNDEBUG
# does not appear to have these issues, but is not ideal due to compiling in
# asserts and other library debug code. Compiling with -O1 also does not appear
# to have these issues, so set maximum optimization level to -O1 for now until
# it can be determined whether these issues are compiler-specific or issues
# in the library.
set (cmake_c_flags_minsizerel_edited "${CMAKE_C_FLAGS_MINSIZEREL}")
string (REPLACE "-O2" "" cmake_c_flags_minsizerel_edited "${cmake_c_flags_minsizerel_edited}")
string (REPLACE "-O3" "" cmake_c_flags_minsizerel_edited "${cmake_c_flags_minsizerel_edited}")
string (REPLACE "-O4" "" cmake_c_flags_minsizerel_edited "${cmake_c_flags_minsizerel_edited}")
string (REPLACE "-Ofast" "" cmake_c_flags_minsizerel_edited "${cmake_c_flags_minsizerel_edited}")
string (REPLACE "-fast" "" cmake_c_flags_minsizerel_edited "${cmake_c_flags_minsizerel_edited}")
string (STRIP "${cmake_c_flags_minsizerel_edited}" cmake_c_flags_minsizerel_edited)
string (PREPEND cmake_c_flags_minsizerel_edited "-O1 ")
set (CMAKE_C_FLAGS_MINSIZEREL "${cmake_c_flags_minsizerel_edited}")

set (cmake_c_flags_release_edited "${CMAKE_C_FLAGS_RELEASE}")
string (REPLACE "-O2" "" cmake_c_flags_release_edited "${cmake_c_flags_release_edited}")
string (REPLACE "-O3" "" cmake_c_flags_release_edited "${cmake_c_flags_release_edited}")
string (REPLACE "-O4" "" cmake_c_flags_release_edited "${cmake_c_flags_release_edited}")
string (REPLACE "-Ofast" "" cmake_c_flags_release_edited "${cmake_c_flags_release_edited}")
string (REPLACE "-fast" "" cmake_c_flags_release_edited "${cmake_c_flags_release_edited}")
string (STRIP "${cmake_c_flags_release_edited}" cmake_c_flags_release_edited)
string (PREPEND cmake_c_flags_release_edited "-O1 ")
set (CMAKE_C_FLAGS_RELEASE "${cmake_c_flags_release_edited}")

set (cmake_c_flags_relwithdebinfo_edited "${CMAKE_C_FLAGS_RELWITHDEBINFO}")
string (REPLACE "-O2" "" cmake_c_flags_relwithdebinfo_edited "${cmake_c_flags_relwithdebinfo_edited}")
string (REPLACE "-O3" "" cmake_c_flags_relwithdebinfo_edited "${cmake_c_flags_relwithdebinfo_edited}")
string (REPLACE "-O4" "" cmake_c_flags_relwithdebinfo_edited "${cmake_c_flags_relwithdebinfo_edited}")
string (REPLACE "-Ofast" "" cmake_c_flags_relwithdebinfo_edited "${cmake_c_flags_relwithdebinfo_edited}")
string (REPLACE "-fast" "" cmake_c_flags_relwithdebinfo_edited "${cmake_c_flags_relwithdebinfo_edited}")
string (STRIP "${cmake_c_flags_relwithdebinfo_edited}" cmake_c_flags_relwithdebinfo_edited)
string (PREPEND cmake_c_flags_relwithdebinfo_edited "-O1 ")
set (CMAKE_C_FLAGS_RELWITHDEBINFO "${cmake_c_flags_relwithdebinfo_edited}")
endif ()

if (CMAKE_COMPILER_IS_GNUCC)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
if (${HDF_CFG_NAME} MATCHES "Debug" OR ${HDF_CFG_NAME} MATCHES "Developer")
Expand Down
57 changes: 0 additions & 57 deletions config/gnu-flags
Original file line number Diff line number Diff line change
Expand Up @@ -53,63 +53,6 @@ if test "X-" = "X-$cc_flags_set"; then
test -n "$cc_vers_patch" || cc_vers_patch=0
fi

# C and Fortran Compiler and Preprocessor Flags
# ---------------------------------------------------
#
# - Flags that end with `_CFLAGS' are always passed to the C compiler.
# - Flags that end with `_FFLAGS' are always passed to the Fortran
# compiler.
# - Flags that end with `_CPPFLAGS' are passed to the C compiler
# when compiling but not when linking.
#
# DEBUG_CFLAGS
# DEBUG_FFLAGS
# DEBUG_CPPFLAGS - Flags to pass to the compiler to create a
# library suitable for use with debugging
# tools. Usually this list will exclude
# optimization switches (like `-O') and include
# switches that turn on symbolic debugging support
# (like `-g').
#
# PROD_CFLAGS
# PROD_FFLAGS
# PROD_CPPFLAGS - Flags to pass to the compiler to create a
# production version of the library. These
# usually exclude symbolic debugging switches (like
# `-g') and include optimization switches (like
# `-O').
#
# PROFILE_CFLAGS
# PROFILE_FFLAGS
# PROFILE_CPPFLAGS- Flags to pass to the compiler to create a
# library suitable for performance testing (like
# `-pg'). This may or may not include debugging or
# production flags.
#
# FFLAGS
# CFLAGS - Flags can be added to these variable which
# might already be partially initialized. These
# flags will always be passed to the compiler and
# should include switches to turn on full warnings.
#
# WARNING: flags do not have to be added to the CFLAGS
# or FFLAGS variable if the compiler is the GNU gcc
# and gfortran compiler.
#
# FFLAGS and CFLAGS should contain *something* or else
# configure will probably add `-g'. For most systems
# this isn't a problem but some systems will disable
# optimizations in favor of the `-g'. The configure
# script will remove the `-g' flag in production mode
# only.
#
# These flags should be set according to the compiler being used.
# There are two ways to check the compiler. You can try using `-v' or
# `--version' to see if the compiler will print a version string. You
# can use the value of $FOO_BASENAME which is the base name of the
# first word in $FOO, where FOO is either CC or F77 (note that the
# value of CC may have changed above).

if test "X-gcc" = "X-$cc_vendor"; then

CFLAGS="$CFLAGS -std=c99"
Expand Down
1 change: 0 additions & 1 deletion config/gnu-warnings/general
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
-Wundef
-Wwrite-strings
-pedantic

# NOTE: Due to the divergence in the C and C++, we're dropping support for
# compiling the C library with a C++ compiler and dropping the -Wc++-compat
# warning.
Expand Down
12 changes: 12 additions & 0 deletions config/linux-gnu
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ fi
# Figure out Clang C compiler flags
. $srcdir/config/clang-flags

# Figure out NVHPC C compiler flags
. $srcdir/config/nvidia-flags

# Use default Fortran compiler according to what C compiler is used.
if test "X-$F77" = "X-"; then
F77=gfortran
Expand Down Expand Up @@ -89,6 +92,15 @@ case $CC in
grep 'GCC' | sed 's/\(.*(GCC) [-a-z0-9\. ]*\).*/\1/'`
;;

*nvc*)
cc_version_info=`$CC $CFLAGS $H4_CFLAGS -V 2>&1 | grep 'nvc'`
;;

*icx*)
cc_version_info=`$CC $CCFLAGS $H4_CCFLAGS -V 2>&1 | grep 'Version' |\
sed 's/\(Intel.* Compiler\).*\( Version [a-z0-9\.]*\).*\( Build [0-9]*\)/\1\2\3/'`
;;

*icc*)
cc_version_info=`$CC $CCFLAGS $H4_CCFLAGS -V 2>&1 | grep 'Version' |\
sed 's/\(Intel.* Compiler\).*\( Version [a-z0-9\.]*\).*\( Build [0-9]*\)/\1\2\3/'`
Expand Down
57 changes: 57 additions & 0 deletions config/nvidia-flags
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# -*- shell-script -*-
#
# This file is part of the HDF4 build script. It is processed shortly
# after configure starts and defines, among other things, flags for
# the various compilation modes.

#

# Get the compiler version in a way that works for nvc
# unless a compiler version is already known
#
# cc_vendor: The compiler name: nvc
# cc_version: Version number: 5.0-2, 5.2-2
#
if test X = "X$cc_flags_set"; then
cc_version="`$CC $CFLAGS -V 2>&1 |grep '^nvc '`"
if test X != "X$cc_version"; then
cc_vendor=`echo $cc_version |sed 's/\([a-z]*\).*/\1/'`
cc_version=`echo $cc_version |sed 's/nvc \([-a-z0-9\.\-]*\).*/\1/'`
echo "compiler '$CC' is NVIDIA $cc_vendor-$cc_version"

# Some version numbers
# NVIDIA version numbers are of the form: "major.minor-patch"
cc_vers_major=`echo $cc_version | cut -f1 -d.`
cc_vers_minor=`echo $cc_version | cut -f2 -d. | cut -f1 -d-`
cc_vers_patch=`echo $cc_version | cut -f2 -d. | cut -f2 -d-`
test -n "$cc_vers_major" || cc_vers_major=0
test -n "$cc_vers_minor" || cc_vers_minor=0
test -n "$cc_vers_patch" || cc_vers_patch=0
cc_vers_all=`expr $cc_vers_major '*' 1000000 + $cc_vers_minor '*' 1000 + $cc_vers_patch`
fi
fi

# Common NVIDIA flags for various situations
if test "X-nvc" = "X-$cc_vendor" -o "X-nvcc" = "X-$cc_vendor"; then
# Default to C99 standard.
CFLAGS="$CFLAGS $arch -c99 -Minform=warn"

DEBUG_CFLAGS="-g -Mbounds"
DEBUG_CPPFLAGS=
#PROD_CFLAGS="-fast"
PROD_CFLAGS="" # -fast implies -O2 and -O2+ currently has test failures.
PROD_CPPFLAGS=
PROFILE_CFLAGS="-Mprof=func,line"
PROFILE_CPPFLAGS=

#################
# Flags are set #
#################
cc_flags_set=yes
fi

# Clear cc info if no flags set
if test "X-$cc_flags_set" = "X-"; then
cc_vendor=
cc_version=
fi
1 change: 0 additions & 1 deletion config/oneapi-flags
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ load_intel_arguments()

# Get the compiler version in a way that works for icx
# icx unless a compiler version is already known
#
# cc_vendor: The compiler name: icx
# cc_version: Version number: 2023.2.0
#
Expand Down

0 comments on commit 90c8a38

Please sign in to comment.