Skip to content

tool builds with Enzyme/autodiff fails #130637

Closed

Description

@ZuseZ4

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:

Activity

  1. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Sep 20, 2024
  2. added
    T-bootstrapRelevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)
    C-bugCategory: This is a bug.
    and removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Sep 20, 2024
  3. onur-ozkan commented on Sep 21, 2024

    @onur-ozkan
    Contributor

    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.

  4. changed the title [-]Bootstrap bug: dist build with Enzyme/autodiff fails[/-] [+]tool builds with Enzyme/autodiff fails[/+] on Sep 21, 2024
  5. added 3 commits that reference this issue on Sep 22, 2024
    3113558
    31c8509
    959f33a
  6. added a commit that references this issue on Sep 22, 2024
    fef3b6c
  7. ZuseZ4 commented on Sep 22, 2024

    @ZuseZ4
    MemberAuthor

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.T-bootstrapRelevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions