# Usage of CUDA.Const

**URL:** <https://discourse.julialang.org/t/usage-of-cuda-const/122157>\
**Category:** GPU\
**Tags:** cuda\
**Created:** [November 1, 2024, 10:03pm UTC](https://discourse.julialang.org/t/usage-of-cuda-const/122157 "2024-11-01T22:03:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marco\_Lombardi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marco_lombardi/32/14608_2.png) [@Marco\_Lombardi](https://discourse.julialang.org/u/Marco_Lombardi)\
**Post date:** [November 1, 2024, 10:03pm UTC](https://discourse.julialang.org/t/usage-of-cuda-const/122157/1 "2024-11-01T22:03:30Z")

</div>

I am unsure how to use the `CUDA.Const` function to mark an array as constant during the execution of a CUDA kernel. From the few examples I saw, it looks like I just need to define a variable within the kernel that “shadow” the original array, as in `cxs = CUDA.Const(xs)`, and then I can directly use the new variable `cxs`. I tried that and it works, but surprisingly I do not see any benefit from its usage, although I would expect a significant one (the same kernel, rewritten with shared memory for `xs`, is almost twice as fast).

Am I missing something or is this expected?

---

<div class="post-metadata">

**Author:** ![maleadt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maleadt/32/10097_2.png) [@maleadt](https://discourse.julialang.org/u/maleadt)\
**Post date:** [November 4, 2024, 4:34pm UTC](https://discourse.julialang.org/t/usage-of-cuda-const/122157/2 "2024-11-04T16:34:13Z")

</div>

> [@Marco\_Lombardi](#):
>
> I tried that and it works, but surprisingly I do not see any benefit from its usage, although I would expect a significant one (the same kernel, rewritten with shared memory for `xs`, is almost twice as fast).

With `Const` we emit loads that use a different GPU cache level (read-only texture cache instead of L1/L2), which used to be much faster. Modern hardware has much faster L1/L2 caches, resulting in `ldg` being much less relevant than it used to be. So depending on your hardware, this is expected.
