Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
9a86944a
提交
9a86944a
authored
10月 11, 2011
作者:
nouiz
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #110 from delallea/nvcc_macos
Fix for nvcc compilation crash in MacOS X
上级
4da8ba40
1a865c68
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
68 行增加
和
9 行删除
+68
-9
nvcc_compiler.py
theano/sandbox/cuda/nvcc_compiler.py
+35
-9
test_nvcc_compiler.py
theano/sandbox/cuda/tests/test_nvcc_compiler.py
+33
-0
没有找到文件。
theano/sandbox/cuda/nvcc_compiler.py
浏览文件 @
9a86944a
...
...
@@ -2,6 +2,7 @@ import commands
import
distutils
import
logging
import
os
import
re
import
subprocess
import
sys
import
warnings
...
...
@@ -216,15 +217,8 @@ def nvcc_module_compile_str(
except
ValueError
,
e
:
done
=
True
# The fix below was suggested by Nicolas Pinto:
# http://groups.google.com/group/theano-users/browse_thread/thread/c84bfe31bb411493
# TODO It is a bit hack-ish, is it possible to find a more generic fix?
# Remove last argument of python-config --ldflags if we are using
# MacPython 2.7.
fwk_str
=
'Python.framework/Versions/2.7/Python'
if
fwk_str
in
cmd
:
cmd
.
pop
(
cmd
.
index
(
fwk_str
))
# Fix for MacOS X.
cmd
=
remove_python_framework_dir
(
cmd
)
#cmd.append("--ptxas-options=-v") #uncomment this to see register and shared-mem requirements
_logger
.
debug
(
'Running cmd
%
s'
,
' '
.
join
(
cmd
))
...
...
@@ -275,3 +269,35 @@ def nvcc_module_compile_str(
#touch the __init__ file
file
(
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
# TODO It is a bit hack-ish, is it possible to find a more generic fix?
fwk_pattern
=
'Python.framework/Versions/2
\
.[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
0 → 100644
浏览文件 @
9a86944a
__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
except
AttributeError
:
return
cmd
.
append
(
'Frameworks/Python.framework/Versions/2.6/Python'
)
with
warnings
.
catch_warnings
(
record
=
True
)
as
record
:
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
)
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论