提交 08f190b1 authored 作者: James Bergstra's avatar James Bergstra

merge

...@@ -656,6 +656,13 @@ def gcc_module_compile_str(module_name, src_code, location=None, include_dirs=[] ...@@ -656,6 +656,13 @@ def gcc_module_compile_str(module_name, src_code, location=None, include_dirs=[]
if python_inc.count('Python.framework')>0 and config.cmodule.mac_framework_link: if python_inc.count('Python.framework')>0 and config.cmodule.mac_framework_link:
preargs.extend(['-framework','Python']) preargs.extend(['-framework','Python'])
# patch from Benjamin Schrauwen
# April 14, 2009
if distutils.sysconfig.get_config_var('CFLAGS').rfind('x86_64') < 0:
# If on mac, and not a 64-bit version of python, switch to 32 bit compilation
preargs.extend(['-m32'])
# sometimes, the linker cannot find -lpython so we need to tell it # sometimes, the linker cannot find -lpython so we need to tell it
# explicitly where it is located # explicitly where it is located
# this returns somepath/lib/python2.x # this returns somepath/lib/python2.x
......
...@@ -3,6 +3,7 @@ from theano.gof.cmodule import (std_libs, std_lib_dirs, std_include_dirs, dlimpo ...@@ -3,6 +3,7 @@ from theano.gof.cmodule import (std_libs, std_lib_dirs, std_include_dirs, dlimpo
get_lib_extension) get_lib_extension)
from theano import config from theano import config
import distutils import distutils
import commands
_logger=logging.getLogger("theano.sandbox.cuda.nvcc_compiler") _logger=logging.getLogger("theano.sandbox.cuda.nvcc_compiler")
_logger.setLevel(logging.WARN) _logger.setLevel(logging.WARN)
...@@ -68,16 +69,26 @@ def nvcc_module_compile_str(module_name, src_code, location=None, include_dirs=[ ...@@ -68,16 +69,26 @@ def nvcc_module_compile_str(module_name, src_code, location=None, include_dirs=[
lib_dirs = std_lib_dirs() + lib_dirs lib_dirs = std_lib_dirs() + lib_dirs
if cuda_root: if cuda_root:
lib_dirs.append(os.path.join(cuda_root, 'lib')) lib_dirs.append(os.path.join(cuda_root, 'lib'))
lib_dirs.append(os.path.join(cuda_root, 'lib64'))
# sometimes, the linker cannot find -lpython so we need to tell it # from Benjamin Schrauwen April 14 2010
# explicitly where it is located if sys.platform != 'darwin':
# this returns somepath/lib/python2.x # No 64 bit CUDA libraries available on the mac, yet..
python_lib = distutils.sysconfig.get_python_lib(plat_specific=1, \ lib_dirs.append(os.path.join(cuda_root, 'lib64'))
standard_lib=1)
python_lib = os.path.dirname(python_lib)
if python_lib not in lib_dirs: if sys.platform == 'darwin':
lib_dirs.append(python_lib) # On the mac, nvcc is not able to link using -framework Python, so we have
# manually add the correct library and paths
darwin_python_lib = commands.getoutput('python-config --ldflags')
else:
# 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.cu') cppfilename = os.path.join(location, 'mod.cu')
cppfile = file(cppfilename, 'w') cppfile = file(cppfilename, 'w')
...@@ -99,7 +110,9 @@ def nvcc_module_compile_str(module_name, src_code, location=None, include_dirs=[ ...@@ -99,7 +110,9 @@ def nvcc_module_compile_str(module_name, src_code, location=None, include_dirs=[
cmd.extend(['-Xcompiler', ','.join(pa for pa in preargs if not pa.startswith('-O'))]) cmd.extend(['-Xcompiler', ','.join(pa for pa in preargs if not pa.startswith('-O'))])
if os.path.exists(os.path.join(config.cuda.root,'lib')): if os.path.exists(os.path.join(config.cuda.root,'lib')):
cmd.extend(['-Xlinker',','.join(['-rpath',os.path.join(config.cuda.root,'lib')])]) cmd.extend(['-Xlinker',','.join(['-rpath',os.path.join(config.cuda.root,'lib')])])
cmd.extend(['-Xlinker',','.join(['-rpath',os.path.join(config.cuda.root,'lib64')])]) if sys.platform != 'darwin':
# No 64 bit CUDA libraries available on the mac, yet..
cmd.extend(['-Xlinker',','.join(['-rpath',os.path.join(config.cuda.root,'lib64')])])
cmd.extend('-I%s'%idir for idir in include_dirs) cmd.extend('-I%s'%idir for idir in include_dirs)
cmd.extend(['-o',lib_filename]) cmd.extend(['-o',lib_filename])
cmd.append(cppfilename) cmd.append(cppfilename)
...@@ -107,6 +120,8 @@ def nvcc_module_compile_str(module_name, src_code, location=None, include_dirs=[ ...@@ -107,6 +120,8 @@ def nvcc_module_compile_str(module_name, src_code, location=None, include_dirs=[
cmd.append(os.path.join(os.path.split(cppfilename)[0],'..','cuda_ndarray','cuda_ndarray.so')) cmd.append(os.path.join(os.path.split(cppfilename)[0],'..','cuda_ndarray','cuda_ndarray.so'))
cmd.extend(['-L%s'%ldir for ldir in lib_dirs]) cmd.extend(['-L%s'%ldir for ldir in lib_dirs])
cmd.extend(['-l%s'%l for l in libs]) cmd.extend(['-l%s'%l for l in libs])
if sys.platform == 'darwin':
cmd.extend(darwin_python_lib.split())
debug('Running cmd', ' '.join(cmd)) debug('Running cmd', ' '.join(cmd))
p = subprocess.Popen(cmd, stderr=subprocess.PIPE) p = subprocess.Popen(cmd, stderr=subprocess.PIPE)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论