$LLVM_DIR/bin/clang++ test.cpp -S -emit-llvm -o input.ll -g -O2 -fno-vectorize -fno-slp-vectorize -fno-unroll-loops
$LLVM_DIR/bin/opt input.ll -load=$ENZYME_DIR/lib/LLVMEnzyme-14.so -enable-new-pm=0 -enzyme -o output.ll -S
$LLVM_DIR/bin/clang output.ll -O1 -g -o a1.exe
$LLVM_DIR/bin/clang output.ll -O2 -g -o a2.exe
wmoses@beast:~/git/Enzyme/enzyme/buildomp (context) $ valgrind ./a2.exe
==109987== Memcheck, a memory error detector
==109987== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==109987== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
==109987== Command: ./a2.exe
==109987==
--109987-- WARNING: Serious error when reading debug info
--109987-- When reading debug info from /mnt/pci4/wmdata/Enzyme/enzyme/buildomp/a2.exe:
--109987-- Ignoring non-Dwarf2/3/4 block in .debug_info
--109987-- WARNING: Serious error when reading debug info
--109987-- When reading debug info from /mnt/pci4/wmdata/Enzyme/enzyme/buildomp/a2.exe:
--109987-- parse_CU_Header: is neither DWARF2 nor DWARF3 nor DWARF4
==109987==
==109987== HEAP SUMMARY:
==109987== in use at exit: 0 bytes in 0 blocks
==109987== total heap usage: 0 allocs, 0 frees, 0 bytes allocated
==109987==
==109987== All heap blocks were freed -- no leaks are possible
==109987==
==109987== For counts of detected and suppressed errors, rerun with: -v
==109987== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
// test.c
#include <stdio.h>
int enzyme_dup;
int enzyme_out;
int enzyme_const;
template<typename... Args>
void __enzyme_autodiff(void*, Args...);
void square(double const* x, double* y, int size) {
for(int i = 0; i < size; i += 1) {
y[i] = x[i] * x[i];
}
}
void dsquare(double const* x, double* x_b, double* y, double const* y_b, int size) {
// This returns the derivative of square or 2 * x
return __enzyme_autodiff((void*) square,
enzyme_dup, x, x_b,
enzyme_dup, y, y_b,
enzyme_const, size);
}
int main() {
int const n = 5;
double x[n];
double x_b[n];
double y[n];
double y_b[n];
for(int i=0; i<5; i++) {
x[i] = i + 1;
y_b[i] = 1.0;
}
dsquare(x, x_b, y, y_b, n);
for(int i=0; i<5; i++) {
printf("t2 square(%f)=%f, dsquare(%f)=%f\n", x[i], y[i], x[i], x_b[i]);
}
}