Skip to content

Instantly share code, notes, and snippets.

@InnovArul
Created February 7, 2016 07:38
Show Gist options
  • Save InnovArul/d1eb6f2c865bd2c1d89a to your computer and use it in GitHub Desktop.
Save InnovArul/d1eb6f2c865bd2c1d89a to your computer and use it in GitHub Desktop.
#define MALLOC_LIMIT 1024*1024*1024 //1 GB
//eliminate calling cudaDeviceSetLimit multiple times
bool IsMallocSet = false;
/**
* API to set the malloc limit of GPU
*/
static void setMallocLimit() {
// cudaDeviceSetLimit can be called only once to set the malloc limit
// this if loop is to prevent multiple calls of cudaDeviceSetLimit
if(!IsMallocSet)
{
cudaError_t cuda_status = cudaDeviceSetLimit(cudaLimitMallocHeapSize, MALLOC_LIMIT);
if (cudaSuccess != cuda_status) {
printf("Error: cudaDeviceSetLimit fails, %s \n",
cudaGetErrorString(cuda_status));
return;
}
IsMallocSet = true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment