提交 1ea78d61 authored 作者: Frederic's avatar Frederic

Test for error earlier in GpuJoin. Also fix memory leak of section_slice

上级 1dbd3e96
......@@ -2959,13 +2959,21 @@ class GpuJoin(tensor.Join, GpuOp):
# getting the shapes of all the involved tensors (input[0]+out)
str = """
int axis = PyInt_AsLong((PyObject*)%(axis)s);
int nd = %(nd)s;
const int axis = PyInt_AsLong((PyObject*)%(axis)s);
const int nd = %(nd)s;
int shape_%(input_1)s[nd];
int shape_out[nd];
int width_sum = 0;
int errorcode;
int sum;
int sum = 0;
PyObject *slice_tuple = NULL;
PyObject *section_slice = NULL;
PyObject *full_slice = NULL;
PyObject *out_sub = NULL;
PyObject *start, *stop, *step;
start = NULL;
stop = NULL;
step = NULL;
for(int i = 0; i<nd; i+=1)
{
......@@ -2984,6 +2992,15 @@ class GpuJoin(tensor.Join, GpuOp):
str += """
int shape_%(cdna)s[nd];
""" % locals()
str += """
if(-1 == axis && PyErr_Occurred()){
%(fail)s;
}
full_slice = PySlice_New(NULL, NULL, NULL);
if(full_slice == NULL){
%(fail)s;
}
""" % locals()
for i, cdna in enumerate(inputs[2:]):
str += """
for(int i = 0; i<nd; i+=1)
......@@ -3013,18 +3030,6 @@ class GpuJoin(tensor.Join, GpuOp):
{
%(fail)s;
}
PyObject *slice_tuple;
PyObject *section_slice;
PyObject *full_slice;
full_slice = PySlice_New(NULL, NULL, NULL);
PyObject *out_sub;
PyObject *start, *stop, *step;
start = NULL;
stop = NULL;
step = NULL;
sum = 0;
""" % locals()
# start copying the data into the new out tensors
for i, cdna in enumerate(inputs[1:]):
......@@ -3032,7 +3037,13 @@ class GpuJoin(tensor.Join, GpuOp):
sum += shape_%(cdna)s[axis];
stop = PyInt_FromLong(sum);
slice_tuple = PyTuple_New(nd);
if(slice_tuple == NULL){
%(fail)s;
}
section_slice = PySlice_New(start, stop, step);
if(section_slice == NULL){
%(fail)s;
}
for(int i=0; i<nd; i++)
{
if(i!=axis)
......@@ -3047,19 +3058,29 @@ class GpuJoin(tensor.Join, GpuOp):
}
}
out_sub = CudaNdarray_Subscript((PyObject*)%(out)s, slice_tuple);
if(out_sub == NULL){
Py_XDECREF(start);
Py_XDECREF(stop);
Py_XDECREF(step);
Py_XDECREF(slice_tuple);
Py_XDECREF(out_sub);
Py_XDECREF(%(out)s);
%(fail)s;
}
Py_CLEAR(slice_tuple);
Py_CLEAR(section_slice);
errorcode = CudaNdarray_CopyFromCudaNdarray((CudaNdarray*)out_sub, %(cdna)s);
if((full_slice == NULL) || (section_slice == NULL) || (out_sub == NULL) || (errorcode != 0))
if(errorcode != 0)
{
Py_XDECREF(start);
Py_XDECREF(stop);
Py_XDECREF(step);
Py_XDECREF(slice_tuple);
Py_XDECREF(out_sub);
Py_XDECREF(%(out)s);
%(fail)s;
}
Py_XDECREF(out_sub);
Py_XDECREF(slice_tuple);
Py_XDECREF(start);
start = stop;
stop = NULL;
......@@ -3072,7 +3093,7 @@ class GpuJoin(tensor.Join, GpuOp):
return str
def c_code_cache_version(self):
return (2,)
return (3,)
gpu_join = GpuJoin()
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论