Skip to content

Commit 9de1478

Browse files
committed
don't create new context on init
1 parent c38ce0a commit 9de1478

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/backends/cudanative/cudanative.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,14 @@ global init, all_contexts, current_context
4040
let contexts = CUContext[]
4141
all_contexts() = copy(contexts)::Vector{CUContext}
4242
current_context() = last(contexts)::CUContext
43-
function init(;ctx = any_context())
43+
function init(;ctx = nothing)
44+
ctx = if ctx == nothing
45+
if isempty(contexts)
46+
any_context()
47+
else
48+
current_context()
49+
end
50+
end
4451
GPUArrays.make_current(ctx)
4552
push!(contexts, ctx)
4653
ctx

test/runtests.jl

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,9 @@ macro allbackends(title, backendname::Symbol, block)
1818
$(esc(backendname)) = backend
1919
$(esc(block))
2020
end
21-
if backend == :cudanative
22-
println("GPUMem: ", CUDAdrv.Mem.used() / 10^6)
23-
gc()
24-
println(" gc: ", CUDAdrv.Mem.used() / 10^6)
25-
end
21+
info("GPUMem: ", CUDAdrv.Mem.used() / 10^6)
22+
gc()
23+
info(" gc: ", CUDAdrv.Mem.used() / 10^6)
2624
end
2725
end
2826
end

0 commit comments

Comments
 (0)