JuliaSIMD / JuliaSIMD/LoopVectorization.jl

Incorrect result in accumulator expression

Offen
#147 2 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
Julia
Sterne
789
Forks
73
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

Something is causing this third case to be unhappy:
```julia
julia> using LoopVectorization

julia> let a = 1.0, b = 1.0, h = 1.0, v = rand(10)
@avx for i in eachindex(v)
h = a * v[i] + h
end
end
5.877242734755752

julia> let a = 1.0, b = 1.0, h = 1.0, v = rand(10)
@avx for i in eachindex(v)
h = v[i] + b * h
end
end
5.35890841491465

julia> let a = 1.0, b = 1.0, h = 1.0, v = rand(10)
@avx for i in eachindex(v)
h = a * v[i] + b * h
end
end
ERROR: UndefVarError: ##op#602_0 not defined
Stacktrace:
[1] macro expansion at /home/mason/.julia/packages/LoopVectorization/OZUlx/src/reconstruct_loopset.jl:503 [inlined]
[2] _avx_! at /home/mason/.julia/packages/LoopVectorization/OZUlx/src/reconstruct_loopset.jl:503 [inlined]
[3] top-level scope at ./REPL[16]:2
```
Furthermore, if I try to fix it by changing around the syntax, it actually runs and gets an incorrect result:
```julia
julia> let a = 1.5, b = 2.0, h = 3.0, v = rand(10)
@avx for i in eachindex(v)
h_old = h
h = a * v[i] + b * h_old
end
h
end
3.0

julia> let a = 1.5, b = 2.0, h = 3.0, v = rand(10)
for i in eachindex(v)
h_old = h
h = a * v[i] + b * h_old
end
h
end
3979.1681593580383

(@v1.5) pkg> st LoopVectorization
Status `~/.julia/environments/v1.5/Project.toml`
[bdcacae8] LoopVectorization v0.8.24

julia> versioninfo()
Julia Version 1.5.0
Commit 96786e22cc* (2020-08-01 23:44 UTC)
Platform Info:
OS: Linux (x86_64-pc-linux-gnu)
CPU: AMD Ryzen 5 2600 Six-Core Processor
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-9.0.1 (ORCJIT, znver1)
Environment:
JULIA_NUM_THREADS = 6

```

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Rechercherichtung

Reproduce the three accumulator examples with Julia 1.5 and LoopVectorization v0.8.24. Start at src/reconstruct_loopset.jl:503, identified in the stack trace, and trace how the @avx loop handles the combined a * v[i] + b * h expression. Done means the expression no longer raises UndefVarError and the transformed loop matches the ordinary loop's result.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
julia
Bereich
performance
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.