# 1D versus 2D textures Spatial Locality

**URL:** <https://forums.developer.nvidia.com/t/1d-versus-2d-textures-spatial-locality/3961>\
**Category:** CUDA Programming and Performance\
**Created:** [June 5, 2008, 6:22am UTC](https://forums.developer.nvidia.com/t/1d-versus-2d-textures-spatial-locality/3961 "2008-06-05T06:22:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![erlebach](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@erlebach](https://forums.developer.nvidia.com/u/erlebach)\
**Post date:** [June 5, 2008, 6:22am UTC](https://forums.developer.nvidia.com/t/1d-versus-2d-textures-spatial-locality/3961/1 "2008-06-05T06:22:58Z")

</div>

Hi,

I’d just like to confirm:

1. is the spatial locality attributed to texture usage is only 1D locality when using linear memory,  
and 2D locality when using CUDA arrays?

2. I have not found any reference to the degree of locality. When fetching an (x,y) element,  
how how many elements are fetched to texture cache? What is the “radius” of the neighborhood  
around (x,y) that goes to cache? In the 1D case, is there information on the extent of locality?

Thanks a lot!

Gordon

---

<div class="post-metadata">

**Author:** ![MisterAnderson42](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@MisterAnderson42](https://forums.developer.nvidia.com/u/MisterAnderson42)\
**Post date:** [June 5, 2008, 11:43am UTC](https://forums.developer.nvidia.com/t/1d-versus-2d-textures-spatial-locality/3961/2 "2008-06-05T11:43:18Z")

</div>

> [@](#):
>
> 1. is the spatial locality attributed to texture usage is only 1D locality when using linear memory,
> 
> and 2D locality when using CUDA arrays?

Yes. You get the 2D locality with a 2D CUDA array and tex2D. There are also 1D arrays if you need 1D filtering.

> [@](#):
>
> 1. I have not found any reference to the degree of locality. When fetching an (x,y) element,
> 
> how how many elements are fetched to texture cache? What is the “radius” of the neighborhood
> 
> around (x,y) that goes to cache? In the 1D case, is there information on the extent of locality?
> 
> [snapback]388593[/snapback]

This is not documented anywhere that I am aware. My experiences with the texture cache are that it is much too small for any kind of temporal locality: other running warps on the multiproc will flush the cache before the scheduler gets back to the first one. What matters most is getting spatially local memory accesses within each warp. For 1D caches, think of this as an efficient “almost coalesced” memory reader.

I’ve never actually tried testing the performance of the texture cache based on the width of each warp’s coverage. Maybe I’ll write a quick benchmark later today.

---

<div class="post-metadata">

**Author:** ![erlebach](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@erlebach](https://forums.developer.nvidia.com/u/erlebach)\
**Post date:** [June 5, 2008, 2:43pm UTC](https://forums.developer.nvidia.com/t/1d-versus-2d-textures-spatial-locality/3961/3 "2008-06-05T14:43:58Z")

</div>

Thanks. What you say makes sense. I also found something interesting: I was using  
2D textures, and switched to 1D linear textures, which use far less registers. As you say, if I am almost coalesced (or coalesced) without textures, then 2D textures are not required. Furthermore, if the idea is to implement a ping-pong buffer, 2D textures are pretty useless, whereas 1D textures are very efficient. Of course, I have no need for  
filtering, although borders would be useful.

I am looking forward to your benchmark results if you get around to it.

Gordon
