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

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,

Hi,

Yes, this is certainly possible in the style of

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

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))
1 Like

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

1 Like