Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
30d8150c
提交
30d8150c
authored
2月 07, 2012
作者:
Olivier Delalleau
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
PEP8
上级
3db224ef
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
38 行增加
和
23 行删除
+38
-23
cc.py
theano/gof/cc.py
+38
-23
没有找到文件。
theano/gof/cc.py
浏览文件 @
30d8150c
...
@@ -1236,20 +1236,21 @@ class OpWiseCLinker(link.LocalLinker):
...
@@ -1236,20 +1236,21 @@ class OpWiseCLinker(link.LocalLinker):
self
.
no_recycling
=
no_recycling
self
.
no_recycling
=
no_recycling
return
self
return
self
def
make_all
(
self
,
profiler
=
None
,
input_storage
=
None
,
output_storage
=
None
):
def
make_all
(
self
,
profiler
=
None
,
input_storage
=
None
,
output_storage
=
None
):
# The lock will be acquired when we compile the first
# The lock will be acquired when we compile the first
# C code. We will keep the lock untill all the function
# C code. We will keep the lock untill all the function
# compilation will be finished. This allow to don't
# compilation will be finished. This allow to don't
# require the lock when all c code are already compiled!
# require the lock when all c code are already compiled!
orig_n_lock
=
getattr
(
get_lock
,
"n_lock"
,
0
)
orig_n_lock
=
getattr
(
get_lock
,
"n_lock"
,
0
)
try
:
try
:
env
=
self
.
env
env
=
self
.
env
order
=
env
.
toposort
()
order
=
env
.
toposort
()
no_recycling
=
self
.
no_recycling
no_recycling
=
self
.
no_recycling
input_storage
,
output_storage
,
storage_map
=
link
.
map_storage
(
env
,
order
,
input_storage
,
output_storage
)
input_storage
,
output_storage
,
storage_map
=
link
.
map_storage
(
env
,
order
,
input_storage
,
output_storage
)
if
self
.
allow_gc
:
if
self
.
allow_gc
:
computed
,
last_user
=
link
.
gc_helper
(
order
)
computed
,
last_user
=
link
.
gc_helper
(
order
)
post_thunk_old_storage
=
[]
post_thunk_old_storage
=
[]
...
@@ -1267,7 +1268,7 @@ class OpWiseCLinker(link.LocalLinker):
...
@@ -1267,7 +1268,7 @@ class OpWiseCLinker(link.LocalLinker):
# There are ops that don't have _op_use_c_code property
# There are ops that don't have _op_use_c_code property
# for example ifelse (or any ops that come with their own
# for example ifelse (or any ops that come with their own
# make_thunk
# make_thunk
old_value
=
getattr
(
node
.
op
,
'_op_use_c_code'
,
False
)
old_value
=
getattr
(
node
.
op
,
'_op_use_c_code'
,
False
)
try
:
try
:
node
.
op
.
_op_use_c_code
=
True
node
.
op
.
_op_use_c_code
=
True
thunks
+=
[
node
.
op
.
make_thunk
(
node
,
thunks
+=
[
node
.
op
.
make_thunk
(
node
,
...
@@ -1282,31 +1283,37 @@ class OpWiseCLinker(link.LocalLinker):
...
@@ -1282,31 +1283,37 @@ class OpWiseCLinker(link.LocalLinker):
if
self
.
allow_gc
:
if
self
.
allow_gc
:
post_thunk_old_storage
.
append
([
storage_map
[
input
]
post_thunk_old_storage
.
append
([
storage_map
[
input
]
for
input
in
node
.
inputs
for
input
in
node
.
inputs
if
(
input
in
computed
)
and
(
input
not
in
env
.
outputs
)
and
node
==
last_user
[
input
]])
if
((
input
in
computed
)
and
(
input
not
in
env
.
outputs
)
and
node
==
last_user
[
input
])])
if
no_recycling
is
True
:
if
no_recycling
is
True
:
no_recycling
=
storage_map
.
values
()
no_recycling
=
storage_map
.
values
()
no_recycling
=
utils
.
difference
(
no_recycling
,
input_storage
)
no_recycling
=
utils
.
difference
(
no_recycling
,
input_storage
)
else
:
else
:
no_recycling
=
[
storage_map
[
r
]
for
r
in
no_recycling
if
r
not
in
env
.
inputs
]
no_recycling
=
[
storage_map
[
r
]
for
r
in
no_recycling
if
r
not
in
env
.
inputs
]
f
=
link
.
streamline
(
env
,
thunks
,
order
,
f
=
link
.
streamline
(
env
,
thunks
,
order
,
post_thunk_old_storage
,
post_thunk_old_storage
,
no_recycling
=
no_recycling
,
no_recycling
=
no_recycling
,
nice_errors
=
self
.
nice_errors
)
nice_errors
=
self
.
nice_errors
)
f
.
allow_gc
=
self
.
allow_gc
f
.
allow_gc
=
self
.
allow_gc
finally
:
finally
:
# Release lock on compilation directory.
# Release lock on compilation directory.
if
getattr
(
get_lock
,
"n_lock"
,
0
)
>
orig_n_lock
:
if
getattr
(
get_lock
,
"n_lock"
,
0
)
>
orig_n_lock
:
release_lock
()
release_lock
()
assert
get_lock
.
n_lock
==
orig_n_lock
assert
get_lock
.
n_lock
==
orig_n_lock
return
f
,
[
link
.
Container
(
input
,
storage
)
for
input
,
storage
in
izip
(
env
.
inputs
,
input_storage
)],
\
return
(
f
,
[
link
.
Container
(
output
,
storage
,
True
)
for
output
,
storage
in
izip
(
env
.
outputs
,
output_storage
)],
\
[
link
.
Container
(
input
,
storage
)
thunks
,
order
for
input
,
storage
in
izip
(
env
.
inputs
,
input_storage
)],
[
link
.
Container
(
output
,
storage
,
True
)
for
output
,
storage
in
izip
(
env
.
outputs
,
output_storage
)],
thunks
,
order
)
def
_default_checker
(
x
,
y
):
def
_default_checker
(
x
,
y
):
...
@@ -1315,7 +1322,9 @@ def _default_checker(x, y):
...
@@ -1315,7 +1322,9 @@ def _default_checker(x, y):
variables contain the same data using ==.
variables contain the same data using ==.
"""
"""
if
x
[
0
]
!=
y
[
0
]:
if
x
[
0
]
!=
y
[
0
]:
raise
Exception
(
"Output mismatch."
,
{
'performlinker'
:
x
[
0
],
'clinker'
:
y
[
0
]})
raise
Exception
(
"Output mismatch."
,
{
'performlinker'
:
x
[
0
],
'clinker'
:
y
[
0
]})
class
DualLinker
(
link
.
Linker
):
class
DualLinker
(
link
.
Linker
):
"""WRITEME
"""WRITEME
...
@@ -1329,7 +1338,7 @@ class DualLinker(link.Linker):
...
@@ -1329,7 +1338,7 @@ class DualLinker(link.Linker):
function.
function.
"""
"""
def
__init__
(
self
,
checker
=
_default_checker
):
def
__init__
(
self
,
checker
=
_default_checker
):
"""
"""
Initialize a DualLinker.
Initialize a DualLinker.
...
@@ -1355,10 +1364,11 @@ class DualLinker(link.Linker):
...
@@ -1355,10 +1364,11 @@ class DualLinker(link.Linker):
self
.
env
=
None
self
.
env
=
None
self
.
checker
=
checker
self
.
checker
=
checker
def
accept
(
self
,
env
,
no_recycling
=
[]):
def
accept
(
self
,
env
,
no_recycling
=
[]):
if
self
.
env
is
not
None
and
self
.
env
is
not
env
:
if
self
.
env
is
not
None
and
self
.
env
is
not
env
:
return
type
(
self
)(
self
.
checker
)
.
accept
(
env
,
no_recycling
)
return
type
(
self
)(
self
.
checker
)
.
accept
(
env
,
no_recycling
)
#raise Exception("Cannot accept from a Linker that is already tied to another Env.")
# raise Exception("Cannot accept from a Linker that is already "
# "tied to another Env.")
self
.
env
=
env
self
.
env
=
env
self
.
no_recycling
=
no_recycling
self
.
no_recycling
=
no_recycling
return
self
return
self
...
@@ -1368,16 +1378,20 @@ class DualLinker(link.Linker):
...
@@ -1368,16 +1378,20 @@ class DualLinker(link.Linker):
env
=
self
.
env
env
=
self
.
env
no_recycling
=
self
.
no_recycling
no_recycling
=
self
.
no_recycling
_f
,
i1
,
o1
,
thunks1
,
order1
=
link
.
PerformLinker
()
.
accept
(
env
,
no_recycling
=
no_recycling
)
.
make_all
(
**
kwargs
)
_f
,
i1
,
o1
,
thunks1
,
order1
=
link
.
PerformLinker
()
.
accept
(
env
,
no_recycling
=
no_recycling
)
.
make_all
(
**
kwargs
)
kwargs
.
pop
(
'input_storage'
,
None
)
kwargs
.
pop
(
'input_storage'
,
None
)
_f
,
i2
,
o2
,
thunks2
,
order2
=
OpWiseCLinker
()
.
accept
(
env
,
no_recycling
=
no_recycling
)
.
make_all
(
**
kwargs
)
_f
,
i2
,
o2
,
thunks2
,
order2
=
OpWiseCLinker
()
.
accept
(
env
,
no_recycling
=
no_recycling
)
.
make_all
(
**
kwargs
)
def
f
():
def
f
():
for
input1
,
input2
in
izip
(
i1
,
i2
):
for
input1
,
input2
in
izip
(
i1
,
i2
):
# set the inputs to be the same in both branches
# Set the inputs to be the same in both branches.
# the copy is necessary in order for inplace ops not to interfere
# The copy is necessary in order for inplace ops not to
# interfere.
input2
.
storage
[
0
]
=
copy
(
input1
.
storage
[
0
])
input2
.
storage
[
0
]
=
copy
(
input1
.
storage
[
0
])
for
thunk1
,
thunk2
,
node1
,
node2
in
izip
(
thunks1
,
thunks2
,
order1
,
order2
):
for
thunk1
,
thunk2
,
node1
,
node2
in
izip
(
thunks1
,
thunks2
,
order1
,
order2
):
for
output
,
storage
in
izip
(
node1
.
outputs
,
thunk1
.
outputs
):
for
output
,
storage
in
izip
(
node1
.
outputs
,
thunk1
.
outputs
):
if
output
in
no_recycling
:
if
output
in
no_recycling
:
storage
[
0
]
=
None
storage
[
0
]
=
None
...
@@ -1387,7 +1401,8 @@ class DualLinker(link.Linker):
...
@@ -1387,7 +1401,8 @@ class DualLinker(link.Linker):
try
:
try
:
thunk1
()
thunk1
()
thunk2
()
thunk2
()
for
output1
,
output2
in
izip
(
thunk1
.
outputs
,
thunk2
.
outputs
):
for
output1
,
output2
in
izip
(
thunk1
.
outputs
,
thunk2
.
outputs
):
self
.
checker
(
output1
,
output2
)
self
.
checker
(
output1
,
output2
)
except
Exception
:
except
Exception
:
link
.
raise_with_op
(
node1
)
link
.
raise_with_op
(
node1
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论