Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
95d3add9
提交
95d3add9
authored
11月 07, 2014
作者:
abergeron
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #2239 from nouiz/dnn
Dnn default and doc
上级
52cb8ec7
7a85fa42
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
118 行增加
和
17 行删除
+118
-17
dnn.txt
doc/library/sandbox/cuda/dnn.txt
+59
-0
index.txt
doc/library/sandbox/cuda/index.txt
+2
-1
cmodule.py
theano/gof/cmodule.py
+18
-8
dnn.py
theano/sandbox/cuda/dnn.py
+0
-0
opt.py
theano/sandbox/cuda/opt.py
+1
-6
test_dnn.py
theano/sandbox/cuda/tests/test_dnn.py
+38
-2
没有找到文件。
doc/library/sandbox/cuda/dnn.txt
0 → 100644
浏览文件 @
95d3add9
.. _libdoc_cuda_dnn:
================================
:mod:`sandbox.cuda.dnn` -- cuDNN
================================
.. moduleauthor:: LISA
`cuDNN <https://developer.nvidia.com/cuDNN>`_ is an NVIDIA library with
functionality used by deep neural network. It provides optimized versions
of some operations like the convolution. cuDNN is not currently
installed with CUDA 6.5. You must download and install it
yourself.
To install it, decompress the downloaded file and make the ``*.h`` and
``*.so*`` files available to the compilation environment. On Linux,
this can be done by setting the environment variables
``LD_LIBRARY_PATH``, ``LIBRARY_PATH`` and ``CPATH`` to the
uncompressed directory path. Separate multiple directory with ``:`` as
the ``PATH`` environment variable. Or you can copy the ``*.h`` files
to ``/usr/include`` and the ``*.so*`` files to ``/lib64``.
By default, Theano will detect if it can use cuDNN. If so, it will use
it. If not, Theano optimizations will not introduce cuDNN ops. So
Theano will still work if the user did not introduce them manually.
To get an error if Theano can not use cuDNN, use this Theano flag:
``optimizer_including=cudnn``.
.. note::
Normally you should not call GPU Ops directly, but the CPU interface
currently does not allow all options supported by cuDNN ops. So it is
possible that you will need to call them manually.
Functions
=========
.. automodule:: theano.sandbox.cuda.dnn
:members: dnn_conv, dnn_pool
Convolution Ops
===============
.. automodule:: theano.sandbox.cuda.dnn
:members: GpuDnnConvDesc, GpuDnnConv, GpuDnnConvGradW, GpuDnnConvGradI,
Pooling Ops
===========
.. automodule:: theano.sandbox.cuda.dnn
:members: GpuDnnPoolDesc, GpuDnnPool, GpuDnnPoolGrad,
Softmax Ops
===========
.. automodule:: theano.sandbox.cuda.dnn
:members: GpuDnnSoftmax, GpuDnnSoftmaxGrad
doc/library/sandbox/cuda/index.txt
浏览文件 @
95d3add9
...
...
@@ -13,6 +13,7 @@
.. toctree::
:maxdepth: 1
op
var
type
op
dnn
theano/gof/cmodule.py
浏览文件 @
95d3add9
...
...
@@ -1788,7 +1788,8 @@ class GCC_compiler(object):
return
cxxflags
@staticmethod
def
try_compile_tmp
(
src_code
,
tmp_prefix
=
''
,
flags
=
(),
try_run
=
False
):
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
...
...
@@ -1799,6 +1800,7 @@ class GCC_compiler(object):
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
...
...
@@ -1818,14 +1820,14 @@ class GCC_compiler(object):
os
.
write
(
fd
,
src_code
)
os
.
close
(
fd
)
fd
=
None
p_ret
=
call
_subprocess_Popen
(
out
,
err
,
p_ret
=
output
_subprocess_Popen
(
[
'g++'
,
path
,
'-o'
,
exe_path
]
+
flags
)
if
p_ret
!=
0
:
compilation_ok
=
False
elif
try_run
:
# Try to execute the program
try
:
p_ret
=
call
_subprocess_Popen
([
exe_path
])
out
,
err
,
p_ret
=
output
_subprocess_Popen
([
exe_path
])
run_ok
=
(
p_ret
==
0
)
finally
:
os
.
remove
(
exe_path
)
...
...
@@ -1839,13 +1841,18 @@ class GCC_compiler(object):
except
OSError
,
e
:
compilation_ok
=
False
if
not
try_run
:
if
not
try_run
and
not
output
:
return
compilation_ok
else
:
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
):
def
try_flags
(
flag_list
,
preambule
=
""
,
body
=
""
,
try_run
=
False
,
output
=
False
):
'''
Try to compile a dummy file with these flags.
...
...
@@ -1856,13 +1863,16 @@ class GCC_compiler(object):
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
=
False
)
flags
=
flag_list
,
try_run
=
try_run
,
output
=
output
)
@staticmethod
def
compile_str
(
module_name
,
src_code
,
location
=
None
,
...
...
theano/sandbox/cuda/dnn.py
浏览文件 @
95d3add9
差异被折叠。
点击展开。
theano/sandbox/cuda/opt.py
浏览文件 @
95d3add9
...
...
@@ -1163,11 +1163,6 @@ def local_conv_fft_full(node):
return
# Needs to be registered before local_gpu_conv_legacy. Otherwise, it
# will have priority over this optimization. We want, if cudnn is
# available and the GPU supports it, to use it. Otherwise, the gemm
# version should be used. If the users want the legacy convolution,
# they should use the Theano flag to disable the dnn and/or gemm version.
@local_optimizer
([
GpuConv
])
def
local_gpu_conv
(
node
):
"""
...
...
@@ -1350,7 +1345,7 @@ conv_groupopt.register("conv_fft_valid", local_conv_fft_valid, 1)
conv_groupopt
.
register
(
"conv_fft_full"
,
local_conv_fft_full
,
1
)
# Use dnn if avail, so have the dnn tag to be able to disable it.
conv_groupopt
.
register
(
'local_gpu_conv'
,
local_gpu_conv
,
10
,
'fast_compile'
,
'fast_run'
,
'dnn'
)
'fast_compile'
,
'fast_run'
,
'
cu
dnn'
)
conv_groupopt
.
register
(
'local_conv_gemm'
,
local_conv_gemm
,
12
,
'fast_compile'
,
'fast_run'
)
...
...
theano/sandbox/cuda/tests/test_dnn.py
浏览文件 @
95d3add9
import
logging
import
unittest
from
nose.plugins.skip
import
SkipTest
import
numpy
import
unittest
import
theano
from
theano.compat.six
import
StringIO
from
theano.gof.python25
import
any
import
theano.tensor
as
T
import
theano.tests.unittest_tools
as
utt
...
...
@@ -85,7 +88,7 @@ def test_pooling_opt():
f
=
theano
.
function
(
[
x
],
max_pool_2d
(
x
,
ds
=
(
2
,
2
)),
mode
=
mode_with_gpu
.
including
(
"cudnn"
)
)
mode
=
mode_with_gpu
)
assert
any
([
isinstance
(
n
.
op
,
cuda
.
dnn
.
GpuDnnPool
)
for
n
in
f
.
maker
.
fgraph
.
toposort
()])
...
...
@@ -97,3 +100,36 @@ def test_pooling_opt():
assert
any
([
isinstance
(
n
.
op
,
cuda
.
dnn
.
GpuDnnPoolGrad
)
for
n
in
f
.
maker
.
fgraph
.
toposort
()])
def
test_dnn_tag
():
"""
We test that if cudnn isn't avail we crash and that if it is avail, we use it.
"""
x
=
T
.
ftensor4
()
old
=
theano
.
config
.
on_opt_error
theano
.
config
.
on_opt_error
=
"raise"
sio
=
StringIO
()
handler
=
logging
.
StreamHandler
(
sio
)
logging
.
getLogger
(
'theano.compile.tests.test_dnn'
)
.
addHandler
(
handler
)
# Silence original handler when intentionnally generating warning messages
logging
.
getLogger
(
'theano'
)
.
removeHandler
(
theano
.
logging_default_handler
)
raised
=
False
try
:
f
=
theano
.
function
(
[
x
],
max_pool_2d
(
x
,
ds
=
(
2
,
2
)),
mode
=
mode_with_gpu
.
including
(
"cudnn"
))
except
RuntimeError
,
e
:
assert
not
cuda
.
dnn
.
dnn_available
()
raised
=
True
finally
:
theano
.
config
.
on_opt_error
=
old
logging
.
getLogger
(
'theano.compile.tests.test_dnn'
)
.
removeHandler
(
handler
)
logging
.
getLogger
(
'theano'
)
.
addHandler
(
theano
.
logging_default_handler
)
if
not
raised
:
assert
cuda
.
dnn
.
dnn_available
()
assert
any
([
isinstance
(
n
.
op
,
cuda
.
dnn
.
GpuDnnPool
)
for
n
in
f
.
maker
.
fgraph
.
toposort
()])
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论