Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
fa552c4b
提交
fa552c4b
authored
3月 07, 2012
作者:
Frederic
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
pep8
上级
897082b5
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
41 行增加
和
27 行删除
+41
-27
cc.py
theano/gof/cc.py
+41
-27
没有找到文件。
theano/gof/cc.py
浏览文件 @
fa552c4b
...
@@ -4,7 +4,7 @@ Defines Linkers that deal with C implementations.
...
@@ -4,7 +4,7 @@ Defines Linkers that deal with C implementations.
# Python imports
# Python imports
from
copy
import
copy
from
copy
import
copy
import
re
#for set_compiledir
import
re
#
for set_compiledir
import
os
import
os
import
StringIO
import
StringIO
import
sys
import
sys
...
@@ -340,14 +340,19 @@ def apply_policy(policy, r, name, sub):
...
@@ -340,14 +340,19 @@ def apply_policy(policy, r, name, sub):
def
struct_variable_codeblocks
(
variable
,
policies
,
id
,
symbol_table
,
sub
):
def
struct_variable_codeblocks
(
variable
,
policies
,
id
,
symbol_table
,
sub
):
"""WRITEME
"""WRITEME
variable -> a Variable
variable -> a Variable
policies -> a pair of tuples ((declare_policy, behavior_policy, cleanup_policy), -- at construction
policies -> a pair of tuples ((declare_policy, behavior_policy,
(declare_policy, behavior_policy, cleanup_policy)) -- at execution
cleanup_policy), -- at construction
the first list will produce an element of the 'struct_builders' argument in struct_gen
(declare_policy, behavior_policy,
the second list will produce an element of the 'blocks' argument in struct_gen
cleanup_policy)) -- at execution
the first list will produce an element of the
'struct_builders' argument in struct_gen the second
list will produce an element of the 'blocks' argument
in struct_gen
id -> the id assigned to this variable's task in the computation
id -> the id assigned to this variable's task in the computation
symbol_table -> a dict that maps variables to variable names. It
is not read
symbol_table -> a dict that maps variables to variable names. It
by this function but a variable name for the variable is computed and added
is not read by this function but a variable name for the
to the table.
variable is computed and added
to the table.
sub -> dictionary for use by L{CodeBlock}.
sub -> dictionary for use by L{CodeBlock}.
"""
"""
...
@@ -361,14 +366,14 @@ def struct_variable_codeblocks(variable, policies, id, symbol_table, sub):
...
@@ -361,14 +366,14 @@ def struct_variable_codeblocks(variable, policies, id, symbol_table, sub):
sub
[
'stor_ptr'
]
=
"storage_
%
s"
%
name
sub
[
'stor_ptr'
]
=
"storage_
%
s"
%
name
# struct_declare, struct_behavior, struct_cleanup, sub)
# struct_declare, struct_behavior, struct_cleanup, sub)
struct_builder
=
CodeBlock
(
*
[
apply_policy
(
policy
,
variable
,
name
,
sub
)
struct_builder
=
CodeBlock
(
*
[
apply_policy
(
policy
,
variable
,
name
,
sub
)
for
policy
in
policies
[
0
]]
+
[
sub
])
for
policy
in
policies
[
0
]]
+
[
sub
])
sub
[
'id'
]
=
id
+
1
sub
[
'id'
]
=
id
+
1
sub
[
'fail'
]
=
failure_code
(
sub
)
sub
[
'fail'
]
=
failure_code
(
sub
)
sub
[
'py_ptr'
]
=
"py_
%
s"
%
name
sub
[
'py_ptr'
]
=
"py_
%
s"
%
name
sub
[
'stor_ptr'
]
=
"storage_
%
s"
%
name
sub
[
'stor_ptr'
]
=
"storage_
%
s"
%
name
# run_declare, run_behavior, run_cleanup, sub)
# run_declare, run_behavior, run_cleanup, sub)
block
=
CodeBlock
(
*
[
apply_policy
(
policy
,
variable
,
name
,
sub
)
block
=
CodeBlock
(
*
[
apply_policy
(
policy
,
variable
,
name
,
sub
)
for
policy
in
policies
[
1
]]
+
[
sub
])
for
policy
in
policies
[
1
]]
+
[
sub
])
return
struct_builder
,
block
return
struct_builder
,
block
...
@@ -392,7 +397,8 @@ class CLinker(link.Linker):
...
@@ -392,7 +397,8 @@ class CLinker(link.Linker):
"""WRITEME"""
"""WRITEME"""
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
)()
.
accept
(
env
,
no_recycling
)
return
type
(
self
)()
.
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
.
fetch_variables
()
self
.
fetch_variables
()
self
.
no_recycling
=
no_recycling
self
.
no_recycling
=
no_recycling
...
@@ -437,8 +443,6 @@ class CLinker(link.Linker):
...
@@ -437,8 +443,6 @@ class CLinker(link.Linker):
no_recycling
=
self
.
no_recycling
no_recycling
=
self
.
no_recycling
env
=
self
.
env
self
.
consts
=
[]
self
.
consts
=
[]
c_support_code_apply
=
[]
c_support_code_apply
=
[]
...
@@ -464,21 +468,28 @@ class CLinker(link.Linker):
...
@@ -464,21 +468,28 @@ class CLinker(link.Linker):
# it might be possible to inline constant variables as C literals
# it might be possible to inline constant variables as C literals
## if getattr(variable, 'constant', False):
## if getattr(variable, 'constant', False):
# policy = [[what to declare in the struct, what to do at construction, what to do at destruction],
# policy = [[what to declare in the struct,
# [what to declare in each run, what to do at the beginning of each run, what to do at the end of each run]]
# what to do at construction,
# what to do at destruction],
# [what to declare in each run,
# what to do at the beginning of each run,
# what to do at the end of each run]]
if
variable
in
self
.
inputs
:
if
variable
in
self
.
inputs
:
# we need to extract the new inputs at each run
# we need to extract the new inputs at each run
# they do not need to be relayed to Python, so we don't sync
# they do not need to be relayed to Python, so we don't sync
# if isinstance(variable, Constant):
# if isinstance(variable, Constant):
# raise TypeError("Inputs to CLinker cannot be Constant.", variable)
# raise TypeError("Inputs to CLinker cannot be Constant.",
# variable)
policy
=
[[
get_nothing
,
get_nothing
,
get_nothing
],
policy
=
[[
get_nothing
,
get_nothing
,
get_nothing
],
[
get_c_declare
,
get_c_extract
,
get_c_cleanup
]]
[
get_c_declare
,
get_c_extract
,
get_c_cleanup
]]
elif
variable
in
self
.
orphans
:
elif
variable
in
self
.
orphans
:
if
not
isinstance
(
variable
,
graph
.
Value
):
if
not
isinstance
(
variable
,
graph
.
Value
):
raise
TypeError
(
"All orphans to CLinker must be Value instances."
,
variable
)
raise
TypeError
(
"All orphans to CLinker must be Value"
" instances."
,
variable
)
if
isinstance
(
variable
,
graph
.
Constant
):
if
isinstance
(
variable
,
graph
.
Constant
):
try
:
try
:
symbol
[
variable
]
=
"("
+
variable
.
type
.
c_literal
(
variable
.
data
)
+
")"
symbol
[
variable
]
=
(
"("
+
variable
.
type
.
c_literal
(
variable
.
data
)
+
")"
)
self
.
consts
.
append
(
variable
)
self
.
consts
.
append
(
variable
)
self
.
orphans
.
remove
(
variable
)
self
.
orphans
.
remove
(
variable
)
continue
continue
...
@@ -542,8 +553,9 @@ class CLinker(link.Linker):
...
@@ -542,8 +553,9 @@ class CLinker(link.Linker):
# specified by the op's c_var_names method to the actual
# specified by the op's c_var_names method to the actual
# variable names that we will use.
# variable names that we will use.
## ivnames, ovnames = op.c_var_names()
## ivnames, ovnames = op.c_var_names()
sub
=
dict
(
failure_var
=
failure_var
)
sub
=
dict
(
failure_var
=
failure_var
)
## for variable, vname in zip(op.inputs + op.outputs, ivnames + ovnames):
## for variable, vname in zip(op.inputs + op.outputs,
## ivnames + ovnames):
## sub[vname] = symbol[variable]
## sub[vname] = symbol[variable]
name
=
"node_
%
i"
%
node_num
name
=
"node_
%
i"
%
node_num
...
@@ -624,7 +636,7 @@ class CLinker(link.Linker):
...
@@ -624,7 +636,7 @@ class CLinker(link.Linker):
self
.
init_tasks
=
init_tasks
self
.
init_tasks
=
init_tasks
self
.
blocks
=
blocks
self
.
blocks
=
blocks
self
.
tasks
=
tasks
self
.
tasks
=
tasks
all
=
self
.
inputs
+
self
.
outputs
+
self
.
orphans
all
_info
=
self
.
inputs
+
self
.
outputs
+
self
.
orphans
self
.
c_support_code_apply
=
c_support_code_apply
self
.
c_support_code_apply
=
c_support_code_apply
if
(
self
.
init_tasks
,
self
.
tasks
)
!=
self
.
get_init_tasks
():
if
(
self
.
init_tasks
,
self
.
tasks
)
!=
self
.
get_init_tasks
():
...
@@ -636,8 +648,8 @@ class CLinker(link.Linker):
...
@@ -636,8 +648,8 @@ class CLinker(link.Linker):
# List of indices that should be ignored when passing the arguments
# List of indices that should be ignored when passing the arguments
# (basically, everything that the previous call to uniq eliminated)
# (basically, everything that the previous call to uniq eliminated)
self
.
dupidx
=
[
i
for
i
,
x
in
enumerate
(
all
)
self
.
dupidx
=
[
i
for
i
,
x
in
enumerate
(
all
_info
)
if
all
.
count
(
x
)
>
1
and
all
.
index
(
x
)
!=
i
]
if
all
_info
.
count
(
x
)
>
1
and
all_info
.
index
(
x
)
!=
i
]
return
self
.
struct_code
return
self
.
struct_code
def
support_code
(
self
):
def
support_code
(
self
):
...
@@ -919,10 +931,13 @@ class CLinker(link.Linker):
...
@@ -919,10 +931,13 @@ class CLinker(link.Linker):
type of the node input, and the nature of that input in the
type of the node input, and the nature of that input in the
graph.
graph.
The nature of a typical variable is encoded by integer pairs ``((a,b),c)``:
The nature of a typical variable is encoded by integer pairs
``a`` is the topological position of the input's owner (-1 for graph inputs),
``((a,b),c)``:
``a`` is the topological position of the input's owner
(-1 for graph inputs),
``b`` is the index of the variable in the owner's output list.
``b`` is the index of the variable in the owner's output list.
``c`` is a flag indicating whether the variable is in the no_recycling set.
``c`` is a flag indicating whether the variable is in the
no_recycling set.
If a variable is also a graph output, then its position in the
If a variable is also a graph output, then its position in the
outputs list is also bundled with this tuple (after the b).
outputs list is also bundled with this tuple (after the b).
...
@@ -1202,7 +1217,6 @@ class CLinker(link.Linker):
...
@@ -1202,7 +1217,6 @@ class CLinker(link.Linker):
return
mod
return
mod
def
cthunk_factory
(
self
,
error_storage
,
in_storage
,
out_storage
,
def
cthunk_factory
(
self
,
error_storage
,
in_storage
,
out_storage
,
keep_lock
=
False
):
keep_lock
=
False
):
"""WRITEME
"""WRITEME
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论