Git Product home page Git Product logo

Comments (3)

chrisvwx avatar chrisvwx commented on August 15, 2024

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

from loopvectorization.jl.

chriselrod avatar chriselrod commented on August 15, 2024

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.

from loopvectorization.jl.

chrisvwx avatar chrisvwx commented on August 15, 2024

Thanks!

from loopvectorization.jl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.