提交 12e948a5 authored 作者: lamblin's avatar lamblin

Merge pull request #1267 from nouiz/march

Fix march on windows
......@@ -1481,12 +1481,10 @@ def gcc_llvm():
"""
if gcc_llvm.is_llvm is None:
pass
dummy_in = open(os.devnull)
p = None
try:
p = call_subprocess_Popen(['g++', '--version'],
stdout=subprocess.PIPE,
stdin=dummy_in.fileno(),
stderr=subprocess.PIPE)
p.wait()
output = p.stdout.read() + p.stderr.read()
......@@ -1499,7 +1497,6 @@ def gcc_llvm():
# will crash later so supposing it is not llvm is "safe".
output = ''
del p
del dummy_in
gcc_llvm.is_llvm = "llvm" in output
return gcc_llvm.is_llvm
gcc_llvm.is_llvm = None
......@@ -1547,8 +1544,9 @@ class GCC_compiler(object):
def get_lines(cmd, parse=True):
p = call_subprocess_Popen(cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
stdout=subprocess.PIPE, shell=True)
shell=True)
p.wait()
stdout = p.stdout.readlines()
stderr = p.stderr.readlines()
......@@ -1566,7 +1564,8 @@ class GCC_compiler(object):
lines = stdout + stderr
return lines
native_lines = get_lines("g++ -march=native -E -v - </dev/null")
# The '-' at the end is needed. Otherwise, g++ do not output enough information.
native_lines = get_lines("g++ -march=native -E -v -")
_logger.info("g++ -march=native selected lines: %s", native_lines)
if len(native_lines) != 1:
_logger.warn(
......@@ -1577,7 +1576,7 @@ class GCC_compiler(object):
" Theano's mailing list such that we fix this"
" problem:\n %s", native_lines)
else:
default_lines = get_lines("g++ -E -v - </dev/null")
default_lines = get_lines("g++ -E -v -")
_logger.info("g++ default lines: %s", default_lines)
if len(default_lines) < 1:
_logger.warn(
......@@ -1588,7 +1587,7 @@ class GCC_compiler(object):
" function. Can you submit the following lines to"
" Theano's mailing list such that we fix this"
" problem:\n %s",
get_lines("g++ -E -v - </dev/null", parse=False))
get_lines("g++ -E -v -", parse=False))
else:
part = native_lines[0].split()
for line in default_lines:
......@@ -1643,7 +1642,6 @@ class GCC_compiler(object):
try:
fd, path = tempfile.mkstemp(suffix='.c', prefix=tmp_prefix)
exe_path = path[:-2]
dummy_stdin = open(os.devnull)
try:
os.write(fd, src_code)
os.close(fd)
......@@ -1651,8 +1649,7 @@ class GCC_compiler(object):
proc = call_subprocess_Popen(
['g++', path, '-o', exe_path] + flags,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
stdin=dummy_stdin.fileno())
stderr=subprocess.PIPE)
proc.wait()
if proc.returncode != 0:
compilation_ok = False
......@@ -1662,14 +1659,12 @@ class GCC_compiler(object):
try:
proc = call_subprocess_Popen([exe_path],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
stdin=dummy_stdin.fileno())
stderr=subprocess.PIPE)
proc.wait()
run_ok = (proc.returncode == 0)
finally:
os.remove(exe_path)
finally:
del dummy_stdin
try:
if fd is not None:
os.close(fd)
......
......@@ -18,13 +18,11 @@ from theano.misc.windows import call_subprocess_Popen
# Using the dummy file descriptors below is a workaround for a crash
# experienced in an unusual Python 2.4.4 Windows environment with the default
# None values.
dummy_in = open(os.devnull)
dummy_err = open(os.devnull, 'w')
p = None
try:
p = call_subprocess_Popen(['g++', '-dumpversion'],
stdout=subprocess.PIPE,
stdin=dummy_in.fileno(),
stderr=dummy_err.fileno())
p.wait()
gcc_version_str = p.stdout.readline().strip().decode()
......@@ -32,7 +30,6 @@ except OSError:
# Typically means gcc cannot be found.
gcc_version_str = 'GCC_NOT_FOUND'
del p
del dummy_in
del dummy_err
compiledir_format_dict = {"platform": platform.platform(),
......
......@@ -491,13 +491,13 @@ try:
# skip VM.__init__
except ImportError:
pass
except (OSError, theano.gof.cmodule.MissingGXX):
except (OSError, theano.gof.cmodule.MissingGXX), e:
# OSError happens when g++ is not installed. In that case, we
# already changed the default linker to something else then CVM.
# Currently this is the py linker.
# Here we assert that the default linker is not cvm.
assert not [x for x in theano.configparser._config_var_list
if x.fullname == 'linker'][0].default.startswith('cvm')
if x.fullname == 'linker'][0].default.startswith('cvm'), e
pass
......
......@@ -21,5 +21,18 @@ def call_subprocess_Popen(command, **params):
# execute "g++" without extensions.
# (Executing "g++.bat" explicitly would also work.)
params['shell'] = True
proc = subprocess.Popen(command, startupinfo=startupinfo, **params)
# Using the dummy file descriptors below is a workaround for a
# crash experienced in an unusual Python 2.4.4 Windows environment
# with the default None values.
stdin = None
if "stdin" not in params:
stdin = open(os.devnull)
params['stdin'] = stdin.fileno()
try:
proc = subprocess.Popen(command, startupinfo=startupinfo, **params)
finally:
if stdin is not None:
del stdin
return proc
......@@ -276,8 +276,7 @@ def run(stdout, stderr, argv, theano_nose, batch_size, time_profile,
# test name in display
# (see class 'DisabDocString' in file theano-nose)
stderr=subprocess.PIPE,
stdout=dummy_out.fileno(),
stdin=dummy_in.fileno())
stdout=dummy_out.fileno())
# recovering and processing data from pipe
err = proc.stderr.read()
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论