提交 8485ebd0 authored 作者: Pascal Lamblin's avatar Pascal Lamblin

Allow allocation of size 0 on gpu

上级 5139056f
...@@ -229,13 +229,22 @@ static int CudaNdarray_alloc_contiguous(CudaNdarray *self, const int nd, const i ...@@ -229,13 +229,22 @@ static int CudaNdarray_alloc_contiguous(CudaNdarray *self, const int nd, const i
return -1; return -1;
} }
assert(size>0); if (size < 0)
{
PyErr_Format(PyExc_AssertionError,
"size (%i) < 0",
size);
return -1;
}
self->devdata = (float*)device_malloc(size*sizeof(real)); self->devdata = (float*)device_malloc(size*sizeof(real));
if (!self->devdata) if (size && !self->devdata)
{ {
CudaNdarray_set_nd(self,-1); CudaNdarray_set_nd(self, -1);
self->data_allocated = 0; self->data_allocated = 0;
self->devdata = 0; self->devdata = 0;
PyErr_SetString(PyExc_RuntimeError,
"Could not allocate memory on device");
return -1; return -1;
} }
if (0) if (0)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论