Skip to content

Conversation

@traversaro
Copy link
Contributor

Just a proposal, but I thought it was easier to discuss with a proposal as opposed to an issue. The add_compile_options($<$<CONFIG:Release>:-O2>) line adds the -O2 on Release builds, but the Release builds on CMake already pass to the compiled the -O3 flag. Passing also the -O2 options results in both options passed to the compiled, see for example (extracted from compile_commands.json):

{
  "directory": "/home/traversaro/gemma.cpp/build",
  "command": "/usr/bin/c++ -DHWY_STATIC_DEFINE -DTOOLCHAIN_MISS_ASM_HWCAP_H -I/home/traversaro/gemma.cpp/. -I/home/traversaro/gemma.cpp/build/_deps/sentencepiece-src -I/home/traversaro/gemma.cpp/build/_deps/highway-src -O3 -DNDEBUG -O2 -std=gnu++17 -o CMakeFiles/libgemma.dir/gemma.cc.o -c /home/traversaro/gemma.cpp/gemma.cc",
  "file": "/home/traversaro/gemma.cpp/gemma.cc"
},

If instead for some reason you want to use -O2, probably it is necessary to make sure that CMake do not pass -O3 in the first place, for example tweaking CMAKE_CXX_FLAGS_RELEASE or similar.

@jan-wassenberg
Copy link
Member

Hi, thanks for your suggestion and pull request. This makes sense to me.
FYI we are working on the sync tooling so can import pull requests hopefully soon.

@austinvhuang austinvhuang changed the base branch from main to dev February 23, 2024 21:59
@jan-wassenberg jan-wassenberg added the copybara-import Trigger Copybara for merging pull requests label Feb 24, 2024
@austinvhuang austinvhuang merged commit 830dda0 into google:dev Feb 24, 2024
copybara-service bot pushed a commit that referenced this pull request Feb 25, 2024
--
19694e1 by Silvio Traversaro <[email protected]>:

Do not pass explicitly -O2 flag to compiler in Release build

COPYBARA_INTEGRATE_REVIEW=#3 from traversaro:patch-1 19694e1
PiperOrigin-RevId: 610096914
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

copybara-import Trigger Copybara for merging pull requests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants