# why constant memory doesn't work in my example application

**URL:** <https://forums.developer.nvidia.com/t/why-constant-memory-doesnt-work-in-my-example-application/20480>\
**Category:** CUDA Programming and Performance\
**Created:** [January 9, 2011, 7:07pm UTC](https://forums.developer.nvidia.com/t/why-constant-memory-doesnt-work-in-my-example-application/20480 "2011-01-09T19:07:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![apostglen46](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@apostglen46](https://forums.developer.nvidia.com/u/apostglen46)\
**Post date:** [January 9, 2011, 7:07pm UTC](https://forums.developer.nvidia.com/t/why-constant-memory-doesnt-work-in-my-example-application/20480/1 "2011-01-09T19:07:46Z")

</div>

i really can’t explain this.  
My application works just great when i use only global memory but when i try to use constant memory it’s like constant memory is filled with zeroes.  
What i’m trying to do in my example is offload data\_x and data\_y in constant memory to speed up my app.  
Thank you for your time.  
Apostolis

[my\_k-means\_map\_tid\_reduce\_atomic\_no\_thrust\_constant.cu](https://forums.developer.nvidia.com/uploads/short-url/52c72dAkylxxeWKcrhVE0BEapP4.cu) (7.53 KB)

[a.txt](https://forums.developer.nvidia.com/uploads/short-url/61RJoJN3khOFfDfZqR2f4YldPVS.txt) (190 Bytes)

[b.txt](https://forums.developer.nvidia.com/uploads/short-url/iofYDv7Zh6leWEhAvrbCg7GnlIh.txt) (192 Bytes)

Edit:i actually found the problem just now,for some weird reason the pointer to constant memory screwed everything up.  
I changed d\_data\_x to c\_data\_x INSIDE the kernel NOT the argument list and it worked,but to my dissapointment it was slower than global memory.(probably due to fermi cache).  
Can anybody explain to me why the pointer thing is happening?

---

<div class="post-metadata">

**Author:** ![tera](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@tera](https://forums.developer.nvidia.com/u/tera)\
**Post date:** [January 9, 2011, 8:09pm UTC](https://forums.developer.nvidia.com/t/why-constant-memory-doesnt-work-in-my-example-application/20480/2 "2011-01-09T20:09:21Z")

</div>

The compiler needs to be able to figure out at compile time to which kind of memory a pointer points to. This is possible if you set in inside the kernel, but not if you pass it in as an argument.  
Did you get a “Cannot tell what pointer points to, assuming global memory space” warning?

Constant cache is best if all threads of a warp read the same address. If different addresses are read, it needs as many cycles as addresses are read, so it might get quite slow. In that case it is better to use a texture.

---

<div class="post-metadata">

**Author:** ![apostglen46](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@apostglen46](https://forums.developer.nvidia.com/u/apostglen46)\
**Post date:** [January 9, 2011, 8:31pm UTC](https://forums.developer.nvidia.com/t/why-constant-memory-doesnt-work-in-my-example-application/20480/3 "2011-01-09T20:31:03Z")

</div>

> [@](#):
>
> The compiler needs to be able to figure out at compile time to which kind of memory a pointer points to. This is possible if you set in inside the kernel, but not if you pass it in as an argument.
> 
> Did you get a “Cannot tell what pointer points to, assuming global memory space” warning?
> 
> Constant cache is best if all threads of a warp read the same address. If different addresses are read, it needs as many cycles as addresses are read, so it might get quite slow. In that case it is better to use a texture.

no i didn’t get any warnings,

I know what constant cache is good for but in any case shouldn’t it be at least as good as global memory ? (that’s why i said that it is likely because of L1 cache that constant memory implementation was slower)

---

<div class="post-metadata">

**Author:** ![tera](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@tera](https://forums.developer.nvidia.com/u/tera)\
**Post date:** [January 10, 2011, 4:09pm UTC](https://forums.developer.nvidia.com/t/why-constant-memory-doesnt-work-in-my-example-application/20480/4 "2011-01-10T16:09:16Z")

</div>

Yes I assume you were perfectly right about the cache as global memory would certainly be slower. However for the reason cited constant cache can be slower than cached global memory.
