JuliaSIMD / JuliaSIMD/LoopVectorization.jl
Inconsistent results w/ and w/o @turbo
- Lingua principale
- Julia
- Stelle
- 789
- Fork
- 73
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
Consider the following code
```julia
using LoopVectorization, OffsetArrays
function morph_dilate(A::AbstractArray{T,N}, kernel::AbstractArray{S,N}) where {T<:Integer,S<:Integer,N}
out = similar(A, tuple((first(axes(A, n)) + first(axes(kernel, n)):
last(axes(A, n)) + last(axes(kernel, n)) for n ∈ 1:N)...)...)
out .= zero(T)
Ks = CartesianIndices(kernel)
@turbo for I in CartesianIndices(A)
for K in Ks
out[I+K] |= A[I] & kernel[K]
end
end
out
end
```
[The function essentially performs a convolution with a given `kernel` of an input array `A`, using the integer *and* (`&`) and the *or* (`|`) instead of the product and sum in the convolution expression. It also *extends* the original input array *A*.]
When I use this function on a test input I obtain an unexpected result:
```julia
julia> morph_dilate([1 2 3; 4 5 6], OffsetArrays.centered([0 7 0; 7 7 7; 0 7 0]))
4×5 OffsetArray(::Matrix{Int64}, 0:3, 0:4) with eltype Int64 with indices 0:3×0:4:
0 1 0 3 0
1 5 3 7 3
4 5 6 7 6
0 4 0 6 0
```
Note that this result is wrong: the correct result, which can be obtained removing the `@turbo` macro in the definition above, is
```julia
julia> morph_dilate([1 2 3; 4 5 6], OffsetArrays.centered([0 7 0; 7 7 7; 0 7 0]))
4×5 OffsetArray(::Matrix{Int64}, 0:3, 0:4) with eltype Int64 with indices 0:3×0:4:
0 1 2 3 0
1 7 7 7 3
4 5 7 7 6
0 4 5 6 0
```
Am I using `@turbo` in an wrong way, or is that a bug?
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Direzione di ricerca
Reproduce the reported morph_dilate example with and without @turbo, using the Julia code and LoopVectorization and OffsetArrays packages named in the issue. Compare both outputs and inspect how @turbo handles the nested CartesianIndices loop and |= update. Done means determining whether the usage is invalid or the optimized result is a LoopVectorization bug, with a regression test or clear reproduction.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- julia
- Ambito
- performance
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100