Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
9ba00a6e
提交
9ba00a6e
authored
3月 19, 2012
作者:
Pascal Lamblin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Clinker using preallocated memory for outputs
Update key for the compilation cache, the generated code is different, we should force recompilation.
上级
52b83f7a
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
53 行增加
和
11 行删除
+53
-11
cc.py
theano/gof/cc.py
+26
-11
type.py
theano/gof/type.py
+20
-0
type.py
theano/sandbox/cuda/type.py
+7
-0
没有找到文件。
theano/gof/cc.py
浏览文件 @
9ba00a6e
...
...
@@ -301,6 +301,15 @@ def get_c_extract(r, name, sub):
return
pre
+
r
.
type
.
c_extract
(
name
,
sub
)
def
get_c_extract_out
(
r
,
name
,
sub
):
"""WRITEME"""
pre
=
"""
py_
%(name)
s = PyList_GET_ITEM(storage_
%(name)
s, 0);
{Py_XINCREF(py_
%(name)
s);}
"""
%
locals
()
return
pre
+
r
.
type
.
c_extract_out
(
name
,
sub
)
def
get_c_cleanup
(
r
,
name
,
sub
):
"""WRITEME"""
post
=
"""
...
...
@@ -514,18 +523,21 @@ class CLinker(link.Linker):
policy
=
[[
get_c_declare
,
get_c_init
,
get_c_cleanup
],
[
get_nothing
,
get_nothing
,
get_nothing
]]
elif
variable
in
self
.
outputs
:
# outputs don't need to be extracted from Python, so
# we call c_init rather than c_extract
if
variable
.
type
.
c_is_simple
()
or
variable
in
no_recycling
:
# Do not extract output from Python
policy
=
[[
get_nothing
,
get_nothing
,
get_nothing
],
[
get_c_declare
,
get_c_init
,
(
get_c_sync
,
get_c_cleanup
)]]
else
:
# it is useful for complex outputs to reuse
# storage at each run, so we only clean up in the
# destructor
policy
=
[[
get_c_declare
,
get_c_init
,
get_c_cleanup
],
[
get_nothing
,
get_nothing
,
get_c_sync
]]
# We try to use the output that is pre-allocated.
# The linker will usually just reuse the storage
# from last run, but in the first execution,
# it will be None.
# We clean-up at each run to enable garbage collection
# in the Linker.
policy
=
[[
get_nothing
,
get_nothing
,
get_nothing
],
[
get_c_declare
,
get_c_extract_out
,
(
get_c_sync
,
get_c_cleanup
)]]
else
:
raise
Exception
(
"what the fuck"
)
...
...
@@ -961,10 +973,12 @@ class CLinker(link.Linker):
be re-used by the computation (the elements of
self.no_recycling) can affect the code that is generated.
The format of each Op's output signature is simply a list of
The format of each Op's output signature is a (version, no_recycle)
pair, where version is incremented if codegen() changes how it
handles the outputs, and no_recycle is simply a list of
booleans, indicating whether each output is in the
no_recycling set.
no_recycling set.
Older versions of compiled modules only have the
no_recycle list.
"""
return
self
.
cmodule_key_
(
self
.
env
,
self
.
no_recycling
,
compile_args
=
self
.
compile_args
(),
...
...
@@ -1086,7 +1100,8 @@ class CLinker(link.Linker):
node
.
op
,
tuple
((
i
.
type
,
in_sig
(
i
,
node_pos
,
ipos
))
for
ipos
,
i
in
enumerate
(
node
.
inputs
)),
tuple
(
o
in
no_recycling
for
o
in
node
.
outputs
)))
(
1
,
# Increment if cmodule change its handling of outputs
tuple
(
o
in
no_recycling
for
o
in
node
.
outputs
))))
if
error_on_play
[
0
]:
# if one of the signatures is not hashable
...
...
theano/gof/type.py
浏览文件 @
9ba00a6e
...
...
@@ -139,6 +139,26 @@ class CLinkerType(CLinkerObject):
"""
raise
MethodNotDefined
(
"c_extract"
,
type
(
self
),
self
.
__class__
.
__name__
)
def
c_extract_out
(
self
,
name
,
sub
):
"""Optional: C code to extract a PyObject * instance.
Unlike c_extract, c_extract_out has to accept Py_None,
meaning that the variable should be left uninitialized.
"""
return
"""
if (py_
%(name)
s == Py_None)
{
%(c_init_code)
s
}
else
{
%(c_extract_code)
s
}
"""
%
dict
(
name
=
name
,
c_init_code
=
self
.
c_init
(
name
,
sub
),
c_extract_code
=
self
.
c_extract
(
name
,
sub
))
def
c_cleanup
(
self
,
name
,
sub
):
"""Optional: Return c code to clean up after `c_extract`.
...
...
theano/sandbox/cuda/type.py
浏览文件 @
9ba00a6e
...
...
@@ -319,6 +319,13 @@ class CudaNdarrayType(Type):
assert(
%(name)
s);
Py_INCREF(py_
%(name)
s);
}
else if (py_
%(name)
s == Py_None)
{
PyErr_SetString(PyExc_TypeError,
"expected a CudaNdarray, not None");
%(name)
s = NULL;
%(fail)
s;
}
else
{
//fprintf(stderr, "FAILING c_extract CNDA object w refcnt
%%
p
%%
i
\\
n", py_
%(name)
s, (py_
%(name)
s->ob_refcnt));
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论