From 1d83431f20098b85cbb014157e28fccef0db75a9 Mon Sep 17 00:00:00 2001 From: Deniz Yuret Date: Fri, 20 Sep 2019 06:16:09 +0300 Subject: [PATCH] Use CuArrays.usage_limit[] to improve stability --- src/Knet.jl | 13 +++++++++---- src/cuarray.jl | 2 +- test/binary.jl | 3 ++- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/Knet.jl b/src/Knet.jl index 30e7264c9..446fcc10b 100644 --- a/src/Knet.jl +++ b/src/Knet.jl @@ -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 diff --git a/src/cuarray.jl b/src/cuarray.jl index c4f758c63..9409e7fc0 100644 --- a/src/cuarray.jl +++ b/src/cuarray.jl @@ -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()) diff --git a/test/binary.jl b/test/binary.jl index 9ad4b8640..bf0056888 100644 --- a/test/binary.jl +++ b/test/binary.jl @@ -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