提交 ce0a3f02 authored 作者: Frederic's avatar Frederic 提交者: Arnaud Bergeron

If the gpu isn't working don't raise an error uselessly

上级 d6b799f8
...@@ -113,23 +113,42 @@ class NanGuardMode(Mode): ...@@ -113,23 +113,42 @@ class NanGuardMode(Mode):
""" """
def __init__(self, nan_is_error, inf_is_error, big_is_error=True): def __init__(self, nan_is_error, inf_is_error, big_is_error=True):
cuda_compile_failed = False
if cuda.cuda_available: if cuda.cuda_available:
self.guard_input = cuda.fvector('nan_guard') self.guard_input = cuda.fvector('nan_guard')
if nan_is_error or inf_is_error: if nan_is_error or inf_is_error:
self.gpumin = theano.function( try:
[self.guard_input], T.min(self.guard_input), self.gpumin = theano.function(
mode='FAST_RUN' [self.guard_input], T.min(self.guard_input),
) mode='FAST_RUN'
if inf_is_error: )
self.gpumax = theano.function( except RuntimeError:
[self.guard_input], T.max(self.guard_input), # This can happen if cuda is available, but the
mode='FAST_RUN' # device is in exclusive mode and used by another
) # process.
if big_is_error: cuda_compile_failed = True
self.gpuabsmax = theano.function( if inf_is_error and not cuda_compile_failed:
[self.guard_input], T.max(T.abs_(self.guard_input)), try:
mode='FAST_RUN' self.gpumax = theano.function(
) [self.guard_input], T.max(self.guard_input),
mode='FAST_RUN'
)
except RuntimeError:
# This can happen if cuda is available, but the
# device is in exclusive mode and used by another
# process.
cuda_compile_failed = True
if big_is_error and not cuda_compile_failed:
try:
self.gpuabsmax = theano.function(
[self.guard_input], T.max(T.abs_(self.guard_input)),
mode='FAST_RUN'
)
except RuntimeError:
# This can happen if cuda is available, but the
# device is in exclusive mode and used by another
# process.
cuda_compile_failed = True
def do_check_on(var, nd, f, is_input): def do_check_on(var, nd, f, is_input):
""" """
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论