Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP herbie #1860

Draft
wants to merge 223 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
Show all changes
223 commits
Select commit Hold shift + click to select a range
f2400db
WIP herbie
wsmoses May 6, 2024
e2fd7b2
build commands
sbrantq May 10, 2024
4dc7fdb
add stuff
sbrantq May 10, 2024
cfcdfe4
append newline
sbrantq May 10, 2024
5cb6b65
fix include
sbrantq May 10, 2024
0b6bb14
improve
sbrantq May 10, 2024
36c8a7e
get standalone binary
sbrantq May 10, 2024
b0cc1f3
fix arg
sbrantq May 10, 2024
8acb959
fix macro
sbrantq May 13, 2024
b5e3c9f
cleanup
sbrantq May 15, 2024
2ff561c
complete boilerplate
sbrantq May 15, 2024
13060e5
use herbie improve instead
sbrantq May 16, 2024
3326cf3
saving progress
sbrantq May 16, 2024
b8a8201
saving progress
sbrantq May 28, 2024
becf55e
fix regex
sbrantq May 28, 2024
b74c899
saving progress
sbrantq May 30, 2024
15528af
improve
sbrantq May 30, 2024
20c5464
disable lit parallelism
sbrantq May 30, 2024
4b800fc
add tests
sbrantq May 30, 2024
17de042
handle constants
sbrantq May 31, 2024
8e98bb3
more test & fast math flags
sbrantq May 31, 2024
4f4106e
cleanup
sbrantq May 31, 2024
c7ad4b3
add working generalized code
sbrantq Jun 6, 2024
6c25238
cleanup
sbrantq Jun 6, 2024
16df413
improve
sbrantq Jun 6, 2024
5de75d8
improve type casting
sbrantq Jun 6, 2024
0b431e4
add call instruction support
sbrantq Jun 8, 2024
c4a3b53
version check for tan
sbrantq Jun 8, 2024
add02ff
fix herbie seed
sbrantq Jun 8, 2024
beef25a
memory management
sbrantq Jun 9, 2024
6d8e9c1
std::vector --> SmallVector
sbrantq Jun 9, 2024
215c766
cleanup with O3 pass?
sbrantq Jun 12, 2024
48e0dcf
sign
sbrantq Jun 12, 2024
c072ac5
add simple phi node test
sbrantq Jun 12, 2024
3763219
unique file names for parallel tests
sbrantq Jun 12, 2024
7efa80d
adjust O3 flag
sbrantq Jun 13, 2024
69eb6d3
saving progress
sbrantq Jun 14, 2024
da12b38
better cleanup
sbrantq Jun 17, 2024
f6dfe4f
merge stuff from main
sbrantq Jun 18, 2024
3272642
demangle log func
sbrantq Jun 18, 2024
dce1297
pass operands to the logger
sbrantq Jun 19, 2024
9f5ed15
improve logging
sbrantq Jun 20, 2024
3aac534
add more complex logger
sbrantq Jun 20, 2024
0fa0343
improve
sbrantq Jun 20, 2024
f3f966d
set debug loc for logger call
sbrantq Jun 20, 2024
5bced48
move logger to separate file
sbrantq Jun 23, 2024
848fd56
improve
sbrantq Jun 23, 2024
d39c34c
fix constants
sbrantq Jun 24, 2024
421c6e4
if expr from Herbie
sbrantq Jun 24, 2024
254175b
herbie properties
sbrantq Jun 24, 2024
f2b156e
improve
sbrantq Jun 24, 2024
dc65ec7
macro
sbrantq Jun 24, 2024
03dc9b8
bool flag for err msg
sbrantq Jun 25, 2024
6bc269a
improve
sbrantq Jun 25, 2024
a21348b
manual arg eval & inf handling
sbrantq Jun 25, 2024
0a2ccbc
cbrt
sbrantq Jun 26, 2024
60d946d
large Herbie constant handling
sbrantq Jun 26, 2024
ca87346
simplify
sbrantq Jun 26, 2024
4259b00
WIP preconditions
sbrantq Jun 26, 2024
cd27b90
fwddiffe -> fwderr
sbrantq Jun 27, 2024
7ec2346
add mode selection
sbrantq Jul 1, 2024
ea59ad1
preprocess orig metadata
sbrantq Jul 1, 2024
8c520e7
neg
sbrantq Jul 1, 2024
11bac95
register fpopt
sbrantq Jul 2, 2024
2af3c11
only preprocess origin metadata to fp inst
sbrantq Jul 2, 2024
6f457fd
ifdef ENZYME_ENABLE_HERBIE
sbrantq Jul 2, 2024
4336ed0
denormals
sbrantq Jul 3, 2024
ecf1aa1
logged bounds for fpconst
sbrantq Jul 3, 2024
32dbbd5
fix bounds parsing
sbrantq Jul 4, 2024
0d005db
preconditions
sbrantq Jul 4, 2024
77f8887
skip declarations
sbrantq Jul 4, 2024
66a7ae3
simplify printed info
sbrantq Jul 4, 2024
7156848
post opt erasure check
sbrantq Jul 4, 2024
1c29d2c
update fpopt tests to include debug flags
sbrantq Jul 4, 2024
294c2a2
print
sbrantq Jul 5, 2024
4b8e17a
add labels to herbie-generated stuff
sbrantq Jul 5, 2024
a7e134c
more tests
sbrantq Jul 6, 2024
9802904
fmuladd
sbrantq Jul 6, 2024
cc53c46
fix test
sbrantq Jul 6, 2024
a5a450c
hypot
sbrantq Jul 6, 2024
0aab938
fix bounds parsing
sbrantq Jul 6, 2024
19443d8
more tests
sbrantq Jul 6, 2024
0cb80da
expm1 + log1p + precond fix
sbrantq Jul 6, 2024
3c16766
fix test
sbrantq Jul 7, 2024
f507934
make cbrt herbiable
sbrantq Jul 7, 2024
1c7cf06
WIP llvm instruction cost model
sbrantq Jul 7, 2024
01d4f8d
subexpr cost estimate
sbrantq Jul 8, 2024
2b14f05
improve
sbrantq Jul 8, 2024
7a4be5e
WIP solver
sbrantq Jul 8, 2024
39973f0
fix
sbrantq Jul 8, 2024
d272fd0
saving progress
sbrantq Jul 11, 2024
1e06089
more herbie knobs
sbrantq Jul 12, 2024
29438c3
reverse mode logging
sbrantq Jul 15, 2024
8e0a0bb
cleanup
sbrantq Jul 16, 2024
23f2a7c
only log grad
sbrantq Jul 16, 2024
0b51aa0
fix test
sbrantq Jul 16, 2024
7544cb2
multiple expr handling
sbrantq Jul 18, 2024
3d015f1
grad log parsing + improvements
sbrantq Jul 19, 2024
69e7bbf
improve
sbrantq Jul 19, 2024
cf89257
Merge branch 'main' of https://github.com/EnzymeAD/Enzyme into herbie
sbrantq Jul 21, 2024
b54886f
improve herbie's build cmd
sbrantq Jul 21, 2024
e9bdadf
TTI costs
sbrantq Jul 23, 2024
9df9349
saving solvers
sbrantq Jul 23, 2024
a2afd2d
fix alternatives
sbrantq Jul 23, 2024
138d8fa
Merge branch 'main' of https://github.com/EnzymeAD/Enzyme into herbie
sbrantq Jul 25, 2024
42ed544
fix dp solver
sbrantq Jul 28, 2024
b16bbcf
update herbie hash
sbrantq Jul 28, 2024
32949f0
update tests
sbrantq Jul 28, 2024
7fc69b9
constantexpr
sbrantq Jul 28, 2024
00259d4
get log func
sbrantq Jul 29, 2024
7fe0519
improve
sbrantq Jul 29, 2024
304a162
separating out value logging
sbrantq Jul 30, 2024
bfa4c61
add unified logger
sbrantq Jul 30, 2024
09bd80f
differential usage for reverse mode value logging
sbrantq Jul 30, 2024
ee85f63
log value before constant inst check
sbrantq Jul 30, 2024
4c1cf63
unified logger
sbrantq Jul 31, 2024
ae4ef9a
solver selection
sbrantq Aug 1, 2024
a18b006
log parsing bug fix
sbrantq Aug 1, 2024
ba4bf0a
log parsing bug fix
sbrantq Aug 1, 2024
9056ed1
WIP typing
sbrantq Aug 2, 2024
9b3a08d
fix f32
sbrantq Aug 3, 2024
afff45f
minor fixes
sbrantq Aug 3, 2024
5e6cff4
use libm func instead
sbrantq Aug 4, 2024
3592826
minor improvements and make fabs non-herbiable
sbrantq Aug 6, 2024
0e7bd4f
fpcc splitting algorithm
sbrantq Aug 6, 2024
748d08a
saving
sbrantq Aug 6, 2024
a577bcb
Merge branch 'main' of https://github.com/EnzymeAD/Enzyme into herbie
sbrantq Aug 16, 2024
9f81169
Merge branch 'main' of https://github.com/EnzymeAD/Enzyme into herbie
sbrantq Aug 25, 2024
cd79402
fix include
sbrantq Aug 25, 2024
7006efb
fix
sbrantq Aug 28, 2024
ddb9307
regex target func spec
sbrantq Aug 30, 2024
3413835
Merge branch 'main' of https://github.com/EnzymeAD/Enzyme into herbie
sbrantq Aug 31, 2024
ffb255d
fix
sbrantq Aug 31, 2024
5c123ed
improve
sbrantq Aug 31, 2024
1d0c686
cleanup
sbrantq Sep 3, 2024
2f876a4
fix tests
sbrantq Sep 3, 2024
8ebd39e
improve
sbrantq Sep 3, 2024
f42e7e8
FP subgraph precision changing
sbrantq Sep 7, 2024
0213868
comments
sbrantq Sep 7, 2024
7dc2be9
improve
sbrantq Sep 8, 2024
1b0a985
rename FPNode::getValue & WIP unified accuracy
sbrantq Sep 8, 2024
64afdbb
RTTI
sbrantq Sep 9, 2024
931f723
improve
sbrantq Sep 15, 2024
0e51d51
shared ptr & WIP golden values
sbrantq Sep 16, 2024
8fe7098
improve
sbrantq Sep 16, 2024
9480b7c
accuracy cost estimator for herbie rewrites
sbrantq Sep 17, 2024
4a80236
random engine
sbrantq Sep 20, 2024
4fa39d1
fix dp solver
sbrantq Sep 20, 2024
bb5b917
guaranteed erasable cost in expressions
sbrantq Sep 20, 2024
4a2f996
fix
sbrantq Sep 20, 2024
59da2ab
WIP PT candidate generation
sbrantq Sep 21, 2024
845f74a
generalize
sbrantq Sep 22, 2024
026e334
use AST nodes in precision tuning
sbrantq Sep 22, 2024
b9b3194
generalized mpfr evaluator
sbrantq Sep 23, 2024
bacca3b
unified accuracy cost done
sbrantq Sep 23, 2024
4a5a621
improve
sbrantq Sep 23, 2024
e7a65fe
fixed accuracy cost for fpcc
sbrantq Sep 23, 2024
ef23ce8
save
sbrantq Sep 29, 2024
df3087a
fix up
sbrantq Sep 29, 2024
498ce49
renaming
sbrantq Sep 29, 2024
d97de6c
custom cost model parsing & disable FP16 for now
sbrantq Sep 29, 2024
0621807
save
sbrantq Sep 30, 2024
834d7c3
generalized dp solver
sbrantq Sep 30, 2024
066ec46
fix up
sbrantq Sep 30, 2024
98d425a
bug fix & ruling out NaNs in acc cost estimation
sbrantq Oct 1, 2024
5371a97
more precisions & fmuladd --> fma
sbrantq Oct 3, 2024
f7ef6d2
cleanup after PT
sbrantq Oct 3, 2024
ec7a55b
costom cost model opcode suffix for fpcasts
sbrantq Oct 3, 2024
4e2fbb4
fix erasable inst check
sbrantq Oct 3, 2024
6953b7a
save
sbrantq Oct 4, 2024
84ab293
Explicit topo sort
sbrantq Oct 4, 2024
829185a
adjusted cost estimation & accuracy estimation bug fix
sbrantq Oct 5, 2024
33cd1b0
Only enable float double conversions
sbrantq Oct 5, 2024
d6dd10d
early pruning flag
sbrantq Oct 6, 2024
aa52ecd
ADAPT-style sensitivity estimation
sbrantq Oct 7, 2024
74dbaff
always fpcast operands first in MPFR evaluator
sbrantq Oct 9, 2024
0ebc1d8
AO/ACC sampled points consistency fix
sbrantq Oct 9, 2024
2c859a4
ponder fast math flags
sbrantq Oct 10, 2024
8309529
bug fix
sbrantq Oct 15, 2024
af67a08
complete PT & improve
sbrantq Oct 16, 2024
7488586
caching for adjusted ACC costs
sbrantq Oct 16, 2024
77992eb
improve
sbrantq Oct 17, 2024
859a954
fix
sbrantq Oct 17, 2024
a9b615e
more PT candidates
sbrantq Oct 29, 2024
653cf32
better temp expr materialization & cost estimation
sbrantq Oct 29, 2024
a558385
solution dominance thresholds
sbrantq Oct 30, 2024
274366c
save
sbrantq Oct 31, 2024
f4965a4
native fp emulator
sbrantq Oct 31, 2024
e381dd2
more options
sbrantq Oct 31, 2024
90cb151
save
sbrantq Nov 2, 2024
f38c611
save
sbrantq Nov 3, 2024
27ed106
print ranges only
sbrantq Nov 3, 2024
e433e5d
fix up
sbrantq Nov 4, 2024
08c4db8
bug fix
sbrantq Nov 4, 2024
46f7d11
improve
sbrantq Nov 4, 2024
67b5944
bug fix
sbrantq Nov 5, 2024
033bbcf
fix
sbrantq Nov 7, 2024
845cbf5
bug fix
sbrantq Nov 7, 2024
60a6ddd
remove duplicated expr
sbrantq Nov 8, 2024
fe0b354
accuracy cost evaluation: arithmetic avg --> geometric avg
sbrantq Nov 8, 2024
da75044
add some progress indication
sbrantq Nov 8, 2024
bb020b4
fix up
sbrantq Nov 8, 2024
6631026
fix up
sbrantq Nov 8, 2024
c67f13d
parallel herbie
sbrantq Nov 8, 2024
91456e2
disable herbie parallelism by default
sbrantq Nov 8, 2024
bd013be
fix up
sbrantq Nov 8, 2024
f4f7335
fix up
sbrantq Nov 8, 2024
50abba3
fix up
sbrantq Nov 8, 2024
003de29
dp solver fix up
sbrantq Nov 8, 2024
1b65a8c
improve
sbrantq Nov 9, 2024
b49de51
save
sbrantq Nov 9, 2024
0e7a6d7
experimental herbie output caching
sbrantq Nov 10, 2024
52950d5
bug fix
sbrantq Nov 10, 2024
5f39b98
FPEvaluator: add hypot
sbrantq Nov 11, 2024
53a57a7
Merge branch 'main' of https://github.com/EnzymeAD/Enzyme into herbie
sbrantq Nov 11, 2024
7eb617e
just skip unexecuted code
sbrantq Nov 11, 2024
7145c49
adapted to poseidon
sbrantq Nov 12, 2024
e39bee8
enzyme_active
sbrantq Nov 12, 2024
5b94be0
bug fix
sbrantq Nov 12, 2024
a8dede8
prune on boundaries
sbrantq Nov 13, 2024
dffbd51
dp table caching
sbrantq Nov 26, 2024
1d88952
range widening
sbrantq Nov 26, 2024
882cd35
fix up
sbrantq Dec 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
differential usage for reverse mode value logging
  • Loading branch information
sbrantq committed Jul 30, 2024
commit 09bd80f0a39a80bd357566073ddaabfbc2016b76
3 changes: 2 additions & 1 deletion enzyme/Enzyme/DifferentialUseAnalysis.h
Original file line number Diff line number Diff line change
@@ -123,7 +123,8 @@ inline bool is_value_needed_in_reverse(
}
}
}
if (gutils->mode == DerivativeMode::ForwardModeError &&
if ((getLogFunction(gutils->oldFunc->getParent(), "enzymeLogValue") ||
gutils->mode == DerivativeMode::ForwardModeError) &&
!gutils->isConstantValue(const_cast<Value *>(inst))) {
if (EnzymePrintDiffUse)
llvm::errs()
41 changes: 41 additions & 0 deletions enzyme/test/Enzyme/ReverseMode/addLog.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
; RUN: if [ %llvmver -lt 16 ]; then %opt < %s %loadEnzyme -enzyme -enzyme-preopt=false -mem2reg -instsimplify -simplifycfg -S | FileCheck %s; fi
; RUN: %opt < %s %newLoadEnzyme -passes="enzyme,function(mem2reg,instsimplify,%simplifycfg)" -enzyme-preopt=false -S | FileCheck %s

; Function Attrs: noinline nounwind readnone uwtable
define double @tester(double %x, double %y) {
entry:
%0 = fadd fast double %x, %y
ret double %0
}

define double @test_derivative(double %x, double %y) {
entry:
%0 = tail call double (double (double, double)*, ...) @__enzyme_autodiff(double (double, double)* nonnull @tester, double %x, double %y)
ret double %0
}

; Function Attrs: nounwind
declare double @__enzyme_autodiff(double (double, double)*, ...)

; Function Attrs: mustprogress noinline optnone ssp uwtable
declare void @enzymeLogValue(i8* noundef %id, double noundef %res, i32 noundef %numOperands, double* noundef %operands)

; Function Attrs: mustprogress noinline optnone ssp uwtable
declare void @enzymeLogGrad(i8* noundef %id, double noundef %grad)


; CHECK: define internal {{(dso_local )?}}{ double, double } @diffetester(double %x, double %y, double %[[differet:.+]])
; CHECK-NEXT: entry:
; CHECK-NEXT: %[[i0:.+]] = alloca [2 x double], align 8
; CHECK-NEXT: %[[i1:.+]] = fadd fast double %x, %y
; CHECK-NEXT: %[[i2:.+]] = getelementptr [2 x double], [2 x double]* %[[i0]], i32 0, i32 0
; CHECK-NEXT: store double %x, double* %[[i2]], align 8
; CHECK-NEXT: %[[i3:.+]] = getelementptr [2 x double], [2 x double]* %[[i0]], i32 0, i32 1
; CHECK-NEXT: store double %y, double* %[[i3]], align 8
; CHECK-NEXT: %[[i4:.+]] = getelementptr [2 x double], [2 x double]* %[[i0]], i32 0, i32 0
; CHECK-NEXT: call void @enzymeLogValue(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @0, i32 0, i32 0), double %[[i1]], i32 2, double* %[[i4]])
; CHECK-NEXT: call void @enzymeLogGrad(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @1, i32 0, i32 0), double %[[differet]])
; CHECK-NEXT: %[[i5:.+]] = insertvalue { double, double } undef, double %[[differet]], 0
; CHECK-NEXT: %[[i6:.+]] = insertvalue { double, double } %[[i5]], double %[[differet]], 1
; CHECK-NEXT: ret { double, double } %[[i6]]
; CHECK-NEXT: }
Loading