提交 8e984c50 authored 作者: Arnaud Bergeron's avatar Arnaud Bergeron

Fix frequent segfaults while using the gpu on Mac.

上级 4a12110c
......@@ -1771,37 +1771,9 @@ class GCC_compiler(object):
# link with libpython.
cxxflags.append('-DMS_WIN64')
#DSE Patch 1 for supporting OSX frameworks; add -framework Python
if sys.platform == 'darwin':
# Use the already-loaded python symbols.
cxxflags.extend(['-undefined', 'dynamic_lookup'])
python_inc = distutils.sysconfig.get_python_inc()
# link with the framework library *if specifically requested*
# config.mac_framework_link is by default False, since on some mac
# installs linking with -framework causes a Bus Error
if (python_inc.count('Python.framework') > 0 and
config.cmodule.mac_framework_link):
cxxflags.extend(['-framework', 'Python'])
if 'Anaconda' in sys.version:
new_path = os.path.join(sys.prefix, "lib")
new_path = os.path.realpath(new_path)
v = os.getenv("DYLD_FALLBACK_LIBRARY_PATH", None)
if v is not None:
# This will resolve symbolic links
v = os.path.realpath(v)
# The python __import__ don't seam to take into account
# the new env variable "DYLD_FALLBACK_LIBRARY_PATH"
# when we set with os.environ['...'] = X or os.putenv()
# So we tell the user and tell him what todo.
if v is None or new_path not in v.split(":"):
raise Exception(
"The environment variable "
"'DYLD_FALLBACK_LIBRARY_PATH' does not contain "
"the '%s' path in its value. This will make "
"Theano unable to compile c code. Update "
"'DYLD_FALLBACK_LIBRARY_PATH' to contain the "
"said value, this will fix this error."
% new_path)
return cxxflags
......
......@@ -264,15 +264,10 @@ class NVCC_compiler(object):
# from Benjamin Schrauwen April 14 2010
if sys.platform != 'darwin':
# No 64 bit CUDA libraries available on the mac, yet..
# OS X uses universal libraries
lib_dirs.append(os.path.join(cuda_root, 'lib64'))
if sys.platform == 'darwin':
# 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:
if sys.platform != 'darwin':
# sometimes, the linker cannot find -lpython so we need to tell it
# explicitly where it is located
# this returns somepath/lib/python2.x
......@@ -335,8 +330,7 @@ class NVCC_compiler(object):
rpaths.append(os.path.join(config.cuda.root, 'lib'))
if sys.platform != 'darwin':
# the 64bit CUDA libs are in the same files as are
# named by the function above
# the CUDA libs are universal (contain both 32-bit and 64-bit)
rpaths.append(os.path.join(config.cuda.root, 'lib64'))
if sys.platform != 'win32':
# the -rpath option is not understood by the Microsoft linker
......@@ -348,19 +342,9 @@ class NVCC_compiler(object):
cmd.extend(['-L%s' % ldir for ldir in lib_dirs])
cmd.extend(['-l%s' % l for l in libs])
if sys.platform == 'darwin':
cmd.extend(darwin_python_lib.split())
if sys.platform == 'darwin':
done = False
while not done:
try:
indexof = cmd.index('-framework')
newarg = '-Xcompiler', ','.join(cmd[indexof:(indexof + 2)])
cmd.pop(indexof) # Remove -framework
cmd.pop(indexof) # Remove argument to -framework
cmd.extend(newarg)
except ValueError, e:
done = True
# This tells the compiler to use the already-loaded python
# symbols (which should always be the right ones).
cmd.extend(['-Xcompiler', '-undefined,dynamic_lookup'])
# Remove "-u Symbol" arguments, since they are usually not
# relevant for the new compilation, even if they were used for
......@@ -375,8 +359,6 @@ class NVCC_compiler(object):
except ValueError, e:
done = True
# Fix for MacOS X.
cmd = remove_python_framework_dir(cmd)
# CUDA Toolkit v4.1 Known Issues:
# Host linker on Mac OS 10.7 (and 10.6 for me) passes -no_pie option
# to nvcc this option is not recognized and generates an error
......@@ -442,37 +424,3 @@ class NVCC_compiler(object):
#touch the __init__ file
open(os.path.join(location, "__init__.py"), 'w').close()
return dlimport(lib_filename)
def remove_python_framework_dir(cmd):
"""
Search for Python framework directory and get rid of it.
:param cmd: A list of strings corresponding to compilation arguments. On
MacOS X, one of these strings may be of the form
"/opt/local/Library/Frameworks/Python.framework/Versions/2.7/Python"
and it needs to be removed as otherwise compilation will fail.
:return: The same list as `cmd`, but without the element of the form
mentioned above, if one exists.
"""
# The fix below was initially suggested by Nicolas Pinto:
# http://groups.google.com/group/theano-users/browse_thread/thread/c84bfe31bb411493
# It was improved later following a bug report by Benjamin Hamner:
# https://groups.google.com/group/theano-users/browse_thread/thread/374ec2dadd3ac369/024e2be792f98d86
# It was modified by Graham Taylor to support Enthought Python Distribution
# 7.x (32 and 64 bit)
# TODO It is a bit hack-ish, is it possible to find a more generic fix?
fwk_pattern = '(Python|EPD64).framework/Versions/(2\.[0-9]|7\.[0-9])/Python$'
rval = [element for element in cmd
if (re.search(fwk_pattern, element) is None
# Keep this element if it turns out to be part of an argument
# like -L.
or element.startswith('-'))]
if len(rval) < len(cmd) - 1:
warnings.warn("'remove_python_framework_dir' removed %s elements from "
"the command line, while it is expected to remove at "
"most one. If compilation fails, this would be a good "
"place to start looking for a problem." %
(len(cmd) - len(rval)))
return rval
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论