# Is it possible to use CuStaticSharedArray(T, n) with n const?

**URL:** <https://discourse.julialang.org/t/is-it-possible-to-use-custaticsharedarray-t-n-with-n-const/125756>\
**Category:** GPU\
**Tags:** cuda, sharedarrays\
**Created:** [February 10, 2025, 5:19pm UTC](https://discourse.julialang.org/t/is-it-possible-to-use-custaticsharedarray-t-n-with-n-const/125756 "2025-02-10T17:19:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ludovic\_Dumoulin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ludovic_dumoulin/32/22414_2.png) [@Ludovic\_Dumoulin](https://discourse.julialang.org/u/Ludovic_Dumoulin)\
**Post date:** [February 10, 2025, 5:19pm UTC](https://discourse.julialang.org/t/is-it-possible-to-use-custaticsharedarray-t-n-with-n-const/125756/1 "2025-02-10T17:19:39Z")

</div>

Hello,  
I would like to compare the size of different block to see how the calculation speed-up or not.  
I use SharedArray of size `CuStaticSharedArray(Float64, (B+2,B+2))` with `B` from 16 to 32, and now I am changing B by hand. I would like to be able to define `B` as a const or at least to not have to change it by hand inside all my kernel.  
I would also like to avoid using a `CuDynamicSharedArray` as it requires more memory than a static one.

The idea would be to have something like that:

> function kernel\_test!(P, B)  
> v\_shared = CuStaticSharedArray(Float64, (B+2,B+2,2))  
> …

Thank you form your help,  
Best,

---

<div class="post-metadata">

**Author:** ![eldee](https://avatars.discourse-cdn.com/v4/letter/e/b5a626/32.png) [@eldee](https://discourse.julialang.org/u/eldee)\
**Post date:** [February 10, 2025, 5:49pm UTC](https://discourse.julialang.org/t/is-it-possible-to-use-custaticsharedarray-t-n-with-n-const/125756/2 "2025-02-10T17:49:10Z")

</div>

Hi,

Yes, this is certainly possible in the style of

```julia
const B = 16

function kernel_test!(P)
    v_shared = CuStaticSharedArray(Float64, (B + 2, B + 2, 2))
    ...
    return
end

```

If you want to experiment with different values of `B`, it might make sense to (temporarily) use something like

```julia
function kernel_test!(P, ::Val{B}) where B
    v_shared = CuStaticSharedArray(Float64, (B + 2, B + 2, 2))
    ...
    return
end

...
@cuda ... kernel_test!(P, Val(16))

```

---

<div class="post-metadata">

**Author:** ![Ludovic\_Dumoulin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ludovic_dumoulin/32/22414_2.png) [@Ludovic\_Dumoulin](https://discourse.julialang.org/u/Ludovic_Dumoulin)\
**Post date:** [February 11, 2025, 8:59am UTC](https://discourse.julialang.org/t/is-it-possible-to-use-custaticsharedarray-t-n-with-n-const/125756/3 "2025-02-11T08:59:19Z")

</div>

Thank you !  
I didn’t know that a kernel has access to variables defined outside !
