Skip to content

Commit 728eec4

Browse files
authored
GCC: inline limit (#3841)
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.
1 parent bb7d5cf commit 728eec4

File tree

9 files changed

+50
-3
lines changed

9 files changed

+50
-3
lines changed

Docs/sphinx_documentation/source/BuildingAMReX.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,12 @@ The list of available options is reported in the :ref:`table <tab:cmakevar>` bel
535535
| AMReX_FLATTEN_FOR | Enable flattening of ParallelFor and similar | NO | YES, NO |
536536
| | functions for host code | | |
537537
+------------------------------+-------------------------------------------------+-------------------------+-----------------------+
538+
| AMReX_COMPILER_DEFAULT_INLINE| Use default inline behavior of compiler, | NO for GCC | YES, NO |
539+
| | so far relevant for GCC Only | YES otherwise | |
540+
+------------------------------+-------------------------------------------------+-------------------------+-----------------------+
541+
| AMReX_INLINE_LIMIT | Inline limit. Relevant only when | 43210 | Non-negative number |
542+
| | AMReX_COMPILER_DEFAULT_INLINE is NO. | | |
543+
+------------------------------+-------------------------------------------------+-------------------------+-----------------------+
538544
.. raw:: latex
539545

540546
\end{center}

Src/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,14 @@ foreach(D IN LISTS AMReX_SPACEDIM)
8686
$<BUILD_INTERFACE:Flags_FPE>
8787
)
8888
endif ()
89+
90+
if (NOT AMReX_COMPILER_DEFULT_INLINE)
91+
target_link_libraries(amrex_${D}d
92+
PUBLIC
93+
$<BUILD_INTERFACE:Flags_INLINE>
94+
)
95+
endif ()
96+
8997
endforeach()
9098

9199
# General configuration

Tools/CMake/AMReXClangTidy.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ macro(setup_clang_tidy)
1717

1818
# Need --extra-arg to suppress warnings like clang-diagnostic-unknown-warning-option
1919
# when GCC is used.
20-
set(AMReX_CLANG_TIDY_COMMAND "${AMReX_CLANG_TIDY_EXE};--extra-arg=-Wno-unknown-warning-option")
20+
set(AMReX_CLANG_TIDY_COMMAND "${AMReX_CLANG_TIDY_EXE};--extra-arg=-Wno-unknown-warning-option;--extra-arg=-Wno-ignored-optimization-argument")
2121
if (AMReX_CLANG_TIDY_CONFIG_FILE_NAME)
2222
set(AMReX_CLANG_TIDY_COMMAND "${AMReX_CLANG_TIDY_COMMAND}"
2323
"--config-file=${AMReX_CLANG_TIDY_CONFIG_FILE_NAME}")

Tools/CMake/AMReXConfig.cmake.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ set(AMReX_FPE_FOUND @AMReX_FPE@)
9191
set(AMReX_PIC_FOUND @AMReX_PIC@)
9292
set(AMReX_ASSERTIONS_FOUND @AMReX_ASSERTIONS@)
9393
set(AMReX_FLATTEN_FOR_FOUND @AMReX_FLATTEN_FOR@)
94+
set(AMReX_COMPILER_DEFAULT_INLINE_FOUND @AMReX_COMPILER_DEFAULT_INLINE@)
95+
set(AMReX_INLINE_LIMIT_FOUND @AMReX_INLINE_LIMIT@)
9496

9597
# Profiling options
9698
set(AMReX_BASEP_FOUND @AMReX_BASE_PROFILE@)

Tools/CMake/AMReXFlagsTargets.cmake

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# Flags_CXX --> Optional flags for C++ code
66
# Flags_Fortran --> Optional flags for Fortran code
77
# Flags_FPE --> Floating-Point Exception flags for both C++ and Fortran
8+
# Flags_INLINE --> Optional flags for inlining
89
#
910
# These INTERFACE targets can be added to the AMReX export set.
1011
#
@@ -93,6 +94,17 @@ target_compile_options( Flags_CXX
9394
$<${_cxx_intelllvm_rel}:>
9495
)
9596

97+
add_library(Flags_INLINE INTERFACE)
98+
add_library(AMReX::Flags_INLINE ALIAS Flags_INLINE)
99+
100+
if (NOT AMReX_COMPILER_DEFAULT_INLINE)
101+
target_compile_options( Flags_INLINE
102+
INTERFACE
103+
$<${_cxx_gnu_rwdbg}:-finline-limit=${AMReX_INLINE_LIMIT}>
104+
$<${_cxx_gnu_rel}:-finline-limit=${AMReX_INLINE_LIMIT}>
105+
)
106+
endif ()
107+
96108
#
97109
# Fortran flags
98110
#

Tools/CMake/AMReXOptions.cmake

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,20 @@ print_option( AMReX_IPO )
369369
option(AMReX_FPE "Enable Floating Point Exceptions checks" OFF)
370370
print_option( AMReX_FPE )
371371

372+
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
373+
option(AMReX_COMPILER_DEFAULT_INLINE "Use compiler default inline behavior" OFF)
374+
set(AMReX_INLINE_LIMIT 43210 CACHE STRING "Inline limit")
375+
if (NOT AMReX_COMPILER_DEFAULT_INLINE)
376+
if (AMReX_INLINE_LIMIT LESS 0)
377+
message(FATAL_ERROR "AMReX_INLINE_LIMIT, if set, must be non-negative")
378+
endif()
379+
message(STATUS " AMReX_INLINE_LIMIT = ${AMReX_INLINE_LIMIT}")
380+
endif ()
381+
else ()
382+
set(AMReX_COMPILER_DEFAULT_INLINE ON)
383+
endif ()
384+
385+
372386
if ( "${CMAKE_BUILD_TYPE}" MATCHES "Debug" )
373387
option( AMReX_ASSERTIONS "Enable assertions" ON)
374388
else ()

Tools/C_scripts/mmclt.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def mmclt(argv):
2828
fout = open(args.output, "w")
2929

3030
fout.write("CLANG_TIDY ?= clang-tidy\n")
31-
fout.write("override CLANG_TIDY_ARGS += --extra-arg=-Wno-unknown-warning-option --extra-arg-before=--driver-mode=g++\n")
31+
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")
3232
fout.write("\n")
3333

3434
fout.write(".SECONDEXPANSION:\n")

Tools/GNUMake/comps/gnu.mak

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ gcc_major_ge_10 = $(shell expr $(gcc_major_version) \>= 10)
4444
gcc_major_ge_11 = $(shell expr $(gcc_major_version) \>= 11)
4545
gcc_major_ge_12 = $(shell expr $(gcc_major_version) \>= 12)
4646

47+
INLINE_LIMIT ?= 43210
48+
4749
ifneq ($(NO_CONFIG_CHECKING),TRUE)
4850
ifneq ($(gcc_major_ge_8),1)
4951
$(error GCC < 8 not supported)
@@ -96,6 +98,9 @@ else
9698
CXXFLAGS += -g -O3
9799
CFLAGS += -g -O3
98100
endif
101+
ifneq ($(USE_COMPILER_DEFAULT_INLINE),TRUE)
102+
CXXFLAGS += -finline-limit=$(INLINE_LIMIT)
103+
endif
99104
endif
100105

101106
ifeq ($(WARN_ALL),TRUE)

Tools/GNUMake/tools/Make.clang-tidy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

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

0 commit comments

Comments
 (0)