-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Autodiff Upstreaming - rustc_codegen_ssa, rustc_middle #133429
Conversation
To expand on 2) #[autodiff(bar, Reverse, ...)]
fn foo(x: f32) -> f32 { x*x } it will expand to #[rustc_autodiff]
fn foo(x: f32) -> f32 {x*x}
#[rustc_autodiff(Reverse,...)]
fn bar(x: f32, scalar_factor: f32) -> (f32, f32) {
// some_dummy_code()
} Now I have some logic in this PR which picks up the rustc_autodiff attributes and passes them onto the backend, where for every single |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have some interim feedback for this draft PR
@@ -996,6 +997,35 @@ mod parse { | |||
} | |||
} | |||
|
|||
pub(crate) fn parse_autodiff(slot: &mut Vec<AutoDiff>, v: Option<&str>) -> bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remark: this has no error messages if the autodiff options failed to parse, acceptable for unstable flag but still poor UX, unacceptable when it comes to stabilization time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be handled with a proper description in parse_autodiff
above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume there is some rustc function to generate suggestions when users make a typo?
I'll update it for now to print the unrecognized value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looked again at all the other options which accept more values (e.g. instrument_xray), and they have no error-handling either. Is there a preferred way to print errors here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can do this later imo.
For codegen/assembly/ui tests you can make it build w/ fat LTO via
I don't quite understand the implication of this. Is there some small example I can refer to?
Can you elaborate on what test conditions you need? What do you mean exactly by "isolated"? Can you not run autodiff but only if there is autodiff support, or do you mean like don't run by default even if there is autodiff support? |
https://github.com/rust-lang/rust/pull/130060/files#diff-a56b374664e290a55d70fa80e456b6280913830b382b73fb70c4483d3d4cf246 |
This just means that for now, you'll have to gate autodiff-related tests with Note that this cannot break and should not modify code that does not use autodiff at all, which is indicated by codegen tests that do not use / opt-in to autodiff support. |
This PR modifies If appropriate, please update Some changes occurred in coverage instrumentation. cc @Zalathar Some changes occurred in cfg and check-cfg configuration cc @Urgau These commits modify the If this was unintentional then you should revert the changes before this PR is merged. |
b30f1d7
to
2ad340e
Compare
This comment has been minimized.
This comment has been minimized.
I rebased now that the other autodiff PR got merged, fixed all conflicts, and got it to compile locally. |
☔ The latest upstream changes (presumably #136030) made this pull request unmergeable. Please resolve the merge conflicts. |
2ad340e
to
c4af0ba
Compare
This comment has been minimized.
This comment has been minimized.
@oli-obk Just to keep track, so far we have 3/4 things which should be fixed here. Potentially not all in this specific PR, but preferably before enabling it for default nightly builds.
After thinking about it for a bit I'll probably just do 4) for now, and leave 1-3 for a follow-up PR, just for the sake of having a working version upstream. I'll need to talk to jieyouxu to see if we then add test's already here, or in the follow-up PR where I fix 3). |
This comment has been minimized.
This comment has been minimized.
1ab7aa0
to
950d91b
Compare
I'll need to add the fn-ptr error message and left a few questions. |
48d4a6c
to
1f30517
Compare
Since it hasn't been added to a rollup yet, I quickly removed an unwanted print statement and especially adjusted a type check in my wrapper, which wasn't working correctly by checking the return type of a function, instead of a call. Wrappers are fun. But now even higher-order derivatives from my (not yet upstream) testset pass again! |
Rollup of 9 pull requests Successful merges: - rust-lang#132156 (When encountering unexpected closure return type, point at return type/expression) - rust-lang#133429 (Autodiff Upstreaming - rustc_codegen_ssa, rustc_middle) - rust-lang#136281 (`rustc_hir_analysis` cleanups) - rust-lang#136297 (Fix a typo in profile-guided-optimization.md) - rust-lang#136300 (atomic: extend compare_and_swap migration docs) - rust-lang#136310 (normalize `*.long-type.txt` paths for compare-mode tests) - rust-lang#136312 (Disable `overflow_delimited_expr` in edition 2024) - rust-lang#136313 (Filter out RPITITs when suggesting unconstrained assoc type on too many generics) - rust-lang#136323 (Fix a typo in conventions.md) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#133429 - EnzymeAD:autodiff-middle, r=oli-obk Autodiff Upstreaming - rustc_codegen_ssa, rustc_middle This PR should not be merged until the rustc_codegen_llvm part is merged. I will also alter it a little based on what get's shaved off from the cg_llvm PR, and address some of the feedback I received in the other PR (including cleanups). I am putting it already up to 1) Discuss with `@jieyouxu` if there is more work needed to add tests to this and 2) Pray that there is someone reviewing who can tell me why some of my autodiff invocations get lost. Re 1: My test require fat-lto. I also modify the compilation pipeline. So if there are any other llvm-ir tests in the same compilation unit then I will likely break them. Luckily there are two groups who currently have the same fat-lto requirement for their GPU code which I have for my autodiff code and both groups have some plans to enable support for thin-lto. Once either that work pans out, I'll copy it over for this feature. I will also work on not changing the optimization pipeline for functions not differentiated, but that will require some thoughts and engineering, so I think it would be good to be able to run the autodiff tests isolated from the rest for now. Can you guide me here please? For context, here are some of my tests in the samples folder: https://github.com/EnzymeAD/rustbook Re 2: This is a pretty serious issue, since it effectively prevents publishing libraries making use of autodiff: EnzymeAD#173. For some reason my dummy code persists till the end, so the code which calls autodiff, deletes the dummy, and inserts the code to compute the derivative never gets executed. To me it looks like the rustc_autodiff attribute just get's dropped, but I don't know WHY? Any help would be super appreciated, as rustc queries look a bit voodoo to me. Tracking: - rust-lang#124509 r? `@jieyouxu`
Hey @ZuseZ4, it looks like this PR had significant perf implications on a small number of benchmarks, as you can see in the post-merge perf results for the rollup where it landed. It could be related to LTO, from a quick look. I don’t see a pre-merge perf run here, so I assume this is not expected. Could you take a look? Thanks! Let’s also cc the reviewer @oli-obk. |
Oh yea that was absolutely not expected. looking... |
Add link attribute for Enzyme's LLVMRust FFI Since rust-lang#133429 landed, the compiler doesn't build with `-Zcross-crate-inline-threshold=always`. I don't expect anyone else to test or fix issues with that goofy configuration, so I'm fixing it. This PR adds a link attribute just like rust-lang#118142 for all the new LLVMRust functions. They were actually added in rust-lang#130060 but weren't used until just now.
Rollup merge of rust-lang#136374 - saethlin:enzyme-linkage, r=oli-obk Add link attribute for Enzyme's LLVMRust FFI Since rust-lang#133429 landed, the compiler doesn't build with `-Zcross-crate-inline-threshold=always`. I don't expect anyone else to test or fix issues with that goofy configuration, so I'm fixing it. This PR adds a link attribute just like rust-lang#118142 for all the new LLVMRust functions. They were actually added in rust-lang#130060 but weren't used until just now.
…ssion, r=<try> test autodiff compile time fixes Tries to fix the regression from rust-lang#133429
perf regression fixed by #136413 |
…ssion, r=oli-obk fix autodiff compile time regression Tries to fix the regression from rust-lang#133429 Tracking: - rust-lang#124509
…oli-obk fix autodiff compile time regression Tries to fix the regression from rust-lang/rust#133429 Tracking: - rust-lang/rust#124509
…oli-obk fix autodiff compile time regression Tries to fix the regression from rust-lang/rust#133429 Tracking: - rust-lang/rust#124509
…oli-obk fix autodiff compile time regression Tries to fix the regression from rust-lang/rust#133429 Tracking: - rust-lang/rust#124509
This PR should not be merged until the rustc_codegen_llvm part is merged.
I will also alter it a little based on what get's shaved off from the cg_llvm PR,
and address some of the feedback I received in the other PR (including cleanups).
I am putting it already up to
Re 1: My test require fat-lto. I also modify the compilation pipeline. So if there are any other llvm-ir tests in the same compilation unit then I will likely break them. Luckily there are two groups who currently have the same fat-lto requirement for their GPU code which I have for my autodiff code and both groups have some plans to enable support for thin-lto. Once either that work pans out, I'll copy it over for this feature. I will also work on not changing the optimization pipeline for functions not differentiated, but that will require some thoughts and engineering, so I think it would be good to be able to run the autodiff tests isolated from the rest for now. Can you guide me here please?
For context, here are some of my tests in the samples folder: https://github.com/EnzymeAD/rustbook
Re 2: This is a pretty serious issue, since it effectively prevents publishing libraries making use of autodiff: EnzymeAD#173. For some reason my dummy code persists till the end, so the code which calls autodiff, deletes the dummy, and inserts the code to compute the derivative never gets executed. To me it looks like the rustc_autodiff attribute just get's dropped, but I don't know WHY? Any help would be super appreciated, as rustc queries look a bit voodoo to me.
Tracking:
r? @jieyouxu