Skip to content

Commit 1ec8563

Browse files
committed
processor: Workaround dynamic dispatch in prio queue
1 parent 6fd94eb commit 1ec8563

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

src/sch/Sch.jl

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,10 +1061,18 @@ function Base.notify(db::Doorbell)
10611061
end
10621062
end
10631063

1064+
struct TaskSpecKey
1065+
task_id::Int
1066+
task_spec::Vector{Any}
1067+
TaskSpecKey(task_spec::Vector{Any}) = new(task_spec[1], task_spec)
1068+
end
1069+
Base.getindex(key::TaskSpecKey) = key.task_spec
1070+
Base.hash(key::TaskSpecKey, h::UInt) = hash(key.task_id, hash(TaskSpecKey, h))
1071+
10641072
struct ProcessorInternalState
10651073
ctx::Context
10661074
proc::Processor
1067-
queue::LockedObject{PriorityQueue{Vector{Any}, UInt32, Base.Order.ForwardOrdering}}
1075+
queue::LockedObject{PriorityQueue{TaskSpecKey, UInt32, Base.Order.ForwardOrdering}}
10681076
reschedule::Doorbell
10691077
tasks::Dict{Int,Task}
10701078
proc_occupancy::Base.RefValue{UInt32}
@@ -1175,7 +1183,8 @@ function start_processor_runner!(istate::ProcessorInternalState, uid::UInt64, re
11751183
if length(queue) == 0
11761184
return nothing
11771185
end
1178-
task, occupancy = peek(queue)
1186+
task_spec, occupancy = peek(queue)
1187+
task = task_spec[]
11791188
scope = task[5]
11801189
if !isa(constrain(scope, Dagger.ExactScope(to_proc)),
11811190
Dagger.InvalidScope) &&
@@ -1202,7 +1211,8 @@ function start_processor_runner!(istate::ProcessorInternalState, uid::UInt64, re
12021211
end
12031212

12041213
@label execute
1205-
task, task_occupancy = task_and_occupancy
1214+
task_spec, task_occupancy = task_and_occupancy
1215+
task = task_spec[]
12061216
thunk_id = task[1]
12071217
time_util = task[2]
12081218
timespan_finish(ctx, :proc_run_fetch, to_proc, (;thunk_id, proc_occupancy=proc_occupancy[], task_occupancy))
@@ -1272,7 +1282,7 @@ function do_tasks(to_proc, return_queue, tasks)
12721282
uid = first(tasks)[18]
12731283
state = proc_states(uid) do states
12741284
get!(states, to_proc) do
1275-
queue = PriorityQueue{Vector{Any}, UInt32}()
1285+
queue = PriorityQueue{TaskSpecKey, UInt32}()
12761286
queue_locked = LockedObject(queue)
12771287
reschedule = Doorbell()
12781288
istate = ProcessorInternalState(ctx, to_proc,
@@ -1302,7 +1312,7 @@ function do_tasks(to_proc, return_queue, tasks)
13021312
end
13031313
end
13041314
should_launch || continue
1305-
enqueue!(queue, task, occupancy)
1315+
enqueue!(queue, TaskSpecKey(task), occupancy)
13061316
timespan_finish(ctx, :enqueue, (;to_proc, thunk_id), nothing)
13071317
@dagdebug thunk_id :processor "Enqueued task"
13081318
end

0 commit comments

Comments
 (0)