提交 588f8a4b authored 作者: Frederic's avatar Frederic

Better error message when Theano isn't able to use cuDNN

上级 a29349fb
......@@ -1788,7 +1788,8 @@ class GCC_compiler(object):
return cxxflags
@staticmethod
def try_compile_tmp(src_code, tmp_prefix='', flags=(), try_run=False):
def try_compile_tmp(src_code, tmp_prefix='', flags=(),
try_run=False, output=False):
"""Try to compile (and run) a test program.
This is useful in various occasions, to check if libraries
......@@ -1799,6 +1800,7 @@ class GCC_compiler(object):
If try_run is False, returns the compilation status.
If try_run is True, returns a (compile_status, run_status) pair.
If output is there, we append the stdout and stderr to the output.
"""
if not theano.config.cxx:
return False
......@@ -1818,14 +1820,14 @@ class GCC_compiler(object):
os.write(fd, src_code)
os.close(fd)
fd = None
p_ret = call_subprocess_Popen(
out, err, p_ret = output_subprocess_Popen(
['g++', path, '-o', exe_path] + flags)
if p_ret != 0:
compilation_ok = False
elif try_run:
# Try to execute the program
try:
p_ret = call_subprocess_Popen([exe_path])
out, err, p_ret = output_subprocess_Popen([exe_path])
run_ok = (p_ret == 0)
finally:
os.remove(exe_path)
......@@ -1839,13 +1841,17 @@ class GCC_compiler(object):
except OSError, e:
compilation_ok = False
if not try_run:
if not try_run and not output:
return compilation_ok
else:
elif not try_run and output:
return (compilation_ok, out, err)
elif not output:
return (compilation_ok, run_ok)
else:
return (compilation_ok, run_ok, out, err)
@staticmethod
def try_flags(flag_list, try_run=False, preambule=""):
def try_flags(flag_list, preambule="", try_run=False, output=False):
'''
Try to compile a dummy file with these flags.
......@@ -1863,7 +1869,8 @@ class GCC_compiler(object):
}
""" % locals())
return GCC_compiler.try_compile_tmp(code, tmp_prefix='try_flags_',
flags=flag_list, try_run=try_run)
flags=flag_list, try_run=try_run,
output=output)
@staticmethod
def compile_str(module_name, src_code, location=None,
......
......@@ -25,9 +25,17 @@ def dnn_available():
dnn_available.msg = "Device not supported by cuDNN"
dnn_available.avail = False
else:
dnn_available.msg = "Can not find the cuDNN library"
dnn_available.avail = all(gof.cmodule.GCC_compiler.try_flags(
["-l", "cudnn"], try_run=True, preambule="#include <cudnn.h>"))
comp, run, out, err = gof.cmodule.GCC_compiler.try_flags(
["-l", "cudnn"], preambule="#include <cudnn.h>",
try_run=True, output=True)
dnn_available.avail = comp and run
if dnn_available.avail:
dnn_available.msg = "cuDNN should work"
else:
dnn_available.msg = (
"Theano is not able to use cuDNN. We got this error: \n" +
err)
return dnn_available.avail
......@@ -1040,6 +1048,7 @@ if cuda_available:
""" Raise a RuntimeError if cudnn can't be used"""
if not dnn_available():
raise RuntimeError(
"cuDNN optimization was enabled, but cuDNN is not available. " +
"cuDNN optimization was enabled, but Theano was not able"
" to use it. We got this error: \n" +
dnn_available.msg)
gpu_seqopt.register("NoCuDNNRaise", NoCuDNNRaise(), 0, 'cudnn')
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论