JuliaSIMD / JuliaSIMD/LoopVectorization.jl
Weird/inconsistent behavior with constant lhs indexing inside @turbo loop
- Lingua principale
- Julia
- Stelle
- 789
- Fork
- 73
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
I've noticed some weird and inconsistent behavior when attempting to assign to given elements of a constant index inside of a set of `@turbo` loops.
The following:
```
X = ones(5, 5)
@turbo for j in axes(X,2)
for i in axes(X,1)
X[1,1] = 0
end
end
```
will give an error `ERROR: BoundsError: attempt to access 0-element Vector{Int64} at index [1]` (which is obviously not true at face value)
However, this version, which should technically be the same
```
X = ones(5, 5)
@turbo for j in axes(X,2)
for i in axes(X,1)
X[1,j-j+1] = 0
end
end
```
runs without complaining, with X becoming
```
0.0 1.0 1.0 1.0 1.0
1.0 1.0 1.0 1.0 1.0
1.0 1.0 1.0 1.0 1.0
1.0 1.0 1.0 1.0 1.0
1.0 1.0 1.0 1.0 1.0
```
as expected.
Perhaps the more worrisome example, however, is the (again, at face value identical)
```
X = ones(5, 5)
@turbo for j in axes(X,2)
for i in axes(X,1)
X[i-i+1,1] = 0
end
end
```
which runs without complaining, but with X becoming
```
0.0 1.0 1.0 1.0 1.0
0.0 1.0 1.0 1.0 1.0
1.0 1.0 1.0 1.0 1.0
1.0 1.0 1.0 1.0 1.0
1.0 1.0 1.0 1.0 1.0
```
which is just wrong.
What to do? Is there some reason that indexing into constant-value vectors shouldn't be allowed inside these loops? And can I be certain that this will work as intended if I do this add/subtract "trick" with a specific index? After a quick check with a tensor it seems like it only messes up if I choose the first/innermost index, but I'd like to know for sure that this is the case.
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Direzione di ricerca
Start by reproducing the three @turbo examples from the issue and tracing how constant indices and expressions such as j-j+1 or i-i+1 are handled during loop analysis and vectorization. Done means the examples either behave consistently with ordinary indexing or are rejected with a clear, correct error, with regression coverage for the reported cases.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- julia
- Ambito
- compilers, performance
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 25/100