Skip to content

[BE]: Try turning on LTO in CMake in CI - #137866

Closed
Skylion007 wants to merge 9 commits into
pytorch:mainfrom
Skylion007:skylion007/exp-lto-2024-10-13
Closed

Skylion007 wants to merge 9 commits into
pytorch:mainfrom
Skylion007:skylion007/exp-lto-2024-10-13

Conversation

@Skylion007

@Skylion007 Skylion007 commented Oct 13, 2024 •

Copy link
Copy Markdown
Collaborator

Fixes #ISSUE_NUMBER
This will very likely not work, but let's see.

cc @jgong5 @mingfeima @XiaobingSuper @sanchitintel @ashokei @jingxu10

@pytorch-bot

pytorch-bot Bot commented Oct 13, 2024 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/137866

Note: Links to docs will display an error until the docs builds have been completed.

❌ 12 New Failures, 1 Unrelated Failure

As of commit 3f4fd0b with merge base c1c8c1f (image):

NEW FAILURES - The following jobs have failed:

UNSTABLE - The following job is marked as unstable, possibly due to flakiness on trunk:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@pytorch-bot pytorch-bot Bot added the topic: not user facing topic category label Oct 13, 2024
@Skylion007
Skylion007 force-pushed the skylion007/exp-lto-2024-10-13 branch 3 times, most recently from fccff69 to 6d1ca1b Compare October 13, 2024 16:29
@Skylion007

Skylion007 commented Oct 13, 2024 •

Copy link
Copy Markdown
Collaborator Author

So seems to have some fun complications. Some version of clang's LLD linker are too old to link some of the GCC prebuilt binaries. On the other hand, clang-10 and below doesn't come with anyway plugins for ld.gold for link time optimization which are needed. We can just an extra binary for clang-tidy 11>=

Alternatively, I am failing to override the linker properly in one place, which could also be possible.

Comment thread .ci/docker/common/install_clang.sh Outdated

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can In install llvmGold.so in versions less than llvm-11?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't try on lower llvm

@Skylion007 Skylion007 Oct 14, 2024 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not, but clang-10 doesn't seem to properly ship the binary llvmGold.so or at the very least it's installed in the wrong place and not found by the linker.

@Skylion007
Skylion007 force-pushed the skylion007/exp-lto-2024-10-13 branch 2 times, most recently from bb1f19a to cae09eb Compare October 13, 2024 19:23
@Skylion007

Skylion007 commented Oct 13, 2024 •

Copy link
Copy Markdown
Collaborator Author

@Skylion007
Skylion007 force-pushed the skylion007/exp-lto-2024-10-13 branch from cae09eb to 7311b07 Compare October 13, 2024 19:50
@pytorch-bot pytorch-bot Bot added the module: cpu CPU specific problem (e.g., perf, algorithm) label Oct 13, 2024
@Skylion007

Skylion007 commented Oct 13, 2024 •

Copy link
Copy Markdown
Collaborator Author

Okay, XNNPACK has a few warnings treated as errors blocking LTO, but they are relatively straightforward fixes:

/var/lib/jenkins/workspace/third_party/XNNPACK/src/amalgam/gen/sse2.c:2482: error: type of ‘xnn_table_exp2minus_k_over_64’ does not match original declaration [-Werror=lto-type-mismatch]
 2482 | extern XNN_INTERNAL const float xnn_table_exp2minus_k_over_64[64];
      | 
/var/lib/jenkins/workspace/third_party/XNNPACK/src/tables/exp2minus-k-over-64.c:12: note: type ‘const uint32_t’ should match type ‘const float’
   12 | XNN_INTERNAL const uint32_t xnn_table_exp2minus_k_over_64[64] = {
      | 
/var/lib/jenkins/workspace/third_party/XNNPACK/src/tables/exp2minus-k-over-64.c:12: note: ‘xnn_table_exp2minus_k_over_64’ was previously declared here
/var/lib/jenkins/workspace/third_party/XNNPACK/src/amalgam/gen/sse2.c:1931: error: type of ‘xnn_table_exp2minus_k_over_16’ does not match original declaration [-Werror=lto-type-mismatch]
 1931 | extern XNN_INTERNAL const float xnn_table_exp2minus_k_over_16[16];
      | 
/var/lib/jenkins/workspace/third_party/XNNPACK/src/tables/exp2minus-k-over-16.c:12: note: type ‘const uint32_t’ should match type ‘const float’
   12 | XNN_INTERNAL const uint32_t xnn_table_exp2minus_k_over_16[16] = {
      | 
/var/lib/jenkins/workspace/third_party/XNNPACK/src/tables/exp2minus-k-over-16.c:12: note: ‘xnn_table_exp2minus_k_over_16’ was previously declared here
lto1: all warnings being treated as errors

@pomelohan

Copy link
Copy Markdown
Contributor

@cyyever Any thoughts here on how to properly enable LTO on Clang workflows? https://cmake.org/cmake/help/latest/module/CheckIPOSupported.html

Maybe a possible version?:

# Optional IPO. Do not use IPO if it's not supported by compiler.
check_ipo_supported(RESULT ipo_supported OUTPUT output)

# Enable IPO for Release builds if supported and not explicitly set
if(CMAKE_BUILD_TYPE STREQUAL "Release" AND ipo_supported)
  if(NOT DEFINED CMAKE_INTERPROCEDURAL_OPTIMIZATION)
    set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON)  # turns CMake LTO for OSS builds
  endif()
elseif(NOT ipo_supported)
  message(WARNING "IPO is not supported by compiler")
endif()

@cyyever

cyyever commented Oct 14, 2024

Copy link
Copy Markdown
Collaborator

I agree, the point is to work out a quick version of LTO and see what tests break

@Skylion007

Copy link
Copy Markdown
Collaborator Author

Oh it's supported alright, the issue is with the linker plugin not being properly distributed in the binary until clang version 11 or newer. There is one binary dependency that is built with a newer linker (which doesn't seem to phase GNU linkers, but fails an assert for LLD unless a more recent one is used).

@Skylion007

Copy link
Copy Markdown
Collaborator Author

Updating to clang11 minimum would likely fix all the other issues since we could use the linker tools apt-get package which is available for llvm 11 and newer

@Skylion007

Copy link
Copy Markdown
Collaborator Author

Switching to lld breaks inductor interestingly enough it seems

@Skylion007

Copy link
Copy Markdown
Collaborator Author

I worked around the GCC warning, and now I hit assembler errors (likely due to LTO optimizing away some important symbols or other bugs in the compile toolchain). Fun...

@Skylion007

Copy link
Copy Markdown
Collaborator Author

Updating our minimum clang version even to 11 and installing the GNU linker plugins so we can use ld would solve most of the problems with clang. I didn't use to have this issue with GCC previously... it's likely coming from custom assembly code somewhere.

@Skylion007

Copy link
Copy Markdown
Collaborator Author

@cyyever The undefined reference stuff seems like stuff you were investigating with the static function / C10_API if you are interested

@cyyever

cyyever commented Oct 29, 2024

Copy link
Copy Markdown
Collaborator

@pytorchbot rebase -b main

@cyyever

cyyever commented Oct 29, 2024

Copy link
Copy Markdown
Collaborator

@cyyever The undefined reference stuff seems like stuff you were investigating with the static function / C10_API if you are interested

merged

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

@pytorchbot started a rebase job onto refs/remotes/origin/main. Check the current status here

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Successfully rebased skylion007/exp-lto-2024-10-13 onto refs/remotes/origin/main, please pull locally before adding more changes (for example, via git checkout skylion007/exp-lto-2024-10-13 && git pull --rebase)

@pytorchmergebot
pytorchmergebot force-pushed the skylion007/exp-lto-2024-10-13 branch from 0ebfd83 to 92bb1f2 Compare October 29, 2024 23:10
@cyyever

cyyever commented Oct 29, 2024

Copy link
Copy Markdown
Collaborator

@Skylion007 clang-lld installation can be submitted in other PR to avoid rebuilding images each time?

@cyyever

cyyever commented Dec 3, 2024

Copy link
Copy Markdown
Collaborator

@Skylion007 No idea now, but I can try it on the local host and observe how to fix

@Skylion007

Copy link
Copy Markdown
Collaborator Author

@pytorchbot rebase

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

@pytorchbot started a rebase job onto refs/remotes/origin/viable/strict. Check the current status here

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Rebase failed due to Command git -C /home/runner/work/pytorch/pytorch rebase refs/remotes/origin/viable/strict pull/137866/head returned non-zero exit code 1

Rebasing (1/17)
Rebasing (2/17)
Rebasing (3/17)
Rebasing (4/17)
Rebasing (5/17)
Rebasing (6/17)
Rebasing (7/17)
Rebasing (8/17)
Auto-merging CMakeLists.txt
CONFLICT (content): Merge conflict in CMakeLists.txt
error: could not apply 120727fc6a... Ignore LTO error for GCC
hint: Resolve all conflicts manually, mark them as resolved with
hint: "git add/rm <conflicted_files>", then run "git rebase --continue".
hint: You can instead skip this commit: run "git rebase --skip".
hint: To abort and get back to the state before "git rebase", run "git rebase --abort".
hint: Disable this message with "git config advice.mergeConflict false"
Could not apply 120727fc6a... Ignore LTO error for GCC

Raised by https://github.com/pytorch/pytorch/actions/runs/12586925754

@Skylion007
Skylion007 force-pushed the skylion007/exp-lto-2024-10-13 branch from 9a77c3a to f992c32 Compare January 2, 2025 18:38
@Skylion007

Skylion007 commented Jan 7, 2025 •

Copy link
Copy Markdown
Collaborator Author

@cyyever The external symbol errors from VSCode are interesting... Does this have to do with your recent symbol PRs?

@github-actions

github-actions Bot commented Mar 8, 2025

Copy link
Copy Markdown
Contributor

Looks like this PR hasn't been updated in a while so we're going to go ahead and mark this as Stale.
Feel free to remove the Stale label if you feel this was a mistake.
If you are unable to remove the Stale label please contact a maintainer in order to do so.
If you want the bot to never mark this PR stale again, add the no-stale label.
Stale pull requests will automatically be closed after 30 days of inactivity.

@github-actions github-actions Bot added the Stale label Mar 8, 2025
@github-actions github-actions Bot closed this Apr 7, 2025
@Skylion007 Skylion007 reopened this Apr 25, 2025
@Skylion007

Copy link
Copy Markdown
Collaborator Author

@pytorchbot rebase

@Skylion007

Copy link
Copy Markdown
Collaborator Author

@pytorchbot rebase

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

@pytorchbot started a rebase job onto refs/remotes/origin/viable/strict. Check the current status here

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Rebase failed due to Command git -C /home/runner/work/pytorch/pytorch rebase refs/remotes/origin/viable/strict pull/137866/head returned non-zero exit code 1

Rebasing (1/12)
Rebasing (2/12)
Rebasing (3/12)
Rebasing (4/12)
Rebasing (5/12)
Rebasing (6/12)
Rebasing (7/12)
Rebasing (8/12)
Auto-merging CMakeLists.txt
CONFLICT (content): Merge conflict in CMakeLists.txt
error: could not apply f992c32d165... Ignore LTO error for GCC
hint: Resolve all conflicts manually, mark them as resolved with
hint: "git add/rm <conflicted_files>", then run "git rebase --continue".
hint: You can instead skip this commit: run "git rebase --skip".
hint: To abort and get back to the state before "git rebase", run "git rebase --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Could not apply f992c32d165... Ignore LTO error for GCC

Raised by https://github.com/pytorch/pytorch/actions/runs/14666205411

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

@pytorchbot started a rebase job onto refs/remotes/origin/viable/strict. Check the current status here

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Rebase failed due to Command git -C /home/runner/work/pytorch/pytorch rebase refs/remotes/origin/viable/strict pull/137866/head returned non-zero exit code 1

Rebasing (1/12)
Rebasing (2/12)
Rebasing (3/12)
Rebasing (4/12)
Rebasing (5/12)
Rebasing (6/12)
Rebasing (7/12)
Rebasing (8/12)
Auto-merging CMakeLists.txt
CONFLICT (content): Merge conflict in CMakeLists.txt
error: could not apply f992c32d165... Ignore LTO error for GCC
hint: Resolve all conflicts manually, mark them as resolved with
hint: "git add/rm <conflicted_files>", then run "git rebase --continue".
hint: You can instead skip this commit: run "git rebase --skip".
hint: To abort and get back to the state before "git rebase", run "git rebase --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Could not apply f992c32d165... Ignore LTO error for GCC

Raised by https://github.com/pytorch/pytorch/actions/runs/14666226433

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

module: cpu CPU specific problem (e.g., perf, algorithm) open source Stale topic: not user facing topic category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants