OpenROAD icon indicating copy to clipboard operation
OpenROAD copied to clipboard

Build with LTO in release mode by default

Open kbieganski opened this issue 1 year ago • 17 comments

Enables link time optimizations by default in release mode, yielding 3-12% better performance for the entire flow.

nangate45/ibex run Mean [s] Min [s] Max [s] Relative
No LTO 256.417 ± 1.089 252.747 258.500 1.12 ± 0.01
With LTO 228.625 ± 1.979 223.222 230.904 1.00
nangate45/black_parrot run Mean [s] Min [s] Max [s] Relative
No LTO 2961.542 ± 14.714 2937.151 2987.307 1.06 ± 0.01
With LTO 2795.283 ± 26.873 2725.632 2822.192 1.00
nangate45/ariane133 run Mean [s] Min [s] Max [s] Relative
No LTO 5807.242 ± 17.377 5791.852 5832.0591 1.03 ± 0.02
With LTO 5651.473 ± 71.611 5550.869 5739.271 1.00

kbieganski avatar Jan 17 '24 18:01 kbieganski

clang-tidy review says "All clean, LGTM! :+1:"

github-actions[bot] avatar Jan 17 '24 18:01 github-actions[bot]

I've tried enabling this before, but the GUI fails to run under LTO. Have you tried running the GUI?

QuantamHD avatar Jan 17 '24 18:01 QuantamHD

https://github.com/InBetweenNames/gentooLTO/issues/444

QuantamHD avatar Jan 17 '24 18:01 QuantamHD

Ah, no, I've only been building without the GUI. I'll try it, and if it doesn't work, I'll add another condition that checks if BUILD_GUI=off.

kbieganski avatar Jan 17 '24 18:01 kbieganski

It also might be possible to compile the GUI without LTO and the other parts with, but I never looked into how that might work.

QuantamHD avatar Jan 17 '24 18:01 QuantamHD

If LTO doesn't work out AutoFDO might be a more stable option https://gcc.gnu.org/wiki/AutoFDO/Tutorial

QuantamHD avatar Jan 17 '24 19:01 QuantamHD

Please also give a summary of the impact on link time of using whatever option you settle on.

maliberty avatar Jan 17 '24 21:01 maliberty

Full build Linking only
No LTO 8 min 23 s 5 s
With LTO 9 min 23 s 1 min 30 s

On GCC 13.2.1, i7-9700 (8 cores)

The GUI actually works for me with LTO (Arch Linux, Qt 5.15.12). I'll try with Clang. Also, seems like the CI is failing on Clang.

kbieganski avatar Jan 19 '24 10:01 kbieganski

The linking only hit is too substantial to be on by default imo. I expect the full build on a bigger machine will also look worse. Let's make this an option. It could be on for the pre-built binary releases (@vvbandeira )

maliberty avatar Jan 19 '24 12:01 maliberty

If it's not possible to build only the GUI without LTO, then maybe CMake can just error if both LTO and the GUI are enabled.

rovinski avatar Jan 19 '24 15:01 rovinski

If we're not going to enable it by default, there's no point in this PR. Closing it.

For future reference:

  • If you want to build with LTO, use -DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON (or -DLINK_TIME_OPTIMIZATION=ON) when configuring
  • The GUI worked for me with LTO (Qt 5.15.12), so this issue may have been resolved. (Also, for CI I recommend -DBUILD_GUI=no)
  • Use a new-ish compiler and avoid the BFD linker (the default GNU linker). For me, BFD segfaulted with Clang. Use gold, lld, or mold. They're much faster anyway: LTO link time with Clang+any of these is about twice as fast as GCC+BFD.

kbieganski avatar Jan 26 '24 11:01 kbieganski

We could make it the default but there needs to be an option to turn it off for developers in an edit/compile/run loop.

maliberty avatar Jan 26 '24 20:01 maliberty

For sure, you don't want LTO while developing. I'll get back to this then.

kbieganski avatar Jan 29 '24 11:01 kbieganski

clang-tidy review says "All clean, LGTM! :+1:"

github-actions[bot] avatar Jan 29 '24 18:01 github-actions[bot]

clang-tidy review says "All clean, LGTM! :+1:"

github-actions[bot] avatar Feb 01 '24 12:02 github-actions[bot]

@kbieganski are you still planning to get back to this?

maliberty avatar Mar 06 '24 18:03 maliberty

I'm busy with other stuff at the moment, so if anyone is willing to take over, go ahead.

kbieganski avatar Mar 06 '24 21:03 kbieganski