提交 ede48744 authored 作者: Frédéric Bastien's avatar Frédéric Bastien

Merge pull request #3858 from mohammadpz/try_blas_flag

auxiliary function 'try_blas_flags' added.
...@@ -288,7 +288,7 @@ SOMEPATH/Canopy_64bit/User/lib/python2.7/site-packages/numpy/distutils/system_in ...@@ -288,7 +288,7 @@ SOMEPATH/Canopy_64bit/User/lib/python2.7/site-packages/numpy/distutils/system_in
flags += ['-l%s' % l for l in ["mkl_core", flags += ['-l%s' % l for l in ["mkl_core",
"mkl_intel_thread", "mkl_intel_thread",
"mkl_rt"]] "mkl_rt"]]
if GCC_compiler.try_flags(flags): if try_blas_flag(flags):
return ' '.join(flags) return ' '.join(flags)
# If numpy was linked with library that are not installed or # If numpy was linked with library that are not installed or
...@@ -304,14 +304,14 @@ SOMEPATH/Canopy_64bit/User/lib/python2.7/site-packages/numpy/distutils/system_in ...@@ -304,14 +304,14 @@ SOMEPATH/Canopy_64bit/User/lib/python2.7/site-packages/numpy/distutils/system_in
['-L%s' % l for l in blas_info['library_dirs']] + ['-L%s' % l for l in blas_info['library_dirs']] +
['-l%s' % l for l in blas_info['libraries']] + ['-l%s' % l for l in blas_info['libraries']] +
[]) [])
if GCC_compiler.try_flags(ret): if try_blas_flag(ret):
return ' '.join(ret) return ' '.join(ret)
# Try to add the anaconda lib directory to runtime loading of lib. # Try to add the anaconda lib directory to runtime loading of lib.
# This fix some case with Anaconda 2.3 on Linux. # This fix some case with Anaconda 2.3 on Linux.
if "Anaconda" in sys.version and "linux" in sys.platform: if "Anaconda" in sys.version and "linux" in sys.platform:
lib_path = os.path.join(sys.prefix, 'lib') lib_path = os.path.join(sys.prefix, 'lib')
ret.append('-Wl,-rpath,' + lib_path) ret.append('-Wl,-rpath,' + lib_path)
if GCC_compiler.try_flags(ret): if try_blas_flag(ret):
return ' '.join(ret) return ' '.join(ret)
except KeyError: except KeyError:
...@@ -322,7 +322,10 @@ SOMEPATH/Canopy_64bit/User/lib/python2.7/site-packages/numpy/distutils/system_in ...@@ -322,7 +322,10 @@ SOMEPATH/Canopy_64bit/User/lib/python2.7/site-packages/numpy/distutils/system_in
# readily available. We try to see if that's the case, rather # readily available. We try to see if that's the case, rather
# than disable blas. To test it correctly, we must load a program. # than disable blas. To test it correctly, we must load a program.
# Otherwise, there could be problem in the LD_LIBRARY_PATH. # Otherwise, there could be problem in the LD_LIBRARY_PATH.
return try_blas_flag(['-lblas'])
def try_blas_flag(flags):
test_code = textwrap.dedent("""\ test_code = textwrap.dedent("""\
extern "C" float sdot_(int*, float*, int*, float*, int*); extern "C" float sdot_(int*, float*, int*, float*, int*);
int main(int argc, char** argv) int main(int argc, char** argv)
...@@ -339,13 +342,14 @@ SOMEPATH/Canopy_64bit/User/lib/python2.7/site-packages/numpy/distutils/system_in ...@@ -339,13 +342,14 @@ SOMEPATH/Canopy_64bit/User/lib/python2.7/site-packages/numpy/distutils/system_in
return 0; return 0;
} }
""") """)
flags = ['-lblas']
flags.extend('-L' + d for d in theano.gof.cmodule.std_lib_dirs()) flags.extend('-L' + d for d in theano.gof.cmodule.std_lib_dirs())
res = GCC_compiler.try_compile_tmp( res = GCC_compiler.try_compile_tmp(
test_code, tmp_prefix='try_blas_', test_code, tmp_prefix='try_blas_',
flags=flags, try_run=True) flags=flags, try_run=True)
# res[0]: shows successful compilation
# res[1]: shows successful execution
if res and res[0] and res[1]: if res and res[0] and res[1]:
return "-lblas" return flags
else: else:
return "" return ""
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论