Enzyme icon indicating copy to clipboard operation
Enzyme copied to clipboard

Enzyme hangs when using CoDiPack forward AD type in function

Open MaxSagebaum opened this issue 1 year ago • 7 comments

This might be related to issue #142.

Enzyme does not finish when applied to the code:

#include <iostream>
#include <codi.hpp>

extern int enzyme_dup;
extern int enzyme_out;
extern int enzyme_const;

template<typename... Args>
void __enzyme_autodiff(void*, Args...);

using Inner = codi::RealForward;
//using Inner = double;


//using Data = int;
using Data = codi::ExternalFunctionUserData;

void func2_prim(Inner const* x, size_t m, Inner* y, size_t n, Data* d) {
  y[0] = 42.0 * x[0] * x[0];
}

void test() {
  Inner tx[1] = {1.0};
  Inner tx_b[1] = {0.0};
  Inner ty[1] = {0.0};
  Inner ty_b[1] = {0.0};
  __enzyme_autodiff(
            (void*) func2_prim ,
            enzyme_dup, &tx, tx_b,
            enzyme_const, (size_t)1,
            enzyme_dup, ty, ty_b,
            enzyme_const, (size_t)1,
            enzyme_const, (Data*)NULL);

}

It works when using the double type. I tried to reproduce this with a simple forward type implementation but this did not trigger the bug.

Clang: clang version 14.0.0 Enzyme: 61332add5 v0.0.71

The output of the crash report: out.txt.zip Full cpp file: e2-33883a.cpp.txt Command line: e2-33883a.sh.txt

MaxSagebaum avatar Jun 28 '23 07:06 MaxSagebaum

Hi, thanks for the report. For your linked issue, 2 years old feels a bit outdated, so it might be worth checking if that one still fails? I do remember that I had one eigen bug that got solved in the meantime.

Also, can you please print the Enzyme Type Analysis? We just discussed yesterday that we should really rewrite that part, I guess it could be the reason here? You can get more output using https://enzyme.mit.edu/getting_started/UsingEnzyme/#enzyme-print-type

(I am on my phone, so I can't check your txt files rn, maybe I missed something there)

ZuseZ4 avatar Jun 28 '23 08:06 ZuseZ4

Hi,

took me a little longer. I ran the same command with the additional arguments -XClang -enzyme-print-type. I also created a version where I used c++filt. Hope this helps.

out.txt.zip out_filt.txt.zip

MaxSagebaum avatar Jun 28 '23 16:06 MaxSagebaum

Related issue still fails to this day

tgymnich avatar Jun 28 '23 18:06 tgymnich

@MaxSagebaum Sorry, completely forgot to check the zip once I was back at my laptop. @wsmoses check the _Rb_tree_node_base, that's probably a case which would be solved by handling recursions nicely, right?

Either way, now that the whole zip finished loading, it looks like it doesn't get stuck, but rather crashes, right?

; Function Attrs: nounwind
declare dso_local void @_ZNSt8__detail15_List_node_base7_M_hookEPS0_(%"struct.std::__detail::_List_node_base"* noundef nonnull align 8 dereferenceable(16), %"struct.std::__detail::_List_node_base"* noundef) #2

clang++: /home/msagebaum/Kaiserslautern/Programms/Enzyme/enzyme/Enzyme/EnzymeLogic.cpp:2101: const AugmentedReturn &EnzymeLogic::CreateAugmentedPrimal(llvm::Function *, DIFFE_TYPE, ArrayRef<DIFFE_TYPE>, TypeAnalysis &, bool, bool, const FnTypeInfo &, const std::map<Argument *, bool>, bool, unsigned int, bool, bool): Assertion `0 && "attempting to differentiate function without definition"' failed.

we should add support for std::__detail::_List_node_base::_M_hook(std::__detail::_List_node_base*)

ZuseZ4 avatar Jul 06 '23 06:07 ZuseZ4

Any updates on the issue?

MaxSagebaum avatar Sep 20 '23 13:09 MaxSagebaum

Given that we miss one of the list functions that you use, there is a good chance that we might miss another list related function or two. Could you please re-run it and post the log after rebuilding Enzyme? This commit should show you not only the next unsupported function, but all unsupported functions, so we know how much is missing and can eventually add support for them together. https://github.com/EnzymeAD/Enzyme/pull/1451

ZuseZ4 avatar Sep 21 '23 07:09 ZuseZ4

I checked out the newest version of Enzyme and performed the output again. Here are the newest results.

out.txt.zip

On a side note: I had problems getting the command to run. My final command line was:

$LLVM_DIR/bin/opt input.ll -load=$ENZYME_DIR/lib/LLVMEnzyme-14.so -load-pass-plugin=$ENZYME_DIR/lib/LLVMEnzyme-14.so --passes=enzyme -enzyme-print-type -o output.ll -S

In https://enzyme.mit.edu/getting_started/Faq/ the argument -load-pass-plugin=$ENZYME_DIR/lib/LLVMEnzyme-14.so is missing. Otherwise I still got that the enzyme pass was missing.

MaxSagebaum avatar Sep 26 '23 14:09 MaxSagebaum