Skip to content
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

tool builds with Enzyme/autodiff fails #130637

Closed
ZuseZ4 opened this issue Sep 20, 2024 · 2 comments · Fixed by #130648
Closed

tool builds with Enzyme/autodiff fails #130637

ZuseZ4 opened this issue Sep 20, 2024 · 2 comments · Fixed by #130648
Labels
C-bug Category: This is a bug. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)

Comments

@ZuseZ4
Copy link
Contributor

ZuseZ4 commented Sep 20, 2024

A while ago we merged the first backend pr to enable automatic differentiation in Rust: #129176.
This was good enough to add and enable the enzyme config in config.toml and run x.py build --stage 1.
We would now like to improve the integration to also successfully run x.py dist --stage 1 (to use Rust in our autodiff compiler explorer).
@jedbrown and I looked into it for a while and while it seems like a simple linker issue, we didn't fully understood where it comes from and what's the best way to fix it. This commit has a few more changes (not yet upstreamed) that might help for understanding how enzyme is used master...EnzymeAD:rust:master. We also have documentation here: https://enzyme.mit.edu/index.fcgi/rust/

Back to the issue. We first build Enzyme (a git submodule) and then try to link it. To copy Jed's observations:
The code to add -lEnzyme-19 is in src/bootstrap/src/core/builder.rs inside fn cargo.

if self.config.llvm_enzyme {
    rustflags.arg("-l");
    rustflags.arg("Enzyme-19");
}

Note that linking works correctly when building normal crates. Also, I find it odd that this one line of code yields so many repeat arguments (as in, "-Wl,-Bdynamic" "-lEnzyme-19" "-lEnzyme-19" "-lEnzyme-19" "-lEnzyme-19" "-lEnzyme-19" "-lEnzyme-19" "-lEnzyme-19" "-lEnzyme-19" "-lEnzyme-19" "-lEnzyme-19" "-lEnzyme-19" "-lEnzyme-19" "-lEnzyme-19" "-lEnzyme-19" "-lEnzyme-19" "-lEnzyme-19" "-lEnzyme-19" "-lEnzyme-19" "-lEnzyme-19" "-lEnzyme-19" "-lEnzyme-19" "-lEnzyme-19" "-lEnzyme-19" "-lEnzyme-19" "-lEnzyme-19" "-lEnzyme-19" "-lEnzyme-19" "-lEnzyme-19" "-lEnzyme-19" "-lEnzyme-19" "-lEnzyme-19" "-lEnzyme-19" "-lEnzyme-19" "-lEnzyme-19" "-lEnzyme-19" "-lgcc_s").

Is there a better way to link Enzyme?
Should we prefer to elide Enzyme linking when it isn't needed or be more explicit with paths so it is always found?
A potentially related linking error only happens under MacOS: EnzymeAD#175

Related Zulip issue: https://rust-lang.zulipchat.com/#narrow/stream/326414-t-infra.2Fbootstrap/topic/Fixing.20x.2Epy.20dist.20linking.20issue

Tracking:

@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Sep 20, 2024
@onur-ozkan onur-ozkan added T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) C-bug Category: This is a bug. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Sep 20, 2024
@onur-ozkan
Copy link
Member

onur-ozkan commented Sep 21, 2024

It's not just about dist builds; this happens on any build that triggers tool builds (e.g., running x build unstable-book-gen would fail too). This happens because enzyme linking flags are set in the general-purpose cargo function and used in every build even when they aren't needed. #130648 changes this so that the flags are set only for the rustc build as they aren't required for other builds.

@onur-ozkan onur-ozkan changed the title Bootstrap bug: dist build with Enzyme/autodiff fails tool builds with Enzyme/autodiff fails Sep 21, 2024
workingjubilee added a commit to workingjubilee/rustc that referenced this issue Sep 22, 2024
move enzyme flags from general cargo to rustc-specific cargo

Resolves rust-lang#130637.
workingjubilee added a commit to workingjubilee/rustc that referenced this issue Sep 22, 2024
move enzyme flags from general cargo to rustc-specific cargo

Resolves rust-lang#130637.
@bors bors closed this as completed in 959f33a Sep 22, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Sep 22, 2024
Rollup merge of rust-lang#130648 - onur-ozkan:enzyme-linking, r=Kobzol

move enzyme flags from general cargo to rustc-specific cargo

Resolves rust-lang#130637.
@ZuseZ4
Copy link
Contributor Author

ZuseZ4 commented Sep 22, 2024

Thank you @onur-ozkan for the quick fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants