Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
34736410
提交
34736410
authored
7月 19, 2009
作者:
Olivier Delalleau
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Towards Windows compatibility: .pyd instead of .so, and Python library linking fixed
上级
af7f0cd8
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
37 行增加
和
9 行删除
+37
-9
cmodule.py
theano/gof/cmodule.py
+37
-9
没有找到文件。
theano/gof/cmodule.py
浏览文件 @
34736410
...
...
@@ -124,7 +124,7 @@ class DynamicModule(object):
#TODO: add_type
def
dlimport
(
fullpath
,
suffix
=
None
):
"""Dynamically load a .so, .dll, or .py file
"""Dynamically load a .so, .
pyd, .
dll, or .py file
:type fullpath: string
:param fullpath: a fully-qualified path do a compiled python module
...
...
@@ -137,6 +137,8 @@ def dlimport(fullpath, suffix=None):
if
suffix
is
None
:
if
fullpath
.
endswith
(
'.so'
):
suffix
=
'.so'
elif
fullpath
.
endswith
(
'.pyd'
):
suffix
=
'.pyd'
elif
fullpath
.
endswith
(
'.dll'
):
suffix
=
'.dll'
elif
fullpath
.
endswith
(
'.py'
):
...
...
@@ -172,9 +174,10 @@ def module_name_from_dir(dirname):
"""Scan the contents of a cache directory and return full path of the dynamic lib in it.
"""
files
=
os
.
listdir
(
dirname
)
names
=
[
file
for
file
in
files
if
file
.
endswith
(
'.so'
)]
names
=
[
file
for
file
in
files
if
file
.
endswith
(
'.so'
)
or
file
.
endswith
(
'.pyd'
)]
if
len
(
names
)
!=
1
:
raise
Exception
(
'Failed to load
.so
from dir'
,
dirname
)
raise
Exception
(
'Failed to load
dynamic libraries
from dir'
,
dirname
)
return
os
.
path
.
join
(
dirname
,
names
[
0
])
class
ModuleCache
(
object
):
...
...
@@ -210,7 +213,7 @@ class ModuleCache(object):
"""maps module names to loaded module objects"""
entry_from_key
=
{}
"""Maps keys to the filename of a .so
"""Maps keys to the filename of a .so
/.pyd.
"""
stats
=
[]
...
...
@@ -345,7 +348,13 @@ class ModuleCache(object):
key_pkl
=
os
.
path
.
join
(
location
,
'key.pkl'
)
key_file
=
file
(
key_pkl
,
'w'
)
try
:
cPickle
.
dump
(
key
,
key_file
,
cPickle
.
HIGHEST_PROTOCOL
)
if
sys
.
platform
==
'win32'
:
# Looks like there is a bug under Windows, where using the
# highest protocol will result in a pickle file that cannot
# be loaded afterwards.
cPickle
.
dump
(
key
,
key_file
)
else
:
cPickle
.
dump
(
key
,
key_file
,
cPickle
.
HIGHEST_PROTOCOL
)
key_file
.
close
()
key_broken
=
False
except
cPickle
.
PicklingError
:
...
...
@@ -441,6 +450,13 @@ def get_module_cache(dirname, force_fresh=None):
atexit
.
register
(
_module_cache
.
_on_atexit
)
return
_module_cache
def
get_lib_extension
():
"""Return the platform-dependent extension for compiled modules."""
if
sys
.
platform
==
'win32'
:
return
'pyd'
else
:
return
'so'
def
gcc_module_compile_str
(
module_name
,
src_code
,
location
=
None
,
include_dirs
=
[],
lib_dirs
=
[],
libs
=
[],
preargs
=
[],
tmpdir
=
None
):
#TODO: don't to the dlimport in this function
...
...
@@ -451,7 +467,18 @@ def gcc_module_compile_str(module_name, src_code, location=None, include_dirs=[]
include_dirs
=
[
distutils
.
sysconfig
.
get_python_inc
()]
+
\
numpy
.
distutils
.
misc_util
.
get_numpy_include_dirs
()
\
+
include_dirs
libs
=
[
os
.
path
.
split
(
distutils
.
sysconfig
.
get_python_inc
())[
-
1
]]
+
libs
python_inc
=
distutils
.
sysconfig
.
get_python_inc
()
if
sys
.
platform
==
'win32'
:
# Typical include directory: C:\Python26\include
libname
=
os
.
path
.
basename
(
os
.
path
.
dirname
(
python_inc
))
.
lower
()
# Also add directory containing the Python library to the library
# directories.
python_lib_dir
=
os
.
path
.
join
(
os
.
path
.
dirname
(
python_inc
),
'libs'
)
lib_dirs
=
[
python_lib_dir
]
+
lib_dirs
else
:
# Typical include directory: /usr/include/python2.6
libname
=
os
.
path
.
basename
(
python_inc
)
libs
=
[
libname
]
+
libs
workdir
=
location
...
...
@@ -465,7 +492,8 @@ def gcc_module_compile_str(module_name, src_code, location=None, include_dirs=[]
cppfile
.
write
(
src_code
)
cppfile
.
close
()
lib_filename
=
os
.
path
.
join
(
workdir
,
'
%
s.so'
%
module_name
)
lib_filename
=
os
.
path
.
join
(
workdir
,
'
%
s.
%
s'
%
(
module_name
,
get_lib_extension
()))
debug
(
'Generating shared lib'
,
lib_filename
)
cmd
=
[
'g++'
,
'-shared'
,
'-g'
]
...
...
@@ -490,7 +518,6 @@ def gcc_module_compile_str(module_name, src_code, location=None, include_dirs=[]
file
(
os
.
path
.
join
(
workdir
,
"__init__.py"
),
'w'
)
.
close
()
rval
=
dlimport
(
lib_filename
)
return
rval
...
...
@@ -522,7 +549,8 @@ def nvcc_module_compile_str(module_name, src_code, location=None, include_dirs=[
try
:
cppfile
.
write
(
src_code
)
cppfile
.
close
()
lib_filename
=
os
.
path
.
join
(
workdir
,
'
%
s.so'
%
module_name
)
lib_filename
=
os
.
path
.
join
(
workdir
,
'
%
s.
%
s'
%
(
module_name
,
get_lib_extension
()))
debug
(
'Generating shared lib'
,
lib_filename
)
cmd
=
[
'nvcc'
,
'-shared'
,
'-g'
]
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论