提交 480472c6 authored 作者: Frederic's avatar Frederic

cache the detected -march=native flags.

上级 b28bed3d
...@@ -1475,6 +1475,9 @@ def gcc_version(): ...@@ -1475,6 +1475,9 @@ def gcc_version():
class GCC_compiler(object): class GCC_compiler(object):
# The equivalent flags of --march=native used by g++.
march_flags = None
@staticmethod @staticmethod
def version_str(): def version_str():
return "g++ " + gcc_version_str return "g++ " + gcc_version_str
...@@ -1484,14 +1487,14 @@ class GCC_compiler(object): ...@@ -1484,14 +1487,14 @@ class GCC_compiler(object):
cxxflags = [flag for flag in config.gcc.cxxflags.split(' ') if flag] cxxflags = [flag for flag in config.gcc.cxxflags.split(' ') if flag]
# Add the equivalent of -march=native flag. We can't use # Add the equivalent of -march=native flag. We can't use
# -march=native as if the compiledir is shared by multiple # -march=native as when the compiledir is shared by multiple
# computers (for example, if the home directory is on NFS), this # computers (for example, if the home directory is on NFS), this
# won't be optimum or cause crash depending if the file is compiled # won't be optimum or cause crash depending if the file is compiled
# on an older or more recent computer. # on an older or more recent computer.
# Those URL discuss how to find witch flags are used by -march=native. # Those URL discuss how to find witch flags are used by -march=native.
#http://en.gentoo-wiki.com/wiki/Safe_Cflags#-march.3Dnative # http://en.gentoo-wiki.com/wiki/Safe_Cflags#-march.3Dnative
#http://en.gentoo-wiki.com/wiki/Hardware_CFLAGS # http://en.gentoo-wiki.com/wiki/Hardware_CFLAGS
add_march = True detect_march = GCC_compiler.march_flags is None
#We will add it ourself in a safe way, so remove them. #We will add it ourself in a safe way, so remove them.
if '-march=native' in cxxflags: if '-march=native' in cxxflags:
...@@ -1499,16 +1502,18 @@ class GCC_compiler(object): ...@@ -1499,16 +1502,18 @@ class GCC_compiler(object):
if '--march=native' in cxxflags: if '--march=native' in cxxflags:
cxxflags.remove('--march=native') cxxflags.remove('--march=native')
for f in cxxflags: if detect_march:
#If the user specify an -march=X parameter, don't add one ourself for f in cxxflags:
if ((f.startswith("--march=") or f.startswith("-march="))): #If the user give an -march=X parameter, don't add one ourself
print ("WARNING: your Theano flags `gcc.cxxflags` specify an" if ((f.startswith("--march=") or f.startswith("-march="))):
" `-march=X` flags that isn't `-march=native`") print ("WARNING: your Theano flags `gcc.cxxflags` specify"
print (" It is better to let Theano/g++ find it " " an `-march=X` flags that isn't `-march=native`")
"automatically, but we don't do it now") print (" It is better to let Theano/g++ find it"
add_march = False " automatically, but we don't do it now")
detect_march = False
if add_march:
if detect_march:
GCC_compiler.march_flags = []
def get_lines(cmd): def get_lines(cmd):
p = call_subprocess_Popen(cmd, p = call_subprocess_Popen(cmd,
stderr=subprocess.PIPE, stderr=subprocess.PIPE,
...@@ -1537,8 +1542,13 @@ class GCC_compiler(object): ...@@ -1537,8 +1542,13 @@ class GCC_compiler(object):
part2 = [p for p in line.split() part2 = [p for p in line.split()
if not 'march' in p and not 'mtune' in p] if not 'march' in p and not 'mtune' in p]
new_flags = [p for p in part if p not in part2] new_flags = [p for p in part if p not in part2]
cxxflags.extend(new_flags) GCC_compiler.march_flags = new_flags
break break
_logger.info("g++ -march=native equivalent flags:",
GCC_compiler.march_flags)
#Add the detected -march=native equivalent flags
cxxflags.extend(GCC_compiler.march_flags)
#NumPy 1.7 Deprecate the old API. I updated most of the places #NumPy 1.7 Deprecate the old API. I updated most of the places
#to use the new API, but not everywhere. When finished, enable #to use the new API, but not everywhere. When finished, enable
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论