Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
edabc511
提交
edabc511
authored
6月 26, 2015
作者:
Arnaud Bergeron
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove the if indentation.
上级
6a02b8a0
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
56 行增加
和
62 行删除
+56
-62
dnn.py
theano/sandbox/gpuarray/dnn.py
+56
-62
没有找到文件。
theano/sandbox/gpuarray/dnn.py
浏览文件 @
edabc511
...
@@ -1487,11 +1487,9 @@ err%(name)s = cudnnSoftmaxBackward(
...
@@ -1487,11 +1487,9 @@ err%(name)s = cudnnSoftmaxBackward(
"""
"""
# Intentation for history
# @register_opt('cudnn') # this optimizer is registered in opt.py instead.
if
False
:
@local_optimizer
([
GpuConv
])
# @register_opt('cudnn') # this optimizer is registered in opt.py instead.
def
local_conv_dnn
(
node
):
@local_optimizer
([
GpuConv
])
def
local_conv_dnn
(
node
):
if
not
dnn_available
():
if
not
dnn_available
():
return
return
if
isinstance
(
node
.
op
,
GpuConv
):
if
isinstance
(
node
.
op
,
GpuConv
):
...
@@ -1509,11 +1507,11 @@ if False:
...
@@ -1509,11 +1507,11 @@ if False:
rval
,
node
.
outputs
[
0
]
.
type
.
broadcastable
)
rval
,
node
.
outputs
[
0
]
.
type
.
broadcastable
)
return
[
rval
]
return
[
rval
]
# This optimizer is registered in opt.py as part of the meta-optimizer.
# This optimizer is registered in opt.py as part of the meta-optimizer.
# It tries exactly the opposite code path of what local_conv_dnn() uses,
# It tries exactly the opposite code path of what local_conv_dnn() uses,
# because for some input/kernel shape configurations, this is faster.
# because for some input/kernel shape configurations, this is faster.
@local_optimizer
([
GpuConv
])
@local_optimizer
([
GpuConv
])
def
local_conv_dnn_alternative
(
node
):
def
local_conv_dnn_alternative
(
node
):
if
not
dnn_available
():
if
not
dnn_available
():
return
return
if
isinstance
(
node
.
op
,
GpuConv
):
if
isinstance
(
node
.
op
,
GpuConv
):
...
@@ -1542,8 +1540,8 @@ if False:
...
@@ -1542,8 +1540,8 @@ if False:
rval
,
node
.
outputs
[
0
]
.
type
.
broadcastable
)
rval
,
node
.
outputs
[
0
]
.
type
.
broadcastable
)
return
[
rval
]
return
[
rval
]
@local_optimizer
([
GpuDnnConv
],
inplace
=
True
)
@local_optimizer
([
GpuDnnConv
],
inplace
=
True
)
def
local_dnn_conv_inplace
(
node
):
def
local_dnn_conv_inplace
(
node
):
if
type
(
node
.
op
)
!=
GpuDnnConv
or
node
.
op
.
inplace
:
if
type
(
node
.
op
)
!=
GpuDnnConv
or
node
.
op
.
inplace
:
return
return
inputs
=
list
(
node
.
inputs
)
inputs
=
list
(
node
.
inputs
)
...
@@ -1554,8 +1552,8 @@ if False:
...
@@ -1554,8 +1552,8 @@ if False:
inputs
[
2
]
=
GpuAllocEmpty
(
dest
.
owner
.
op
.
dtype
)(
*
dest
.
owner
.
inputs
)
inputs
[
2
]
=
GpuAllocEmpty
(
dest
.
owner
.
op
.
dtype
)(
*
dest
.
owner
.
inputs
)
return
[
GpuDnnConv
(
workmem
=
node
.
op
.
workmem
,
inplace
=
True
)(
*
inputs
)]
return
[
GpuDnnConv
(
workmem
=
node
.
op
.
workmem
,
inplace
=
True
)(
*
inputs
)]
@local_optimizer
([
GpuDnnConvGradW
],
inplace
=
True
)
@local_optimizer
([
GpuDnnConvGradW
],
inplace
=
True
)
def
local_dnn_convgw_inplace
(
node
):
def
local_dnn_convgw_inplace
(
node
):
if
type
(
node
.
op
)
!=
GpuDnnConvGradW
or
node
.
op
.
inplace
:
if
type
(
node
.
op
)
!=
GpuDnnConvGradW
or
node
.
op
.
inplace
:
return
return
inputs
=
list
(
node
.
inputs
)
inputs
=
list
(
node
.
inputs
)
...
@@ -1566,8 +1564,8 @@ if False:
...
@@ -1566,8 +1564,8 @@ if False:
inputs
[
2
]
=
GpuAllocEmpty
(
dest
.
owner
.
op
.
dtype
)(
*
dest
.
owner
.
inputs
)
inputs
[
2
]
=
GpuAllocEmpty
(
dest
.
owner
.
op
.
dtype
)(
*
dest
.
owner
.
inputs
)
return
[
GpuDnnConvGradW
(
inplace
=
True
)(
*
inputs
)]
return
[
GpuDnnConvGradW
(
inplace
=
True
)(
*
inputs
)]
@local_optimizer
([
GpuDnnConvGradI
],
inplace
=
True
)
@local_optimizer
([
GpuDnnConvGradI
],
inplace
=
True
)
def
local_dnn_convgi_inplace
(
node
):
def
local_dnn_convgi_inplace
(
node
):
if
type
(
node
.
op
)
!=
GpuDnnConvGradI
or
node
.
op
.
inplace
:
if
type
(
node
.
op
)
!=
GpuDnnConvGradI
or
node
.
op
.
inplace
:
return
return
inputs
=
list
(
node
.
inputs
)
inputs
=
list
(
node
.
inputs
)
...
@@ -1578,55 +1576,55 @@ if False:
...
@@ -1578,55 +1576,55 @@ if False:
inputs
[
2
]
=
GpuAllocEmpty
(
dest
.
owner
.
op
.
dtype
)(
*
dest
.
owner
.
inputs
)
inputs
[
2
]
=
GpuAllocEmpty
(
dest
.
owner
.
op
.
dtype
)(
*
dest
.
owner
.
inputs
)
return
[
GpuDnnConvGradI
(
inplace
=
True
)(
*
inputs
)]
return
[
GpuDnnConvGradI
(
inplace
=
True
)(
*
inputs
)]
optdb
.
register
(
'local_dnn_conv_inplace'
,
optdb
.
register
(
'local_dnn_conv_inplace'
,
tensor
.
opt
.
in2out
(
local_dnn_conv_inplace
,
tensor
.
opt
.
in2out
(
local_dnn_conv_inplace
,
local_dnn_convgw_inplace
,
local_dnn_convgw_inplace
,
local_dnn_convgi_inplace
,
local_dnn_convgi_inplace
,
name
=
"local_dnn_conv_inplace"
),
name
=
"local_dnn_conv_inplace"
),
70.0
,
'fast_run'
,
'inplace'
,
'gpu'
,
'cudnn'
)
70.0
,
'fast_run'
,
'inplace'
,
'gpu'
,
'cudnn'
)
@register_opt
(
'cudnn'
)
@register_opt
(
'cudnn'
)
@alpha_merge
(
GpuDnnConv
,
alpha_in
=
4
,
beta_in
=
5
,
nd
=
4
)
@alpha_merge
(
GpuDnnConv
,
alpha_in
=
4
,
beta_in
=
5
,
nd
=
4
)
def
local_dnn_conv_alpha_merge
(
node
,
*
inputs
):
def
local_dnn_conv_alpha_merge
(
node
,
*
inputs
):
if
not
dnn_available
()
or
version
()
==
-
1
:
if
not
dnn_available
()
or
version
()
==
-
1
:
return
None
return
None
return
[
GpuDnnConv
(
workmem
=
node
.
op
.
workmem
)(
*
inputs
)]
return
[
GpuDnnConv
(
workmem
=
node
.
op
.
workmem
)(
*
inputs
)]
@register_opt
(
'cudnn'
)
@register_opt
(
'cudnn'
)
@alpha_merge
(
GpuDnnConvGradW
,
alpha_in
=
4
,
beta_in
=
5
,
nd
=
4
)
@alpha_merge
(
GpuDnnConvGradW
,
alpha_in
=
4
,
beta_in
=
5
,
nd
=
4
)
def
local_dnn_convw_alpha_merge
(
node
,
*
inputs
):
def
local_dnn_convw_alpha_merge
(
node
,
*
inputs
):
if
not
dnn_available
()
or
version
()
==
-
1
:
if
not
dnn_available
()
or
version
()
==
-
1
:
return
None
return
None
return
[
GpuDnnConvGradW
()(
*
inputs
)]
return
[
GpuDnnConvGradW
()(
*
inputs
)]
@register_opt
(
'cudnn'
)
@register_opt
(
'cudnn'
)
@alpha_merge
(
GpuDnnConvGradI
,
alpha_in
=
4
,
beta_in
=
5
,
nd
=
4
)
@alpha_merge
(
GpuDnnConvGradI
,
alpha_in
=
4
,
beta_in
=
5
,
nd
=
4
)
def
local_dnn_convi_alpha_merge
(
node
,
*
inputs
):
def
local_dnn_convi_alpha_merge
(
node
,
*
inputs
):
if
not
dnn_available
()
or
version
()
==
-
1
:
if
not
dnn_available
()
or
version
()
==
-
1
:
return
None
return
None
return
[
GpuDnnConvGradI
()(
*
inputs
)]
return
[
GpuDnnConvGradI
()(
*
inputs
)]
@register_opt
(
'cudnn'
)
@register_opt
(
'cudnn'
)
@output_merge
(
GpuDnnConv
,
alpha_in
=
4
,
beta_in
=
5
,
out_in
=
2
,
nd
=
4
)
@output_merge
(
GpuDnnConv
,
alpha_in
=
4
,
beta_in
=
5
,
out_in
=
2
,
nd
=
4
)
def
local_dnn_conv_output_merge
(
node
,
*
inputs
):
def
local_dnn_conv_output_merge
(
node
,
*
inputs
):
inputs
=
inputs
[
0
:
2
]
+
(
gpu_contiguous
(
inputs
[
2
]),)
+
inputs
[
3
:]
inputs
=
inputs
[
0
:
2
]
+
(
gpu_contiguous
(
inputs
[
2
]),)
+
inputs
[
3
:]
return
[
GpuDnnConv
(
workmem
=
node
.
op
.
workmem
)(
*
inputs
)]
return
[
GpuDnnConv
(
workmem
=
node
.
op
.
workmem
)(
*
inputs
)]
@register_opt
(
'cudnn'
)
@register_opt
(
'cudnn'
)
@output_merge
(
GpuDnnConvGradW
,
alpha_in
=
4
,
beta_in
=
5
,
out_in
=
2
,
nd
=
4
)
@output_merge
(
GpuDnnConvGradW
,
alpha_in
=
4
,
beta_in
=
5
,
out_in
=
2
,
nd
=
4
)
def
local_dnn_convw_output_merge
(
node
,
*
inputs
):
def
local_dnn_convw_output_merge
(
node
,
*
inputs
):
inputs
=
inputs
[
0
:
2
]
+
(
gpu_contiguous
(
inputs
[
2
]),)
+
inputs
[
3
:]
inputs
=
inputs
[
0
:
2
]
+
(
gpu_contiguous
(
inputs
[
2
]),)
+
inputs
[
3
:]
return
[
GpuDnnConvGradW
()(
*
inputs
)]
return
[
GpuDnnConvGradW
()(
*
inputs
)]
@register_opt
(
'cudnn'
)
@register_opt
(
'cudnn'
)
@output_merge
(
GpuDnnConvGradI
,
alpha_in
=
4
,
beta_in
=
5
,
out_in
=
2
,
nd
=
4
)
@output_merge
(
GpuDnnConvGradI
,
alpha_in
=
4
,
beta_in
=
5
,
out_in
=
2
,
nd
=
4
)
def
local_dnn_convi_output_merge
(
node
,
*
inputs
):
def
local_dnn_convi_output_merge
(
node
,
*
inputs
):
inputs
=
inputs
[
0
:
2
]
+
(
gpu_contiguous
(
inputs
[
2
]),)
+
inputs
[
3
:]
inputs
=
inputs
[
0
:
2
]
+
(
gpu_contiguous
(
inputs
[
2
]),)
+
inputs
[
3
:]
return
[
GpuDnnConvGradI
()(
*
inputs
)]
return
[
GpuDnnConvGradI
()(
*
inputs
)]
@register_opt
(
'cudnn'
)
@register_opt
(
'cudnn'
)
@local_optimizer
([
GpuDownsampleFactorMax
])
@local_optimizer
([
GpuDownsampleFactorMax
])
def
local_pool_dnn
(
node
):
def
local_pool_dnn
(
node
):
if
not
dnn_available
():
if
not
dnn_available
():
return
return
if
isinstance
(
node
.
op
,
GpuDownsampleFactorMax
):
if
isinstance
(
node
.
op
,
GpuDownsampleFactorMax
):
...
@@ -1636,9 +1634,9 @@ if False:
...
@@ -1636,9 +1634,9 @@ if False:
ds
=
node
.
op
.
ds
ds
=
node
.
op
.
ds
return
[
dnn_pool
(
gpu_contiguous
(
img
),
ds
,
ds
)]
return
[
dnn_pool
(
gpu_contiguous
(
img
),
ds
,
ds
)]
@register_opt
(
'cudnn'
)
@register_opt
(
'cudnn'
)
@local_optimizer
([
DownsampleFactorMax
])
@local_optimizer
([
DownsampleFactorMax
])
def
local_pool_dnn_alternative
(
node
):
def
local_pool_dnn_alternative
(
node
):
if
not
dnn_available
():
if
not
dnn_available
():
return
return
if
isinstance
(
node
.
op
,
DownsampleFactorMax
):
if
isinstance
(
node
.
op
,
DownsampleFactorMax
):
...
@@ -1654,9 +1652,9 @@ if False:
...
@@ -1654,9 +1652,9 @@ if False:
ds
,
stride
=
stride
,
pad
=
pad
,
mode
=
mode
)
ds
,
stride
=
stride
,
pad
=
pad
,
mode
=
mode
)
return
[
host_from_gpu
(
ret
)]
return
[
host_from_gpu
(
ret
)]
@register_opt
(
'cudnn'
)
@register_opt
(
'cudnn'
)
@local_optimizer
([
GpuDownsampleFactorMaxGrad
])
@local_optimizer
([
GpuDownsampleFactorMaxGrad
])
def
local_pool_dnn_grad
(
node
):
def
local_pool_dnn_grad
(
node
):
if
not
dnn_available
():
if
not
dnn_available
():
return
return
if
isinstance
(
node
.
op
,
GpuDownsampleFactorMaxGrad
):
if
isinstance
(
node
.
op
,
GpuDownsampleFactorMaxGrad
):
...
@@ -1671,9 +1669,9 @@ if False:
...
@@ -1671,9 +1669,9 @@ if False:
gpu_contiguous
(
inp_grad
),
gpu_contiguous
(
inp_grad
),
desc
)]
desc
)]
@register_opt
(
'cudnn'
)
@register_opt
(
'cudnn'
)
@local_optimizer
([
DownsampleFactorMaxGrad
])
@local_optimizer
([
DownsampleFactorMaxGrad
])
def
local_pool_dnn_grad_stride
(
node
):
def
local_pool_dnn_grad_stride
(
node
):
if
not
dnn_available
():
if
not
dnn_available
():
return
return
if
isinstance
(
node
.
op
,
DownsampleFactorMaxGrad
):
if
isinstance
(
node
.
op
,
DownsampleFactorMaxGrad
):
...
@@ -1696,9 +1694,9 @@ if False:
...
@@ -1696,9 +1694,9 @@ if False:
desc
)
desc
)
return
[
host_from_gpu
(
ret
)]
return
[
host_from_gpu
(
ret
)]
@register_opt
(
'cudnn'
)
@register_opt
(
'cudnn'
)
@local_optimizer
([
GpuSoftmax
])
@local_optimizer
([
GpuSoftmax
])
def
local_softmax_dnn
(
node
):
def
local_softmax_dnn
(
node
):
if
not
dnn_available
():
if
not
dnn_available
():
return
return
if
isinstance
(
node
.
op
,
GpuSoftmax
):
if
isinstance
(
node
.
op
,
GpuSoftmax
):
...
@@ -1708,7 +1706,7 @@ if False:
...
@@ -1708,7 +1706,7 @@ if False:
out
=
as_gpuarray_variable
(
out
.
dimshuffle
(
0
,
1
))
out
=
as_gpuarray_variable
(
out
.
dimshuffle
(
0
,
1
))
return
[
out
]
return
[
out
]
class
NoCuDNNRaise
(
Optimizer
):
class
NoCuDNNRaise
(
Optimizer
):
def
apply
(
self
,
fgraph
):
def
apply
(
self
,
fgraph
):
""" Raise a RuntimeError if cudnn can't be used"""
""" Raise a RuntimeError if cudnn can't be used"""
if
not
dnn_available
():
if
not
dnn_available
():
...
@@ -1718,11 +1716,11 @@ if False:
...
@@ -1718,11 +1716,11 @@ if False:
"cuDNN optimization was enabled, but Theano was not able"
"cuDNN optimization was enabled, but Theano was not able"
" to use it. We got this error:
\n
"
+
" to use it. We got this error:
\n
"
+
dnn_available
.
msg
)
dnn_available
.
msg
)
gpu_seqopt
.
register
(
"NoCuDNNRaise"
,
NoCuDNNRaise
(),
0
,
'cudnn'
)
gpu_seqopt
.
register
(
"NoCuDNNRaise"
,
NoCuDNNRaise
(),
0
,
'cudnn'
)
@register_opt
(
'cudnn'
)
@register_opt
(
'cudnn'
)
@local_optimizer
([
SoftmaxGrad
])
@local_optimizer
([
SoftmaxGrad
])
def
local_softmax_dnn_grad
(
node
):
def
local_softmax_dnn_grad
(
node
):
if
(
isinstance
(
node
.
op
,
SoftmaxGrad
)
and
if
(
isinstance
(
node
.
op
,
SoftmaxGrad
)
and
((
node
.
inputs
[
0
]
.
owner
and
((
node
.
inputs
[
0
]
.
owner
and
isinstance
(
node
.
inputs
[
0
]
.
owner
.
op
,
HostFromGpu
))
or
isinstance
(
node
.
inputs
[
0
]
.
owner
.
op
,
HostFromGpu
))
or
...
@@ -1738,12 +1736,8 @@ if False:
...
@@ -1738,12 +1736,8 @@ if False:
return
return
ins
.
append
(
n
.
dimshuffle
(
0
,
1
,
'x'
,
'x'
))
ins
.
append
(
n
.
dimshuffle
(
0
,
1
,
'x'
,
'x'
))
out
=
GpuDnnSoftmaxGrad
(
out
=
GpuDnnSoftmaxGrad
(
'bc01'
,
'bc01'
,
'accurate'
,
'accurate'
,
'channel'
'channel'
)(
gpu_contiguous
(
ins
[
0
]),
)(
gpu_contiguous
(
ins
[
1
]))
gpu_contiguous
(
ins
[
0
]),
gpu_contiguous
(
ins
[
1
])
)
return
[
out
.
dimshuffle
(
0
,
1
)]
return
[
out
.
dimshuffle
(
0
,
1
)]
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论