-
Notifications
You must be signed in to change notification settings - Fork 9
LTO support #595
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
LTO support #595
Changes from all commits
99e75f8
6ecb2c8
30ad401
620b3fb
34f95f9
231ede5
687609a
e2d9e0c
2d3cafd
ea7b3bc
b2ddf35
02b08f9
52c34cb
20ad7f1
ab7b2aa
cec4f13
5a6165b
a1f1340
6886e8d
7460c7e
803ac19
73ca17f
e976a19
192a150
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -60,3 +60,66 @@ function(target_set_warning_flags TARGET) | |
| target_compile_options("${TARGET}" PRIVATE "-Wno-unused-lambda-capture") | ||
| endif() | ||
| endfunction() | ||
|
|
||
|
|
||
|
|
||
| function(target_set_optimization_flags TARGET) | ||
| if (CMAKE_BUILD_TYPE STREQUAL "Debug") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [3 — medium] The With Ninja Multi-Config, Xcode, or Visual Studio, The identical guard at Fix: use a
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct though I don't think the added complexity is really worth the hassle. This can be dealt with once someone actually uses Windows to do SeQuant developing. |
||
| return() | ||
| endif() | ||
|
|
||
| get_target_property(TARGET_TYPE "${TARGET}" TYPE) | ||
|
|
||
| if (TARGET_TYPE STREQUAL "INTERFACE_LIBRARY") | ||
| message(WARNING "target_set_optimization_flags is not intended to be used on interface targets") | ||
| return() | ||
| endif() | ||
|
|
||
| include(CheckCXXCompilerFlag) | ||
| include(CheckIPOSupported) | ||
|
|
||
| check_ipo_supported(RESULT CMAKE_SUPPORTS_COMPILER_LTO LANGUAGES CXX) | ||
|
Krzmbrzl marked this conversation as resolved.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [B — low]
Measured on an M-series mac with this branch's That is roughly 13-18 s added to every Fix: wrap all four checks in a one-shot guard, e.g. |
||
|
|
||
| set(CMAKE_TRY_COMPILE_TARGET_TYPE "STATIC_LIBRARY") | ||
| check_cxx_compiler_flag("-flto" SEQUANT_LTO_FLAG_SUPPORTED) | ||
| check_cxx_compiler_flag("-flto=auto" SEQUANT_LTO_AUTO_SUPPORTED) | ||
| check_cxx_compiler_flag("-flto;-ffat-lto-objects" SEQUANT_FAT_LTO_FLAG_SUPPORTED) | ||
|
|
||
| if (DEFINED SEQUANT_LTO) | ||
| # Always honor explicit user choice | ||
| set(ENABLE_LTO ${SEQUANT_LTO}) | ||
| elseif(TARGET_TYPE STREQUAL "STATIC_LIBRARY" OR TARGET_TYPE STREQUAL "OBJECT_LIBRARY") | ||
| # For static/object libraries we only want to enable LTO by default, if we can create | ||
| # "fat" object files. Those can still be linked without LTO and hence shouldn't | ||
| # break any downstream use. | ||
| set(ENABLE_LTO ${SEQUANT_FAT_LTO_FLAG_SUPPORTED}) | ||
| elseif(SEQUANT_LTO_FLAG_SUPPORTED OR CMAKE_SUPPORTS_COMPILER_LTO) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [A — medium-low] LTO link options are enabled by a probe that never links.
This line then enables LTO on Scenario: GCC or Clang paired with a GNU Fix: |
||
| # Anything but static/object libraries is also linked by us and | ||
| # hence enabling LTO doesn't affect downstream compatibility | ||
| set(ENABLE_LTO ON) | ||
| endif() | ||
|
|
||
| if (ENABLE_LTO) | ||
| if (SEQUANT_LTO_FLAG_SUPPORTED) | ||
| # We prefer to manually set the LTO flag(s) rather than CMake doing it for us | ||
| # due to https://gitlab.kitware.com/cmake/cmake/-/work_items/23136 | ||
| # On some compilers, the thin LTO type requested by CMake is incompatible | ||
| # with explicitly asking for fat LTO object files. | ||
| # Besides, it seems like full LTO achieves quite a bit better optimizations | ||
| # with Clang. | ||
| if (SEQUANT_LTO_AUTO_SUPPORTED) | ||
| target_compile_options("${TARGET}" PRIVATE -flto=auto) | ||
| target_link_options("${TARGET}" PRIVATE -flto=auto) | ||
| else() | ||
| target_compile_options("${TARGET}" PRIVATE -flto) | ||
| target_link_options("${TARGET}" PRIVATE -flto) | ||
| endif() | ||
|
|
||
| if (SEQUANT_FAT_LTO_FLAG_SUPPORTED) | ||
| target_compile_options("${TARGET}" PRIVATE -ffat-lto-objects) | ||
| endif() | ||
| else() | ||
| set_target_properties("${TARGET}" PROPERTIES INTERPROCEDURAL_OPTIMIZATION ON) | ||
|
Krzmbrzl marked this conversation as resolved.
|
||
| endif() | ||
| endif() | ||
| endfunction() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -110,6 +110,9 @@ Useful CMake Variables | |
| - ``ABORT`` in ``Debug`` mode, ``IGNORE`` otherwise | ||
| - Controls how assertions within SeQuant's code are handled. Valid options are ``ABORT``, ``THROW`` and ``IGNORE``. The latter disables | ||
| assertions, whereas the former keep them active and either abort the program or throw an exception on violation respectively. | ||
| * - SEQUANT_LTO | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [D — low] The documented default does not match the code, and Three things in this new row:
|
||
| - `ON` if the compiler supportes "fat" LTO objects, `OFF` otherwise | ||
| - Controls whether SeQuant will be built with link-time optimizations (LTO) | ||
|
|
||
|
|
||
| Configuring and Building | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,7 @@ endif() | |
| pybind11_add_module(python-sequant MODULE src/sequant/_sequant.cc) | ||
|
|
||
| target_link_libraries(python-sequant PRIVATE SeQuant) | ||
| target_set_optimization_flags(python-sequant) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [C — low] This line is my fault, and it should be dropped. I asked for it in finding 2 of the previous review without checking that pybind11 already handles LTO for this target. It does: Concrete effect of adding ours on top: on GCC the compile line for Recommend reverting this one line. Sorry for the churn. |
||
| target_include_directories(python-sequant PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/include") | ||
|
|
||
| set_target_properties( | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.