Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
21351eed
提交
21351eed
authored
4月 24, 2015
作者:
Frederic
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix the merge of GpuDnnConv* by enabling again the merge of GpuAllocEmpty and…
Fix the merge of GpuDnnConv* by enabling again the merge of GpuAllocEmpty and fix the inplace by duplicating them in the inplace opt
上级
b75cf2e1
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
119 行增加
和
11 行删除
+119
-11
basic_ops.py
theano/sandbox/cuda/basic_ops.py
+0
-6
dnn.py
theano/sandbox/cuda/dnn.py
+22
-4
test_dnn.py
theano/sandbox/cuda/tests/test_dnn.py
+97
-1
没有找到文件。
theano/sandbox/cuda/basic_ops.py
浏览文件 @
21351eed
...
@@ -3299,9 +3299,6 @@ class GpuAllocEmpty(GpuOp):
...
@@ -3299,9 +3299,6 @@ class GpuAllocEmpty(GpuOp):
# XXX: We could implement and call CudaNdarray.empty(sh) instead.
# XXX: We could implement and call CudaNdarray.empty(sh) instead.
out
[
0
]
=
cuda_ndarray
.
cuda_ndarray
.
CudaNdarray
.
zeros
(
sh
)
out
[
0
]
=
cuda_ndarray
.
cuda_ndarray
.
CudaNdarray
.
zeros
(
sh
)
def
do_merge
(
self
,
node
):
return
False
def
c_code
(
self
,
node
,
name
,
inputs
,
out_
,
sub
):
def
c_code
(
self
,
node
,
name
,
inputs
,
out_
,
sub
):
out
,
=
out_
out
,
=
out_
fail
=
sub
[
'fail'
]
fail
=
sub
[
'fail'
]
...
@@ -3354,9 +3351,6 @@ class GpuAlloc(GpuAllocEmpty):
...
@@ -3354,9 +3351,6 @@ class GpuAlloc(GpuAllocEmpty):
"""
"""
__props__
=
(
'memset_0'
,)
__props__
=
(
'memset_0'
,)
def
do_merge
(
self
,
node
):
return
True
def
__init__
(
self
,
memset_0
=
False
):
def
__init__
(
self
,
memset_0
=
False
):
self
.
memset_0
=
memset_0
self
.
memset_0
=
memset_0
...
...
theano/sandbox/cuda/dnn.py
浏览文件 @
21351eed
...
@@ -17,7 +17,7 @@ from theano.sandbox.cuda import GpuOp
...
@@ -17,7 +17,7 @@ from theano.sandbox.cuda import GpuOp
from
theano.sandbox.cuda.basic_ops
import
(
as_cuda_ndarray_variable
,
from
theano.sandbox.cuda.basic_ops
import
(
as_cuda_ndarray_variable
,
host_from_gpu
,
host_from_gpu
,
gpu_contiguous
,
HostFromGpu
,
gpu_contiguous
,
HostFromGpu
,
gpu_alloc_empty
)
gpu_alloc_empty
,
GpuAllocEmpty
)
from
theano.sandbox.cuda.blas
import
(
GpuConv
,
GpuDownsampleFactorMax
,
from
theano.sandbox.cuda.blas
import
(
GpuConv
,
GpuDownsampleFactorMax
,
GpuDownsampleFactorMaxGrad
)
GpuDownsampleFactorMaxGrad
)
from
theano.sandbox.cuda.nnet
import
GpuSoftmax
from
theano.sandbox.cuda.nnet
import
GpuSoftmax
...
@@ -1533,19 +1533,37 @@ if True:
...
@@ -1533,19 +1533,37 @@ if 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
return
[
GpuDnnConv
(
workmem
=
node
.
op
.
workmem
,
inplace
=
True
)(
*
node
.
inputs
)]
inputs
=
list
(
node
.
inputs
)
dest
=
inputs
[
2
]
if
(
dest
.
owner
and
isinstance
(
dest
.
owner
.
op
,
GpuAllocEmpty
)
and
len
(
dest
.
clients
)
>
1
):
inputs
[
2
]
=
gpu_alloc_empty
(
*
dest
.
owner
.
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
return
[
GpuDnnConvGradW
(
inplace
=
True
)(
*
node
.
inputs
)]
inputs
=
list
(
node
.
inputs
)
dest
=
inputs
[
2
]
if
(
dest
.
owner
and
isinstance
(
dest
.
owner
.
op
,
GpuAllocEmpty
)
and
len
(
dest
.
clients
)
>
1
):
inputs
[
2
]
=
gpu_alloc_empty
(
*
dest
.
owner
.
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
return
[
GpuDnnConvGradI
(
inplace
=
True
)(
*
node
.
inputs
)]
inputs
=
list
(
node
.
inputs
)
dest
=
inputs
[
2
]
if
(
dest
.
owner
and
isinstance
(
dest
.
owner
.
op
,
GpuAllocEmpty
)
and
len
(
dest
.
clients
)
>
1
):
inputs
[
2
]
=
gpu_alloc_empty
(
*
dest
.
owner
.
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
,
...
...
theano/sandbox/cuda/tests/test_dnn.py
浏览文件 @
21351eed
...
@@ -12,6 +12,7 @@ from theano.sandbox.neighbours import images2neibs
...
@@ -12,6 +12,7 @@ from theano.sandbox.neighbours import images2neibs
from
theano.tensor.signal.downsample
import
max_pool_2d
from
theano.tensor.signal.downsample
import
max_pool_2d
from
theano.tensor.signal.downsample
import
DownsampleFactorMaxGrad
from
theano.tensor.signal.downsample
import
DownsampleFactorMaxGrad
import
theano.sandbox.cuda.dnn
as
dnn
import
theano.sandbox.cuda.dnn
as
dnn
from
theano.sandbox.cuda.basic_ops
import
GpuAllocEmpty
,
gpu_alloc_empty
# Skip test if cuda_ndarray is not available.
# Skip test if cuda_ndarray is not available.
import
theano.sandbox.cuda
as
cuda
import
theano.sandbox.cuda
as
cuda
...
@@ -49,6 +50,101 @@ def test_dnn_conv_desc_merge():
...
@@ -49,6 +50,101 @@ def test_dnn_conv_desc_merge():
assert
d1
!=
d2
assert
d1
!=
d2
def
test_dnn_conv_merge
():
"""This test that we merge correctly multiple dnn_conv.
This can is more difficult due to GpuEmptyAlloc that aren't
merged.
"""
if
not
cuda
.
dnn
.
dnn_available
():
raise
SkipTest
(
cuda
.
dnn
.
dnn_available
.
msg
)
img_shp
=
[
2
,
5
,
6
,
8
]
kern_shp
=
[
3
,
5
,
5
,
6
]
out_shp
=
[
2
,
3
,
2
,
3
]
img
=
T
.
ftensor4
(
'img'
)
kern
=
T
.
ftensor4
(
'kern'
)
out
=
T
.
ftensor4
(
'out'
)
desc
=
dnn
.
GpuDnnConvDesc
(
border_mode
=
'valid'
)(
img
.
shape
,
kern
.
shape
)
# Test forward op
o1
=
dnn
.
dnn_conv
(
img
,
kern
)
o2
=
dnn
.
dnn_conv
(
img
,
kern
)
f
=
theano
.
function
([
img
,
kern
],
[
o1
,
o2
],
mode
=
mode_with_gpu
)
d1
,
d2
=
f
(
numpy
.
random
.
rand
(
*
img_shp
)
.
astype
(
'float32'
),
numpy
.
random
.
rand
(
*
kern_shp
)
.
astype
(
'float32'
))
topo
=
f
.
maker
.
fgraph
.
toposort
()
assert
len
([
n
for
n
in
topo
if
isinstance
(
n
.
op
,
dnn
.
GpuDnnConv
)])
==
1
# Test grad w op
o1
=
dnn
.
GpuDnnConvGradW
()(
img
,
kern
,
out
,
desc
)
o2
=
dnn
.
GpuDnnConvGradW
()(
img
,
kern
,
out
,
desc
)
f
=
theano
.
function
([
img
,
kern
,
out
],
[
o1
,
o2
],
mode
=
mode_with_gpu
)
topo
=
f
.
maker
.
fgraph
.
toposort
()
assert
len
([
n
for
n
in
topo
if
isinstance
(
n
.
op
,
dnn
.
GpuDnnConvGradW
)])
==
1
# Test grad i op
o1
=
dnn
.
GpuDnnConvGradI
()(
img
,
kern
,
out
,
desc
)
o2
=
dnn
.
GpuDnnConvGradI
()(
img
,
kern
,
out
,
desc
)
f
=
theano
.
function
([
img
,
kern
,
out
],
[
o1
,
o2
],
mode
=
mode_with_gpu
)
topo
=
f
.
maker
.
fgraph
.
toposort
()
assert
len
([
n
for
n
in
topo
if
isinstance
(
n
.
op
,
dnn
.
GpuDnnConvGradI
)])
==
1
def
test_dnn_conv_inplace
():
"""This test that we have inplace work correctly even when
GpuAllocEmpty get merged together.
"""
if
not
cuda
.
dnn
.
dnn_available
():
raise
SkipTest
(
cuda
.
dnn
.
dnn_available
.
msg
)
img_shp
=
[
2
,
5
,
6
,
8
]
kern_shp
=
[
3
,
5
,
5
,
6
]
out_shp
=
[
2
,
3
,
2
,
3
]
img
=
T
.
ftensor4
(
'img'
)
kern
=
T
.
ftensor4
(
'kern'
)
out
=
T
.
ftensor4
(
'out'
)
desc1
=
dnn
.
GpuDnnConvDesc
(
border_mode
=
'valid'
,
conv_mode
=
'conv'
)(
img
.
shape
,
kern
.
shape
)
desc2
=
dnn
.
GpuDnnConvDesc
(
border_mode
=
'valid'
,
conv_mode
=
'cross'
)(
img
.
shape
,
kern
.
shape
)
# Test forward op
o1
=
dnn
.
dnn_conv
(
img
,
kern
,
conv_mode
=
'conv'
)
o2
=
dnn
.
dnn_conv
(
img
,
kern
,
conv_mode
=
'cross'
)
f
=
theano
.
function
([
img
,
kern
],
[
o1
,
o2
],
mode
=
mode_with_gpu
)
d1
,
d2
=
f
(
numpy
.
random
.
rand
(
*
img_shp
)
.
astype
(
'float32'
),
numpy
.
random
.
rand
(
*
kern_shp
)
.
astype
(
'float32'
))
topo
=
f
.
maker
.
fgraph
.
toposort
()
convs
=
[
n
for
n
in
topo
if
isinstance
(
n
.
op
,
dnn
.
GpuDnnConv
)]
assert
len
(
convs
)
==
2
assert
all
([
node
.
op
.
inplace
for
node
in
convs
])
assert
len
([
n
for
n
in
topo
if
isinstance
(
n
.
op
,
GpuAllocEmpty
)])
==
2
# Test grad w op
out
=
gpu_alloc_empty
(
*
kern
.
shape
)
o1
=
dnn
.
GpuDnnConvGradW
()(
img
,
kern
,
out
,
desc1
)
o2
=
dnn
.
GpuDnnConvGradW
()(
img
,
kern
,
out
,
desc2
)
f
=
theano
.
function
([
img
,
kern
],
[
o1
,
o2
],
mode
=
mode_with_gpu
)
topo
=
f
.
maker
.
fgraph
.
toposort
()
convs
=
[
n
for
n
in
topo
if
isinstance
(
n
.
op
,
dnn
.
GpuDnnConvGradW
)]
assert
len
(
convs
)
==
2
assert
all
([
node
.
op
.
inplace
for
node
in
convs
])
assert
len
([
n
for
n
in
topo
if
isinstance
(
n
.
op
,
GpuAllocEmpty
)])
==
2
# Test grad i op
out
=
gpu_alloc_empty
(
*
img
.
shape
)
o1
=
dnn
.
GpuDnnConvGradI
()(
img
,
kern
,
out
,
desc1
)
o2
=
dnn
.
GpuDnnConvGradI
()(
img
,
kern
,
out
,
desc2
)
f
=
theano
.
function
([
img
,
kern
],
[
o1
,
o2
],
mode
=
mode_with_gpu
)
topo
=
f
.
maker
.
fgraph
.
toposort
()
convs
=
[
n
for
n
in
topo
if
isinstance
(
n
.
op
,
dnn
.
GpuDnnConvGradI
)]
assert
len
(
convs
)
==
2
assert
all
([
node
.
op
.
inplace
for
node
in
convs
])
assert
len
([
n
for
n
in
topo
if
isinstance
(
n
.
op
,
GpuAllocEmpty
)])
==
2
def
pool_2d_i2n
(
input
,
ds
=
(
2
,
2
),
strides
=
None
,
def
pool_2d_i2n
(
input
,
ds
=
(
2
,
2
),
strides
=
None
,
pad
=
(
0
,
0
),
pad
=
(
0
,
0
),
pool_function
=
T
.
max
,
mode
=
'ignore_borders'
):
pool_function
=
T
.
max
,
mode
=
'ignore_borders'
):
...
@@ -500,7 +596,7 @@ def test_dnn_conv_border_mode():
...
@@ -500,7 +596,7 @@ def test_dnn_conv_border_mode():
dnn
.
dnn_conv
(
img
,
kern
,
border_mode
=
'valid'
)
dnn
.
dnn_conv
(
img
,
kern
,
border_mode
=
'valid'
)
def
test_dnn_conv_merge
():
def
test_dnn_conv_
alpha_output_
merge
():
if
not
cuda
.
dnn
.
dnn_available
():
if
not
cuda
.
dnn
.
dnn_available
():
raise
SkipTest
(
cuda
.
dnn
.
dnn_available
.
msg
)
raise
SkipTest
(
cuda
.
dnn
.
dnn_available
.
msg
)
img
=
T
.
ftensor4
()
img
=
T
.
ftensor4
()
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论