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