@@ -156,16 +156,13 @@ If this returns a `Chunk`, all thunks will be skipped, and the `Chunk` will be
156
156
returned. If `nothing` is returned, restoring is skipped, and the scheduler
157
157
will execute as usual. If this function throws an error, restoring will be
158
158
skipped, and the error will be displayed.
159
- - `round_robin::Bool=false`: Whether to schedule in round-robin mode, which
160
- spreads load instead of the default behavior of filling processors to capacity.
161
159
"""
162
160
Base. @kwdef struct SchedulerOptions
163
- single:: Int = 0
161
+ single:: Union{ Int,Nothing} = nothing
164
162
proclist = nothing
165
- allow_errors:: Bool = false
163
+ allow_errors:: Union{ Bool,Nothing} = false
166
164
checkpoint = nothing
167
165
restore = nothing
168
- round_robin:: Bool = false
169
166
end
170
167
171
168
"""
@@ -209,11 +206,11 @@ device must support `MemPool.CPURAMResource`. When `nothing`, uses
209
206
`MemPool.GLOBAL_DEVICE[]`.
210
207
"""
211
208
Base. @kwdef struct ThunkOptions
212
- single:: Int = 0
209
+ single:: Union{ Int,Nothing} = nothing
213
210
proclist = nothing
214
- time_util:: Dict{Type,Any} = Dict {Type,Any} ()
215
- alloc_util:: Dict{Type,UInt64} = Dict {Type,UInt64} ()
216
- allow_errors:: Bool = false
211
+ time_util:: Union{ Dict{Type,Any},Nothing} = nothing
212
+ alloc_util:: Union{ Dict{Type,UInt64},Nothing} = nothing
213
+ allow_errors:: Union{ Bool,Nothing} = nothing
217
214
checkpoint = nothing
218
215
restore = nothing
219
216
storage:: Union{Chunk,Nothing} = nothing
@@ -228,20 +225,50 @@ include("eager.jl")
228
225
Combine `SchedulerOptions` and `ThunkOptions` into a new `ThunkOptions`.
229
226
"""
230
227
function Base. merge (sopts:: SchedulerOptions , topts:: ThunkOptions )
231
- single = topts. single != 0 ? topts. single : sopts. single
232
- allow_errors = sopts . allow_errors || topts. allow_errors
228
+ single = topts. single != = nothing ? topts. single : sopts. single
229
+ allow_errors = topts . allow_errors != = nothing ? topts. allow_errors : sopts . allow_errors
233
230
proclist = topts. proclist != = nothing ? topts. proclist : sopts. proclist
234
- ThunkOptions (single, proclist, topts. time_util, topts. alloc_util, allow_errors, topts. checkpoint, topts. restore, topts. storage)
231
+ ThunkOptions (single,
232
+ proclist,
233
+ topts. time_util,
234
+ topts. alloc_util,
235
+ allow_errors,
236
+ topts. checkpoint,
237
+ topts. restore,
238
+ topts. storage)
235
239
end
236
240
Base. merge (sopts:: SchedulerOptions , :: Nothing ) =
237
- ThunkOptions (sopts. single, sopts. proclist, Dict {Type,Any} (), sopts. allow_errors)
241
+ ThunkOptions (sopts. single,
242
+ sopts. proclist,
243
+ nothing ,
244
+ nothing ,
245
+ sopts. allow_errors)
246
+ """
247
+ populate_defaults(opts::ThunkOptions, Tf, Targs) -> ThunkOptions
238
248
239
- function isrestricted (task:: Thunk , proc:: OSProc )
240
- if (task. options != = nothing ) && (task. options. single != 0 ) &&
241
- (task. options. single != proc. pid)
242
- return true
249
+ Returns a `ThunkOptions` with default values filled in for a function of type
250
+ `Tf` with argument types `Targs`, if the option was previously unspecified in
251
+ `opts`.
252
+ """
253
+ function populate_defaults (opts:: ThunkOptions , Tf, Targs)
254
+ function maybe_default (opt:: Symbol )
255
+ old_opt = getproperty (opts, opt)
256
+ if old_opt != = nothing
257
+ return old_opt
258
+ else
259
+ return Dagger. default_option (Val (opt), Tf, Targs... )
260
+ end
243
261
end
244
- return false
262
+ ThunkOptions (
263
+ maybe_default (:single ),
264
+ maybe_default (:proclist ),
265
+ maybe_default (:time_util ),
266
+ maybe_default (:alloc_util ),
267
+ maybe_default (:allow_errors ),
268
+ maybe_default (:checkpoint ),
269
+ maybe_default (:restore ),
270
+ maybe_default (:storage ),
271
+ )
245
272
end
246
273
247
274
function cleanup (ctx)
@@ -470,7 +497,8 @@ function scheduler_run(ctx, state::ComputeState, d::Thunk, options)
470
497
timespan_finish (ctx, :handle_fault , 0 , 0 )
471
498
return # effectively `continue`
472
499
else
473
- if ctx. options. allow_errors || unwrap_weak_checked (state. thunk_dict[thunk_id]). options. allow_errors
500
+ if something (ctx. options. allow_errors, false ) ||
501
+ something (unwrap_weak_checked (state. thunk_dict[thunk_id]). options. allow_errors, false )
474
502
thunk_failed = true
475
503
else
476
504
throw (res)
@@ -537,7 +565,7 @@ function scheduler_exit(ctx, state::ComputeState, options)
537
565
end
538
566
539
567
function procs_to_use (ctx, options= ctx. options)
540
- return if options. single != = 0
568
+ return if options. single != = nothing
541
569
@assert options. single in vcat (1 , workers ()) " Sch option `single` must specify an active worker ID."
542
570
OSProc[OSProc (options. single)]
543
571
else
@@ -617,7 +645,9 @@ function schedule!(ctx, state, procs=procs_to_use(ctx))
617
645
@goto fallback
618
646
end
619
647
620
- local_procs, costs = estimate_task_costs (state, local_procs, task)
648
+ inputs = collect_task_inputs (state, task)
649
+ opts = populate_defaults (opts, chunktype (task. f), map (chunktype, inputs))
650
+ local_procs, costs = estimate_task_costs (state, local_procs, task, inputs)
621
651
scheduled = false
622
652
623
653
# Move our corresponding ThreadProc to be the last considered
@@ -703,9 +733,6 @@ function schedule!(ctx, state, procs=procs_to_use(ctx))
703
733
push! (get! (()-> Vector {Tuple{Thunk,<:Any,<:Any}} (), to_fire, (gproc, proc)), (task, est_time_util, est_alloc_util))
704
734
705
735
# Proceed to next entry to spread work
706
- if ! ctx. options. round_robin
707
- @warn " Round-robin mode is always on"
708
- end
709
736
state. procs_cache_list[] = state. procs_cache_list[]. next
710
737
@goto pop_task
711
738
@@ -777,46 +804,6 @@ function remove_dead_proc!(ctx, state, proc, options=ctx.options)
777
804
state. procs_cache_list[] = nothing
778
805
end
779
806
780
- function pop_with_affinity! (ctx, tasks, proc)
781
- # TODO : use the size
782
- parent_affinity_procs = Vector (undef, length (tasks))
783
- # parent_affinity_sizes = Vector(undef, length(tasks))
784
- for i= length (tasks): - 1 : 1
785
- t = tasks[i]
786
- aff = affinity (t)
787
- aff_procs = first .(aff)
788
- if proc in aff_procs
789
- if ! isrestricted (t,proc)
790
- deleteat! (tasks, i)
791
- return t
792
- end
793
- end
794
- parent_affinity_procs[i] = aff_procs
795
- end
796
- for i= length (tasks): - 1 : 1
797
- # use up tasks without affinities
798
- # let the procs with the respective affinities pick up
799
- # other tasks
800
- aff_procs = parent_affinity_procs[i]
801
- if isempty (aff_procs)
802
- t = tasks[i]
803
- if ! isrestricted (t,proc)
804
- deleteat! (tasks, i)
805
- return t
806
- end
807
- end
808
- if all (! (p in aff_procs) for p in procs (ctx))
809
- # no proc is ever going to ask for it
810
- t = tasks[i]
811
- if ! isrestricted (t,proc)
812
- deleteat! (tasks, i)
813
- return t
814
- end
815
- end
816
- end
817
- return nothing
818
- end
819
-
820
807
function finish_task! (ctx, state, node, thunk_failed)
821
808
pop! (state. running, node)
822
809
delete! (state. running_on, node)
@@ -909,12 +896,12 @@ function fire_tasks!(ctx, thunks::Vector{<:Tuple}, (gproc, proc), state)
909
896
toptions = thunk. options != = nothing ? thunk. options : ThunkOptions ()
910
897
options = merge (ctx. options, toptions)
911
898
propagated = get_propagated_options (thunk)
912
- @assert (options. single == 0 ) || (gproc. pid == options. single)
899
+ @assert (options. single === nothing ) || (gproc. pid == options. single)
913
900
# TODO : Set `sch_handle.tid.ref` to the right `DRef`
914
901
sch_handle = SchedulerHandle (ThunkID (thunk. id, nothing ), state. worker_chans[gproc. pid]. .. )
915
902
916
903
# TODO : De-dup common fields (log_sink, uid, etc.)
917
- push! (to_send, Any[thunk. id, time_util, alloc_util, fn_type (thunk. f), data, thunk. get_result,
904
+ push! (to_send, Any[thunk. id, time_util, alloc_util, chunktype (thunk. f), data, thunk. get_result,
918
905
thunk. persist, thunk. cache, thunk. meta, options,
919
906
propagated, ids,
920
907
(log_sink= ctx. log_sink, profile= ctx. profile),
0 commit comments