Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LoadError on simple example #331

Open
droodman opened this issue Aug 28, 2021 · 1 comment
Open

LoadError on simple example #331

droodman opened this issue Aug 28, 2021 · 1 comment

Comments

@droodman
Copy link

I'm struggling to understand why this function won't load:

using LoopVectorization
function f(X::Matrix{Float64})
  retval = [1]
  @turbo for i ∈ eachindex(X)
    retval[1] += X[i]
  end
end

When I try to execute this code in Julia 1.6.2--not execute the f() function--I get:

ERROR: LoadError: LoadError: KeyError: key Symbol("###RHS###5###") not found
Stacktrace:
 [1] getindex
   @ .\dict.jl:482 [inlined]
 [2] add_reduction!(ls::LoopVectorization.LoopSet, var::Symbol, reduceddeps::Vector{Symbol}, deps::Vector{Symbol}, vparents::Vector{LoopVectorization.Operation}, reduction_ind::Int64, elementbytes::Int64, instr::LoopVectorization.Instruction)
@chriselrod
Copy link
Member

chriselrod commented Aug 28, 2021

There's another issue like this somewhere, but I couldn't find it with a brief check.
You can do some variant of:

function f(X::Matrix{Float64})
  retval = 1
  @turbo for i  eachindex(X)
    retval += X[i]
  end
   [retval]
end

Basically, if you're accumulating into an array, it wants that array to be indexed by one of the loops.
I could manually add the transform to go from

function f(X::Matrix{Float64})
  retval = [1]
  @turbo for i  eachindex(X)
    retval[1] += X[i]
  end
end

to

function f(X::Matrix{Float64})
  retval = [1]
  retval_tmp = retval[1]
  @turbo for i  eachindex(X)
    retval_tmp += X[i]
  end
  retval[1] = retval_tmp
end

or some variant of this, but it seems easy enough to do it manually that spending time on that is a very low priority for me.

A PR applying this transform would be welcome, however.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants