Skip to content

Commit

Permalink
Sch: Minimize calls to reschedule_inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
jpsamaroo committed May 16, 2022
1 parent 2f47217 commit c17b86d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/sch/Sch.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Fields:
- `waiting_data::Dict{Union{Thunk,Chunk},Set{Thunk}}` - Map from input `Chunk`/upstream `Thunk` to all unfinished downstream `Thunk`s, to retain caches
- `ready::Vector{Thunk}` - The list of `Thunk`s that are ready to execute
- `cache::WeakKeyDict{Thunk, Any}` - Maps from a finished `Thunk` to it's cached result, often a DRef
- `valid::WeakKeyDict{Thunk, Nothing}` - Tracks all `Thunk`s that are in a valid scheduling state
- `running::Set{Thunk}` - The set of currently-running `Thunk`s
- `running_on::Dict{Thunk,OSProc}` - Map from `Thunk` to the OS process executing it
- `thunk_dict::Dict{Int, WeakThunk}` - Maps from thunk IDs to a `Thunk`
Expand All @@ -70,6 +71,7 @@ struct ComputeState
waiting_data::Dict{Union{Thunk,Chunk},Set{Thunk}}
ready::Vector{Thunk}
cache::WeakKeyDict{Thunk, Any}
valid::WeakKeyDict{Thunk, Nothing}
running::Set{Thunk}
running_on::Dict{Thunk,OSProc}
thunk_dict::Dict{Int, WeakThunk}
Expand All @@ -93,7 +95,8 @@ function start_state(deps::Dict, node_order, chan)
OneToMany(),
deps,
Vector{Thunk}(undef, 0),
Dict{Thunk, Any}(),
WeakKeyDict{Thunk, Any}(),
WeakKeyDict{Thunk, Nothing}(),
Set{Thunk}(),
Dict{Thunk,OSProc}(),
Dict{Int, WeakThunk}(),
Expand All @@ -119,6 +122,7 @@ function start_state(deps::Dict, node_order, chan)
else
state.waiting[k] = waiting
end
state.valid[k] = nothing
end
end
state
Expand Down
1 change: 1 addition & 0 deletions src/sch/dynamic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ function _add_thunk!(ctx, state, task, tid, (f, args, kwargs, future, ref))
# Preserve the `EagerThunkFinalizer` through `thunk`
thunk.eager_ref = ref
end
state.valid[thunk] = nothing
put!(state.chan, RescheduleSignal())
timespan_finish(ctx, :add_thunk, tid, 0)
return thunk_id
Expand Down
3 changes: 3 additions & 0 deletions src/sch/util.jl
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ function reschedule_inputs!(state, thunk, seen=Set{Thunk}())
while !isempty(to_visit)
thunk = pop!(to_visit)
push!(seen, thunk)
if haskey(state.valid, thunk)
continue
end
if haskey(state.cache, thunk) || (thunk in state.ready) || (thunk in state.running)
continue
end
Expand Down

0 comments on commit c17b86d

Please sign in to comment.