@@ -59,7 +59,7 @@ Fields:
59
59
- worker_loadavg::Dict{Int,NTuple{3,Float64}} - Worker load average
60
60
- worker_chans::Dict{Int, Tuple{RemoteChannel,RemoteChannel}} - Communication channels between the scheduler and each worker
61
61
- procs_cache_list::Base.RefValue{Union{ProcessorCacheEntry,Nothing}} - Cached linked list of processors ready to be used
62
- - function_cost_cache::Dict{Function ,Float64} - Cache of estimated CPU time required to compute the function
62
+ - function_cost_cache::Dict{Type{<:Tuple} ,Float64} - Cache of estimated CPU time required to compute the given signature
63
63
- halt::Base.RefValue{Bool} - Flag indicating, when set, that the scheduler should halt immediately
64
64
- lock::ReentrantLock() - Lock around operations which modify the state
65
65
- futures::Dict{Thunk, Vector{ThunkFuture}} - Futures registered for waiting on the result of a thunk.
@@ -82,7 +82,7 @@ struct ComputeState
82
82
worker_loadavg:: Dict{Int,NTuple{3,Float64}}
83
83
worker_chans:: Dict{Int, Tuple{RemoteChannel,RemoteChannel}}
84
84
procs_cache_list:: Base.RefValue{Union{ProcessorCacheEntry,Nothing}}
85
- function_cost_cache:: Dict{Function ,Float64}
85
+ function_cost_cache:: Dict{Type{<:Tuple} ,Float64}
86
86
halt:: Base.RefValue{Bool}
87
87
lock:: ReentrantLock
88
88
futures:: Dict{Thunk, Vector{ThunkFuture}}
@@ -106,7 +106,7 @@ function start_state(deps::Dict, node_order, chan)
106
106
Dict {Int,NTuple{3,Float64}} (),
107
107
Dict {Int, Tuple{RemoteChannel,RemoteChannel}} (),
108
108
Ref {Union{ProcessorCacheEntry,Nothing}} (nothing ),
109
- Dict {Function ,Float64} (),
109
+ Dict {Type{<:Tuple} ,Float64} (),
110
110
Ref {Bool} (false ),
111
111
ReentrantLock (),
112
112
Dict {Thunk, Vector{ThunkFuture}} (),
@@ -386,7 +386,8 @@ function compute_dag(ctx, d::Thunk; options=SchedulerOptions())
386
386
state. worker_pressure[pid][typeof (proc)] = metadata. pressure
387
387
state. worker_loadavg[pid] = metadata. loadavg
388
388
node = state. thunk_dict[thunk_id]
389
- state. function_cost_cache[node. f] = (metadata. threadtime + get (state. function_cost_cache, node. f, 0.0 )) / 2
389
+ sig = signature (node, state)
390
+ state. function_cost_cache[sig] = (metadata. threadtime + get (state. function_cost_cache, sig, 0.0 )) / 2
390
391
state. cache[node] = res
391
392
if node. options != = nothing && node. options. checkpoint != = nothing
392
393
try
@@ -489,14 +490,14 @@ function schedule!(ctx, state, procs=procs_to_use(ctx))
489
490
490
491
return true
491
492
end
492
- function has_capacity (p, gp, procutil, f )
493
+ function has_capacity (p, gp, procutil, sig )
493
494
T = typeof (p)
494
495
extra_util = get (procutil, T, 1.0 )
495
496
real_util = state. worker_pressure[gp][T]
496
- if (T === Dagger. ThreadProc) && haskey (state. function_cost_cache, f )
497
+ if (T === Dagger. ThreadProc) && haskey (state. function_cost_cache, sig )
497
498
# Assume that the extra pressure is between estimated and measured
498
499
# TODO : Generalize this to arbitrary processor types
499
- extra_util = min (extra_util, state. function_cost_cache[f ])
500
+ extra_util = min (extra_util, state. function_cost_cache[sig ])
500
501
end
501
502
# TODO : update real_util based on loadavg
502
503
cap = state. worker_capacity[gp][T]
@@ -514,15 +515,16 @@ function schedule!(ctx, state, procs=procs_to_use(ctx))
514
515
# Select a new task and get its options
515
516
task = pop! (state. ready)
516
517
opts = merge (ctx. options, task. options)
518
+ sig = signature (task, state)
517
519
518
520
# Try to select a processor
519
521
selected_entry = nothing
520
522
entry = state. procs_cache_list[]
521
523
cap, extra_util = nothing , nothing
522
524
procs_found = false
523
525
# N.B. if we only have one processor, we need to select it now
524
- if can_use_proc (task, entry. proc, opts)
525
- has_cap, cap, extra_util = has_capacity (entry. proc, entry. gproc. pid, opts. procutil, task . f )
526
+ if can_use_proc (task, entry. gproc, entry . proc, opts)
527
+ has_cap, cap, extra_util = has_capacity (entry. proc, entry. gproc. pid, opts. procutil, sig )
526
528
if has_cap
527
529
selected_entry = entry
528
530
else
@@ -542,8 +544,8 @@ function schedule!(ctx, state, procs=procs_to_use(ctx))
542
544
end
543
545
end
544
546
545
- if can_use_proc (task, entry. proc, opts)
546
- has_cap, cap, extra_util = has_capacity (entry. proc, entry. gproc. pid, opts. procutil, task . f )
547
+ if can_use_proc (task, entry. gproc, entry . proc, opts)
548
+ has_cap, cap, extra_util = has_capacity (entry. proc, entry. gproc. pid, opts. procutil, sig )
547
549
if has_cap
548
550
# Select this processor
549
551
selected_entry = entry
0 commit comments