# cudaMallocPitch()

**URL:** <https://forums.developer.nvidia.com/t/cudamallocpitch/12863>\
**Category:** CUDA Programming and Performance\
**Created:** [October 20, 2009, 11:19pm UTC](https://forums.developer.nvidia.com/t/cudamallocpitch/12863 "2009-10-20T23:19:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gpu\_user](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@gpu\_user](https://forums.developer.nvidia.com/u/gpu_user)\
**Post date:** [October 20, 2009, 11:19pm UTC](https://forums.developer.nvidia.com/t/cudamallocpitch/12863/1 "2009-10-20T23:19:01Z")

</div>

In cudaMallocPitch( (void\*\*) &d\_src , &pitch , width \* sizeof(float) , height);, is height the number of rows and width the number of columns, or the other way around? Thanks.

---

<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:** [October 21, 2009, 2:06am UTC](https://forums.developer.nvidia.com/t/cudamallocpitch/12863/2 "2009-10-21T02:06:27Z")

</div>

> [@](#):
>
> In cudaMallocPitch( (void\*\*) &d\_src , &pitch , width \* sizeof(float) , height);, is height the number of rows and width the number of columns, or the other way around? Thanks.

width = number of columns;

height = number of rows;

pitch = round of (width \* sizeof(type)) and multiple of 64;

for example, assume that if we have a matrix with height = 5, width = 5 and type = “short”, so width \* sizeof(short) = 10 bytes. It means that the matrix needs only 5x5xsizeof(short) = 5x10 bytes.

But when using cudaMallocPitch to allocate this matrix. Pitch = 64. so this matrix will be allocated with 5x64bytes.

I used type of data is short but it also same for float type.

---

<div class="post-metadata">

**Author:** ![gpu\_user](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@gpu\_user](https://forums.developer.nvidia.com/u/gpu_user)\
**Post date:** [October 21, 2009, 3:16pm UTC](https://forums.developer.nvidia.com/t/cudamallocpitch/12863/3 "2009-10-21T15:16:33Z")

</div>

Thanks a lot!

> [@](#):
>
> width = number of columns;
> 
> height = number of rows;
> 
> pitch = round of (width \* sizeof(type)) and multiple of 64;
> 
> for example, assume that if we have a matrix with height = 5, width = 5 and type = “short”, so width \* sizeof(short) = 10 bytes. It means that the matrix needs only 5x5xsizeof(short) = 5x10 bytes.
> 
> But when using cudaMallocPitch to allocate this matrix. Pitch = 64. so this matrix will be allocated with 5x64bytes.
> 
> I used type of data is short but it also same for float type.
