提交 7b735c43 authored 作者: Arnaud Bergeron's avatar Arnaud Bergeron

Make GpuFromHost reuse the output if possible.

上级 f3157aee
...@@ -391,12 +391,31 @@ class GpuFromHost(Op): ...@@ -391,12 +391,31 @@ class GpuFromHost(Op):
def infer_shape(self, node, xshp): def infer_shape(self, node, xshp):
return xshp return xshp
def c_headers(self):
return ["gpuarray_helper.h"]
def c_header_dirs(self):
return [os.path.dirname(__file__)]
def c_code(self, node, name, inputs, outputs, sub): def c_code(self, node, name, inputs, outputs, sub):
return """ return """
PyArrayObject *%(name)s_tmp; PyArrayObject *%(name)s_tmp;
%(name)s_tmp = PyArray_GETCONTIGUOUS(%(inp)s); %(name)s_tmp = PyArray_GETCONTIGUOUS(%(inp)s);
if (%(name)s_tmp == NULL) if (%(name)s_tmp == NULL)
%(fail)s %(fail)s
if (%(out)s != NULL && GpuArray_IS_C_CONTIGUOUS(&%(out)s->ga) &&
theano_size_check(%(out)s, PyArray_NDIM(%(name)s_tmp),
(size_t *)PyArray_DIMS(%(name)s_tmp),
get_typecode((PyObject *)PyArray_DESCR(%(name)s_tmp)))) {
int err = GpuArray_write(&%(out)s->ga, PyArray_DATA(%(name)s_tmp),
PyArray_NBYTES(%(name)s_tmp));
Py_DECREF(%(name)s_tmp);
if (err != GA_NO_ERROR) {
PyErr_Format(PyExc_RuntimeError, "Could not write data to gpu");
%(fail)s;
}
} else {
Py_XDECREF(%(out)s); Py_XDECREF(%(out)s);
%(out)s = pygpu_fromhostdata(PyArray_DATA(%(name)s_tmp), %(out)s = pygpu_fromhostdata(PyArray_DATA(%(name)s_tmp),
get_typecode((PyObject *)PyArray_DESCR(%(name)s_tmp)), get_typecode((PyObject *)PyArray_DESCR(%(name)s_tmp)),
...@@ -409,11 +428,12 @@ class GpuFromHost(Op): ...@@ -409,11 +428,12 @@ class GpuFromHost(Op):
if (%(out)s == NULL) { if (%(out)s == NULL) {
%(fail)s %(fail)s
} }
}
""" % {'name': name, 'inp': inputs[0], 'ctx': sub['context'], """ % {'name': name, 'inp': inputs[0], 'ctx': sub['context'],
'out': outputs[0], 'fail': sub['fail']} 'out': outputs[0], 'fail': sub['fail']}
def c_code_cache_version(self): def c_code_cache_version(self):
return (7,) return (8,)
class GpuToGpu(Op): class GpuToGpu(Op):
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论