JuliaSIMD / LoopVectorization.jl

Macro(s) for vectorizing loops.
MIT License
742 stars 66 forks source link

LoadError: BoundsError: attempt to access 2-element Vector{LoopVectorization.ArrayReferenceMeta} at index [0] #527

Open chengxo opened 8 months ago

chengxo commented 8 months ago

Hi,

I am working with Julia v1.6.2 with LoopVectorization v0.12.166. I am new to LoopVectorization, and I cannot figure out the problem after searching online for quite a while.

Here is a MWE of the error that I encounter.

using LoopVectorization
function test(a, b)
    @turbo for i in axes(a,1)
        a[i, 1] = 0.0
        for j in axes(a,2)
            a[i, 1] += b[i,j]
        end
    end
    return nothing
end

a = rand(256, 256)
b = rand(256, 256)
test(a, b)

will give me ($HOMEFOLDER is used below for privacy) ERROR: LoadError: BoundsError: attempt to access 2-element Vector{LoopVectorization.ArrayReferenceMeta} at index [0] Stacktrace: [1] getindex @ .\array.jl:801 [inlined] [2] getindex @ .\abstractarray.jl:1173 [inlined] [3] mref_elbytes @ $HOMEFOLDER.julia\packages\LoopVectorization\7gWfp\src\reconstruct_loopset.jl:675 [inlined] [4] add_op!(ls::LoopVectorization.LoopSet, instr::LoopVectorization.Instruction, ops::Vector{LoopVectorization.OperationStruct}, nopsv::Vector{Int64}, expandedv::Vector{Bool}, i::Int64, mrefs::Vector{LoopVectorization.ArrayReferenceMeta}, opsymbol::Symbol, elementbytes::Vector{Int64}) @ LoopVectorization $HOMEFOLDER.julia\packages\LoopVectorization\7gWfp\src\reconstruct_loopset.jl:69

However, if I remove the line a[i, 1] = 0.0, it works well. The original also works if I don't use @turbo.

Could you help me understand this error message? And how should I implement such a task using @turbo? Thanks very much!

chengxo commented 8 months ago

After looking more into the issue list, I think it is related to #331, #411, although removing a[i,1] = 0.0 fixing the issue still looks weird to me.