JuliaSIMD / JuliaSIMD/LoopVectorization.jl

`maybescalarize` instead of `can_turbo`?

Offen
#453 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
good first issue help wanted
Vorherrschende Sprache
Julia
Sterne
789
Forks
73
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

See here for some background: https://github.com/JuliaSIMD/StrideArrays.jl/issues/62#issuecomment-1367775417

The idea is not to check whether a function has a `SIMD` implementation, but to scalarize in case we do not have one.
```julia
@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:
https://github.com/JuliaSIMD/LoopVectorization.jl/blob/35f83103c12992ddd887cd709bf65e345db5ec9e/src/modeling/costs.jl#L17-L23
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 https://github.com/JuliaSIMD/StrideArrays.jl/issues/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!

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Rechercherichtung

Start with the proposed scalarize methods in the issue, then inspect src/modeling/costs.jl and src/codegen/lower_compute.jl. Trace how generated calls are emitted and identify the handling needed for VecUnroll, AbstractSIMDVector, other argument counts, and non-vector types. Done means the missing scalarize cases are covered and code generation calls maybescalarize where appropriate.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
julia
Bereich
compilers, performance
Issue-Typ
Feature
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
38/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.