Skip to content

Commit 9db56f1

Browse files
committed
add wait on event with progress callback
1 parent 9f96e25 commit 9db56f1

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

src/backends/cpu.jl

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,15 @@ struct CPUEvent <: Event
22
task::Core.Task
33
end
44

5-
function wait(ev::CPUEvent)
6-
wait(ev.task)
5+
function wait(ev::CPUEvent, progress=nothing)
6+
if progress === nothing
7+
wait(ev.task)
8+
else
9+
while !Base.istaskdone(ev.task)
10+
progress()
11+
yield() # yield to the scheduler
12+
end
13+
end
714
end
815

916
function (obj::Kernel{CPU})(args...; ndrange=nothing, workgroupsize=nothing, dependencies=nothing)

src/backends/cuda.jl

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,15 @@ end
1919
struct CudaEvent <: Event
2020
event::CuEvent
2121
end
22-
function wait(ev::CudaEvent)
23-
# TODO: MPI/libuv progress
24-
CUDAdrv.wait(ev.event)
22+
function wait(ev::CudaEvent, progress=nothing)
23+
if progress === nothing
24+
CUDAdrv.wait(ev.event)
25+
else
26+
while !CUDAdrv.query(ev.event)
27+
progress()
28+
# do we need to `yield` here?
29+
end
30+
end
2531
end
2632

2733
@init begin

0 commit comments

Comments
 (0)