Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
fbc384cf
提交
fbc384cf
authored
6月 16, 2016
作者:
Frederic Bastien
提交者:
sentient07
7月 08, 2016
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Special Alloc and AllocEmpty to move them to the GPU in one pass.
上级
12fa1c5b
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
40 行增加
和
6 行删除
+40
-6
opt.py
theano/gpuarray/opt.py
+14
-1
test_opt.py
theano/gpuarray/tests/test_opt.py
+26
-5
没有找到文件。
theano/gpuarray/opt.py
浏览文件 @
fbc384cf
...
@@ -323,7 +323,20 @@ class GraphToGPU(NavigatorOptimizer):
...
@@ -323,7 +323,20 @@ class GraphToGPU(NavigatorOptimizer):
context_name
=
i
.
type
.
context_name
context_name
=
i
.
type
.
context_name
move_to_GPU
=
True
move_to_GPU
=
True
break
break
if
(
not
move_to_GPU
and
isinstance
(
node
.
op
,
(
theano
.
tensor
.
Alloc
,
theano
.
tensor
.
AllocEmpty
))):
# If the Alloc[Empty] have a client that will be moved
# to the GPU, we should move the Alloc* on the GPU.
# We approximate this by supposing that if we have an
# optimization for one of the clients op, then we will
# move the client to the GPU.
for
c
,
_
in
node
.
outputs
[
0
]
.
clients
:
if
(
c
!=
'output'
and
(
self
.
local_optimizers_map
.
get
(
c
.
op
,
[])
+
self
.
local_optimizers_map
.
get
(
type
(
c
.
op
)))):
move_to_GPU
=
True
new_ops
=
None
new_ops
=
None
outputs
=
[]
outputs
=
[]
# Apply the lifter
# Apply the lifter
...
...
theano/gpuarray/tests/test_opt.py
浏览文件 @
fbc384cf
...
@@ -138,11 +138,21 @@ def test_local_gpualloc_memset_0():
...
@@ -138,11 +138,21 @@ def test_local_gpualloc_memset_0():
ones
=
numpy
.
ones
((
2
,),
dtype
=
'float32'
)
ones
=
numpy
.
ones
((
2
,),
dtype
=
'float32'
)
# Test with 0 from CPU op.
# Test with 0 from CPU op.
# Should not be transfered as the only client is the output
a
=
tensor
.
alloc
(
z
,
i
)
a
=
tensor
.
alloc
(
z
,
i
)
f
=
theano
.
function
([
i
],
a
,
mode
=
mode_with_gpu
)
f
=
theano
.
function
([
i
],
a
,
mode
=
mode_with_gpu
)
topo
=
f
.
maker
.
fgraph
.
toposort
()
topo
=
f
.
maker
.
fgraph
.
toposort
()
assert
len
(
topo
)
==
2
assert
len
(
topo
)
==
1
assert
isinstance
(
topo
[
0
]
.
op
,
GpuAlloc
)
and
topo
[
0
]
.
op
.
memset_0
assert
isinstance
(
topo
[
0
]
.
op
,
theano
.
tensor
.
Alloc
)
assert
(
numpy
.
asarray
(
f
(
6
))
==
0
)
.
all
()
# Test with 0 from CPU op.
# Should be transfered as it is used by another op.
a
=
tensor
.
alloc
(
z
,
i
)
f
=
theano
.
function
([
i
],
a
.
cumsum
(),
mode
=
mode_with_gpu
)
topo
=
f
.
maker
.
fgraph
.
toposort
()
assert
len
(
topo
)
==
3
assert
isinstance
(
topo
[
0
]
.
op
,
GpuAlloc
)
assert
(
numpy
.
asarray
(
f
(
6
))
==
0
)
.
all
()
assert
(
numpy
.
asarray
(
f
(
6
))
==
0
)
.
all
()
# Test with 0
# Test with 0
...
@@ -177,19 +187,30 @@ def test_local_gpualloc_empty():
...
@@ -177,19 +187,30 @@ def test_local_gpualloc_empty():
ii
=
theano
.
tensor
.
iscalar
()
ii
=
theano
.
tensor
.
iscalar
()
# Test with vector
# Test with vector
# Should not be moved as the only client is the uutput
a
=
tensor
.
AllocEmpty
(
'float32'
)(
i
)
a
=
tensor
.
AllocEmpty
(
'float32'
)(
i
)
f
=
theano
.
function
([
i
],
a
,
mode
=
mode_with_gpu
)
f
=
theano
.
function
([
i
],
a
,
mode
=
mode_with_gpu
)
topo
=
f
.
maker
.
fgraph
.
toposort
()
topo
=
f
.
maker
.
fgraph
.
toposort
()
assert
len
(
topo
)
==
2
assert
len
(
topo
)
==
1
assert
isinstance
(
topo
[
0
]
.
op
,
theano
.
tensor
.
AllocEmpty
)
# This return not initilized data, so we can only check the shape
assert
f
(
3
)
.
shape
==
(
3
,)
# Test with vector
# Should be moved
a
=
tensor
.
AllocEmpty
(
'float32'
)(
i
)
f
=
theano
.
function
([
i
],
a
.
cumsum
(),
mode
=
mode_with_gpu
)
topo
=
f
.
maker
.
fgraph
.
toposort
()
assert
len
(
topo
)
==
3
assert
isinstance
(
topo
[
0
]
.
op
,
GpuAllocEmpty
)
assert
isinstance
(
topo
[
0
]
.
op
,
GpuAllocEmpty
)
# This return not initilized data, so we can only check the shape
# This return not initilized data, so we can only check the shape
assert
f
(
3
)
.
shape
==
(
3
,)
assert
f
(
3
)
.
shape
==
(
3
,)
# Test with matrix
# Test with matrix
a
=
tensor
.
AllocEmpty
(
'float32'
)(
i
,
ii
)
a
=
tensor
.
AllocEmpty
(
'float32'
)(
i
,
ii
)
f
=
theano
.
function
([
i
,
ii
],
a
,
mode
=
mode_with_gpu
)
f
=
theano
.
function
([
i
,
ii
],
a
.
cumsum
(
axis
=
0
)
,
mode
=
mode_with_gpu
)
topo
=
f
.
maker
.
fgraph
.
toposort
()
topo
=
f
.
maker
.
fgraph
.
toposort
()
assert
len
(
topo
)
==
2
assert
len
(
topo
)
==
3
assert
isinstance
(
topo
[
0
]
.
op
,
GpuAllocEmpty
)
assert
isinstance
(
topo
[
0
]
.
op
,
GpuAllocEmpty
)
# This return not initilized data, so we can only check the shape
# This return not initilized data, so we can only check the shape
assert
f
(
3
,
4
)
.
shape
==
(
3
,
4
)
assert
f
(
3
,
4
)
.
shape
==
(
3
,
4
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论