JuliaSIMD / JuliaSIMD/LoopVectorization.jl
Incorrect results using @turbo with linear array indexing
- Lingua principale
- Julia
- Stelle
- 789
- Fork
- 73
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
There was some discussion about this issue [here](https://discourse.julialang.org/t/inconsistent-results-using-loopvectorization-turbo-with-linear-indexing/104481). Essentially, when using linear indexing of an array `@turbo` appears to start indexing the array incorrectly when a offset term is used. An example of this (code and commentary copied directly from the discourse discussion) is below.
```
julia> H = collect(reshape(1.0:6.0, 3, 2))
3×2 Matrix{Float64}:
1.0 4.0
2.0 5.0
3.0 6.0
julia> su = zeros(3);
julia> for k = 1:1
ind = 0 # LinearIndices((3, 2))[1, 1] - 1
for ij in 1:3
su[ij] += H[ij + ind]
end
end
julia> su
3-element Vector{Float64}:
1.0
2.0
3.0
julia> su = zeros(3);
julia> for k = 1:1
ind = 0
@turbo for ij in 1:3
su[ij] += H[ij + ind]
end
end
julia> su
3-element Vector{Float64}:
6.94274366677856e-310
1.0
2.0
```
so `H` is being indexed at 0, 1, 2 instead of 1, 2, 3. The effect doesn’t seem to happen on the left hand expression e.g. `su[ij + ind]` and doesn’t seem to shift more with more additions e.g. `H[ij + ind + ind]`. It does it correctly if the index was added to a literal 0 instead of `ind` or if not added:
```
julia> su = zeros(3);
julia> for k = 1:1
@turbo for ij in 1:3
su[ij] += H[ij + 0]
end
end
julia> su
3-element Vector{Float64}:
1.0
2.0
3.0
julia> su = zeros(3);
julia> for k = 1:1
@turbo for ij in 1:3
su[ij] += H[ij]
end
end
julia> su
3-element Vector{Float64}:
1.0
2.0
3.0
```
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Valutazione
Questa issue non è ancora stata valutata.