Julia: SIMD example from performance tips has terrible performance

Created on 8 Jun 2018  路  6Comments  路  Source: JuliaLang/julia

Using the example from the performance tips page has awful performance, both on a swanky AVX512 system and on my old Nehalem i5 laptop. Results from the AVX512 system:

julia> function inner(x::Array, y::Array)
           s = zero(eltype(x))
           for i=eachindex(x)
               @inbounds s += x[i]*y[i]
           end
           s
       end
inner (generic function with 1 method)

julia> function innersimd(x::Array, y::Array)
           s = zero(eltype(x))
           @simd for i=eachindex(x)
               @inbounds s += x[i]*y[i]
           end
           s
       end
innersimd (generic function with 1 method)

julia> function timeit(n, reps)
           x = rand(Float32,n)
           y = rand(Float32,n)
           s = zero(Float64)
           time = @elapsed for j in 1:reps
               s+=inner(x,y)
           end
           println("GFlop/sec        = ",2.0*n*reps/time*1E-9)
           time = @elapsed for j in 1:reps
               s+=innersimd(x,y)
           end
           println("GFlop/sec (SIMD) = ",2.0*n*reps/time*1E-9)
       end
timeit (generic function with 1 method)

julia> timeit(1000,1000)
GFlop/sec        = 17543.85964912281
GFlop/sec (SIMD) = 20.469362481705506

Tentatively marking this as a regression, as apparently on at least _some_ system the SIMD version was 10x faster than the non-simd one in the past.

performance simd

Most helpful comment

That first number seems way too high?

All 6 comments

That first number seems way too high?

What, you don't think my 8 year old laptop can do 34 Teraflops?

Adding @noinline causes this to behave as expected. Thanks for gut-check :)

Didn't I just fix this? Are you looking at up to date docs? Or has docs not deployed since?

Sure enough. But the docs haven't updated yet? https://docs.julialang.org/en/latest/manual/performance-tips/#man-performance-annotations-1

Perhaps master CI hasn't passed since.

Was this page helpful?
0 / 5 - 0 ratings