EnzymeAD / rust

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

Failing sin(*x) testcase #72

Closed ZuseZ4 closed 4 months ago

ZuseZ4 commented 5 months ago

Here is the extra debug info:

      30 [compiler/rustc_codegen_llvm/src/llvm/ffi.rs:942:5] &fnc = (ptr:; Function Attrs: mustprogress nofree noinline nosync nounwind nonlazybind sanitize_hwaddress willreturn          memory(argmem: read) uwtable 
      29 define internal noundef double @_ZN2ad3foo17h901f7b61e40dfe72E(ptr noalias nocapture noundef readonly align 8 dereferenceable(8) %0) unnamed_addr #5 {
      28   %2 = load double, ptr %0, align 8, !noundef !6
      27   %3 = tail call double @llvm.sin.f64(double %2)    
      26   ret double %3
      25 }
      24 )
      23 num_fnc_args: 1
      22 input_activity.len(): 1
      21 analyzing function preprocess__ZN2ad3foo17h901f7b61e40dfe72E
      20  + knowndata: ptr %0 : {[-1]:Pointer, [-1,-1]:Float@double} - {}
      19  + retdata: {[-1]:Float@double}
      18 updating analysis of val: ptr %0 current: {} new {[-1]:Pointer, [-1,-1]:Float@double} from ptr %0 Changed=1 legal=1
      17 updating analysis of val: ptr %0 current: {[-1]:Pointer, [-1,-1]:Float@double} new {[-1]:Pointer, [-1,-1]:Float@double} from ptr %0 Changed=0 legal=1
      16 updating analysis of val:   %3 = tail call double @llvm.sin.f64(double %2) #112 current: {} new {[-1]:Float@double} from   %3 = tail call double @llvm.sin.f64(double %2)          #112 Changed=1 legal=1                 
      15 updating analysis of val:   %3 = tail call double @llvm.sin.f64(double %2) #112 current: {[-1]:Float@double} new {[-1]:Float@double} from   %3 = tail call double @llvm.s         in.f64(double %2) #112 Changed=0 legal=1
      14 updating analysis of val: ptr %0 current: {[-1]:Pointer, [-1,-1]:Float@double} new {[-1]:Pointer} from   %2 = load double, ptr %0, align 8, !noundef !6 Changed=0 legal=1
      13 updating analysis of val:   %2 = load double, ptr %0, align 8, !noundef !6 current: {} new {[-1]:Float@double} from   %2 = load double, ptr %0, align 8, !noundef !6 Chan         ged=1 legal=1
      12 updating analysis of val:   %3 = tail call double @llvm.sin.f64(double %2) #112 current: {[-1]:Float@double} new {[-1]:Float@double} from   %3 = tail call double @llvm.s         in.f64(double %2) #112 Changed=0 legal=1
      11 updating analysis of val:   %2 = load double, ptr %0, align 8, !noundef !6 current: {[-1]:Float@double} new {[-1]:Float@double} from   %3 = tail call double @llvm.sin.f6         4(double %2) #112 Changed=0 legal=1

And here is the error message:

      21 fn:; Function Attrs: mustprogress nofree noinline nosync nounwind nonlazybind sanitize_hwaddress willreturn memory(argmem: readwrite) uwtable
      20 define internal noundef { double, double } @diffe_ZN2ad3foo17h901f7b61e40dfe72E(ptr noalias nocapture noundef readonly align 8 dereferenceable(8) %0, ptr nocapture align          8 %1) unnamed_addr #111 {
      19   %3 = alloca double, align 8
      18   %4 = alloca double, align 8
      17   %5 = load double, ptr %0, align 8, !noundef !6
      16   %6 = tail call double @llvm.sin.f64(double %5) #112
      15   store double %6, ptr %4, align 8
      14   ret double %6
      13 
      12 7:                                                ; No predecessors!
      11 
      10 8:                                                ; No predecessors!
       9 }
       8 
       7 oval=  %3 = tail call double @llvm.sin.f64(double %2) #112 icv=0
       6 available inversion for ptr %0 of ptr %1
       5 rustc: /h/344/drehwald/prog/rust/src/tools/enzyme/enzyme/Enzyme/GradientUtils.cpp:6147: llvm::Value* GradientUtils::invertPointerM(llvm::Value*, llvm::IRBuilder<>&, bool         ): Assertion `0 && "cannot find deal with ptr that isnt arg"' failed.

Not reproducible on CE.

ZuseZ4 commented 5 months ago

Here is a c example that compiles, but I don't know how to adjust it to replicate the Rust settings (ie both returns). https://fwd.gymni.ch/Qoq8jh

wsmoses commented 4 months ago

This is an invalid use of the API, presumably this is caused by a request for the derivative return pointer, which doesn't exist here since you return a scalar

ZuseZ4 commented 4 months ago

True, fixed a while ago. Creating a new issue.