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

ERROR: LoadError: KeyError: key :zeroB not found #15

Closed
chrisvwx opened this issue Jan 10, 2020 · 3 comments
Closed

ERROR: LoadError: KeyError: key :zeroB not found #15

chrisvwx opened this issue Jan 10, 2020 · 3 comments

Comments

@chrisvwx
Copy link

Using LoopVectorization.jl#master, I get the following error. I'm not certain how to describe the error, so I put part of the error message in the issue name. I tried a few small variants, with the same result. Is it somehow obvious that I should not put B[i,j] inside the k loop? It works fine without the @avx macro.

julia> using LoopVectorization
julia> function myGramFail!(A, B)
           zeroB = zero(eltype(B))
           @avx for i ∈ 1:size(A,1), j ∈ 1:size(A,2)
               B[i,j] = zeroB
               for k ∈ 1:size(A,2)
                   B[i,j] += A[i,k] * A[k,j]
               end
           end
       end
ERROR: LoadError: KeyError: key :zeroB not found
Stacktrace:
 [1] getindex at ./dict.jl:477 [inlined]
 [2] getop at /Users/cp/.julia/packages/LoopVectorization/M6TfP/src/graphs.jl:161 [inlined]
 [3] add_store!(::LoopVectorization.LoopSet, ::Symbol, ::LoopVectorization.ArrayReference, ::Int64) at /Users/cp/.julia/packages/LoopVectorization/M6TfP/src/graphs.jl:505
 [4] add_store_ref! at /Users/cp/.julia/packages/LoopVectorization/M6TfP/src/graphs.jl:512 [inlined]
 [5] push!(::LoopVectorization.LoopSet, ::Expr, ::Int64) at /Users/cp/.julia/packages/LoopVectorization/M6TfP/src/graphs.jl:586
 [6] add_block!(::LoopVectorization.LoopSet, ::Expr, ::Int64) at /Users/cp/.julia/packages/LoopVectorization/M6TfP/src/graphs.jl:228
 [7] add_loop!(::LoopVectorization.LoopSet, ::Expr, ::Int64) at /Users/cp/.julia/packages/LoopVectorization/M6TfP/src/graphs.jl:285
 [8] add_loop! at /Users/cp/.julia/packages/LoopVectorization/M6TfP/src/graphs.jl:282 [inlined]
 [9] copyto! at /Users/cp/.julia/packages/LoopVectorization/M6TfP/src/constructors.jl:6 [inlined]
 [10] LoopVectorization.LoopSet(::Expr) at /Users/cp/.julia/packages/LoopVectorization/M6TfP/src/constructors.jl:46
 [11] @avx(::LineNumberNode, ::Module, ::Any) at /Users/cp/.julia/packages/LoopVectorization/M6TfP/src/constructors.jl:86
in expression starting at REPL[2]:3
@chrisvwx
Copy link
Author

chrisvwx commented Jan 10, 2020

I get a different error with a slightly different function:

               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.3.1 (2019-12-30)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia> using LoopVectorization
julia> function myGramF!(A, B)
           M,N = size(A);
           @avx for i ∈ 1:M, j ∈ 1:N
               B[i,j] = zero(eltype(B))
               for k ∈ 1:N
                   B[i,j] += A[i,k] * A[k,j]
               end
           end
       end
myGramF! (generic function with 1 method)
julia> N = 20;
julia> A = randn(N, N);
julia> B1 = Matrix{Float64}(undef, N, N);
julia> myGramF!(A, B1)
ERROR: UndefVarError: ####RHS#424_0_0 not defined
Stacktrace:
 [1] myGramF!(::Array{Float64,2}, ::Array{Float64,2}) at ./gcutils.jl:91
 [2] top-level scope at REPL[6]:1

Update: I am aware that the following function works; is it obvious why it works and the two above do not?

function myGramAVX!(A, B)
    z = zero(eltype(B))
    M,N = size(A);
    @avx for i ∈ 1:M, j ∈ 1:N
        Bᵢⱼ = z
        for k ∈ 1:N
            Bᵢⱼ += A[i,k] * A[k,j]
        end
        B[i,j] = Bᵢⱼ
    end
end

@chriselrod
Copy link
Member

Thanks for the bug report!
These are all really helping to make the software more robust.

The key difference between the two versions that did not work and the version that did is that in the former, dependencies go through memory locations, while in the latter they go through variable assignment.
I had been tracking dependencies through assignments (updating bindings), but not through modifying memory.

To be brief, it wasn't recognizing that this:

B[i,j] = zero(eltype(B))

effected the results of:

B[i,j] += A[i,k] * A[k,j]

through changing memory, rather than updating variables. This resulted in a variety of problems.

I now added some basic tracking based on indices, so that your examples work and appear to be optimized correctly, with the store->load also getting CSE-ed.

I'll add your gramF! functions to the tests when I get back home. For now, I added similar matmul code and confirmed that tests pass.

@chrisvwx
Copy link
Author

Thanks!

This issue was closed.
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