11# Remote
22function eager_submit_internal! (@nospecialize (payload))
3- Sch. init_eager ()
4-
53 ctx = Dagger. Sch. eager_context ()
64 state = Dagger. Sch. EAGER_STATE[]
75 task = current_task ()
@@ -12,8 +10,6 @@ function eager_submit_internal!(ctx, state, task, tid, payload; uid_to_tid=Dict{
1210 @nospecialize payload
1311 ntasks, uid, future, ref, f, args, options, reschedule = payload
1412
15- Sch. init_eager ()
16-
1713 if uid isa Vector
1814 thunk_ids = Sch. ThunkID[]
1915 for i in 1 : ntasks
@@ -31,6 +27,7 @@ function eager_submit_internal!(ctx, state, task, tid, payload; uid_to_tid=Dict{
3127 timespan_start (ctx, :add_thunk , tid, 0 )
3228
3329 # Lookup EagerThunk/ThunkID -> Thunk
30+ old_args = copy (args)
3431 args:: Vector{Any}
3532 syncdeps = if haskey (options, :syncdeps )
3633 collect (options. syncdeps)
@@ -51,6 +48,13 @@ function eager_submit_internal!(ctx, state, task, tid, payload; uid_to_tid=Dict{
5148 elseif arg isa Sch. ThunkID
5249 arg_tid = arg. id
5350 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)
5458 else
5559 arg
5660 end
@@ -80,7 +84,7 @@ function eager_submit_internal!(ctx, state, task, tid, payload; uid_to_tid=Dict{
8084 options = merge (options, (;syncdeps))
8185 end
8286
83- GC. @preserve args begin
87+ GC. @preserve old_args args begin
8488 # Create the `Thunk`
8589 thunk = Thunk (f, args... ; options... )
8690
@@ -125,7 +129,14 @@ function eager_submit!(ntasks, uid, future, finalizer_ref, f, args, options)
125129 h = Dagger. sch_handle ()
126130 return exec! (eager_submit_internal!, h, ntasks, uid, future, finalizer_ref, f, args, options, true )
127131 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
129140 else
130141 Sch. init_eager ()
131142 state = Dagger. Sch. EAGER_STATE[]
@@ -143,8 +154,6 @@ function eager_process_elem_submission_to_local(id_map, x)
143154 @assert ! isa (x, Thunk) " Cannot use `Thunk`s in `@spawn`/`spawn`"
144155 if x isa Dagger. EagerThunk && haskey (id_map, x. uid)
145156 return Sch. ThunkID (id_map[x. uid], x. thunk_ref)
146- elseif x isa Dagger. Chunk
147- return WeakChunk (x)
148157 else
149158 return x
150159 end
0 commit comments