Skip to content

Commit 01c2727

Browse files
authored
Remove CTask (#123)
1 parent 4a85b47 commit 01c2727

File tree

11 files changed

+97
-100
lines changed

11 files changed

+97
-100
lines changed

Diff for: Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ uuid = "6f1fad26-d15e-5dc8-ae53-837a1d7b8c9f"
33
license = "MIT"
44
desc = "Tape based task copying in Turing"
55
repo = "https://github.com/TuringLang/Libtask.jl.git"
6-
version = "0.6.10"
6+
version = "0.7.0"
77

88
[deps]
99
IRTools = "7869d1d1-7146-5819-86e3-90919afe41df"

Diff for: README.md

+17-17
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,17 @@ function f()
1919
end
2020
end
2121

22-
ctask = CTask(f)
22+
ttask = TapedTask(f)
2323

24-
@show consume(ctask) # 0
25-
@show consume(ctask) # 1
24+
@show consume(ttask) # 0
25+
@show consume(ttask) # 1
2626

27-
a = copy(ctask)
27+
a = copy(ttask)
2828
@show consume(a) # 2
2929
@show consume(a) # 3
3030

31-
@show consume(ctask) # 2
32-
@show consume(ctask) # 3
31+
@show consume(ttask) # 2
32+
@show consume(ttask) # 3
3333
```
3434

3535
Heap allocated objects are shallow copied:
@@ -45,17 +45,17 @@ function f()
4545
end
4646
end
4747

48-
ctask = CTask(f)
48+
ttask = TapedTask(f)
4949

50-
@show consume(ctask) # 0
51-
@show consume(ctask) # 1
50+
@show consume(ttask) # 0
51+
@show consume(ttask) # 1
5252

5353
a = copy(t)
5454
@show consume(a) # 2
5555
@show consume(a) # 3
5656

57-
@show consume(ctask) # 4
58-
@show consume(ctask) # 5
57+
@show consume(ttask) # 4
58+
@show consume(ttask) # 5
5959
```
6060

6161
In constrast to standard arrays, which are only shallow copied during
@@ -74,17 +74,17 @@ function f()
7474
end
7575
end
7676

77-
ctask = CTask(f)
77+
ttask = TapedTask(f)
7878

79-
@show consume(ctask) # 0
80-
@show consume(ctask) # 1
79+
@show consume(ttask) # 0
80+
@show consume(ttask) # 1
8181

82-
a = copy(ctask)
82+
a = copy(ttask)
8383
@show consume(a) # 2
8484
@show consume(a) # 3
8585

86-
@show consume(ctask) # 2
87-
@show consume(ctask) # 3
86+
@show consume(ttask) # 2
87+
@show consume(ttask) # 3
8888
```
8989

9090
Note: The [Turing](https://github.com/TuringLang/Turing.jl)

Diff for: perf/p0.jl

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# ]add Turing#hg/new-libtask2
2-
31
using Libtask
42
using Turing, DynamicPPL, AdvancedPS
53
using BenchmarkTools
@@ -26,8 +24,8 @@ args = m.evaluator[2:end];
2624
@btime f(args...)
2725
# (2.0, VarInfo (2 variables (μ, σ), dimension 2; logp: -6.162))
2826

29-
@show "CTask construction..."
30-
t = @btime Libtask.CTask(f, args...)
27+
@show "TapedTask construction..."
28+
t = @btime TapedTask(f, args...)
3129
# schedule(t.task) # work fine!
3230
# @show Libtask.result(t.tf)
3331
@show "Run a tape..."
@@ -39,8 +37,8 @@ m = Turing.Core.TracedModel(gdemo(1.5, 2.), Sampler(SMC(50)), VarInfo());
3937
@show "Directly call..."
4038
@btime m.evaluator[1](m.evaluator[2:end]...)
4139

42-
@show "CTask construction..."
43-
t = @btime Libtask.CTask(m.evaluator[1], m.evaluator[2:end]...);
40+
@show "TapedTask construction..."
41+
t = @btime TapedTask(m.evaluator[1], m.evaluator[2:end]...);
4442
# schedule(t.task)
4543
# @show Libtask.result(t.tf.tape)
4644
@show "Run a tape..."

Diff for: perf/p2.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ m = Turing.Core.TracedModel(model_fun, Sampler(SMC(50)), VarInfo())
5656
f = m.evaluator[1]
5757
args = m.evaluator[2:end]
5858

59-
t = Libtask.CTask(f, args...)
59+
t = TapedTask(f, args...)
6060

6161
t.tf(args...)
6262

Diff for: src/Libtask.jl

+1-5
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,13 @@ using MacroTools
55

66
using LRUCache
77

8-
export CTask, consume, produce
8+
export TapedTask, consume, produce
99
export TArray, tzeros, tfill, TRef
1010

11-
export TapedTask
12-
1311
include("tapedfunction.jl")
1412
include("tapedtask.jl")
1513

1614
include("tarray.jl")
1715
include("tref.jl")
1816

19-
const CTask = TapedTask
20-
2117
end

Diff for: src/tapedtask.jl

+10-6
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,20 @@ struct TapedTaskException
33
backtrace::Vector{Any}
44
end
55

6-
struct TapedTask
6+
struct TapedTask{F}
77
task::Task
8-
tf::TapedFunction
8+
tf::TapedFunction{F}
99
produce_ch::Channel{Any}
1010
consume_ch::Channel{Int}
1111
produced_val::Vector{Any}
1212

1313
function TapedTask(
14-
t::Task, tf::TapedFunction, pch::Channel{Any}, cch::Channel{Int})
15-
new(t, tf, pch, cch, Any[])
14+
t::Task,
15+
tf::TapedFunction{F},
16+
produce_ch::Channel{Any},
17+
consume_ch::Channel{Int}
18+
) where {F}
19+
new{F}(t, tf, produce_ch, consume_ch, Any[])
1620
end
1721
end
1822

@@ -148,8 +152,8 @@ function Base.iterate(t::TapedTask, state=nothing)
148152
nothing
149153
end
150154
end
151-
Base.IteratorSize(::Type{TapedTask}) = Base.SizeUnknown()
152-
Base.IteratorEltype(::Type{TapedTask}) = Base.EltypeUnknown()
155+
Base.IteratorSize(::Type{<:TapedTask}) = Base.SizeUnknown()
156+
Base.IteratorEltype(::Type{<:TapedTask}) = Base.EltypeUnknown()
153157

154158

155159
# copy the task

Diff for: test/benchmarks.jl

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using BenchmarkTools
22
using Libtask
33

4-
54
macro rep(cnt, exp)
65
blk =:(begin end)
76
for _ in 1:eval(cnt)
@@ -47,10 +46,10 @@ function f()
4746
end
4847

4948
@btime begin
50-
ctask = CTask(f)
51-
consume(ctask)
52-
consume(ctask)
53-
a = copy(ctask)
49+
ttask = TapedTask(f)
50+
consume(ttask)
51+
consume(ttask)
52+
a = copy(ttask)
5453
consume(a)
5554
consume(a)
5655
end

Diff for: test/runtests.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ using Libtask
22
using Test
33

44
include("tf.jl")
5-
include("ctask.jl")
5+
include("tapedtask.jl")
66
include("tarray.jl")
77
include("tref.jl")
88

9-
if get(ENV, "BENCHMARK", nothing) != nothing
9+
if haskey(ENV, "BENCHMARK")
1010
include("benchmarks.jl")
1111
end

Diff for: test/ctask.jl renamed to test/tapedtask.jl

+39-39
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@testset "ctask" begin
1+
@testset "tapedtask" begin
22
# Test case 1: stack allocated objects are deep copied.
33
@testset "stack allocated objects" begin
44
function f()
@@ -9,14 +9,14 @@
99
end
1010
end
1111

12-
ctask = CTask(f)
13-
@test consume(ctask) == 0
14-
@test consume(ctask) == 1
15-
a = copy(ctask)
12+
ttask = TapedTask(f)
13+
@test consume(ttask) == 0
14+
@test consume(ttask) == 1
15+
a = copy(ttask)
1616
@test consume(a) == 2
1717
@test consume(a) == 3
18-
@test consume(ctask) == 2
19-
@test consume(ctask) == 3
18+
@test consume(ttask) == 2
19+
@test consume(ttask) == 3
2020

2121
@inferred Libtask.TapedFunction(f)
2222
end
@@ -31,16 +31,16 @@
3131
end
3232
end
3333

34-
ctask = CTask(f)
35-
@test consume(ctask) == 0
36-
@test consume(ctask) == 1
37-
a = copy(ctask)
34+
ttask = TapedTask(f)
35+
@test consume(ttask) == 0
36+
@test consume(ttask) == 1
37+
a = copy(ttask)
3838
@test consume(a) == 2
3939
@test consume(a) == 3
40-
@test consume(ctask) == 4
41-
@test consume(ctask) == 5
42-
@test consume(ctask) == 6
43-
@test consume(ctask) == 7
40+
@test consume(ttask) == 4
41+
@test consume(ttask) == 5
42+
@test consume(ttask) == 6
43+
@test consume(ttask) == 7
4444
end
4545

4646
@testset "iteration" begin
@@ -52,20 +52,20 @@
5252
end
5353
end
5454

55-
ctask = CTask(f)
55+
ttask = TapedTask(f)
5656

57-
next = iterate(ctask)
57+
next = iterate(ttask)
5858
@test next === (1, nothing)
5959

6060
val, state = next
61-
next = iterate(ctask, state)
61+
next = iterate(ttask, state)
6262
@test next === (2, nothing)
6363

6464
val, state = next
65-
next = iterate(ctask, state)
65+
next = iterate(ttask, state)
6666
@test next === (3, nothing)
6767

68-
a = collect(Iterators.take(ctask, 7))
68+
a = collect(Iterators.take(ttask, 7))
6969
@test eltype(a) === Int
7070
@test a == 4:10
7171
end
@@ -82,14 +82,14 @@
8282
end
8383
end
8484

85-
ctask = CTask(f)
85+
ttask = TapedTask(f)
8686
try
87-
consume(ctask)
87+
consume(ttask)
8888
catch ex
8989
@test ex isa MethodError
9090
end
9191
if VERSION >= v"1.5"
92-
@test ctask.task.exception isa MethodError
92+
@test ttask.task.exception isa MethodError
9393
end
9494
end
9595

@@ -103,14 +103,14 @@
103103
end
104104
end
105105

106-
ctask = CTask(f)
106+
ttask = TapedTask(f)
107107
try
108-
consume(ctask)
108+
consume(ttask)
109109
catch ex
110110
@test ex isa ErrorException
111111
end
112112
if VERSION >= v"1.5"
113-
@test ctask.task.exception isa ErrorException
113+
@test ttask.task.exception isa ErrorException
114114
end
115115
end
116116

@@ -125,14 +125,14 @@
125125
end
126126
end
127127

128-
ctask = CTask(f)
128+
ttask = TapedTask(f)
129129
try
130-
consume(ctask)
130+
consume(ttask)
131131
catch ex
132132
@test ex isa BoundsError
133133
end
134134
if VERSION >= v"1.5"
135-
@test ctask.task.exception isa BoundsError
135+
@test ttask.task.exception isa BoundsError
136136
end
137137
end
138138

@@ -147,15 +147,15 @@
147147
end
148148
end
149149

150-
ctask = CTask(f)
151-
@test consume(ctask) == 2
150+
ttask = TapedTask(f)
151+
@test consume(ttask) == 2
152152
try
153-
consume(ctask)
153+
consume(ttask)
154154
catch ex
155155
@test ex isa BoundsError
156156
end
157157
if VERSION >= v"1.5"
158-
@test ctask.task.exception isa BoundsError
158+
@test ttask.task.exception isa BoundsError
159159
end
160160
end
161161

@@ -170,17 +170,17 @@
170170
end
171171
end
172172

173-
ctask = CTask(f)
174-
@test consume(ctask) == 2
175-
ctask2 = copy(ctask)
173+
ttask = TapedTask(f)
174+
@test consume(ttask) == 2
175+
ttask2 = copy(ttask)
176176
try
177-
consume(ctask2)
177+
consume(ttask2)
178178
catch ex
179179
@test ex isa BoundsError
180180
end
181-
@test ctask.task.exception === nothing
181+
@test ttask.task.exception === nothing
182182
if VERSION >= v"1.5"
183-
@test ctask2.task.exception isa BoundsError
183+
@test ttask2.task.exception isa BoundsError
184184
end
185185
end
186186
end

0 commit comments

Comments
 (0)