Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
e8f6cb73
提交
e8f6cb73
authored
1月 15, 2014
作者:
Frédéric Bastien
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1692 from abergeron/mac_link
Fix frequent segfaults while using the gpu on Mac.
上级
e7b90016
643bd310
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
7 行增加
和
137 行删除
+7
-137
cmodule.py
theano/gof/cmodule.py
+1
-29
nvcc_compiler.py
theano/sandbox/cuda/nvcc_compiler.py
+6
-58
test_nvcc_compiler.py
theano/sandbox/cuda/tests/test_nvcc_compiler.py
+0
-50
没有找到文件。
theano/gof/cmodule.py
浏览文件 @
e8f6cb73
...
...
@@ -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
...
...
theano/sandbox/cuda/nvcc_compiler.py
浏览文件 @
e8f6cb73
...
...
@@ -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
theano/sandbox/cuda/tests/test_nvcc_compiler.py
deleted
100644 → 0
浏览文件 @
e7b90016
__copyright__
=
"(c) 2011, Universite de Montreal"
__license__
=
"3-clause BSD License"
import
warnings
from
theano.sandbox.cuda.nvcc_compiler
import
remove_python_framework_dir
def
test_remove_python_framework_dir
():
"""
Test function 'remove_python_framework_dir'.
"""
# This is a typical output of 'python-config --ldflags'.
cmd
=
(
'-L/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/config '
'-ldl -framework CoreFoundation -lpython2.7 -u _PyMac_Error '
'/opt/local/Library/Frameworks/Python.framework/Versions/2.7/Python'
)
.
split
()
assert
remove_python_framework_dir
(
cmd
)
==
cmd
[
0
:
-
1
]
# Add a fake argument that should not be removed.
cmd
.
append
(
'-L/opt/local/Library/Frameworks/Python.framework/Versions/2.7/Python'
)
assert
remove_python_framework_dir
(
cmd
)
==
cmd
[
0
:
-
2
]
+
cmd
[
-
1
:]
# We test for the warning only if we can use 'catch_warnings' (Python 2.6+)
# as otherwise it is difficult to do it properly.
try
:
warnings
.
catch_warnings
test_warning
=
True
except
AttributeError
:
test_warning
=
False
if
test_warning
:
cmd
.
append
(
'Frameworks/Python.framework/Versions/2.6/Python'
)
# Python 2.4 "emulation" of `with` statement. It is necessary even if this
# code is not executed, because using `with` would result in a SyntaxError.
with_context
=
warnings
.
catch_warnings
(
record
=
True
)
record
=
with_context
.
__enter__
()
try
:
assert
remove_python_framework_dir
(
cmd
)
==
cmd
[
0
:
-
3
]
+
cmd
[
-
2
:
-
1
]
assert
len
(
record
)
==
1
assert
'remove_python_framework_dir'
in
str
(
record
[
0
]
.
message
)
finally
:
with_context
.
__exit__
(
None
,
None
,
None
)
# Now test some more typical arguments that should be caught by the regex.
for
arg_to_remove
in
[
'/Library/Frameworks/EPD64.framework/Versions/7.1/Python'
,
'/Library/Frameworks/Python.framework/Versions/7.2/Python'
,
]:
# Make sure those arguments are removed.
assert
not
remove_python_framework_dir
([
arg_to_remove
])
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论