1
1
# Remote
2
2
function eager_submit_internal! (@nospecialize (payload))
3
- Sch. init_eager ()
4
-
5
3
ctx = Dagger. Sch. eager_context ()
6
4
state = Dagger. Sch. EAGER_STATE[]
7
5
task = current_task ()
@@ -12,8 +10,6 @@ function eager_submit_internal!(ctx, state, task, tid, payload; uid_to_tid=Dict{
12
10
@nospecialize payload
13
11
ntasks, uid, future, ref, f, args, options, reschedule = payload
14
12
15
- Sch. init_eager ()
16
-
17
13
if uid isa Vector
18
14
thunk_ids = Sch. ThunkID[]
19
15
for i in 1 : ntasks
@@ -31,6 +27,7 @@ function eager_submit_internal!(ctx, state, task, tid, payload; uid_to_tid=Dict{
31
27
timespan_start (ctx, :add_thunk , tid, 0 )
32
28
33
29
# Lookup EagerThunk/ThunkID -> Thunk
30
+ old_args = copy (args)
34
31
args:: Vector{Any}
35
32
syncdeps = if haskey (options, :syncdeps )
36
33
collect (options. syncdeps)
@@ -51,6 +48,13 @@ function eager_submit_internal!(ctx, state, task, tid, payload; uid_to_tid=Dict{
51
48
elseif arg isa Sch. ThunkID
52
49
arg_tid = arg. id
53
50
state. thunk_dict[arg_tid]
51
+ elseif arg isa Chunk
52
+ # N.B. Different Chunks with the same DRef handle will hash to the same slot,
53
+ # so we just pick an equivalent Chunk as our upstream
54
+ if haskey (state. waiting_data, arg)
55
+ arg = only (filter (o-> o isa Chunk && o. handle == arg. handle, keys (state. waiting_data))):: Chunk
56
+ end
57
+ WeakChunk (arg)
54
58
else
55
59
arg
56
60
end
@@ -80,7 +84,7 @@ function eager_submit_internal!(ctx, state, task, tid, payload; uid_to_tid=Dict{
80
84
options = merge (options, (;syncdeps))
81
85
end
82
86
83
- GC. @preserve args begin
87
+ GC. @preserve old_args args begin
84
88
# Create the `Thunk`
85
89
thunk = Thunk (f, args... ; options... )
86
90
@@ -125,7 +129,14 @@ function eager_submit!(ntasks, uid, future, finalizer_ref, f, args, options)
125
129
h = Dagger. sch_handle ()
126
130
return exec! (eager_submit_internal!, h, ntasks, uid, future, finalizer_ref, f, args, options, true )
127
131
elseif myid () != 1
128
- return remotecall_fetch (eager_submit_internal!, 1 , (ntasks, uid, future, finalizer_ref, f, args, options, true ))
132
+ return remotecall_fetch (1 , (ntasks, uid, future, finalizer_ref, f, args, options, true )) do payload
133
+ @nospecialize payload
134
+ Sch. init_eager ()
135
+ state = Dagger. Sch. EAGER_STATE[]
136
+ lock (state. lock) do
137
+ eager_submit_internal! (payload)
138
+ end
139
+ end
129
140
else
130
141
Sch. init_eager ()
131
142
state = Dagger. Sch. EAGER_STATE[]
@@ -143,8 +154,6 @@ function eager_process_elem_submission_to_local(id_map, x)
143
154
@assert ! isa (x, Thunk) " Cannot use `Thunk`s in `@spawn`/`spawn`"
144
155
if x isa Dagger. EagerThunk && haskey (id_map, x. uid)
145
156
return Sch. ThunkID (id_map[x. uid], x. thunk_ref)
146
- elseif x isa Dagger. Chunk
147
- return WeakChunk (x)
148
157
else
149
158
return x
150
159
end
0 commit comments