# memory exhausted on GPU

**URL:** <https://forums.developer.nvidia.com/t/memory-exhausted-on-gpu/34772>\
**Category:** CUDA Programming and Performance\
**Created:** [September 9, 2014, 10:52am UTC](https://forums.developer.nvidia.com/t/memory-exhausted-on-gpu/34772 "2014-09-09T10:52:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![hitesh1612](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@hitesh1612](https://forums.developer.nvidia.com/u/hitesh1612)\
**Post date:** [September 9, 2014, 10:52am UTC](https://forums.developer.nvidia.com/t/memory-exhausted-on-gpu/34772/1 "2014-09-09T10:52:23Z")

</div>

**global** void GPU\_Offload(int nt,int total\_np,int num\_recv,int l\_x,int l\_z,float \*d\_amp,int nx,int nz,int \*x\_r,int \*z\_r)  
{

```
printf("\n\n\nin device at start %d ,%d",nx,nz); nx=14000 and nz=3600
//fflush(0);
int a=num_recv;
	PREV_PR_o prev;
	prev.px_l1=(float*)malloc(sizeof(float)*nz);
            prev.px_l2=(float*)malloc(sizeof(float)*nz);
            prev.px_r1=(float*)malloc(sizeof(float)*nz);
            prev.px_r2=(float*)malloc(sizeof(float)*nz);
	
	prev.pz_t1=(float*)malloc(sizeof(float)*nx);
            prev.pz_t2=(float*)malloc(sizeof(float)*nx);
            prev.pz_b1=(float*)malloc(sizeof(float)*nx);
            prev.pz_b2=(float*)malloc(sizeof(float)*nx);

 printf("%s %d \n", __FILE__ , __LINE__ );
int i,t_step,j;
float **p1,** p2, **econs,** tmp,*pw;
 pw=(float*)malloc(sizeof(float)*nx*nz);
if(pw==NULL)
printf("error in allocation"); // gives error here do i ran out of memory

for(i=1;i<10;i++)
{
	pw[i]=0.0f;
	//pw1[threadIdx.x]=0.0f;
}

```

}

---

<div class="post-metadata">

**Author:** ![cbuchner1](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/cbuchner1/32/14168_2.png) [@cbuchner1](https://forums.developer.nvidia.com/u/cbuchner1)\
**Post date:** [September 9, 2014, 11:23am UTC](https://forums.developer.nvidia.com/t/memory-exhausted-on-gpu/34772/2 "2014-09-09T11:23:23Z")

</div>

I think it is possible to set the size of the permissible heap space per kernel.

The default values are too low for your particulare use case.

---

<div class="post-metadata">

**Author:** ![pasoleatis](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@pasoleatis](https://forums.developer.nvidia.com/u/pasoleatis)\
**Post date:** [September 9, 2014, 12:36pm UTC](https://forums.developer.nvidia.com/t/memory-exhausted-on-gpu/34772/3 "2014-09-09T12:36:15Z")

</div>

I am not sure I understood correctly, but is it each thread allocating memory?

---

<div class="post-metadata">

**Author:** ![Robert\_Crovella](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/robert_crovella/32/14043_2.png) [@Robert\_Crovella](https://forums.developer.nvidia.com/u/Robert_Crovella)\
**Post date:** [September 9, 2014, 2:18pm UTC](https://forums.developer.nvidia.com/t/memory-exhausted-on-gpu/34772/4 "2014-09-09T14:18:24Z")

</div>

Read about malloc in the programming guide:

[url][Programming Guide :: CUDA Toolkit Documentation](http://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#dynamic-global-memory-allocation-and-operations%5B/url%5D)

There is a device heap limit, and you can increase it.
