Skip to content

Commit 384ca23

Browse files
authored
CMake: IPO/LTO (#1890)
Add optional interprocedural optimization (IPO) aka link-time optimization (LTO) to AMReX. In my WarpX tests recently on x86_64 and ppc64le, using those options incurred a 2% performance hit (although one would expect a slight increase). Thus, they are not enabled by default. Also, enabling them with some toolchains needs users to set the linker properly. Nontheless, enabling IPO shrinks the binary size a lot. This is very valuable and worth the runtime penalty for our binary deployments, e.g. when shipping generic x86_64, aarch64 and ppc64le binaries on conda-forge to users. WarpX binary size (default build): * no IPO: 217MiB * WarpX IPO, AMReX no IPO: 155MiB * both WarpX and AMReX with IPO: 127M
1 parent ef0eb9f commit 384ca23

File tree

5 files changed

+40
-0
lines changed

5 files changed

+40
-0
lines changed

Docs/sphinx_documentation/source/BuildingAMReX.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,8 @@ The list of available options is reported in the :ref:`table <tab:cmakevar>` bel
433433
+------------------------------+-------------------------------------------------+-------------------------+-----------------------+
434434
| AMReX_PIC | Build Position Independent Code | NO | YES, NO |
435435
+------------------------------+-------------------------------------------------+-------------------------+-----------------------+
436+
| AMReX_IPO | Interprocedural optimization (IPO/LTO) | NO | YES, NO |
437+
+------------------------------+-------------------------------------------------+-------------------------+-----------------------+
436438
| AMReX_MPI | Build with MPI support | YES | YES, NO |
437439
+------------------------------+-------------------------------------------------+-------------------------+-----------------------+
438440
| AMReX_OMP | Build with OpenMP support | NO | YES, NO |

Tools/CMake/AMReXBuildInfo.cmake

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,4 +226,16 @@ function (generate_buildinfo _target _git_dir)
226226
POSITION_INDEPENDENT_CODE ${_pic}
227227
WINDOWS_EXPORT_ALL_SYMBOLS ${_sym} )
228228

229+
# IPO/LTO
230+
if (AMReX_IPO)
231+
include(CheckIPOSupported)
232+
check_ipo_supported(RESULT is_IPO_available)
233+
if(is_IPO_available)
234+
set_target_properties(buildInfo${_target} PROPERTIES
235+
INTERPROCEDURAL_OPTIMIZATION TRUE)
236+
else()
237+
message(FATAL_ERROR "Interprocedural optimization is not available, set AMReX_IPO=OFF")
238+
endif()
239+
endif()
240+
229241
endfunction ()

Tools/CMake/AMReXOptions.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,9 @@ endif ()
269269
option( AMReX_PIC "Build position-independent code" OFF)
270270
print_option( AMReX_PIC )
271271

272+
option( AMReX_IPO "Enable interprocedural optimization (IPO/LTO)" OFF)
273+
print_option( AMReX_IPO )
274+
272275
option(AMReX_FPE "Enable Floating Point Exceptions checks" OFF)
273276
print_option( AMReX_FPE )
274277

Tools/CMake/AMReXTypecheck.cmake

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,18 @@ function( add_typecheck_target _target)
182182
WINDOWS_EXPORT_ALL_SYMBOLS ON
183183
)
184184

185+
# IPO/LTO
186+
if (AMReX_IPO)
187+
include(CheckIPOSupported)
188+
check_ipo_supported(RESULT is_IPO_available)
189+
if(is_IPO_available)
190+
set_target_properties(${_typecheckobjs} PROPERTIES
191+
INTERPROCEDURAL_OPTIMIZATION TRUE)
192+
else()
193+
message(FATAL_ERROR "Interprocedural optimization is not available, set AMReX_IPO=OFF")
194+
endif()
195+
endif()
196+
185197
# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
186198
# STEP 2: create CPPD files from C++ headers
187199
# <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

Tools/CMake/AMReX_Config.cmake

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,17 @@ function (configure_amrex)
148148
WINDOWS_EXPORT_ALL_SYMBOLS ON )
149149
endif ()
150150

151+
# IPO/LTO
152+
if (AMReX_IPO)
153+
include(CheckIPOSupported)
154+
check_ipo_supported(RESULT is_IPO_available)
155+
if(is_IPO_available)
156+
set_target_properties(amrex PROPERTIES INTERPROCEDURAL_OPTIMIZATION TRUE)
157+
else()
158+
message(FATAL_ERROR "Interprocedural optimization is not available, set AMReX_IPO=OFF")
159+
endif()
160+
endif()
161+
151162
#
152163
# Setup third-party profilers
153164
#

0 commit comments

Comments
 (0)