Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
9f48c753
提交
9f48c753
authored
10月 30, 2013
作者:
Frederic
提交者:
Arnaud Bergeron
10月 30, 2013
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Move Flatten to the new GPU back-end by reusing reshape.
上级
2284a814
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
55 行增加
和
3 行删除
+55
-3
opt.py
theano/sandbox/gpuarray/opt.py
+18
-3
test_opt.py
theano/sandbox/gpuarray/tests/test_opt.py
+37
-0
没有找到文件。
theano/sandbox/gpuarray/opt.py
浏览文件 @
9f48c753
...
...
@@ -62,7 +62,10 @@ def op_lifter(OP):
new_op
=
maker
(
node
)
# This is needed as sometimes new_op inherit from OP.
if
new_op
and
new_op
!=
node
.
op
:
return
[
host_from_gpu
(
new_op
(
*
node
.
inputs
))]
if
isinstance
(
new_op
,
theano
.
Op
):
return
[
host_from_gpu
(
new_op
(
*
node
.
inputs
))]
else
:
# suppose it is a variable on the GPU
return
[
host_from_gpu
(
new_op
)]
return
False
local_opt
.
__name__
=
maker
.
__name__
return
local_optimizer
([
OP
])(
local_opt
)
...
...
@@ -128,12 +131,24 @@ def local_gpureshape(node):
if
type
(
node
.
op
)
is
not
tensor
.
Reshape
:
return
None
if
name
:
name
=
'Gpu'
+
name
name
=
'Gpu'
+
name
res
=
GpuReshape
(
op
.
ndim
,
op
.
name
)
o
=
res
(
*
node
.
inputs
)
return
res
@register_opt
()
@op_lifter
(
tensor
.
Flatten
)
def
local_gpuflatten
(
node
):
op
=
node
.
op
if
type
(
node
.
op
)
is
not
tensor
.
Flatten
:
return
None
if
op
.
outdim
!=
1
:
return
None
res
=
GpuReshape
(
op
.
outdim
,
None
)
o
=
res
(
node
.
inputs
[
0
],
theano
.
tensor
.
constant
([
-
1
]))
return
o
@register_opt
()
@op_lifter
(
tensor
.
Elemwise
)
def
local_gpu_elemwise
(
node
):
...
...
theano/sandbox/gpuarray/tests/test_opt.py
0 → 100644
浏览文件 @
9f48c753
import
numpy
import
theano
from
theano.tests
import
unittest_tools
as
utt
from
theano.sandbox.gpuarray.basic_ops
import
GpuReshape
import
theano.sandbox.gpuarray
if
theano
.
sandbox
.
gpuarray
.
pygpu
is
None
:
raise
SkipTest
(
"pygpu not installed"
)
import
theano.sandbox.cuda
as
cuda_ndarray
if
cuda_ndarray
.
cuda_available
and
not
theano
.
sandbox
.
gpuarray
.
pygpu_activated
:
if
not
cuda_ndarray
.
use
.
device_number
:
cuda_ndarray
.
use
(
'gpu'
)
theano
.
sandbox
.
gpuarray
.
init_dev
(
'cuda'
)
if
not
theano
.
sandbox
.
gpuarray
.
pygpu_activated
:
raise
SkipTest
(
"pygpu disabled"
)
if
theano
.
config
.
mode
==
'FAST_COMPILE'
:
mode_with_gpu
=
theano
.
compile
.
mode
.
get_mode
(
'FAST_RUN'
)
.
including
(
'gpuarray'
)
.
excluding
(
'gpu'
)
mode_without_gpu
=
theano
.
compile
.
mode
.
get_mode
(
'FAST_RUN'
)
.
excluding
(
'gpuarray'
)
else
:
mode_with_gpu
=
theano
.
compile
.
mode
.
get_default_mode
()
.
including
(
'gpuarray'
)
.
excluding
(
'gpu'
)
mode_without_gpu
=
theano
.
compile
.
mode
.
get_default_mode
()
.
excluding
(
'gpuarray'
)
def
test_flatten
():
m
=
theano
.
tensor
.
fmatrix
()
f
=
theano
.
function
([
m
],
m
.
flatten
(),
mode
=
mode_with_gpu
)
val
=
numpy
.
random
.
rand
(
10
,
11
)
.
astype
(
"float32"
)
res
=
f
(
val
)
utt
.
assert_allclose
(
res
,
val
.
flatten
())
assert
res
.
shape
==
val
.
flatten
()
.
shape
assert
GpuReshape
in
[
type
(
node
.
op
)
for
node
in
f
.
maker
.
fgraph
.
toposort
()]
\ No newline at end of file
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论