refactor(autodiff): Simplify Autodiff Handling of rlib Dependencies#153379
Conversation
|
Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt Some changes occurred in compiler/rustc_codegen_llvm/src/builder/autodiff.rs cc @ZuseZ4 |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
08fc7e9 to
671a24e
Compare
This comment has been minimized.
This comment has been minimized.
| }; | ||
|
|
||
| let fn_ptr_ty = | ||
| Ty::new_fn_ptr(tcx, fn_source.ty(tcx, TypingEnv::fully_monomorphized()).fn_sig(tcx)); |
There was a problem hiding this comment.
The other half of the fix is changing the rustc_autodiff intrinsic to accept a function pointer rather than function item.
There was a problem hiding this comment.
Great! It can be even less code. Love reducing code.
671a24e to
cd9aa24
Compare
|
Some changes occurred in compiler/rustc_builtin_macros/src/autodiff.rs cc @ZuseZ4 |
This comment has been minimized.
This comment has been minimized.
…ust_activity_to_abi`, drop mono-collection & cross-crate-inline workarounds
cd9aa24 to
8a3d0f4
Compare
|
Thanks! I verified that tests still pass locally with this. I'm slightly disappointed that this makes writing the intrinsic by hand a little more annoying, but we only do that very rarely when prototyping some frontend changes. Re-reading Bjorn's comment, I guess that also was to be expected. The benefits of being able to completely remove autodiff handling from @bors r+ cc @saethlin |
This comment has been minimized.
This comment has been minimized.
What is this?This is an experimental post-merge analysis report that shows differences in test outcomes between the merged PR and its parent PR.Comparing b49ecc9 (parent) -> d1c7945 (this PR) Test differencesShow 16 test diffs16 doctest diffs were found. These are ignored, as they are noisy. Test dashboardRun cargo run --manifest-path src/ci/citool/Cargo.toml -- \
test-dashboard d1c79458b5d13bd0179d7dbafd5ca4ea9ae3e6aa --output-dir test-dashboardAnd then open Job duration changes
How to interpret the job duration changes?Job durations can vary a lot, based on the actual runner instance |
|
Finished benchmarking commit (d1c7945): comparison URL. Overall result: ❌ regressions - no action needed@rustbot label: -perf-regression Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (primary -1.7%, secondary 1.0%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (primary 1.7%, secondary -3.5%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeResults (primary -0.0%, secondary -0.1%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Bootstrap: 479.93s -> 479.3s (-0.13%) |
| #[rustc_autodiff(Forward, 1, Dual, Const, Dual)] | ||
| pub fn df1(x: &[f64], bx_0: &[f64], y: f64) -> (f64, f64) { | ||
| ::core::intrinsics::autodiff(f1::<>, df1::<>, (x, bx_0, y)) | ||
| ::core::intrinsics::autodiff(f1::<> as fn(_: &[f64], _: f64) -> f64, |
There was a problem hiding this comment.
f1::<> as _ may also work. That should allow getting rid of most code you added to compiler/rustc_builtin_macros/src/autodiff.rs
There was a problem hiding this comment.
Do we need a follow-up PR?
There was a problem hiding this comment.
I tried locally updating the primal_fn_ptr to
let primal_fn_ptr = ecx.expr(span, ast::ExprKind::Cast(primal_path_expr, ecx.ty(span, TyKind::Infer)));:
45 #[rustc_autodiff(Forward, 1, Dual, Const, Const)]
46 pub fn df2(x: &[f64], bx_0: &[f64], y: f64) -> f64 {
- ::core::intrinsics::autodiff(f2::<> as fn(_: &[f64], _: f64) -> f64,
- df2::<>, (x, bx_0, y))
+ ::core::intrinsics::autodiff(f2::<> as _, df2::<>, (x, bx_0, y))
49 }
But unfortunately, type inference fails in all cases then:
------rustc stderr------------------------------
error[E0282]: type annotations needed
--> /home/manuel/prog/rust/tests/codegen-llvm/autodiff/generic.rs:16:1
|
16 | #[autodiff_reverse(d_square, Duplicated, Active)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type
Summary:
Resolves the two FIXMEs left in #149033, per @bjorn3 guidance in the discussion.
Closes #149164
r? @ZuseZ4
cc @bjorn3