Hi,
the example checks if the storage exists and if it exists and have the same shape, it will reuse it:
// Validate that the output storage exists and has the same
// dimension as x.
if (NULL == %(z)s ||
PyArray_DIMS(%(x)s)[0] != PyArray_DIMS(%(z)s)[0])
{
/* Reference received to invalid output variable.
Decrease received reference's ref count and allocate new
output variable */
Py_XDECREF(%(z)s);
%(z)s = (PyArrayObject*)PyArray_EMPTY(1,
PyArray_DIMS(%(x)s),
PyArray_TYPE(%(x)s),
0);
if (!%(z)s) {
%(fail)s;
}
}
It also said the following:
output_storage
. A function Mode may allow output_storage
elements to persist between evaluations, or it may reset output_storage
cells to hold a value of None
. It can also pre-allocate some memory for the op to use. This feature can allow perform
to reuse memory between calls
The example simply calls:
without any checking if a pygpu array buffer exists. Does the reuse memory between calls trick exist when I develop a GPU Op?
Thanks.