# Confusion on using texture?

**URL:** <https://forums.developer.nvidia.com/t/confusion-on-using-texture/11077>\
**Category:** CUDA Programming and Performance\
**Created:** [July 23, 2009, 8:01am UTC](https://forums.developer.nvidia.com/t/confusion-on-using-texture/11077 "2009-07-23T08:01:53Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![CUDAkk](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@CUDAkk](https://forums.developer.nvidia.com/u/CUDAkk)\
**Post date:** [July 23, 2009, 8:01am UTC](https://forums.developer.nvidia.com/t/confusion-on-using-texture/11077/1 "2009-07-23T08:01:53Z")

</div>

Hi All,

Is excessive use of texture in program causing low performance ?

---

<div class="post-metadata">

**Author:** ![Electro](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@Electro](https://forums.developer.nvidia.com/u/Electro)\
**Post date:** [July 23, 2009, 9:02am UTC](https://forums.developer.nvidia.com/t/confusion-on-using-texture/11077/2 "2009-07-23T09:02:32Z")

</div>

Yes, that could happen.

Check the SDK’s sample “deviceQuery” it will tell you your maximum amount of constant memory (65536 Bytes for me)  
I assume this value is the amount of cached memory. If more is used, i guess data will be tacken from global memory, which is really slower.

---

<div class="post-metadata">

**Author:** ![CUDAkk](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@CUDAkk](https://forums.developer.nvidia.com/u/CUDAkk)\
**Post date:** [July 23, 2009, 9:47am UTC](https://forums.developer.nvidia.com/t/confusion-on-using-texture/11077/3 "2009-07-23T09:47:09Z")

</div>

> [@](#):
>
> Check the SDK’s sample “deviceQuery” it will tell you your maximum amount of constant memory (65536 Bytes for me)

I am talking about texture memory not constant memory .

**Is any limitation on texture memory uses?**

When I run SDK’s sample “deviceQuery” then I got following:

> [@](#):
>
> CUDA Device Query (Runtime API) version (CUDART static linking)
> 
> There is 1 device supporting CUDA
> 
> Device 0: “Quadro CX”
> 
> CUDA Capability Major revision number: 1
> 
> CUDA Capability Minor revision number: 3
> 
> Total amount of global memory: 1610285056 bytes
> 
> Number of multiprocessors: 24
> 
> Number of cores: 192
> 
> Total amount of constant memory: 65536 bytes
> 
> Total amount of shared memory per block: 16384 bytes
> 
> Total number of registers available per block: 16384
> 
> Warp size: 32
> 
> Maximum number of threads per block: 512
> 
> Maximum sizes of each dimension of a block: 512 x 512 x 64
> 
> Maximum sizes of each dimension of a grid: 65535 x 65535 x 1
> 
> Maximum memory pitch: 262144 bytes
> 
> Texture alignment: 256 bytes
> 
> Clock rate: 1.19 GHz
> 
> Concurrent copy and execution: Yes
> 
> Run time limit on kernels: Yes
> 
> Integrated: No
> 
> Support host page-locked memory mapping: Yes
> 
> Compute mode: Default (multiple host threads
> 
> can use this device simultaneously)
> 
> Test PASSED
> 
> Press ENTER to exit…

---

<div class="post-metadata">

**Author:** ![avidday](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/avidday/32/59219_2.png) [@avidday](https://forums.developer.nvidia.com/u/avidday)\
**Post date:** [July 23, 2009, 10:43am UTC](https://forums.developer.nvidia.com/t/confusion-on-using-texture/11077/4 "2009-07-23T10:43:26Z")

</div>

Texture memory is just global memory with some on GPU read cache. When usage patterns are not optimal for the cache, texture memory can be slower than global memory because you incur a cache miss penalty in addition to the normal global memory load latency.

---

<div class="post-metadata">

**Author:** ![CUDAkk](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@CUDAkk](https://forums.developer.nvidia.com/u/CUDAkk)\
**Post date:** [July 23, 2009, 10:52am UTC](https://forums.developer.nvidia.com/t/confusion-on-using-texture/11077/5 "2009-07-23T10:52:24Z")

</div>

> [@](#):
>
> Texture memory is just global memory with some on GPU read cache. When usage patterns are not optimal for the cache, texture memory can be slower than global memory because you incur a cache miss penalty in addition to the normal global memory load latency.

Could you explain bit more what is **cache miss**?

---

<div class="post-metadata">

**Author:** ![Nico](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@Nico](https://forums.developer.nvidia.com/u/Nico)\
**Post date:** [July 23, 2009, 10:59am UTC](https://forums.developer.nvidia.com/t/confusion-on-using-texture/11077/6 "2009-07-23T10:59:32Z")

</div>

> [@](#):
>
> Could you explain bit more what is **cache miss**?

http://en.wikipedia.org/wiki/Cache

N.

---

<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:** [July 23, 2009, 11:23am UTC](https://forums.developer.nvidia.com/t/confusion-on-using-texture/11077/7 "2009-07-23T11:23:05Z")

</div>

> [@](#):
>
> Texture memory is just global memory with some on GPU read cache. When usage patterns are not optimal for the cache, texture memory can be slower than global memory because you incur a cache miss penalty in addition to the normal global memory load latency.

But global memory is completely uncached…

In my experience, completely random reads are about 3 times faster from the texture cache than from straight global memory reads (yes, even on G200 hardware). With optimal access patterns from the texture you can hit the save device memory bandwidth limits that you do with global memory reads.

---

<div class="post-metadata">

**Author:** ![CUDAkk](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@CUDAkk](https://forums.developer.nvidia.com/u/CUDAkk)\
**Post date:** [July 23, 2009, 11:34am UTC](https://forums.developer.nvidia.com/t/confusion-on-using-texture/11077/8 "2009-07-23T11:34:19Z")

</div>

> [@](#):
>
> But global memory is completely uncached…
> 
> In my experience, completely random reads are about 3 times faster from the texture cache than from straight global memory reads (yes, even on G200 hardware). With optimal access patterns from the texture you can hit the save device memory bandwidth limits that you do with global memory reads.

Actually in my program I have to access 2400\*1800 scattered texture memory read that takes a half of my program execution time. Since My read is scattered so I canot use shared memory.

**Could you guide me here how to reduce scattered read?**

---

<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:** [July 23, 2009, 11:40am UTC](https://forums.developer.nvidia.com/t/confusion-on-using-texture/11077/9 "2009-07-23T11:40:11Z")

</div>

> [@](#):
>
> Actually in my program I have to access 2400\*1800 scattered texture memory read that takes a half of my program execution time. Since My read is scattered so I canot use shared memory.

My solution for scattered reads is to reorder the data in memory so that nearby threads are likely to read nearby values in the texture.

---

<div class="post-metadata">

**Author:** ![CUDAkk](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@CUDAkk](https://forums.developer.nvidia.com/u/CUDAkk)\
**Post date:** [July 23, 2009, 11:55am UTC](https://forums.developer.nvidia.com/t/confusion-on-using-texture/11077/10 "2009-07-23T11:55:01Z")

</div>

> [@](#):
>
> My solution for scattered reads is to reorder the data in memory so that nearby threads are likely to read nearby values in the texture.

I am also thinking same but one confusion is that if I made a extera kernel for reordering the memory than ,

Is it efficient to use large array of size **2400 \* 1800 \* sizeof (float)** that is accessing in two different kernels?

---

<div class="post-metadata">

**Author:** ![laxsu19](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@laxsu19](https://forums.developer.nvidia.com/u/laxsu19)\
**Post date:** [July 23, 2009, 12:04pm UTC](https://forums.developer.nvidia.com/t/confusion-on-using-texture/11077/11 "2009-07-23T12:04:34Z")

</div>

I’m having similar problems ([topic=“102492”][http://forums.nvidia.com/index.php?showtopic=102492[/topic]](http://forums.nvidia.com/index.php?showtopic=102492%5B/topic%5D)),  
and texture reads also seem slower, and seem to kill my program execution.

I feel like you in that I am merely using the texture to add some caching in case there is a chance for a near-hit, otherwise the index of the textured array I am accessing is purely random, by design of the code. It’s not exactly what CUDA is made for, I know, but it doesn’t mean I wont try…

---

<div class="post-metadata">

**Author:** ![CUDAkk](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@CUDAkk](https://forums.developer.nvidia.com/u/CUDAkk)\
**Post date:** [July 23, 2009, 4:49pm UTC](https://forums.developer.nvidia.com/t/confusion-on-using-texture/11077/12 "2009-07-23T16:49:49Z")

</div>

> [@](#):
>
> I’m having similar problems ([topic=“102492”][The Official NVIDIA Forums | NVIDIA](http://forums.nvidia.com/index.php?showtopic=102492%5B/topic%5D)),
> 
> and texture reads also seem slower, and seem to kill my program execution.
> 
> I feel like you in that I am merely using the texture to add some caching in case there is a chance for a near-hit, otherwise the index of the textured array I am accessing is purely random, by design of the code. It’s not exactly what CUDA is made for, I know, but it doesn’t mean I wont try…

Have you got any sucess?

---

<div class="post-metadata">

**Author:** ![laxsu19](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@laxsu19](https://forums.developer.nvidia.com/u/laxsu19)\
**Post date:** [July 23, 2009, 5:14pm UTC](https://forums.developer.nvidia.com/t/confusion-on-using-texture/11077/13 "2009-07-23T17:14:48Z")

</div>

> [@](#):
>
> Have you got any sucess?

Not thus far. I have 5 sites in the program where tex1dfetch can be called instead of a global memory linear array index read.

If I enable (remove comments from them) the first four of these, it works, with a consistent 0.1sec time penalty.

If i enable the last one, which is no different really than the others, the code will have the 5 second timeout error.

This even happens if the first four are commented out and JUST the last one is enabled. Weird huh?

---

<div class="post-metadata">

**Author:** ![byung](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@byung](https://forums.developer.nvidia.com/u/byung)\
**Post date:** [September 3, 2009, 3:53pm UTC](https://forums.developer.nvidia.com/t/confusion-on-using-texture/11077/14 "2009-09-03T15:53:10Z")

</div>

> [@](#):
>
> But global memory is completely uncached…
> 
> In my experience, completely random reads are about 3 times faster from the texture cache than from straight global memory reads (yes, even on G200 hardware). With optimal access patterns from the texture you can hit the save device memory bandwidth limits that you do with global memory reads.

MisterAnderson42,

I always appreciate your contribution to the community.

I would like to ask you that what is the optimal access pattern for texture memory, from your professional experience.

It would be appreciated to see simple loop nest that exhibits optimal memory access pattern for texture memory.

Thanks again,

---

<div class="post-metadata">

**Author:** ![CUDAkk](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@CUDAkk](https://forums.developer.nvidia.com/u/CUDAkk)\
**Post date:** [September 4, 2009, 4:31am UTC](https://forums.developer.nvidia.com/t/confusion-on-using-texture/11077/15 "2009-09-04T04:31:57Z")

</div>

> [@](#):
>

> [@](#):
>
> I would like to ask you that what is the optimal access pattern for texture memory

It is always suggested to use texture memory instead global memory or if you have scatter memory read that use texture insted texture instead of global memory.

If you have 1D texture then use tex1Dfetch() for reading data this gives better performance as compare to global memory read( see page 113 of CUDA programming guide 2.3).
