Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
cdea94b3
提交
cdea94b3
authored
10月 20, 2014
作者:
Frederic
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Change the default GPU 2d convolution.
上级
35e2aa0e
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
77 行增加
和
2 行删除
+77
-2
conv.txt
doc/library/tensor/nnet/conv.txt
+23
-0
opt.py
theano/sandbox/cuda/opt.py
+29
-2
test_conv_cuda_ndarray.py
theano/sandbox/cuda/tests/test_conv_cuda_ndarray.py
+25
-0
没有找到文件。
doc/library/tensor/nnet/conv.txt
浏览文件 @
cdea94b3
...
@@ -22,6 +22,29 @@
...
@@ -22,6 +22,29 @@
.. moduleauthor:: LISA
.. moduleauthor:: LISA
.. note::
As October 20, 2014, the default GPU image convolution
changed. Now, if `cuDNN <https://developer.nvidia.com/cuDNN>`_ is
available and the GPU selected is supported by it. This give
faster GPU convolution without using more memory then the legacy
convolution.
- If can use cuDNN, use it.
- If not, use gemm version (slower then cuDNN, use more memory).
- If the user don't want the extra memory of the gemm version,
they can enable the legacy code that is even slower, but don't
use extra memory.
- There is also the fft version that is the fastest in some cases,
but use even more memory. It don't support striding to remove
computation and have some shape restriction.
- There is also the cuda_convnet convolution in Pylearn2. It use a
different memory layout, have shapes restriction, but don't use
extra memory and is faster then the legacy convolution.
TODO: Give examples on how to use these things! They are pretty complicated.
TODO: Give examples on how to use these things! They are pretty complicated.
- Convolution operators implemented:
- Convolution operators implemented:
...
...
theano/sandbox/cuda/opt.py
浏览文件 @
cdea94b3
...
@@ -1109,9 +1109,36 @@ def local_gpu_softmax_with_bias(node):
...
@@ -1109,9 +1109,36 @@ def local_gpu_softmax_with_bias(node):
from
theano.tensor.nnet
import
conv
from
theano.tensor.nnet
import
conv
@register_opt
()
# Need 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 support it, use it. Otherwise, the gemm
# version should be used. If the user want the legacy convolution,
# they should use the Theano flag:
# optimizer_excluding=local_conv_gemm.
# If cudnn is available, this flag should be added:
# optimizer_excluding=local_gpu_conv
@register_opt
(
"dnn"
)
@local_optimizer
([
gpu_from_host
,
conv
.
ConvOp
])
@local_optimizer
([
gpu_from_host
,
conv
.
ConvOp
])
def
local_gpu_conv
(
node
):
def
local_gpu_conv
(
node
):
"""
If cudnn is available, use it. Otherwise, use the gemm version.
"""
if
theano
.
sandbox
.
cuda
.
dnn
.
dnn_available
():
repl
=
local_gpu_conv_legacy
.
transform
(
node
)
if
repl
:
n
=
repl
[
0
]
.
owner
.
inputs
[
0
]
.
owner
assert
isinstance
(
n
.
op
,
GpuConv
)
ret
=
theano
.
sandbox
.
cuda
.
dnn
.
local_conv_dnn
.
transform
(
n
)
if
ret
:
return
[
host_from_gpu
(
ret
[
0
])]
# If dnn isn't avail, the local_gpu_conv_legacy wil introduce the
# legacy opt. Then the local_conv_gemm will convert it to gemm
# opt.
@register_opt
()
@local_optimizer
([
gpu_from_host
,
conv
.
ConvOp
])
def
local_gpu_conv_legacy
(
node
):
"""
"""
gpu_from_host(conv) -> gpu_conv(gpu_from_host)
gpu_from_host(conv) -> gpu_conv(gpu_from_host)
...
@@ -1438,6 +1465,7 @@ def local_gpu_downsample_factor_max_grad(node):
...
@@ -1438,6 +1465,7 @@ def local_gpu_downsample_factor_max_grad(node):
gpu_from_host
(
gz
)))]
gpu_from_host
(
gz
)))]
@register_opt
()
@local_optimizer
([
GpuConv
])
@local_optimizer
([
GpuConv
])
def
local_conv_gemm
(
node
):
def
local_conv_gemm
(
node
):
if
(
isinstance
(
node
.
op
,
GpuConv
)
and
if
(
isinstance
(
node
.
op
,
GpuConv
)
and
...
@@ -1493,7 +1521,6 @@ def local_conv_gemm(node):
...
@@ -1493,7 +1521,6 @@ def local_conv_gemm(node):
return
[
GpuCorrMM_gradInputs
(
'valid'
,
subsample
,
pad
)(
return
[
GpuCorrMM_gradInputs
(
'valid'
,
subsample
,
pad
)(
gpu_contiguous
(
kern
),
gpu_contiguous
(
img
))]
gpu_contiguous
(
kern
),
gpu_contiguous
(
img
))]
gpu_optimizer
.
register
(
"conv_gemm"
,
local_conv_gemm
)
from
theano.sandbox.cuda.basic_ops
import
gpu_join
,
GpuJoin
from
theano.sandbox.cuda.basic_ops
import
gpu_join
,
GpuJoin
...
...
theano/sandbox/cuda/tests/test_conv_cuda_ndarray.py
浏览文件 @
cdea94b3
...
@@ -586,6 +586,31 @@ def test_dnn_valid():
...
@@ -586,6 +586,31 @@ def test_dnn_valid():
yield
t
yield
t
def
test_default_conv
():
"""Just test that we introduce the right GPU convolution
versoin.
"""
img
=
theano
.
tensor
.
ftensor4
()
fil
=
theano
.
tensor
.
ftensor4
()
c
=
theano
.
tensor
.
nnet
.
conv2d
(
img
,
fil
)
f
=
theano
.
function
([
img
,
fil
],
c
,
mode
=
theano_mode
)
if
cuda
.
dnn
.
dnn_available
():
assert
any
([
isinstance
(
a
.
op
,
GpuDnnConv
)
for
a
in
f
.
maker
.
fgraph
.
apply_nodes
])
else
:
assert
any
([
isinstance
(
a
.
op
,
cuda
.
blas
.
GpuCorrMM
)
for
a
in
f
.
maker
.
fgraph
.
apply_nodes
])
mode
=
theano_mode
.
excluding
(
'local_gpu_conv'
,
'local_conv_gemm'
)
f
=
theano
.
function
([
img
,
fil
],
c
,
mode
=
mode
)
assert
any
([
isinstance
(
a
.
op
,
cuda
.
blas
.
GpuConv
)
for
a
in
f
.
maker
.
fgraph
.
apply_nodes
])
def
_test_full
(
cls
,
mode
=
None
,
version
=
[
-
1
],
extra_shapes
=
[]):
def
_test_full
(
cls
,
mode
=
None
,
version
=
[
-
1
],
extra_shapes
=
[]):
seed_rng
()
seed_rng
()
shapes
=
get_basic_shapes
()
shapes
=
get_basic_shapes
()
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论