JuliaSIMD / JuliaSIMD/LoopVectorization.jl
Weird behavior
- Lingua principale
- Julia
- Stelle
- 789
- Fork
- 73
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
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)
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Valutazione
Questa issue non è ancora stata valutata.