Skip to content

Commit 5b5f816

Browse files
authored
Merge pull request #554 from JuliaParallel/jps/dtaskfailedexception
More `Thunk` to `DTask` renames
2 parents 52a97dd + 57e2209 commit 5b5f816

19 files changed

+77
-68
lines changed

Diff for: docs/src/api-dagger/functions.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,13 @@ addprocs!
5959
rmprocs!
6060
```
6161

62-
## Thunk Execution Environment Functions
62+
## DTask Execution Environment Functions
6363

64-
These functions are used within the function called by a `Thunk`.
64+
These functions are used within the function called by a `DTask`.
6565

6666
```@docs
67-
in_thunk
68-
thunk_processor
67+
in_task
68+
task_processor
6969
```
7070

7171
### Dynamic Scheduler Control Functions

Diff for: docs/src/darray.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ julia> Dagger.chunks(DZ)
357357
DTask (finished) DTask (finished)
358358
359359
julia> Dagger.chunks(fetch(DZ))
360-
2×2 Matrix{Union{Thunk, Dagger.Chunk}}:
360+
2×2 Matrix{Union{DTask, Dagger.Chunk}}:
361361
Chunk{Matrix{Float64}, DRef, ThreadProc, AnyScope}(Matrix{Float64}, ArrayDomain{2}((1:50, 1:50)), DRef(4, 8, 0x0000000000004e20), ThreadProc(4, 1), AnyScope(), true) … Chunk{Matrix{Float64}, DRef, ThreadProc, AnyScope}(Matrix{Float64}, ArrayDomain{2}((1:50, 1:50)), DRef(2, 5, 0x0000000000004e20), ThreadProc(2, 1), AnyScope(), true)
362362
Chunk{Matrix{Float64}, DRef, ThreadProc, AnyScope}(Matrix{Float64}, ArrayDomain{2}((1:50, 1:50)), DRef(5, 5, 0x0000000000004e20), ThreadProc(5, 1), AnyScope(), true) Chunk{Matrix{Float64}, DRef, ThreadProc, AnyScope}(Matrix{Float64}, ArrayDomain{2}((1:50, 1:50)), DRef(3, 3, 0x0000000000004e20), ThreadProc(3, 1), AnyScope(), true)
363363
```

Diff for: docs/src/scopes.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ using VideoIO, Distributed
2323

2424
function get_handle()
2525
handle = VideoIO.opencamera()
26-
proc = Dagger.thunk_processor()
26+
proc = Dagger.task_processor()
2727
scope = Dagger.scope(worker=myid()) # constructs a `ProcessScope`
2828
return Dagger.tochunk(handle, proc, scope)
2929
end
@@ -78,7 +78,7 @@ function generate()
7878
fill!(arr, 1)
7979
Mmap.sync!(arr)
8080
# Note: Dagger.scope() does not yet support node scopes
81-
Dagger.tochunk(path, Dagger.thunk_processor(), NodeScope())
81+
Dagger.tochunk(path, Dagger.task_processor(), NodeScope())
8282
end
8383

8484
function consume(path)
@@ -120,7 +120,7 @@ function generate_secrets()
120120
secrets = open("/shared/secret_results.txt", "r") do io
121121
String(read(io))
122122
end
123-
Dagger.tochunk(secrets, Dagger.thunk_processor(), secrets_scope)
123+
Dagger.tochunk(secrets, Dagger.task_processor(), secrets_scope)
124124
end
125125

126126
summarize(secrets) = occursin("QA Pass", secrets)
@@ -144,7 +144,7 @@ constraints). For example:
144144
ps2 = ProcessScope(2)
145145
ps3 = ProcessScope(3)
146146

147-
generate(scope) = Dagger.tochunk(rand(64), Dagger.thunk_processor(), scope)
147+
generate(scope) = Dagger.tochunk(rand(64), Dagger.task_processor(), scope)
148148

149149
d2 = Dagger.@spawn generate(ps2) # Run on process 2
150150
d3 = Dagger.@spawn generate(ps3) # Run on process 3

Diff for: src/array/alloc.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ function partition(p::AbstractBlocks, dom::ArrayDomain)
2525
end
2626

2727
function allocate_array(f, T, idx, sz)
28-
new_f = allocate_array_func(thunk_processor(), f)
28+
new_f = allocate_array_func(task_processor(), f)
2929
return new_f(idx, T, sz)
3030
end
3131
function allocate_array(f, T, sz)
32-
new_f = allocate_array_func(thunk_processor(), f)
32+
new_f = allocate_array_func(task_processor(), f)
3333
return new_f(T, sz)
3434
end
3535
allocate_array_func(::Processor, f) = f

Diff for: src/array/cholesky.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
LinearAlgebra.cholcopy(A::DArray{T,2}) where T = copy(A)
22
function potrf_checked!(uplo, A, info_arr)
3-
_A, info = move(thunk_processor(), LAPACK.potrf!)(uplo, A)
3+
_A, info = move(task_processor(), LAPACK.potrf!)(uplo, A)
44
if info != 0
55
fill!(info_arr, info)
66
throw(PosDefException(info))
@@ -41,7 +41,7 @@ function LinearAlgebra._chol!(A::DArray{T,2}, ::Type{UpperTriangular}) where T
4141
end
4242
end
4343
catch err
44-
err isa ThunkFailedException || rethrow()
44+
err isa DTaskFailedException || rethrow()
4545
err = Dagger.Sch.unwrap_nested_exception(err.ex)
4646
err isa PosDefException || rethrow()
4747
end
@@ -82,7 +82,7 @@ function LinearAlgebra._chol!(A::DArray{T,2}, ::Type{LowerTriangular}) where T
8282
end
8383
end
8484
catch err
85-
err isa ThunkFailedException || rethrow()
85+
err isa DTaskFailedException || rethrow()
8686
err = Dagger.Sch.unwrap_nested_exception(err.ex)
8787
err isa PosDefException || rethrow()
8888
end

Diff for: src/dtask.jl

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
export DTask
2+
13
"A future holding the result of a `Thunk`."
24
struct ThunkFuture
35
future::Future

Diff for: src/sch/Sch.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import Random: randperm
88
import Base: @invokelatest
99

1010
import ..Dagger
11-
import ..Dagger: Context, Processor, Thunk, WeakThunk, ThunkFuture, ThunkFailedException, Chunk, WeakChunk, OSProc, AnyScope, DefaultScope, LockedObject
12-
import ..Dagger: order, dependents, noffspring, istask, inputs, unwrap_weak_checked, affinity, tochunk, timespan_start, timespan_finish, procs, move, chunktype, processor, get_processors, get_parent, execute!, rmprocs!, thunk_processor, constrain, cputhreadtime
11+
import ..Dagger: Context, Processor, Thunk, WeakThunk, ThunkFuture, DTaskFailedException, Chunk, WeakChunk, OSProc, AnyScope, DefaultScope, LockedObject
12+
import ..Dagger: order, dependents, noffspring, istask, inputs, unwrap_weak_checked, affinity, tochunk, timespan_start, timespan_finish, procs, move, chunktype, processor, get_processors, get_parent, execute!, rmprocs!, task_processor, constrain, cputhreadtime
1313
import ..Dagger: @dagdebug, @safe_lock_spin1
1414
import DataStructures: PriorityQueue, enqueue!, dequeue_pair!, peek
1515

Diff for: src/sch/dynamic.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ end
132132
function Base.fetch(h::SchedulerHandle, id::ThunkID)
133133
future = ThunkFuture(Future(1))
134134
exec!(_register_future!, h, future, id, true)
135-
fetch(future; proc=thunk_processor())
135+
fetch(future; proc=task_processor())
136136
end
137137
"""
138138
Waits on a thunk to complete, and fetches its result. If `check` is set to

Diff for: src/sch/eager.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ Allows a thunk to safely wait on another thunk by temporarily reducing its
6161
effective occupancy to 0, which allows a newly-spawned task to run.
6262
"""
6363
function thunk_yield(f)
64-
if Dagger.in_thunk()
64+
if Dagger.in_task()
6565
h = sch_handle()
6666
tls = Dagger.get_tls()
67-
proc = Dagger.thunk_processor()
67+
proc = Dagger.task_processor()
6868
proc_istate = proc_states(tls.sch_uid) do states
6969
states[proc].state
7070
end

Diff for: src/sch/util.jl

+5-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,11 @@ end
175175
"Marks `thunk` and all dependent thunks as failed."
176176
function set_failed!(state, origin, thunk=origin)
177177
filter!(x->x!==thunk, state.ready)
178-
state.cache[thunk] = ThunkFailedException(thunk, origin, state.cache[origin])
178+
ex = state.cache[origin]
179+
if ex isa RemoteException
180+
ex = ex.captured
181+
end
182+
state.cache[thunk] = DTaskFailedException(thunk, origin, ex)
179183
state.errored[thunk] = true
180184
finish_failed!(state, thunk, origin)
181185
end

Diff for: src/submission.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ end
159159

160160
# Local -> Remote
161161
function eager_submit!(ntasks, uid, future, finalizer_ref, f, args, options)
162-
if Dagger.in_thunk()
162+
if Dagger.in_task()
163163
h = Dagger.sch_handle()
164164
return exec!(eager_submit_internal!, h, ntasks, uid, future, finalizer_ref, f, args, options, true)
165165
elseif myid() != 1

Diff for: src/task-tls.jl

+9-7
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
# In-Thunk Helpers
22

33
"""
4-
thunk_processor()
4+
task_processor()
55
6-
Get the current processor executing the current thunk.
6+
Get the current processor executing the current Dagger task.
77
"""
8-
thunk_processor() = task_local_storage(:_dagger_processor)::Processor
8+
task_processor() = task_local_storage(:_dagger_processor)::Processor
9+
@deprecate thunk_processor() task_processor()
910

1011
"""
11-
in_thunk()
12+
in_task()
1213
13-
Returns `true` if currently in a [`Thunk`](@ref) process, else `false`.
14+
Returns `true` if currently executing in a [`DTask`](@ref), else `false`.
1415
"""
15-
in_thunk() = haskey(task_local_storage(), :_dagger_sch_uid)
16+
in_task() = haskey(task_local_storage(), :_dagger_sch_uid)
17+
@deprecate in_thunk() in_task()
1618

1719
"""
1820
get_tls()
@@ -22,7 +24,7 @@ Gets all Dagger TLS variable as a `NamedTuple`.
2224
get_tls() = (
2325
sch_uid=task_local_storage(:_dagger_sch_uid),
2426
sch_handle=task_local_storage(:_dagger_sch_handle),
25-
processor=thunk_processor(),
27+
processor=task_processor(),
2628
task_spec=task_local_storage(:_dagger_task_spec),
2729
)
2830

Diff for: src/thunk.jl

+14-13
Original file line numberDiff line numberDiff line change
@@ -220,22 +220,23 @@ function Base.convert(::Type{ThunkSummary}, t::WeakThunk)
220220
return t
221221
end
222222

223-
struct ThunkFailedException{E<:Exception} <: Exception
223+
struct DTaskFailedException{E<:Exception} <: Exception
224224
thunk::ThunkSummary
225225
origin::ThunkSummary
226226
ex::E
227227
end
228-
ThunkFailedException(thunk, origin, ex::E) where E =
229-
ThunkFailedException{E}(convert(ThunkSummary, thunk),
228+
DTaskFailedException(thunk, origin, ex::E) where E =
229+
DTaskFailedException{E}(convert(ThunkSummary, thunk),
230230
convert(ThunkSummary, origin),
231231
ex)
232-
function Base.showerror(io::IO, ex::ThunkFailedException)
232+
@deprecate ThunkFailedException DTaskFailedException
233+
function Base.showerror(io::IO, ex::DTaskFailedException)
233234
t = ex.thunk
234235

235236
# Find root-cause thunk
236237
last_tfex = ex
237238
failed_tasks = Union{ThunkSummary,Nothing}[]
238-
while last_tfex.ex isa ThunkFailedException
239+
while last_tfex.ex isa DTaskFailedException
239240
push!(failed_tasks, last_tfex.thunk)
240241
last_tfex = last_tfex.ex
241242
end
@@ -246,7 +247,7 @@ function Base.showerror(io::IO, ex::ThunkFailedException)
246247
Tinputs = Any[]
247248
for (_, input) in t.inputs
248249
if istask(input)
249-
push!(Tinputs, "Thunk(id=$(input.id))")
250+
push!(Tinputs, "DTask(id=$(input.id))")
250251
else
251252
push!(Tinputs, input)
252253
end
@@ -256,28 +257,28 @@ function Base.showerror(io::IO, ex::ThunkFailedException)
256257
else
257258
"$(t.f)($(length(Tinputs)) inputs...)"
258259
end
259-
return "Thunk(id=$(t.id), $t_sig)"
260+
return "DTask(id=$(t.id), $t_sig)"
260261
end
261262
t_str = thunk_string(t)
262263
o_str = thunk_string(o)
263-
println(io, "ThunkFailedException:")
264-
println(io, " Root Exception Type: $(typeof(root_ex))")
264+
println(io, "DTaskFailedException:")
265+
println(io, " Root Exception Type: $(typeof(Sch.unwrap_nested_exception(root_ex)))")
265266
println(io, " Root Exception:")
266267
Base.showerror(io, root_ex); println(io)
267268
if t.id !== o.id
268-
println(io, " Root Thunk: $o_str")
269+
println(io, " Root Task: $o_str")
269270
if length(failed_tasks) <= 4
270271
for i in failed_tasks
271272
i_str = thunk_string(i)
272-
println(io, " Inner Thunk: $i_str")
273+
println(io, " Inner Task: $i_str")
273274
end
274275
else
275276
println(io, " ...")
276-
println(io, " $(length(failed_tasks)) Inner Thunks...")
277+
println(io, " $(length(failed_tasks)) Inner Tasks...")
277278
println(io, " ...")
278279
end
279280
end
280-
print(io, " This Thunk: $t_str")
281+
print(io, " This Task: $t_str")
281282
end
282283

283284
"""

Diff for: test/datadeps.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ function test_datadeps(;args_chunks::Bool,
396396

397397
# Scope
398398
exec_procs = fetch.(Dagger.spawn_datadeps(;aliasing) do
399-
[Dagger.@spawn Dagger.thunk_processor() for i in 1:10]
399+
[Dagger.@spawn Dagger.task_processor() for i in 1:10]
400400
end)
401401
unique!(exec_procs)
402402
scope = Dagger.get_options(:scope)

Diff for: test/mutation.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ end
4848
x = Dagger.@mutable worker=w Ref{Int}()
4949
@test fetch(Dagger.@spawn mutable_update!(x)) == w
5050
wo_scope = Dagger.ProcessScope(wo)
51-
@test_throws_unwrap Dagger.ThunkFailedException fetch(Dagger.@spawn scope=wo_scope mutable_update!(x))
51+
@test_throws_unwrap Dagger.DTaskFailedException fetch(Dagger.@spawn scope=wo_scope mutable_update!(x))
5252
end
5353
end # @testset "@mutable"
5454

Diff for: test/processors.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ end
3737
end
3838
@testset "Processor exhaustion" begin
3939
opts = ThunkOptions(proclist=[OptOutProc])
40-
@test_throws_unwrap Dagger.ThunkFailedException ex isa Dagger.Sch.SchedulingException ex.reason="No processors available, try widening scope" collect(delayed(sum; options=opts)([1,2,3]))
40+
@test_throws_unwrap Dagger.DTaskFailedException ex isa Dagger.Sch.SchedulingException ex.reason="No processors available, try widening scope" collect(delayed(sum; options=opts)([1,2,3]))
4141
opts = ThunkOptions(proclist=(proc)->false)
42-
@test_throws_unwrap Dagger.ThunkFailedException ex isa Dagger.Sch.SchedulingException ex.reason="No processors available, try widening scope" collect(delayed(sum; options=opts)([1,2,3]))
42+
@test_throws_unwrap Dagger.DTaskFailedException ex isa Dagger.Sch.SchedulingException ex.reason="No processors available, try widening scope" collect(delayed(sum; options=opts)([1,2,3]))
4343
opts = ThunkOptions(proclist=nothing)
4444
@test collect(delayed(sum; options=opts)([1,2,3])) == 6
4545
end
@@ -89,7 +89,7 @@ end
8989

9090
@testset "Processor TLS accessor" begin
9191
@everywhere function mythunk(x)
92-
typeof(Dagger.thunk_processor())
92+
typeof(Dagger.task_processor())
9393
end
9494
@test collect(delayed(mythunk)(1)) === ThreadProc
9595
end

Diff for: test/scheduler.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ end
182182
@testset "allow errors" begin
183183
opts = ThunkOptions(;allow_errors=true)
184184
a = delayed(error; options=opts)("Test")
185-
@test_throws_unwrap Dagger.ThunkFailedException collect(a)
185+
@test_throws_unwrap Dagger.DTaskFailedException collect(a)
186186
end
187187
end
188188

Diff for: test/scopes.jl

+6-6
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656

5757
# Different nodes
5858
for (ch1, ch2) in [(ns1_ch, ns2_ch), (ns2_ch, ns1_ch)]
59-
@test_throws_unwrap Dagger.ThunkFailedException ex.reason<"Scopes are not compatible:" fetch(Dagger.@spawn ch1 + ch2)
59+
@test_throws_unwrap Dagger.DTaskFailedException ex.reason<"Scopes are not compatible:" fetch(Dagger.@spawn ch1 + ch2)
6060
end
6161
end
6262
@testset "Process Scope" begin
@@ -75,19 +75,19 @@
7575

7676
# Different process
7777
for (ch1, ch2) in [(ps1_ch, ps2_ch), (ps2_ch, ps1_ch)]
78-
@test_throws_unwrap Dagger.ThunkFailedException ex.reason<"Scopes are not compatible:" fetch(Dagger.@spawn ch1 + ch2)
78+
@test_throws_unwrap Dagger.DTaskFailedException ex.reason<"Scopes are not compatible:" fetch(Dagger.@spawn ch1 + ch2)
7979
end
8080

8181
# Same process and node
8282
@test fetch(Dagger.@spawn process_scope_test(ps1_ch, ns1_ch)) == wid1
8383

8484
# Different process and node
8585
for (ch1, ch2) in [(ps1_ch, ns2_ch), (ns2_ch, ps1_ch)]
86-
@test_throws_unwrap Dagger.ThunkFailedException ex.reason<"Scopes are not compatible:" fetch(Dagger.@spawn ch1 + ch2)
86+
@test_throws_unwrap Dagger.DTaskFailedException ex.reason<"Scopes are not compatible:" fetch(Dagger.@spawn ch1 + ch2)
8787
end
8888
end
8989
@testset "Exact Scope" begin
90-
@everywhere exact_scope_test(ch...) = Dagger.thunk_processor()
90+
@everywhere exact_scope_test(ch...) = Dagger.task_processor()
9191
@test es1.parent.wid == wid1
9292
@test es1.parent.parent.uuid == Dagger.system_uuid(wid1)
9393
@test es2.parent.wid == wid2
@@ -104,14 +104,14 @@
104104

105105
# Different process, different processor
106106
for (ch1, ch2) in [(es1_ch, es2_ch), (es2_ch, es1_ch)]
107-
@test_throws_unwrap Dagger.ThunkFailedException ex.reason<"Scopes are not compatible:" fetch(Dagger.@spawn ch1 + ch2)
107+
@test_throws_unwrap Dagger.DTaskFailedException ex.reason<"Scopes are not compatible:" fetch(Dagger.@spawn ch1 + ch2)
108108
end
109109

110110
# Same process, different processor
111111
es1_2 = ExactScope(Dagger.ThreadProc(wid1, 2))
112112
es1_2_ch = Dagger.tochunk(nothing, OSProc(), es1_2)
113113
for (ch1, ch2) in [(es1_ch, es1_2_ch), (es1_2_ch, es1_ch)]
114-
@test_throws_unwrap Dagger.ThunkFailedException ex.reason<"Scopes are not compatible:" fetch(Dagger.@spawn ch1 + ch2)
114+
@test_throws_unwrap Dagger.DTaskFailedException ex.reason<"Scopes are not compatible:" fetch(Dagger.@spawn ch1 + ch2)
115115
end
116116
end
117117
@testset "Union Scope" begin

0 commit comments

Comments
 (0)