Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
0ce3cc18
提交
0ce3cc18
authored
11月 23, 2015
作者:
Arnaud Bergeron
提交者:
Pascal Lamblin
12月 04, 2015
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add optimizations in the gpuarray backend for AbstractConv2d
上级
84120e95
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
97 行增加
和
3 行删除
+97
-3
dnn.py
theano/sandbox/gpuarray/dnn.py
+74
-3
opt.py
theano/sandbox/gpuarray/opt.py
+23
-0
没有找到文件。
theano/sandbox/gpuarray/dnn.py
浏览文件 @
0ce3cc18
...
...
@@ -5,6 +5,7 @@ import warnings
import
theano
from
theano
import
Op
,
Apply
,
tensor
,
config
,
Variable
from
theano.scalar
import
as_scalar
,
constant
,
Log
from
theano.tensor
import
as_tensor_variable
from
theano.gradient
import
DisconnectedType
,
grad_not_implemented
from
theano.gof
import
Optimizer
,
local_optimizer
,
COp
from
theano.gof.cmodule
import
GCC_compiler
...
...
@@ -12,9 +13,12 @@ from theano.gof.type import CDataType, Generic
from
theano.compile
import
optdb
from
theano.compile.ops
import
shape_i
from
theano.tensor.nnet
import
SoftmaxGrad
from
theano.tensor.nnet.abstract_conv
import
get_conv_output_shape
from
theano.tensor.signal.downsample
import
(
DownsampleFactorMax
,
MaxPoolGrad
,
AveragePoolGrad
)
from
theano.tensor.nnet.abstract_conv
import
(
AbstractConv2d
,
AbstractConv2d_gradWeights
,
AbstractConv2d_gradInputs
,
get_conv_output_shape
)
from
theano.tensor.signal.downsample
import
(
DownsampleFactorMax
,
MaxPoolGrad
,
AveragePoolGrad
)
from
.
import
pygpu
from
.type
import
get_context
,
gpu_context_type
,
list_contexts
...
...
@@ -819,6 +823,30 @@ def dnn_conv(img, kerns, border_mode='valid', subsample=(1, 1),
return
GpuDnnConv
(
algo
=
algo
)(
img
,
kerns
,
out
,
desc
)
def
dnn_gradweight
(
img
,
topgrad
,
kerns_shp
,
border_mode
=
'valid'
,
subsample
=
(
1
,
1
),
conv_mode
=
'conv'
):
ctx_name
=
infer_context_name
(
img
,
topgrad
)
img
=
gpu_contiguous
(
img
)
topgrad
=
gpu_contiguous
(
topgrad
)
kerns_shp
=
as_tensor_variable
(
kerns_shp
)
desc
=
GpuDnnConvDesc
(
border_mode
=
border_mode
,
subsample
=
subsample
,
conv_mode
=
conv_mode
)(
img
.
shape
,
kerns_shp
)
out
=
GpuAllocEmpty
(
img
.
dtype
,
ctx_name
)(
*
kerns_shp
)
return
GpuDnnConvGradW
()(
img
,
topgrad
,
out
,
desc
)
def
dnn_gradinput
(
kerns
,
topgrad
,
img_shp
,
border_mode
=
'valid'
,
subsample
=
(
1
,
1
),
conv_mode
=
'conv'
):
ctx_name
=
infer_context_name
(
img
,
topgrad
)
kerns
=
gpu_contiguous
(
kerns
)
topgrad
=
gpu_contiguous
(
topgrad
)
img_shp
=
as_tensor_variable
(
img_shp
)
desc
=
GpuDnnConvDesc
(
border_mode
=
border_mode
,
subsample
=
subsample
,
conv_mode
=
conv_mode
)(
img_shp
,
kerns
.
shape
)
out
=
GpuAllocEmpty
(
kerns
.
dtype
,
ctx_name
)(
*
img_shp
)
return
GpuDnnConvGradI
()(
kerns
,
topgrad
,
out
,
desc
)
class
GpuDnnPoolDesc
(
Op
):
"""
This Op builds a pooling descriptor for use in the other
...
...
@@ -1240,6 +1268,49 @@ def local_conv_dnn_alternative(node):
conv_groupopt
.
register
(
'local_conv_dnn'
,
local_conv_dnn
,
20
,
'conv_dnn'
,
'fast_compile'
,
'fast_run'
,
'cudnn'
)
@local_optimizer
([
AbstractConv2d
,
AbstractConv2d_gradWeights
,
AbstractConv2d_gradInputs
])
def
local_abstractconv_cudnn
(
node
):
if
(
not
isinstance
(
node
.
op
,
(
AbstractConv2d
,
AbstractConv2d_gradWeights
,
AbstractConv2d_gradInputs
))):
return
None
inp1
=
node
.
inputs
[
0
]
inp2
=
node
.
inputs
[
1
]
if
(
not
isinstance
(
inp1
.
type
,
GpuArrayType
)
or
not
isinstance
(
inp2
.
type
,
GpuArrayType
)):
return
None
if
not
dnn_available
():
return
None
if
node
.
op
.
filter_flip
:
conv_mode
=
'conv'
else
:
conv_mode
=
'cross'
if
isinstance
(
node
.
op
,
AbstractConv2d
):
rval
=
dnn_conv
(
inp1
,
inp2
,
border_mode
=
node
.
op
.
border_mode
,
subsample
=
node
.
op
.
subsample
,
direction_hint
=
'forward!'
,
conv_mode
=
conv_mode
)
if
isinstance
(
node
.
op
,
AbstractConv2d_gradWeights
):
shape
=
(
inp2
.
shape
[
1
],
inp1
.
shape
[
1
],
node
.
inputs
[
2
][
0
],
node
.
inputs
[
2
][
1
])
rval
=
dnn_gradweight
(
inp1
,
inp2
,
shape
,
border_mode
=
node
.
op
.
border_mode
,
subsample
=
node
.
op
.
subsample
,
conv_mode
=
conv_mode
)
if
isinstance
(
node
.
op
,
AbstractConv2d_gradInputs
):
shape
=
(
inp2
.
shape
[
0
],
inp1
.
shape
[
1
],
node
.
inputs
[
2
][
0
],
node
.
inputs
[
2
][
1
])
rval
=
dnn_gradinput
(
inp1
,
inp2
,
shape
,
border_mode
=
node
.
op
.
border_mode
,
subsample
=
node
.
op
.
subsample
,
conv_mode
=
conv_mode
)
return
[
rval
]
@inplace_allocempty
(
GpuDnnConv
,
2
)
def
local_dnn_conv_inplace
(
node
,
inputs
):
...
...
theano/sandbox/gpuarray/opt.py
浏览文件 @
0ce3cc18
...
...
@@ -15,6 +15,10 @@ from theano.scalar.basic import Scalar, Pow, Cast
from
theano.scan_module
import
scan_utils
,
scan_op
,
scan_opt
from
theano.tensor.nnet.conv
import
ConvOp
from
theano.tensor.nnet.abstract_conv2d
import
(
BaseAbstractConv2d
,
AbstractConv2d
,
AbstractConv2d_gradWeights
,
AbstractConv2d_gradInputs
)
from
theano.tests.breakpoint
import
PdbBreakpoint
from
.type
import
(
GpuArrayType
,
GpuArrayConstant
,
get_context
,
...
...
@@ -851,6 +855,25 @@ def local_gpu_conv(node, context_name):
register_opt
()(
conv_groupopt
)
@register_opt
()
@op_lifter
([
AbstractConv2d
])
def
local_lift_abstractconv2d
(
node
,
context_name
):
return
[
node
.
op
(
as_gpuarray_variable
(
node
.
inputs
[
0
],
context_name
=
context_name
),
as_gpuarray_variable
(
node
.
inputs
[
0
],
context_name
=
context_name
))]
@register_opt
()
@op_lifter
([
AbstractConv2d_gradWeights
,
AbstractConv2d_gradInputs
])
def
local_lift_abstractconv2dgrad
(
node
,
context_name
):
return
[
node
.
op
(
as_gpuarray_variable
(
node
.
inputs
[
0
],
context_name
=
context_name
),
as_gpuarray_variable
(
node
.
inputs
[
0
],
context_name
=
context_name
),
node
.
inputs
[
2
])]
@register_opt
(
"low_memory"
)
@local_optimizer
([
GpuCAReduceCuda
])
def
local_gpu_elemwise_careduce
(
node
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论