提交 7b47fbde authored 作者: Ian Goodfellow's avatar Ian Goodfellow

add disabled instrumentation

上级 61aadd97
...@@ -14,6 +14,17 @@ ...@@ -14,6 +14,17 @@
//If true, we fill with NAN allocated device memory. //If true, we fill with NAN allocated device memory.
#define ALLOC_MEMSET 0 #define ALLOC_MEMSET 0
//If true, we print out when we free a device pointer, uninitialize a
//CudaNdarray, or allocate a device pointer
#define PRINT_FREE_MALLOC 0
//If true, we do error checking at the start of functions, to make sure there
//is not a pre-existing error when the function is called.
//You probably need to set the environment variable
//CUDA_LAUNCH_BLOCKING=1
//if you want this to work.
#define PRECHECK_ERROR 0
///////////////////////// /////////////////////////
// Alloc and Free // Alloc and Free
///////////////////////// /////////////////////////
...@@ -53,37 +64,53 @@ void * device_malloc(size_t size) ...@@ -53,37 +64,53 @@ void * device_malloc(size_t size)
// it returns something else I still don't see why we should ignore // it returns something else I still don't see why we should ignore
// it. All we want to do here is reset the flag. // it. All we want to do here is reset the flag.
cudaGetLastError(); cudaGetLastError();
#if COMPUTE_GPU_MEM_USED #if COMPUTE_GPU_MEM_USED
fprintf(stderr, "Error allocating %li bytes of device memory (%s). new total bytes allocated: %d\n", (long)size, cudaGetErrorString(err),_allocated_size); fprintf(stderr, "Error allocating %li bytes of device memory (%s). new total bytes allocated: %d\n", (long)size, cudaGetErrorString(err),_allocated_size);
#else #else
fprintf(stderr, "Error allocating %li bytes of device memory (%s).\n", (long)size, cudaGetErrorString(err)); fprintf(stderr, "Error allocating %li bytes of device memory (%s).\n", (long)size, cudaGetErrorString(err));
#endif #endif
PyErr_Format(PyExc_MemoryError, "Error allocating %li bytes of device memory (%s).", (long)size, cudaGetErrorString(err)); PyErr_Format(PyExc_MemoryError,
"Error allocating %li bytes of device memory (%s).", (long)size, cudaGetErrorString(err));
return NULL; return NULL;
} }
_outstanding_mallocs[0] += (rval != NULL); _outstanding_mallocs[0] += (rval != NULL);
#if COMPUTE_GPU_MEM_USED #if COMPUTE_GPU_MEM_USED
for(int i=0;i<TABLE_SIZE;i++){ for(int i=0;i<TABLE_SIZE;i++){
if(NULL==_alloc_size_table[i].ptr){ if(NULL==_alloc_size_table[i].ptr){
_alloc_size_table[i].ptr=rval; _alloc_size_table[i].ptr=rval;
_alloc_size_table[i].size=size; _alloc_size_table[i].size=size;
break; break;
}
} }
} _allocated_size += size;
_allocated_size += size; #endif
#endif //fprintf(stderr,
//fprintf(stderr, "allocated %li bytes of device memory (%s). new total bytes allocated: %d. ptr: %p\n", (long)size, cudaGetErrorString(err),_allocated_size,rval); //"allocated %li bytes of device memory (%s). new total bytes allocated: %d. ptr: %p\n",
//(long)size, cudaGetErrorString(err),_allocated_size,rval);
if(ALLOC_MEMSET){ if(ALLOC_MEMSET){
//We init them to nan to make sure we catch more debug case. //We init them to nan to make sure we catch more debug case.
cudaMemset(rval, 0xFF, size); cudaMemset(rval, 0xFF, size);
//printf("MEMSET\n"); //printf("MEMSET\n");
} }
#if PRINT_FREE_MALLOC
fprintf(stderr, "device malloc %p\n",rval);
#endif
return rval; return rval;
} }
int device_free(void *ptr) int device_free(void *ptr)
{ {
#if PRINT_FREE_MALLOC
fprintf(stderr, "device_free %p\n",ptr);
#endif
#if PRECHECK_ERROR
cudaError_t prevError = cudaGetLastError();
if (cudaSuccess != prevError)
{
fprintf(stderr, "Error existed before calling device_free.\n");
}
#endif
// if there is no gpu context, the call to cudaFree will fail; skip it entirely // if there is no gpu context, the call to cudaFree will fail; skip it entirely
if(!g_gpu_context_active) { if(!g_gpu_context_active) {
...@@ -163,6 +190,9 @@ CudaNdarray_null_init(CudaNdarray*self) ...@@ -163,6 +190,9 @@ CudaNdarray_null_init(CudaNdarray*self)
static int static int
CudaNdarray_uninit(CudaNdarray*self) CudaNdarray_uninit(CudaNdarray*self)
{ {
#if PRINT_FREE_MALLOC
fprintf(stderr, "CudaNdarray_uninit %p\n", self);
#endif
int rval = 0; int rval = 0;
if (self->data_allocated) { if (self->data_allocated) {
assert(self->devdata); assert(self->devdata);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论