提交 fcac4d80 authored 作者: Pascal Lamblin's avatar Pascal Lamblin

Ensure that the base of a CudaNdarray is always the initial array.

This is needed to avoid keeping in memory a chain of intermediate arrays.
上级 d149e674
...@@ -2492,11 +2492,19 @@ int CudaNdarray_set_device_data(CudaNdarray * self, float * data, PyObject * bas ...@@ -2492,11 +2492,19 @@ int CudaNdarray_set_device_data(CudaNdarray * self, float * data, PyObject * bas
return -1; return -1;
} }
} }
// Get the original base object (base.base.base...)
// TODO: check that base is indeed a CudaNdarray?
PyObject * orig_base = base;
while (((CudaNdarray*) orig_base)->base)
{
// base_base is itself a view
orig_base = ((CudaNdarray*) orig_base)->base;
}
//N.B. XDECREF and XINCREF are no-ops for NULL pointers //N.B. XDECREF and XINCREF are no-ops for NULL pointers
if (self->base != base) if (self->base != orig_base)
{ {
Py_XDECREF(self->base); Py_XDECREF(self->base);
self->base = base; self->base = orig_base;
Py_XINCREF(self->base); Py_XINCREF(self->base);
} }
self->data_allocated = 0; self->data_allocated = 0;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论