Skip to content

Commit

Permalink
Merge pull request #88 from JuliaGPU/teh/stream
Browse files Browse the repository at this point in the history
Fix Stream construction
  • Loading branch information
vchuravy authored May 30, 2017
2 parents 8dd0042 + 58aa3d9 commit dc286ac
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/stream.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ end
function Stream()
p = Ref{Ptr{Void}}()
rt.cudaStreamCreate(p)
hnd = CuStream(p[])
ctx = contexts[device()]
hnd = CuStream(p[], ctx)
Stream(hnd, AsyncCondition())
end
NullStream() = Stream(CUDAdrv.CuDefaultStream(), AsyncCondition())
Expand Down
25 changes: 22 additions & 3 deletions test/test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,34 @@ end
gc() # check for finalizer errors

#########################################
# Multiple devices, streams, and wait() #
# Streams, multiple devices, and wait() #
#########################################
devices(dev->CUDArt.capability(dev)[1] >= 2, nmax=1) do devlist
sleeptime = 0.5
dev = first(devlist)
device(dev)
stream = Stream()
# Force one run to precompile
cudasleep(sleeptime; dev=dev, stream=stream)
wait(stream)
# Since the frequency is dynamic, cudasleep can be unreliable (at
# least on some GPUs), so do a median-of-3
sleeptimes = Float64[0, 0, 0]
for i = 1:3
tstart = time()
cudasleep(sleeptime; dev=dev, stream=stream)
wait(stream)
tstop = time()
sleeptimes[i] = tstop - tstart
end
@test 0.9*sleeptime <= median(sleeptimes) <= 1.1*sleeptime
end

if devcount() > 1
devices(dev->true, nmax=2) do devlist
sleeptime = 0.5
results = Array{Any}(ceil(Int, 2.5*length(devlist)))
streams = [(device(dev); Stream()) for dev in devlist]
# Force one run to precompile
cudasleep(sleeptime; dev=devlist[1], stream=streams[1])
wait(streams[1])
i = 1
nextidx() = (idx=i; i+=1; idx)
Expand Down

0 comments on commit dc286ac

Please sign in to comment.