Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
170abace
提交
170abace
authored
4月 12, 2010
作者:
fsavard
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added optimization for GpuJoin (one case), plus one unit test for it
上级
b9d6183a
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
92 行增加
和
2 行删除
+92
-2
opt.py
theano/sandbox/cuda/opt.py
+63
-0
test_cuda_ndarray.py
theano/sandbox/cuda/tests/test_cuda_ndarray.py
+3
-2
test_opt.py
theano/sandbox/cuda/tests/test_opt.py
+26
-0
没有找到文件。
theano/sandbox/cuda/opt.py
浏览文件 @
170abace
...
@@ -465,3 +465,66 @@ def local_gpu_downsample_factor_max_grad(node):
...
@@ -465,3 +465,66 @@ def local_gpu_downsample_factor_max_grad(node):
gpu_ds_grad
=
GpuDownsampleFactorMaxGrad
(
node
.
op
.
ds
,
node
.
op
.
ignore_border
)
gpu_ds_grad
=
GpuDownsampleFactorMaxGrad
(
node
.
op
.
ds
,
node
.
op
.
ignore_border
)
return
[
host_from_gpu
(
gpu_ds_grad
(
x
.
owner
.
inputs
[
0
],
gpu_from_host
(
z
),
gpu_from_host
(
gz
)))]
return
[
host_from_gpu
(
gpu_ds_grad
(
x
.
owner
.
inputs
[
0
],
gpu_from_host
(
z
),
gpu_from_host
(
gz
)))]
from
theano.sandbox.cuda.basic_ops
import
gpu_join
@register_opt
()
@local_optimizer
([])
def
local_gpu_join
(
node
):
"""
Inspired by the opt for convop.
Very loose notation follows.
Subgraphs concerned first look like
[array of HostTensor] -> HostToGpu -> GpuToHost
-> Join -> HostToGpu -> GpuToHost
First we apply this Opt:
join(host_from_gpu) -> host_from_gpu(gpu_join)
then, as an intermediate result, there should be
host_from_gpu(gpu_join) -> HostToGpu -> GpuToHost
this unnecessary GpuToHost -> HostToGpu should be removed
by other opts, leaving us with
host_from_gpu(gpu_join)
For intermediate places in the graph not covered by the first opt, the following could be useful:
gpu_from_host(join) -> gpu_join(gpu_from_host)
not implemented yet.
"""
if
isinstance
(
node
.
op
,
tensor
.
Join
):
# optimizing this case:
# join(host_from_gpu) -> host_from_gpu(gpu_join)
# print "OPT: we've got a Join instance"
axis_and_tensors
=
node
.
inputs
#print "OPT: axis_and_tensors=", axis_and_tensors
matches
=
[
not
t
.
owner
is
None
and
t
.
owner
.
op
==
host_from_gpu
for
t
in
axis_and_tensors
[
1
:]]
#print "OPT: matches =", matches
# if all input tensors are host_from_gpu'ified
if
numpy
.
all
(
matches
):
# the extra gpu_from_host introduced here will
# be removed by further optimizations
new_tensors
=
[
gpu_from_host
(
t
)
for
t
in
axis_and_tensors
[
1
:]]
new_a_and_t
=
[
axis_and_tensors
[
0
]]
+
new_tensors
replacement_node
=
host_from_gpu
(
gpu_join
(
*
new_a_and_t
))
# print "OPT: replacement_node", replacement_node
return
[
replacement_node
]
theano/sandbox/cuda/tests/test_cuda_ndarray.py
浏览文件 @
170abace
...
@@ -386,12 +386,13 @@ def test_zeros_basic_3d_tensor():
...
@@ -386,12 +386,13 @@ def test_zeros_basic_3d_tensor():
assert
numpy
.
allclose
(
numpy
.
asarray
(
_a
),
numpy
.
zeros
((
3
,
4
,
5
)))
assert
numpy
.
allclose
(
numpy
.
asarray
(
_a
),
numpy
.
zeros
((
3
,
4
,
5
)))
def
test_zeros_basic_vector
():
def
test_zeros_basic_vector
():
_a
=
cuda_ndarray
.
CudaNdarray
.
zeros
((
300
))
_a
=
cuda_ndarray
.
CudaNdarray
.
zeros
((
300
,
))
assert
numpy
.
allclose
(
numpy
.
asarray
(
_a
),
numpy
.
zeros
((
300
)))
assert
numpy
.
allclose
(
numpy
.
asarray
(
_a
),
numpy
.
zeros
((
300
,
)))
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
test_zeros_basic_3d_tensor
()
test_zeros_basic_3d_tensor
()
test_zeros_basic_vector
()
test_setitem_matrixvector1
()
test_setitem_matrixvector1
()
test_setitem_matrix_tensor3
()
test_setitem_matrix_tensor3
()
test_setitem_broadcast_must_fail
()
test_setitem_broadcast_must_fail
()
...
...
theano/sandbox/cuda/tests/test_opt.py
浏览文件 @
170abace
...
@@ -71,3 +71,29 @@ def test_softmax_with_bias():
...
@@ -71,3 +71,29 @@ def test_softmax_with_bias():
xv
=
numpy
.
random
.
rand
(
7
,
8
)
xv
=
numpy
.
random
.
rand
(
7
,
8
)
bv
=
numpy
.
random
.
rand
(
8
)
bv
=
numpy
.
random
.
rand
(
8
)
assert
numpy
.
allclose
(
f
(
xv
,
bv
),
f2
(
xv
,
bv
))
assert
numpy
.
allclose
(
f
(
xv
,
bv
),
f2
(
xv
,
bv
))
def
test_opt_gpujoin_onlyajoin
():
_a
=
numpy
.
asarray
([[
1
,
2
],[
3
,
4
]],
dtype
=
'float32'
)
_b
=
numpy
.
asarray
([[
5
,
6
,
7
],[
8
,
9
,
10
]],
dtype
=
'float32'
)
a
=
theano
.
shared
(
_a
)
b
=
theano
.
shared
(
_b
)
c
=
tensor
.
join
(
1
,
a
,
b
)
f
=
theano
.
function
([],
c
)
#theano.printing.debugprint(f)
graph_nodes
=
f
.
maker
.
env
.
toposort
()
assert
isinstance
(
graph_nodes
[
-
1
]
.
op
,
cuda
.
HostFromGpu
)
assert
isinstance
(
graph_nodes
[
-
2
]
.
op
,
cuda
.
GpuJoin
)
assert
numpy
.
all
(
f
()
==
numpy
.
concatenate
([
_a
,
_b
],
axis
=
1
))
if
__name__
==
'__main__'
:
test_opt_gpujoin_onlyajoin
()
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论