Create static vector of variable lenght in gpu kernel

Are there any ways to create a static vector of variable length for each thread in a gpu kernel?
I tried this but it didn’t work.

function dosomething(n)
    vec = @MVector zeros(n)

@cuda threads=5 dosomething(n)

In my application, I need to create few local small arrays (the size is determined by the argument of the kernel function call) for some intermediate calculation. Are there any alternative ways to do this?

Try passing it as a value type:

using CUDA, StaticArrays

function dosomething(::Val{N}) where N
    vec = @MVector zeros(N)

@cuda threads=5 dosomething(Val(3))
1 Like

It works. Thanks a lot!

1 Like