Skip to content

Commit

Permalink
Merge pull request JuliaGPU#205 from JuliaGPU/tb/query
Browse files Browse the repository at this point in the history
Add query for stream and event.
  • Loading branch information
maleadt committed Feb 6, 2020
2 parents e47a654 + 259059b commit 0336a6b
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/events.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,23 @@ Waits for an event to complete.
"""
synchronize(e::CuEvent) = cuEventSynchronize(e)

"""
query(e::CuEvent)
Return `false` if there is outstanding work preceding the most recent
call to `record(e)` and `true` if all captured work has been completed.
"""
function query(e::CuEvent)
res = unsafe_cuEventQuery(e)
if res === ERROR_NOT_READY
return false
elseif res === SUCCESS
return true
else
throw_api_error(res)
end
end

"""
wait(e::CuEvent, stream=CuDefaultStream())
Expand Down
17 changes: 17 additions & 0 deletions src/stream.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,20 @@ Return the default stream.
Wait until a stream's tasks are completed.
"""
synchronize(s::CuStream) = cuStreamSynchronize(s)

"""
query(s::CuStream)
Return `false` if a stream is busy (has task running or queued)
and `true` if that stream is free.
"""
function query(s::CuStream)
res = unsafe_cuStreamQuery(s)
if res === ERROR_NOT_READY
return false
elseif res === SUCCESS
return true
else
throw_api_error(res)
end
end
5 changes: 5 additions & 0 deletions test/events.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ CuEvent(CUDAdrv.EVENT_BLOCKING_SYNC | CUDAdrv.EVENT_DISABLE_TIMING)
synchronize()
end

@testset "event query" begin
event = CuEvent()
@test CUDAdrv.query(event) == true
end

@testset "elapsed stream" begin
stream = CuStream()
@test (CUDAdrv.@elapsed stream begin end) > 0
Expand Down
2 changes: 2 additions & 0 deletions test/stream.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
let
s = CuStream()
synchronize(s)
@test CUDAdrv.query(s) == true

let s2 = CuStream()
@test s != s2
end
Expand Down

0 comments on commit 0336a6b

Please sign in to comment.