JuliaSIMD / JuliaSIMD/LoopVectorization.jl
Inconsistent results w/ and w/o @turbo
- Vorherrschende Sprache
- Julia
- Sterne
- 789
- Forks
- 73
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
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?
Beitragsleitfaden
Für dieses Repository ist kein Beitragsleitfaden indexiert
Rechercherichtung
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.
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