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

adding autodiff tests #136419

Merged
merged 9 commits into from
Feb 10, 2025
Merged

adding autodiff tests #136419

merged 9 commits into from
Feb 10, 2025

Conversation

ZuseZ4
Copy link
Contributor

@ZuseZ4 ZuseZ4 commented Feb 2, 2025

I'd like to get started with upstreaming some tests, even though I'm still waiting for an answer on how to best integrate the enzyme pass. Can we therefore temporarily support the -Z llvm-plugins here without too much effort? And in that case, how would that work? I saw you can do remapping, e.g. rust-src-base, but I don't think that will give me the path to libEnzyme.so. Do you have another suggestion?

Other than that this test simply checks that the derivative of x*x is 2.0 * x, which in this case is computed as
%0 = fadd fast double %x.0.val, %x.0.val
(I'll add a few more tests and move it to an autodiff folder if we can use the -Z flag)

r? @jieyouxu

Locally at least -Zllvm-plugins=${PWD}/build/x86_64-unknown-linux-gnu/enzyme/build/Enzyme/libEnzyme-19.so seems to work if I copy the command I get from x.py test and run it manually. However, running x.py test itself fails.

Tracking:

Zulip discussion: https://rust-lang.zulipchat.com/#narrow/channel/326414-t-infra.2Fbootstrap/topic/Enzyme.20build.20changes

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 2, 2025
@traviscross traviscross mentioned this pull request Feb 2, 2025
7 tasks
@jieyouxu
Copy link
Member

jieyouxu commented Feb 4, 2025

We can add another remapping variable or do something like //@ add-core-stubs, I'd like #136542 cleanup to land first though to un-confuse the build directory paths in compiletest.
@rustbot blocked (#136542)

@rustbot rustbot added S-blocked Status: Blocked on something else such as an RFC or other implementation work. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 4, 2025
@jieyouxu jieyouxu added A-testsuite Area: The testsuite used to check the correctness of rustc A-compiletest Area: The compiletest test runner F-autodiff `#![feature(autodiff)]` labels Feb 4, 2025
@rust-log-analyzer

This comment has been minimized.

@ZuseZ4
Copy link
Contributor Author

ZuseZ4 commented Feb 7, 2025

@jieyouxu You can remove the blocked message, I don't need a path anymore.
I don't think it will work with another gh repo, but let's try:

@rustbot blocked(EnzymeAD/Enzyme#2238)

@rustbot rustbot added the T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) label Feb 7, 2025
@rust-log-analyzer

This comment has been minimized.

@jieyouxu
Copy link
Member

jieyouxu commented Feb 7, 2025

You can remove the blocked message, I don't need a path anymore. I don't think it will work with another gh repo, but let's try

The message doesn't matter at all, it's just @_rustbot blocked that matters lol

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@ZuseZ4
Copy link
Contributor Author

ZuseZ4 commented Feb 7, 2025

This works locally, so I'll probably make registerEnzyme a weak symbol and gate the pass loading on enzyme being enabled, then this should be ready to merge.

I will leave fighting CI and getting this to work on nightly for the other open PR in which I already started testing to enable this by default.

@rustbot
Copy link
Collaborator

rustbot commented Feb 8, 2025

This PR changes how LLVM is built. Consider updating src/bootstrap/download-ci-llvm-stamp.

@ZuseZ4
Copy link
Contributor Author

ZuseZ4 commented Feb 8, 2025

Nope, not changing how LLVM is build, just Enzyme. So no change should be needed, I'd think.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@ZuseZ4
Copy link
Contributor Author

ZuseZ4 commented Feb 10, 2025

Ok that should be it. Summary of the changes.

  1. A small fix autodiff.rs to our parser. We were not handling forward-mode autodiff correctly, breaking one testcase.
  2. Improve the Enzyme build. Enzyme consists of two passes, one which applies optimizations and one which does autodiff. In the past I was only building the autodiff pass, now I adjusted build_steps/llvm.rs to also build (and run) the opt pass by defining "ENZYME" during the build.
  3. Automatically load the now combined Enzyme opt+autodiff pass. This allows the test to pass without extra flags.
  4. Based on discussion with some LLVM devs and having better control thanks to 3) we now have a better llvm opt scheduling. We first run individual pre-autodiff opt passes on individual CGU. Then we enter the (fat)-lto opt stage (since autodiff atm enforces fat-lto). When rust schedules the fat-lto optimizations we append Enzyme's opt/autodiff pass.
    Finally, we run the whole fat-lto pipeline a second time, to make sure that all the code now is fully optimized.
  5. The last commit removes ForwardFirst and ReverseFirst. Those were temporarily needed for higher-order derivatives (e.g. you generate df by differentiating f, and then you differentiate df). By now using a pass (instead of differentiating functions one at a time) the pass takes care of differentiating this in the right order.

To make 4) a bit clearer I introduced an enum AutodiffStage.
The enzyme submodule updated marked registerEnzyme as extern "C", so I'm able to link against it from Rust.

Those seem to be enough things for one PR, so I don't consider how this impacts compile times (and runtime perf) if Enzyme is enabled (there are no impacts if it's disabled). There is a second PR where I make sure that we can ship this on nightly without regressions.

@onur-ozkan Any other requests?

@rustbot rustbot added the A-attributes Area: Attributes (`#[…]`, `#![…]`) label Feb 10, 2025
@rustbot
Copy link
Collaborator

rustbot commented Feb 10, 2025

Some changes occurred in compiler/rustc_codegen_ssa/src/codegen_attrs.rs

cc @jdonszelmann

@ZuseZ4
Copy link
Contributor Author

ZuseZ4 commented Feb 10, 2025

r? @onur-ozkan (lmk if you want someone else to review it).

@rustbot
Copy link
Collaborator

rustbot commented Feb 10, 2025

Could not assign reviewer from: onur-ozkan.
User(s) onur-ozkan are either the PR author, already assigned, or on vacation. Please use r? to specify someone else to assign.

@ZuseZ4 ZuseZ4 requested a review from jieyouxu February 10, 2025 03:34
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Feb 10, 2025
@ZuseZ4
Copy link
Contributor Author

ZuseZ4 commented Feb 10, 2025

Interesting, Onur is assigned, but not a reviewer, so I couldn't request a review. Requested one from jieyouxu, just s.t. the PR status is correct.

Copy link
Member

@onur-ozkan onur-ozkan left a comment

Choose a reason for hiding this comment

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

Thanks!

@onur-ozkan
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Feb 10, 2025

📌 Commit 8578aae has been approved by onur-ozkan

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 10, 2025
@ZuseZ4
Copy link
Contributor Author

ZuseZ4 commented Feb 10, 2025

(I didn't directly expect an r+ and didn't want to force-push while people were potentially reviewing, so I just cleaned it up now.)

@jieyouxu
Copy link
Member

I can never remember what the force-push behavior was, so...
@bors r=onur-ozkan,jieyouxu

@bors
Copy link
Contributor

bors commented Feb 10, 2025

📌 Commit 061abbc has been approved by onur-ozkan,jieyouxu

It is now in the queue for this repository.

@onur-ozkan
Copy link
Member

onur-ozkan commented Feb 10, 2025

(I didn't directly expect an r+ and didn't want to force-push while people were potentially reviewing, so I just cleaned it up now.)

As you r? me I thought you didn't want to re-work on commit history (most people avoid that). It would be better to have cleaner commit history for sure.

@rustbot

This comment was marked as off-topic.

workingjubilee added a commit to workingjubilee/rustc that referenced this pull request Feb 10, 2025
…kan,jieyouxu

adding autodiff tests

I'd like to get started with upstreaming some tests, even though I'm still waiting for an answer on how to best integrate the enzyme pass. Can we therefore temporarily support the -Z llvm-plugins here without too much effort? And in that case, how would that work? I saw you can do remapping, e.g. `rust-src-base`, but I don't think that will give me the path to libEnzyme.so. Do you have another suggestion?

Other than that this test simply checks that the derivative of `x*x` is `2.0 * x`, which in this case is computed as
`%0 = fadd fast double %x.0.val, %x.0.val`
(I'll add a few more tests and move it to an autodiff folder if we can use the -Z flag)

r? `@jieyouxu`

Locally at least `-Zllvm-plugins=${PWD}/build/x86_64-unknown-linux-gnu/enzyme/build/Enzyme/libEnzyme-19.so` seems to work if I copy the command I get from x.py test and run it manually. However, running x.py test itself fails.

Tracking:

- rust-lang#124509

Zulip discussion: https://rust-lang.zulipchat.com/#narrow/channel/326414-t-infra.2Fbootstrap/topic/Enzyme.20build.20changes
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 10, 2025
…kingjubilee

Rollup of 9 pull requests

Successful merges:

 - rust-lang#134626 (Add Four Codegen Tests)
 - rust-lang#135408 (x86: make SSE2 required for i686 hardfloat targets and use it to pass SIMD types)
 - rust-lang#136155 (Enable sanitizers on MSVC CI jobs)
 - rust-lang#136419 (adding autodiff tests)
 - rust-lang#136603 (compiler: gate `extern "{abi}"` in ast_lowering)
 - rust-lang#136628 (ci: upgrade to crosstool-ng 1.27.0)
 - rust-lang#136714 (Update `compiler-builtins` to 0.1.146)
 - rust-lang#136731 (rustc_middle: parallel: TyCtxt: remove "unsafe impl DynSend/DynSync")
 - rust-lang#136761 (tests: `-Copt-level=3` instead of `-O` in codegen tests)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 10, 2025
…iaskrgr

Rollup of 6 pull requests

Successful merges:

 - rust-lang#136419 (adding autodiff tests)
 - rust-lang#136628 (ci: upgrade to crosstool-ng 1.27.0)
 - rust-lang#136681 (resolve `llvm-config` path properly on cross builds)
 - rust-lang#136714 (Update `compiler-builtins` to 0.1.146)
 - rust-lang#136731 (rustc_middle: parallel: TyCtxt: remove "unsafe impl DynSend/DynSync")
 - rust-lang#136791 (Disable DWARF in linker options for i686-unknown-uefi)

Failed merges:

 - rust-lang#136767 (improve host/cross target checking)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 78f5bdd into rust-lang:master Feb 10, 2025
6 checks passed
@rustbot rustbot added this to the 1.86.0 milestone Feb 10, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Feb 10, 2025
Rollup merge of rust-lang#136419 - EnzymeAD:autodiff-tests, r=onur-ozkan,jieyouxu

adding autodiff tests

I'd like to get started with upstreaming some tests, even though I'm still waiting for an answer on how to best integrate the enzyme pass. Can we therefore temporarily support the -Z llvm-plugins here without too much effort? And in that case, how would that work? I saw you can do remapping, e.g. `rust-src-base`, but I don't think that will give me the path to libEnzyme.so. Do you have another suggestion?

Other than that this test simply checks that the derivative of `x*x` is `2.0 * x`, which in this case is computed as
`%0 = fadd fast double %x.0.val, %x.0.val`
(I'll add a few more tests and move it to an autodiff folder if we can use the -Z flag)

r? ``@jieyouxu``

Locally at least `-Zllvm-plugins=${PWD}/build/x86_64-unknown-linux-gnu/enzyme/build/Enzyme/libEnzyme-19.so` seems to work if I copy the command I get from x.py test and run it manually. However, running x.py test itself fails.

Tracking:

- rust-lang#124509

Zulip discussion: https://rust-lang.zulipchat.com/#narrow/channel/326414-t-infra.2Fbootstrap/topic/Enzyme.20build.20changes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`) A-compiletest Area: The compiletest test runner A-testsuite Area: The testsuite used to check the correctness of rustc F-autodiff `#![feature(autodiff)]` S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants