Skip to content

Implement autodiff using intrinsics #142640

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

Open
wants to merge 33 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
9ab0519
Lower autodiff functions using instrinsics
Sa4dUs Jun 4, 2025
4bc9e4f
Macro expansion with `rustc_intrinsic`
Sa4dUs Jun 5, 2025
6eb931c
Lowering draft
Sa4dUs Jun 17, 2025
4a3203e
Naive impl of intrinsic codegen
Sa4dUs Jun 23, 2025
63a0cfd
Feature intrinsics in cg tests
Sa4dUs Jun 24, 2025
02395d7
Remove `sret` logic
Sa4dUs Jun 29, 2025
2fc199d
Move logic to a dedicated `enzyme_autodiff` intrinsic
Sa4dUs Jul 7, 2025
9296843
Remove attr checking from hir_analysis
Sa4dUs Jul 7, 2025
d5611e4
FIx generics error when passing fn as param to intrinsic
Sa4dUs Jul 8, 2025
7415234
Use Instance::new_raw instead of Instance::mono
Sa4dUs Jul 8, 2025
3f64b82
Hacky fix for issues at trait calls
Sa4dUs Jul 10, 2025
1b7a540
Fix how fns where being retrieved at intrinsic cg
Sa4dUs Jul 11, 2025
cde3c2f
Use Self instead of Foo placeholder
Sa4dUs Jul 11, 2025
5b3909e
Remove unused code
Sa4dUs Jul 12, 2025
9ce6d16
Remove primal call and collect it in mono instead
Sa4dUs Jul 14, 2025
4e2a005
Update codegen tests
Sa4dUs Jul 15, 2025
c55e7ca
Handle slices when extracting args from tuple
Sa4dUs Jul 22, 2025
70503d7
Do not depend on mono anymore
Sa4dUs Jul 23, 2025
09bb20e
Get args from tuple using fnabi and minor fixes
Sa4dUs Jul 23, 2025
4108677
Remove dead code
Sa4dUs Jul 25, 2025
e347e00
Reintroduce autodiff enable and lto errors
Sa4dUs Jul 25, 2025
ba32958
Minor fixes after rebase
Sa4dUs Jul 25, 2025
ce2da2b
Add rest of test fixes
Sa4dUs Jul 25, 2025
fde1300
Remove cfg enzyme for ci
Sa4dUs Jul 25, 2025
886559b
FIx cg_gcc
Sa4dUs Jul 25, 2025
e8e0081
Macro expansion cleanup
Sa4dUs Jul 27, 2025
3330692
Remove dead code
Sa4dUs Jul 27, 2025
c56d57f
Add `enzyme_autodiff` doc comment
Sa4dUs Jul 28, 2025
7f0aca5
Add expansion example to intrinsic docs
Sa4dUs Jul 28, 2025
5673cb8
Better error handling
Sa4dUs Jul 29, 2025
68df065
Allow `core_intrinsics` when `autodiff` is enabled
Sa4dUs Jul 29, 2025
b79b337
Remove autodiff limitations subsection
Sa4dUs Jul 30, 2025
b7d7b73
Remove inlining for autodiff handling
Sa4dUs Jul 30, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4307,7 +4307,6 @@ name = "rustc_monomorphize"
version = "0.0.0"
dependencies = [
"rustc_abi",
"rustc_ast",
"rustc_data_structures",
"rustc_errors",
"rustc_fluent_macro",
Expand All @@ -4316,7 +4315,6 @@ dependencies = [
"rustc_middle",
"rustc_session",
"rustc_span",
"rustc_symbol_mangling",
"rustc_target",
"serde",
"serde_json",
Expand Down
440 changes: 131 additions & 309 deletions compiler/rustc_builtin_macros/src/autodiff.rs

Large diffs are not rendered by default.

6 changes: 0 additions & 6 deletions compiler/rustc_codegen_gcc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ use gccjit::{CType, Context, OptimizationLevel};
#[cfg(feature = "master")]
use gccjit::{TargetInfo, Version};
use rustc_ast::expand::allocator::AllocatorKind;
use rustc_ast::expand::autodiff_attrs::AutoDiffItem;
use rustc_codegen_ssa::back::lto::{SerializedModule, ThinModule};
use rustc_codegen_ssa::back::write::{
CodegenContext, FatLtoInput, ModuleConfig, TargetMachineFactoryFn,
Expand Down Expand Up @@ -362,12 +361,7 @@ impl WriteBackendMethods for GccCodegenBackend {
_exported_symbols_for_lto: &[String],
each_linked_rlib_for_lto: &[PathBuf],
modules: Vec<FatLtoInput<Self>>,
diff_fncs: Vec<AutoDiffItem>,
) -> Result<ModuleCodegen<Self::Module>, FatalError> {
if !diff_fncs.is_empty() {
unimplemented!();
}

back::lto::run_fat(cgcx, each_linked_rlib_for_lto, modules)
}

Expand Down
Loading
Loading