# Use of static array in a kernel function

**URL:** <https://discourse.julialang.org/t/use-of-static-array-in-a-kernel-function/52852>\
**Category:** GPU\
**Created:** [January 4, 2021, 9:43pm UTC](https://discourse.julialang.org/t/use-of-static-array-in-a-kernel-function/52852 "2021-01-04T21:43:34Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![marius311](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marius311/32/3953_2.png) [@marius311](https://discourse.julialang.org/u/marius311)\
**Post date:** [January 4, 2021, 11:12pm UTC](https://discourse.julialang.org/t/use-of-static-array-in-a-kernel-function/52852/2 "2021-01-04T23:12:11Z")

</div>

You definitely can, StaticArrays are super handy in kernels since they don’t allocate (which is a requirement of kernel code). The problem with your code above is just that its not valid CPU code either, your `x` variable is just a type, not an instance of an SVector. Here’s a similar example that works,

```julia
using StaticArrays, Setfield

function register()
    x = @SVector Float64[0, 0, 0]
    @set! x[1] = 1
    return nothing
end

```

Note also the use of `@set!` from `Setfield` since you can’t actually mutate the SVector. Depending on what you’re trying to do, that could be useful (though not necessarily the most performant thing).

---

_[View the full topic](https://discourse.julialang.org/t/use-of-static-array-in-a-kernel-function/52852)._
