# cudaErrorMemoryAllocation error

**URL:** <https://forums.developer.nvidia.com/t/cudaerrormemoryallocation-error/30100>\
**Category:** CUDA Programming and Performance\
**Created:** [July 15, 2013, 12:59pm UTC](https://forums.developer.nvidia.com/t/cudaerrormemoryallocation-error/30100 "2013-07-15T12:59:02Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![asterix87](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@asterix87](https://forums.developer.nvidia.com/u/asterix87)\
**Post date:** [July 15, 2013, 12:59pm UTC](https://forums.developer.nvidia.com/t/cudaerrormemoryallocation-error/30100/1 "2013-07-15T12:59:02Z")

</div>

I’ve a CUDA function that compute a simple operation on an array.

```auto
__global__ void funct (int *v, int *dest){
      int idx=blockIdx.x*blockDim.x + threadIdx.x;

      dest[idx] = 3* v[idx]+4;
      }

```

v is vector initialized, and d is a destination vector.

When I run the program on 1000, 10000, 10000 elements of array there isn’t any problems. On the other and, when elements are 1000000 an error occurs: cudaErrorMemoryAllocation.

How do I solve the problem?

For 1000000 elements the parameters of kernel function are: DIM\_GRID(1954,1) DIM\_BLOCK(512,1,1)

---

<div class="post-metadata">

**Author:** ![nezix](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/nezix/32/28228_2.png) [@nezix](https://forums.developer.nvidia.com/u/nezix)\
**Post date:** [July 15, 2013, 2:44pm UTC](https://forums.developer.nvidia.com/t/cudaerrormemoryallocation-error/30100/2 "2013-07-15T14:44:45Z")

</div>

Hi,

1954 x 512 = 1000448 so you must do something like :

```auto
#define N 1000000 
__global__ void funct (int *v, int *dest){
    int idx=blockIdx.x*blockDim.x + threadIdx.x;
    if(idx>=N)
        idx = N-1;
    dest[idx] = 3 * v[idx] + 4;
}

```

Or add N in the arguments of the kernel.

You should provide the way you allocate the memory. You should do :

```auto
int *v_dev, *dest_dev;
cudaMalloc((void**)&v_dev,sizeof(int)*N);
cudaMalloc((void**)&dest_dev,sizeof(int)*N);

```

You seem to be far from the amount of memory available on your GPU but this is the kind of error you have when you try to allocate more than the GPU can.

---

<div class="post-metadata">

**Author:** ![asterix87](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@asterix87](https://forums.developer.nvidia.com/u/asterix87)\
**Post date:** [July 15, 2013, 5:32pm UTC](https://forums.developer.nvidia.com/t/cudaerrormemoryallocation-error/30100/3 "2013-07-15T17:32:12Z")

</div>

I’ve already tried but the error persists.  
So to be more precise the error appears on second cudaMalloc and not on the first:

```auto
cudaMalloc((void**)&dest_dev,sizeof(int)*N);

```

---

<div class="post-metadata">

**Author:** ![nezix](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/nezix/32/28228_2.png) [@nezix](https://forums.developer.nvidia.com/u/nezix)\
**Post date:** [July 15, 2013, 7:54pm UTC](https://forums.developer.nvidia.com/t/cudaerrormemoryallocation-error/30100/4 "2013-07-15T19:54:17Z")

</div>

Can you provide the card, the system and the number of screens you are working on ?  
Also you can check the available memory in nvidia-settings (if you are on a Linux OS).

---

<div class="post-metadata">

**Author:** ![asterix87](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@asterix87](https://forums.developer.nvidia.com/u/asterix87)\
**Post date:** [July 15, 2013, 8:08pm UTC](https://forums.developer.nvidia.com/t/cudaerrormemoryallocation-error/30100/5 "2013-07-15T20:08:20Z")

</div>

I use Visual Studio 2010 on Windows 7.

Graphic Card is NVIDIA GeForce 8400M GT (Compute capability 1.1). These are the features provided by NSight:

ASYNC\_ENGINE\_COUNT 1  
CAN\_MAP\_HOST\_MEMORY 1  
CAN\_TEX2D\_GATHER 0  
CLOCK\_RATE 900000  
COMPUTE\_CAPABILITY\_MAJOR 1  
COMPUTE\_CAPABILITY\_MINOR 1  
COMPUTE\_MODE 0  
CONCURRENT\_KERNELS 0  
DISPLAY\_NAME GeForce 8400M GT  
ECC\_ENABLED 0  
GLOBAL\_MEMORY\_BUS\_WIDTH 64  
GPU\_OVERLAP 1  
GPU\_PCI\_DEVICE\_ID 69603550  
GPU\_PCI\_EXT\_DEVICE\_ID 1062  
GPU\_PCI\_REVISION\_ID 161  
GPU\_PCI\_SUB\_SYSTEM\_ID 2416250957  
INTEGRATED 0  
KERNEL\_EXEC\_TIMEOUT 1  
L2\_CACHE\_SIZE 0  
MAX\_BLOCK\_DIM\_X 512  
MAX\_BLOCK\_DIM\_Y 512  
MAX\_BLOCK\_DIM\_Z 64  
MAX\_GRID\_DIM\_X 65535  
MAX\_GRID\_DIM\_Y 65535  
MAX\_GRID\_DIM\_Z 1  
MAX\_PITCH 2147483647  
MAX\_REGISTERS\_PER\_BLOCK 8192  
MAX\_SHARED\_MEMORY\_PER\_BLOCK 16384  
MAX\_THREADS\_PER\_BLOCK 512  
MAX\_THREADS\_PER\_MULTIPROCESSOR 768  
MAXIMUM\_SURFACE1D\_LAYERED\_LAYERS 0  
MAXIMUM\_SURFACE1D\_LAYERED\_WIDTH 0  
MAXIMUM\_SURFACE1D\_WIDTH 4096  
MAXIMUM\_SURFACE2D\_HEIGHT 65536  
MAXIMUM\_SURFACE2D\_LAYERED\_HEIGHT 0  
MAXIMUM\_SURFACE2D\_LAYERED\_LAYERS 0  
MAXIMUM\_SURFACE2D\_LAYERED\_WIDTH 0  
MAXIMUM\_SURFACE2D\_WIDTH 4096  
MAXIMUM\_SURFACE3D\_DEPTH 0  
MAXIMUM\_SURFACE3D\_HEIGHT 0  
MAXIMUM\_SURFACE3D\_WIDTH 0  
MAXIMUM\_SURFACECUBEMAP\_LAYERED\_LAYERS 0  
MAXIMUM\_SURFACECUBEMAP\_LAYERED\_WIDTH 0  
MAXIMUM\_SURFACECUBEMAP\_WIDTH 0  
MAXIMUM\_TEXTURE1D\_LAYERED\_LAYERS 512  
MAXIMUM\_TEXTURE1D\_LAYERED\_WIDTH 8192  
MAXIMUM\_TEXTURE1D\_LINEAR\_WIDTH 134217728  
MAXIMUM\_TEXTURE1D\_MIPMAPPED\_WIDTH 8192  
MAXIMUM\_TEXTURE1D\_WIDTH 8192  
MAXIMUM\_TEXTURE2D\_GATHER\_HEIGHT 0  
MAXIMUM\_TEXTURE2D\_GATHER\_WIDTH 0  
MAXIMUM\_TEXTURE2D\_HEIGHT 32768  
MAXIMUM\_TEXTURE2D\_LAYERED\_HEIGHT 8192  
MAXIMUM\_TEXTURE2D\_LAYERED\_LAYERS 512  
MAXIMUM\_TEXTURE2D\_LAYERED\_WIDTH 8192  
MAXIMUM\_TEXTURE2D\_LINEAR\_HEIGHT 65000  
MAXIMUM\_TEXTURE2D\_LINEAR\_PITCH 1048544  
MAXIMUM\_TEXTURE2D\_LINEAR\_WIDTH 65000  
MAXIMUM\_TEXTURE2D\_MIPMAPPED\_HEIGHT 8192  
MAXIMUM\_TEXTURE2D\_MIPMAPPED\_WIDTH 8192  
MAXIMUM\_TEXTURE2D\_WIDTH 65536  
MAXIMUM\_TEXTURE3D\_DEPTH 2048  
MAXIMUM\_TEXTURE3D\_DEPTH\_ALTERNATE 0  
MAXIMUM\_TEXTURE3D\_HEIGHT 2048  
MAXIMUM\_TEXTURE3D\_HEIGHT\_ALTERNATE 0  
MAXIMUM\_TEXTURE3D\_WIDTH 2048  
MAXIMUM\_TEXTURE3D\_WIDTH\_ALTERNATE 0  
MAXIMUM\_TEXTURECUBEMAP\_LAYERED\_LAYERS 0  
MAXIMUM\_TEXTURECUBEMAP\_LAYERED\_WIDTH 0  
MAXIMUM\_TEXTURECUBEMAP\_WIDTH 8192  
MEMORY\_CLOCK\_RATE 602000  
MULTIPROCESSOR\_COUNT 2  
PCI\_BUS\_ID 1  
PCI\_DEVICE\_ID 0  
PCI\_DOMAIN\_ID 0  
RAM\_LOCATION 1  
RAM\_TYPE 5  
SURFACE\_ALIGNMENT 256  
TCC\_DRIVER 0  
TEXTURE\_ALIGNMENT 256  
TEXTURE\_PITCH\_ALIGNMENT 32  
TOTAL\_CONSTANT\_MEMORY 65536  
TOTAL\_MEMORY 67108864  
UNIFIED\_ADDRESSING 0  
WARP\_SIZE 32

---

<div class="post-metadata">

**Author:** ![asterix87](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@asterix87](https://forums.developer.nvidia.com/u/asterix87)\
**Post date:** [August 20, 2013, 9:32pm UTC](https://forums.developer.nvidia.com/t/cudaerrormemoryallocation-error/30100/6 "2013-08-20T21:32:44Z")

</div>

Solved! :

Turn Off Windows Aero!
