提交 54ac558b authored 作者: Pascal Lamblin's avatar Pascal Lamblin

Changes to CudaNdarray_alloc_contiguous not to free memory we did not alloc

上级 3faca5cc
......@@ -95,6 +95,12 @@ CudaNdarray_Check(const PyObject * ob);
int
CudaNdarray_CheckExact(const PyObject * ob);
/**
* Return true for a C-contiguous CudaNdarray, else false
*/
bool
CudaNdarray_is_c_contiguous(const CudaNdarray * self);
/****
* Returns the number of elements necessary in host_structure and dev_structure for a given number of dimensions.
*/
......@@ -386,13 +392,20 @@ int CudaNdarray_alloc_contiguous(CudaNdarray *self, const int nd, const inttype
size = size * dim[i];
}
if (self->data_allocated != size)
if (CudaNdarray_is_c_contiguous(self) && (self->data_allocated == size))
{
return 0;
}
else
{
if (device_free(self->devdata))
// If self is a view, do not try to free its memory
if (self->data_allocated && device_free(self->devdata))
{
// Does this ever happen?? Do we need to set data_allocated or devdata to 0?
self->devdata = NULL;
self->data_allocated = 0;
return -1;
}
assert(size>0);
self->devdata = (float*)device_malloc(size*sizeof(real));
if (!self->devdata)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论