提交 b1984de0 authored 作者: nouiz's avatar nouiz

Merge pull request #1228 from lamblin/default_blas_flags

Test default blas flags before using them
...@@ -1483,6 +1483,49 @@ class GCC_compiler(object): ...@@ -1483,6 +1483,49 @@ class GCC_compiler(object):
cxxflags.append("-D NPY_ARRAY_F_CONTIGUOUS=NPY_F_CONTIGUOUS") cxxflags.append("-D NPY_ARRAY_F_CONTIGUOUS=NPY_F_CONTIGUOUS")
return cxxflags return cxxflags
@staticmethod
def try_flags(flag_list):
'''
Try to compile a dummy file with these flags.
Returns True if compilation was successful, False if there
were errors.
'''
if not theano.config.cxx:
return False
rval = True
try:
code = """
int main(int argc, char** argv)
{
return 0;
}
"""
fd, path = tempfile.mkstemp(suffix='.c', prefix='try_flags_')
dummy_stdin = open(os.devnull)
try:
os.write(fd, code)
os.close(fd)
fd = None
proc = call_subprocess_Popen(['g++', path] + flag_list,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
stdin=dummy_stdin.fileno())
proc.wait()
if proc.returncode != 0:
rval = False
finally:
del dummy_stdin
try:
if fd is not None:
os.close(fd)
finally:
os.remove(path)
except OSError, e:
rval = False
return rval
@staticmethod @staticmethod
def compile_str(module_name, src_code, location=None, def compile_str(module_name, src_code, location=None,
include_dirs=None, lib_dirs=None, libs=None, include_dirs=None, lib_dirs=None, libs=None,
......
...@@ -138,6 +138,7 @@ from theano.gof import (utils, Op, view_roots, DestroyHandler, ...@@ -138,6 +138,7 @@ from theano.gof import (utils, Op, view_roots, DestroyHandler,
InconsistencyError, toolbox, SequenceDB, InconsistencyError, toolbox, SequenceDB,
EquilibriumOptimizer, Apply, EquilibriumOptimizer, Apply,
ReplacementDidntRemovedError) ReplacementDidntRemovedError)
from theano.gof.cmodule import GCC_compiler
from theano.printing import pprint, FunctionPrinter, debugprint from theano.printing import pprint, FunctionPrinter, debugprint
from theano.compile.mode import optdb from theano.compile.mode import optdb
from theano.gof.python25 import all, any from theano.gof.python25 import all, any
...@@ -373,9 +374,8 @@ def default_blas_ldflags(): ...@@ -373,9 +374,8 @@ def default_blas_ldflags():
#if numpy was linked with library that are not installed, we #if numpy was linked with library that are not installed, we
#can't reuse them. #can't reuse them.
if all(not os.path.exists(dir) for dir in blas_info['library_dirs']): if any(os.path.exists(dir) for dir in blas_info['library_dirs']):
return "-lblas" return ' '.join(
return ' '.join(
#TODO: the Gemm op below should separate the #TODO: the Gemm op below should separate the
# -L and -l arguments into the two callbacks # -L and -l arguments into the two callbacks
# that CLinker uses for that stuff. for now, # that CLinker uses for that stuff. for now,
...@@ -386,7 +386,17 @@ def default_blas_ldflags(): ...@@ -386,7 +386,17 @@ def default_blas_ldflags():
[]) [])
# ['-I%s' % l for l in blas_info['include_dirs']]) # ['-I%s' % l for l in blas_info['include_dirs']])
except KeyError: except KeyError:
pass
# Even if we could not detect what was used for numpy, or if these
# libraries are not found, most Linux systems have a libblas.so
# readily available. We try to see if that's the case, rather
# than disable blas.
if GCC_compiler.try_flags(["-lblas"]):
return "-lblas" return "-lblas"
else:
return ""
AddConfigVar('blas.ldflags', AddConfigVar('blas.ldflags',
"lib[s] to include for [Fortran] level-3 blas implementation", "lib[s] to include for [Fortran] level-3 blas implementation",
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论