What's the difference between LAYOUT_PITCH and LAYOUT_BLOCKLINEAR?


Can someone explain what’s the difference between pitch and blocklinear buffer layout?

Thank you.


Pitch is a linear memory allocation calculated from the user provide’s 2D sizes, with the required padding to ensure row major access correctly.
Block linear layout is to optimize the coherence of 2D (and 3D) access patterns both for reading and writing purposes.

There is no block height in pitch surfaces. It is simple pitch storage format.
For block linear surfaces, depends on the architecture, it will have a different vertical arrangement.


Thank you AastaLL!
So in Pitch layout, if I have image size WxH and if I would like to access pixel P at location (r,c), I would do P(r,c) = r*W + c, where r = row & c = column location of pixel?

Also, how much is the padding? I have 640x480 image of YUV420 (all 8-bit), the size of Y channel reports 393216 bytes.I expected 640*480 = 307200 bytes.

Thank you.

1 Like


For a data pointer p(r, c), where r < height and c < width, p(r,c) = r * pitch + c.
Pitch is a return value of cudaMallocPitch() and stands for the real buffer width with padding.

More details, please check this document:
[url]Programming Guide :: CUDA Toolkit Documentation