EnzymeAD / rust

A rust fork to work towards Enzyme integration
https://www.rust-lang.org
Other
67 stars 9 forks source link

parallel global access #66

Closed ZuseZ4 closed 6 months ago

ZuseZ4 commented 10 months ago

We don't support globals on the rust side yet, but maybe the support is also something we could improve on the Enzyme core side. Credits to Ralf Jung for the alternative approach, bugs in the example are my own production ^^


#[autodiff_shadow(dx)]
global x: f32 = 2.0;
global dx: f32 = 0.0;

#[autodiff(...)]
fn foo (y: f32) -> f32 {
   return x * y
}

fn main() {
  for i in someArr.par_iter() {
    let dy = dfoo(i);
    ...
  }
  // will we get the right result?
  println!("{dx}");
}

Since we already modify function types, can't we instead require shadows of globals to be passed as extra input to dfoo? WIP

ZuseZ4 commented 6 months ago

Following a discussion with Ralf and others we (for now) intentionally don't support Globals since they are discouraged and even without AD cause safety concerns, more in the context of AD. Probably not worth as a tradeoff.