Skip to content

Commit

Permalink
GCC: inline limit (AMReX-Codes#3841)
Browse files Browse the repository at this point in the history
By default, set GCC inline limit to a huge number (43210). GCC's default
value is version dependent. It appears to be smaller than 2000 in recent
versions. The motivation for setting this to a huge number is that GCC
especially the recent versions (e.g., 12) no longer inline big lambda
functions passed to ParallelFor, resulting in serious performance
issues.
  • Loading branch information
WeiqunZhang authored Apr 1, 2024
1 parent bb7d5cf commit 728eec4
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 3 deletions.
6 changes: 6 additions & 0 deletions Docs/sphinx_documentation/source/BuildingAMReX.rst
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,12 @@ The list of available options is reported in the :ref:`table <tab:cmakevar>` bel
| AMReX_FLATTEN_FOR | Enable flattening of ParallelFor and similar | NO | YES, NO |
| | functions for host code | | |
+------------------------------+-------------------------------------------------+-------------------------+-----------------------+
| AMReX_COMPILER_DEFAULT_INLINE| Use default inline behavior of compiler, | NO for GCC | YES, NO |
| | so far relevant for GCC Only | YES otherwise | |
+------------------------------+-------------------------------------------------+-------------------------+-----------------------+
| AMReX_INLINE_LIMIT | Inline limit. Relevant only when | 43210 | Non-negative number |
| | AMReX_COMPILER_DEFAULT_INLINE is NO. | | |
+------------------------------+-------------------------------------------------+-------------------------+-----------------------+
.. raw:: latex

\end{center}
Expand Down
8 changes: 8 additions & 0 deletions Src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ foreach(D IN LISTS AMReX_SPACEDIM)
$<BUILD_INTERFACE:Flags_FPE>
)
endif ()

if (NOT AMReX_COMPILER_DEFULT_INLINE)
target_link_libraries(amrex_${D}d
PUBLIC
$<BUILD_INTERFACE:Flags_INLINE>
)
endif ()

endforeach()

# General configuration
Expand Down
2 changes: 1 addition & 1 deletion Tools/CMake/AMReXClangTidy.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ macro(setup_clang_tidy)

# Need --extra-arg to suppress warnings like clang-diagnostic-unknown-warning-option
# when GCC is used.
set(AMReX_CLANG_TIDY_COMMAND "${AMReX_CLANG_TIDY_EXE};--extra-arg=-Wno-unknown-warning-option")
set(AMReX_CLANG_TIDY_COMMAND "${AMReX_CLANG_TIDY_EXE};--extra-arg=-Wno-unknown-warning-option;--extra-arg=-Wno-ignored-optimization-argument")
if (AMReX_CLANG_TIDY_CONFIG_FILE_NAME)
set(AMReX_CLANG_TIDY_COMMAND "${AMReX_CLANG_TIDY_COMMAND}"
"--config-file=${AMReX_CLANG_TIDY_CONFIG_FILE_NAME}")
Expand Down
2 changes: 2 additions & 0 deletions Tools/CMake/AMReXConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ set(AMReX_FPE_FOUND @AMReX_FPE@)
set(AMReX_PIC_FOUND @AMReX_PIC@)
set(AMReX_ASSERTIONS_FOUND @AMReX_ASSERTIONS@)
set(AMReX_FLATTEN_FOR_FOUND @AMReX_FLATTEN_FOR@)
set(AMReX_COMPILER_DEFAULT_INLINE_FOUND @AMReX_COMPILER_DEFAULT_INLINE@)
set(AMReX_INLINE_LIMIT_FOUND @AMReX_INLINE_LIMIT@)

# Profiling options
set(AMReX_BASEP_FOUND @AMReX_BASE_PROFILE@)
Expand Down
12 changes: 12 additions & 0 deletions Tools/CMake/AMReXFlagsTargets.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# Flags_CXX --> Optional flags for C++ code
# Flags_Fortran --> Optional flags for Fortran code
# Flags_FPE --> Floating-Point Exception flags for both C++ and Fortran
# Flags_INLINE --> Optional flags for inlining
#
# These INTERFACE targets can be added to the AMReX export set.
#
Expand Down Expand Up @@ -93,6 +94,17 @@ target_compile_options( Flags_CXX
$<${_cxx_intelllvm_rel}:>
)

add_library(Flags_INLINE INTERFACE)
add_library(AMReX::Flags_INLINE ALIAS Flags_INLINE)

if (NOT AMReX_COMPILER_DEFAULT_INLINE)
target_compile_options( Flags_INLINE
INTERFACE
$<${_cxx_gnu_rwdbg}:-finline-limit=${AMReX_INLINE_LIMIT}>
$<${_cxx_gnu_rel}:-finline-limit=${AMReX_INLINE_LIMIT}>
)
endif ()

#
# Fortran flags
#
Expand Down
14 changes: 14 additions & 0 deletions Tools/CMake/AMReXOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,20 @@ print_option( AMReX_IPO )
option(AMReX_FPE "Enable Floating Point Exceptions checks" OFF)
print_option( AMReX_FPE )

if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
option(AMReX_COMPILER_DEFAULT_INLINE "Use compiler default inline behavior" OFF)
set(AMReX_INLINE_LIMIT 43210 CACHE STRING "Inline limit")
if (NOT AMReX_COMPILER_DEFAULT_INLINE)
if (AMReX_INLINE_LIMIT LESS 0)
message(FATAL_ERROR "AMReX_INLINE_LIMIT, if set, must be non-negative")
endif()
message(STATUS " AMReX_INLINE_LIMIT = ${AMReX_INLINE_LIMIT}")
endif ()
else ()
set(AMReX_COMPILER_DEFAULT_INLINE ON)
endif ()


if ( "${CMAKE_BUILD_TYPE}" MATCHES "Debug" )
option( AMReX_ASSERTIONS "Enable assertions" ON)
else ()
Expand Down
2 changes: 1 addition & 1 deletion Tools/C_scripts/mmclt.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def mmclt(argv):
fout = open(args.output, "w")

fout.write("CLANG_TIDY ?= clang-tidy\n")
fout.write("override CLANG_TIDY_ARGS += --extra-arg=-Wno-unknown-warning-option --extra-arg-before=--driver-mode=g++\n")
fout.write("override CLANG_TIDY_ARGS += --extra-arg=-Wno-unknown-warning-option --extra-arg=-Wno-ignored-optimization-argument --extra-arg-before=--driver-mode=g++\n")
fout.write("\n")

fout.write(".SECONDEXPANSION:\n")
Expand Down
5 changes: 5 additions & 0 deletions Tools/GNUMake/comps/gnu.mak
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ gcc_major_ge_10 = $(shell expr $(gcc_major_version) \>= 10)
gcc_major_ge_11 = $(shell expr $(gcc_major_version) \>= 11)
gcc_major_ge_12 = $(shell expr $(gcc_major_version) \>= 12)

INLINE_LIMIT ?= 43210

ifneq ($(NO_CONFIG_CHECKING),TRUE)
ifneq ($(gcc_major_ge_8),1)
$(error GCC < 8 not supported)
Expand Down Expand Up @@ -96,6 +98,9 @@ else
CXXFLAGS += -g -O3
CFLAGS += -g -O3
endif
ifneq ($(USE_COMPILER_DEFAULT_INLINE),TRUE)
CXXFLAGS += -finline-limit=$(INLINE_LIMIT)
endif
endif

ifeq ($(WARN_ALL),TRUE)
Expand Down
2 changes: 1 addition & 1 deletion Tools/GNUMake/tools/Make.clang-tidy
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

CLANG_TIDY = clang-tidy
CLANG_TIDY_ARGS = --extra-arg=-Wno-unknown-warning-option --extra-arg-before=--driver-mode=g++
CLANG_TIDY_ARGS = --extra-arg=-Wno-unknown-warning-option --extra-arg=-Wno-ignored-optimization-argument --extra-arg-before=--driver-mode=g++
# space-separated list of paths to skip, matched against the absolute path of each source file
CLANG_TIDY_IGNORE_SOURCES ?=

Expand Down

0 comments on commit 728eec4

Please sign in to comment.