提交 dd59c429 authored 作者: Arnaud Bergeron's avatar Arnaud Bergeron

Fix the type to use the new c_init_code interface and work on something other than OSX.

上级 17d65d5e
...@@ -151,17 +151,13 @@ class GpuFromHost(Op): ...@@ -151,17 +151,13 @@ class GpuFromHost(Op):
return """ return """
PyArrayObject *%(name)s_tmp; PyArrayObject *%(name)s_tmp;
int %(name)serr; int %(name)serr;
if ((PyObject *)GpuArray_default_context == Py_None) {
PyErr_SetString(PyExc_ValueError, "No default context, gpuarray not initialized?");
%(fail)s
}
%(name)s_tmp = PyArray_GETCONTIGUOUS(%(inp)s); %(name)s_tmp = PyArray_GETCONTIGUOUS(%(inp)s);
if (%(name)s_tmp == NULL) { if (%(name)s_tmp == NULL) {
// PyArray_GETCONTIGUOUS sets an error message if it fails // PyArray_GETCONTIGUOUS sets an error message if it fails
%(fail)s %(fail)s
} }
Py_XDECREF(%(out)s); Py_XDECREF(%(out)s);
%(out)s = new_GpuArray((PyObject *)&GpuArrayType, GpuArray_default_context); %(out)s = new_GpuArray((PyObject *)&GpuArrayType, GpuArray_default_context());
if (%(out)s == NULL) { if (%(out)s == NULL) {
Py_DECREF(%(name)s_tmp); Py_DECREF(%(name)s_tmp);
// new_GpuArray calls __new__ which will set an error message // new_GpuArray calls __new__ which will set an error message
...@@ -169,8 +165,8 @@ class GpuFromHost(Op): ...@@ -169,8 +165,8 @@ class GpuFromHost(Op):
%(fail)s %(fail)s
} }
%(name)serr = GpuArray_empty(&%(out)s->ga, %(name)serr = GpuArray_empty(&%(out)s->ga,
GpuArray_default_context->ops, GpuArray_default_context()->ops,
GpuArray_default_context->ctx, GpuArray_default_context()->ctx,
%(typecode)s, %(typecode)s,
PyArray_NDIM(%(inp)s), PyArray_NDIM(%(inp)s),
(size_t *)PyArray_DIMS(%(inp)s), (size_t *)PyArray_DIMS(%(inp)s),
...@@ -279,7 +275,7 @@ class GpuFromCuda(Op): ...@@ -279,7 +275,7 @@ class GpuFromCuda(Op):
ssize_t *%(name)sstr; ssize_t *%(name)sstr;
cuCtxGetCurrent(&%(name)scur); cuCtxGetCurrent(&%(name)scur);
if (%(name)scur != cuda_get_ctx(GpuArray_default_context->ctx)) { if (%(name)scur != cuda_get_ctx(GpuArray_default_context()->ctx)) {
PyErr_SetString(PyErr_ValueError, "Ambient cuda context is not the same as output context."); PyErr_SetString(PyErr_ValueError, "Ambient cuda context is not the same as output context.");
%(fail)s %(fail)s
} }
...@@ -308,7 +304,7 @@ class GpuFromCuda(Op): ...@@ -308,7 +304,7 @@ class GpuFromCuda(Op):
%(fail)s %(fail)s
} }
%(name)sdata = cuda_make_buf(GpuArray_default_context->ctx, %(name)sdata = cuda_make_buf(GpuArray_default_context()->ctx,
(CUdeviceptr)%(in)s->devdata, (CUdeviceptr)%(in)s->devdata,
(size_t)%(in)s->data_allocated); (size_t)%(in)s->data_allocated);
if (%(name)sdata == NULL) { if (%(name)sdata == NULL) {
...@@ -319,7 +315,7 @@ class GpuFromCuda(Op): ...@@ -319,7 +315,7 @@ class GpuFromCuda(Op):
%(fail)s %(fail)s
} }
%(name)serr = GpuArray_fromdata(&%(out)s->ga, %(name)serr = GpuArray_fromdata(&%(out)s->ga,
GpuArray_default_context->ops, GpuArray_default_context()->ops,
%(name)sdata, 0, GA_FLOAT, %(in)s->nd, %(name)sdata, 0, GA_FLOAT, %(in)s->nd,
%(name)sdims, %(name)sstr, 1); %(name)sdims, %(name)sstr, 1);
free(%(name)sdims); free(%(name)sdims);
......
...@@ -174,15 +174,23 @@ class GpuArrayType(Type): ...@@ -174,15 +174,23 @@ class GpuArrayType(Type):
} }
""" % {'name': name} """ % {'name': name}
def c_init_code(self):
# We don't actually need the numpy API except in
# HostFromGpu and GpuFromHost and those case will be covered
# by the TensorType parameter
return ['import_pygpu__gpuarray();']
def c_headers(self): def c_headers(self):
return ['pygpu/gpuarray.h', 'compyte/array.h', 'compyte/kernel.h', # We need arrayobject for the PyArrayDescr struct def
'compyte/error.h'] # (even if we just use a pointer to it in a function def)
return ['<compyte/array.h>', '<compyte/kernel.h>', '<compyte/error.h>',
'<numpy/arrayobject.h>', '<gpuarray_api.h>']
def c_header_dirs(self): def c_header_dirs(self):
return [pygpu.get_include()] return [pygpu.get_include(), numpy.get_include()]
def c_code_cache_version(self): def c_code_cache_version(self):
return (0,) return (1,)
class _operators(tensor.basic._tensor_py_operators): class _operators(tensor.basic._tensor_py_operators):
...@@ -265,7 +273,7 @@ theano.compile.register_view_op_c_code(GpuArrayType, """ ...@@ -265,7 +273,7 @@ theano.compile.register_view_op_c_code(GpuArrayType, """
theano.compile.register_deep_copy_op_c_code(GpuArrayType, """ theano.compile.register_deep_copy_op_c_code(GpuArrayType, """
Py_XDECREF(%(oname)s); Py_XDECREF(%(oname)s);
%(oname)s = new_GpuArray((PyObject *)&GpuArrayType, GpuArray_default_context); %(oname)s = new_GpuArray((PyObject *)&GpuArrayType, GpuArray_default_context());
if (!%(oname)s) { %(fail)s } if (!%(oname)s) { %(fail)s }
int err; int err;
err = GpuArray_copy(&%(oname)s->ga, &%(iname)s->ga, GA_ANY_ORDER); err = GpuArray_copy(&%(oname)s->ga, &%(iname)s->ga, GA_ANY_ORDER);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论