Open sitbackrelax opened 1 month ago
Works in Enzyme Explorer: https://fwd.gymni.ch/JTva2a
That indeed works, thank you!
However, if I try to pass an integer as the dimension of a std::vector
double g2(double x, int n) {
std::vectorv
.
return dprod(v);
}
I tried to compute the dg2/dx as follows, double x = 3; int n = 5; double dg2_dx = __enzyme_autodiff((void*)g2, enzyme_out, x, enzyme_const, n);
clang18 with "-O3 --std=c++20" works, but clang20 with "-O3 --std=c++20" fails with the following compilation error, any idea?
unknown tbaa call instruction user inst: %call.i = tail call noundef double @pow(double noundef %x, double noundef %conv.i) #12, !dbg !2031, !tbaa !2032 vdptr: {[]:Pointer, [-1]:Integer}
unknown tbaa call instruction user inst: %call.i = tail call noundef double @pow(double noundef %x, double noundef %conv.i) #13, !dbg !2030, !tbaa !2031 vdptr: {[]:Pointer, [-1]:Integer}
clang++: /root/llvm-project/llvm/lib/IR/Instruction.cpp:153: void llvm::Instruction::insertBefore(llvm::BasicBlock&, llvm::iplist_impl<llvm::simple_ilist<llvm::Instruction, llvm::ilist_iterator_bits
Start to try Enzyme in Enzyme explorer. I found it does not compile when a runtime size container is involved, e.g. std::vector, as in the following example,
double dprod(const std::vector& v) {
double r = 1;
for (int i = 0; i < v.size(); i++) {
r *= v[i];
}
return r;
}
double g(double x) { std::vector v;
v.push_back(x);
v.push_back(x*x);
return dprod(v);
}
int main() { double x = 3; double d_x = __enzyme_autodiff((void*)g, enzyme_out, x);
printf("d_x = %g\n", d_x);
}
This is critical for us, because we need to use Eigen::MatrixXd and Eigen::VectorXd with their sizes determined at runtime. Their elements are functions of some physical design variables.
Thanks for your help!