|  | 
|  | 1 | +//@ revisions: DEBUG RELEASE | 
|  | 2 | +//@[RELEASE] compile-flags: -Zautodiff=Enable,NoTT -C opt-level=3 -Clto=fat | 
|  | 3 | +//@[DEBUG]   compile-flags: -Zautodiff=Enable,NoTT -C opt-level=0 -Clto=fat -C debuginfo=2 | 
|  | 4 | +//@ needs-enzyme | 
|  | 5 | +//@ incremental | 
|  | 6 | +//@ no-prefer-dynamic | 
|  | 7 | +//@ build-pass | 
|  | 8 | +#![crate_type = "bin"] | 
|  | 9 | +#![feature(autodiff)] | 
|  | 10 | + | 
|  | 11 | +// We used to use llvm's metadata to instruct enzyme how to differentiate a function. | 
|  | 12 | +// In debug mode we would use incremental compilation which caused the metadata to be | 
|  | 13 | +// dropped. We now use globals instead and add this test to verify that incremental | 
|  | 14 | +// keeps working. Also testing debug mode while at it. | 
|  | 15 | + | 
|  | 16 | +use std::autodiff::autodiff_reverse; | 
|  | 17 | + | 
|  | 18 | +#[autodiff_reverse(bar, Duplicated, Duplicated)] | 
|  | 19 | +pub fn foo(r: &[f64; 10], res: &mut f64) { | 
|  | 20 | +    let mut output = [0.0; 10]; | 
|  | 21 | +    output[0] = r[0]; | 
|  | 22 | +    output[1] = r[1] * r[2]; | 
|  | 23 | +    output[2] = r[4] * r[5]; | 
|  | 24 | +    output[3] = r[2] * r[6]; | 
|  | 25 | +    output[4] = r[1] * r[7]; | 
|  | 26 | +    output[5] = r[2] * r[8]; | 
|  | 27 | +    output[6] = r[1] * r[9]; | 
|  | 28 | +    output[7] = r[5] * r[6]; | 
|  | 29 | +    output[8] = r[5] * r[7]; | 
|  | 30 | +    output[9] = r[4] * r[8]; | 
|  | 31 | +    *res = output.iter().sum(); | 
|  | 32 | +} | 
|  | 33 | +fn main() { | 
|  | 34 | +    let inputs = Box::new([3.1; 10]); | 
|  | 35 | +    let mut d_inputs = Box::new([0.0; 10]); | 
|  | 36 | +    let mut res = Box::new(0.0); | 
|  | 37 | +    let mut d_res = Box::new(1.0); | 
|  | 38 | + | 
|  | 39 | +    bar(&inputs, &mut d_inputs, &mut res, &mut d_res); | 
|  | 40 | +    dbg!(&d_inputs); | 
|  | 41 | +} | 
0 commit comments