Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
47d59f97
提交
47d59f97
authored
3月 26, 2015
作者:
Frederic
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Make cudnn_available() use nvcc
上级
a47b7df0
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
111 行增加
和
79 行删除
+111
-79
cmodule.py
theano/gof/cmodule.py
+95
-77
dnn.py
theano/sandbox/cuda/dnn.py
+1
-1
nvcc_compiler.py
theano/sandbox/cuda/nvcc_compiler.py
+15
-1
没有找到文件。
theano/gof/cmodule.py
浏览文件 @
47d59f97
...
...
@@ -1526,7 +1526,96 @@ def gcc_llvm():
gcc_llvm
.
is_llvm
=
None
class
GCC_compiler
(
object
):
class
Compiler
(
object
):
"""
Meta compiler that offer some generic function
"""
@staticmethod
def
_try_compile_tmp
(
src_code
,
tmp_prefix
=
''
,
flags
=
(),
try_run
=
False
,
output
=
False
,
compiler
=
None
):
"""Try to compile (and run) a test program.
This is useful in various occasions, to check if libraries
or compilers are behaving as expected.
If try_run is True, the src_code is assumed to be executable,
and will be run.
If try_run is False, returns the compilation status.
If try_run is True, returns a (compile_status, run_status) pair.
If output is there, we append the stdout and stderr to the output.
"""
if
not
compiler
:
return
False
flags
=
list
(
flags
)
compilation_ok
=
True
run_ok
=
False
out
,
err
=
None
,
None
try
:
fd
,
path
=
tempfile
.
mkstemp
(
suffix
=
'.c'
,
prefix
=
tmp_prefix
)
exe_path
=
path
[:
-
2
]
try
:
# Python3 compatibility: try to cast Py3 strings as Py2 strings
try
:
src_code
=
b
(
src_code
)
except
Exception
:
pass
os
.
write
(
fd
,
src_code
)
os
.
close
(
fd
)
fd
=
None
out
,
err
,
p_ret
=
output_subprocess_Popen
(
[
compiler
,
path
,
'-o'
,
exe_path
]
+
flags
)
if
p_ret
!=
0
:
compilation_ok
=
False
elif
try_run
:
out
,
err
,
p_ret
=
output_subprocess_Popen
([
exe_path
])
run_ok
=
(
p_ret
==
0
)
finally
:
try
:
if
fd
is
not
None
:
os
.
close
(
fd
)
finally
:
os
.
remove
(
path
)
os
.
remove
(
exe_path
)
except
OSError
,
e
:
compilation_ok
=
False
if
not
try_run
and
not
output
:
return
compilation_ok
elif
not
try_run
and
output
:
return
(
compilation_ok
,
out
,
err
)
elif
not
output
:
return
(
compilation_ok
,
run_ok
)
else
:
return
(
compilation_ok
,
run_ok
,
out
,
err
)
@staticmethod
def
_try_flags
(
flag_list
,
preambule
=
""
,
body
=
""
,
try_run
=
False
,
output
=
False
,
compiler
=
None
):
'''
Try to compile a dummy file with these flags.
Returns True if compilation was successful, False if there
were errors.
'''
if
not
compiler
:
return
False
code
=
b
(
"""
%(preambule)
s
int main(int argc, char** argv)
{
%(body)
s
return 0;
}
"""
%
locals
())
return
Compiler
.
_try_compile_tmp
(
code
,
tmp_prefix
=
'try_flags_'
,
flags
=
flag_list
,
try_run
=
try_run
,
output
=
output
,
compiler
=
compiler
)
class
GCC_compiler
(
Compiler
):
# The equivalent flags of --march=native used by g++.
march_flags
=
None
...
...
@@ -1791,86 +1880,15 @@ class GCC_compiler(object):
@staticmethod
def
try_compile_tmp
(
src_code
,
tmp_prefix
=
''
,
flags
=
(),
try_run
=
False
,
output
=
False
):
"""Try to compile (and run) a test program.
This is useful in various occasions, to check if libraries
or compilers are behaving as expected.
If try_run is True, the src_code is assumed to be executable,
and will be run.
If try_run is False, returns the compilation status.
If try_run is True, returns a (compile_status, run_status) pair.
If output is there, we append the stdout and stderr to the output.
"""
if
not
theano
.
config
.
cxx
:
return
False
flags
=
list
(
flags
)
compilation_ok
=
True
run_ok
=
False
out
,
err
=
None
,
None
try
:
fd
,
path
=
tempfile
.
mkstemp
(
suffix
=
'.c'
,
prefix
=
tmp_prefix
)
exe_path
=
path
[:
-
2
]
try
:
# Python3 compatibility: try to cast Py3 strings as Py2 strings
try
:
src_code
=
b
(
src_code
)
except
Exception
:
pass
os
.
write
(
fd
,
src_code
)
os
.
close
(
fd
)
fd
=
None
out
,
err
,
p_ret
=
output_subprocess_Popen
(
[
theano
.
config
.
cxx
,
path
,
'-o'
,
exe_path
]
+
flags
)
if
p_ret
!=
0
:
compilation_ok
=
False
elif
try_run
:
out
,
err
,
p_ret
=
output_subprocess_Popen
([
exe_path
])
run_ok
=
(
p_ret
==
0
)
finally
:
try
:
if
fd
is
not
None
:
os
.
close
(
fd
)
finally
:
os
.
remove
(
path
)
os
.
remove
(
exe_path
)
except
OSError
,
e
:
compilation_ok
=
False
if
not
try_run
and
not
output
:
return
compilation_ok
elif
not
try_run
and
output
:
return
(
compilation_ok
,
out
,
err
)
elif
not
output
:
return
(
compilation_ok
,
run_ok
)
else
:
return
(
compilation_ok
,
run_ok
,
out
,
err
)
return
Compiler
.
_try_compile_tmp
(
src_code
,
tmp_prefix
,
flags
,
try_run
,
output
,
theano
.
config
.
cxx
)
@staticmethod
def
try_flags
(
flag_list
,
preambule
=
""
,
body
=
""
,
try_run
=
False
,
output
=
False
):
'''
Try to compile a dummy file with these flags.
Returns True if compilation was successful, False if there
were errors.
'''
if
not
theano
.
config
.
cxx
:
return
False
code
=
b
(
"""
%(preambule)
s
int main(int argc, char** argv)
{
%(body)
s
return 0;
}
"""
%
locals
())
return
GCC_compiler
.
try_compile_tmp
(
code
,
tmp_prefix
=
'try_flags_'
,
flags
=
flag_list
,
try_run
=
try_run
,
output
=
output
)
return
Compiler
.
_try_flags
(
flag_list
,
preambule
,
body
,
try_run
,
output
,
theano
.
config
.
cxx
)
@staticmethod
def
compile_str
(
module_name
,
src_code
,
location
=
None
,
...
...
theano/sandbox/cuda/dnn.py
浏览文件 @
47d59f97
...
...
@@ -58,7 +58,7 @@ if ((err = cudnnCreate(&_handle)) != CUDNN_STATUS_SUCCESS) {
# default gpu, not the one selected by the user. If mixed
# GPU are installed or if the GPUs are configured in
# exclusive mode, this cause bad detection.
comp
,
out
,
err
=
gof
.
cmodule
.
G
CC_compiler
.
try_flags
(
comp
,
out
,
err
=
NV
CC_compiler
.
try_flags
(
[
"-l"
,
"cudnn"
,
"-I"
+
os
.
path
.
dirname
(
__file__
),
"-I"
+
os
.
path
.
join
(
theano
.
config
.
cuda
.
root
,
'include'
),
"-L"
+
os
.
path
.
join
(
theano
.
config
.
cuda
.
root
,
'lib64'
)],
...
...
theano/sandbox/cuda/nvcc_compiler.py
浏览文件 @
47d59f97
...
...
@@ -12,6 +12,7 @@ from theano.gof import local_bitwidth
from
theano.gof.cc
import
hash_from_file
from
theano.gof.cmodule
import
(
std_libs
,
std_lib_dirs
,
std_include_dirs
,
dlimport
,
Compiler
,
get_lib_extension
)
from
theano.compat.python2x
import
any
from
theano.misc.windows
import
output_subprocess_Popen
...
...
@@ -126,7 +127,20 @@ def add_standard_rpath(rpath):
rpath_defaults
.
append
(
rpath
)
class
NVCC_compiler
(
object
):
class
NVCC_compiler
(
Compiler
):
@staticmethod
def
try_compile_tmp
(
src_code
,
tmp_prefix
=
''
,
flags
=
(),
try_run
=
False
,
output
=
False
):
return
Compiler
.
_try_compile_tmp
(
src_code
,
tmp_prefix
,
flags
,
try_run
,
output
,
nvcc_path
)
@staticmethod
def
try_flags
(
flag_list
,
preambule
=
""
,
body
=
""
,
try_run
=
False
,
output
=
False
):
return
Compiler
.
_try_flags
(
flag_list
,
preambule
,
body
,
try_run
,
output
,
nvcc_path
)
@staticmethod
def
version_str
():
return
"nvcc "
+
nvcc_version
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论