Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
62ccf59f
提交
62ccf59f
authored
11月 20, 2015
作者:
Frédéric Bastien
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #3656 from carriepl/scan_backend_speedup
Scan - Move costly checks from runtime to compilation
上级
21adebb5
fa0007df
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
43 行增加
和
20 行删除
+43
-20
scan_op.py
theano/scan_module/scan_op.py
+43
-20
scan_perform.c
theano/scan_module/scan_perform.c
+0
-0
scan_perform.pyx
theano/scan_module/scan_perform.pyx
+0
-0
scan_perform_ext.py
theano/scan_module/scan_perform_ext.py
+0
-0
没有找到文件。
theano/scan_module/scan_op.py
浏览文件 @
62ccf59f
...
...
@@ -314,12 +314,23 @@ class Scan(PureOp):
# Generate the mappings between inner and outer inputs and outputs
# if they haven't already been generated.
self
.
var_mappings
=
self
.
get_oinp_iinp_iout_oout_mappings
()
if
(
hasattr
(
self
,
'fn'
)
and
not
hasattr
(
self
,
'thunk_mit_mot_out_slices'
)):
# The thunk has been compiled before mit_mot preallocation feature
# was implemented. Mark every mit_mot output tap as not having
# been preallocated
self
.
mitmots_preallocated
=
[
False
]
*
self
.
n_mit_mot_outs
if
hasattr
(
self
,
'fn'
):
if
not
hasattr
(
self
,
'thunk_mit_mot_out_slices'
):
# The thunk has been compiled before mit_mot preallocation
# feature was implemented. Mark every mit_mot output tap as
# not having been preallocated
self
.
mitmots_preallocated
=
[
False
]
*
self
.
n_mit_mot_outs
if
not
hasattr
(
self
,
'outs_on_gpu'
):
# The thunk has been compiled before the analysis, at
# compilation time, of the location of the inputs and outputs.
# Perform this analysis here.
self
.
inps_on_gpu
=
[
not
isinstance
(
out
,
theano
.
tensor
.
TensorVariable
)
for
out
in
self
.
fn
.
maker
.
fgraph
.
inputs
]
self
.
outs_on_gpu
=
[
not
isinstance
(
out
,
theano
.
tensor
.
TensorVariable
)
for
out
in
self
.
fn
.
maker
.
fgraph
.
outputs
]
# Ensure that the graph associated with the inner function is valid.
self
.
validate_inner_graph
()
...
...
@@ -858,6 +869,13 @@ class Scan(PureOp):
profile
=
profile
,
on_unused_input
=
'ignore'
)
# Analyse the compile inner function to determine which inputs and
# outputs are on the gpu and speed up some checks during the execution
self
.
inps_on_gpu
=
[
not
isinstance
(
out
,
theano
.
tensor
.
TensorVariable
)
for
out
in
self
.
fn
.
maker
.
fgraph
.
inputs
]
self
.
outs_on_gpu
=
[
not
isinstance
(
out
,
theano
.
tensor
.
TensorVariable
)
for
out
in
self
.
fn
.
maker
.
fgraph
.
outputs
]
try
:
cython_mintaps
=
numpy
.
asarray
(
self
.
mintaps
,
dtype
=
'int32'
)
cython_tap_array_len
=
\
...
...
@@ -894,6 +912,9 @@ class Scan(PureOp):
cython_mitmots_preallocated
=
numpy
.
asarray
(
self
.
mitmots_preallocated
,
dtype
=
'int32'
)
cython_inps_on_gpu
=
numpy
.
asarray
(
self
.
inps_on_gpu
,
dtype
=
'int32'
)
cython_outs_on_gpu
=
numpy
.
asarray
(
self
.
outs_on_gpu
,
dtype
=
'int32'
)
if
hasattr
(
self
,
'destroy_map'
):
cython_destroy_map
=
[
x
in
self
.
destroy_map
for
x
in
xrange
(
len
(
node
.
outputs
))]
...
...
@@ -921,6 +942,8 @@ class Scan(PureOp):
cython_mit_mot_out_slices
,
cython_mit_mot_out_nslices
,
cython_mitmots_preallocated
,
cython_inps_on_gpu
,
cython_outs_on_gpu
,
self
.
fn
.
fn
,
self
.
fn
,
cython_destroy_map
,
...
...
@@ -1280,12 +1303,12 @@ class Scan(PureOp):
var
=
output_storage
[
idx
]
.
storage
[
0
]
old_output_storage
[
idx
]
=
var
if
hasattr
(
var
,
'gpudata'
):
if
var
is
None
:
old_output_data
[
idx
]
=
None
elif
self
.
outs_on_gpu
[
idx
]:
old_output_data
[
idx
]
=
var
.
gpudata
elif
hasattr
(
var
,
'data'
):
old_output_data
[
idx
]
=
var
.
data
else
:
old_output_data
[
idx
]
=
None
old_output_data
[
idx
]
=
var
.
data
# 4.6. Keep a reference to the variables (ndarrays, CudaNdarrays,
# etc) associated with mitmot inputs currently in the
...
...
@@ -1298,12 +1321,12 @@ class Scan(PureOp):
var
=
input_storage
[
idx
+
self
.
n_seqs
]
.
storage
[
0
]
old_mitmot_input_storage
[
idx
]
=
var
if
hasattr
(
var
,
'gpudata'
):
if
var
is
None
:
old_mitmot_input_data
[
idx
]
=
None
elif
self
.
inps_on_gpu
[
idx
]:
old_mitmot_input_data
[
idx
]
=
var
.
gpudata
elif
hasattr
(
var
,
'data'
):
old_mitmot_input_data
[
idx
]
=
var
.
data
else
:
old_mitmot_input_data
[
idx
]
=
None
old_mitmot_input_data
[
idx
]
=
var
.
data
# 5.1 compute outputs
t0_fn
=
time
.
time
()
...
...
@@ -1365,9 +1388,9 @@ class Scan(PureOp):
new_var
=
input_storage
[
self
.
n_seqs
+
inp_idx
]
.
storage
[
0
]
if
old_var
is
new_var
:
old_data
=
old_mitmot_input_data
[
inp_idx
]
if
hasattr
(
new_var
,
'gpudata'
)
:
if
self
.
inps_on_gpu
[
self
.
n_seqs
+
inp_idx
]
:
same_data
=
(
new_var
.
gpudata
==
old_data
)
el
if
hasattr
(
new_var
,
'data'
)
:
el
se
:
same_data
=
(
new_var
.
data
==
old_data
)
else
:
same_data
=
False
...
...
@@ -1411,9 +1434,9 @@ class Scan(PureOp):
old_data
=
old_output_data
[
offset_out
+
j
]
if
old_data
is
None
:
output_reused
=
False
elif
hasattr
(
new_var
,
'gpudata'
)
:
elif
self
.
outs_on_gpu
[
offset_out
+
j
]
:
output_reused
=
(
new_var
.
gpudata
==
old_data
)
el
if
hasattr
(
new_var
,
'data'
)
:
el
se
:
output_reused
=
(
new_var
.
data
==
old_data
)
else
:
output_reused
=
False
...
...
@@ -1454,9 +1477,9 @@ class Scan(PureOp):
if
old_var
is
new_var
:
if
old_data
is
None
:
output_reused
=
False
elif
hasattr
(
new_var
,
'gpudata'
)
:
elif
self
.
outs_on_gpu
[
offset_out
+
j
]
:
output_reused
=
(
new_var
.
gpudata
==
old_data
)
el
if
hasattr
(
new_var
,
'data'
)
:
el
se
:
output_reused
=
(
new_var
.
data
==
old_data
)
else
:
output_reused
=
False
...
...
theano/scan_module/scan_perform.c
浏览文件 @
62ccf59f
This source diff could not be displayed because it is too large. You can
view the blob
instead.
theano/scan_module/scan_perform.pyx
浏览文件 @
62ccf59f
差异被折叠。
点击展开。
theano/scan_module/scan_perform_ext.py
浏览文件 @
62ccf59f
差异被折叠。
点击展开。
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论