[Build] Add LTO, PGO, and -march=native CMake options#11025
Open
taherbert wants to merge 1 commit intosimulationcraft:midnightfrom
Open
[Build] Add LTO, PGO, and -march=native CMake options#11025taherbert wants to merge 1 commit intosimulationcraft:midnightfrom
taherbert wants to merge 1 commit intosimulationcraft:midnightfrom
Conversation
The legacy engine/Makefile supports LTO, PGO, and -march=native but the CMake build has no equivalent. This adds opt-in CMake options that bring those capabilities to cmake users. New options (all OFF by default, existing builds unaffected): - SC_LTO: thin LTO on Clang, full LTO on GCC - SC_MARCH_NATIVE: tune for the host CPU - SC_PGO_GENERATE / SC_PGO_USE: LLVM/GCC profile-guided optimization Bumps cmake_minimum_required to 3.13 for target_link_options(). Also adds scripts/benchmark.sh which automates a three-way comparison (baseline vs LTO+march vs PGO+LTO+march) and prints a results table. Tested on Apple Silicon (M4 Max, AppleClang 17): Variant Time(s) Speedup Release (baseline) 0.64 1.00x LTO + march=native 0.57 1.12x PGO + LTO + march=native 0.55 1.16x (best of 3 runs, 1000 iterations, 4 threads, MID1_Priest_Shadow)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The legacy engine/Makefile supports LTO, PGO, and -march=native but the CMake build has no equivalent. This adds them as opt-in options.
New options (all OFF by default — existing builds unaffected):
SC_LTO— thin LTO on Clang, full LTO on GCCSC_MARCH_NATIVE— tune for the host CPUSC_PGO_GENERATE/SC_PGO_USE— profile-guided optimization (Clang and GCC)Bumps
cmake_minimum_requiredto 3.13 fortarget_link_options().Also adds
scripts/benchmark.shwhich builds all three variants and prints a comparison table.Results (Apple Silicon M4 Max, AppleClang 17, best of 3 runs, 1000 iterations, 4 threads):
-ffast-mathwas also tested — it made things 3x slower, so it is excluded.Usage:
Or run
scripts/benchmark.shfor the full comparison including PGO.Note: Let me know if we'd prefer to remove benchmarking script, but thought it would be helpful for verification.