Skip to content

Commit

Permalink
Use CuArrays.usage_limit[] to improve stability
Browse files Browse the repository at this point in the history
  • Loading branch information
denizyuret committed Sep 20, 2019
1 parent ed1bae9 commit 1d83431
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
13 changes: 9 additions & 4 deletions src/Knet.jl
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,17 @@ dir(path...) = joinpath(dirname(@__DIR__),path...)
# See if we have a gpu at initialization:
function __init__()
try
r = gpu(true)
r >= 0 && AutoGrad.set_gc_function(knetgcnode)
#@info(r >= 0 ? "Knet using GPU $r" : "No GPU found, Knet using the CPU")
dev = gpu(true)
if dev >= 0
CuArrays.usage_limit[] = gpufree() - 100_000_000
AutoGrad.set_gc_function(knetgcnode)
@debug "Knet using GPU $dev"
else
@debug "No GPU found, Knet using the CPU"
end
catch e
gpu(false)
#@warn("Knet using the CPU: $e")
@warn "Knet cannot use the GPU: $e"
end
end

Expand Down
2 changes: 1 addition & 1 deletion src/cuarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

if find_cuda_library("cuda", tk) != nothing # has_cuda()
try
using CuArrays: CuPtr, unsafe_free!
using CuArrays: CuArrays, CuPtr, unsafe_free!, usage_limit
import CuArrays: CuArray
catch ex
@warn "CUDA is installed, but CuArrays.jl fails to load" exception=(ex,catch_backtrace())
Expand Down
3 changes: 2 additions & 1 deletion test/binary.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
include("header.jl")
#using Dates
#date(x)=(join(stdout,[Dates.format(Dates.now(),"HH:MM:SS"), x,'\n'],' '); flush(stdout))
date(x)=(println(round(Int,time())%3600, ':', x); flush(stdout))
time0 = time()
date(x)=(println(round(Int,time()-time0), ':', x); flush(stdout))
macro dbg(_x); end
#macro dbg(_x); :(@show $(esc(_x))); end

Expand Down

0 comments on commit 1d83431

Please sign in to comment.