Skip to content
This repository was archived by the owner on Mar 12, 2021. It is now read-only.

Commit 8635a2f

Browse files
committed
Adapt to initialization API changes.
1 parent 9ebe74e commit 8635a2f

File tree

15 files changed

+39
-43
lines changed

15 files changed

+39
-43
lines changed

Manifest.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ version = "2.0.0"
3030

3131
[[CUDAdrv]]
3232
deps = ["CEnum", "CUDAapi", "Printf"]
33-
git-tree-sha1 = "5a9dd9ec20a5a2c78c784c31361cf5a813c7a9c2"
33+
git-tree-sha1 = "5c2cf00a78503e1f71409cecf3d64508fb33f17f"
3434
repo-rev = "master"
3535
repo-url = "https://github.com/JuliaGPU/CUDAdrv.jl.git"
3636
uuid = "c5f51814-7f29-56b8-a69c-e4d8f6be1fde"
3737
version = "4.0.4"
3838

3939
[[CUDAnative]]
4040
deps = ["Adapt", "CEnum", "CUDAapi", "CUDAdrv", "DataStructures", "InteractiveUtils", "LLVM", "Libdl", "Printf", "TimerOutputs"]
41-
git-tree-sha1 = "1a04a76171016f68f4790e9643524a3ac31f3d32"
41+
git-tree-sha1 = "8b1a585344fee94bdb95ac44653fd057d74e32e6"
4242
repo-rev = "master"
4343
repo-url = "https://github.com/JuliaGPU/CUDAnative.jl.git"
4444
uuid = "be33ccc6-a3ff-5ff2-a52e-74243cff1e17"

src/blas/CUBLAS.jl

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ const active_xt_handles = Vector{Union{Nothing,cublasXtHandle_t}}()
3535
function handle()
3636
tid = Threads.threadid()
3737
if @inbounds active_handles[tid] === nothing
38-
context = CuGetContext()
39-
active_handles[tid] = get!(created_handles, context) do
38+
ctx = context()
39+
active_handles[tid] = get!(created_handles, ctx) do
4040
handle = cublasCreate_v2()
41-
atexit(()->CUDAdrv.isvalid(context) && cublasDestroy_v2(handle))
41+
atexit(()->CUDAdrv.isvalid(ctx) && cublasDestroy_v2(handle))
4242

4343
# enable tensor math mode if our device supports it, and fast math is enabled
44-
dev = CUDAdrv.device(context)
44+
dev = CUDAdrv.device()
4545
if Base.JLOptions().fast_math == 1 && CUDAdrv.capability(dev) >= v"7.0" && version() >= v"9"
4646
cublasSetMathMode(CUBLAS_TENSOR_OP_MATH, handle)
4747
end
@@ -55,11 +55,10 @@ end
5555
function xt_handle()
5656
tid = Threads.threadid()
5757
if @inbounds active_xt_handles[tid] === nothing
58-
CUDAnative.maybe_initialize("cublasXtGetHandle")
59-
context = CuCurrentContext()
60-
active_xt_handles[tid] = get!(created_xt_handles, context) do
58+
ctx = context()
59+
active_xt_handles[tid] = get!(created_xt_handles, ctx) do
6160
handle = cublasXtCreate()
62-
atexit(()->CUDAdrv.isvalid(context) && cublasXtDestroy(handle))
61+
atexit(()->CUDAdrv.isvalid(ctx) && cublasXtDestroy(handle))
6362

6463
# select the devices
6564
# TODO: this is weird, since we typically use a single device per thread/context
@@ -79,7 +78,7 @@ function __init__()
7978
resize!(active_xt_handles, Threads.nthreads())
8079
fill!(active_xt_handles, nothing)
8180

82-
CUDAnative.atcontextswitch() do tid, ctx, dev
81+
CUDAnative.atcontextswitch() do tid, ctx
8382
# we don't eagerly initialize handles, but do so lazily when requested
8483
active_handles[tid] = nothing
8584
active_xt_handles[tid] = nothing

src/blas/error.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ end
5555
macro check(ex)
5656
fun = Symbol(decode_ccall_function(ex))
5757
init = if !in(fun, preinit_apicalls)
58-
:(CUDAnative.maybe_initialize($(QuoteNode(fun))))
58+
:(CUDAnative.maybe_initialize())
5959
end
6060
quote
6161
$init

src/dnn/CUDNN.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ const active_handles = Vector{Union{Nothing,cudnnHandle_t}}()
4747
function handle()
4848
tid = Threads.threadid()
4949
if @inbounds active_handles[tid] === nothing
50-
context = CuGetContext()
51-
active_handles[tid] = get!(created_handles, context) do
50+
ctx = context()
51+
active_handles[tid] = get!(created_handles, ctx) do
5252
handle = cudnnCreate()
53-
atexit(()->CUDAdrv.isvalid(context) && cudnnDestroy(handle))
53+
atexit(()->CUDAdrv.isvalid(ctx) && cudnnDestroy(handle))
5454
handle
5555
end
5656
end
@@ -61,7 +61,7 @@ function __init__()
6161
resize!(active_handles, Threads.nthreads())
6262
fill!(active_handles, nothing)
6363

64-
CUDAnative.atcontextswitch() do tid, ctx, dev
64+
CUDAnative.atcontextswitch() do tid, ctx
6565
# we don't eagerly initialize handles, but do so lazily when requested
6666
active_handles[tid] = nothing
6767
end

src/dnn/error.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ end
3030
macro check(ex)
3131
fun = Symbol(decode_ccall_function(ex))
3232
init = if !in(fun, preinit_apicalls)
33-
:(CUDAnative.maybe_initialize($(QuoteNode(fun))))
33+
:(CUDAnative.maybe_initialize())
3434
end
3535
quote
3636
$init

src/fft/error.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ end
6868
macro check(ex)
6969
fun = Symbol(decode_ccall_function(ex))
7070
init = if !in(fun, preinit_apicalls)
71-
:(CUDAnative.maybe_initialize($(QuoteNode(fun))))
71+
:(CUDAnative.maybe_initialize())
7272
end
7373
quote
7474
$init

src/memory.jl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -280,9 +280,7 @@ synchronized right before and after executing `ex` to exclude any external effec
280280
macro time(ex)
281281
quote
282282
# @time might surround an application, so be sure to initialize CUDA before that
283-
# FIXME: this should be done in CUDAdrv (`synchronize(ctx=CuCurrentOrNewContext()`)
284-
# but the CUDA initialization mechanics are part of CUDAnative.jl
285-
CUDAnative.maybe_initialize("@time")
283+
CUDAnative.maybe_initialize()
286284

287285
# coarse synchronization to exclude effects from previously-executed code
288286
CUDAdrv.synchronize()

src/rand/CURAND.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ const active_generators = Vector{Union{Nothing,RNG}}()
3030
function generator()
3131
tid = Threads.threadid()
3232
if @inbounds active_generators[tid] === nothing
33-
context = CuGetContext()
34-
active_generators[tid] = get!(created_generators, context) do
33+
ctx = context()
34+
active_generators[tid] = get!(created_generators, ctx) do
3535
RNG()
3636
end
3737
end
@@ -42,7 +42,7 @@ function __init__()
4242
resize!(active_generators, Threads.nthreads())
4343
fill!(active_generators, nothing)
4444

45-
CUDAnative.atcontextswitch() do tid, ctx, dev
45+
CUDAnative.atcontextswitch() do tid, ctx
4646
# we don't eagerly initialize handles, but do so lazily when requested
4747
active_generators[tid] = nothing
4848
end

src/rand/error.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ end
6060
macro check(ex)
6161
fun = Symbol(decode_ccall_function(ex))
6262
init = if !in(fun, preinit_apicalls)
63-
:(CUDAnative.maybe_initialize($(QuoteNode(fun))))
63+
:(CUDAnative.maybe_initialize())
6464
end
6565
quote
6666
$init

src/solver/CUSOLVER.jl

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ const active_sparse_handles = Vector{Union{Nothing,cusolverSpHandle_t}}()
3737
function dense_handle()
3838
tid = Threads.threadid()
3939
if @inbounds active_dense_handles[tid] === nothing
40-
context = CuGetContext()
41-
active_dense_handles[tid] = get!(created_dense_handles, context) do
40+
ctx = context()
41+
active_dense_handles[tid] = get!(created_dense_handles, ctx) do
4242
handle = cusolverDnCreate()
43-
atexit(()->CUDAdrv.isvalid(context) && cusolverDnDestroy(handle))
43+
atexit(()->CUDAdrv.isvalid(ctx) && cusolverDnDestroy(handle))
4444
handle
4545
end
4646
end
@@ -50,11 +50,10 @@ end
5050
function sparse_handle()
5151
tid = Threads.threadid()
5252
if @inbounds active_sparse_handles[tid] === nothing
53-
CUDAnative.maybe_initialize("cublasXtGetHandle")
54-
context = CuCurrentContext()
55-
active_sparse_handles[tid] = get!(created_sparse_handles, context) do
53+
ctx = context()
54+
active_sparse_handles[tid] = get!(created_sparse_handles, ctx) do
5655
handle = cusolverSpCreate()
57-
atexit(()->CUDAdrv.isvalid(context) && cusolverSpDestroy(handle))
56+
atexit(()->CUDAdrv.isvalid(ctx) && cusolverSpDestroy(handle))
5857
handle
5958
end
6059
end
@@ -68,7 +67,7 @@ function __init__()
6867
resize!(active_sparse_handles, Threads.nthreads())
6968
fill!(active_sparse_handles, nothing)
7069

71-
CUDAnative.atcontextswitch() do tid, ctx, dev
70+
CUDAnative.atcontextswitch() do tid, ctx
7271
# we don't eagerly initialize handles, but do so lazily when requested
7372
active_dense_handles[tid] = nothing
7473
active_sparse_handles[tid] = nothing

src/solver/error.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ end
5050
macro check(ex)
5151
fun = Symbol(decode_ccall_function(ex))
5252
init = if !in(fun, preinit_apicalls)
53-
:(CUDAnative.maybe_initialize($(QuoteNode(fun))))
53+
:(CUDAnative.maybe_initialize())
5454
end
5555
quote
5656
$init

src/sparse/CUSPARSE.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ const active_handles = Vector{Union{Nothing,cusparseHandle_t}}()
3535
function handle()
3636
tid = Threads.threadid()
3737
if @inbounds active_handles[tid] === nothing
38-
context = CuGetContext()
39-
active_handles[tid] = get!(created_handles, context) do
38+
ctx = context()
39+
active_handles[tid] = get!(created_handles, ctx) do
4040
handle = cusparseCreate()
41-
atexit(()->CUDAdrv.isvalid(context) && cusparseDestroy(handle))
41+
atexit(()->CUDAdrv.isvalid(ctx) && cusparseDestroy(handle))
4242
handle
4343
end
4444
end
@@ -49,7 +49,7 @@ function __init__()
4949
resize!(active_handles, Threads.nthreads())
5050
fill!(active_handles, nothing)
5151

52-
CUDAnative.atcontextswitch() do tid, ctx, dev
52+
CUDAnative.atcontextswitch() do tid, ctx
5353
# we don't eagerly initialize handles, but do so lazily when requested
5454
active_handles[tid] = nothing
5555
end

src/sparse/error.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ end
6060
macro check(ex)
6161
fun = Symbol(decode_ccall_function(ex))
6262
init = if !in(fun, preinit_apicalls)
63-
:(CUDAnative.maybe_initialize($(QuoteNode(fun))))
63+
:(CUDAnative.maybe_initialize())
6464
end
6565
quote
6666
$init

src/tensor/CUTENSOR.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ const active_handles = Vector{Union{Nothing,Ref{cutensorHandle_t}}}()
3434
function handle()
3535
tid = Threads.threadid()
3636
if @inbounds active_handles[tid] === nothing
37-
context = CuGetContext()
38-
active_handles[tid] = get!(created_handles, context) do
37+
ctx = context()
38+
active_handles[tid] = get!(created_handles, ctx) do
3939
handle = Ref{cutensorHandle_t}()
4040
cutensorInit(handle)
4141
handle
@@ -48,7 +48,7 @@ function __init__()
4848
resize!(active_handles, Threads.nthreads())
4949
fill!(active_handles, nothing)
5050

51-
CUDAnative.atcontextswitch() do tid, ctx, dev
51+
CUDAnative.atcontextswitch() do tid, ctx
5252
# we don't eagerly initialize handles, but do so lazily when requested
5353
active_handles[tid] = nothing
5454
end

src/tensor/error.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ end
6363
macro check(ex)
6464
fun = Symbol(decode_ccall_function(ex))
6565
init = if !in(fun, preinit_apicalls)
66-
:(CUDAnative.maybe_initialize($(QuoteNode(fun))))
66+
:(CUDAnative.maybe_initialize())
6767
end
6868
quote
6969
$init

0 commit comments

Comments
 (0)