-
Notifications
You must be signed in to change notification settings - Fork 13k
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
base: master
Are you sure you want to change the base?
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
let available_cgus = | ||
tcx.collect_and_partition_mono_items(()).1.iter().map(|cgu| cgu.name()).collect(); | ||
tcx.collect_and_partition_mono_items(()).2.iter().map(|cgu| cgu.name()).collect(); |
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.
Suggestion: maybe explicitly destructure this
let (_, _, available_cgus) = tcx.collect_and_partition_mono_items(());
let available_cgus = available_cgus.iter().map(|cgu| cgu.name()).collect();
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 think we should just make it a struct instead of a tuple. This can be done in a separate PR landing before this PR
trace!("AUTODIFF ITEMS EXIST"); | ||
for item in &mut *autodiff_items { | ||
trace!("{}", &item); | ||
} |
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: probably more structured tracing?
@@ -370,6 +370,7 @@ mod desc { | |||
pub(crate) const parse_list: &str = "a space-separated list of strings"; | |||
pub(crate) const parse_list_with_polarity: &str = | |||
"a comma-separated list of strings, with elements beginning with + or -"; | |||
pub(crate) const parse_autodiff: &str = "various values"; |
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.
Suggestion: a comma-separated list of autodiff options?
@@ -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.
@@ -194,6 +194,39 @@ impl Default for CoverageLevel { | |||
} | |||
} | |||
|
|||
/// The different settings that the `-Z ad` flag can have. |
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.
Problem: please spell the name out, i.e. -Z autodiff
instead of using the shorthand ad
. Actually I think this is indeed the case, the docs here is just outdated.
autodiff: Vec<crate::config::AutoDiff> = (Vec::new(), parse_autodiff, [TRACKED], | ||
"a list autodiff flags to enable (comma separated)"), |
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.
Problems: see above,
// If you add a new option, please update:
// - compiler/rustc_interface/src/tests.rs
// - src/doc/unstable-book/src/compiler-flags
- Please update
compiler/rustc_interface/src/tests.rs
- Please update
src/doc/rustc/src/codegen-options/index.md
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. |
@@ -176,6 +176,8 @@ pub(crate) fn default_configuration(sess: &Session) -> Cfg { | |||
// NOTE: These insertions should be kept in sync with | |||
// `CheckCfg::fill_well_known` below. | |||
|
|||
ins_none!(sym::autodiff_fallback); |
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.
This is making the autodiff_fallback
cfg stably available.
The cfg should at least be gated behind nightly (with tests, documentation, ...), but is your goal to even let users use autodiff_fallback
cfg? or is it intended to be purely an internal cfg?
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). |
The job Click to see the possible cause of the failure (guessed by this bot)
|
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