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 34 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
9f09fa2
Lower autodiff functions using instrinsics
Sa4dUs Jun 4, 2025
5f1136c
Macro expansion with `rustc_intrinsic`
Sa4dUs Jun 5, 2025
03ae1a8
Lowering draft
Sa4dUs Jun 17, 2025
7b28dce
Naive impl of intrinsic codegen
Sa4dUs Jun 23, 2025
226b806
Feature intrinsics in cg tests
Sa4dUs Jun 24, 2025
a4f6850
Remove `sret` logic
Sa4dUs Jun 29, 2025
cd67bf1
Move logic to a dedicated `enzyme_autodiff` intrinsic
Sa4dUs Jul 7, 2025
0f8facb
Remove attr checking from hir_analysis
Sa4dUs Jul 7, 2025
75f4d3f
FIx generics error when passing fn as param to intrinsic
Sa4dUs Jul 8, 2025
d47e6e1
Use Instance::new_raw instead of Instance::mono
Sa4dUs Jul 8, 2025
ae998a4
Hacky fix for issues at trait calls
Sa4dUs Jul 10, 2025
2b9f347
Fix how fns where being retrieved at intrinsic cg
Sa4dUs Jul 11, 2025
3b6eedc
Use Self instead of Foo placeholder
Sa4dUs Jul 11, 2025
c724fab
Remove unused code
Sa4dUs Jul 12, 2025
61f65f0
Remove primal call and collect it in mono instead
Sa4dUs Jul 14, 2025
52cc23b
Update codegen tests
Sa4dUs Jul 15, 2025
6aaef32
Handle slices when extracting args from tuple
Sa4dUs Jul 22, 2025
f2f116a
Do not depend on mono anymore
Sa4dUs Jul 23, 2025
04f64af
Get args from tuple using fnabi and minor fixes
Sa4dUs Jul 23, 2025
1e09cea
Remove dead code
Sa4dUs Jul 25, 2025
838d115
Reintroduce autodiff enable and lto errors
Sa4dUs Jul 25, 2025
d5437ef
Minor fixes after rebase
Sa4dUs Jul 25, 2025
5ad7521
Add rest of test fixes
Sa4dUs Jul 25, 2025
1d0e8e2
Remove cfg enzyme for ci
Sa4dUs Jul 25, 2025
92f84d3
FIx cg_gcc
Sa4dUs Jul 25, 2025
261d0d8
Macro expansion cleanup
Sa4dUs Jul 27, 2025
d12683c
Remove dead code
Sa4dUs Jul 27, 2025
99e9147
Add `enzyme_autodiff` doc comment
Sa4dUs Jul 28, 2025
56ab39c
Add expansion example to intrinsic docs
Sa4dUs Jul 28, 2025
2b4844f
Better error handling
Sa4dUs Jul 29, 2025
66d2219
Allow `core_intrinsics` when `autodiff` is enabled
Sa4dUs Jul 29, 2025
408f52f
Remove autodiff limitations subsection
Sa4dUs Jul 30, 2025
0bfbef0
Remove inlining for autodiff handling
Sa4dUs Aug 7, 2025
66fe728
Update tests for LLVM 21
Sa4dUs Aug 9, 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
436 changes: 147 additions & 289 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 @@ -93,7 +93,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 @@ -363,12 +362,7 @@ impl WriteBackendMethods for GccCodegenBackend {
_exported_symbols_for_lto: &[String],
each_linked_rlib_for_lto: &[PathBuf],
modules: Vec<FatLtoInput<Self>>,
diff_functions: Vec<AutoDiffItem>,
) -> Result<ModuleCodegen<Self::Module>, FatalError> {
if !diff_functions.is_empty() {
unimplemented!();
}

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

Expand Down
Loading
Loading