提交 8c30d10a authored 作者: Frederic's avatar Frederic

Don't overflow in printing over 4G by using the good print size.

上级 4c303896
...@@ -47,13 +47,13 @@ static PyObject *CudaNdarray_get_shape(CudaNdarray *self, void *closure); ...@@ -47,13 +47,13 @@ static PyObject *CudaNdarray_get_shape(CudaNdarray *self, void *closure);
int _outstanding_mallocs[] = {0,0}; int _outstanding_mallocs[] = {0,0};
#if COMPUTE_GPU_MEM_USED #if COMPUTE_GPU_MEM_USED
int _allocated_size = 0; size_t _allocated_size = 0;
int _max_allocated_size = 0; size_t _max_allocated_size = 0;
const int TABLE_SIZE = 10000; const int TABLE_SIZE = 10000;
struct table_struct{ struct table_struct{
void* ptr; void* ptr;
int size; size_t size;
}; };
table_struct _alloc_size_table[TABLE_SIZE]; table_struct _alloc_size_table[TABLE_SIZE];
#endif #endif
...@@ -97,21 +97,21 @@ void * device_malloc(size_t size, int verbose) ...@@ -97,21 +97,21 @@ void * device_malloc(size_t size, int verbose)
} }
#if COMPUTE_GPU_MEM_USED #if COMPUTE_GPU_MEM_USED
fprintf(stderr, fprintf(stderr,
"Error allocating %li bytes of device memory (%s)." "Error allocating %zd bytes of device memory (%s)."
" new total bytes allocated: %d." " new total bytes allocated: %d."
" Driver report %d bytes free and %d bytes total \n", " Driver report %zd bytes free and %zd bytes total \n",
(long)size, cudaGetErrorString(err), _allocated_size, size, cudaGetErrorString(err), _allocated_size,
free, total); free, total);
#else #else
fprintf(stderr, fprintf(stderr,
"Error allocating %li bytes of device memory (%s)." "Error allocating %zd bytes of device memory (%s)."
" Driver report %d bytes free and %d bytes total \n", " Driver report %zd bytes free and %zd bytes total \n",
(long)size, cudaGetErrorString(err), free, total); size, cudaGetErrorString(err), free, total);
#endif #endif
} }
PyErr_Format(PyExc_MemoryError, PyErr_Format(PyExc_MemoryError,
"Error allocating %li bytes of device memory (%s).", "Error allocating %zd bytes of device memory (%s).",
(long)size, cudaGetErrorString(err)); size, cudaGetErrorString(err));
return NULL; return NULL;
} }
if (rval != NULL){ if (rval != NULL){
...@@ -227,15 +227,15 @@ int device_free(void *ptr) ...@@ -227,15 +227,15 @@ int device_free(void *ptr)
} }
assert(i<TABLE_SIZE); assert(i<TABLE_SIZE);
fprintf(stderr, fprintf(stderr,
"Error freeing device pointer %p (%s) of size %d. %d byte already allocated." "Error freeing device pointer %p (%s) of size %d. %zd byte already allocated."
" Driver report %d bytes free and %d bytes total \n", " Driver report %zd bytes free and %zd bytes total \n",
ptr, cudaGetErrorString(err), ptr, cudaGetErrorString(err),
_alloc_size_table[i].size, _allocated_size, free, total); _alloc_size_table[i].size, _allocated_size, free, total);
} }
#else #else
fprintf(stderr, fprintf(stderr,
"Error freeing device pointer %p (%s)." "Error freeing device pointer %p (%s)."
" Driver report %d bytes free and %d bytes total \n", " Driver report %zd bytes free and %zd bytes total \n",
ptr, ptr,
cudaGetErrorString(err), free, total); cudaGetErrorString(err), free, total);
#endif #endif
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论