提交 08b01559 authored 作者: Frederic's avatar Frederic

Make f.fn.allow_gc accesible with the CVM and allow to change it dynamically.

上级 47a46357
...@@ -930,6 +930,34 @@ static PyMethodDef CLazyLinker_methods[] = { ...@@ -930,6 +930,34 @@ static PyMethodDef CLazyLinker_methods[] = {
}; };
#endif #endif
static PyObject *
CLazyLinker_get_allow_gc(CLazyLinker *self, void *closure)
{
return PyBool_FromLong(self->allow_gc);
}
static int
CLazyLinker_set_allow_gc(CLazyLinker *self, PyObject *value, void *closure)
{
if(!PyBool_Check(value))
return -1;
if (value == Py_True)
self->allow_gc = true;
else
self->allow_gc = false;
return 0;
}
static PyGetSetDef CLazyLinker_getset[] = {
{"allow_gc",
(getter)CLazyLinker_get_allow_gc,
(setter)CLazyLinker_set_allow_gc,
"do this function support allow_gc",
NULL},
{NULL, NULL, NULL, NULL} /* Sentinel */
};
static PyMemberDef CLazyLinker_members[] = { static PyMemberDef CLazyLinker_members[] = {
{(char*)"nodes", T_OBJECT_EX, offsetof(CLazyLinker, nodes), 0, {(char*)"nodes", T_OBJECT_EX, offsetof(CLazyLinker, nodes), 0,
(char*)"list of nodes"}, (char*)"list of nodes"},
...@@ -983,7 +1011,7 @@ static PyTypeObject lazylinker_ext_CLazyLinkerType = { ...@@ -983,7 +1011,7 @@ static PyTypeObject lazylinker_ext_CLazyLinkerType = {
0, /* tp_iternext */ 0, /* tp_iternext */
0,//CLazyLinker_methods, /* tp_methods */ 0,//CLazyLinker_methods, /* tp_methods */
CLazyLinker_members, /* tp_members */ CLazyLinker_members, /* tp_members */
0, /* tp_getset */ CLazyLinker_getset, /* tp_getset */
0, /* tp_base */ 0, /* tp_base */
0, /* tp_dict */ 0, /* tp_dict */
0, /* tp_descr_get */ 0, /* tp_descr_get */
......
...@@ -184,6 +184,25 @@ def test_speed_lazy(): ...@@ -184,6 +184,25 @@ def test_speed_lazy():
time_linker('vmLinker_C', lambda : vm.VM_Linker(allow_gc=False, time_linker('vmLinker_C', lambda : vm.VM_Linker(allow_gc=False,
use_cloop=True)) use_cloop=True))
def test_allow_gc_cvm():
v = theano.tensor.vector()
f = theano.function([v], v + 1)
f([1])
n = list(f.maker.fgraph.apply_nodes)[0].outputs[0]
assert f.fn.storage_map[n][0] is None
assert f.fn.allow_gc is True
f.fn.allow_gc = False
assert f.fn.allow_gc is False
f([1])
assert f.fn.storage_map[n][0] is not None
f.fn.allow_gc = True
assert f.fn.allow_gc is True
f([1])
assert f.fn.storage_map[n][0] is None
run_memory_usage_tests = False run_memory_usage_tests = False
if run_memory_usage_tests: if run_memory_usage_tests:
# these are not normal unit tests, do not run them as part of standard # these are not normal unit tests, do not run them as part of standard
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论