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

Merge pull request #1267 from nouiz/march

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