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

Merge pull request #3654 from nouiz/blas

Better detect if we can use -lblas and more reuse of anaconda blas.
......@@ -1627,6 +1627,16 @@ def std_lib_dirs_and_libs():
# Typical include directory: /usr/include/python2.6
libname = os.path.basename(python_inc)
std_lib_dirs_and_libs.data = [libname], []
# sometimes, the linker cannot find -lpython so we need to tell it
# explicitly where it is located this returns
# somepath/lib/python2.x
python_lib = distutils.sysconfig.get_python_lib(plat_specific=1,
standard_lib=1)
python_lib = os.path.dirname(python_lib)
if python_lib not in std_lib_dirs_and_libs.data[1]:
std_lib_dirs_and_libs.data[1].append(python_lib)
return std_lib_dirs_and_libs.data
std_lib_dirs_and_libs.data = None
......@@ -2107,15 +2117,6 @@ class GCC_compiler(Compiler):
libs = std_libs() + libs
lib_dirs = std_lib_dirs() + lib_dirs
# sometimes, the linker cannot find -lpython so we need to tell it
# explicitly where it is located
# this returns somepath/lib/python2.x
python_lib = distutils.sysconfig.get_python_lib(plat_specific=1,
standard_lib=1)
python_lib = os.path.dirname(python_lib)
if python_lib not in lib_dirs:
lib_dirs.append(python_lib)
cppfilename = os.path.join(location, 'mod.cpp')
cppfile = open(cppfilename, 'w')
......
......@@ -129,6 +129,7 @@ import copy
import logging
import os
import sys
import textwrap
import time
import warnings
......@@ -305,6 +306,13 @@ SOMEPATH/Canopy_64bit/User/lib/python2.7/site-packages/numpy/distutils/system_in
[])
if GCC_compiler.try_flags(ret):
return ' '.join(ret)
# Try to add the anaconda lib directory to runtime loading of lib.
# This fix some case with Anaconda 2.3 on Linux.
if "Anaconda" in sys.version and "linux" in sys.platform:
lib_path = os.path.join(sys.prefix, 'lib')
ret.append('-Wl,-rpath,' + lib_path)
if GCC_compiler.try_flags(ret):
return ' '.join(ret)
except KeyError:
pass
......@@ -312,8 +320,31 @@ SOMEPATH/Canopy_64bit/User/lib/python2.7/site-packages/numpy/distutils/system_in
# 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"]):
# than disable blas. To test it correctly, we must load a program.
# Otherwise, there could be problem in the LD_LIBRARY_PATH.
test_code = textwrap.dedent("""\
extern "C" float sdot_(int*, float*, int*, float*, int*);
int main(int argc, char** argv)
{
int Nx = 5;
int Sx = 1;
float x[5] = {0, 1, 2, 3, 4};
float r = sdot_(&Nx, x, &Sx, x, &Sx);
if ((r - 30.f) > 1e-6 || (r - 30.f) < -1e-6)
{
return -1;
}
return 0;
}
""")
flags = ['-lblas']
flags.extend('-L'.join(theano.gof.cmodule.std_lib_dirs()))
res = GCC_compiler.try_compile_tmp(
test_code, tmp_prefix='try_blas_',
flags=flags, try_run=True)
if res[0] and res[1]:
return "-lblas"
else:
return ""
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论