提交 4b8d4973 authored 作者: James Bergstra's avatar James Bergstra

FIX: raise exception on allocation failure in GpuAlloc

上级 41a1abeb
...@@ -2180,16 +2180,30 @@ class GpuAlloc(GpuOp): ...@@ -2180,16 +2180,30 @@ class GpuAlloc(GpuOp):
str += "if(%(out)s==NULL\n" % locals() str += "if(%(out)s==NULL\n" % locals()
for idx,sh in enumerate(shps): for idx,sh in enumerate(shps):
str += "||CudaNdarray_HOST_DIMS(%(out)s)[%(idx)s]!=dims[%(idx)s]" % locals() str += "||CudaNdarray_HOST_DIMS(%(out)s)[%(idx)s]!=dims[%(idx)s]" % locals()
str+="""){ str += """){
Py_XDECREF(%(out)s); Py_XDECREF(%(out)s);
%(out)s= (CudaNdarray*)CudaNdarray_New(); %(out)s = (CudaNdarray*)CudaNdarray_New();
CudaNdarray_alloc_contiguous(%(out)s, %(nd)s, dims); if (!%(out)s)
} {
if (CudaNdarray_CopyFromCudaNdarray(%(out)s, %(value)s, true)) // exception already set
{ %(fail)s;
%(fail)s; }
} if (CudaNdarray_alloc_contiguous(%(out)s, %(nd)s, dims))
""" % locals() {
// exception already set
Py_XDECREF(%(out)s);
%(out)s = NULL;
%(fail)s;
}
}
if (CudaNdarray_CopyFromCudaNdarray(%(out)s, %(value)s, true))
{
// exception already set
Py_XDECREF(%(out)s);
%(out)s = NULL;
%(fail)s;
}
""" % locals()
return str return str
def infer_shape(self, node, input_shapes): def infer_shape(self, node, input_shapes):
...@@ -2200,7 +2214,7 @@ class GpuAlloc(GpuOp): ...@@ -2200,7 +2214,7 @@ class GpuAlloc(GpuOp):
return [None for i in inputs] return [None for i in inputs]
def c_code_cache_version(self): def c_code_cache_version(self):
return (3,) return (4,)
def do_constant_folding(self, node): def do_constant_folding(self, node):
for client in node.outputs[0].clients: for client in node.outputs[0].clients:
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论