Skip to content

tool builds with Enzyme/autodiff fails #130637

Closed
@ZuseZ4

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:

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