提交 1c5f42e0 authored 作者: David Warde-Farley's avatar David Warde-Farley

Revert changes to device_malloc calls; overload instead.

上级 629c173b
...@@ -53,6 +53,12 @@ struct table_struct{ ...@@ -53,6 +53,12 @@ struct table_struct{
}; };
table_struct _alloc_size_table[TABLE_SIZE]; table_struct _alloc_size_table[TABLE_SIZE];
#endif #endif
void * device_malloc(size_t size)
{
return device_malloc(size, VERBOSE_DEVICE_MALLOC);
}
void * device_malloc(size_t size, int verbose) void * device_malloc(size_t size, int verbose)
{ {
void * rval=NULL; void * rval=NULL;
...@@ -962,7 +968,7 @@ CudaNdarray_TakeFrom(CudaNdarray * self, PyObject *args){ ...@@ -962,7 +968,7 @@ CudaNdarray_TakeFrom(CudaNdarray * self, PyObject *args){
// Create the memory place that will store the error information. // Create the memory place that will store the error information.
if (err_var == NULL) { if (err_var == NULL) {
err_var = (int*)device_malloc(sizeof(int), VERBOSE_DEVICE_MALLOC); err_var = (int*)device_malloc(sizeof(int));
if (!err_var) { // PyErr set by device_malloc if (!err_var) { // PyErr set by device_malloc
Py_DECREF(indices); Py_DECREF(indices);
Py_DECREF(out); Py_DECREF(out);
...@@ -2628,7 +2634,7 @@ static __global__ void get_gpu_ptr_size(int* dst) ...@@ -2628,7 +2634,7 @@ static __global__ void get_gpu_ptr_size(int* dst)
PyObject * PyObject *
CudaNdarray_ptr_int_size(PyObject* _unused, PyObject* args) CudaNdarray_ptr_int_size(PyObject* _unused, PyObject* args)
{ {
int *gpu_data = (int*)device_malloc(sizeof(int)*2, VERBOSE_DEVICE_MALLOC); int *gpu_data = (int*)device_malloc(sizeof(int)*2);
if(gpu_data == NULL){ if(gpu_data == NULL){
return PyErr_Format(PyExc_MemoryError, return PyErr_Format(PyExc_MemoryError,
"CudaNdarray_ptr_int_size: Can't allocate memory on the gpu."); "CudaNdarray_ptr_int_size: Can't allocate memory on the gpu.");
...@@ -4524,7 +4530,7 @@ cnda_copy_structure_to_device(const CudaNdarray * self) ...@@ -4524,7 +4530,7 @@ cnda_copy_structure_to_device(const CudaNdarray * self)
int struct_size = cnda_structure_size(self->nd); int struct_size = cnda_structure_size(self->nd);
if (struct_size) if (struct_size)
{ {
self->dev_structure = (int*)device_malloc(struct_size* sizeof(int), VERBOSE_DEVICE_MALLOC); self->dev_structure = (int*)device_malloc(struct_size* sizeof(int));
if (NULL == self->dev_structure) if (NULL == self->dev_structure)
{ {
return -1; return -1;
......
...@@ -51,6 +51,7 @@ typedef float real; ...@@ -51,6 +51,7 @@ typedef float real;
* device_malloc will set the Python error message before returning None. * device_malloc will set the Python error message before returning None.
* device_free will return nonzero on failure (after setting the python error message) * device_free will return nonzero on failure (after setting the python error message)
*/ */
DllExport void * device_malloc(size_t size);
DllExport void * device_malloc(size_t size, int verbose); DllExport void * device_malloc(size_t size, int verbose);
DllExport int device_free(void * ptr); DllExport int device_free(void * ptr);
...@@ -338,7 +339,7 @@ static int CudaNdarray_alloc_contiguous(CudaNdarray *self, const int nd, const i ...@@ -338,7 +339,7 @@ static int CudaNdarray_alloc_contiguous(CudaNdarray *self, const int nd, const i
return -1; return -1;
} }
self->devdata = (float*)device_malloc(size*sizeof(real), VERBOSE_DEVICE_MALLOC); self->devdata = (float*)device_malloc(size*sizeof(real));
if (size && !self->devdata) if (size && !self->devdata)
{ {
CudaNdarray_set_nd(self, -1); CudaNdarray_set_nd(self, -1);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论