Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 4 additions & 4 deletions compiler/rustc_builtin_macros/src/autodiff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ mod llvm_enzyme {
// first get information about the annotable item: visibility, signature, name and generic
// parameters.
// these will be used to generate the differentiated version of the function
let Some((vis, sig, primal, generics, impl_of_trait)) = (match &item {
let Some((vis, sig, primal, generics, is_impl)) = (match &item {
Annotatable::Item(iitem) => {
extract_item_info(iitem).map(|(v, s, p, g)| (v, s, p, g, false))
}
Expand All @@ -224,13 +224,13 @@ mod llvm_enzyme {
}
_ => None,
},
Annotatable::AssocItem(assoc_item, Impl { of_trait }) => match &assoc_item.kind {
Annotatable::AssocItem(assoc_item, Impl { of_trait: _ }) => match &assoc_item.kind {
ast::AssocItemKind::Fn(box ast::Fn { sig, ident, generics, .. }) => Some((
assoc_item.vis.clone(),
sig.clone(),
ident.clone(),
generics.clone(),
*of_trait,
true,
)),
_ => None,
},
Expand Down Expand Up @@ -328,7 +328,7 @@ mod llvm_enzyme {
span,
&d_sig,
&generics,
impl_of_trait,
is_impl,
)],
);

Expand Down
36 changes: 36 additions & 0 deletions tests/codegen-llvm/autodiff/impl.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//@ compile-flags: -Zautodiff=Enable -Zautodiff=NoPostopt -C opt-level=3 -Clto=fat
//@ no-prefer-dynamic
//@ needs-enzyme

// Just check it does not crash for now
// CHECK: ;
#![feature(autodiff)]

use std::autodiff::autodiff_reverse;

#[derive(Clone)]
struct OptProblem {
a: f64,
b: f64,
}

impl OptProblem {
#[autodiff_reverse(d_objective, Duplicated, Duplicated, Duplicated)]
fn objective(&self, x: &[f64], out: &mut f64) {
*out = self.a + x[0].sqrt() * self.b
}
}

fn main() {
let p = OptProblem { a: 1., b: 2. };
let x = [2.0];

let mut p_shadow = OptProblem { a: 0., b: 0. };
let mut dx = [0.0];
let mut out = 0.0;
let mut dout = 1.0;

p.d_objective(&mut p_shadow, &x, &mut dx, &mut out, &mut dout);

dbg!(dx);
}
Loading