Implementing a basic Genetic Algorithm using GPUArrays

I don’t know much about GPUs in Julia, but I know enough to answer part of your question:

The reason that SVector works where MVector does not is that an SVector is a “bits” type: https://docs.julialang.org/en/stable/stdlib/base/#Base.isbits A bits type is one that is immutable and is composed entirely of primitive values, tuples, or other bits types. A static, immutable vector of, for example, Float64s is a bits type, but a mutable vector is not.

Bits types are somewhat special in Julia: in particular, Julia guarantees that if you have an Array of bits types, those types will be stored directly inline in the array, and not as pointers. That’s probably why the bits distinction is important for GPU arrays.

Bits types are also super important for performance, because they can generally be stack-allocated. As a result, creating a new instance of a bits type has very little performance cost. That’s why SVectors are so useful for code in which you’re creating new vectors frequently within a loop.

So, that’s all to say that there’s not much that StaticArrays.jl could do to make an MVector the same as an SVector. It would have to be a change in Julia itself.

1 Like