# cudaMemcpy2DArraytoArray vs cudaMemcpy2DtoArray what is the difference?

**URL:** <https://forums.developer.nvidia.com/t/cudamemcpy2darraytoarray-vs-cudamemcpy2dtoarray-what-is-the-difference/8550>\
**Category:** CUDA Programming and Performance\
**Created:** [March 25, 2009, 9:54pm UTC](https://forums.developer.nvidia.com/t/cudamemcpy2darraytoarray-vs-cudamemcpy2dtoarray-what-is-the-difference/8550 "2009-03-25T21:54:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![CudaHenry](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@CudaHenry](https://forums.developer.nvidia.com/u/CudaHenry)\
**Post date:** [March 25, 2009, 9:54pm UTC](https://forums.developer.nvidia.com/t/cudamemcpy2darraytoarray-vs-cudamemcpy2dtoarray-what-is-the-difference/8550/1 "2009-03-25T21:54:57Z")

</div>

Hi,  
I am new to CUDA and currently working on a project in which I need to copy large amount of constant 2D array data into device memory. I checked the Reference Manual and found the following functions:  
cudaMemcpy2DArraytoArray  
cudaMemcpy2DtoArray

My question is  
1: what is the difference between these two functions?  
2. Will they copy the 2D array from host to device without any change or they will reshape the 2D array to a 1D array in copying process?  
3. What is the best way to copy a 2D array to device without changing or reshaping it?

Thank you so much!

CudaHenry

---

<div class="post-metadata">

**Author:** ![Quoc\_Vinh](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@Quoc\_Vinh](https://forums.developer.nvidia.com/u/Quoc_Vinh)\
**Post date:** [March 26, 2009, 9:21am UTC](https://forums.developer.nvidia.com/t/cudamemcpy2darraytoarray-vs-cudamemcpy2dtoarray-what-is-the-difference/8550/2 "2009-03-26T09:21:23Z")

</div>

> [@](#):
>
> Hi,
> 
> I am new to CUDA and currently working on a project in which I need to copy large amount of constant 2D array data into device memory. I checked the Reference Manual and found the following functions:
> 
> cudaMemcpy2DArraytoArray
> 
> cudaMemcpy2DtoArray
> 
> My question is
> 
> 1: what is the difference between these two functions?
> 
> 1. Will they copy the 2D array from host to device without any change or they will reshape the 2D array to a 1D array in copying process?
> 
> 2. What is the best way to copy a 2D array to device without changing or reshaping it?
> 
> Thank you so much!
> 
> CudaHenry

remember that Array in cudaMemcpy2DArraytoArray() and cudaMemcpy2DtoArray() not has the normal structure. Z-curve structure.

**1: what is the difference between these two functions?**

cudaMemcpy2DArraytoArray(): In device memory, you already have allocated 2 Array (by using cudaMallocArray()), and copy data between these Array.

cudaMemcpy2DtoArray(). copy 2D array to cudaArray. 2D array is means that a matrix with 2 dimension with normal structure. In your case you can use this

functio to copy 2D array from host to device global memory.

**2. Will they copy the 2D array from host to device without any change or they will reshape the 2D array to a 1D array in copying process?**

I think that it copy 2D array from host to device without any change .

**3. What is the best way to copy a 2D array to device without changing or reshaping it?**

you have 2 functions to do it.

cudaMemcpy2D(): copy data from host to device memory (normal structure)

cudaMemcpy2DToArray(): copy data from host to cuda Array(not normal structure)

---

<div class="post-metadata">

**Author:** ![CudaHenry](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@CudaHenry](https://forums.developer.nvidia.com/u/CudaHenry)\
**Post date:** [March 26, 2009, 4:41pm UTC](https://forums.developer.nvidia.com/t/cudamemcpy2darraytoarray-vs-cudamemcpy2dtoarray-what-is-the-difference/8550/3 "2009-03-26T16:41:28Z")

</div>

Thanks much, Quoc Vinh! Your answer is very clear.

CudaHenry
