Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
b8008818
提交
b8008818
authored
9月 02, 2015
作者:
Cesar Laurent
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Gpu reshape opt.
上级
87f8c5a1
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
41 行增加
和
0 行删除
+41
-0
basic_ops.py
theano/sandbox/cuda/basic_ops.py
+2
-0
opt.py
theano/sandbox/cuda/opt.py
+29
-0
test_opt.py
theano/sandbox/cuda/tests/test_opt.py
+10
-0
没有找到文件。
theano/sandbox/cuda/basic_ops.py
浏览文件 @
b8008818
...
@@ -2445,6 +2445,8 @@ class GpuReshape(tensor.Reshape, GpuOp):
...
@@ -2445,6 +2445,8 @@ class GpuReshape(tensor.Reshape, GpuOp):
# __hash__, __eq__, __str__ come from tensor.Subtensor
# __hash__, __eq__, __str__ come from tensor.Subtensor
def
make_node
(
self
,
x
,
shp
):
def
make_node
(
self
,
x
,
shp
):
x
=
as_cuda_ndarray_variable
(
x
)
shp
=
tensor
.
as_tensor_variable
(
shp
)
host_reshaped
=
host_from_gpu
(
x
)
.
reshape
(
shp
,
ndim
=
self
.
ndim
)
host_reshaped
=
host_from_gpu
(
x
)
.
reshape
(
shp
,
ndim
=
self
.
ndim
)
return
Apply
(
self
,
[
x
,
shp
],
return
Apply
(
self
,
[
x
,
shp
],
[
CudaNdarrayType
(
host_reshaped
.
broadcastable
)()])
[
CudaNdarrayType
(
host_reshaped
.
broadcastable
)()])
...
...
theano/sandbox/cuda/opt.py
浏览文件 @
b8008818
...
@@ -944,6 +944,35 @@ def local_gpu_reshape(node):
...
@@ -944,6 +944,35 @@ def local_gpu_reshape(node):
return
False
return
False
@local_optimizer
([
GpuReshape
])
def
local_gpu_reshape_chain
(
node
):
"""
GuReshape(GpuReshape(shape1),shape2) -> GpuReshape(shape2)
"""
if
not
tensor
.
opt
.
opt
.
check_chain
(
node
,
GpuReshape
,
GpuReshape
):
return
False
# TODO: this can permit a failing program to run by eliminating
# the lower reshape
rval
=
node
.
op
(
node
.
inputs
[
0
]
.
owner
.
inputs
[
0
],
node
.
inputs
[
1
])
# It might happen that the desired output of this node has a broadcastable
# pattern that does not match that of 'rval'. This is when originally, we
# were able to figure out that one of the dimensions of the reshape is one,
# but some other transformation replaced the shape by one for which this
# cannot be guessed.
# We should try to figure out why we lost the information about this
# constant value... but in the meantime, better not apply this
# optimization.
if
rval
.
broadcastable
==
node
.
outputs
[
0
]
.
broadcastable
:
return
[
rval
]
else
:
return
False
gpu_cut_copies
.
register
(
'cut_local_gpu_reshape_chain'
,
local_gpu_reshape_chain
,
'fast_run'
,
'gpu'
)
@register_opt
()
@register_opt
()
@local_optimizer
([
gpu_from_host
,
tensor
.
Flatten
])
@local_optimizer
([
gpu_from_host
,
tensor
.
Flatten
])
def
local_gpu_flatten
(
node
):
def
local_gpu_flatten
(
node
):
...
...
theano/sandbox/cuda/tests/test_opt.py
浏览文件 @
b8008818
...
@@ -819,6 +819,16 @@ class test_diag(theano.tensor.tests.test_nlinalg.test_diag):
...
@@ -819,6 +819,16 @@ class test_diag(theano.tensor.tests.test_nlinalg.test_diag):
self
)
.
__init__
(
name
)
self
)
.
__init__
(
name
)
def
test_local_gpu_reshape
():
mode
=
mode_with_gpu
a
=
tensor
.
fmatrix
()
b
=
basic_ops
.
GpuReshape
(
3
)(
a
,
[
2
,
3
,
4
])
c
=
basic_ops
.
GpuReshape
(
1
)(
b
,
[
24
])
f
=
theano
.
function
([
a
],
c
,
mode
=
mode
)
topo
=
f
.
maker
.
fgraph
.
toposort
()
assert
sum
(
isinstance
(
node
.
op
,
basic_ops
.
GpuReshape
)
for
node
in
topo
)
==
1
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
test_gpualloc
()
test_gpualloc
()
test_opt_gpujoin_onlyajoin
()
test_opt_gpujoin_onlyajoin
()
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论