Segfault with SIMD.jl and BenchmarkTools.jl

Hi,
I try to learn how to use SIMD.jl and the following snippet produces a segmentation fault when I use @btime.

using BenchmarkTools
using SIMD

const SBS=8

function  microaxpy_simd!(ys::Vector{T}, a::T, xs::Vector{T}) where {T}
    @assert length(ys) == length(xs)
    lane = VecRange{SBS}(0)
    ys[lane+1] += a*xs[lane+1]
end

function test()
   x=ones(SBS)
   y=ones(SBS)
   a=2.0

   microaxpy_simd!(y,a,x) #Seems OK
   @show y
   # @btime microaxpy_simd!($y,$a,$x) #produce s segfault
end

Any hints ?

2 Likes

Shouldn’t this be VecRange{SBS}(1), in accordance with

?

Thank you for the suggestion but when I try

lane = VecRange{SBS}(1)
ys[lane+0] += a*xs[lane+0]

I have the same segfault crash as with

lane = VecRange{SBS}(0)
ys[lane+1] += a*xs[lane+1]

which I copied from the SIMD.jl markdown README (I could not find a more detailed doc).
What is strange is that if you try the top MWE, the result y looks fine ([3.0,...3.0]).

1 Like

Ah OK, yeah. I think it might have to do with returning the Vec{8, Float64} from microaxpy_simd!. If you return ys or nothing, it’s fine. Not sure why.

1 Like

Argh, not the first time that I forget that returning nothing must be explicit :blush:

Thank you very much for your help !

Still, if anyone knows why returning a SIMD.Vec (a glorified NTuple of Core.VecElements) causes a segfault, I’d like to know.

1 Like

Here is a GitHub issue (from last December).

If you return a NTuple{W,Core.VecElement{T}} wrapped in a struct (eg, a SIMD.Vec or a tuple), you’re likely to get a segfault.

4 Likes