Skip to content

Peformance Optimization #138

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

Merged
merged 35 commits into from
Jun 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
16e4df1
use generated function to run instruction
KDr2 Apr 2, 2022
e1529f1
optimize mem allocation
KDr2 Apr 27, 2022
10578ea
optiomize copy and update_var!
KDr2 May 5, 2022
64924e4
Merge branch 'master' into perf
yebai May 10, 2022
4e0e60c
optimization on constant
KDr2 May 12, 2022
2d9ecd4
remove MacroTools
KDr2 May 12, 2022
18e1629
don't optimize function call
KDr2 May 12, 2022
f8472b0
opt const function-call conditionally
KDr2 May 12, 2022
b6a4c77
remove `val`
KDr2 May 12, 2022
d1a2fea
breakdown benchmarks
KDr2 May 18, 2022
48355e1
Merge branch 'master' into perf
yebai May 23, 2022
d19ef67
use Vector as bindings
KDr2 May 25, 2022
9a1b11b
use Int as box, inline _update_var! manually
KDr2 May 26, 2022
2374767
code refactor
KDr2 May 26, 2022
4597d6d
remove unused code
KDr2 May 27, 2022
c4dd9f0
Update src/tapedfunction.jl
yebai May 27, 2022
3a31c4e
add comments
KDr2 May 31, 2022
252b846
update comments
KDr2 Jun 1, 2022
f8e3752
update from review
KDr2 Jun 1, 2022
9675907
update from review
KDr2 Jun 2, 2022
3ab024f
use a compact bindings, remove the offset limitation
KDr2 Jun 8, 2022
36a793e
bugfix: unify TypedSlot and SlotNumber
KDr2 Jun 8, 2022
00f2553
document
KDr2 Jun 8, 2022
a99b50c
refine types
KDr2 Jun 8, 2022
124e2e1
give bindings a sizehint
KDr2 Jun 8, 2022
6c49595
update docs for `tape_copy`
KDr2 Jun 9, 2022
dba0001
remove outdated comments
KDr2 Jun 9, 2022
08f085a
update from review
KDr2 Jun 11, 2022
2811318
disable logging by default
KDr2 Jun 11, 2022
03d971b
update comments
KDr2 Jun 11, 2022
9bafecf
use vector to store arg indices
KDr2 Jun 13, 2022
20f49ef
rename fields in TF
KDr2 Jun 15, 2022
d8f2371
remove TempBindings
KDr2 Jun 15, 2022
5343c34
Update tapedfunction.jl
yebai Jun 15, 2022
7bf4f29
Update Project.toml
yebai Jun 15, 2022
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
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ uuid = "6f1fad26-d15e-5dc8-ae53-837a1d7b8c9f"
license = "MIT"
desc = "Tape based task copying in Turing"
repo = "https://github.com/TuringLang/Libtask.jl.git"
version = "0.7.3"
version = "0.7.4"

[deps]
FunctionWrappers = "069b7b12-0de2-55c6-9aab-29f3d0a68a2e"
Expand Down
27 changes: 20 additions & 7 deletions perf/benchmark.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function benchmark_driver!(f, x...; f_displayname=string(f))
x = (x..., nothing)

println("benchmarking $(f_displayname)...")
tf = Libtask.TapedFunction(f, x...);
tf = Libtask.TapedFunction(f, x...)

print(" Run Original Function:")
@btime $f($(x)...)
Expand All @@ -24,18 +24,18 @@ function benchmark_driver!(f, x...; f_displayname=string(f))
GC.gc()

print(" Run TapedTask: ")
x = (x[1:end-1]..., produce);
x = (x[1:end-1]..., produce)
# show the number of produce calls inside `f`
f_task = (f, x; verbose=false) -> begin
tt = TapedTask(f, x...);
function f_task(f, x; verbose=false)
tt = TapedTask(f, x...)
c = 0
while consume(tt)!==nothing
c+=1
end
verbose && print("#produce=", c, "; ");
verbose && print("#produce=", c, "; ")
end
# Note that we need to pass `f` instead of `tf` to avoid
# default continuation in `TapedTask` constructor, see, e.g.
# Note that we need to pass `f` instead of `tf` to avoid
# default continuation in `TapedTask` constructor, see, e.g.
# https://github.com/TuringLang/Libtask.jl/pull/135
f_task(f, x; verbose=true) # print #produce calls
@btime $f_task($f, $x)
Expand Down Expand Up @@ -109,4 +109,17 @@ benchmark_driver!(neural_net, xs...)

####################################################################

println("======= breakdown benchmark =======")

x = rand(100000)
tf = Libtask.TapedFunction(ackley, x, nothing)
tf(x, nothing);
ins = tf.tape[45]
b = ins.input[1]

@show ins.input |> length
@btime map(x -> Libtask._lookup(tf, x), ins.input)
@btime Libtask._lookup(tf, b)
@btime tf.binding_values[b]

println("done")
Loading