Skip to content

Commit

Permalink
Rename special stream fetchers.
Browse files Browse the repository at this point in the history
  • Loading branch information
maleadt committed Oct 18, 2021
1 parent 27c87a6 commit fe81884
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 17 deletions.
6 changes: 3 additions & 3 deletions docs/src/lib/driver.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@ CUDA.@sync
For specific use cases, special streams are available:

```@docs
CuDefaultStream
CuStreamLegacy
CuStreamPerThread
default_stream
legacy_stream
per_thread_stream
```

## Event Management
Expand Down
22 changes: 11 additions & 11 deletions lib/cudadrv/stream.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Stream management

export
CuStream, CuDefaultStream, CuStreamLegacy, CuStreamPerThread,
CuStream, default_stream, legacy_stream, per_thread_stream,
priority, priority_range, synchronize, device_synchronize

"""
Expand Down Expand Up @@ -29,15 +29,15 @@ mutable struct CuStream
return obj
end

global CuDefaultStream() = new(convert(CUstream, C_NULL), nothing)
global default_stream() = new(convert(CUstream, C_NULL), nothing)

global CuStreamLegacy() = new(convert(CUstream, 1), nothing)
global legacy_stream() = new(convert(CUstream, 1), nothing)

global CuStreamPerThread() = new(convert(CUstream, 2), nothing)
global per_thread_stream() = new(convert(CUstream, 2), nothing)
end

"""
CuDefaultStream()
default_stream()
Return the default stream.
Expand All @@ -46,21 +46,21 @@ Return the default stream.
It is generally better to use `stream()` to get a stream object that's local to the
current task. That way, operations scheduled in other tasks can overlap.
"""
CuDefaultStream()
default_stream()

"""
CuStreamLegacy()
legacy_stream()
Return a special object to use use an implicit stream with legacy synchronization behavior.
You can use this stream to perform operations that should block on all streams (with the
exception of streams created with `STREAM_NON_BLOCKING`). This matches the old pre-CUDA 7
global stream behavior.
"""
CuStreamLegacy()
legacy_stream()

"""
CuStreamPerThread()
per_thread_stream()
Return a special object to use an implicit stream with per-thread synchronization behavior.
This stream object is normally meant to be used with APIs that do not have per-thread
Expand All @@ -72,7 +72,7 @@ versions of their APIs (i.e. without a `ptsz` or `ptds` suffix).
gets its own non-blocking stream, and multithreading in Julia is typically
accomplished using tasks.
"""
CuStreamPerThread()
per_thread_stream()

Base.unsafe_convert(::Type{CUstream}, s::CuStream) = s.handle

Expand Down Expand Up @@ -155,7 +155,7 @@ Block for the current device's tasks to complete. This is a heavyweight operatio
you only need to call [`synchronize`](@ref) which only synchronizes the stream associated
with the current task.
"""
device_synchronize() = synchronize(CuStreamLegacy())
device_synchronize() = synchronize(legacy_stream())

"""
priority_range()
Expand Down
2 changes: 1 addition & 1 deletion lib/cufft/fft.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function CUDA.unsafe_free!(plan::CuFFTPlan, stream::CuStream=stream())
unsafe_free!(plan.workarea, stream)
end

unsafe_finalize!(plan::CuFFTPlan) = unsafe_free!(plan, CuDefaultStream())
unsafe_finalize!(plan::CuFFTPlan) = unsafe_free!(plan, default_stream())

mutable struct cCuFFTPlan{T<:cufftNumber,K,inplace,N} <: CuFFTPlan{T,K,inplace}
handle::cufftHandle
Expand Down
4 changes: 2 additions & 2 deletions src/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ earlier to reduce pressure on the memory allocator.
By default, the operation is performed on the task-local stream. During task or process
finalization however, that stream may be destroyed already, so be sure to specify a safe
stream (i.e. `CuDefaultStream()`, which will ensure the operation will block on other
stream (i.e. `default_stream()`, which will ensure the operation will block on other
streams) when calling this function from a finalizer. For simplicity, the `unsafe_finalize!`
function does exactly that.
"""
Expand Down Expand Up @@ -98,7 +98,7 @@ function unsafe_finalize!(xs::CuArray)
# stream, it synchronizes "too much". we could do better, e.g., by keeping track of all
# streams involved, or by refcounting uses and decrementing that refcount after the
# operation using `cuLaunchHostFunc`. See CUDA.jl#778 and CUDA.jl#780 for details.
unsafe_free!(xs, CuDefaultStream())
unsafe_free!(xs, default_stream())
end


Expand Down
4 changes: 4 additions & 0 deletions src/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@
@deprecate CuCurrentContext() current_context()
@deprecate CuContext(ptr::Union{Ptr,CuPtr}) context(ptr)
@deprecate CuDevice(ptr::Union{Ptr,CuPtr}) device(ptr)

@deprecate CuDefaultStream() default_stream()
@deprecate CuStreamLegacy() legacy_stream()
@deprecate CuStreamPerThread() per_thread_stream()

0 comments on commit fe81884

Please sign in to comment.