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

maybescalarize instead of can_turbo? #453

Open
chriselrod opened this issue Jan 3, 2023 · 0 comments
Open

maybescalarize instead of can_turbo? #453

chriselrod opened this issue Jan 3, 2023 · 0 comments
Labels
good first issue Good for newcomers help wanted Extra attention is needed

Comments

@chriselrod
Copy link
Member

chriselrod commented Jan 3, 2023

See here for some background: JuliaSIMD/StrideArrays.jl#62 (comment)

The idea is not to check whether a function has a SIMD implementation, but to scalarize in case we do not have one.

@inline function maybescalarize(f::F, x::Vararg{Any,K}) where {K}
    T = Base.promote_op(f, x...)
    T === Union{} && scalarize(f, x...)
    return f(x...)
end
using VectorizationBase: AbstractSIMDVector
@inline function scalarize(f::F, x::AbstractSIMDVector{W}) where {W}
    Vec(ntuple(f  x, Val(8))...)
end

Two things are missing:

  1. Add all the missing scalarize methods I didn't include above. This means VecUnroll and things that are neither VecUnroll or AbstractSIMDVector. We also need to consider functions with all sorts of different numbers of arguments. Thankfully, we don't need to consider memory operations like vload or vstore, because these should always vectorize (our checks on the arrays should handle that).
  2. Updating LV's code generation to call maybescalarize(f, args...) instead of f(args...). This might only mean editing here:
    function callexpr(instr::Instruction)
    if instr.mod === :LoopVectorization
    Expr(:call, lv(instr.instr))
    else#if instr.mod === :Main
    Expr(:call, instr.instr)
    end
    end

    and this file
    https://github.com/JuliaSIMD/LoopVectorization.jl/blob/main/src/codegen/lower_compute.jl
    because all of the other places are probably related to load/store or address calculation.

With respect to JuliaSIMD/StrideArrays.jl#62 this will vectorize the call (exactly what we want), because our type check will be using the actually correct argument types to the function, and not just Vec{2,Int}.

Seems like this should be fairly straightforward, and may be a nice improvement.

I'd be happy to provide instructions/guidance/answer questions if anyone wants to take this on!

@chriselrod chriselrod added help wanted Extra attention is needed good first issue Good for newcomers labels Jan 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant