Skip to content

Commit 896ef2a

Browse files
committed
Add function like example.
1 parent 863c585 commit 896ef2a

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

Diff for: 5_fn_like/Makefile

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
all: fn_like.o
2+
3+
clean:
4+
rm -f *.o *.ll
5+
6+
%.o: %.c
7+
../dockerscript.sh clang-12 /host/$^ -O3 -Xclang -load -Xclang /Enzyme/enzyme/build/Enzyme/ClangEnzyme-12.so -ffast-math -o /host/$@
8+
9+
run-%: %.o
10+
../dockerscript.sh /host/$^ 3.14

Diff for: 5_fn_like/fn_like.c

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include <stdio.h>
2+
#include <math.h>
3+
#include <assert.h>
4+
5+
6+
double __enzyme_autodiff(void*, ...);
7+
8+
double log1p_like_function(double a) {
9+
return 2*a;
10+
}
11+
12+
double test(double a) {
13+
return log1p_like_function(a);
14+
}
15+
16+
void* __enzyme_function_like[2] = {(void*)log1p_like_function, "log1p"};
17+
18+
int main(int argc, char** argv) {
19+
20+
double grad_out = __enzyme_autodiff(test, 2.0);
21+
printf("Gradient of the log1p like function is %f", grad_out);
22+
23+
return 0;
24+
}

0 commit comments

Comments
 (0)