JuliaSIMD / JuliaSIMD/LoopVectorization.jl

Weird behavior

Offen
#381 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

Function `f()`, which goes over the data once, is more than ten times slower than function `f2()`, which goes over the data twice. Is this some kind of bug?

```julia
using BenchmarkTools, LoopVectorization, Random
function f(g::AbstractArray{T}, q::AbstractArray{T}, f::AbstractArray{T}) where T
r = zero(T)
I, J = size(g)
@turbo for j in 1:J
for i in 1:I
qf_local = zero(T)
for k in 1:K
qf_local += q[k, i] * f[k, j]
end
r += g[i, j] * log(qf_local) + (2one(T) - g[i, j]) * log(one(T) - qf_local)
end
end
end

function f2(g::AbstractArray{T}, q::AbstractArray{T}, f::AbstractArray{T}) where T
r = zero(T)
I, J = size(g)
@turbo for j in 1:J
for i in 1:I
qf_local = zero(T)
for k in 1:K
qf_local += q[k, i] * f[k, j]
end
r += g[i, j] * log(qf_local)
end
end
@turbo for j in 1:J
for i in 1:I
qf_local = zero(T)
for k in 1:K
qf_local += q[k, i] * f[k, j]
end
r += (2one(T) - g[i, j]) * log(one(T) - qf_local)
end
end
end
g = rand(100000, 1000)
qq = rand(3, 100000)
ff = rand(3, 1000)
```

```julia
@btime f(g, qq, ff)
```

1.961 s (22 allocations: 560 bytes)

```julia
@btime f2(g, qq, ff)
```

172.651 ms (53 allocations: 1.77 KiB)

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Rechercherichtung

Reproduce the reported difference between f and f2 using the provided Julia definitions, @turbo loops, and @btime commands. Start by checking how LoopVectorization handles the combined expression versus the two separate passes; done means identifying whether the behavior is a bug and documenting or correcting it.

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.