# Cuda Memory transfer limit 

**URL:** <https://forums.developer.nvidia.com/t/cuda-memory-transfer-limit/44659>\
**Category:** CUDA Programming and Performance\
**Created:** [August 31, 2016, 4:36pm UTC](https://forums.developer.nvidia.com/t/cuda-memory-transfer-limit/44659 "2016-08-31T16:36:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![A\_F](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@A\_F](https://forums.developer.nvidia.com/u/A_F)\
**Post date:** [August 31, 2016, 4:36pm UTC](https://forums.developer.nvidia.com/t/cuda-memory-transfer-limit/44659/1 "2016-08-31T16:36:59Z")

</div>

Hi!

I have a problem with a program, when I try to pass to the GPU a vector bigger than 1 000 000 the program doesn’t work.  
The vector is double type so its size is 8Mb and my GPU has 1Gb of global memory so I don’t understand what is the problem.

I have tried to split this vector in two parts but the result is the same, I can’t pass to the GPU more than 1 000 000 (each part has 500 000 components).

If the vector is float type I can pass 2 000 000 components.

In all these trials the memory size of the vector was 8Mb, so I understand that the problem should be with the total memory size is pass to the GPU or with the time needed to transfer 8Mb.

In relation with this question I have another question: “Can I change the Timeout Detection & Recovery (TDR) in Mac?”  
(I have done it for Windows but I didn’t get information to do it in Mac)

I have performed a naive code with the problem:  
(In the code vector C gives problems when N \> 1 000 000  
The kernel is a naive kernel where C doesn’t do anything it is only to check that the problem is in cudaMemcpy)

#include \<stdio.h\>

const int N = 1000000;  
const int K = 100;

const int BLOCK\_SIZE = 1024;  
const int NUM\_BLOCKS = 1;

**global** void kernel(double \*C, double \*out)  
{

```
int l = threadIdx.x;

if(l < K)
{
	out[l] = 2.;
}

```

}

int main()  
{

```
double hostOut[K], hostC[N];
double *deviceC, *deviceOut;
int i;

```

//Vector C values  
for (i = 0; i \< N; i++)  
{  
hostC[i] = 1.;  
}

```
cudaMalloc(&deviceOut, sizeof(double)*K);
cudaMalloc(&deviceC, sizeof(double)*N);
		
cudaMemcpy(deviceC, hostC, sizeof(double)*N, cudaMemcpyHostToDevice);

kernel <<<NUM_BLOCKS, BLOCK_SIZE >>>(deviceC, deviceOut);

cudaMemcpy(hostOut, deviceOut, sizeof(double)*K, cudaMemcpyDeviceToHost);

cudaFree(deviceC);
cudaFree(deviceOut);

```

//Print to check the program goes well  
for(int j = 0; j \< 5; j++)  
{  
printf(“f[%i] = %f\n”, j, hostOut[j]);  
}

```
return 0;

```

}

---

<div class="post-metadata">

**Author:** ![BulatZiganshin](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@BulatZiganshin](https://forums.developer.nvidia.com/u/BulatZiganshin)\
**Post date:** [August 31, 2016, 5:14pm UTC](https://forums.developer.nvidia.com/t/cuda-memory-transfer-limit/44659/2 "2016-08-31T17:14:55Z")

</div>

> double hostOut[K], hostC[N];

it’s not the CUDa, you can’t allocate such large arrays in the stack. use the following instead:

```auto
double *hostOut = new double[K], *hostC = new double[N];

```

and at the end:

```auto
delete[] hostOut;
delete[] hostC;

```

and btw, there is a CODE tag, it’s the last in toolbox above the message

PS: for a pure C, use malloc/free instead and check returned pointers

---

<div class="post-metadata">

**Author:** ![A\_F](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@A\_F](https://forums.developer.nvidia.com/u/A_F)\
**Post date:** [August 31, 2016, 5:55pm UTC](https://forums.developer.nvidia.com/t/cuda-memory-transfer-limit/44659/3 "2016-08-31T17:55:50Z")

</div>

Great!!

Thank you very much, it worked perfectly! :)
