Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
d65475af
提交
d65475af
authored
7月 11, 2013
作者:
James Bergstra
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #3 from nouiz/gpu_inc_diagonal_subtensor
Gpu inc diagonal subtensor and optimization refactoring.
上级
cf85d105
92327dec
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
72 行增加
和
25 行删除
+72
-25
conv3d2d.py
theanoconv3d2d/conv3d2d.py
+57
-22
tests.py
theanoconv3d2d/tests.py
+15
-3
没有找到文件。
theanoconv3d2d/conv3d2d.py
浏览文件 @
d65475af
...
@@ -21,7 +21,12 @@ class DiagonalSubtensor(Op):
...
@@ -21,7 +21,12 @@ class DiagonalSubtensor(Op):
"""
"""
Work on the GPU.
Work on the GPU.
"""
"""
def
__init__
(
self
,
inplace
):
def
__str__
(
self
):
if
self
.
inplace
:
return
"
%
s{inplace}"
%
self
.
__class__
.
__name__
return
"
%
s"
%
self
.
__class__
.
__name__
def
__init__
(
self
,
inplace
=
False
):
self
.
inplace
=
inplace
self
.
inplace
=
inplace
if
inplace
:
if
inplace
:
self
.
view_map
=
{
0
:
[
0
]}
self
.
view_map
=
{
0
:
[
0
]}
...
@@ -57,7 +62,12 @@ diagonal_subtensor = DiagonalSubtensor(False)
...
@@ -57,7 +62,12 @@ diagonal_subtensor = DiagonalSubtensor(False)
class
IncDiagonalSubtensor
(
Op
):
class
IncDiagonalSubtensor
(
Op
):
def
__init__
(
self
,
inplace
):
def
__str__
(
self
):
if
self
.
inplace
:
return
"
%
s{inplace}"
%
self
.
__class__
.
__name__
return
"
%
s"
%
self
.
__class__
.
__name__
def
__init__
(
self
,
inplace
=
False
):
self
.
inplace
=
inplace
self
.
inplace
=
inplace
if
inplace
:
if
inplace
:
self
.
destroy_map
=
{
0
:
[
0
]}
self
.
destroy_map
=
{
0
:
[
0
]}
...
@@ -176,24 +186,49 @@ def conv3d(signals, filters,
...
@@ -176,24 +186,49 @@ def conv3d(signals, filters,
return
out_5d
return
out_5d
@cuda.opt.register_opt
()
def
make_gpu_optimizer
(
op
,
to_gpu
):
@theano.gof.local_optimizer
([])
"""This function create optimizer that move some inputs to the GPU
def
local_gpu_diagonal_subtensor
(
node
):
for op that work on both CPU and GPU.
"""
diagonal_subtensor(host_from_gpu()) -> host_from_gpu(diagonal_subtensor)
The op object is created by calling op(), so good default value
gpu_from_host(diagonal_subtensor) -> diagonal_subtensor(gpu_from_host)
are needed.
We suppose the same op work with CPU and GPU inputs.
:param op: the op that support GPU inputs
:param to_gpu: a list of op inputs that are moved to the GPU.
"""
"""
if
isinstance
(
node
.
op
,
DiagonalSubtensor
):
@theano.gof.local_optimizer
([])
input
=
node
.
inputs
[
0
]
def
local_to_gpu
(
node
):
if
input
.
owner
and
isinstance
(
input
.
owner
.
op
,
cuda
.
HostFromGpu
):
"""
return
[
cuda
.
host_from_gpu
(
diagonal_subtensor
(
cuda
.
gpu_from_host
(
input
),
op(host_from_gpu()) -> host_from_gpu(op)
*
node
.
inputs
[
1
:]))]
gpu_from_host(op) -> op(gpu_from_host)
if
node
.
op
==
cuda
.
gpu_from_host
:
"""
host_input
=
node
.
inputs
[
0
]
if
isinstance
(
node
.
op
,
op
):
if
host_input
.
owner
and
isinstance
(
host_input
.
owner
.
op
,
#op(host_from_gpu()) -> host_from_gpu(op)
DiagonalSubtensor
):
#If any of the input that go on the GPU are on the GPU,
diag_node
=
host_input
.
owner
#move the op to the gpu.
return
[
tensor
.
diagonal_subtensor
(
if
any
(
node
.
inputs
[
idx
]
.
owner
and
cuda
.
gpu_from_host
(
diag_node
.
inputs
[
0
]),
isinstance
(
node
.
inputs
[
idx
]
.
owner
.
op
,
cuda
.
HostFromGpu
)
*
diag_node
.
inputs
[
1
:])]
for
idx
in
to_gpu
):
return
False
new_inp
=
list
(
node
.
inputs
)
for
idx
in
to_gpu
:
new_inp
[
idx
]
=
cuda
.
gpu_from_host
(
new_inp
[
idx
])
return
[
cuda
.
host_from_gpu
(
op
()(
*
new_inp
))]
if
node
.
op
==
cuda
.
gpu_from_host
:
#gpu_from_host(op) -> op(gpu_from_host)
host_input
=
node
.
inputs
[
0
]
if
host_input
.
owner
and
isinstance
(
host_input
.
owner
.
op
,
op
):
op_node
=
host_input
.
owner
new_inp
=
list
(
op_node
.
inputs
)
for
idx
in
to_gpu
:
new_inp
[
idx
]
=
cuda
.
gpu_from_host
(
new_inp
[
idx
])
return
[
op
()(
*
new_inp
)]
return
False
local_to_gpu
.
__name__
=
"local_to_gpu_"
+
op
.
__name__
cuda
.
opt
.
register_opt
()(
local_to_gpu
)
make_gpu_optimizer
(
DiagonalSubtensor
,
[
0
])
make_gpu_optimizer
(
IncDiagonalSubtensor
,
[
0
,
3
])
theanoconv3d2d/tests.py
浏览文件 @
d65475af
...
@@ -123,12 +123,24 @@ def test_conv3d():
...
@@ -123,12 +123,24 @@ def test_conv3d():
s_filters
=
shared
(
filters
)
s_filters
=
shared
(
filters
)
s_output
=
shared
(
signals
*
0
)
s_output
=
shared
(
signals
*
0
)
out
=
conv3d
(
s_signals
,
s_filters
,
signals_shape
=
signals
.
shape
,
filters_shape
=
filters
.
shape
)
newconv3d
=
theano
.
function
([],
[],
newconv3d
=
theano
.
function
([],
[],
updates
=
{
s_output
:
conv3d
(
s_signals
,
s_filters
,
updates
=
{
s_output
:
out
},
signals_shape
=
signals
.
shape
,
filters_shape
=
filters
.
shape
)},
mode
=
mode
)
mode
=
mode
)
t0
=
time
.
time
()
t0
=
time
.
time
()
newconv3d
()
newconv3d
()
print
time
.
time
()
-
t0
print
time
.
time
()
-
t0
gsignals
,
gfilters
=
theano
.
grad
(
out
.
sum
(),
[
s_signals
,
s_filters
])
gnewconv3d
=
theano
.
function
([],
[],
updates
=
[(
s_filters
,
gfilters
),
(
s_signals
,
gsignals
)],
mode
=
mode
,
name
=
'grad'
)
t0
=
time
.
time
()
gnewconv3d
()
print
'grad'
,
time
.
time
()
-
t0
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论